Пример #1
0
    void GLWidget::paintGL(){

        glClear(GL_COLOR_BUFFER_BIT | GL_STENCIL_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
        glPushMatrix();
        glMatrixMode(GL_MODELVIEW) ;
        glLoadIdentity ();             /* clear the matrix */

        gluLookAt(0.0, 0.0, volRenderer.projector.vSourceLocation.VectorZ, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);

        volRenderer.RenderVolImage() ;			// render the volume image

        glClear(GL_DEPTH_BUFFER_BIT) ;			// so that this volume image does not block other objects
                                                // Since we have enabled depth test
        glRotatef(anglex,1.0,0.0,0.0) ;
        glRotatef(angley,0.0,1.0,0.0) ;
        glRotatef(anglez,0.0,0.0,1.0) ;

        double boxLenX = volRenderer.params.CtFileVoxelSpacing.VectorX ;
        double boxLenY = volRenderer.params.CtFileVoxelSpacing.VectorY ;
        double boxLenZ = volRenderer.params.CtFileVoxelSpacing.VectorZ ;

        DrawAxisAndBox(boxLenX, boxLenY, boxLenZ) ;						// draw axis and bounding box

        // get the volume center in the coordinate center
        float tz = (slices)*boxLenZ/2 ;
        float ty = (rows)*boxLenY/2 ;
        float tx = (cols)*boxLenX/2 ;

        glTranslatef(-tx, -ty, -tz) ;

        if(streamlines.bVisible){
            streamlines.RenderStreamlines(eigenfloats) ;		// display streamlines
        }
        if(vectorField.bVisible){
            if(shift)
                vectorField.RenderSlice();
            else
                vectorField.drawQuadric() ;	// draw vector field
        }

        if(magnifying){
            Magnify();
//            glutSetCursor(GLUT_CURSOR_NONE);
        }
//        else
//            glutSetCursor(GLUT_CURSOR_TOP_LEFT_CORNER);

        glPopMatrix();

        swapBuffers();
//        glutSwapBuffers() ;

  //      paintGL();

    }
Пример #2
0
    void GLWidget::mouseMoveEvent(QMouseEvent *event){

        mouseMotion(event->pos().x(), event->y());

        if( CurrIM == ExploreMode){
            if(LeftButtonDown == 1 ){				// rotate the volume
                MouseMoveToRotate(event->x()-buttonDownX, event->y()-buttonDownY) ;
                buttonDownX = event->x() ;
                buttonDownY = event->y() ;
            }
            else if( RightButtonDown == 1){			// move the camera, zoom in or out
                MouseMoveToZoom(event->x()-buttonDownX, event->y()-buttonDownY) ;
                buttonDownX = event->x() ;
                buttonDownY = event->y() ;
            }
        } //if( InteractionMode == ExploreMode)
        else if( CurrIM == SelectMode){
            if(LeftButtonDown == 1 ){				// temporary streamline selection or seedpoint move
                if( streamlines.bSeedpointSelected && iSeedpointMoveDir != -1 ){// seedpoint was already selected
                    MouseMoveToSeedpointMove(event->x()-buttonDownX, event->y()-buttonDownY) ;
                    buttonDownX = event->x() ;
                    buttonDownY = event->y() ;
                    updateGL();
                }
                else{
                    SelectObjectAtXY(event->x(), event->y());
                    switch(ObjectCatagory){
                        case STREAMLINE:
                            //printf("ObjectName %d\n",iObjectName) ;
                            streamlines.bSeedpointSelected = false ;
                            streamlines.TemporarySelectedStreamline(iObjectName) ;
                            updateGL();
                            break ;
                        case SEEDPOINT:
                            if(!streamlines.bSeedpointSelected){		// user just moved in to seed point
                                buttonDownX = event->x() ;
                                buttonDownY = event->y() ;
                                streamlines.bSeedpointSelected = true ;
                                updateGL();
                            }
                            break ;
                        case NO_OBJECT:
                            streamlines.TempSelectedStreamline = -1 ;
                            streamlines.bSeedpointSelected = false ;
                            updateGL();
                            break ;
                        default:
                            printf("Unidentified object.\n") ;
                            break ;
                    }  //switch(iObjectCatagory){
                } // else
            } //if(LeftButtonDown == 1 ){
        } //else if( CurrIM == SelectMode){
    }
Пример #3
0
        bool FixedNumPoints::operator() (const Streamline<>& in, Streamline<>& out) const
        {
          // Perform an explicit calculation of streamline length
          // From this, derive the spline position of each sample
          assert (in.size() > 1);
          out.clear();
          out.index = in.index;
          out.weight = in.weight;
          value_type length = 0.0;
          vector<value_type> steps;
          for (size_t i = 1; i != in.size(); ++i) {
            const value_type dist = (in[i] - in[i-1]).norm();
            length += dist;
            steps.push_back (dist);
          }
          steps.push_back (value_type(0));

          Math::Hermite<value_type> interp (hermite_tension);
          Streamline<> temp (in);
          const size_t s = temp.size();
          temp.insert    (temp.begin(), temp[0] + (temp[0] - temp[ 1 ]));
          temp.push_back (              temp[s] + (temp[s] - temp[s-1]));

          value_type cumulative_length = value_type(0);
          size_t input_index = 0;
          for (size_t output_index = 0; output_index != num_points; ++output_index) {
            const value_type target_length = length * output_index / value_type(num_points-1);
            while (input_index < s && (cumulative_length + steps[input_index] < target_length))
              cumulative_length += steps[input_index++];
            if (input_index == s) {
              out.push_back (temp[s]);
              break;
            }
            const value_type mu = (target_length - cumulative_length) / steps[input_index];
            interp.set (mu);
            out.push_back (interp.value (temp[input_index], temp[input_index+1], temp[input_index+2], temp[input_index+3]));
          }

          return true;
        }
Пример #4
0
    void GLWidget::SelectObjectAtXY(int x, int y){
        GLint hits;
        GLint viewport[4];
        glGetIntegerv (GL_VIEWPORT, viewport);
        GLuint selectBuf[BUFSIZE];

        glSelectBuffer (BUFSIZE, selectBuf);
        (void) glRenderMode (GL_SELECT);

        glInitNames();									// initializing the name stack

        glMatrixMode (GL_PROJECTION);
        glPushMatrix ();
        glLoadIdentity ();
                /*  create 5x5 pixel picking region near cursor location	*/
        gluPickMatrix ((GLdouble) x, (GLdouble) (viewport[3] - y),
                      5.0, 5.0, viewport);

        glMatrixMode (GL_MODELVIEW);
        glPushName(STREAMLINE);							// signature of a streamline
        streamlines.SelectModeStreamlinesDraw() ;
        glPopName() ;									// pop streamline signature

        glPushName(SEEDPOINT);							// signature of a seedpoint
        streamlines.SelectModeSeedPointDraw() ;
        glPopName() ;									// pop seedpoint signature

        glMatrixMode (GL_PROJECTION);
        glPopMatrix ();
        //glFlush ();

        hits = glRenderMode (GL_RENDER);
        if( hits > 0 )
            processHits (hits, selectBuf);
        else{		// no hit
            ObjectCatagory = NO_OBJECT ;
        }
    }
Пример #5
0
void run ()
{

  const bool weights_provided = get_options ("tck_weights_in").size();

  float step_size = NaN;
  size_t count = 0, header_count = 0;
  float min_length = std::numeric_limits<float>::infinity();
  float max_length = 0.0f;
  double sum_lengths = 0.0, sum_weights = 0.0;
  std::vector<double> histogram;
  std::vector<LW> all_lengths;
  all_lengths.reserve (header_count);

  {
    Tractography::Properties properties;
    Tractography::Reader<float> reader (argument[0], properties);

    if (properties.find ("count") != properties.end())
      header_count = to<size_t> (properties["count"]);

    if (properties.find ("output_step_size") != properties.end())
      step_size = to<float> (properties["output_step_size"]);
    else
      step_size = to<float> (properties["step_size"]);
    if (!std::isfinite (step_size) || !step_size) {
      WARN ("Streamline step size undefined in header");
      if (get_options ("histogram").size())
        WARN ("Histogram will be henerated using a 1mm interval");
    }

    std::unique_ptr<File::OFStream> dump;
    auto opt = get_options ("dump");
    if (opt.size())
      dump.reset (new File::OFStream (std::string(opt[0][0]), std::ios_base::out | std::ios_base::trunc));

    ProgressBar progress ("Reading track file", header_count);
    Streamline<> tck;
    while (reader (tck)) {
      ++count;
      const float length = std::isfinite (step_size) ? tck.calc_length (step_size) : tck.calc_length();
      if (std::isfinite (length)) {
        min_length = std::min (min_length, length);
        max_length = std::max (max_length, length);
        sum_lengths += tck.weight * length;
        sum_weights += tck.weight;
        all_lengths.push_back (LW (length, tck.weight));
        const size_t index = std::isfinite (step_size) ? std::round (length / step_size) : std::round (length);
        while (histogram.size() <= index)
          histogram.push_back (0.0);
        histogram[index] += tck.weight;
      }
      if (dump)
        (*dump) << length << "\n";
      ++progress;
    }
  }

  if (histogram.front())
    WARN ("read " + str(histogram.front()) + " zero-length tracks");
  if (count != header_count)
    WARN ("expected " + str(header_count) + " tracks according to header; read " + str(count));

  const float mean_length = sum_lengths / sum_weights;

  float median_length = 0.0f;
  if (weights_provided) {
    // Perform a weighted median calculation
    std::sort (all_lengths.begin(), all_lengths.end());
    size_t median_index = 0;
    double sum = sum_weights - all_lengths[0].get_weight();
    while (sum > 0.5 * sum_weights) { sum -= all_lengths[++median_index].get_weight(); }
    median_length = all_lengths[median_index].get_length();
  } else {
    median_length = Math::median (all_lengths).get_length();
  }

  double stdev = 0.0;
  for (std::vector<LW>::const_iterator i = all_lengths.begin(); i != all_lengths.end(); ++i)
    stdev += i->get_weight() * Math::pow2 (i->get_length() - mean_length);
  stdev = std::sqrt (stdev / (((count - 1) / float(count)) * sum_weights));

  const size_t width = 12;

  std::cout << " " << std::setw(width) << std::right << "mean"
            << " " << std::setw(width) << std::right << "median"
            << " " << std::setw(width) << std::right << "std. dev."
            << " " << std::setw(width) << std::right << "min"
            << " " << std::setw(width) << std::right << "max"
            << " " << std::setw(width) << std::right << "count\n";

  std::cout << " " << std::setw(width) << std::right << (mean_length)
            << " " << std::setw(width) << std::right << (median_length)
            << " " << std::setw(width) << std::right << (stdev)
            << " " << std::setw(width) << std::right << (min_length)
            << " " << std::setw(width) << std::right << (max_length)
            << " " << std::setw(width) << std::right << (count) << "\n";

  auto opt = get_options ("histogram");
  if (opt.size()) {
    File::OFStream out (opt[0][0], std::ios_base::out | std::ios_base::trunc);
    if (!std::isfinite (step_size))
      step_size = 1.0f;
    if (weights_provided) {
      out << "Length,Sum_weights\n";
      for (size_t i = 0; i != histogram.size(); ++i)
        out << str(i * step_size) << "," << str(histogram[i]) << "\n";
    } else {
      out << "Length,Count\n";
      for (size_t i = 0; i != histogram.size(); ++i)
        out << str(i * step_size) << "," << str<size_t>(histogram[i]) << "\n";
    }
    out << "\n";
  }

}
Пример #6
0
        bool Worker::operator() (Streamline<>& in, Streamline<>& out) const
        {

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

          if (!thresholds (in)) {
            // Want to test thresholds before wasting time on resampling
            if (inverse)
              in.swap (out);
            return true;
          }

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

            include_visited.assign (properties.include.size(), false);

            if (ends_only) {
              for (size_t i = 0; i != 2; ++i) {
                const Eigen::Vector3f& p (i ? in.back() : in.front());
                properties.include.contains (p, include_visited);
                if (properties.exclude.contains (p)) {
                  if (inverse)
                    in.swap (out);
                  return true;
                }
              }
            } else {
              for (const auto& p : in) {
                properties.include.contains (p, include_visited);
                if (properties.exclude.contains (p)) {
                  if (inverse)
                    in.swap (out);
                  return true;
                }
              }
            }

            // Make sure all of the include regions were visited
            for (const auto& i : include_visited) {
              if (!i) {
                if (inverse)
                  in.swap (out);
                return true;
              }
            }

          }

          if (properties.mask.size()) {

            // Split tck into separate tracks based on the mask
            vector<vector<Eigen::Vector3f>> cropped_tracks;
            vector<Eigen::Vector3f> temp;

            for (const auto& p : in) {
              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;

            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 ({ NaN, NaN, NaN });
            for (const auto& i : cropped_tracks) {
              for (const auto& p : i)
                out.push_back (p);
              out.push_back ({ NaN, NaN, NaN });
            }
            return true;

          } else {

            if (!inverse)
              in.swap (out);
            return true;

          }

        }
Пример #7
0
    // the mouse callback
    void GLWidget::mousePressEvent(QMouseEvent *event){

        if( CurrIM == ExploreMode ){				// xplore mode mouse interaction
            if (event->buttons() ) {
                 if (Qt::LeftButton){
                      LeftButtonDown = 1 ;
                      buttonDownX = event->x() ;
                      buttonDownY = event->y() ;
                 }

                 else if(Qt::RightButton){
                      RightButtonDown = 1 ;
                      buttonDownX = event->x() ;
                      buttonDownY = event->y() ;
                }
            } //if (state == GLUT_DOWN )
            else if( event->buttons() ){
                LeftButtonDown = RightButtonDown = 0 ;
                volRenderer.SetProjectionResolution(false, false) ;
                updateGL() ;
            }
        } //if( CurrIM == ExploreMode )
        else if(CurrIM == SelectMode ){
            if (event->buttons() ) {
                if( Qt::RightButton){
                        LeftButtonDown = 1 ;
                        SelectObjectAtXY(event->x(), event->y());
                        switch(ObjectCatagory){
                            case STREAMLINE:
                                streamlines.TemporarySelectedStreamline(iObjectName);
                                updateGL() ;
                                break ;
                            case SEEDPOINT:
                            buttonDownX = event->x ();
                            buttonDownY = event->y() ;
                                streamlines.bSeedpointSelected = true ;
                                updateGL() ;
                                break ;
                            case NO_OBJECT:
                                break;
                            default:
                                printf("Unidentified object.\n") ;
                                break ;
                        }//switch(iObjectCatagory){
            }
            } //if (state == GLUT_DOWN )
            else if( event->buttons() ){
                LeftButtonDown = RightButtonDown = 0 ;
                //clear if any streamline was temporarily selected
                streamlines.TempSelectedStreamline = -1 ;
                switch(ObjectCatagory){
                    case STREAMLINE:
                        streamlines.UpdateStreamlineStatus(iObjectName) ;
                        updateGL() ;
                        break ;
                    case SEEDPOINT:
                        if( streamlines.bSeedpointMoved )
                            streamlines.UpdateSeedPoint() ;
                        streamlines.bSeedpointMoved = false ;
                        streamlines.bSeedpointSelected = false ;
                        ObjectCatagory = NO_OBJECT ;
                        iSeedpointMoveDir = -1 ;
                        updateGL() ;
                        break ;
                    case NO_OBJECT:
                        break ;
                }//switch(ObjectCatagory){
            }//else if( state == GLUT_UP )
            else{
                LeftButtonDown = RightButtonDown = 0 ;
            }
        } //else if(CurrIM == SelectMode )
    }