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

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

Abstract base class for segmentation tools. More...

#include <mitkSegTool2D.h>

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

List of all members.

Public Types

typedef SegTool2D Self
typedef Tool Superclass
typedef itk::SmartPointer< SelfPointer
typedef itk::SmartPointer
< const Self
ConstPointer

Public Member Functions

virtual const char * GetClassName () const

Static Public Member Functions

static bool DetermineAffectedImageSlice (const Image *image, const PlaneGeometry *plane, int &affectedDimension, int &affectedSlice)
 Calculates for a given Image and PlaneGeometry, which slice of the image (in index corrdinates) is meant by the plane.

Protected Member Functions

 SegTool2D ()
 SegTool2D (const char *)
virtual ~SegTool2D ()
virtual bool OnMousePressed (Action *, const StateEvent *)
virtual bool OnMouseMoved (Action *, const StateEvent *)
virtual bool OnMouseReleased (Action *, const StateEvent *)
virtual bool OnInvertLogic (Action *, const StateEvent *)
Image::Pointer GetAffectedImageSliceAs2DImage (const PositionEvent *, const Image *image)
 Extract the slice of an image that the user just scribbles on.
Image::Pointer GetAffectedWorkingSlice (const PositionEvent *)
 Extract the slice of the currently selected working image that the user just scribbles on.
Image::Pointer GetAffectedReferenceSlice (const PositionEvent *)
 Extract the slice of the currently selected reference image that the user just scribbles on.
void InteractiveSegmentationBugMessage (const std::string &message)

Detailed Description

Abstract base class for segmentation tools.

See also:
Tool

Implements 2D segmentation specific helper methods, that might be of use to all kind of 2D segmentation tools. At the moment these are:

SegTool2D tries to structure the interaction a bit. If you pass "PressMoveRelease" as the interaction type of your derived tool, you might implement the methods OnMousePressed, OnMouseMoved, and OnMouseReleased. Yes, your guess about when they are called is correct.

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

$Author$

Definition at line 55 of file mitkSegTool2D.h.


Member Typedef Documentation

typedef itk::SmartPointer<const Self> mitk::SegTool2D::ConstPointer
typedef itk::SmartPointer<Self> mitk::SegTool2D::Pointer

Constructor & Destructor Documentation

mitk::SegTool2D::SegTool2D (  ) [protected]
mitk::SegTool2D::SegTool2D ( const char *  type ) [protected]

Definition at line 30 of file mitkSegTool2D.cpp.

References CONNECT_ACTION, OnInvertLogic(), OnMouseMoved(), OnMousePressed(), and OnMouseReleased().

:Tool(type),
 m_LastEventSender(NULL),
 m_LastEventSlice(0)
{
  // great magic numbers
  CONNECT_ACTION( 80, OnMousePressed );
  CONNECT_ACTION( 90, OnMouseMoved );
  CONNECT_ACTION( 42, OnMouseReleased );
  CONNECT_ACTION( 49014, OnInvertLogic );
}
mitk::SegTool2D::~SegTool2D (  ) [protected, virtual]

Definition at line 42 of file mitkSegTool2D.cpp.

{
}

Member Function Documentation

bool mitk::SegTool2D::DetermineAffectedImageSlice ( const Image image,
const PlaneGeometry plane,
int &  affectedDimension,
int &  affectedSlice 
) [static]

Calculates for a given Image and PlaneGeometry, which slice of the image (in index corrdinates) is meant by the plane.

Returns:
false, if no slice direction seems right (e.g. rotated planes)
Parameters:
affectedDimensionThe image dimension, which is constant for all points in the plane, e.g. Transversal --> 2
affectedSliceThe index of the image slice

Definition at line 92 of file mitkSegTool2D.cpp.

References mitk::Geometry3D::GetAxisVector(), mitk::Geometry3D::GetCenter(), mitk::Image::GetDimension(), mitk::BaseData::GetGeometry(), mitk::PlaneGeometry::GetNormal(), mitk::SlicedData::GetSlicedGeometry(), MITK_DEBUG, mitk::Geometry2D::Project(), ROUND, and mitk::Geometry3D::WorldToIndex().

