Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes

mitk::CorrectorTool2D Class Reference
[Interaction ClassesClasses related to InteractiveSegmentation]

Corrector tool for 2D binary segmentations. More...

#include <mitkCorrectorTool2D.h>

Inheritance diagram for mitk::CorrectorTool2D:
Inheritance graph
[legend]
Collaboration diagram for mitk::CorrectorTool2D:
Collaboration graph
[legend]

List of all members.

Public Types

typedef CorrectorTool2D Self
typedef FeedbackContourTool Superclass
typedef itk::SmartPointer< SelfPointer
typedef itk::SmartPointer
< const Self
ConstPointer

Public Member Functions

virtual const char * GetClassName () const
virtual const char ** GetXPM () const
 Returns an icon in the XPM format.
virtual const char * GetName () const
 Returns the name of this tool. Make it short!

Static Public Member Functions

static Pointer New ()

Protected Member Functions

 CorrectorTool2D (int paintingPixelValue=1)
virtual ~CorrectorTool2D ()
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 *)

Protected Attributes

int m_PaintingPixelValue
Image::Pointer m_WorkingSlice

Detailed Description

Corrector tool for 2D binary segmentations.

See also:
FeedbackContourTool
ExtractImageFilter
OverwriteSliceImageFilter

Lets the user draw a (multi-point) line and intelligently decides what to do. The underlying algorithm tests if the line begins and ends inside or outside a segmentation and either adds or subtracts a piece of segmentation.

Algorithm is implemented in CorrectorAlgorithm (so that it could be reimplemented in a more modern fashion some time).

Warning:
Only to be instantiated by mitk::ToolManager.

$Author$

Definition at line 50 of file mitkCorrectorTool2D.h.


Member Typedef Documentation

typedef itk::SmartPointer<const Self> mitk::CorrectorTool2D::ConstPointer

Reimplemented from mitk::FeedbackContourTool.

Definition at line 54 of file mitkCorrectorTool2D.h.

typedef itk::SmartPointer<Self> mitk::CorrectorTool2D::Pointer

Reimplemented from mitk::FeedbackContourTool.

Definition at line 54 of file mitkCorrectorTool2D.h.

Reimplemented from mitk::FeedbackContourTool.

Definition at line 54 of file mitkCorrectorTool2D.h.

Reimplemented from mitk::FeedbackContourTool.

Definition at line 54 of file mitkCorrectorTool2D.h.


Constructor & Destructor Documentation

mitk::CorrectorTool2D::CorrectorTool2D ( int  paintingPixelValue = 1 ) [protected]

Definition at line 32 of file mitkCorrectorTool2D.cpp.

References mitk::FeedbackContourTool::GetFeedbackContour(), and mitk::Contour::SetClosed().

:FeedbackContourTool("PressMoveRelease"),
 m_PaintingPixelValue(paintingPixelValue)
{
  GetFeedbackContour()->SetClosed( false ); // don't close the contour to a polygon
}
mitk::CorrectorTool2D::~CorrectorTool2D (  ) [protected, virtual]

Definition at line 39 of file mitkCorrectorTool2D.cpp.

{
}

Member Function Documentation

void mitk::CorrectorTool2D::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 53 of file mitkCorrectorTool2D.cpp.

void mitk::CorrectorTool2D::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 58 of file mitkCorrectorTool2D.cpp.

virtual const char* mitk::CorrectorTool2D::GetClassName (  ) const [virtual]

Reimplemented from mitk::FeedbackContourTool.

const char * mitk::CorrectorTool2D::GetName (  ) const [virtual]

Returns the name of this tool. Make it short!

This name has to fit into some kind of button in most applications, so take some time to think of a good name!

Implements mitk::Tool.

Definition at line 48 of file mitkCorrectorTool2D.cpp.

{
  return "Correction";
}
const char ** mitk::CorrectorTool2D::GetXPM (  ) const [virtual]

Returns an icon in the XPM format.

This icon has to fit into some kind of button in most applications, so make it smaller than 25x25 pixels.

XPM is e.g. supported by The Gimp. But if you open any XPM file in your text editor, you will see that you could also "draw" it with an editor.

Implements mitk::Tool.

Definition at line 43 of file mitkCorrectorTool2D.cpp.

{
  return mitkCorrectorTool2D_xpm;
}
static Pointer mitk::CorrectorTool2D::New (  ) [static]
bool mitk::CorrectorTool2D::OnMouseMoved ( Action action,
const StateEvent stateEvent 
) [protected, virtual]

Reimplemented from mitk::SegTool2D.

Definition at line 79 of file mitkCorrectorTool2D.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::CorrectorTool2D::OnMousePressed ( Action action,
const StateEvent stateEvent 
) [protected, virtual]

Reimplemented from mitk::SegTool2D.

Definition at line 63 of file mitkCorrectorTool2D.cpp.

References mitk::Contour::AddVertex(), mitk::StateEvent::GetEvent(), mitk::FeedbackContourTool::GetFeedbackContour(), mitk::DisplayPositionEvent::GetWorldPosition(), mitk::Contour::Initialize(), mitk::SegTool2D::OnMousePressed(), 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);

  return true;
}
bool mitk::CorrectorTool2D::OnMouseReleased ( Action action,
const StateEvent stateEvent 
) [protected, virtual]

Reimplemented from mitk::SegTool2D.

Definition at line 95 of file mitkCorrectorTool2D.cpp.

References mitk::SegTool2D::DetermineAffectedImageSlice(), 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::CorrectorAlgorithm::New(), mitk::SegTool2D::OnMouseReleased(), 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 ( FeedbackContourTool::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
    m_WorkingSlice = FeedbackContourTool::GetAffectedImageSliceAs2DImage( positionEvent, image );

    if ( m_WorkingSlice.IsNull() )
    {
      MITK_ERROR << "Unable to extract slice." << std::endl;
      return false;
    }

    CorrectorAlgorithm::Pointer algorithm = CorrectorAlgorithm::New();
    algorithm->SetInput( m_WorkingSlice );
    algorithm->SetContour( FeedbackContourTool::GetFeedbackContour() );
    try 
    {
      algorithm->UpdateLargestPossibleRegion();
    }
    catch ( std::exception& e )
    {
      MITK_ERROR << "Caught exception '" << e.what() << "'" << std::endl;
    }


    // 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( algorithm->GetOutput() );
    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;
}

Member Data Documentation

Definition at line 72 of file mitkCorrectorTool2D.h.

Definition at line 74 of file mitkCorrectorTool2D.h.


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines