Public Types | Public Member Functions | Public Attributes | Protected Member Functions | Protected Attributes | Friends

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

Base class of all tools used by mitk::ToolManager. More...

#include <mitkTool.h>

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

List of all members.

Public Types

typedef unsigned char DefaultSegmentationDataType
typedef Tool Self
typedef StateMachine Superclass
typedef itk::SmartPointer< SelfPointer
typedef itk::SmartPointer
< const Self
ConstPointer

Public Member Functions

virtual const char * GetClassName () const
virtual const char ** GetXPM () const =0
 Returns an icon in the XPM format.
virtual const char * GetName () const =0
 Returns the name of this tool. Make it short!
virtual const char * GetGroup () const
 Name of a group.
virtual itk::Object::Pointer GetGUI (const std::string &toolkitPrefix, const std::string &toolkitPostfix)
 Interface for GUI creation.
virtual
NodePredicateBase::ConstPointer 
GetReferenceDataPreference () const
virtual
NodePredicateBase::ConstPointer 
GetWorkingDataPreference () const
DataNode::Pointer CreateEmptySegmentationNode (Image *original, const std::string &organName, const mitk::Color &color)
DataNode::Pointer CreateSegmentationNode (Image *image, const std::string &organName, const mitk::Color &color)
virtual bool GetSupportRoi ()
virtual void SetSupportRoi (bool _arg)
virtual void SupportRoiOn ()
virtual void SupportRoiOff ()

Public Attributes

Message GUIProcessEventsMessage
 To let GUI process new events (e.g. qApp->processEvents() )
Message1< std::string > ErrorMessage
 To send error messages (to be shown by some GUI)
Message1< std::string > GeneralMessage
 To send general messages (to be shown by some GUI)

Protected Member Functions

virtual void SetToolManager (ToolManager *)
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).
 Tool ()
 Tool (const char *)
virtual ~Tool ()

Protected Attributes

ToolManagerm_ToolManager
bool m_SupportRoi

Friends

class ToolManager

Detailed Description

Base class of all tools used by mitk::ToolManager.

See also:
ToolManager
SegTool2D

There is a separate page describing the QmitkInteractiveSegmentationTechnicalPage.

Every tool is a mitk::StateMachine, which can follow any transition pattern that it likes. One important thing to know is, that every derived tool should always call SuperClass::Deactivated() in its own implementation of Deactivated, because mitk::Tool resets the StateMachine in this method. Only if you are very sure that you covered all possible things that might happen to your own tool, you should consider not to reset the StateMachine from time to time.

To learn about the MITK implementation of state machines in general, have a look at Interaction and Undo/Redo Concepts.

To derive a non-abstract tool, you inherit from mitk::Tool (or some other base class further down the inheritance tree), and in your own parameterless constructor (that is called from the itkNewMacro that you use) you pass a StateMachine pattern name to the superclass. Names for valid patterns can be found in StateMachine.xml (which might be enhanced by you).

You have to implement at least GetXPM() and GetName() to provide some identification.

Each Tool knows its ToolManager, which can provide the data that the tool should work on.

Warning:
Only to be instantiated by mitk::ToolManager (because SetToolManager has to be called). All other uses are unsupported.

$Author$

Definition at line 76 of file mitkTool.h.


Member Typedef Documentation

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

Definition at line 80 of file mitkTool.h.

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

Constructor & Destructor Documentation

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

Definition at line 26 of file mitkTool.cpp.

