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 "mitkContourTool.h"
00019
00020 #include "mitkToolManager.h"
00021 #include "mitkOverwriteSliceImageFilter.h"
00022
00023 #include "mitkBaseRenderer.h"
00024 #include "mitkRenderingManager.h"
00025
00026
00027 mitk::ContourTool::ContourTool(int paintingPixelValue)
00028 :FeedbackContourTool("PressMoveReleaseWithCTRLInversion"),
00029 m_PaintingPixelValue(paintingPixelValue)
00030 {
00031 }
00032
00033 mitk::ContourTool::~ContourTool()
00034 {
00035 }
00036
00037 void mitk::ContourTool::Activated()
00038 {
00039 Superclass::Activated();
00040 }
00041
00042 void mitk::ContourTool::Deactivated()
00043 {
00044 Superclass::Deactivated();
00045 }
00046
00050 bool mitk::ContourTool::OnMousePressed (Action* action, const StateEvent* stateEvent)
00051 {
00052 if (!FeedbackContourTool::OnMousePressed( action, stateEvent )) return false;
00053
00054 const PositionEvent* positionEvent = dynamic_cast<const PositionEvent*>(stateEvent->GetEvent());
00055 if (!positionEvent) return false;
00056
00057 Contour* contour = FeedbackContourTool::GetFeedbackContour();
00058 contour->Initialize();
00059 contour->AddVertex( positionEvent->GetWorldPosition() );
00060
00061 FeedbackContourTool::SetFeedbackContourVisible(true);
00062 assert( positionEvent->GetSender()->GetRenderWindow() );
00063 mitk::RenderingManager::GetInstance()->RequestUpdate( positionEvent->GetSender()->GetRenderWindow() );
00064
00065 return true;
00066 }
00067
00071 bool mitk::ContourTool::OnMouseMoved (Action* action, const StateEvent* stateEvent)
00072 {
00073 if (!FeedbackContourTool::OnMouseMoved( action, stateEvent )) return false;
00074
00075 const PositionEvent* positionEvent = dynamic_cast<const PositionEvent*>(stateEvent->GetEvent());
00076 if (!positionEvent) return false;
00077
00078 Contour* contour = FeedbackContourTool::GetFeedbackContour();
00079 contour->AddVertex( positionEvent->GetWorldPosition() );
00080
00081 assert( positionEvent->GetSender()->GetRenderWindow() );
00082 mitk::RenderingManager::GetInstance()->RequestUpdate( positionEvent->GetSender()->GetRenderWindow() );
00083
00084 return true;
00085 }
00086
00090 bool mitk::ContourTool::OnMouseReleased(Action* action, const StateEvent* stateEvent)
00091 {
00092
00093 FeedbackContourTool::SetFeedbackContourVisible(false);
00094
00095 const PositionEvent* positionEvent = dynamic_cast<const PositionEvent*>(stateEvent->GetEvent());
00096 if (!positionEvent) return false;
00097
00098 assert( positionEvent->GetSender()->GetRenderWindow() );
00099 mitk::RenderingManager::GetInstance()->RequestUpdate( positionEvent->GetSender()->GetRenderWindow() );
00100
00101 if (!FeedbackContourTool::OnMouseReleased( action, stateEvent )) return false;
00102
00103 DataNode* workingNode( m_ToolManager->GetWorkingData(0) );
00104 if (!workingNode) return false;
00105
00106 Image* image = dynamic_cast<Image*>(workingNode->GetData());
00107 const PlaneGeometry* planeGeometry( dynamic_cast<const PlaneGeometry*> (positionEvent->GetSender()->GetCurrentWorldGeometry2D() ) );
00108 if ( !image || !planeGeometry ) return false;
00109
00110 int affectedDimension( -1 );
00111 int affectedSlice( -1 );
00112 if ( SegTool2D::DetermineAffectedImageSlice( image, planeGeometry, affectedDimension, affectedSlice ) )
00113 {
00114
00115 Image::Pointer slice = SegTool2D::GetAffectedImageSliceAs2DImage( positionEvent, image );
00116
00117 if ( slice.IsNull() )
00118 {
00119 MITK_ERROR << "Unable to extract slice." << std::endl;
00120 return false;
00121 }
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132 Contour* feedbackContour( FeedbackContourTool::GetFeedbackContour() );
00133 Contour::Pointer projectedContour = FeedbackContourTool::ProjectContourTo2DSlice( slice, feedbackContour, true, false );
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147 if (projectedContour.IsNull()) return false;
00148
00149 FeedbackContourTool::FillContourInSlice( projectedContour, slice, m_PaintingPixelValue );
00150
00151
00152 OverwriteSliceImageFilter::Pointer slicewriter = OverwriteSliceImageFilter::New();
00153 slicewriter->SetInput( image );
00154 slicewriter->SetCreateUndoInformation( true );
00155 slicewriter->SetSliceImage( slice );
00156 slicewriter->SetSliceDimension( affectedDimension );
00157 slicewriter->SetSliceIndex( affectedSlice );
00158 slicewriter->SetTimeStep( positionEvent->GetSender()->GetTimeStep( image ) );
00159 slicewriter->Update();
00160
00161
00162 assert( positionEvent->GetSender()->GetRenderWindow() );
00163
00164 mitk::RenderingManager::GetInstance()->RequestUpdate( positionEvent->GetSender()->GetRenderWindow() );
00165 }
00166 else
00167 {
00168 InteractiveSegmentationBugMessage( "FeedbackContourTool could not determine which slice of the image you are drawing on." );
00169 }
00170
00171 return true;
00172 }
00173
00177 bool mitk::ContourTool::OnInvertLogic(Action* action, const StateEvent* stateEvent)
00178 {
00179 if (!FeedbackContourTool::OnInvertLogic(action, stateEvent)) return false;
00180
00181
00182 if (m_PaintingPixelValue == 1)
00183 {
00184 m_PaintingPixelValue = 0;
00185 FeedbackContourTool::SetFeedbackContourColor( 1.0, 0.0, 0.0 );
00186 }
00187 else if (m_PaintingPixelValue == 0)
00188 {
00189 m_PaintingPixelValue = 1;
00190 FeedbackContourTool::SetFeedbackContourColorDefault();
00191 }
00192
00193 return true;
00194 }
00195