Exemple #1
0
void Region2DLine::UpdateStats()
{
  char ch[1000];
  sprintf( ch, "%.2f mm", sqrt(vtkMath::Distance2BetweenPoints( m_dPt1, m_dPt2 )) );
  m_strShortStats = ch;
  m_actorText->SetInput( ch );

  LayerMRI* layer = m_view->GetFirstNonLabelVolume();
  if ( layer )
  {
    double* values = NULL;
    int* indices = NULL;
    int count = 0;
    layer->GetVoxelsOnLine( m_dPt1, m_dPt2, m_view->GetViewPlane(), indices, values, &count );
    char ch[1000];
    m_strsLongStats.clear();
    for ( int i = 0; i < count; i++ )
    {
      sprintf( ch, "[%d, %d, %d]  %.2f", indices[i*3], indices[i*3+1], indices[i*3+2], values[i] );
      m_strsLongStats.push_back( ch );
    }
    delete[] indices;
    delete[] values;
  }

  Region2D::UpdateStats();
}
void Region2DPolyline::UpdateStats()
{
  if ( m_worldPts.size() < 2 )
  {
    return;
  }

  double dist = 0;
  char ch[1000];
  LayerMRI* layer = m_view->GetFirstNonLabelVolume();
  m_strsLongStats.clear();
  if ( m_bSpline )
  {
    vtkSmartPointer<vtkPoints> pts = vtkSmartPointer<vtkPoints>::New();
    for ( size_t i = 0; i < m_worldPts.size(); i++ )
    {
      pts->InsertNextPoint( m_worldPts[i].pos );
    }
    vtkSmartPointer<vtkParametricSpline> spline = vtkSmartPointer<vtkParametricSpline>::New();
    spline->SetPoints( pts );

    int nSteps = 100;
    double* values = NULL;
    int* indices = NULL;
    for ( int i = 0; i < nSteps; i++ )
    {
      double pt1[3], pt2[3], u[3], du[9];
      double uvalue = ((double)i)/nSteps;
      u[0] = u[1] = u[2] = uvalue;
      spline->Evaluate( u, pt1, du );
      uvalue = (i+1.0)/nSteps;
      u[0] = u[1] = u[2] = uvalue;
      spline->Evaluate( u, pt2, du );
      dist += sqrt( vtkMath::Distance2BetweenPoints( pt1, pt2 ) );
      int count = 0;
      if ( layer )
      {
        layer->GetVoxelsOnLine( pt1, pt2, m_view->GetViewPlane(), indices, values, &count );
        for ( int j = 0; j < (i==nSteps-1?count:count-1); j++ )
        {
          sprintf( ch, "[%d, %d, %d]  %.2f", indices[j*3], indices[j*3+1], indices[j*3+2], values[j] );
          m_strsLongStats.push_back( ch );
        }
        delete[] values;
        delete[] indices;
      }
    }
  }
  else
  {
    double* values = NULL;
    int* indices = NULL;
    for ( size_t i = 1; i < m_worldPts.size(); i++ )
    {
      dist += sqrt( vtkMath::Distance2BetweenPoints( m_worldPts[i-1].pos, m_worldPts[i].pos ) );
      int count = 0;
      if ( layer )
      {
        layer->GetVoxelsOnLine( m_worldPts[i-1].pos, m_worldPts[i].pos, m_view->GetViewPlane(), indices, values, &count );
        for ( int j = 0; j < (i==m_worldPts.size()-1?count:count-1); j++ )
        {
          sprintf( ch, "[%d, %d, %d]  %.2f", indices[j*3], indices[j*3+1], indices[j*3+2], values[j] );
          m_strsLongStats.push_back( ch );
        }
        delete[] values;
        delete[] indices;
      }
    }
  }

  sprintf( ch, "%.2f mm", dist );
  m_strShortStats = ch;
  m_actorText->SetInput( ch );

  Region2D::UpdateStats();
}