Referenced by QmitkSlicesInterpolator::GetSliceForWindowsID(), QmitkSlicesInterpolator::Interpolate(), QmitkSegmentationView::IsRenderWindowAligned(), mitk::PaintbrushTool::OnMouseMoved(), mitk::SetRegionTool::OnMouseReleased(), mitk::RegionGrowingTool::OnMouseReleased(), mitk::CorrectorTool2D::OnMouseReleased(), and mitk::ContourTool::OnMouseReleased().

{
  assert(image);
  assert(plane);

  // compare normal of plane to the three axis vectors of the image
  Vector3D normal       = plane->GetNormal();
  Vector3D imageNormal0 = image->GetSlicedGeometry()->GetAxisVector(0);
  Vector3D imageNormal1 = image->GetSlicedGeometry()->GetAxisVector(1);
  Vector3D imageNormal2 = image->GetSlicedGeometry()->GetAxisVector(2);

  normal.Normalize();
  imageNormal0.Normalize();
  imageNormal1.Normalize();
  imageNormal2.Normalize();

  imageNormal0.Set_vnl_vector( vnl_cross_3d<ScalarType>(normal.Get_vnl_vector(),imageNormal0.Get_vnl_vector()) );
  imageNormal1.Set_vnl_vector( vnl_cross_3d<ScalarType>(normal.Get_vnl_vector(),imageNormal1.Get_vnl_vector()) );
  imageNormal2.Set_vnl_vector( vnl_cross_3d<ScalarType>(normal.Get_vnl_vector(),imageNormal2.Get_vnl_vector()) );

  double eps( 0.00001 );
  // transversal
  if ( imageNormal2.GetNorm() <= eps )
  {
    affectedDimension = 2;
  }
  // sagittal
  else if ( imageNormal1.GetNorm() <= eps )
  {
    affectedDimension = 1;
  }
  // frontal
  else if ( imageNormal0.GetNorm() <= eps )
  {
    affectedDimension = 0;
  }
  else
  {
    affectedDimension = -1; // no idea
    return false;
  }

  // determine slice number in image
  Geometry3D* imageGeometry = image->GetGeometry(0);
  Point3D testPoint = imageGeometry->GetCenter();
  Point3D projectedPoint;
  plane->Project( testPoint, projectedPoint );

  Point3D indexPoint;

  imageGeometry->WorldToIndex( projectedPoint, indexPoint );
  affectedSlice = ROUND( indexPoint[affectedDimension] );
  MITK_DEBUG << "indexPoint " << indexPoint << " affectedDimension " << affectedDimension << " affectedSlice " << affectedSlice;

  // check if this index is still within the image
  if ( affectedSlice < 0 || affectedSlice >= static_cast<int>(image->GetDimension(affectedDimension)) ) return false;
 
  return true;
}
mitk::Image::Pointer mitk::SegTool2D::GetAffectedImageSliceAs2DImage ( const PositionEvent positionEvent,
const Image image 
) [protected]

Extract the slice of an image that the user just scribbles on.

Returns:
NULL if SegTool2D is either unable to determine which slice was affected, or if there was some problem getting the image data at that position.

Definition at line 152 of file mitkSegTool2D.cpp.

References mitk::BaseRenderer::GetCurrentWorldGeometry2D(), mitk::Event::GetSender(), mitk::BaseRenderer::GetTimeStep(), and mitk::ExtractImageFilter::New().

Referenced by mitk::PaintbrushTool::OnMouseMoved(), mitk::SetRegionTool::OnMouseReleased(), mitk::CorrectorTool2D::OnMouseReleased(), and mitk::ContourTool::OnMouseReleased().

