Simple contour filling tool. More...
#include <mitkContourTool.h>
Public Types | |
typedef ContourTool | Self |
typedef FeedbackContourTool | Superclass |
typedef itk::SmartPointer< Self > | Pointer |
typedef itk::SmartPointer < const Self > | ConstPointer |
Public Member Functions | |
virtual const char * | GetClassName () const |
Protected Member Functions | |
ContourTool (int paintingPixelValue=1) | |
virtual | ~ContourTool () |
virtual void | Activated () |
Called when the tool gets activated (registered to mitk::GlobalInteraction). | |
virtual void | Deactivated () |
Called when the tool gets deactivated (unregistered from mitk::GlobalInteraction). | |
virtual bool | OnMousePressed (Action *, const StateEvent *) |
virtual bool | OnMouseMoved (Action *, const StateEvent *) |
virtual bool | OnMouseReleased (Action *, const StateEvent *) |
virtual bool | OnInvertLogic (Action *, const StateEvent *) |
Protected Attributes | |
int | m_PaintingPixelValue |
Simple contour filling tool.
Fills a visible contour (from FeedbackContourTool) during mouse dragging. When the mouse button is released, ContourTool tries to extract a slice from the working image and fill in the (filled) contour as a binary image.
The painting "color" is defined by m_PaintingPixelValue, which is set in the constructor (by sub-classes) or during some event (e.g. in OnInvertLogic - when CTRL is pressed).
$Author$
Definition at line 51 of file mitkContourTool.h.
typedef itk::SmartPointer<const Self> mitk::ContourTool::ConstPointer |
Reimplemented from mitk::FeedbackContourTool.
Reimplemented in mitk::AddContourTool, and mitk::SubtractContourTool.
Definition at line 55 of file mitkContourTool.h.
typedef itk::SmartPointer<Self> mitk::ContourTool::Pointer |
Reimplemented from mitk::FeedbackContourTool.
Reimplemented in mitk::AddContourTool, and mitk::SubtractContourTool.
Definition at line 55 of file mitkContourTool.h.
typedef ContourTool mitk::ContourTool::Self |
Reimplemented from mitk::FeedbackContourTool.
Reimplemented in mitk::AddContourTool, and mitk::SubtractContourTool.
Definition at line 55 of file mitkContourTool.h.
Reimplemented from mitk::FeedbackContourTool.
Reimplemented in mitk::AddContourTool, and mitk::SubtractContourTool.
Definition at line 55 of file mitkContourTool.h.
mitk::ContourTool::ContourTool | ( | int | paintingPixelValue = 1 ) |
[protected] |
Definition at line 27 of file mitkContourTool.cpp.
:FeedbackContourTool("PressMoveReleaseWithCTRLInversion"), m_PaintingPixelValue(paintingPixelValue) { }
mitk::ContourTool::~ContourTool | ( | ) | [protected, virtual] |
Definition at line 33 of file mitkContourTool.cpp.
{ }
void mitk::ContourTool::Activated | ( | ) | [protected, virtual] |
Called when the tool gets activated (registered to mitk::GlobalInteraction).
Derived tools should call their parents implementation.
Reimplemented from mitk::Tool.
Definition at line 37 of file mitkContourTool.cpp.
{ Superclass::Activated(); }
void mitk::ContourTool::Deactivated | ( | ) | [protected, virtual] |
Called when the tool gets deactivated (unregistered from mitk::GlobalInteraction).
Derived tools should call their parents implementation.
Reimplemented from mitk::Tool.
Definition at line 42 of file mitkContourTool.cpp.
{ Superclass::Deactivated(); }
virtual const char* mitk::ContourTool::GetClassName | ( | ) | const [virtual] |
Reimplemented from mitk::FeedbackContourTool.
Reimplemented in mitk::AddContourTool, and mitk::SubtractContourTool.
bool mitk::ContourTool::OnInvertLogic | ( | Action * | action, |
const StateEvent * | stateEvent | ||
) | [protected, virtual] |
Called when the CTRL key is pressed. Will change the painting pixel value from 0 to 1 or from 1 to 0.
Reimplemented from mitk::SegTool2D.
Definition at line 177 of file mitkContourTool.cpp.
References mitk::SegTool2D::OnInvertLogic(), mitk::FeedbackContourTool::SetFeedbackContourColor(), and mitk::FeedbackContourTool::SetFeedbackContourColorDefault().
{ if (!FeedbackContourTool::OnInvertLogic(action, stateEvent)) return false; // Inversion only for 0 and 1 as painting values if (m_PaintingPixelValue == 1) { m_PaintingPixelValue = 0; FeedbackContourTool::SetFeedbackContourColor( 1.0, 0.0, 0.0 ); } else if (m_PaintingPixelValue == 0) { m_PaintingPixelValue = 1; FeedbackContourTool::SetFeedbackContourColorDefault(); } return true; }
bool mitk::ContourTool::OnMouseMoved | ( | Action * | action, |
const StateEvent * | stateEvent | ||
) | [protected, virtual] |
Insert the point to the feedback contour.
Reimplemented from mitk::SegTool2D.
Definition at line 71 of file mitkContourTool.cpp.
References mitk::Contour::AddVertex(), mitk::StateEvent::GetEvent(), mitk::FeedbackContourTool::GetFeedbackContour(), mitk::RenderingManager::GetInstance(), mitk::BaseRenderer::GetRenderWindow(), mitk::Event::GetSender(), mitk::DisplayPositionEvent::GetWorldPosition(), mitk::SegTool2D::OnMouseMoved(), and mitk::RenderingManager::RequestUpdate().
{ if (!FeedbackContourTool::OnMouseMoved( action, stateEvent )) return false; const PositionEvent* positionEvent = dynamic_cast<const PositionEvent*>(stateEvent->GetEvent()); if (!positionEvent) return false; Contour* contour = FeedbackContourTool::GetFeedbackContour(); contour->AddVertex( positionEvent->GetWorldPosition() ); assert( positionEvent->GetSender()->GetRenderWindow() ); mitk::RenderingManager::GetInstance()->RequestUpdate( positionEvent->GetSender()->GetRenderWindow() ); return true; }
bool mitk::ContourTool::OnMousePressed | ( | Action * | action, |
const StateEvent * | stateEvent | ||
) | [protected, virtual] |
Just show the contour, insert the first point.
Reimplemented from mitk::SegTool2D.
Definition at line 50 of file mitkContourTool.cpp.
References mitk::Contour::AddVertex(), mitk::StateEvent::GetEvent(), mitk::FeedbackContourTool::GetFeedbackContour(), mitk::RenderingManager::GetInstance(), mitk::BaseRenderer::GetRenderWindow(), mitk::Event::GetSender(), mitk::DisplayPositionEvent::GetWorldPosition(), mitk::Contour::Initialize(), mitk::SegTool2D::OnMousePressed(), mitk::RenderingManager::RequestUpdate(), and mitk::FeedbackContourTool::SetFeedbackContourVisible().
{ if (!FeedbackContourTool::OnMousePressed( action, stateEvent )) return false; const PositionEvent* positionEvent = dynamic_cast<const PositionEvent*>(stateEvent->GetEvent()); if (!positionEvent) return false; Contour* contour = FeedbackContourTool::GetFeedbackContour(); contour->Initialize(); contour->AddVertex( positionEvent->GetWorldPosition() ); FeedbackContourTool::SetFeedbackContourVisible(true); assert( positionEvent->GetSender()->GetRenderWindow() ); mitk::RenderingManager::GetInstance()->RequestUpdate( positionEvent->GetSender()->GetRenderWindow() ); return true; }
bool mitk::ContourTool::OnMouseReleased | ( | Action * | action, |
const StateEvent * | stateEvent | ||
) | [protected, virtual] |
Close the contour, project it to the image slice and fill it in 2D.
Reimplemented from mitk::SegTool2D.
Definition at line 90 of file mitkContourTool.cpp.
References mitk::SegTool2D::DetermineAffectedImageSlice(), mitk::FeedbackContourTool::FillContourInSlice(), mitk::SegTool2D::GetAffectedImageSliceAs2DImage(), mitk::BaseRenderer::GetCurrentWorldGeometry2D(), mitk::StateEvent::GetEvent(), mitk::FeedbackContourTool::GetFeedbackContour(), mitk::RenderingManager::GetInstance(), mitk::BaseRenderer::GetRenderWindow(), mitk::Event::GetSender(), mitk::BaseRenderer::GetTimeStep(), MITK_ERROR, mitk::OverwriteSliceImageFilter::New(), mitk::SegTool2D::OnMouseReleased(), mitk::FeedbackContourTool::ProjectContourTo2DSlice(), mitk::RenderingManager::RequestUpdate(), and mitk::FeedbackContourTool::SetFeedbackContourVisible().
{ // 1. Hide the feedback contour, find out which slice the user clicked, find out which slice of the toolmanager's working image corresponds to that FeedbackContourTool::SetFeedbackContourVisible(false); const PositionEvent* positionEvent = dynamic_cast<const PositionEvent*>(stateEvent->GetEvent()); if (!positionEvent) return false; assert( positionEvent->GetSender()->GetRenderWindow() ); mitk::RenderingManager::GetInstance()->RequestUpdate( positionEvent->GetSender()->GetRenderWindow() ); if (!FeedbackContourTool::OnMouseReleased( action, stateEvent )) return false; DataNode* workingNode( m_ToolManager->GetWorkingData(0) ); if (!workingNode) return false; Image* image = dynamic_cast<Image*>(workingNode->GetData()); const PlaneGeometry* planeGeometry( dynamic_cast<const PlaneGeometry*> (positionEvent->GetSender()->GetCurrentWorldGeometry2D() ) ); if ( !image || !planeGeometry ) return false; int affectedDimension( -1 ); int affectedSlice( -1 ); if ( SegTool2D::DetermineAffectedImageSlice( image, planeGeometry, affectedDimension, affectedSlice ) ) { // 2. Slice is known, now we try to get it as a 2D image and project the contour into index coordinates of this slice Image::Pointer slice = SegTool2D::GetAffectedImageSliceAs2DImage( positionEvent, image ); if ( slice.IsNull() ) { MITK_ERROR << "Unable to extract slice." << std::endl; return false; } /* DataNode::Pointer debugNode = DataNode::New(); debugNode->SetData( slice ); debugNode->SetProperty( "name", StringProperty::New("extracted slice") ); debugNode->SetProperty( "color", ColorProperty::New(1.0, 0.0, 0.0) ); debugNode->SetProperty( "layer", FloatProperty::New(100) ); m_ToolManager->GetDataStorage()->Add( debugNode ); */ Contour* feedbackContour( FeedbackContourTool::GetFeedbackContour() ); Contour::Pointer projectedContour = FeedbackContourTool::ProjectContourTo2DSlice( slice, feedbackContour, true, false ); // true: actually no idea why this is neccessary, but it works :-( // false: don't constrain the contour to the image's inside /* Contour::Pointer back = FeedbackContourTool::BackProjectContourFrom2DSlice( slice, projectedContour, true ); // true: actually no idea why this is neccessary, but it works :-( for (unsigned int idx = 0; idx < back->GetNumberOfPoints(); ++idx) { Point3D before = feedbackContour->GetPoints()->ElementAt(idx); Point3D inbtw = projectedContour->GetPoints()->ElementAt(idx); Point3D after = back->GetPoints()->ElementAt(idx); MITK_DEBUG << "before " << before << " zwischen " << inbtw << " after " << after; } */ if (projectedContour.IsNull()) return false; FeedbackContourTool::FillContourInSlice( projectedContour, slice, m_PaintingPixelValue ); // 5. Write the modified 2D working data slice back into the image OverwriteSliceImageFilter::Pointer slicewriter = OverwriteSliceImageFilter::New(); slicewriter->SetInput( image ); slicewriter->SetCreateUndoInformation( true ); slicewriter->SetSliceImage( slice ); slicewriter->SetSliceDimension( affectedDimension ); slicewriter->SetSliceIndex( affectedSlice ); slicewriter->SetTimeStep( positionEvent->GetSender()->GetTimeStep( image ) ); slicewriter->Update(); // 6. Make sure the result is drawn again --> is visible then. assert( positionEvent->GetSender()->GetRenderWindow() ); mitk::RenderingManager::GetInstance()->RequestUpdate( positionEvent->GetSender()->GetRenderWindow() ); } else { InteractiveSegmentationBugMessage( "FeedbackContourTool could not determine which slice of the image you are drawing on." ); } return true; }
int mitk::ContourTool::m_PaintingPixelValue [protected] |
Definition at line 71 of file mitkContourTool.h.