Exemple #1
0
void mitk::SegTool2D::WriteBackSegmentationResult (const InteractionPositionEvent* positionEvent, Image* slice)
{
  if(!positionEvent) return;

  const PlaneGeometry* planeGeometry( dynamic_cast<const PlaneGeometry*> (positionEvent->GetSender()->GetCurrentWorldGeometry2D() ) );

  if( planeGeometry && slice)
  {
    DataNode* workingNode( m_ToolManager->GetWorkingData(0) );
    Image* image = dynamic_cast<Image*>(workingNode->GetData());
    unsigned int timeStep = positionEvent->GetSender()->GetTimeStep( image );
    this->WriteBackSegmentationResult(planeGeometry, slice, timeStep);

    slice->DisconnectPipeline();
    ImageToContourFilter::Pointer contourExtractor = ImageToContourFilter::New();
    contourExtractor->SetInput(slice);
    contourExtractor->Update();
    mitk::Surface::Pointer contour = contourExtractor->GetOutput();

    if (m_3DInterpolationEnabled && contour->GetVtkPolyData()->GetNumberOfPoints() > 0 && image->GetDimension() == 3)
    {
      unsigned int pos = this->AddContourmarker(positionEvent);
      us::ServiceReference<PlanePositionManagerService> serviceRef =
          us::GetModuleContext()->GetServiceReference<PlanePositionManagerService>();
      PlanePositionManagerService* service = us::GetModuleContext()->GetService(serviceRef);
      mitk::SurfaceInterpolationController::GetInstance()->AddNewContour( contour, service->GetPlanePosition(pos));
      contour->DisconnectPipeline();
    }
  }

}
Exemple #2
0
void mitk::SegTool2D::WriteBackSegmentationResult (const PositionEvent* positionEvent, Image* slice)
{
  const PlaneGeometry* planeGeometry( dynamic_cast<const PlaneGeometry*> (positionEvent->GetSender()->GetCurrentWorldGeometry2D() ) );

  DataNode* workingNode( m_ToolManager->GetWorkingData(0) );
  Image* image = dynamic_cast<Image*>(workingNode->GetData());

  unsigned int timeStep = positionEvent->GetSender()->GetTimeStep( image );

    //Make sure that for reslicing and overwriting the same alogrithm is used. We can specify the mode of the vtk reslicer
  vtkSmartPointer<mitkVtkImageOverwrite> reslice = vtkSmartPointer<mitkVtkImageOverwrite>::New();

  //Set the slice as 'input'
  reslice->SetInputSlice(slice->GetVtkImageData());

  //set overwrite mode to true to write back to the image volume
  reslice->SetOverwriteMode(true);
  reslice->Modified();

  mitk::ExtractSliceFilter::Pointer extractor =  mitk::ExtractSliceFilter::New(reslice);
  extractor->SetInput( image );
  extractor->SetTimeStep( timeStep );
  extractor->SetWorldGeometry( planeGeometry );
  extractor->SetVtkOutputRequest(true);
  extractor->SetResliceTransformByGeometry( image->GetTimeSlicedGeometry()->GetGeometry3D( timeStep ) );

  extractor->Modified();
  extractor->Update();

  //the image was modified within the pipeline, but not marked so
  image->Modified();
  image->GetVtkImageData()->Modified();

  /*============= BEGIN undo feature block ========================*/
  //specify the undo operation with the edited slice
  m_doOperation = new DiffSliceOperation(image, extractor->GetVtkOutput(),slice->GetGeometry(), timeStep, const_cast<mitk::PlaneGeometry*>(planeGeometry));

  //create an operation event for the undo stack
  OperationEvent* undoStackItem = new OperationEvent( DiffSliceOperationApplier::GetInstance(), m_doOperation, m_undoOperation, "Segmentation" );

  //add it to the undo controller
  UndoController::GetCurrentUndoModel()->SetOperationEvent( undoStackItem );

  //clear the pointers as the operation are stored in the undocontroller and also deleted from there
  m_undoOperation = NULL;
  m_doOperation = NULL;
  /*============= END undo feature block ========================*/

  slice->DisconnectPipeline();
  ImageToContourFilter::Pointer contourExtractor = ImageToContourFilter::New();
  contourExtractor->SetInput(slice);
  contourExtractor->Update();
  mitk::Surface::Pointer contour = contourExtractor->GetOutput();

  if (m_3DInterpolationEnabled && contour->GetVtkPolyData()->GetNumberOfPoints() > 0 )
  {
    unsigned int pos = this->AddContourmarker(positionEvent);
    mitk::ServiceReference serviceRef = mitk::GetModuleContext()->GetServiceReference<PlanePositionManagerService>();
    PlanePositionManagerService* service = dynamic_cast<PlanePositionManagerService*>(mitk::GetModuleContext()->GetService(serviceRef));
    mitk::SurfaceInterpolationController::GetInstance()->AddNewContour( contour, service->GetPlanePosition(pos));
    contour->DisconnectPipeline();
  }

  mitk::RenderingManager::GetInstance()->RequestUpdateAll();
}