Exemplo n.º 1
0
        bool Receiver::operator() (const Tractography::Streamline<>& in)
        {
          auto display_func = [&](){ return printf ("%8" PRIu64 " read, %8" PRIu64 " written", total_count, count); };

          if (number && (count == number))
            return false;

          ++total_count;

          if (in.empty()) {
            writer (in);
            progress.update (display_func);
            return true;
          }

          if (in[0].valid()) {

            if (skip) {
              --skip;
              progress.update (display_func);
              return true;
            }
            writer (in);

          } else {

            // Explicitly handle case where the streamline has been cropped into multiple components
            // Worker class separates track segments using invalid points as delimiters
            Tractography::Streamline<> temp;
            temp.index = in.index;
            temp.weight = in.weight;
            for (Tractography::Streamline<>::const_iterator p = in.begin(); p != in.end(); ++p) {
              if (p->valid()) {
                temp.push_back (*p);
              } else if (temp.size()) {
                writer (temp);
                temp.clear();
              }
            }

          }

          ++count;
          progress.update (display_func);
          return (!(number && (count == number)));

        }
Exemplo n.º 2
0
        bool Worker::operator() (const Tractography::Streamline<>& in, Tractography::Streamline<>& out) const
        {

          out.clear();
          out.index = in.index;
          out.weight = in.weight;

          if (!thresholds (in)) {
            // Want to test thresholds before wasting time on upsampling; but if -inverse is set,
            //   still need to apply both the upsampler and downsampler before writing to output
            if (inverse) {
              std::vector< Point<float> > tck (in);
              upsampler (tck);
              downsampler (tck);
              tck.swap (out);
            }
            return true;
          }

          // Upsample track before mapping to ROIs
          std::vector< Point<float> > tck (in);
          upsampler (tck);

          // Assign to ROIs
          if (properties.include.size() || properties.exclude.size()) {

            include_visited.assign (properties.include.size(), false);
            for (std::vector< Point<float> >::const_iterator p = tck.begin(); p != tck.end(); ++p) {
              properties.include.contains (*p, include_visited);
              if (properties.exclude.contains (*p)) {
                if (inverse) {
                  downsampler (tck);
                  tck.swap (out);
                }
                return true;
              }
            }

            // Make sure all of the include regions were visited
            for (std::vector<bool>::const_iterator i = include_visited.begin(); i != include_visited.end(); ++i) {
              if (!*i) {
                if (inverse) {
                  downsampler (tck);
                  tck.swap (out);
                }
                return true;
              }
            }

          }

          if (properties.mask.size()) {

            // Split tck into separate tracks based on the mask
            std::vector< std::vector< Point<float> > > cropped_tracks;
            std::vector< Point<float> > temp;

            for (std::vector< Point<float> >::const_iterator p = tck.begin(); p != tck.end(); ++p) {
              const bool contains = properties.mask.contains (*p);
              if (contains == inverse) {
                if (temp.size() >= 2)
                  cropped_tracks.push_back (temp);
                temp.clear();
              } else {
                temp.push_back (*p);
              }
            }
            if (temp.size() >= 2)
              cropped_tracks.push_back (temp);

            if (cropped_tracks.empty())
              return true;

            // Apply downsampler independently to each
            for (std::vector< std::vector< Point<float> > >::iterator i = cropped_tracks.begin(); i != cropped_tracks.end(); ++i)
              downsampler (*i);

            if (cropped_tracks.size() == 1) {
              cropped_tracks[0].swap (out);
              return true;
            }

            // Stitch back together in preparation for sending down queue as a single track
            out.push_back (Point<float>());
            for (std::vector< std::vector< Point<float> > >::const_iterator i = cropped_tracks.begin(); i != cropped_tracks.end(); ++i) {
              for (std::vector< Point<float> >::const_iterator p = i->begin(); p != i->end(); ++p)
                out.push_back (*p);
              out.push_back (Point<float>());
            }
            out.push_back (Point<float>());
            return true;

          } else {

            if (!inverse) {
              downsampler (tck);
              tck.swap (out);
            }
            return true;

          }

        }