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

mitk::BinaryThresholdULTool Class Reference
[Classes related to InteractiveSegmentation]

Calculates the segmented volumes for binary images. More...

#include <mitkBinaryThresholdULTool.h>

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

List of all members.

Public Types

typedef BinaryThresholdULTool Self
typedef AutoSegmentationTool 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!
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 SetThresholdValues (int lower, int upper)
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
Message2< int, int > ThresholdingValuesChanged

Protected Types

typedef itk::Image< int, 3 > ImageType
typedef itk::Image
< Tool::DefaultSegmentationDataType, 3 > 
SegmentationType
typedef
itk::BinaryThresholdImageFilter
< ImageType, SegmentationType
ThresholdFilterType

Protected Member Functions

 BinaryThresholdULTool ()
virtual ~BinaryThresholdULTool ()
void SetupPreviewNodeFor (DataNode *nodeForThresholding)
void CreateNewSegmentationFromThreshold (DataNode *node, const std::string &organType, const Color &color)
void OnRoiDataChanged ()
void UpdatePreview ()
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_CurrentLowerThresholdValue
int m_CurrentUpperThresholdValue
ThresholdFilterType::Pointer m_ThresholdFilter

Detailed Description

Calculates the segmented volumes for binary images.

See also:
mitk::Tool
QmitkInteractiveSegmentation

Last contributor: $Author$

Definition at line 41 of file mitkBinaryThresholdULTool.h.


Member Typedef Documentation

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

Reimplemented from mitk::AutoSegmentationTool.

Definition at line 48 of file mitkBinaryThresholdULTool.h.

Definition at line 86 of file mitkBinaryThresholdULTool.h.

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

Reimplemented from mitk::AutoSegmentationTool.

Definition at line 48 of file mitkBinaryThresholdULTool.h.

Definition at line 87 of file mitkBinaryThresholdULTool.h.

Reimplemented from mitk::AutoSegmentationTool.

Definition at line 48 of file mitkBinaryThresholdULTool.h.

Reimplemented from mitk::AutoSegmentationTool.

Definition at line 48 of file mitkBinaryThresholdULTool.h.

typedef itk::BinaryThresholdImageFilter<ImageType, SegmentationType> mitk::BinaryThresholdULTool::ThresholdFilterType [protected]

Definition at line 88 of file mitkBinaryThresholdULTool.h.


Constructor & Destructor Documentation

mitk::BinaryThresholdULTool::BinaryThresholdULTool (  ) [protected]

Definition at line 44 of file mitkBinaryThresholdULTool.cpp.

References mitk::CoreObjectFactory::GetInstance(), m_ThresholdFeedbackNode, mitk::FloatProperty::New(), mitk::StringProperty::New(), mitk::IntProperty::New(), mitk::BoolProperty::New(), mitk::ColorProperty::New(), New(), and mitk::Tool::SupportRoiOn().

:m_SensibleMinimumThresholdValue(-100),
m_SensibleMaximumThresholdValue(+100),
m_CurrentLowerThresholdValue(1),
m_CurrentUpperThresholdValue(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("binary", BoolProperty::New(true));
  m_ThresholdFeedbackNode->SetProperty( "helper object", BoolProperty::New(true) );
}
mitk::BinaryThresholdULTool::~BinaryThresholdULTool (  ) [protected, virtual]

Definition at line 65 of file mitkBinaryThresholdULTool.cpp.

{
}

Member Function Documentation

void mitk::BinaryThresholdULTool::AcceptCurrentThresholdValue ( const std::string &  organName,
const Color color 
) [virtual]
void mitk::BinaryThresholdULTool::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 79 of file mitkBinaryThresholdULTool.cpp.

References OnRoiDataChanged().

void mitk::BinaryThresholdULTool::CancelThresholding (  ) [virtual]

Definition at line 136 of file mitkBinaryThresholdULTool.cpp.

{
  m_ToolManager->ActivateTool(-1);
}
void mitk::BinaryThresholdULTool::CreateNewSegmentationFromThreshold ( DataNode node,
const std::string &  organType,
const Color color 
) [protected]

Definition at line 184 of file mitkBinaryThresholdULTool.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::BinaryThresholdULTool::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 95 of file mitkBinaryThresholdULTool.cpp.

References mitk::RenderingManager::GetInstance(), OnRoiDataChanged(), and mitk::RenderingManager::RequestUpdateAll().

