Пример #1
0
void RenderView3D::UpdateSliceFrames()
{
  MainWindow* mainwnd = MainWindow::GetMainWindow();
  LayerCollection* lc = mainwnd->GetLayerCollection( "MRI" );
  if ( lc->IsEmpty() )
  {
    lc = mainwnd->GetLayerCollection( "Surface" );
  }
  double* bounds = m_dBounds;
  double* slicepos = lc->GetSlicePosition();

  vtkSmartPointer<vtkPoints> points = vtkSmartPointer<vtkPoints>::New();
  vtkSmartPointer<vtkCellArray> lines = vtkSmartPointer<vtkCellArray>::New();
  points->InsertPoint( 0, slicepos[0], bounds[2], bounds[4] );
  points->InsertPoint( 1, slicepos[0], bounds[2], bounds[5] );
  points->InsertPoint( 2, slicepos[0], bounds[3], bounds[5] );
  points->InsertPoint( 3, slicepos[0], bounds[3], bounds[4] );
  vtkIdType ids[5] = { 0, 1, 2, 3, 0 };
  lines->InsertNextCell( 5, ids );
  vtkSmartPointer<vtkPolyData> polydata = vtkSmartPointer<vtkPolyData>::New();
  polydata->SetPoints( points );
  polydata->SetLines( lines );
  vtkPolyDataMapper::SafeDownCast(m_actorSliceFrames[0]->GetMapper())->SetInput( polydata );

  points = vtkSmartPointer<vtkPoints>::New();
  points->InsertPoint( 0, bounds[0], slicepos[1], bounds[4] );
  points->InsertPoint( 1, bounds[0], slicepos[1], bounds[5] );
  points->InsertPoint( 2, bounds[1], slicepos[1], bounds[5] );
  points->InsertPoint( 3, bounds[1], slicepos[1], bounds[4] );
  polydata = vtkSmartPointer<vtkPolyData>::New();
  polydata->SetPoints( points );
  polydata->SetLines( lines );
  vtkPolyDataMapper::SafeDownCast(m_actorSliceFrames[1]->GetMapper())->SetInput( polydata );

  points = vtkSmartPointer<vtkPoints>::New();
  points->InsertPoint( 0, bounds[0], bounds[2], slicepos[2] );
  points->InsertPoint( 1, bounds[0], bounds[3], slicepos[2] );
  points->InsertPoint( 2, bounds[1], bounds[3], slicepos[2] );
  points->InsertPoint( 3, bounds[1], bounds[2], slicepos[2] );
  polydata = vtkSmartPointer<vtkPolyData>::New();
  polydata->SetPoints( points );
  polydata->SetLines( lines );
  vtkPolyDataMapper::SafeDownCast(m_actorSliceFrames[2]->GetMapper())->SetInput( polydata );

  for ( int i = 0; i < 3; i++ )
  {
    double bds[6];
    for ( int n = 0; n < 3; n++ )
    {
      bds[n*2]   = m_dBounds[n*2] - m_dBoundingTolerance;
      bds[n*2+1] = m_dBounds[n*2+1] + m_dBoundingTolerance;
    }

    bds[i*2] = slicepos[i] - m_dBoundingTolerance;
    bds[i*2+1] = slicepos[i] + m_dBoundingTolerance;
    m_cubeSliceBoundingBox[i]->SetBounds( bds );
    m_actorSliceBoundingBox[i]->GetMapper()->Update();
  }
  RequestRedraw();
}
bool Interactor2DVolumeEdit::ProcessMouseUpEvent( QMouseEvent* event, RenderView* renderview )
{
// RenderView2D* view = ( RenderView2D* )renderview;
  UpdateCursor( event, renderview );

  if ( m_bEditing )
  {
    m_nMousePosX = event->x();
    m_nMousePosY = event->y();

    if ( event->button() != Qt::LeftButton ||
         (m_nAction != EM_Polyline && m_nAction != EM_Livewire ) ||
         m_dPolylinePoints.size() == 0 )
    {
      m_bEditing = false;
    }

    LayerCollection* lc = MainWindow::GetMainWindow()->GetLayerCollection( m_strLayerTypeName );
    LayerVolumeBase* mri = ( LayerVolumeBase* )lc->GetActiveLayer();
//   mri->SendBroadcast( "LayerEdited", mri );

    return false;
  }
  else
  {
    return Interactor2D::ProcessMouseUpEvent( event, renderview );
  }
}
Пример #3
0
void RenderView3D::OnSlicePositionChanged()
{
  LayerCollection* lc = MainWindow::GetMainWindow()->GetLayerCollection( "MRI" );
  m_cursor3D->SetPosition( lc->GetSlicePosition() );
  UpdateSliceFrames();
  UpdateSurfaceCorrelationData();

  RenderView::OnSlicePositionChanged();
}
Пример #4
0
void PanelSurface::OnLayerSelectionChanged( wxCommandEvent& event )
{
  if ( m_listBoxLayers->GetSelection() != wxNOT_FOUND )
  {
    LayerCollection* lc = MainWindow::GetMainWindowPointer()->GetLayerCollection( "Surface" );
    lc->SetActiveLayer( ( Layer* )m_listBoxLayers->GetClientData( m_listBoxLayers->GetSelection() ) );
  }
  UpdateUI();
}
Пример #5
0
bool RenderView3D::UpdateBounds()
{
  MainWindow* mainwnd = MainWindow::GetMainWindow();
  double bounds[6] = { 1000000, -1000000, 1000000, -1000000, 1000000, -1000000 };
  for ( int n = 0; n < 1; n++ )
  {
    LayerCollection* lc = mainwnd->GetLayerCollection( (n == 0 ? "MRI" : "Surface") );
    for ( int i = 0; i < lc->GetNumberOfLayers(); i++ )
    {
      double bd[6];
      lc->GetLayer( i )->GetDisplayBounds( bd );
      for ( int j = 0; j < 3; j++ )
      {
        if ( bounds[j*2] > bd[j*2] )
        {
          bounds[j*2] = bd[j*2];
        }
        if ( bounds[j*2+1] < bd[j*2+1] )
        {
          bounds[j*2+1] = bd[j*2+1];
        }
      }
    }
  }
  for ( int i = 0; i < 6; i++ )
  {
    m_dBounds[i] = bounds[i];
  }

  double dMaxLength = 0;
  for ( int i = 0; i < 3; i++ )
  {
    if ( dMaxLength < ( bounds[i*2+1]-bounds[i*2] ) )
    {
      dMaxLength = bounds[i*2+1]-bounds[i*2];
    }
  }

  m_dBoundingTolerance = dMaxLength * 0.02;
  UpdateSliceFrames();
  if (dMaxLength > 0)
    m_cursor3D->RebuildActor(dMaxLength/256);

  // update axis
  m_actorAxesActor->SetBounds(m_dBounds);

  return true;
}
Пример #6
0
void PanelSurface::UpdateLayerList( Layer* layer )
{
  LayerCollection* lc = MainWindow::GetMainWindowPointer()->GetLayerCollection( "Surface" );
  int nIndex = lc->GetLayerIndex( layer );
  std::vector<Layer*> layers = lc->GetLayers();
  if ( nIndex != -1 )
  {
    m_listBoxLayers->Clear();
    int nSel = 0;
    for ( size_t i = 0; i < layers.size(); i++ )
    {
      m_listBoxLayers->Append( wxString::FromAscii( layers[i]->GetName() ), layers[i] );
      m_listBoxLayers->Check( i, layers[i]->IsVisible() );
      if ( lc->GetActiveLayer() == layers[i] )
        nSel = i;
    }
    m_listBoxLayers->SetSelection( nSel );

    UpdateUI();
  }
}
Пример #7
0
void PanelSurface::OnSurfaceClose( wxCommandEvent& event )
{
  LayerCollection* lc = MainWindow::GetMainWindowPointer()->GetLayerCollection( "Surface" );
  int nSel = m_listBoxLayers->GetSelection();
  if ( lc && nSel != wxNOT_FOUND )
  {
    Layer* layer = ( Layer* )( void* )m_listBoxLayers->GetClientData( nSel );    

    m_listBoxLayers->Delete( nSel );   

    if ( (int)m_listBoxLayers->GetCount() > nSel )
      m_listBoxLayers->SetSelection( nSel );
    else if ( nSel >= 1 )
      m_listBoxLayers->SetSelection( nSel - 1 );        

    if ( layer )
      lc->RemoveLayer( layer );

    UpdateUI();
  }
}
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 );
  }
}
bool Interactor2DVolumeEdit::ProcessMouseUpEvent( wxMouseEvent& event, RenderView* renderview )
{
// RenderView2D* view = ( RenderView2D* )renderview;
  UpdateCursor( event, renderview );

  if ( m_bEditing )
  {
    m_nMousePosX = event.GetX();
    m_nMousePosY = event.GetY();

    if ( !event.LeftUp() || (m_nAction != EM_Polyline && m_nAction != EM_Livewire )|| m_dPolylinePoints.size() == 0 )
      m_bEditing = false;

    LayerCollection* lc = MainWindow::GetMainWindowPointer()->GetLayerCollection( m_strLayerTypeName.c_str() );
    LayerVolumeBase* mri = ( LayerVolumeBase* )lc->GetActiveLayer();
    mri->SendBroadcast( "LayerEdited", mri );

    return false;
  }
  else
  {
    return Interactor2D::ProcessMouseUpEvent( event, renderview );
  }
}
Пример #10
0
void RenderView3D::MoveSliceToScreenCoord( int x, int y )
{
  if ( m_nSliceHighlighted < 0 )
  {
    return;
  }

  MainWindow* mainwnd = MainWindow::GetMainWindow();
  LayerCollection* lc = mainwnd->GetLayerCollection( "MRI" );
  if ( lc->IsEmpty() )
  {
    lc = mainwnd->GetLayerCollection( "Surface" );
  }
  double* bounds = m_dBounds;
  double slicepos[3];
  lc->GetSlicePosition( slicepos );
  double pt[3];
  pt[0] = m_dIntersectPoint[0];
  pt[1] = m_dIntersectPoint[1];
  pt[2] = m_dIntersectPoint[2];

  double v[3] = { 0, 0, 0 };
  switch ( m_nSliceHighlighted )
  {
  case 0:
    if ( qMin( fabs( pt[1] - bounds[2] ), fabs( pt[1] - bounds[3] ) ) <
         qMin( fabs( pt[2] - bounds[4] ), fabs( pt[2] - bounds[5] ) ) )
    {
      v[1] = 1;
      if ( fabs( pt[1] - bounds[2] ) < fabs( pt[1] - bounds[3] ) )
      {
        pt[1] = bounds[2];
      }
      else
      {
        pt[1] = bounds[3];
      }
    }
    else
    {
      v[2] = 1;
      if ( fabs( pt[2] - bounds[4] ) < fabs( pt[2] - bounds[5] ) )
      {
        pt[2] = bounds[4];
      }
      else
      {
        pt[2] = bounds[5];
      }
    }
    break;
  case 1:
    if ( qMin( fabs( pt[0] - bounds[0] ), fabs( pt[0] - bounds[1] ) ) <
         qMin( fabs( pt[2] - bounds[4] ), fabs( pt[2] - bounds[5] ) ) )
    {
      v[0] = 1;
      if ( fabs( pt[0] - bounds[0] ) < fabs( pt[0] - bounds[1] ) )
      {
        pt[0] = bounds[0];
      }
      else
      {
        pt[0] = bounds[1];
      }
    }
    else
    {
      v[2] = 1;
      if ( fabs( pt[2] - bounds[4] ) < fabs( pt[2] - bounds[5] ) )
      {
        pt[2] = bounds[4];
      }
      else
      {
        pt[2] = bounds[5];
      }
    }
    break;
  case 2:
    if ( qMin( fabs( pt[0] - bounds[0] ), fabs( pt[0] - bounds[1] ) ) <
         qMin( fabs( pt[1] - bounds[2] ), fabs( pt[1] - bounds[3] ) ) )
    {
      v[0] = 1;
      if ( fabs( pt[0] - bounds[0] ) < fabs( pt[0] - bounds[1] ) )
      {
        pt[0] = bounds[0];
      }
      else
      {
        pt[0] = bounds[1];
      }
    }
    else
    {
      v[1] = 1;
      if ( fabs( pt[1] - bounds[2] ) < fabs( pt[1] - bounds[3] ) )
      {
        pt[1] = bounds[2];
      }
      else
      {
        pt[1] = bounds[3];
      }
    }
    break;
  }
  pt[m_nSliceHighlighted] = slicepos[m_nSliceHighlighted];

  double pt1[3], pt2[3];
  this->ScreenToWorld( x, y, -100, pt1[0], pt1[1], pt1[2] );
  this->ScreenToWorld( x, y, 100, pt2[0], pt2[1], pt2[2] );
  double new_pt[3], t = 0;
  vtkPlane::IntersectWithLine( pt1, pt2, v, pt, t, new_pt );
  if ( t > 100000 )
  {
    new_pt[0] = pt[0];
    new_pt[1] = pt[1];
    new_pt[2] = pt[2];
  }
  if ( new_pt[m_nSliceHighlighted] < bounds[m_nSliceHighlighted*2] )
  {
    new_pt[m_nSliceHighlighted] = bounds[m_nSliceHighlighted*2];
  }
  else if ( new_pt[m_nSliceHighlighted] > bounds[m_nSliceHighlighted*2+1] )
  {
    new_pt[m_nSliceHighlighted] = bounds[m_nSliceHighlighted*2+1];
  }
  mainwnd->OffsetSlicePosition( m_nSliceHighlighted, new_pt[m_nSliceHighlighted] - slicepos[m_nSliceHighlighted], false );
  slicepos[m_nSliceHighlighted] = new_pt[m_nSliceHighlighted];
  lc->SetCursorRASPosition( slicepos );
}
Пример #11
0
void PanelSurface::DoUpdateUI()
{
  if ( !IsShown() )
    return;
  
  bool bHasSurface = ( m_listBoxLayers->GetSelection() != wxNOT_FOUND );
  wxWindowList children = XRCCTRL( *this, "ID_SCROLL_WINDOW", wxScrolledWindow )->GetChildren();
  wxWindowList::iterator it = children.begin(), end = children.end();
  for (; it != end; it++)
  {
    if ( !(*it)->IsKindOf(CLASSINFO(wxToolBar) ) && *it != m_listBoxLayers )
      (*it)->Enable( bHasSurface );
  }

  LayerSurface* layer = NULL;
  FSSurface* surf = NULL;
  if ( bHasSurface )
  {
    LayerCollection* lc = MainWindow::GetMainWindowPointer()->GetLayerCollection( "Surface" );
    for ( int i = 0; i < (int)m_listBoxLayers->GetCount() && i < lc->GetNumberOfLayers(); i++ )
      m_listBoxLayers->Check( i, lc->GetLayer( i )->IsVisible() );
    layer = ( LayerSurface* )( void* )m_listBoxLayers->GetClientData( m_listBoxLayers->GetSelection() );
    if ( layer )
    {
      m_sliderOpacity->SetValue( (int)( layer->GetProperties()->GetOpacity() * 100 ) );
      UpdateTextValue( m_textOpacity, layer->GetProperties()->GetOpacity() );
      double* rgb = layer->GetProperties()->GetBinaryColor();
      m_colorPicker->SetColour( wxColour( (int)(rgb[0]*255), (int)(rgb[1]*255), (int)(rgb[2]*255) ) );
      rgb = layer->GetProperties()->GetEdgeColor();
      m_colorPickerEdge->SetColour( wxColour( (int)(rgb[0]*255), (int)(rgb[1]*255), (int)(rgb[2]*255) ) );
      rgb = layer->GetProperties()->GetVectorColor();
      m_colorPickerVector->SetColour( wxColour( (int)(rgb[0]*255), (int)(rgb[1]*255), (int)(rgb[2]*255) ) );
      m_textFileName->ChangeValue( wxString::FromAscii( layer->GetFileName() ) );
      m_textFileName->SetInsertionPointEnd();
      m_textFileName->ShowPosition( m_textFileName->GetLastPosition() );
      m_spinEdgeThickness->SetValue( layer->GetProperties()->GetEdgeThickness() );
      m_spinVectorPointSize->SetValue( layer->GetProperties()->GetVectorPointSize() );

      m_choiceCurvatureMap->SetSelection( layer->GetProperties()->GetCurvatureMap() );

      UpdateTextValue( m_textMidPoint,  layer->GetProperties()->GetThresholdMidPoint()  );
      UpdateTextValue( m_textSlope,   layer->GetProperties()->GetThresholdSlope()  );
      double range[2];
      layer->GetCurvatureRange( range );
      m_sliderMidPoint->SetValue( (int) ( ( layer->GetProperties()->GetThresholdMidPoint() - range[0] ) / ( range[1] - range[0] ) * 100 ) );
      m_sliderSlope->SetValue( (int) ( layer->GetProperties()->GetThresholdSlope() ) );

      surf = layer->GetSourceSurface();     
       
      m_choiceRenderMode->SetSelection( layer->GetProperties()->GetSurfaceRenderMode() );
      m_choiceMeshColorMap->SetSelection( layer->GetProperties()->GetMeshColorMap() );
      m_checkShowVertices->SetValue( layer->GetProperties()->GetShowVertices() );
      rgb = layer->GetProperties()->GetVertexColor();
      m_colorPickerVertex->SetColour( wxColour( (int)(rgb[0]*255), (int)(rgb[1]*255), (int)(rgb[2]*255) ) );     
      m_spinVertexPointSize->SetValue( layer->GetProperties()->GetVertexPointSize() );
      
      double* dPos = layer->GetProperties()->GetPosition();
      wxString value_strg = ( (wxString)_("") << dPos [0] << _(" ") << dPos[1] << _(" ") << dPos[2] );
      m_textPosition->ChangeValue( value_strg );
      
      m_checkHideInfo->SetValue( !layer->GetProperties()->GetShowInfo() );
    }

    lc->SetActiveLayer( ( Layer* )m_listBoxLayers->GetClientData( m_listBoxLayers->GetSelection() ) );
  }

  m_choiceVector->Clear();
  m_choiceVector->Append( _("Off") );
  if ( surf )
  {
    for ( int i = 0; i < surf->GetNumberOfVectorSets(); i++ )
    {
      m_choiceVector->Append( wxString::FromAscii( surf->GetVectorSetName( i ) ) );
    }
  }
  m_choiceVector->Append( _("Load vector data...") );
  m_choiceVector->SetSelection( surf ? 1 + surf->GetActiveVector() : 0 );
  
  // update overlay controls
  m_choiceOverlay->Clear();
  m_choiceOverlay->Append( _("Off") );
  if ( layer )
  {
    for ( int i = 0; i < layer->GetNumberOfOverlays(); i++ )
    {
      m_choiceOverlay->Append( wxString::FromAscii( layer->GetOverlay( i )->GetName() ) );
    }
  }
  m_choiceOverlay->Append( _("Load from file...") );
  m_choiceOverlay->SetSelection( layer ? 1 + layer->GetActiveOverlayIndex() : 0 );
  
  m_btnOverlayConfiguration->Show( layer && layer->GetActiveOverlayIndex() >= 0 );
  
  // update annotation controls
  m_choiceAnnotation->Clear();
  m_choiceAnnotation->Append( _("Off") );
  if ( layer )
  {
    for ( int i = 0; i < layer->GetNumberOfAnnotations(); i++ )
    {
      m_choiceAnnotation->Append( wxString::FromAscii( layer->GetAnnotation( i )->GetName() ) );
    }
  }
  m_choiceAnnotation->Append( _("Load from file...") );
  m_choiceAnnotation->SetSelection( layer ? 1 + layer->GetActiveAnnotationIndex() : 0 );
  
  // update label controls
  m_choiceLabel->Clear();
  if ( layer )
  {
    if ( layer->GetNumberOfLabels() > 0 )
    {
      for ( int i = 0; i < layer->GetNumberOfLabels(); i++ )
      {
        m_choiceLabel->Append( wxString::FromAscii( layer->GetLabel( i )->GetName() ) );
      }
    }
    else
      m_choiceLabel->Append( _("None") );
  }
  m_choiceLabel->Append( _("Load from file...") );
  if ( layer && layer->GetActiveLabelIndex() >= 0 )
    m_choiceLabel->SetSelection( layer->GetActiveLabelIndex() );
  else
    m_choiceLabel->SetSelection( 0 );  
  if ( layer && layer->GetActiveLabel() )
  {
    double* rgb = layer->GetActiveLabel()->GetColor();
    m_colorPickerLabel->SetColour( wxColour( (int)(rgb[0]*255), (int)(rgb[1]*255), (int)(rgb[2]*255) ) );  
  }   

  int nCurvatureMap = layer ? layer->GetProperties()->GetCurvatureMap() : 0;
  for ( size_t i = 0; i < m_widgetsMidPoint.size(); i++ )
  {
    m_widgetsMidPoint[i]->Show( nCurvatureMap != LayerPropertiesSurface::CM_Off );
  }
  for ( size_t i = 0; i < m_widgetsSlope.size(); i++ )
  {
    m_widgetsSlope[i]->Show( nCurvatureMap == LayerPropertiesSurface::CM_Threshold );
  }
  for ( size_t i = 0; i < m_widgetsVector.size(); i++ )
  {
    m_widgetsVector[i]->Show( m_choiceVector->GetSelection() > 0 );
  }
  for ( size_t i = 0; i < m_widgetsVertex.size(); i++ )
  {
    m_widgetsVertex[i]->Show( m_checkShowVertices->GetValue() );
  }
  for ( size_t i = 0; i < m_widgetsMesh.size(); i++ )
  {
    m_widgetsMesh[i]->Show( layer && layer->GetProperties()->GetSurfaceRenderMode() != LayerPropertiesSurface::SM_Surface );
  }
  for ( size_t i = 0; i < m_widgetsLabel.size(); i++ )
  {
    m_widgetsLabel[i]->Show( layer && layer->GetActiveLabelIndex() >= 0 );
  }
  m_colorPicker->Enable( layer ); // && nCurvatureMap != LayerPropertiesSurface::CM_Threshold );

  // hack to force resize of these controls in scrolled window
  for ( size_t i = 0; i < m_widgetsResize.size(); i++ )
  {
    wxSize sz = m_widgetsResize[i]->GetMinSize();
    m_widgetsResize[i]->SetMinSize( wxSize( 100, sz.GetHeight() ) );
  }
 
  Layout();
}
Пример #12
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;
  }
}
Пример #13
0
void ToolWindowEdit::DoUpdateTools()
{
  int nViewId = MainWindow::GetMainWindowPointer()->GetActiveViewId();
  if ( nViewId < 0 || nViewId > 2 )
    nViewId = 0;
  RenderView2D* view = ( RenderView2D* )MainWindow::GetMainWindowPointer()->GetRenderView( nViewId );
  
  bool bVoxelEditVisible = m_toolbarVoxelEdit->IsShown();
  bool bROIEditVisible = m_toolbarROIEdit->IsShown();
  if ( bVoxelEditVisible != (view->GetInteractionMode() == RenderView2D::IM_VoxelEdit) ||
       bROIEditVisible != (view->GetInteractionMode() == RenderView2D::IM_ROIEdit) )
  {
    m_toolbarVoxelEdit ->Show( view->GetInteractionMode() == RenderView2D::IM_VoxelEdit );
    m_toolbarROIEdit ->Show( view->GetInteractionMode() == RenderView2D::IM_ROIEdit );

    XRCCTRL( *this, "ID_PANEL_HOLDER", wxPanel )->Layout();
  }

// XRCCTRL( *m_toolbarBrush, "ID_STATIC_BRUSH_SIZE", wxStaticText )->Enable( m_viewAxial->GetAction() != Interactor2DROIEdit::EM_Fill );
  m_spinBrushSize->Enable( view->GetAction() != Interactor2DROIEdit::EM_Fill );
  m_spinBrushTolerance->Enable( view->GetAction() == Interactor2DROIEdit::EM_Fill );
// choiceTemplate->Enable( checkTemplate->IsChecked() && m_viewAxial->GetAction() == Interactor2DROIEdit::EM_Fill );
// XRCCTRL( *m_toolbarBrush, "ID_STATIC_BRUSH_TOLERANCE", wxStaticText )->Enable( checkTemplate->IsChecked() ); //&& m_viewAxial->GetAction() == Interactor2DROIEdit::EM_Fill );
// XRCCTRL( *m_toolbarBrush, "ID_SPIN_BRUSH_TOLERANCE", wxSpinCtrl )->Enable( checkTemplate->IsChecked() );//&& m_viewAxial->GetAction() == Interactor2DROIEdit::EM_Fill );

  BrushProperty* bp = MainWindow::GetMainWindowPointer()->GetBrushProperty();
  LayerVolumeBase* layer = bp->GetReferenceLayer();
// if ( m_choiceTemplate->GetSelection() != wxNOT_FOUND )
//  layer = ( LayerEditable* )(void*)m_choiceTemplate->GetClientData( m_choiceTemplate->GetSelection() );

  m_choiceTemplate->Clear();
  m_choiceTemplate->Append( _("None"), (void*)NULL );
  LayerCollection* lc = MainWindow::GetMainWindowPointer()->GetLayerCollection( "MRI" );
  int nSel = 0;
  for ( int i = 0; i < lc->GetNumberOfLayers(); i++ )
  {
    LayerMRI* mri = (LayerMRI*)lc->GetLayer( i );
    if ( layer == mri )
    {
      nSel = i+1;
    }

    m_choiceTemplate->Append( wxString::FromAscii( mri->GetName() ), (void*)mri );
  }
// if ( !lc->IsEmpty() )
  m_choiceTemplate->SetSelection( nSel );

  m_spinBrushSize->SetValue( bp->GetBrushSize() );
  m_spinBrushTolerance->SetValue( bp->GetBrushTolerance( ) );

  m_checkDrawConnectedOnly->SetValue( bp->GetDrawConnectedOnly() );
  m_checkDrawRange  ->SetValue( bp->GetDrawRangeEnabled() );
  m_checkExcludeRange  ->SetValue( bp->GetExcludeRangeEnabled() );

  m_editDrawRangeLow  ->Enable( bp->GetDrawRangeEnabled() );
  m_editDrawRangeHigh  ->Enable( bp->GetDrawRangeEnabled() );
  m_editExcludeRangeLow ->Enable( bp->GetExcludeRangeEnabled() );
  m_editExcludeRangeHigh ->Enable( bp->GetExcludeRangeEnabled() );

  double* range = bp->GetDrawRange();
  UpdateTextValue( m_editDrawRangeLow, range[0] );
  UpdateTextValue( m_editDrawRangeHigh, range[1] );
  range = bp->GetExcludeRange();
  UpdateTextValue( m_editExcludeRangeLow, range[0] );
  UpdateTextValue( m_editExcludeRangeHigh, range[1] );

  Contour2D* c2d = view->GetContour2D();
  m_checkSmooth->SetValue( c2d->GetSmooth() );
  UpdateTextValue( m_editSmoothSD, c2d->GetSmoothSD() );
  m_editSmoothSD->Enable( c2d->GetSmooth() );
  UpdateTextValue( m_editContourValue, c2d->GetContourValue() );
  
  double* rgb = c2d->GetContourColor();
  m_colorPickerContour->SetColour( wxColour( (int)(rgb[0]*255), (int)(rgb[1]*255), (int)(rgb[2]*255) ) );
  
  int nAction = view->GetAction(); 
  ShowWidgets( m_widgetsBrushSize, nAction != Interactor2DVoxelEdit::EM_Contour &&
                                   nAction != Interactor2DVoxelEdit::EM_ColorPicker && 
                                   nAction != Interactor2DVoxelEdit::EM_Fill );
  ShowWidgets( m_widgetsReference, nAction == Interactor2DVoxelEdit::EM_Fill || 
                                   nAction == Interactor2DVoxelEdit::EM_Contour );  
  ShowWidgets( m_widgetsTolerance, nAction == Interactor2DVoxelEdit::EM_Fill );
  ShowWidgets( m_widgetsConstrain, nAction != Interactor2DVoxelEdit::EM_ColorPicker && 
      nAction != Interactor2DVoxelEdit::EM_Contour ); 
  ShowWidgets( m_widgetsSmooth, nAction == Interactor2DVoxelEdit::EM_Contour );
  ShowWidgets( m_widgetsContour, nAction == Interactor2DVoxelEdit::EM_Contour );
  
  m_bToUpdateTools = false;
  wxPanel* panel = XRCCTRL( *this, "ID_PANEL_HOLDER", wxPanel );
  panel->Layout();
  panel->Fit();
  Fit();
  Layout();
  MainWindow::GetMainWindowPointer()->NeedRedraw( 1 );
}
Пример #14
0
bool Interactor2DMeasure::ProcessMouseDownEvent( QMouseEvent* event, RenderView* renderview )
{
  RenderView2D* view = ( RenderView2D* )renderview;
// UpdateCursor( event, view );

  if ( m_region && !m_bDrawing && !m_bEditing )
  {
    m_region->Highlight( false );
  }

  if ( event->button() == Qt::LeftButton )
  {
    if ( ( event->modifiers() & CONTROL_MODIFIER ) && ( event->modifiers() & Qt::ShiftModifier ) )
    {
      return Interactor2D::ProcessMouseDownEvent( event, renderview );
    }

    LayerCollection* lc = MainWindow::GetMainWindow()->GetLayerCollection( "MRI" );
    LayerVolumeBase* mri = ( LayerVolumeBase* )lc->GetActiveLayer();
    if ( mri )
    {
      m_nMousePosX = event->x();
      m_nMousePosY = event->y();

      if ( m_region && m_bDrawing ) // drawing
      {
        ((Region2DPolyline*)m_region)->AddPoint( m_nMousePosX, m_nMousePosY );
      }
      else
      {
        Region2D* reg = view->GetRegion( m_nMousePosX, m_nMousePosY, &m_nPointIndex );
        if ( !reg ) // new region
        {
          if ( m_nAction == MM_Line )
          {
            Region2DLine* reg_line = new Region2DLine( view );
            reg_line->SetLine( m_nMousePosX, m_nMousePosY, m_nMousePosX, m_nMousePosY );
            view->AddRegion( reg_line );
            m_region = reg_line;
          }
          else if ( m_nAction == MM_Spline || m_nAction == MM_Polyline )
          {
            Region2DPolyline* reg_polyline = new Region2DPolyline( view, m_nAction == MM_Spline );
            reg_polyline->AddPoint( m_nMousePosX, m_nMousePosY );
            reg_polyline->AddPoint( m_nMousePosX, m_nMousePosY ); // add second point
            view->AddRegion( reg_polyline );
            m_region = reg_polyline;
          }
          else if ( m_nAction == MM_Rectangle )
          {
            Region2DRectangle* reg_rect = new Region2DRectangle( view );
            reg_rect->SetRect( m_nMousePosX, m_nMousePosY, 1, 1 );
            view->AddRegion( reg_rect );
            m_region = reg_rect;
          }
          m_bDrawing = true;
        }
        else      // editing
        {
          m_region = reg;
          m_bEditing = true;
          m_region->Highlight();
          view->EmitRegionSelected( reg );
          view->RequestRedraw();
        }
      }
      return false;
    }
  }
  else if ( event->button() == Qt::RightButton )
  {
    if ( m_bDrawing && m_region )
    {
      m_bDrawing = false;
      m_bEditing = false;
      if ( m_nAction == MM_Spline || m_nAction == MM_Polyline )
      {
        ((Region2DPolyline*)m_region)->RemoveLastPoint();
      }
      view->RequestRedraw();
      return false;
    }
  }

  return Interactor2D::ProcessMouseDownEvent( event, renderview ); // pass down the event
}
Пример #15
0
bool Interactor2DVolumeEdit::ProcessMouseMoveEvent( QMouseEvent* event, RenderView* renderview )
{
  RenderView2D* view = ( RenderView2D* )renderview;

  if ( m_bEditing )
  {
    UpdateCursor( event, view );
    int posX = event->x();
    int posY = event->y();

    LayerCollection* lc = MainWindow::GetMainWindow()->GetLayerCollection( m_strLayerTypeName );
    LayerVolumeBase* mri = ( LayerVolumeBase* )lc->GetActiveLayer();
    if ( m_nAction == EM_Freehand )
    {
      double ras1[3], ras2[3];
      view->MousePositionToRAS( m_nMousePosX, m_nMousePosY, ras1 );
      view->MousePositionToRAS( posX, posY, ras2 );

      mri->SetVoxelByRAS( ras1, ras2, view->GetViewPlane(),
                          !(event->modifiers() & Qt::ShiftModifier) && !(event->buttons() & Qt::RightButton) );
    }
    else if ( m_nAction == EM_Polyline || m_nAction == EM_Livewire )
    {
      double ras[3];
      view->MousePositionToRAS( posX, posY, ras );
      view->GetCursor2D()->SetPosition2( ras );
      if ( m_nAction == EM_Livewire )
      {
        view->GetCursor2D()->SetInterpolationPoints(
          mri->GetLiveWirePointsByRAS( ras,
                                       view->GetCursor2D()->GetPosition(),
                                       view->GetViewPlane() ) );
      }
      view->GetCursor2D()->SetPosition( view->GetCursor2D()->GetPosition(), true );
      view->RequestRedraw();
    }
    else if ( m_nAction == EM_Contour )
    {
      LayerMRI* mri_ref = (LayerMRI*)MainWindow::GetMainWindow()->GetBrushProperty()->GetReferenceLayer();
      Contour2D* c2d = view->GetContour2D();
      if ( event->modifiers() & Qt::ShiftModifier )
      {
        double ras1[3], ras2[3];
        view->MousePositionToRAS( m_nMousePosX, m_nMousePosY, ras1 );
        view->MousePositionToRAS( posX, posY, ras2 );
        c2d->RemoveLine( ras1, ras2 );
      }
      else if ( (event->modifiers() & CONTROL_MODIFIER) && (event->modifiers() & Qt::AltModifier) )
      {
        double scale = 0.2;
        if ( mri_ref )
        {
          double dMin = mri_ref->GetProperty()->GetMinValue();
          double dMax = mri_ref->GetProperty()->GetMaxValue();
          scale = ( dMax - dMin ) * 0.0005;
        }
        c2d->SetContourValue( c2d->GetContourValue() + scale * ( posY - m_nMousePosY ) );
      }
      else
      {
        double ras1[3], ras2[3];
        view->MousePositionToRAS( m_nMousePosX, m_nMousePosY, ras1 );
        view->MousePositionToRAS( posX, posY, ras2 );
        c2d->AddLine( ras1, ras2 );
      }

      view->RequestRedraw();
    }

    m_nMousePosX = posX;
    m_nMousePosY = posY;

    return false;
  }
  else
  {
    return Interactor2D::ProcessMouseMoveEvent( event, renderview );
  }
}
Пример #16
0
bool Interactor2DVolumeEdit::ProcessMouseDownEvent( wxMouseEvent& event, RenderView* renderview )
{
  RenderView2D* view = ( RenderView2D* )renderview;
// UpdateCursor( event, view );

  if ( event.LeftDown() || ( event.RightDown() && event.LeftIsDown() ) )
  {
    if ( event.CmdDown() && event.ShiftDown() )
      return Interactor2D::ProcessMouseDownEvent( event, renderview );

    LayerCollection* lc = MainWindow::GetMainWindowPointer()->GetLayerCollectionManager()->GetLayerCollection( m_strLayerTypeName.c_str() );
    LayerVolumeBase* mri = ( LayerVolumeBase* )lc->GetActiveLayer();
    if ( (!mri || !mri->IsVisible()) ) //&& ( event.CmdDown() || m_nAction == EM_Polyline ) )
    {
      SendBroadcast( m_strLayerTypeName + "NotVisible", this );
    }
    else if ( !mri->IsEditable() ) //&& ( event.CmdDown() || m_nAction == EM_Polyline ) )
    {
      SendBroadcast( m_strLayerTypeName + "NotEditable", this );
    }
    else if ( m_strLayerTypeName == "MRI" && ((LayerMRI*)mri)->IsTransformed() )
    {
      SendBroadcast( m_strLayerTypeName + "NotEditableForTransformation", this );
    }
    else
    {
      m_nMousePosX = event.GetX();
      m_nMousePosY = event.GetY();

      double ras[3];
      view->MousePositionToRAS( m_nMousePosX, m_nMousePosY, ras );
      if ( m_nAction == EM_Freehand ) //&& ( event.CmdDown() ) )
      {
        mri->SaveForUndo( view->GetViewPlane() );
        if ( event.CmdDown() )
        {
          mri->FloodFillByRAS( ras, view->GetViewPlane(), !event.ShiftDown() && !event.RightIsDown() );
        }
        else
        {
          m_bEditing = true;
          mri->SetVoxelByRAS( ras, view->GetViewPlane(), !event.ShiftDown() && !event.RightIsDown() );
        }
      }
      else if ( m_nAction == EM_Fill ) //&& ( event.CmdDown() ) )
      {
        mri->SaveForUndo( view->GetViewPlane() );
        mri->FloodFillByRAS( ras, view->GetViewPlane(), !event.ShiftDown() && !event.RightIsDown() );
      }
      else if ( m_nAction == EM_Polyline || m_nAction == EM_Livewire )
      {
        mri->SaveForUndo( view->GetViewPlane() );
        if ( event.CmdDown() )
        {
          mri->FloodFillByRAS( ras, view->GetViewPlane(), !event.ShiftDown() && !event.RightIsDown() );
        }
        else
        {
          m_bEditing = true;
          double ras2[3];
          view->GetCursor2D()->ClearInterpolationPoints();
          view->GetCursor2D()->GetPosition( ras2 );
          view->GetCursor2D()->SetPosition( ras );
          view->GetCursor2D()->SetPosition2( ras );
          if ( m_dPolylinePoints.size() > 0 )
          {
            if ( m_nAction == EM_Polyline )
              mri->SetVoxelByRAS( ras, ras2, view->GetViewPlane(), !event.ShiftDown() && !event.RightIsDown() );
            else
              mri->SetLiveWireByRAS( ras, ras2, view->GetViewPlane() );
          }
          else
          {
            // mri->SaveForUndo( view->GetViewPlane() );
            m_dPolylinePoints.push_back( ras[0] );
            m_dPolylinePoints.push_back( ras[1] );
            m_dPolylinePoints.push_back( ras[2] );
            view->GetCursor2D()->SetPosition( ras );
          }
  
          if ( view->GetCapture() == view )
            view->ReleaseMouse();
          view->CaptureMouse();
        }
      }
      else if ( m_nAction == EM_ColorPicker && mri->IsTypeOf( "MRI" ) )
      {
        if ( event.CmdDown() )
        {
          mri->SaveForUndo( view->GetViewPlane() );
          mri->FloodFillByRAS( ras, view->GetViewPlane(), !event.ShiftDown() && !event.RightIsDown() );
        }
        else
        {
          double dValue = ((LayerMRI*)mri)->GetVoxelValue( ras );
          if ( dValue != 0 )
          {
            mri->SetFillValue( (float)dValue );
            mri->SendBroadcast( "LayerActorUpdated", mri );
          }
        }
      }
      else if ( m_nAction == EM_Contour && mri->IsTypeOf( "MRI" ) )
      {
        LayerMRI* mri_ref = (LayerMRI*)MainWindow::GetMainWindowPointer()->GetBrushProperty()->GetReferenceLayer();
        if ( !mri_ref )
        {
          SendBroadcast( m_strLayerTypeName + "ReferenceNotSet", this );
          return false;
        }
          
        Contour2D* c2d = view->GetContour2D();
        if ( event.CmdDown() && event.AltDown() )
        {
          double dValue = mri_ref->GetVoxelValue( ras );
          if ( dValue != 0 )
          {
            m_bEditing = true;
            c2d->SetInput( mri_ref->GetSliceImageData( view->GetViewPlane() ), dValue, ras[view->GetViewPlane()], mri_ref->GetActiveFrame() );
            c2d->SetVisible( true );
            view->NeedRedraw();
          }
          else if ( c2d->IsVisible() )
          {
            m_bEditing = true;
          }
        }
        else if ( event.CmdDown() && !event.AltDown() )
        {
          mri->SaveForUndo( view->GetViewPlane() );
          ((LayerMRI*)mri)->FloodFillByContour2D( ras, c2d );
        }
        else if ( event.ShiftDown() )
        {
          m_bEditing = true;
          c2d->RemoveLine( ras, ras );
          view->NeedRedraw();
        }
        else
        {
          m_bEditing = true;
          c2d->AddLine( ras, ras );
          view->NeedRedraw();
        }
        
      }
      else
        return Interactor2D::ProcessMouseDownEvent( event, renderview );
    }

    return false;
  }
  else if ( m_bEditing )
  {
    m_bEditing = false;
    if ( m_nAction == EM_Polyline || m_nAction == EM_Livewire )
    {
      if ( event.MiddleDown() )
      {
        view->GetCursor2D()->Update();
        view->NeedRedraw();
      }
      else if ( event.RightDown() )
      {
        if ( m_dPolylinePoints.size() > 0 && m_nAction == EM_Polyline )
        {
          LayerCollection* lc = MainWindow::GetMainWindowPointer()->GetLayerCollection( m_strLayerTypeName.c_str() );
          LayerVolumeBase* mri = ( LayerVolumeBase* )lc->GetActiveLayer();

          double ras1[3] = { m_dPolylinePoints[0], m_dPolylinePoints[1], m_dPolylinePoints[2] };
          double ras2[3];
          view->GetCursor2D()->GetPosition( ras2 );
          view->GetCursor2D()->SetPosition2( ras2 );
          view->GetCursor2D()->SetPosition( ras1 );
          mri->SetVoxelByRAS( ras1, ras2, view->GetViewPlane(), !event.ShiftDown() );
        }
        else
        {
          // mri->SetLiveWireByRAS( ras1, ras2, view->GetViewPlane() );
          view->GetCursor2D()->Update();
          view->NeedRedraw();
        }
      }
    }

    m_dPolylinePoints.clear();
    if ( view->GetCapture() == view )
      view->ReleaseMouse();

    return false;
  }
  return Interactor2D::ProcessMouseDownEvent( event, renderview ); // pass down the event
}
Пример #17
0
bool Interactor2DRegionEdit::ProcessMouseDownEvent( wxMouseEvent& event, RenderView* renderview )
{
  RenderView2D* view = ( RenderView2D* )renderview;
// UpdateCursor( event, view );

  if ( event.LeftDown() )
  {
    // if ( event.CmdDown() )
    //  return Interactor2D::ProcessMouseDownEvent( event, renderview );

    LayerCollection* lc = MainWindow::GetMainWindowPointer()->GetLayerCollectionManager()->GetLayerCollection( "MRI" );
    LayerMRI* mri = ( LayerMRI* )lc->GetActiveLayer();
    if ( (!mri || !mri->IsVisible()) ) //&& ( event.CmdDown() || m_nAction == EM_Polyline ) )
    {
      SendBroadcast( "MRINotVisible", this );
    }
    else if ( !mri->IsEditable() ) //&& ( event.CmdDown() || m_nAction == EM_Polyline ) )
    {
      SendBroadcast( "MRINotEditable", this );
    }
    else
    {
      m_nMousePosX = event.GetX();
      m_nMousePosY = event.GetY();

      double ras[3];
      view->MousePositionToRAS( m_nMousePosX, m_nMousePosY, ras );
      if ( m_nAction == EM_Freehand ) //&& ( event.CmdDown() ) )
      {
        mri->SaveForUndo( view->GetViewPlane() );
        if ( event.CmdDown() )
        {
          mri->FloodFillByRAS( ras, view->GetViewPlane(), !event.ShiftDown() );
        }
        else
        {
          m_bEditing = true;
          mri->SetVoxelByRAS( ras, view->GetViewPlane(), !event.ShiftDown() );
        }
      }
      else if ( m_nAction == EM_Fill ) //&& ( event.CmdDown() ) )
      {
        mri->SaveForUndo( view->GetViewPlane() );
        mri->FloodFillByRAS( ras, view->GetViewPlane(), !event.ShiftDown() );
      }
      else if ( m_nAction == EM_Polyline )
      {
        m_bEditing = true;
        double ras2[3];
        view->GetCursor2D()->GetPosition( ras2 );
        view->GetCursor2D()->SetPosition( ras );
        view->GetCursor2D()->SetPosition2( ras );
        if ( m_dPolylinePoints.size() > 0 )
        {
          mri->SetVoxelByRAS( ras, ras2, view->GetViewPlane(), !event.ShiftDown() );
        }
        else
        {
          mri->SaveForUndo( view->GetViewPlane() );
          m_dPolylinePoints.push_back( ras[0] );
          m_dPolylinePoints.push_back( ras[1] );
          m_dPolylinePoints.push_back( ras[2] );
        }

        if ( view->GetCapture() == view )
          view->ReleaseMouse();
        view->CaptureMouse();
      }
      else
        return Interactor2D::ProcessMouseDownEvent( event, renderview );
    }

    return false;
  }
  else if ( m_bEditing )
  {
    m_bEditing = false;
    if ( m_nAction == EM_Polyline )
    {
      if ( event.MiddleDown() )
      {
        view->GetCursor2D()->Update();
        view->NeedRedraw();
      }
      else if ( event.RightDown() )
      {
        if ( m_dPolylinePoints.size() > 0 )
        {
          LayerCollection* lc = MainWindow::GetMainWindowPointer()->GetLayerCollection( "MRI" );
          LayerMRI* mri = ( LayerMRI* )lc->GetActiveLayer();

          double ras1[3] = { m_dPolylinePoints[0], m_dPolylinePoints[1], m_dPolylinePoints[2] };
          double ras2[3];
          view->GetCursor2D()->GetPosition( ras2 );
          view->GetCursor2D()->SetPosition2( ras2 );
          view->GetCursor2D()->SetPosition( ras1 );
          mri->SetVoxelByRAS( ras1, ras2, view->GetViewPlane(), !event.ShiftDown() );
        }
      }
    }

    m_dPolylinePoints.clear();
    if ( view->GetCapture() == view )
      view->ReleaseMouse();

    return false;
  }
  return Interactor2D::ProcessMouseDownEvent( event, renderview ); // pass down the event
}
Пример #18
0
bool Interactor2DVolumeEdit::ProcessMouseDownEvent( QMouseEvent* event, RenderView* renderview )
{
  RenderView2D* view = ( RenderView2D* )renderview;

  if ( !view->hasFocus() )
  {
    return Interactor2D::ProcessMouseDownEvent( event, renderview );
  }

  if ( event->button() == Qt::LeftButton ||
       ( event->button() == Qt::RightButton && (event->buttons() & Qt::LeftButton) ) )
  {
    if ( (event->modifiers() & CONTROL_MODIFIER ) && (event->modifiers() & Qt::ShiftModifier) )
    {
      return Interactor2D::ProcessMouseDownEvent( event, renderview );
    }

    LayerCollection* lc = MainWindow::GetMainWindow()->GetLayerCollection( m_strLayerTypeName );
    LayerVolumeBase* mri = ( LayerVolumeBase* )lc->GetActiveLayer();
    if ( (!mri || !mri->IsVisible()) ) //&& ( event->ControlDown() || m_nAction == EM_Polyline ) )
    {
      emit Error( "LayerNotVisible", mri );
    }
    else if ( !mri->IsEditable() ) //&& ( event->ControlDown() || m_nAction == EM_Polyline ) )
    {
      emit Error( "LayerNotEditable", mri );
    }
    else if ( m_strLayerTypeName == "MRI" && ((LayerMRI*)mri)->IsTransformed() )
    {
      emit Error( "LayerNotEditableForTransformation", mri );
    }
    else
    {
      m_nMousePosX = event->x();
      m_nMousePosY = event->y();

      double ras[3];
      view->MousePositionToRAS( m_nMousePosX, m_nMousePosY, ras );
      bool bCondition = !(event->modifiers() & Qt::ShiftModifier) && !(event->buttons() & Qt::RightButton);
      if ( m_nAction == EM_Freehand ) //&& ( event->ControlDown() ) )
      {
        mri->SaveForUndo( view->GetViewPlane() );
        if ( event->modifiers() & CONTROL_MODIFIER )
        {
          mri->FloodFillByRAS( ras, view->GetViewPlane(), bCondition );
        }
        else
        {
          m_bEditing = true;
          mri->SetVoxelByRAS( ras, view->GetViewPlane(),bCondition );
        }
      }
      else if ( m_nAction == EM_Fill ) //&& ( event->ControlDown() ) )
      {
        mri->SaveForUndo( view->GetViewPlane() );
        mri->FloodFillByRAS( ras, view->GetViewPlane(), bCondition );
      }
      else if ( m_nAction == EM_Polyline || m_nAction == EM_Livewire )
      {
        mri->SaveForUndo( view->GetViewPlane() );
        if ( event->modifiers() & CONTROL_MODIFIER )
        {
          mri->FloodFillByRAS( ras, view->GetViewPlane(), bCondition );
        }
        else
        {
          m_bEditing = true;
          double ras2[3];
          view->GetCursor2D()->ClearInterpolationPoints();
          view->GetCursor2D()->GetPosition( ras2 );
          view->GetCursor2D()->SetPosition( ras );
          view->GetCursor2D()->SetPosition2( ras );
          if ( m_dPolylinePoints.size() > 0 )
          {
            if ( m_nAction == EM_Polyline )
            {
              mri->SetVoxelByRAS( ras, ras2, view->GetViewPlane(), bCondition );
            }
            else
            {
              mri->SetLiveWireByRAS( ras, ras2, view->GetViewPlane() );
            }
          }
          else
          {
            // mri->SaveForUndo( view->GetViewPlane() );
            m_dPolylinePoints.push_back( ras[0] );
            m_dPolylinePoints.push_back( ras[1] );
            m_dPolylinePoints.push_back( ras[2] );
            view->GetCursor2D()->SetPosition( ras );
          }

          view->grabMouse();
        }
      }
      else if ( m_nAction == EM_ColorPicker && mri->IsTypeOf( "MRI" ) )
      {
        if ( event->modifiers() & CONTROL_MODIFIER )
        {
          mri->SaveForUndo( view->GetViewPlane() );
          mri->FloodFillByRAS( ras, view->GetViewPlane(), bCondition );
        }
        else
        {
          double dValue = ((LayerMRI*)mri)->GetVoxelValue( ras );
          if ( dValue != 0 )
          {
            mri->SetFillValue( (float)dValue );
          }
        }
      }
      else if ( m_nAction == EM_Contour && mri->IsTypeOf( "MRI" ) )
      {
        LayerMRI* mri_ref = (LayerMRI*)MainWindow::GetMainWindow()->GetBrushProperty()->GetReferenceLayer();
        if ( !mri_ref )
        {
          emit Error( "LayerReferenceNotSet" );
          return false;
        }

        Contour2D* c2d = view->GetContour2D();
        if ( (event->modifiers() & CONTROL_MODIFIER) && (event->modifiers() & Qt::AltModifier) )
        {
          double dValue = mri_ref->GetVoxelValue( ras );
          if ( dValue != 0 )
          {
            m_bEditing = true;
            c2d->SetInput( mri_ref->GetSliceImageData( view->GetViewPlane() ), dValue, ras[view->GetViewPlane()], mri_ref->GetActiveFrame() );
            c2d->SetVisible( true );
            view->RequestRedraw();
          }
          else if ( c2d->IsVisible() )
          {
            m_bEditing = true;
          }
        }
        else if ( (event->modifiers() & CONTROL_MODIFIER) && !(event->modifiers() & Qt::AltModifier) )
        {
          mri->SaveForUndo( view->GetViewPlane() );
          ((LayerMRI*)mri)->FloodFillByContour2D( ras, c2d );
        }
        else if ( event->modifiers() & Qt::ShiftModifier )
        {
          m_bEditing = true;
          c2d->RemoveLine( ras, ras );
          view->RequestRedraw();
        }
        else
        {
          m_bEditing = true;
          c2d->AddLine( ras, ras );
          view->RequestRedraw();
        }
      }
      else
      {
        return Interactor2D::ProcessMouseDownEvent( event, renderview );
      }
    }

    return false;
  }
  else if ( m_bEditing )
  {
    m_bEditing = false;
    if ( m_nAction == EM_Polyline || m_nAction == EM_Livewire )
    {
      if ( event->button() == Qt::MidButton )
      {
        view->GetCursor2D()->Update();
        view->RequestRedraw();
      }
      else if ( event->button() == Qt::RightButton )
      {
        if ( m_dPolylinePoints.size() > 0 && m_nAction == EM_Polyline )
        {
          LayerCollection* lc = MainWindow::GetMainWindow()->GetLayerCollection( m_strLayerTypeName );
          LayerVolumeBase* mri = ( LayerVolumeBase* )lc->GetActiveLayer();

          double ras1[3] = { m_dPolylinePoints[0], m_dPolylinePoints[1], m_dPolylinePoints[2] };
          double ras2[3];
          view->GetCursor2D()->GetPosition( ras2 );
          view->GetCursor2D()->SetPosition2( ras2 );
          view->GetCursor2D()->SetPosition( ras1 );
          mri->SetVoxelByRAS( ras1, ras2, view->GetViewPlane(), !(event->modifiers() & Qt::ShiftModifier) );
        }
        else
        {
          // mri->SetLiveWireByRAS( ras1, ras2, view->GetViewPlane() );
          view->GetCursor2D()->Update();
          view->RequestRedraw();
        }
      }
    }

    m_dPolylinePoints.clear();
    view->releaseMouse();

    return false;
  }
  return Interactor2D::ProcessMouseDownEvent( event, renderview ); // pass down the event
}
Пример #19
0
bool Interactor2DMeasure::ProcessMouseDownEvent( wxMouseEvent& event, RenderView* renderview )
{
  RenderView2D* view = ( RenderView2D* )renderview;
// UpdateCursor( event, view );

  if ( m_region && !m_bDrawing && !m_bEditing )
    m_region->Highlight( false );
  
  if ( event.LeftDown() )
  {
    if ( event.CmdDown() && event.ShiftDown() )
      return Interactor2D::ProcessMouseDownEvent( event, renderview );

    LayerCollection* lc = MainWindow::GetMainWindowPointer()->GetLayerCollectionManager()->GetLayerCollection( "MRI" );
    LayerVolumeBase* mri = ( LayerVolumeBase* )lc->GetActiveLayer();
    if ( mri )
    {
      m_nMousePosX = event.GetX();
      m_nMousePosY = event.GetY();
      
      Region2D* reg = view->GetRegion( m_nMousePosX, m_nMousePosY, &m_nPointIndex );
      if ( m_region && m_bDrawing )
      {       
        ((Region2DPolyline*)m_region)->AddPoint( m_nMousePosX, m_nMousePosY );
      }
      else if ( !reg )   // drawing
      {
        if ( m_nAction == MM_Line )
        {
          Region2DLine* reg_line = new Region2DLine( view );
          reg_line->SetLine( m_nMousePosX, m_nMousePosY, m_nMousePosX, m_nMousePosY ); 
          view->AddRegion( reg_line );
          m_region = reg_line;
        }
        else if ( m_nAction == MM_Spline || m_nAction == MM_Polyline )
        {
          Region2DPolyline* reg_polyline = new Region2DPolyline( view, m_nAction == MM_Spline );
          reg_polyline->AddPoint( m_nMousePosX, m_nMousePosY ); 
          reg_polyline->AddPoint( m_nMousePosX, m_nMousePosY ); // add second point
          view->AddRegion( reg_polyline );
          m_region = reg_polyline;
        }
        else if ( m_nAction == MM_Rectangle )
        {
          Region2DRectangle* reg_rect = new Region2DRectangle( view );
          reg_rect->SetRect( m_nMousePosX, m_nMousePosY, 1, 1 );
          view->AddRegion( reg_rect );
          m_region = reg_rect;
        }
        m_bDrawing = true;
      }
      else      // editing
      {
        m_region = reg;
        m_bEditing = true;
        m_region->Highlight();
        view->SendBroadcast( "RegionSelected", m_region );
        view->NeedRedraw();
      }
      return false;
    }
  }
  else if ( event.RightDown() )
  {
    if ( m_bDrawing && m_region )
    {
      m_bDrawing = false;
      m_bEditing = false;
      if ( m_nAction == MM_Spline || m_nAction == MM_Polyline )
        ((Region2DPolyline*)m_region)->RemoveLastPoint();
      view->NeedRedraw();
      return false;
    }
  }
  
  return Interactor2D::ProcessMouseDownEvent( event, renderview ); // pass down the event
}