{
  if (!positionEvent) return NULL;
  
  assert( positionEvent->GetSender() ); // sure, right?
  unsigned int timeStep = positionEvent->GetSender()->GetTimeStep( image ); // get the timestep of the visible part (time-wise) of the image

  // first, we determine, which slice is affected
  const PlaneGeometry* planeGeometry( dynamic_cast<const PlaneGeometry*> (positionEvent->GetSender()->GetCurrentWorldGeometry2D() ) );

  if ( !image || !planeGeometry ) return NULL;

  int affectedDimension( -1 );
  int affectedSlice( -1 );
  if ( DetermineAffectedImageSlice( image, planeGeometry, affectedDimension, affectedSlice ) )
  {
    try
    {
      // now we extract the correct slice from the volume, resulting in a 2D image
      ExtractImageFilter::Pointer extractor= ExtractImageFilter::New();
      extractor->SetInput( image );
      extractor->SetSliceDimension( affectedDimension );
      extractor->SetSliceIndex( affectedSlice );
      extractor->SetTimeStep( timeStep );
      extractor->Update();

      // here we have a single slice that can be modified
      Image::Pointer slice = extractor->GetOutput();
      
      return slice;
    }
    catch(...)
    {
      // not working
      return NULL;
    }
  }
  else
  {
    return NULL;
  }
}
mitk::Image::Pointer mitk::SegTool2D::GetAffectedReferenceSlice ( const PositionEvent positionEvent ) [protected]

Extract the slice of the currently selected reference image that the user just scribbles on.

Returns:
NULL if SegTool2D is either unable to determine which slice was affected, or if there was some problem getting the image data at that position, or just no reference image is selected.

Definition at line 206 of file mitkSegTool2D.cpp.

Referenced by mitk::RegionGrowingTool::OnMousePressed().

{
  DataNode* referenceNode( m_ToolManager->GetReferenceData(0) );
  if ( !referenceNode ) return NULL;
  
  Image* referenceImage = dynamic_cast<Image*>(referenceNode->GetData());
  if ( !referenceImage ) return NULL;
  
  return GetAffectedImageSliceAs2DImage( positionEvent, referenceImage );
}
mitk::Image::Pointer mitk::SegTool2D::GetAffectedWorkingSlice ( const PositionEvent positionEvent ) [protected]

Extract the slice of the currently selected working image that the user just scribbles on.

Returns:
NULL if SegTool2D is either unable to determine which slice was affected, or if there was some problem getting the image data at that position, or just no working image is selected.

Definition at line 195 of file mitkSegTool2D.cpp.

Referenced by mitk::SetRegionTool::OnMousePressed(), mitk::RegionGrowingTool::OnMousePressed(), and mitk::PaintbrushTool::UpdateContour().

{
  DataNode* workingNode( m_ToolManager->GetWorkingData(0) );
  if ( !workingNode ) return NULL;
  
  Image* workingImage = dynamic_cast<Image*>(workingNode->GetData());
  if ( !workingImage ) return NULL;
  
  return GetAffectedImageSliceAs2DImage( positionEvent, workingImage );
}
virtual const char* mitk::SegTool2D::GetClassName (  ) const [virtual]
void mitk::SegTool2D::InteractiveSegmentationBugMessage ( const std::string &  message ) [protected]

Definition at line 217 of file mitkSegTool2D.cpp.

References MITK_ERROR.

{
  MITK_ERROR << "********************************************************************************" << std::endl
            << " " << message << std::endl
            << "********************************************************************************" << std::endl
            << "  " << std::endl
            << " If your image is rotated or the 2D views don't really contain the patient image, try to press the button next to the image selection. " << std::endl
            << "  " << std::endl
            << " Please file a BUG REPORT: " << std::endl
            << " http://bugs.mitk.org" << std::endl
            << " Contain the following information:" << std::endl
            << "  - What image were you working on?" << std::endl
            << "  - Which region of the image?" << std::endl
            << "  - Which tool did you use?" << std::endl
            << "  - What did you do?" << std::endl
            << "  - What happened (not)? What did you expect?" << std::endl;
}
bool mitk::SegTool2D::OnInvertLogic ( Action ,
const StateEvent stateEvent 
) [protected, virtual]

