Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include "mitkCorrectorTool2D.h"
00019 #include "mitkCorrectorAlgorithm.h"
00020
00021 #include "mitkToolManager.h"
00022 #include "mitkOverwriteSliceImageFilter.h"
00023 #include "mitkBaseRenderer.h"
00024 #include "mitkRenderingManager.h"
00025
00026 #include "mitkCorrectorTool2D.xpm"
00027
00028 namespace mitk {
00029 MITK_TOOL_MACRO(MitkExt_EXPORT, CorrectorTool2D, "Correction tool");
00030 }
00031
00032 mitk::CorrectorTool2D::CorrectorTool2D(int paintingPixelValue)
00033 :FeedbackContourTool("PressMoveRelease"),
00034 m_PaintingPixelValue(paintingPixelValue)
00035 {
00036 GetFeedbackContour()->SetClosed( false );
00037 }
00038
00039 mitk::CorrectorTool2D::~CorrectorTool2D()
00040 {
00041 }
00042
00043 const char** mitk::CorrectorTool2D::GetXPM() const
00044 {
00045 return mitkCorrectorTool2D_xpm;
00046 }
00047
00048 const char* mitk::CorrectorTool2D::GetName() const
00049 {
00050 return "Correction";
00051 }
00052
00053 void mitk::CorrectorTool2D::Activated()
00054 {
00055 Superclass::Activated();
00056 }
00057
00058 void mitk::CorrectorTool2D::Deactivated()
00059 {
00060 Superclass::Deactivated();
00061 }
00062
00063 bool mitk::CorrectorTool2D::OnMousePressed (Action* action, const StateEvent* stateEvent)
00064 {
00065 if (!FeedbackContourTool::OnMousePressed( action, stateEvent )) return false;
00066
00067 const PositionEvent* positionEvent = dynamic_cast<const PositionEvent*>(stateEvent->GetEvent());
00068 if (!positionEvent) return false;
00069
00070 Contour* contour = FeedbackContourTool::GetFeedbackContour();
00071 contour->Initialize();
00072 contour->AddVertex( positionEvent->GetWorldPosition() );
00073
00074 FeedbackContourTool::SetFeedbackContourVisible(true);
00075
00076 return true;
00077 }
00078
00079 bool mitk::CorrectorTool2D::OnMouseMoved (Action* action, const StateEvent* stateEvent)
00080 {
00081 if (!FeedbackContourTool::OnMouseMoved( action, stateEvent )) return false;
00082
00083 const PositionEvent* positionEvent = dynamic_cast<const PositionEvent*>(stateEvent->GetEvent());
00084 if (!positionEvent) return false;
00085
00086 Contour* contour = FeedbackContourTool::GetFeedbackContour();
00087 contour->AddVertex( positionEvent->GetWorldPosition() );
00088
00089 assert( positionEvent->GetSender()->GetRenderWindow() );
00090 mitk::RenderingManager::GetInstance()->RequestUpdate( positionEvent->GetSender()->GetRenderWindow() );
00091
00092 return true;
00093 }
00094
00095 bool mitk::CorrectorTool2D::OnMouseReleased(Action* action, const StateEvent* stateEvent)
00096 {
00097
00098 FeedbackContourTool::SetFeedbackContourVisible(false);
00099
00100 const PositionEvent* positionEvent = dynamic_cast<const PositionEvent*>(stateEvent->GetEvent());
00101 if (!positionEvent) return false;
00102
00103 assert( positionEvent->GetSender()->GetRenderWindow() );
00104 mitk::RenderingManager::GetInstance()->RequestUpdate( positionEvent->GetSender()->GetRenderWindow() );
00105
00106 if (!FeedbackContourTool::OnMouseReleased( action, stateEvent )) return false;
00107
00108 DataNode* workingNode( m_ToolManager->GetWorkingData(0) );
00109 if (!workingNode) return false;
00110
00111 Image* image = dynamic_cast<Image*>(workingNode->GetData());
00112 const PlaneGeometry* planeGeometry( dynamic_cast<const PlaneGeometry*> (positionEvent->GetSender()->GetCurrentWorldGeometry2D() ) );
00113 if ( !image || !planeGeometry ) return false;
00114
00115 int affectedDimension( -1 );
00116 int affectedSlice( -1 );
00117 if ( FeedbackContourTool::DetermineAffectedImageSlice( image, planeGeometry, affectedDimension, affectedSlice ) )
00118 {
00119
00120 m_WorkingSlice = FeedbackContourTool::GetAffectedImageSliceAs2DImage( positionEvent, image );
00121
00122 if ( m_WorkingSlice.IsNull() )
00123 {
00124 MITK_ERROR << "Unable to extract slice." << std::endl;
00125 return false;
00126 }
00127
00128 CorrectorAlgorithm::Pointer algorithm = CorrectorAlgorithm::New();
00129 algorithm->SetInput( m_WorkingSlice );
00130 algorithm->SetContour( FeedbackContourTool::GetFeedbackContour() );
00131 try
00132 {
00133 algorithm->UpdateLargestPossibleRegion();
00134 }
00135 catch ( std::exception& e )
00136 {
00137 MITK_ERROR << "Caught exception '" << e.what() << "'" << std::endl;
00138 }
00139
00140
00141
00142 OverwriteSliceImageFilter::Pointer slicewriter = OverwriteSliceImageFilter::New();
00143 slicewriter->SetInput( image );
00144 slicewriter->SetCreateUndoInformation( true );
00145 slicewriter->SetSliceImage( algorithm->GetOutput() );
00146 slicewriter->SetSliceDimension( affectedDimension );
00147 slicewriter->SetSliceIndex( affectedSlice );
00148 slicewriter->SetTimeStep( positionEvent->GetSender()->GetTimeStep( image ) );
00149 slicewriter->Update();
00150
00151
00152 assert( positionEvent->GetSender()->GetRenderWindow() );
00153 mitk::RenderingManager::GetInstance()->RequestUpdate( positionEvent->GetSender()->GetRenderWindow() );
00154 }
00155 else
00156 {
00157 InteractiveSegmentationBugMessage( "FeedbackContourTool could not determine which slice of the image you are drawing on." );
00158 }
00159
00160 return true;
00161 }
00162