: StateMachine(type),
  m_SupportRoi(false),
  // for reference images
  m_PredicateImages(NodePredicateDataType::New("Image")),
  m_PredicateDim3(NodePredicateDimension::New(3, 1)),
  m_PredicateDim4(NodePredicateDimension::New(4, 1)),
  m_PredicateDimension( mitk::NodePredicateOr::New(m_PredicateDim3, m_PredicateDim4) ),
  m_PredicateImage3D( NodePredicateAnd::New(m_PredicateImages, m_PredicateDimension) ),

  m_PredicateBinary(NodePredicateProperty::New("binary", BoolProperty::New(true))),
  m_PredicateNotBinary( NodePredicateNot::New(m_PredicateBinary) ),

  m_PredicateSegmentation(NodePredicateProperty::New("segmentation", BoolProperty::New(true))),
  m_PredicateNotSegmentation( NodePredicateNot::New(m_PredicateSegmentation) ),
  
  m_PredicateHelper(NodePredicateProperty::New("helper object", BoolProperty::New(true))),
  m_PredicateNotHelper( NodePredicateNot::New(m_PredicateHelper) ),
  
  m_PredicateImageColorful( NodePredicateAnd::New(m_PredicateNotBinary, m_PredicateNotSegmentation) ),

  m_PredicateImageColorfulNotHelper( NodePredicateAnd::New(m_PredicateImageColorful, m_PredicateNotHelper) ),
  
  m_PredicateReference( NodePredicateAnd::New(m_PredicateImage3D, m_PredicateImageColorfulNotHelper) ),

  // for working image
  m_IsSegmentationPredicate(NodePredicateAnd::New(NodePredicateOr::New(m_PredicateBinary, m_PredicateSegmentation), m_PredicateNotHelper))
{
}
mitk::Tool::~Tool (  ) [protected, virtual]

Definition at line 56 of file mitkTool.cpp.

{
}

Member Function Documentation

void mitk::Tool::Activated (  ) [protected, virtual]

Called when the tool gets activated (registered to mitk::GlobalInteraction).

Derived tools should call their parents implementation.

Reimplemented in mitk::BinaryThresholdTool, mitk::BinaryThresholdULTool, mitk::ContourTool, mitk::CorrectorTool2D, mitk::MorphologicTool, mitk::PaintbrushTool, mitk::RegionGrowingTool, mitk::SegmentationsProcessingTool, and mitk::SetRegionTool.

Definition at line 70 of file mitkTool.cpp.

{
}
mitk::DataNode::Pointer mitk::Tool::CreateEmptySegmentationNode ( Image original,
const std::string &  organName,
const mitk::Color color 
)

Definition at line 116 of file mitkTool.cpp.

References mitk::TimeSlicedGeometry::Clone(), ErrorMessage, mitk::Image::GetDimension(), mitk::Image::GetDimensions(), mitk::BaseData::GetTimeSlicedGeometry(), and mitk::Image::New().

Referenced by QmitkSegmentationView::CreateNewSegmentation(), mitk::BinaryThresholdULTool::CreateNewSegmentationFromThreshold(), and mitk::BinaryThresholdTool::CreateNewSegmentationFromThreshold().

{
  // we NEED a reference image for size etc.
  if (!original) return NULL;

  // actually create a new empty segmentation
  PixelType pixelType( typeid(DefaultSegmentationDataType) );
  Image::Pointer segmentation = Image::New();
 
  segmentation->Initialize( pixelType, original->GetDimension(), original->GetDimensions() );

  unsigned int byteSize = sizeof(DefaultSegmentationDataType);
  for (unsigned int dim = 0; dim < segmentation->GetDimension(); ++dim) 
  {
    byteSize *= segmentation->GetDimension(dim);
  }
  memset( segmentation->GetData(), 0, byteSize );

  if (original->GetTimeSlicedGeometry() )
  {
    AffineGeometryFrame3D::Pointer originalGeometryAGF = original->GetTimeSlicedGeometry()->Clone();
    TimeSlicedGeometry::Pointer originalGeometry = dynamic_cast<TimeSlicedGeometry*>( originalGeometryAGF.GetPointer() );
    segmentation->SetGeometry( originalGeometry );
  }
  else
  {
    Tool::ErrorMessage("Original image does not have a 'Time sliced geometry'! Cannot create a segmentation.");
    return NULL;
  }

  return CreateSegmentationNode( segmentation, organName, color );
}
mitk::DataNode::Pointer mitk::Tool::CreateSegmentationNode ( Image image,
const std::string &  organName,
const mitk::Color color 
)

Definition at line 149 of file mitkTool.cpp.

