Calculates the segmented volumes for binary images. More...
#include <mitkBinaryThresholdTool.h>
Public Types | |
typedef BinaryThresholdTool | Self |
typedef AutoSegmentationTool | Superclass |
typedef itk::SmartPointer< Self > | Pointer |
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! | |
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 void | SetThresholdValue (int value) |
virtual void | AcceptCurrentThresholdValue (const std::string &organName, const Color &color) |
virtual void | CancelThresholding () |
Static Public Member Functions | |
static Pointer | New () |
Public Attributes | |
Message2< int, int > | IntervalBordersChanged |
Message1< int > | ThresholdingValueChanged |
Protected Member Functions | |
BinaryThresholdTool () | |
virtual | ~BinaryThresholdTool () |
void | SetupPreviewNodeFor (DataNode *nodeForThresholding) |
void | CreateNewSegmentationFromThreshold (DataNode *node, const std::string &organType, const Color &color) |
void | OnRoiDataChanged () |
template<typename TPixel , unsigned int VImageDimension> | |
void | ITKThresholding (itk::Image< TPixel, VImageDimension > *originalImage, mitk::Image *segmentation, unsigned int timeStep) |
Protected Attributes | |
DataNode::Pointer | m_ThresholdFeedbackNode |
DataNode::Pointer | m_OriginalImageNode |
DataNode::Pointer | m_NodeForThresholding |
int | m_SensibleMinimumThresholdValue |
int | m_SensibleMaximumThresholdValue |
int | m_CurrentThresholdValue |
Calculates the segmented volumes for binary images.
Last contributor: $Author$
Definition at line 40 of file mitkBinaryThresholdTool.h.
typedef itk::SmartPointer<const Self> mitk::BinaryThresholdTool::ConstPointer |
Reimplemented from mitk::AutoSegmentationTool.
Definition at line 47 of file mitkBinaryThresholdTool.h.
typedef itk::SmartPointer<Self> mitk::BinaryThresholdTool::Pointer |
Reimplemented from mitk::AutoSegmentationTool.
Definition at line 47 of file mitkBinaryThresholdTool.h.
Reimplemented from mitk::AutoSegmentationTool.
Definition at line 47 of file mitkBinaryThresholdTool.h.
Reimplemented from mitk::AutoSegmentationTool.
Definition at line 47 of file mitkBinaryThresholdTool.h.
mitk::BinaryThresholdTool::BinaryThresholdTool | ( | ) | [protected] |
Definition at line 44 of file mitkBinaryThresholdTool.cpp.
References mitk::CoreObjectFactory::GetInstance(), m_ThresholdFeedbackNode, mitk::FloatProperty::New(), mitk::StringProperty::New(), mitk::LevelWindowProperty::New(), mitk::IntProperty::New(), mitk::BoolProperty::New(), mitk::ColorProperty::New(), New(), and mitk::Tool::SupportRoiOn().
:m_SensibleMinimumThresholdValue(-100), m_SensibleMaximumThresholdValue(+100), m_CurrentThresholdValue(1) { this->SupportRoiOn(); m_ThresholdFeedbackNode = DataNode::New(); mitk::CoreObjectFactory::GetInstance()->SetDefaultProperties( m_ThresholdFeedbackNode ); m_ThresholdFeedbackNode->SetProperty( "color", ColorProperty::New(1.0, 0.0, 0.0) ); m_ThresholdFeedbackNode->SetProperty( "texture interpolation", BoolProperty::New(false) ); m_ThresholdFeedbackNode->SetProperty( "layer", IntProperty::New( 100 ) ); m_ThresholdFeedbackNode->SetProperty( "levelwindow", LevelWindowProperty::New( LevelWindow(100, 1) ) ); m_ThresholdFeedbackNode->SetProperty( "name", StringProperty::New("Thresholding feedback") ); m_ThresholdFeedbackNode->SetProperty( "opacity", FloatProperty::New(0.3) ); m_ThresholdFeedbackNode->SetProperty( "helper object", BoolProperty::New(true) ); }
mitk::BinaryThresholdTool::~BinaryThresholdTool | ( | ) | [protected, virtual] |
Definition at line 63 of file mitkBinaryThresholdTool.cpp.
{ }
void mitk::BinaryThresholdTool::AcceptCurrentThresholdValue | ( | const std::string & | organName, |
const Color & | color | ||
) | [virtual] |
Definition at line 123 of file mitkBinaryThresholdTool.cpp.
References mitk::RenderingManager::GetInstance(), and mitk::RenderingManager::RequestUpdateAll().
{ CreateNewSegmentationFromThreshold(m_NodeForThresholding, organName, color ); RenderingManager::GetInstance()->RequestUpdateAll(); m_ToolManager->ActivateTool(-1); }
void mitk::BinaryThresholdTool::Activated | ( | ) | [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 77 of file mitkBinaryThresholdTool.cpp.
References OnRoiDataChanged().
{ m_ToolManager->RoiDataChanged += mitk::MessageDelegate<mitk::BinaryThresholdTool>(this, &mitk::BinaryThresholdTool::OnRoiDataChanged); m_OriginalImageNode = m_ToolManager->GetReferenceData(0); m_NodeForThresholding = m_OriginalImageNode; if ( m_NodeForThresholding.IsNotNull() ) { SetupPreviewNodeFor( m_NodeForThresholding ); } else { m_ToolManager->ActivateTool(-1); } }
void mitk::BinaryThresholdTool::CancelThresholding | ( | ) | [virtual] |
Definition at line 132 of file mitkBinaryThresholdTool.cpp.
{ m_ToolManager->ActivateTool(-1); }
void mitk::BinaryThresholdTool::CreateNewSegmentationFromThreshold | ( | DataNode * | node, |
const std::string & | organType, | ||
const Color & | color | ||
) | [protected] |
Definition at line 178 of file mitkBinaryThresholdTool.cpp.
References AccessFixedDimensionByItk_2, mitk::Tool::CreateEmptySegmentationNode(), mitk::Tool::ErrorMessage, and mitk::ImageTimeSelector::New().
{ if (node) { Image::Pointer image = dynamic_cast<Image*>( m_NodeForThresholding->GetData() ); if (image.IsNotNull()) { // create a new image of the same dimensions and smallest possible pixel type DataNode::Pointer emptySegmentation = Tool::CreateEmptySegmentationNode( image, organName, color ); if (emptySegmentation) { // actually perform a thresholding and ask for an organ type for (unsigned int timeStep = 0; timeStep < image->GetTimeSteps(); ++timeStep) { try { ImageTimeSelector::Pointer timeSelector = ImageTimeSelector::New(); timeSelector->SetInput( image ); timeSelector->SetTimeNr( timeStep ); timeSelector->UpdateLargestPossibleRegion(); Image::Pointer image3D = timeSelector->GetOutput(); AccessFixedDimensionByItk_2( image3D, ITKThresholding, 3, dynamic_cast<Image*>(emptySegmentation->GetData()), timeStep ); } catch(...) { Tool::ErrorMessage("Error accessing single time steps of the original image. Cannot create segmentation."); } } if (DataStorage* storage = m_ToolManager->GetDataStorage()) { storage->Add( emptySegmentation, m_OriginalImageNode ); // add as a child, because the segmentation "derives" from the original } m_ToolManager->SetWorkingData( emptySegmentation ); } } } }
void mitk::BinaryThresholdTool::Deactivated | ( | ) | [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 93 of file mitkBinaryThresholdTool.cpp.
References mitk::RenderingManager::GetInstance(), OnRoiDataChanged(), and mitk::RenderingManager::RequestUpdateAll().
{ m_ToolManager->RoiDataChanged -= mitk::MessageDelegate<mitk::BinaryThresholdTool>(this, &mitk::BinaryThresholdTool::OnRoiDataChanged); m_NodeForThresholding = NULL; m_OriginalImageNode = NULL; try { if (DataStorage* storage = m_ToolManager->GetDataStorage()) { storage->Remove( m_ThresholdFeedbackNode ); RenderingManager::GetInstance()->RequestUpdateAll(); } } catch(...) { // don't care } m_ThresholdFeedbackNode->SetData(NULL); }
virtual const char* mitk::BinaryThresholdTool::GetClassName | ( | ) | const [virtual] |
Reimplemented from mitk::AutoSegmentationTool.
const char * mitk::BinaryThresholdTool::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 72 of file mitkBinaryThresholdTool.cpp.
{ return "Thresholding"; }
const char ** mitk::BinaryThresholdTool::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 67 of file mitkBinaryThresholdTool.cpp.
{
return mitkBinaryThresholdTool_xpm;
}
void mitk::BinaryThresholdTool::ITKThresholding | ( | itk::Image< TPixel, VImageDimension > * | originalImage, |
mitk::Image * | segmentation, | ||
unsigned int | timeStep | ||
) | [protected] |
Definition at line 221 of file mitkBinaryThresholdTool.cpp.
References mitk::CastToItkImage(), and mitk::ImageTimeSelector::New().
{ ImageTimeSelector::Pointer timeSelector = ImageTimeSelector::New(); timeSelector->SetInput( segmentation ); timeSelector->SetTimeNr( timeStep ); timeSelector->UpdateLargestPossibleRegion(); Image::Pointer segmentation3D = timeSelector->GetOutput(); typedef itk::Image< Tool::DefaultSegmentationDataType, 3> SegmentationType; // this is sure for new segmentations SegmentationType::Pointer itkSegmentation; CastToItkImage( segmentation3D, itkSegmentation ); // iterate over original and segmentation typedef itk::ImageRegionConstIterator< itk::Image<TPixel, VImageDimension> > InputIteratorType; typedef itk::ImageRegionIterator< SegmentationType > SegmentationIteratorType; InputIteratorType inputIterator( originalImage, originalImage->GetLargestPossibleRegion() ); SegmentationIteratorType outputIterator( itkSegmentation, itkSegmentation->GetLargestPossibleRegion() ); inputIterator.GoToBegin(); outputIterator.GoToBegin(); while (!outputIterator.IsAtEnd()) { if ( (signed)inputIterator.Get() >= m_CurrentThresholdValue ) { outputIterator.Set( 1 ); } else { outputIterator.Set( 0 ); } ++inputIterator; ++outputIterator; } }
static Pointer mitk::BinaryThresholdTool::New | ( | ) | [static] |
Referenced by BinaryThresholdTool().
void mitk::BinaryThresholdTool::OnRoiDataChanged | ( | ) | [protected] |
Definition at line 259 of file mitkBinaryThresholdTool.cpp.
References mitk::CastToItkImage(), mitk::CastToMitkImage(), mitk::DataNode::GetData(), mitk::BoundingObjectToSegmentationFilter::New(), mitk::Image::New(), and mitk::DataNode::New().
Referenced by Activated(), and Deactivated().
{ typedef itk::Image<int, 3> ItkImageType; typedef itk::Image<unsigned char, 3> ItkMaskType; typedef itk::MaskImageFilter<ItkImageType, ItkMaskType, ItkImageType> MaskFilterType; mitk::DataNode* node = m_ToolManager->GetRoiData(0); if (node == NULL) { this->SetupPreviewNodeFor(m_OriginalImageNode); m_NodeForThresholding = m_OriginalImageNode; return; } mitk::DataNode::Pointer new_node = mitk::DataNode::New(); mitk::Image* image = dynamic_cast<mitk::Image*> (m_OriginalImageNode->GetData()); mitk::Image::Pointer new_image = mitk::Image::New(); mitk::Image::Pointer roi; mitk::BoundingObject* boundingObject = dynamic_cast<mitk::BoundingObject*> (node->GetData()); if (boundingObject) { mitk::BoundingObjectToSegmentationFilter::Pointer filter = mitk::BoundingObjectToSegmentationFilter::New(); filter->SetBoundingObject( boundingObject); filter->SetInput(image); filter->Update(); roi = filter->GetOutput(); } else roi = dynamic_cast<mitk::Image*> (node->GetData()); if (roi) { MaskFilterType::Pointer filter = MaskFilterType::New(); ItkMaskType::Pointer itkRoi = ItkMaskType::New(); ItkImageType::Pointer itkImage = ItkImageType::New(); mitk::CastToItkImage(image, itkImage); mitk::CastToItkImage(roi, itkRoi); filter->SetInput1(itkImage); filter->SetInput2(itkRoi); filter->SetOutsideValue(-32765); filter->Update(); mitk::CastToMitkImage(filter->GetOutput(),new_image); } new_node->SetData(new_image); this->SetupPreviewNodeFor(new_node); m_NodeForThresholding = new_node; }
void mitk::BinaryThresholdTool::SetThresholdValue | ( | int | value ) | [virtual] |
Definition at line 113 of file mitkBinaryThresholdTool.cpp.
References mitk::RenderingManager::GetInstance(), mitk::LevelWindowProperty::New(), and mitk::RenderingManager::RequestUpdateAll().
{ if (m_ThresholdFeedbackNode.IsNotNull()) { m_CurrentThresholdValue = value; m_ThresholdFeedbackNode->SetProperty( "levelwindow", LevelWindowProperty::New( LevelWindow(m_CurrentThresholdValue, 1) ) ); RenderingManager::GetInstance()->RequestUpdateAll(); } }
void mitk::BinaryThresholdTool::SetupPreviewNodeFor | ( | DataNode * | nodeForThresholding ) | [protected] |
Definition at line 137 of file mitkBinaryThresholdTool.cpp.
References mitk::DataNode::GetData(), and mitk::DataNode::GetIntProperty().
{ if (nodeForThresholding) { Image::Pointer image = dynamic_cast<Image*>( nodeForThresholding->GetData() ); Image::Pointer originalImage = dynamic_cast<Image*> (m_OriginalImageNode->GetData()); if (image.IsNotNull()) { // initialize and a new node with the same image as our reference image // use the level window property of this image copy to display the result of a thresholding operation m_ThresholdFeedbackNode->SetData( image ); int layer(50); nodeForThresholding->GetIntProperty("layer", layer); m_ThresholdFeedbackNode->SetIntProperty("layer", layer+1); if (DataStorage* storage = m_ToolManager->GetDataStorage()) { if (storage->Exists(m_ThresholdFeedbackNode)) storage->Remove(m_ThresholdFeedbackNode); storage->Add( m_ThresholdFeedbackNode, nodeForThresholding ); } m_SensibleMinimumThresholdValue = static_cast<int>( originalImage->GetScalarValueMin() ); m_SensibleMaximumThresholdValue = static_cast<int>( originalImage->GetScalarValueMax() ); LevelWindowProperty::Pointer lwp = dynamic_cast<LevelWindowProperty*>( m_ThresholdFeedbackNode->GetProperty( "levelwindow" )); if (lwp) { m_CurrentThresholdValue = static_cast<int>( lwp->GetLevelWindow().GetLevel() ); } else { m_CurrentThresholdValue = (m_SensibleMaximumThresholdValue + m_SensibleMinimumThresholdValue)/2; } IntervalBordersChanged.Send(m_SensibleMinimumThresholdValue, m_SensibleMaximumThresholdValue); ThresholdingValueChanged.Send(m_CurrentThresholdValue); } } }
Definition at line 44 of file mitkBinaryThresholdTool.h.
int mitk::BinaryThresholdTool::m_CurrentThresholdValue [protected] |
Definition at line 81 of file mitkBinaryThresholdTool.h.
Definition at line 77 of file mitkBinaryThresholdTool.h.
Definition at line 76 of file mitkBinaryThresholdTool.h.
int mitk::BinaryThresholdTool::m_SensibleMaximumThresholdValue [protected] |
Definition at line 80 of file mitkBinaryThresholdTool.h.
int mitk::BinaryThresholdTool::m_SensibleMinimumThresholdValue [protected] |
Definition at line 79 of file mitkBinaryThresholdTool.h.
Definition at line 75 of file mitkBinaryThresholdTool.h.
Referenced by BinaryThresholdTool().
Definition at line 45 of file mitkBinaryThresholdTool.h.