Exemplo n.º 1
0
bool Interactor2D::ProcessMouseUpEvent( wxMouseEvent& event, RenderView* renderview )
{
  RenderView2D* view = ( RenderView2D* )renderview;

  if ( m_bSelecting )
  {
    view->StopSelection();
    view->NeedRedraw();
  }
  
  m_nMousePosX = event.GetX();
  m_nMousePosY = event.GetY();
  m_bWindowLevel = false;
  m_bChangeSlice = false;
  m_bMovingCursor = false;
  m_bSelecting = false;

  view->UpdateAnnotation();
  view->Update2DOverlay();

  if ( event.LeftUp() )
  {
    return false;
  }
  else
  {
    return Interactor::ProcessMouseUpEvent( event, renderview );
  }
}
Exemplo n.º 2
0
bool Interactor2D::ProcessMouseUpEvent( QMouseEvent* event, RenderView* renderview )
{
  RenderView2D* view = ( RenderView2D* )renderview;

  if ( m_bSelecting )
  {
    view->StopSelection();
    view->RequestRedraw();
  }

  m_nMousePosX = event->x();
  m_nMousePosY = event->y();
  m_bWindowLevel = false;
  m_bChangeSlice = false;
  m_bMovingCursor = false;
  m_bSelecting = false;

  view->UpdateAnnotation();
  view->Update2DOverlay();

  if ( event->button() == Qt::LeftButton )
  {
    return false;
  }
  else
  {
    return Interactor::ProcessMouseUpEvent( event, renderview );
  }
}
Exemplo n.º 3
0
void Interactor2DMeasure::UpdateCursor( wxEvent& event, wxWindow* wnd )
{
  RenderView2D* view = ( RenderView2D* )wnd;
  if ( wnd->FindFocus() == wnd )
  {
    if ( event.IsKindOf( CLASSINFO( wxMouseEvent ) ) )
    {
      wxMouseEvent* e = ( wxMouseEvent* )&event;
      if ( ( ( e->MiddleDown() || e->RightDown() ) && !m_bEditing ) ||
           ( e->CmdDown() && e->ShiftDown() ) )
      {
        Interactor2D::UpdateCursor( event, wnd );
        return;
      }
      else if ( ( !m_bEditing && !m_bDrawing && view->GetRegion( e->GetX(), e->GetY() ) ) ||
                ( m_bEditing && m_nPointIndex < 0 ) )
      {
        wnd->SetCursor( CursorFactory::CursorGrab );
      }
      else
      {
        if ( m_nAction == MM_Line ) 
          wnd->SetCursor( CursorFactory::CursorMeasureLine );
        else if ( m_nAction == MM_Rectangle )
          wnd->SetCursor( CursorFactory::CursorMeasureRectangle );
        else if ( m_nAction == MM_Polyline || m_nAction == MM_Spline )
          wnd->SetCursor( CursorFactory::CursorMeasurePolyline );
      }
    }   
  }
  else
    Interactor2D::UpdateCursor( event, wnd );
}
Exemplo n.º 4
0
bool Interactor2DNavigate::ProcessMouseDownEvent( QMouseEvent* event, RenderView* renderview )
{
  if (m_nCurrentLandmark < 0)
    return Interactor2D::ProcessMouseDownEvent(event, renderview);

  RenderView2D* view = ( RenderView2D* )renderview;

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

    LayerLandmarks* landmarks = (LayerLandmarks*)MainWindow::GetMainWindow()->GetSupplementLayer("Landmarks");
    if ( !landmarks )
    {
      emit Error( "Landmarks non-exist", landmarks );
    }
    else
    {
      m_bEditing = true;
      double pos[3];
      view->MousePositionToRAS( event->x(), event->y(), pos );
      landmarks->SetLandmarkPosition(m_nCurrentLandmark, pos);
    }

    return false;
  }
  else
  {
    return Interactor2D::ProcessMouseDownEvent( event, renderview );  // pass down the event
  }
}
bool Interactor2DVolumeEdit::ProcessKeyDownEvent( QKeyEvent* event, RenderView* renderview )
{
  UpdateCursor( event, renderview );

  RenderView2D* view = ( RenderView2D* )renderview;
  if ( event->modifiers() & Qt::AltModifier && event->key() == Qt::Key_H )
  {
    Contour2D* c2d = view->GetContour2D();
    c2d->SetVisible( !c2d->IsVisible() );
    view->RequestRedraw();
    return false;
  }
  else if (event->modifiers() & Qt::ShiftModifier && event->key() == Qt::Key_C)
  {
    m_bColorPicking = true;
    return false;
  }
  else if (event->key() == Qt::Key_Escape)
  {
    m_bColorPicking = false;
    return false;
  }

  if ( !m_bEditing )
  {
    return Interactor2D::ProcessKeyDownEvent( event, renderview );
  }
  else
  {
    return false;
  }
}
Exemplo n.º 6
0
bool Interactor2DMeasure::ProcessMouseMoveEvent( QMouseEvent* event, RenderView* renderview )
{
  RenderView2D* view = ( RenderView2D* )renderview;

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

//    LayerCollection* lc = MainWindow::GetMainWindowPointer()->GetLayerCollection( m_strLayerTypeName.c_str() );
//    LayerVolumeBase* mri = ( LayerVolumeBase* )lc->GetActiveLayer();

    if ( m_region )
    {
      if ( m_nAction == MM_Line )
      {
        ((Region2DLine*)m_region)->SetPoint2( posX, posY );
      }
      else if ( m_nAction == MM_Spline || m_nAction == MM_Polyline )
      {
        ((Region2DPolyline*)m_region)->UpdatePoint( -1, posX, posY );
      }
      else if ( m_nAction == MM_Rectangle )
      {
        ((Region2DRectangle*)m_region)->SetBottomRight( posX, posY );
      }
      view->RequestRedraw();
    }

    return false;
  }
  else if ( m_bEditing )
  {
    UpdateCursor( event, view );
    int offsetX = event->x() - m_nMousePosX;
    int offsetY = event->y() - m_nMousePosY;
    if ( m_region )
    {
      m_nMousePosX = event->x();
      m_nMousePosY = event->y();
      if ( m_nPointIndex >= 0 )
      {
        m_region->UpdatePoint( m_nPointIndex, m_nMousePosX, m_nMousePosY );
      }
      else
      {
        m_region->Offset( offsetX, offsetY );
      }
      view->RequestRedraw();
    }

    return false;
  }
  else
  {
    return Interactor2D::ProcessMouseMoveEvent( event, renderview );
  }
}
Exemplo n.º 7
0
void ToolWindowEdit::OnActionROIFreehandUpdateUI( wxUpdateUIEvent& event)
{
  RenderView2D* view = ( RenderView2D* )MainWindow::GetMainWindowPointer()->GetRenderView( 0 );
  event.Check( view->GetInteractionMode() == RenderView2D::IM_ROIEdit
               && view->GetAction() == Interactor2DROIEdit::EM_Freehand );
  event.Enable( view->GetInteractionMode() == RenderView2D::IM_ROIEdit
                && !MainWindow::GetMainWindowPointer()->GetLayerCollection( "MRI" )->IsEmpty() );
}
Exemplo n.º 8
0
bool Interactor2DMeasure::ProcessMouseUpEvent( QMouseEvent* event, RenderView* renderview )
{
  RenderView2D* view = ( RenderView2D* )renderview;
  UpdateCursor( event, renderview );

  if ( m_bDrawing )
  {
    if ( ( m_nAction == MM_Spline || m_nAction == MM_Polyline ) && m_region )
    {
      return false;
    }

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

      //    if ( event->LeftUp() )

//     LayerCollection* lc = MainWindow::GetMainWindowPointer()->GetLayerCollection( "MRI" );
//     LayerVolumeBase* mri = ( LayerVolumeBase* )lc->GetActiveLayer();
//     mri->SendBroadcast( "LayerEdited", mri );
      if ( m_region )
      {
        if ( m_nAction == MM_Line )
        {
          ((Region2DLine*)m_region)->SetPoint2( m_nMousePosX, m_nMousePosY );
        }
        else if ( m_nAction == MM_Rectangle )
        {
          ((Region2DRectangle*)m_region)->SetBottomRight( m_nMousePosX, m_nMousePosY );
        }
      }
    }
    else
    {
      if ( m_region && m_nAction != MM_Polyline && m_nAction != MM_Spline )
      {
        view->DeleteRegion( m_region );
        m_region = NULL;
      }
    }

    m_bEditing = false;
    m_bDrawing = false;
    return false;
  }
  else if ( m_bEditing )
  {
    m_bEditing = false;
    m_bDrawing = false;
    return false;
  }
  else
  {
    return Interactor2D::ProcessMouseUpEvent( event, renderview );
  }
}
Exemplo n.º 9
0
void ToolWindowEdit::OnActionVoxelColorPickerUpdateUI( wxUpdateUIEvent& event)
{
  RenderView2D* view = ( RenderView2D* )MainWindow::GetMainWindowPointer()->GetRenderView( 0 );
  event.Check( view->GetInteractionMode() == RenderView2D::IM_VoxelEdit
      && view->GetAction() == Interactor2DVoxelEdit::EM_ColorPicker );

  event.Enable( view->GetInteractionMode() == RenderView2D::IM_VoxelEdit
      && !MainWindow::GetMainWindowPointer()->GetLayerCollection( "MRI" )->IsEmpty() );
}
Exemplo n.º 10
0
void Interactor2D::ProcessPostMouseWheelEvent( wxMouseEvent& event, RenderView* renderview )
{
  RenderView2D* view = ( RenderView2D* )renderview;
  view->UpdateAnnotation();
  view->Update2DOverlay();
  view->NeedRedraw();
  view->SendBroadcast( "Zooming", view );

  Interactor::ProcessPostMouseWheelEvent( event, renderview );
}
Exemplo n.º 11
0
void ToolWindowEdit::OnActionVoxelContourUpdateUI( wxUpdateUIEvent& event)
{
  RenderView2D* view = ( RenderView2D* )MainWindow::GetMainWindowPointer()->GetRenderView( 0 );
  event.Check( view->GetInteractionMode() == RenderView2D::IM_VoxelEdit
      && view->GetAction() == Interactor2DVoxelEdit::EM_Contour );

  LayerMRI* mri = (LayerMRI*)MainWindow::GetMainWindowPointer()->GetLayerCollection( "MRI" )->GetActiveLayer();
  event.Enable( view->GetInteractionMode() == RenderView2D::IM_VoxelEdit
      && mri /*&& mri->GetProperties()->GetColorMap() == LayerPropertiesMRI::LUT*/ );
}
Exemplo n.º 12
0
void ToolWindowEdit::OnCheckSmooth( wxCommandEvent& event )
{
  for ( int i = 0; i < 3; i++ )
  {
    RenderView2D* view = ( RenderView2D* )MainWindow::GetMainWindowPointer()->GetRenderView( i );
    Contour2D* c2d = view->GetContour2D();
    c2d->SetSmooth( event.IsChecked() );
  }
  UpdateTools();
}
Exemplo n.º 13
0
void Interactor2D::ProcessPostMouseWheelEvent( QWheelEvent* event, RenderView* renderview )
{
  RenderView2D* view = ( RenderView2D* )renderview;
  view->UpdateAnnotation();
  view->Update2DOverlay();
  view->RequestRedraw();
  view->EmitZooming();

  Interactor::ProcessPostMouseWheelEvent( event, renderview );
}
Exemplo n.º 14
0
void ToolWindowEdit::OnColorContour( wxColourPickerEvent& event )
{
  wxColour c = event.GetColour();
  for ( int i = 0; i < 3; i++ )
  {
    RenderView2D* view = ( RenderView2D* )MainWindow::GetMainWindowPointer()->GetRenderView( i );
    Contour2D* c2d = view->GetContour2D();
    c2d->SetContourColor( c.Red()/255.0, c.Green()/255.0, c.Blue()/255.0 );
  }
}
Exemplo n.º 15
0
void Interactor2D::ProcessPostMouseMoveEvent( QMouseEvent* event, RenderView* renderview )
{
  RenderView2D* view = ( RenderView2D* )renderview;
  if ( event->buttons() & Qt::RightButton )
  {
    view->Update2DOverlay();
    view->RequestRedraw();
  }

  Interactor::ProcessPostMouseMoveEvent( event, renderview );
}
Exemplo n.º 16
0
void Interactor2D::ProcessPostMouseMoveEvent( wxMouseEvent& event, RenderView* renderview )
{
  RenderView2D* view = ( RenderView2D* )renderview;
  if ( event.RightIsDown() )
  {
    view->Update2DOverlay();
    view->NeedRedraw();
  }

  Interactor::ProcessPostMouseMoveEvent( event, renderview );
}
Exemplo n.º 17
0
bool Interactor2D::ProcessKeyDownEvent( QKeyEvent* event, RenderView* renderview )
{
  RenderView2D* view = ( RenderView2D* )renderview;

  if ( MainWindow::GetMainWindow()->IsEmpty() )
  {
    return Interactor::ProcessKeyDownEvent( event, renderview );
  }

  int nKeyCode = event->key();
  if ( event->modifiers() & Qt::ShiftModifier )
  {
      if ( nKeyCode == Qt::Key_Up )
      {
        view->Zoom(1.05);
      }
      else if ( nKeyCode == Qt::Key_Down )
      {
        view->Zoom(0.95);
      }
  }
  else if ( nKeyCode == Qt::Key_PageUp )
  {
    view->MoveSlice( 1 );
  }
  else if ( nKeyCode == Qt::Key_PageDown )
  {
    view->MoveSlice( -1 );
  }
  else if ( nKeyCode == Qt::Key_Up )
  {
    view->MoveUp();
  }
  else if ( nKeyCode == Qt::Key_Down )
  {
    view->MoveDown();
  }
  else if ( nKeyCode == Qt::Key_Left )
  {
    view->MoveLeft();
  }
  else if ( nKeyCode == Qt::Key_Right )
  {
    view->MoveRight();
  }
  else if ( nKeyCode == Qt::Key_3 /*|| nKeyCode == 'W' || nKeyCode == 'S'*/ || nKeyCode == Qt::Key_R || nKeyCode == Qt::Key_F )
  {
    // do nothing, just intercept these vtk default keycodes
  }
  else
  {
    return Interactor::ProcessKeyDownEvent( event, view );
  }

  return false;
}
Exemplo n.º 18
0
bool Interactor2DMeasure::ProcessKeyDownEvent( wxKeyEvent& event, RenderView* renderview )
{
  RenderView2D* view = ( RenderView2D* )renderview;
  UpdateCursor( event, renderview );

  if ( m_region && ( event.GetKeyCode() == WXK_DELETE || event.GetKeyCode() == WXK_NUMPAD_DELETE ) )
  {
    view->DeleteRegion( m_region );
    m_region = NULL;
    return false;
  }
  else
  {
    return Interactor2D::ProcessKeyDownEvent( event, renderview );
  }
}
Exemplo n.º 19
0
bool Interactor2DMeasure::ProcessKeyDownEvent( QKeyEvent* event, RenderView* renderview )
{
  RenderView2D* view = ( RenderView2D* )renderview;
  UpdateCursor( event, renderview );

  if ( m_region && event->key() == Qt::Key_Delete )
  {
    view->DeleteRegion( m_region );
    m_region = NULL;
    return false;
  }
  else
  {
    return Interactor2D::ProcessKeyDownEvent( event, renderview );
  }
}
Exemplo n.º 20
0
bool Interactor2DVolumeEdit::ProcessKeyDownEvent( wxKeyEvent& event, RenderView* renderview )
{
  UpdateCursor( event, renderview );
  
  RenderView2D* view = ( RenderView2D* )renderview;
  if ( event.GetModifiers() == wxMOD_ALT && event.GetKeyCode() == 'H' )
  {
    Contour2D* c2d = view->GetContour2D();
    c2d->SetVisible( !c2d->IsVisible() );
    view->NeedRedraw();
    return false;
  }
  
  if ( !m_bEditing )
    return Interactor2D::ProcessKeyDownEvent( event, renderview );
  else
    return false;
}
Exemplo n.º 21
0
void ToolWindowEdit::OnEditSmoothSD( wxCommandEvent& event )
{
  double value;

  if (m_editSmoothSD != NULL)
  {
    if ( m_editSmoothSD->GetValue().ToDouble( &value ) && value > 0 )
    {
      for ( int i = 0; i < 3; i++ )
      {
        RenderView2D* view = ( RenderView2D* )MainWindow::GetMainWindowPointer()->GetRenderView( i );
        Contour2D* c2d = view->GetContour2D();
        c2d->SetSmoothSD( value );
      }
      UpdateTools();
    }
  }
}
Exemplo n.º 22
0
void Interactor2DMeasure::UpdateCursor( QEvent* event, QWidget* wnd )
{
  RenderView2D* view = ( RenderView2D* )wnd;
  if ( wnd->hasFocus() )
  {
    if ( event->type() == QEvent::MouseButtonPress ||
         event->type() == QEvent::MouseButtonRelease ||
         event->type() == QEvent::MouseMove)
    {
      QMouseEvent* e = ( QMouseEvent* )event;
      if ( ( ( e->button() == Qt::MidButton || e->button() == Qt::RightButton ) && !m_bEditing ) ||
           ( ( e->modifiers() & CONTROL_MODIFIER) && (e->modifiers() & Qt::ShiftModifier) ) )
      {
        Interactor2D::UpdateCursor( event, wnd );
        return;
      }
      else if ( ( !m_bEditing && !m_bDrawing && view->GetRegion( e->x(), e->y() ) ) ||
                ( m_bEditing && m_nPointIndex < 0 ) )
      {
        wnd->setCursor( CursorFactory::CursorGrab );
      }
      else
      {
        if ( m_nAction == MM_Line )
        {
          wnd->setCursor( CursorFactory::CursorMeasureLine );
        }
        else if ( m_nAction == MM_Rectangle )
        {
          wnd->setCursor( CursorFactory::CursorMeasureRectangle );
        }
        else if ( m_nAction == MM_Polyline || m_nAction == MM_Spline )
        {
          wnd->setCursor( CursorFactory::CursorMeasurePolyline );
        }
      }
    }
  }
  else
  {
    Interactor2D::UpdateCursor( event, wnd );
  }
}
Exemplo n.º 23
0
bool Interactor2DNavigate::ProcessMouseMoveEvent( QMouseEvent* event, RenderView* renderview )
{
  RenderView2D* view = ( RenderView2D* )renderview;
  if ( m_bEditing && m_nCurrentLandmark >= 0 )
  {
    UpdateCursor( event, view );
    LayerLandmarks* landmarks = (LayerLandmarks*)MainWindow::GetMainWindow()->GetSupplementLayer("Landmarks");
    if ( landmarks )
    {
      double pos[3];
      view->MousePositionToRAS( event->x(), event->y(), pos );
      landmarks->SetLandmarkPosition(m_nCurrentLandmark, pos);
    }
    return false;
  }
  else
  {
    return Interactor2D::ProcessMouseMoveEvent( event, renderview );
  }
}
Exemplo n.º 24
0
bool Interactor2D::ProcessMouseDownEvent( wxMouseEvent& event, RenderView* renderview )
{
  RenderView2D* view = ( RenderView2D* )renderview;

  m_nMousePosX = event.GetX();
  m_nMousePosY = event.GetY();

  view->UpdateAnnotation();

  if ( event.CmdDown() && !event.ShiftDown() )
  {
    if ( event.LeftDown() )
    {
      view->ZoomAtCursor( m_nMousePosX, m_nMousePosY, true );
      return false;
    }
    else if ( event.RightDown() )
    {
      view->ZoomAtCursor( m_nMousePosX, m_nMousePosY, false );
      return false;
    }
  }

  if ( event.LeftDown() )
  {
    m_nDownPosX = m_nMousePosX;
    m_nDownPosY = m_nMousePosY;

    if ( event.ShiftDown() && !event.CmdDown() )
    {
      m_bWindowLevel = true;
    }
    else
    {
      m_bMovingCursor = true;
      view->UpdateCursorRASPosition( m_nMousePosX, m_nMousePosY );
      view->NeedRedraw();
    }
  }
  else if ( event.MiddleDown() && event.ShiftDown() )
  {
      m_bSelecting = true;
      view->StartSelection( m_nMousePosX, m_nMousePosY );
  }
  else if ( event.RightDown() && event.ShiftDown() && !event.CmdDown() )
  {
    m_bWindowLevel = true;
  }
  else
  {
    return Interactor::ProcessMouseDownEvent( event, renderview ); // pass down the event
  }

  return false; // do not pass down the event
}
Exemplo n.º 25
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();
  }
}
Exemplo n.º 26
0
void ToolWindowEdit::OnShow( wxShowEvent& event )
{
//#if wxCHECK_VERSION(2,9,0)
#if wxVERSION_NUMBER > 2900  
  if ( event.IsShown() )
#else
  if ( event.GetShow() )
#endif
  {
    wxConfigBase* config = wxConfigBase::Get();
    if ( config )
    {
      int x = config->Read( _T("/ToolWindowEdit/PosX"), 0L );
      int y = config->Read( _T("/ToolWindowEdit/PosY"), 0L );
      if ( x == 0 && y == 0 )
        Center();
      else
        Move( x, y );
    }
    for ( int i = 0; i < 3; i++ )
    {
      RenderView2D* view = ( RenderView2D* )MainWindow::GetMainWindowPointer()->GetRenderView( i );
      view->GetContour2D()->AddListener( this );
    }
  }
  else
  {
    wxConfigBase* config = wxConfigBase::Get();
    if ( config )
    {
      int x, y;
      GetPosition( &x, &y );
      config->Write( _T("/ToolWindowEdit/PosX"), (long) x );
      config->Write( _T("/ToolWindowEdit/PosY"), (long) y );
    } 
  }
  MainWindow::GetMainWindowPointer()->SetFocus();
}
Exemplo n.º 27
0
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 );
  }
}
Exemplo n.º 28
0
bool Interactor2D::ProcessKeyDownEvent( wxKeyEvent& event, RenderView* renderview )
{
  RenderView2D* view = ( RenderView2D* )renderview;

  LayerCollectionManager* lcm = MainWindow::GetMainWindowPointer()->GetLayerCollectionManager();
  if ( !lcm->HasAnyLayer() )
  {
    return Interactor::ProcessKeyDownEvent( event, renderview );
  }

  int nKeyCode = event.GetKeyCode();
  if ( nKeyCode == WXK_PAGEUP )
  {
    view->MoveSlice( 1 );
  }
  else if ( nKeyCode == WXK_PAGEDOWN)
  {
    view->MoveSlice( -1 );
  }
  else if ( nKeyCode == WXK_UP )
  {
    view->MoveUp();
  }
  else if ( nKeyCode == WXK_DOWN )
  {
    view->MoveDown();
  }
  else if ( nKeyCode == WXK_LEFT )
  {
    view->MoveLeft();
  }
  else if ( nKeyCode == WXK_RIGHT )
  {
    view->MoveRight();
  }
  else if ( nKeyCode == '3' /*|| nKeyCode == 'W' || nKeyCode == 'S'*/ || nKeyCode == 'R' || nKeyCode == 'F' )
  {
    // do nothing, just intercept these vtk default keycodes
  }
  else
    return Interactor::ProcessKeyDownEvent( event, view );

  return false;
}
Exemplo n.º 29
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
}
Exemplo n.º 30
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 );
  }
}