bool RenderView3D::PickSelectRegion( int nId )
{
  LayerCollection* lc_mri = MainWindow::GetMainWindow()->GetLayerCollection( "MRI" );
  LayerMRI* mri = NULL;
  for ( int i = 0; i < lc_mri->GetNumberOfLayers(); i++ )
  {
    LayerMRI* mri_temp = (LayerMRI*)lc_mri->GetLayer(i);
    if ( mri_temp->GetProperty()->GetShowAsContour() )
    {
      mri = mri_temp;
      break;
    }
  }

  if ( !mri )
  {
    return false;
  }

  SurfaceRegion* reg = mri->SelectSurfaceRegion( nId );
  if ( reg )
  {
    emit SurfaceRegionSelected(reg);
  }
  return true;
}
void DialogTransformVolume::RespondTextTranslate( int n )
{
  if ( isVisible() )
  {
    bool bOK;
    double dvalue =m_textTranslate[n]->text().toDouble(&bOK);
    if ( bOK )
    {
      LayerMRI* layer = ( LayerMRI* )MainWindow::GetMainWindow()->GetActiveLayer( "MRI" );
      if ( layer )
      {
        double pos[3];
        layer->GetTranslate( pos );
        pos[n] = dvalue;
        layer->SetTranslate( pos );
        MainWindow::GetMainWindow()->RequestRedraw();

        double* vs = layer->GetWorldVoxelSize();
        int range = m_scrollTranslate[n]->maximum();
        m_scrollTranslate[n]->blockSignals(true);
        m_scrollTranslate[n]->setValue(range/2 + (int)( pos[n] / vs[n] ) );
        m_scrollTranslate[n]->blockSignals(false);
        UpdateUI( 1 );
      }
    }
  }
}
bool RenderView3D::InitializeSelectRegion( int posX, int posY )
{
  double pos[3];
  vtkProp* prop = this->PickProp( posX, posY, pos );
  if ( !prop )
  {
    return false;
  }

  LayerCollection* lc_mri = MainWindow::GetMainWindow()->GetLayerCollection( "MRI" );
  LayerMRI* mri = NULL;
  for ( int i = 0; i < lc_mri->GetNumberOfLayers(); i++ )
  {
    LayerMRI* mri_temp = (LayerMRI*)lc_mri->GetLayer(i);
    if ( mri_temp->HasProp( prop ) && mri_temp->GetProperty()->GetShowAsContour() )
    {
      mri = mri_temp;
      break;
    }
  }

  if ( !mri )
  {
    return false;
  }

  lc_mri->SetActiveLayer( mri );
  SurfaceRegion* reg = mri->CreateNewSurfaceRegion( pos );
  if ( reg )
  {
    emit SurfaceRegionSelected(reg);
  }
  return true;
}
void DialogTransformVolume::RespondTextRotate( int n )
{
  if ( isVisible() )
  {
    bool bOK;
    double dvalue = m_textAngle[n]->text().toDouble(&bOK);
    if ( bOK )
    {
      LayerMRI* layer = ( LayerMRI* )MainWindow::GetMainWindow()->GetActiveLayer( "MRI" );
      if ( layer )
      {
        double angle[3];
        layer->GetRotate( angle );
        angle[n] = dvalue;
        layer->SetRotate( angle, ui->radioButtonAroundCenter->isChecked() );
        MainWindow::GetMainWindow()->RequestRedraw();

        while (dvalue > 180)
          dvalue -= 360;
        while (dvalue < -180)
          dvalue += 360;

        m_sliderRotate[n]->blockSignals(true);
        m_sliderRotate[n]->setValue( (int)dvalue );
        m_sliderRotate[n]->blockSignals(false);
        UpdateUI( 1 );
      }
    }
  }
}
void DialogTransformVolume::RespondTextScale( int n )
{
  if ( isVisible() )
  {
    bool bOK;
    double dvalue = m_textScale[n]->text().toDouble(&bOK);
    if ( bOK && dvalue > 0 )
    {
      LayerMRI* layer = ( LayerMRI* )MainWindow::GetMainWindow()->GetActiveLayer( "MRI" );
      if ( layer )
      {
        double scale[3];
        layer->GetScale( scale );
        scale[n] = dvalue;
        layer->SetScale( scale );
        MainWindow::GetMainWindow()->RequestRedraw();

        m_scrollScale[n]->blockSignals(true);
        if ( dvalue >= 1 )
        {
          m_scrollScale[n]->setValue( 50 + (int)( (dvalue-1.0)*50 ) );
        }
        else
        {
          m_scrollScale[n]->setValue( 50 - (int)( (1.0-dvalue)*100 ) );
        }
        m_scrollScale[n]->blockSignals(false);
        UpdateUI( 0 );
      }
    }
  }
}
Beispiel #6
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 WindowTimeCourse::OnFrameChanged(int frame)
{
  LayerMRI* layer = qobject_cast<LayerMRI*>(MainWindow::GetMainWindow()->GetActiveLayer("MRI"));
  if (layer && frame != layer->GetActiveFrame() && frame < layer->GetNumberOfFrames())
  {
    layer->SetActiveFrame(frame);
  }
}
void RenderView3D::CloseSelectRegion()
{
  LayerMRI* mri = (LayerMRI*)MainWindow::GetMainWindow()->GetActiveLayer( "MRI" );
  if ( mri )
  {
    mri->CloseSurfaceRegion();
  }
}
void DialogTransformVolume::OnRestore()
{
  LayerMRI* layer = ( LayerMRI* )MainWindow::GetMainWindow()->GetActiveLayer( "MRI" );
  if ( layer )
  {
    layer->Restore();
    UpdateUI();
  }
  LayerLandmarks* landmarks = (LayerLandmarks*)MainWindow::GetMainWindow()->GetSupplementLayer("Landmarks");
  landmarks->Restore();
}
Beispiel #10
0
void RenderView3D::DeleteCurrentSelectRegion()
{
  LayerMRI* mri = (LayerMRI*)MainWindow::GetMainWindow()->GetActiveLayer( "MRI" );
  if ( mri )
  {
    SurfaceRegion* reg = mri->GetCurrentSurfaceRegion();
    if ( mri->DeleteCurrentSurfaceRegion() )
    {
      emit SurfaceRegionRemoved(reg);
    }
  }
}
void DialogTransformVolume::OnSampleMethodChanged()
{
  LayerMRI* layer = (LayerMRI* )MainWindow::GetMainWindow()->GetActiveLayer( "MRI" );
  if (layer)
  {
    int nMethod = SAMPLE_NEAREST;
    if (ui->radioButtonTrilinear->isChecked())
      nMethod = SAMPLE_TRILINEAR;
    else if (ui->radioButtonCubic->isChecked())
      nMethod = SAMPLE_CUBIC_BSPLINE;
    layer->GetProperty()->SetResliceInterpolation(nMethod);
  }
}
Beispiel #12
0
void LayerVolumeBase::SaveBufferItem( UndoRedoBufferItem& item, int nPlane, int nSlice, const char* mask )
{
  item.plane = nPlane;
  item.slice = nSlice;
  if ( nPlane >= 0 )
  {
    int nDim[3], nStart[3] = { 0, 0, 0 };
    m_imageData->GetDimensions( nDim );
    nDim[nPlane] = 1;
    nStart[nPlane] = nSlice;
    int nSize = nDim[0]*nDim[1]*nDim[2]*m_imageData->GetScalarSize();
    item.data = new char[nSize];
    memset( item.data, 0, nSize );
    int n = 0;
    for ( int i = nStart[0]; i < nStart[0] + nDim[0]; i++ )
    {
      for ( int j = nStart[1]; j < nStart[1] + nDim[1]; j++ )
      {
        for ( int k = nStart[2]; k < nStart[2] + nDim[2]; k++ )
        {
          if ( !mask || mask[n] > 0 )
          {
            memcpy( item.data + ( (k-nStart[2])*nDim[1]*nDim[0] + (j-nStart[1])*nDim[0] + (i-nStart[0]) ) * m_imageData->GetScalarSize(),
                    m_imageData->GetScalarPointer( i, j, k ),
                    m_imageData->GetScalarSize() );
          }
          n++;
        }
      }
    }
  }
  else    // save whole volume in cache file
  {
    int nDim[3];
    m_imageData->GetDimensions( nDim );
    int nSize = nDim[0]*nDim[1]*nDim[2]*m_imageData->GetScalarSize();
    QFile file(this->GenerateCacheFileName());
    if (!file.open(QIODevice::WriteOnly))
    {
      return;
    }
    file.write((char*)m_imageData->GetScalarPointer() + nSize*m_nActiveFrame, nSize);
    file.close();
    item.cache_filename = file.fileName();
    if (this->IsTypeOf("MRI"))
    {
      LayerMRI* mri = qobject_cast<LayerMRI*>(this);
      item.mri_settings = mri->GetProperty()->GetSettings();
    }
  }
}
Beispiel #13
0
void LayerVolumeBase::LoadBufferItem( UndoRedoBufferItem& item, bool bIgnoreZeros )
{
  if (item.plane >= 0)
  {
    int nDim[3], nStart[3] = { 0, 0, 0 };
    m_imageData->GetDimensions( nDim );
    nDim[item.plane] = 1;
    nStart[item.plane] = item.slice;
    for ( int i = nStart[0]; i < nStart[0] + nDim[0]; i++ )
    {
      for ( int j = nStart[1]; j < nStart[1] + nDim[1]; j++ )
      {
        for ( int k = nStart[2]; k < nStart[2] + nDim[2]; k++ )
        {
          double dValue = m_imageData->GetScalarComponentAsDouble( i, j, k, 0 );
          memcpy( m_imageData->GetScalarPointer( i, j, k ),
                  item.data + ( (k-nStart[2])*nDim[1]*nDim[0] + (j-nStart[1])*nDim[0] + (i-nStart[0]) ) * m_imageData->GetScalarSize(),
                  m_imageData->GetScalarSize() );
          if ( bIgnoreZeros )
          {
            if ( m_imageData->GetScalarComponentAsDouble( i, j, k, 0 ) == 0 )
            {
              m_imageData->SetScalarComponentFromDouble( i, j, k, 0, dValue );
            }
          }
        }
      }
    }
  }
  else if (!item.cache_filename.isEmpty())
  {
    QFile file(item.cache_filename);
    if (!file.open(QIODevice::ReadOnly))
    {
      return;
    }
    int nDim[3];
    m_imageData->GetDimensions( nDim );
    int nSize = nDim[0]*nDim[1]*nDim[2]*m_imageData->GetScalarSize();
    char* p = (char*)m_imageData->GetScalarPointer() + nSize*m_nActiveFrame;
    file.read(p, nSize);
    file.close();
    if (this->IsTypeOf("MRI"))
    {
      LayerMRI* mri = qobject_cast<LayerMRI*>(this);
      mri->GetProperty()->RestoreSettings(item.mri_settings);
    }
    m_imageData->Modified();
  }
}
Beispiel #14
0
void RenderView3D::AddSelectRegionLoopPoint( int posX, int posY )
{
  LayerMRI* mri = (LayerMRI*)MainWindow::GetMainWindow()->GetActiveLayer( "MRI" );
  if ( mri )
  {
    double pos[3];
    vtkProp* prop = this->PickProp( posX, posY, pos );
    if ( !prop || !mri->HasProp( prop ) )
    {
      return;
    }

    mri->AddSurfaceRegionLoopPoint( pos );
  }
}
void DialogTransformVolume::RespondSliderRotate( int n )
{
  if ( isVisible() )
  {
    LayerMRI* layer = ( LayerMRI* )MainWindow::GetMainWindow()->GetActiveLayer( "MRI" );
    if ( layer )
    {
      double angle[3];
      layer->GetRotate( angle );
      angle[n] = m_sliderRotate[n]->value();
      layer->SetRotate( angle, ui->radioButtonAroundCenter->isChecked() );
      MainWindow::GetMainWindow()->RequestRedraw();
      ChangeLineEditNumber(m_textAngle[n], angle[n] );
      UpdateUI( 1 );
    }
  }
}
void DialogTransformVolume::OnCheckBoxFlip()
{
  if (isVisible())
  {
    LayerMRI* layer = ( LayerMRI* )MainWindow::GetMainWindow()->GetActiveLayer( "MRI" );
    if ( layer )
    {
      bool flip[3];
      layer->GetFlip(flip);
      flip[0] = ui->checkBoxFlipX->isChecked();
      flip[1] = ui->checkBoxFlipY->isChecked();
      flip[2] = ui->checkBoxFlipZ->isChecked();
      layer->SetFlip(flip);
      MainWindow::GetMainWindow()->RequestRedraw();
    }
  }
}
void DialogTransformVolume::OnActiveLayerChanged()
{
  if ( isVisible() )
  {
    UpdateUI();
  }
  LayerMRI* layer = (LayerMRI* )MainWindow::GetMainWindow()->GetActiveLayer( "MRI" );
  if (!layer)
    return;
  connect(layer->GetProperty(), SIGNAL(ColorMapChanged()), this, SLOT(OnActiveLayerChanged()), Qt::UniqueConnection);
  LayerLandmarks* landmarks = (LayerLandmarks*)MainWindow::GetMainWindow()->GetSupplementLayer( "Landmarks" );
  landmarks->SetMRIRef(layer);
  if (layer->GetProperty()->GetColorMap() == LayerPropertyMRI::LUT)
    ui->radioButtonNearestNeighbor->setChecked(true);
  else
    ui->radioButtonCubic->setChecked(true);
  OnSampleMethodChanged();
}
void DialogTransformVolume::RespondScrollTranslate( int n )
{
  if ( isVisible() )
  {
    LayerMRI* layer = ( LayerMRI* )MainWindow::GetMainWindow()->GetActiveLayer( "MRI" );
    if ( layer )
    {
      double pos[3];
      layer->GetTranslate( pos );
      int range = m_scrollTranslate[n]->maximum();
      int npos = m_scrollTranslate[n]->value();
      pos[n] = ( npos - range/2 ) * m_dIncrementTranslate;
      layer->SetTranslate( pos );
      MainWindow::GetMainWindow()->RequestRedraw();
      ChangeLineEditNumber(m_textTranslate[n], pos[n], 2, true);
      UpdateUI( 1 );
    }
  }
}
void DialogRepositionSurface::UpdateIntensity()
{
  LayerMRI* mri = (LayerMRI*)MainWindow::GetMainWindow()->GetTopVisibleLayer("MRI");
  LayerSurface* surf = (LayerSurface*)MainWindow::GetMainWindow()->GetActiveLayer( "Surface" );
  if (mri && surf)
  {
    double ras[3], surf_ras[3];
    mri->GetSlicePosition(ras);
    surf->GetSurfaceRASAtTarget(ras, surf_ras);
    mri->RemapPositionToRealRAS(ras, ras);
    double val = mri->GetSampledVoxelValueByRAS(ras);
    if (val >= 0)
    {
      ui->lineEditTarget->setText(QString::number(val, 'f', 2));
      OnCoordinateTypeChanged();
    }
    ui->lineEditTargetX->setText(QString::number(surf_ras[0], 'f', 2));
    ui->lineEditTargetY->setText(QString::number(surf_ras[1], 'f', 2));
    ui->lineEditTargetZ->setText(QString::number(surf_ras[2], 'f', 2));
  }
}
bool Interactor2DRegionEdit::ProcessMouseMoveEvent( wxMouseEvent& event, RenderView* renderview )
{
  RenderView2D* view = ( RenderView2D* )renderview;

  if ( m_bEditing )
  {
    UpdateCursor( event, view );
    int posX = event.GetX();
    int posY = event.GetY();

    if ( m_nAction == EM_Freehand )
    {
      LayerCollection* lc = MainWindow::GetMainWindowPointer()->GetLayerCollection( "MRI" );
      LayerMRI* mri = ( LayerMRI* )lc->GetActiveLayer();

      double ras1[3], ras2[3];
      view->MousePositionToRAS( m_nMousePosX, m_nMousePosY, ras1 );
      view->MousePositionToRAS( posX, posY, ras2 );

      mri->SetVoxelByRAS( ras1, ras2, view->GetViewPlane(), !event.ShiftDown() );
    }
    else if ( m_nAction == EM_Polyline )
    {
      double ras[3];
      view->MousePositionToRAS( posX, posY, ras );
      view->GetCursor2D()->SetPosition2( ras );
      view->GetCursor2D()->SetPosition( view->GetCursor2D()->GetPosition(), true );
      view->NeedRedraw();
    }

    m_nMousePosX = posX;
    m_nMousePosY = posY;

    return false;
  }
  else
  {
    return Interactor2D::ProcessMouseMoveEvent( event, renderview );
  }
}
void WindowTimeCourse::UpdateData()
{
  LayerMRI* layer = qobject_cast<LayerMRI*>(MainWindow::GetMainWindow()->GetActiveLayer("MRI"));
  if (layer && layer->GetNumberOfFrames() > 1)
  {
    double ras[3];
    int n[3];
    MainWindow::GetMainWindow()->GetLayerCollection("MRI")->GetSlicePosition(ras);
    layer->RemapPositionToRealRAS(ras, ras);
    layer->RASToOriginalIndex(ras, n);
    QList<double> data;
    for (int i = 0; i < layer->GetNumberOfFrames(); i++)
      data <<  layer->GetVoxelValueByOriginalIndex(n[0], n[1], n[2], i);
    FSVolume* vol = layer->GetSourceVolume();
    ui->widgetPlot->SetTimeCourseData(data, vol->GetMinValue(), vol->GetMaxValue(), layer->GetTR());
    ui->widgetPlot->SetCurrentFrame(layer->GetActiveFrame());
  }
}
Beispiel #22
0
void ToolWindowEdit::OnEditContourValue( wxCommandEvent& event )
{
  double value;
  if ( m_editContourValue->GetValue().ToDouble( &value ) && value > 0 )
  {
    BrushProperty* bp = MainWindow::GetMainWindowPointer()->GetBrushProperty();
    LayerMRI* mri = (LayerMRI*)bp->GetReferenceLayer();
    for ( int i = 0; i < 3; i++ )
    {
      RenderView2D* view = ( RenderView2D* )MainWindow::GetMainWindowPointer()->GetRenderView( i );
      Contour2D* c2d = view->GetContour2D();
      if ( c2d->GetInputImage() )
        c2d->SetContourValue( value );
      else if ( mri )
      {
        c2d->SetInput( mri->GetSliceImageData( view->GetViewPlane() ), value, mri->GetSlicePosition()[i], mri->GetActiveFrame() ); 
        c2d->SetVisible( true );
      }
    }
    UpdateTools();
  }
}
void DialogTransformVolume::RespondScrollScale( int n )
{
  LayerMRI* layer = ( LayerMRI* )MainWindow::GetMainWindow()->GetActiveLayer( "MRI" );
  if ( layer )
  {
    double scale[3];
    layer->GetScale( scale );
    int npos = m_scrollScale[n]->value();
    if ( npos >= 50 )
    {
      scale[n] = ( npos - 50 ) / 50.0 + 1.0;
    }
    else
    {
      scale[n] = ( npos - 50 ) / 100.0 + 1.0;
    }
    layer->SetScale( scale );
    MainWindow::GetMainWindow()->RequestRedraw();

    ChangeLineEditNumber( m_textScale[n], scale[n] );
    UpdateUI( 0 );
  }
}
void DialogTransformVolume::OnButtonCenterToCursor()
{
  if ( isVisible() )
  {
    LayerMRI* layer = ( LayerMRI* )MainWindow::GetMainWindow()->GetActiveLayer( "MRI" );
    if ( layer )
    {
      double pos[3];
      layer->GetSlicePosition(pos);
      layer->SetTranslateByCenterPosition( pos );
      MainWindow::GetMainWindow()->RequestRedraw();

      double* vs = layer->GetWorldVoxelSize();
      for (int n = 0; n < 3; n++)
      {
        int range = m_scrollTranslate[n]->maximum();
        m_scrollTranslate[n]->blockSignals(true);
        m_scrollTranslate[n]->setValue(range/2 + (int)( pos[n] / vs[n] ) );
        m_scrollTranslate[n]->blockSignals(false);
      }
      UpdateUI( 0 );
    }
  }
}
bool Interactor3DMeasure::ProcessMouseDownEvent( wxMouseEvent& event, RenderView* renderview )
{
  RenderView3D* view = ( RenderView3D* )renderview;

  bool ret = Interactor3D::ProcessMouseDownEvent( event, renderview );

  if ( m_nAction == MM_SurfaceRegion && !Interactor3D::IsInAction() && event.LeftDown() )
  {
    if ( event.CmdDown() && !event.ShiftDown() )
    {
      if ( view->InitializeSelectRegion( event.GetX(), event.GetY() ) )
      {
        m_bSelectRegion = true;
        return false;   // do not pass down the event
      }
    }
    else if ( event.CmdDown() && event.ShiftDown() )
    {
      LayerMRI* mri = (LayerMRI*)MainWindow::GetMainWindowPointer()->GetActiveLayer( "MRI" );
      if ( mri && mri->GetCurrentSurfaceRegion() )
      {
        mri->GetCurrentSurfaceRegion()->ResetOutline();
        m_bSelectRegion = true;
        return false;
      }
    }
    else if ( !event.CmdDown() && event.ShiftDown() )
    {
      LayerMRI* mri = (LayerMRI*)MainWindow::GetMainWindowPointer()->GetActiveLayer( "MRI" );
      if ( mri && mri->GetCurrentSurfaceRegion() )
      {
        if ( mri->GetCurrentSurfaceRegion()->DeleteCell( view, event.GetX(), event.GetY() ) )
          view->NeedRedraw();
        return false;
      }
    }
  }
   
  return ret;
}
Beispiel #26
0
void ToolWindowEdit::OnActionVoxelContour( wxCommandEvent& event )
{
  MainWindow::GetMainWindowPointer()->SetAction( Interactor2DVoxelEdit::EM_Contour );
  BrushProperty* bp = MainWindow::GetMainWindowPointer()->GetBrushProperty();  
  LayerMRI* layer = (LayerMRI*)MainWindow::GetMainWindowPointer()->GetActiveLayer( "MRI" );
  if ( layer && layer->GetProperties()->GetColorMap() == LayerPropertiesMRI::LUT )
    layer->GetProperties()->SetShowLabelOutline( true );
  
  if ( !bp->GetReferenceLayer() )
  {
    LayerCollection* lc_mri = MainWindow::GetMainWindowPointer()->GetLayerCollection( "MRI" );
    for ( int i = 0; i < lc_mri->GetNumberOfLayers(); i++ )
    {
      LayerMRI* mri = (LayerMRI*)lc_mri->GetLayer( i );
      if ( mri->GetProperties()->GetColorMap() != LayerPropertiesMRI::LUT && mri->IsVisible() && mri != layer )
      {
        bp->SetReferenceLayer( mri );
        break;
      }
    }
  }
  UpdateTools();
}
Beispiel #27
0
void PixelInfoListCtrl::OnFinishEditing( wxCommandEvent& event )
{
  LayerCollectionManager* lcm = MainWindow::GetMainWindowPointer()->GetLayerCollectionManager();
  LayerCollection* lc = MainWindow::GetMainWindowPointer()->GetLayerCollection( "MRI" );

  // see if entered text is valid
  wxArrayString sa = MyUtils::SplitString( m_textEditor->GetValue(), _(",") );
  long ptr = m_listPtr[m_nRowEdited];
  Layer* layer_ptr = (Layer*)ptr;
  if ( ptr == 1 || ( layer_ptr && layer_ptr->IsTypeOf( "MRI" ) ) )
  {
    if ( sa.Count() < 3 )
      sa = MyUtils::SplitString( m_textEditor->GetValue(), _(" ") );

    if ( sa.Count() < 3 )
    {
      cerr << "Invalid coordinate string. Make sure they are three numbers." << endl;
      return;
    }
  }

  if ( ptr == 1 ) // RAS
  {
    double ras[3];
    if ( sa[0].ToDouble( ras ) && sa[1].ToDouble( ras+1 ) && sa[2].ToDouble( ras+2 ) )
    {
      wxListItem item;
      GetColumn( 0, item );
      LayerMRI* layer = (LayerMRI*)lc->GetLayer( 0 );
      if ( layer )
        layer->RASToTarget( ras, ras );
      if ( item.GetText() == _("Cursor") )
      {
        lc->SetCursorRASPosition( ras );
        lcm->SetSlicePosition( ras );
      }
      else if ( item.GetText() == _("Mouse") )
        lc->SetCurrentRASPosition( ras );
      UpdateList();
      m_textEditor->Hide();
    }
    else
    {
      cerr << "Invalid coordinate string. Make sure they are three numbers." << endl;
    }
  }
  else if ( layer_ptr && layer_ptr->IsTypeOf( "MRI" ) ) // voxel
  {
    long x, y, z;
    if ( sa.Count() < 3 )
    {
      cerr << "Invalid voxel coordinate string. Make sure they are three numbers." << endl;
      return;
    }
    int n = sa[0].Find( wxChar('['), true );
    if ( n != wxNOT_FOUND )
      sa[0] = sa[0].Mid( n+1 );
    n = sa[2].Find( wxChar(']') );
    if ( n != wxNOT_FOUND )
      sa[2] = sa[2].Left( n );
    if ( sa[0].ToLong( &x ) && sa[1].ToLong( &y ) && sa[2].ToLong( &z ) )
    {
      int nv[3] = { x, y, z };
      double ras[3];
      wxListItem item;
      GetColumn( 0, item );
      LayerMRI* layer = (LayerMRI*)layer_ptr;
      layer->OriginalIndexToRAS( nv, ras );
      layer->RASToTarget( ras, ras );
      if ( item.GetText() == _("Cursor") )
      {
        lc->SetCursorRASPosition( ras );
        lcm->SetSlicePosition( ras );
      }
      else if ( item.GetText() == _("Mouse") )
        lc->SetCurrentRASPosition( ras );
      UpdateList();
      m_textEditor->Hide();
    }
    else
    {
      cerr << "Invalid voxel coordinate string. Make sure they are three numbers." << endl;
    }
  }  
  else if ( layer_ptr && layer_ptr->IsTypeOf( "Surface" )  ) // surface
  {
    wxString strg = m_textEditor->GetValue();
    LayerSurface* layer = (LayerSurface*)layer_ptr;
    double ras[3];
    bool bSuccess = false;
    if ( m_listValue[m_nRowEdited].Find( _("Coord") ) == 0 )  // coordinate item
    {
      sa = MyUtils::SplitString( strg, _(",") );
      if ( sa.Count() < 3 )
        sa = MyUtils::SplitString( m_textEditor->GetValue(), _(" ") );
      if ( sa.Count() >= 3 && sa[0].ToDouble( ras ) && sa[1].ToDouble( ras+1 ) && sa[2].ToDouble( ras+2 ) )
      {
        layer->GetTargetAtSurfaceRAS( ras, ras );
        bSuccess = true;
      }
    }
    else        // vertex index item
    {
      long nIndex;
      if ( strg.ToLong( &nIndex ) && layer->GetTargetAtVertex( nIndex, ras ) )
        bSuccess = true;
    }
    if ( bSuccess )
    {
      wxListItem item;
      GetColumn( 0, item );
      if ( item.GetText() == _("Cursor") )
      {
        lc->SetCursorRASPosition( ras );
        lcm->SetSlicePosition( ras );
      }
      else if ( item.GetText() == _("Mouse") )
        lc->SetCurrentRASPosition( ras );
          
      UpdateList();
      m_textEditor->Hide();
    }
    else
      cerr << "Invalid index or coordinate string." << endl;
  }
}
Beispiel #28
0
void PixelInfoListCtrl::DoUpdateList()
{
  Reset();

  LayerCollection* lc_mri = MainWindow::GetMainWindowPointer()->GetLayerCollection( "MRI" );
  LayerCollection* lc_surf = MainWindow::GetMainWindowPointer()->GetLayerCollection( "Surface" );
  if ( !lc_mri || !lc_surf )
  {
    // collection does not exist. program must be in exiting process.
    return;
  }
  if ( lc_mri->IsEmpty() && lc_surf->IsEmpty() )
  {
    SetItemCount( 0 );
    return;
  }
  else
    AddItem( _("RAS"), _(""), 1, false );
  
  if ( !lc_mri->IsEmpty() )
  {
    LayerMRI* mri = ( LayerMRI* )lc_mri->GetLayer( 0 );
    double ras[3];
    mri->RemapPositionToRealRAS( m_dRASPosition, ras );
    m_listValue[0].Printf( _("%.2f, %.2f, %.2f"), ras[0], ras[1], ras[2] );

    int nIndex[3];
    std::vector<Layer*> layers = lc_mri->GetLayers();
    for ( size_t i = 0; i < layers.size(); i++ )
    {      
      if ( layers[i]->GetProperties()->GetShowInfo() )
      {
        ((LayerMRI*)layers[i])->RASToOriginalIndex( ras, nIndex );
  //      double dvalue = ( (LayerMRI*)layers[i] )->GetVoxelValueByOriginalIndex( nIndex[0], nIndex[1], nIndex[2] );
        double dvalue = ( (LayerMRI*)layers[i] )->GetVoxelValue( m_dRASPosition );  
        wxString coordStrg;
        if ( m_bShowVoxelCoordinates )
          coordStrg.Printf( _("[%d, %d, %d] "), nIndex[0], nIndex[1], nIndex[2] );
        
        wxString labelStrg;
        if (layers[i]->IsTypeOf("PLabel"))
        {
          labelStrg = wxString::FromAscii( ( (LayerPLabel*)layers[i] )->GetLabelName( m_dRASPosition ).c_str() );
        }
        else
        {
          labelStrg = wxString::FromAscii( ( (LayerMRI*)layers[i] )->GetLabelName( dvalue ).c_str() );
          if ( m_bShowShortName )
            labelStrg = GetShortName( labelStrg );
        }
        
        AddItem( wxString::FromAscii( layers[i]->GetName() ),
                AppendSpaceString( ( wxString() << dvalue ) ) + coordStrg + _("  ") + labelStrg,
                (long)layers[i],
                false );
      }
    }
  }
  if ( !lc_surf->IsEmpty() )
  {
    if ( lc_mri->IsEmpty() )
    {
      double ras[3] = { m_dRASPosition[0], m_dRASPosition[1], m_dRASPosition[2] };
      // mri->RemapPositionToRealRAS( m_dRASPosition, ras );
      m_listValue[0].Printf( _("%.2f, %.2f, %.2f"), ras[0], ras[1], ras[2] );
    }

    std::vector<Layer*> layers = lc_surf->GetLayers();
    for ( size_t i = 0; i < layers.size(); i++ )
    {
      if ( layers[i]->GetProperties()->GetShowInfo() )
      {
        LayerSurface* surf = ( LayerSurface* )layers[i];
        AddSurfaceItem( surf, m_dRASPosition, false );
      }
    }
  }

  SetItemCount( m_listName.Count() );
}
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();
}
void Region2DPolyline::Update()
{
  if ( !m_actorPolyline->GetVisibility() || m_worldPts.size() < 2 )
  {
    return;
  }

  double pt[3];
  vtkSmartPointer<vtkPoints> pts = vtkSmartPointer<vtkPoints>::New();
  vtkSmartPointer<vtkCellArray> lines = vtkSmartPointer<vtkCellArray>::New();
  lines->InsertNextCell( m_worldPts.size() );
  for ( size_t i = 0; i < m_worldPts.size(); i++ )
  {
    m_view->WorldToViewport( m_worldPts[i].pos[0], m_worldPts[i].pos[1], m_worldPts[i].pos[2], pt[0], pt[1], pt[2] );
    pts->InsertNextPoint( pt );
    lines->InsertCellPoint( i );
  }

  vtkSmartPointer<vtkPolyData> polydata = vtkSmartPointer<vtkPolyData>::New();
  polydata->SetPoints( pts );
  polydata->SetLines( lines );
  vtkSmartPointer<vtkPolyDataMapper2D> mapper = vtkSmartPointer<vtkPolyDataMapper2D>::New();
  if ( !m_bSpline )
  {
    mapper->SetInput( polydata );
  }
  else
  {
    vtkSmartPointer<vtkSplineFilter> spline = vtkSmartPointer<vtkSplineFilter>::New();
    spline->SetInput( polydata );
    LayerMRI* layer = m_view->GetFirstNonLabelVolume();
    if ( layer )
    {
      spline->SetSubdivideToLength();
      spline->SetLength( 3*layer->GetMinimumVoxelSize() );
    }
    spline->Update();
    mapper->SetInputConnection( spline->GetOutputPort() );
  }

  vtkSmartPointer<vtkCoordinate> coords = vtkSmartPointer<vtkCoordinate>::New();
  coords->SetCoordinateSystemToViewport();
  mapper->SetTransformCoordinate( coords );
  m_actorPolyline->SetMapper( mapper );

  vtkSmartPointer<vtkPolyData> polydata2 = vtkSmartPointer<vtkPolyData>::New();
  polydata2->SetPoints( pts );
  vtkSmartPointer<vtkCellArray> verts = vtkSmartPointer<vtkCellArray>::New();
  verts->Allocate( pts->GetNumberOfPoints() );
  for ( int i = 0; i < pts->GetNumberOfPoints(); i++ )
  {
    vtkIdType n = i;
    verts->InsertNextCell( 1, &n );
  }
  polydata2->SetVerts( verts );
  mapper = vtkSmartPointer<vtkPolyDataMapper2D>::New();
  mapper->SetInput( polydata2 );
  mapper->SetTransformCoordinate( coords );
  m_actorPoints->SetMapper( mapper );

//  m_actorText->SetInput( GetShortStats().c_str() );
//  double mid_pt[3];
  m_actorText->SetPosition( pts->GetPoint( 0 ) );
  UpdateStats();
}