{
  m_ToolManager->RoiDataChanged -= mitk::MessageDelegate<mitk::BinaryThresholdULTool>(this, &mitk::BinaryThresholdULTool::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::BinaryThresholdULTool::GetClassName (  ) const [virtual]

Reimplemented from mitk::AutoSegmentationTool.

const char * mitk::BinaryThresholdULTool::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 74 of file mitkBinaryThresholdULTool.cpp.

{
  return "ThresholdingUL";
}
const char ** mitk::BinaryThresholdULTool::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 69 of file mitkBinaryThresholdULTool.cpp.

{
  return mitkBinaryThresholdULTool_xpm;
}
template<typename TPixel , unsigned int VImageDimension>
void mitk::BinaryThresholdULTool::ITKThresholding ( itk::Image< TPixel, VImageDimension > *  originalImage,
mitk::Image segmentation,
unsigned int  timeStep 
) [protected]

Definition at line 227 of file mitkBinaryThresholdULTool.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_CurrentLowerThresholdValue && (signed)inputIterator.Get() <= m_CurrentUpperThresholdValue )
    {
      outputIterator.Set( 1 );
    }
    else
    {
      outputIterator.Set( 0 );
    }

    ++inputIterator;
    ++outputIterator;
  }
}
static Pointer mitk::BinaryThresholdULTool::New (  ) [static]

Referenced by BinaryThresholdULTool().

void mitk::BinaryThresholdULTool::OnRoiDataChanged (  ) [protected]

Definition at line 265 of file mitkBinaryThresholdULTool.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;
  UpdatePreview();
}
void mitk::BinaryThresholdULTool::SetThresholdValues ( int  lower,
int  upper 
) [virtual]

Definition at line 115 of file mitkBinaryThresholdULTool.cpp.

References mitk::RenderingManager::GetInstance(), and mitk::RenderingManager::RequestUpdateAll().

{
  if (m_ThresholdFeedbackNode.IsNotNull())
  {
    m_CurrentLowerThresholdValue = lower;
    m_CurrentUpperThresholdValue = upper;
    UpdatePreview();
    //m_ThresholdFeedbackNode->SetProperty( "levelwindow", LevelWindowProperty::New( LevelWindow(m_CurrentThresholdValue, 1) ) );
    RenderingManager::GetInstance()->RequestUpdateAll();
  }
}
void mitk::BinaryThresholdULTool::SetupPreviewNodeFor ( DataNode nodeForThresholding ) [protected]

Definition at line 141 of file mitkBinaryThresholdULTool.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_CurrentLowerThresholdValue = static_cast<int>( lwp->GetLevelWindow().GetLevel() );
        m_CurrentUpperThresholdValue = m_CurrentLowerThresholdValue+100;
      }
      else
      {*/
        m_CurrentLowerThresholdValue = (m_SensibleMaximumThresholdValue + m_SensibleMinimumThresholdValue) / 3;
        m_CurrentUpperThresholdValue = 2*m_CurrentLowerThresholdValue;
      //}

      IntervalBordersChanged.Send(m_SensibleMinimumThresholdValue, m_SensibleMaximumThresholdValue);
      ThresholdingValuesChanged.Send(m_CurrentLowerThresholdValue, m_CurrentUpperThresholdValue);
    }
  }
}
void mitk::BinaryThresholdULTool::UpdatePreview (  ) [protected]

Definition at line 316 of file mitkBinaryThresholdULTool.cpp.

References mitk::CastToItkImage(), mitk::CastToMitkImage(), and mitk::Image::New().

{
  typedef itk::Image<int, 3> ImageType;
  typedef itk::Image<unsigned char, 3> SegmentationType;
  typedef itk::BinaryThresholdImageFilter<ImageType, SegmentationType> ThresholdFilterType;
  mitk::Image::Pointer thresholdimage = dynamic_cast<mitk::Image*> (m_NodeForThresholding->GetData());
    if(thresholdimage)
    {
      ImageType::Pointer itkImage = ImageType::New();
      CastToItkImage(thresholdimage, itkImage);
      ThresholdFilterType::Pointer filter = ThresholdFilterType::New();
      filter->SetInput(itkImage);
      filter->SetLowerThreshold(m_CurrentLowerThresholdValue);
      filter->SetUpperThreshold(m_CurrentUpperThresholdValue);
      filter->SetInsideValue(1);
      filter->SetOutsideValue(0);
      filter->Update();

      mitk::Image::Pointer new_image = mitk::Image::New();
      CastToMitkImage(filter->GetOutput(), new_image);
      m_ThresholdFeedbackNode->SetData(new_image);
    }
}

Member Data Documentation

Definition at line 45 of file mitkBinaryThresholdULTool.h.

Definition at line 83 of file mitkBinaryThresholdULTool.h.

Definition at line 84 of file mitkBinaryThresholdULTool.h.

Definition at line 79 of file mitkBinaryThresholdULTool.h.

Definition at line 78 of file mitkBinaryThresholdULTool.h.

Definition at line 82 of file mitkBinaryThresholdULTool.h.

Definition at line 81 of file mitkBinaryThresholdULTool.h.

Definition at line 77 of file mitkBinaryThresholdULTool.h.

Referenced by BinaryThresholdULTool().

ThresholdFilterType::Pointer mitk::BinaryThresholdULTool::m_ThresholdFilter [protected]

Definition at line 89 of file mitkBinaryThresholdULTool.h.

Definition at line 46 of file mitkBinaryThresholdULTool.h.


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