References mitk::VtkResliceInterpolationProperty::New(), mitk::FloatProperty::New(), mitk::LevelWindowProperty::New(), mitk::IntProperty::New(), mitk::ColorProperty::New(), mitk::BoolProperty::New(), mitk::StringProperty::New(), and mitk::DataNode::New().

{
  if (!image) return NULL;

  // decorate the datatreenode with some properties
  DataNode::Pointer segmentationNode = DataNode::New();
  segmentationNode->SetData( image );

  // name
  segmentationNode->SetProperty( "name", StringProperty::New( organName ) );

  // visualization properties
  segmentationNode->SetProperty( "binary", BoolProperty::New(true) );
  segmentationNode->SetProperty( "color", ColorProperty::New(color) );
  segmentationNode->SetProperty( "texture interpolation", BoolProperty::New(false) );
  segmentationNode->SetProperty( "layer", IntProperty::New(10) );
  segmentationNode->SetProperty( "levelwindow", LevelWindowProperty::New( LevelWindow(0.5, 1) ) );
  segmentationNode->SetProperty( "opacity", FloatProperty::New(0.3) );
  segmentationNode->SetProperty( "segmentation", BoolProperty::New(true) );
  segmentationNode->SetProperty( "reslice interpolation", VtkResliceInterpolationProperty::New() ); // otherwise -> segmentation appears in 2 slices sometimes (only visual effect, not different data)
  // For MITK-3M3 release, the volume of all segmentations should be shown
  segmentationNode->SetProperty( "showVolume", BoolProperty::New( true ) );
  
  return segmentationNode;
}
void mitk::Tool::Deactivated (  ) [protected, virtual]

Called when the tool gets deactivated (unregistered from mitk::GlobalInteraction).

Derived tools should call their parents implementation.

Reimplemented in mitk::BinaryThresholdTool, mitk::BinaryThresholdULTool, mitk::ContourTool, mitk::CorrectorTool2D, mitk::MorphologicTool, mitk::PaintbrushTool, mitk::RegionGrowingTool, mitk::SegmentationsProcessingTool, and mitk::SetRegionTool.

Definition at line 74 of file mitkTool.cpp.

References mitk::StateMachine::ResetStatemachineToStartState().

{
  StateMachine::ResetStatemachineToStartState(); // forget about the past
}
virtual const char* mitk::Tool::GetClassName (  ) const [virtual]
const char * mitk::Tool::GetGroup (  ) const [virtual]

Name of a group.

You can group several tools by assigning a group name. Graphical tool selectors might use this information to group tools. (What other reason could there be?)

Reimplemented in mitk::AutoSegmentationTool, mitk::MorphologicTool, and mitk::SegmentationsProcessingTool.

Definition at line 60 of file mitkTool.cpp.

Referenced by QmitkToolWorkingDataSelectionBox::GetAllNodes(), QmitkToolReferenceDataSelectionBox::GetAllPossibleReferenceImagesPredicate(), QmitkToolSelectionBox::RecreateButtons(), and QmitkToolSelectionBox::SetOrUnsetButtonForActiveTool().

{
  return "default";
}
itk::Object::Pointer mitk::Tool::GetGUI ( const std::string &  toolkitPrefix,
const std::string &  toolkitPostfix 
) [virtual]

Interface for GUI creation.

This is the basic interface for creation of a GUI object belonging to one tool.

Tools that support a GUI (e.g. for display/editing of parameters) should follow some rules:

  • A Tool and its GUI are two separate classes
  • There may be several instances of a GUI at the same time.
  • mitk::Tool is toolkit (Qt, wxWidgets, etc.) independent, the GUI part is of course dependent
  • The GUI part inherits both from itk::Object and some GUI toolkit class
  • The GUI class name HAS to be constructed like "toolkitPrefix" tool->GetClassName() + "toolkitPostfix", e.g. MyTool -> wxMyToolGUI
  • For each supported toolkit there is a base class for tool GUIs, which contains some convenience methods
  • Tools notify the GUI about changes using ITK events. The GUI must observe interesting events.
  • The GUI base class may convert all ITK events to the GUI toolkit's favoured messaging system (Qt -> signals)
  • Calling methods of a tool by its GUI is done directly. In some cases GUIs don't want to be notified by the tool when they cause a change in a tool. There is a macro CALL_WITHOUT_NOTICE(method()), which will temporarily disable all notifications during a method call.

