Exemplo n.º 1
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.º 2
0
bool Interactor2D::ProcessMouseMoveEvent( wxMouseEvent& event, RenderView* renderview )
{
  RenderView2D* view = ( RenderView2D* )renderview;

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

  int posX = event.GetX();
  int posY = event.GetY();

  if ( m_bChangeSlice )
  {
    double* voxelSize = lcm->GetLayerCollection( "MRI" )->GetWorldVoxelSize();
    int nPlane = view->GetViewPlane();
    double dPixelPer = -0.20;
    double dPosDiff =  ( ( (int)( dPixelPer * ( posY - m_nDownPosY ) ) ) / dPixelPer -
                         ( (int)( dPixelPer * ( m_nMousePosY - m_nDownPosY ) ) ) / dPixelPer )
                       * dPixelPer * voxelSize[nPlane];
    if ( lcm->OffsetSlicePosition( nPlane, dPosDiff ) )
    {
      m_nMousePosX = posX;
      m_nMousePosY = posY;
    }
  }
  else if ( m_bMovingCursor )
  {
    view->UpdateCursorRASPosition( posX, posY );
    view->NeedRedraw();
  }
  else if ( m_bWindowLevel )
  {
    std::vector<Layer*> layers = lcm->GetLayerCollection( "MRI" )->GetLayers();
    LayerMRI* layer = NULL;
    for ( size_t i = 0; i < layers.size(); i++ )
    {
      layer = ( LayerMRI*)layers[i];
      if ( layer->IsVisible() && layer->GetProperties()->GetColorMap() == LayerPropertiesMRI::Grayscale )
        break;
    }
    if ( layer )
    {
      double scaleX = 0.002;
      double scaleY = 0.002;
      double w = ( posX - m_nMousePosX ) * scaleX;
      double l = ( posY - m_nMousePosY ) * scaleY;
      double scaleOverall = layer->GetProperties()->GetMaxValue() -
                            layer->GetProperties()->GetMinValue();
      w *= scaleOverall;
      l *= scaleOverall;
      w += layer->GetProperties()->GetWindow();
      l += layer->GetProperties()->GetLevel();
      if ( w < 0 )
        w = 0;
      layer->GetProperties()->SetWindowLevel( w, l );
    }
    m_nMousePosX = posX;
    m_nMousePosY = posY;
  }
  else if ( m_bSelecting )
  {
    view->UpdateSelection( posX, posY );   
    view->NeedRedraw();
  }
  else
  {
    if ( event.MiddleIsDown() || event.RightIsDown() )
    {
      view->UpdateAnnotation();
      view->Update2DOverlay();
      if ( event.RightIsDown() )
        view->SendBroadcast( "Zooming", view );
    }
    else
      view->UpdateMouseRASPosition( posX, posY );

    return Interactor::ProcessMouseMoveEvent( event, renderview );
  }

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