示例#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();
}
示例#2
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 );
}