Definition at line 79 of file mitkTool.cpp.

References MITK_ERROR.

Referenced by QmitkToolSelectionBox::SetOrUnsetButtonForActiveTool(), and QmitkSegmentationPostProcessing::ThresholdImage().

{
  itk::Object::Pointer object;

  std::string classname = this->GetNameOfClass();
  std::string guiClassname = toolkitPrefix + classname + toolkitPostfix;

  std::list<itk::LightObject::Pointer> allGUIs = itk::ObjectFactoryBase::CreateAllInstance(guiClassname.c_str());
  for( std::list<itk::LightObject::Pointer>::iterator iter = allGUIs.begin();
       iter != allGUIs.end();
       ++iter )
  {
    if (object.IsNull())
    {
      object = dynamic_cast<itk::Object*>( iter->GetPointer() );
    }
    else
    {
      MITK_ERROR << "There is more than one GUI for " << classname << " (several factories claim ability to produce a " << guiClassname << " ) " << std::endl;
      return NULL; // people should see and fix this error
    }
  }

  return object;
}
virtual const char* mitk::Tool::GetName (  ) const [pure virtual]
mitk::NodePredicateBase::ConstPointer mitk::Tool::GetReferenceDataPreference (  ) const [virtual]

Definition at line 105 of file mitkTool.cpp.

Referenced by QmitkToolReferenceDataSelectionBox::GetAllPossibleReferenceImagesPredicate().

{
  return m_PredicateReference.GetPointer();
}
virtual bool mitk::Tool::GetSupportRoi (  ) [virtual]
mitk::NodePredicateBase::ConstPointer mitk::Tool::GetWorkingDataPreference (  ) const [virtual]

Definition at line 111 of file mitkTool.cpp.

Referenced by QmitkToolWorkingDataSelectionBox::GetAllNodes().

{
  return m_IsSegmentationPredicate.GetPointer();
}
virtual const char** mitk::Tool::GetXPM (  ) const [pure 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.

Implemented in mitk::AddContourTool, mitk::AutoCropTool, mitk::BinaryThresholdTool, mitk::BinaryThresholdULTool, mitk::CalculateGrayValueStatisticsTool, mitk::CalculateVolumetryTool, mitk::ClosingTool, mitk::CorrectorTool2D, mitk::CreateSurfaceTool, mitk::DilateTool, mitk::DrawPaintbrushTool, mitk::ErasePaintbrushTool, mitk::EraseRegionTool, mitk::ErodeTool, mitk::FillRegionTool, mitk::OpeningTool, mitk::RegionGrowingTool, and mitk::SubtractContourTool.

Referenced by QmitkToolSelectionBox::RecreateButtons().

virtual void mitk::Tool::SetSupportRoi ( bool  _arg ) [virtual]
void mitk::Tool::SetToolManager ( ToolManager manager ) [protected, virtual]

Definition at line 65 of file mitkTool.cpp.

{
  m_ToolManager = manager;
}
virtual void mitk::Tool::SupportRoiOff (  ) [virtual]
virtual void mitk::Tool::SupportRoiOn (  ) [virtual]

Friends And Related Function Documentation

friend class ToolManager [friend]

Definition at line 153 of file mitkTool.h.


Member Data Documentation

To send general messages (to be shown by some GUI)

Definition at line 95 of file mitkTool.h.

Referenced by QmitkToolSelectionBox::RecreateButtons().

To let GUI process new events (e.g. qApp->processEvents() )

Definition at line 85 of file mitkTool.h.

Referenced by QmitkToolSelectionBox::RecreateButtons().

bool mitk::Tool::m_SupportRoi [protected]

Definition at line 182 of file mitkTool.h.

Definition at line 180 of file mitkTool.h.


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