Reimplemented in mitk::ContourTool, mitk::PaintbrushTool, and mitk::SetRegionTool.

Definition at line 81 of file mitkSegTool2D.cpp.

References mitk::StateEvent::GetEvent(), and mitk::Event::GetSender().

Referenced by mitk::SetRegionTool::OnInvertLogic(), mitk::PaintbrushTool::OnInvertLogic(), mitk::ContourTool::OnInvertLogic(), and SegTool2D().

{
  const PositionEvent* positionEvent = dynamic_cast<const PositionEvent*>(stateEvent->GetEvent());
  if (!positionEvent) return false;
  
  if ( m_LastEventSender != positionEvent->GetSender() ) return false;
  if ( m_LastEventSlice  != m_LastEventSender->GetSlice() ) return false;

  return true;
}
bool mitk::SegTool2D::OnMouseMoved ( Action ,
const StateEvent stateEvent 
) [protected, virtual]

Reimplemented in mitk::ContourTool, mitk::CorrectorTool2D, mitk::PaintbrushTool, and mitk::RegionGrowingTool.

Definition at line 59 of file mitkSegTool2D.cpp.

References mitk::StateEvent::GetEvent(), and mitk::Event::GetSender().

Referenced by mitk::RegionGrowingTool::OnMouseMoved(), mitk::CorrectorTool2D::OnMouseMoved(), mitk::ContourTool::OnMouseMoved(), and SegTool2D().

{
  const PositionEvent* positionEvent = dynamic_cast<const PositionEvent*>(stateEvent->GetEvent());
  if (!positionEvent) return false;
  
  if ( m_LastEventSender != positionEvent->GetSender() ) return false;
  if ( m_LastEventSlice  != m_LastEventSender->GetSlice() ) return false;

  return true;
}
bool mitk::SegTool2D::OnMousePressed ( Action ,
const StateEvent stateEvent 
) [protected, virtual]

Reimplemented in mitk::ContourTool, mitk::CorrectorTool2D, mitk::PaintbrushTool, mitk::RegionGrowingTool, and mitk::SetRegionTool.

Definition at line 46 of file mitkSegTool2D.cpp.

References mitk::StateEvent::GetEvent(), mitk::BaseRenderer::GetMapperID(), mitk::Event::GetSender(), mitk::BaseRenderer::GetSlice(), and mitk::BaseRenderer::Standard2D.

Referenced by mitk::SetRegionTool::OnMousePressed(), mitk::RegionGrowingTool::OnMousePressed(), mitk::PaintbrushTool::OnMousePressed(), mitk::CorrectorTool2D::OnMousePressed(), mitk::ContourTool::OnMousePressed(), and SegTool2D().

{
  const PositionEvent* positionEvent = dynamic_cast<const PositionEvent*>(stateEvent->GetEvent());
  if (!positionEvent) return false;

  if ( positionEvent->GetSender()->GetMapperID() != BaseRenderer::Standard2D ) return false; // we don't want anything but 2D

  m_LastEventSender = positionEvent->GetSender();
  m_LastEventSlice = m_LastEventSender->GetSlice();

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

Reimplemented in mitk::ContourTool, mitk::CorrectorTool2D, mitk::PaintbrushTool, mitk::RegionGrowingTool, and mitk::SetRegionTool.

Definition at line 70 of file mitkSegTool2D.cpp.

References mitk::StateEvent::GetEvent(), and mitk::Event::GetSender().

Referenced by mitk::SetRegionTool::OnMouseReleased(), mitk::RegionGrowingTool::OnMouseReleased(), mitk::CorrectorTool2D::OnMouseReleased(), mitk::ContourTool::OnMouseReleased(), and SegTool2D().

{
  const PositionEvent* positionEvent = dynamic_cast<const PositionEvent*>(stateEvent->GetEvent());
  if (!positionEvent) return false;

  if ( m_LastEventSender != positionEvent->GetSender() ) return false;
  if ( m_LastEventSlice  != m_LastEventSender->GetSlice() ) return false;
  
  return true;
}

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