Medical Imaging Interaction Toolkit  2018.4.99-08619e4f
Medical Imaging Interaction Toolkit
mitkAutoSegmentationTool.cpp
Go to the documentation of this file.
1 /*============================================================================
2 
3 The Medical Imaging Interaction Toolkit (MITK)
4 
5 Copyright (c) German Cancer Research Center (DKFZ)
6 All rights reserved.
7 
8 Use of this source code is governed by a 3-clause BSD license that can be
9 found in the LICENSE file.
10 
11 ============================================================================*/
12 
14 #include "mitkImage.h"
15 #include "mitkToolManager.h"
16 #include <mitkImageTimeSelector.h>
17 
18 mitk::AutoSegmentationTool::AutoSegmentationTool() : Tool("dummy"), m_OverwriteExistingSegmentation(false)
19 {
20 }
21 
23 {
24 }
25 
27 {
28  return "autoSegmentation";
29 }
30 
32 {
33  if (nullptr == image)
34  return image;
35 
36  if (image->GetDimension() != 4)
37  return image;
38 
40 
41  imageTimeSelector->SetInput(image);
42  imageTimeSelector->SetTimeNr(static_cast<int>(timestep));
43 
44  imageTimeSelector->UpdateLargestPossibleRegion();
45 
46  return imageTimeSelector->GetOutput();
47 }
48 
50 {
51  if (nullptr == image)
52  return image;
53 
54  if (!image->GetTimeGeometry()->IsValidTimePoint(timePoint))
55  return nullptr;
56 
57  return this->Get3DImage(image, image->GetTimeGeometry()->TimePointToTimeStep(timePoint));
58 }
59 
61 {
63 }
64 
66 {
68  return m_ToolManager->GetWorkingData(0)->GetName();
69  else
70  return "";
71 }
72 
74 {
77  {
79  if (refNode.IsNull())
80  {
81  // TODO create and use segmentation exceptions instead!!
82  MITK_ERROR << "No valid reference data!";
83  return nullptr;
84  }
85 
86  std::string nodename = refNode->GetName() + "_" + this->GetName();
87  mitk::Color color;
88  color.SetRed(1);
89  color.SetBlue(0);
90  color.SetGreen(0);
91  //create a new segmentation node based on the current segmentation as template
92  segmentationNode = CreateEmptySegmentationNode(dynamic_cast<mitk::Image *>(segmentationNode->GetData()), nodename, color);
93 
94  m_ToolManager->GetDataStorage()->Add(segmentationNode, refNode);
95  }
96  return segmentationNode;
97 }
virtual const char * GetName() const =0
Returns the name of this tool. Make it short!
Base class of all tools used by mitk::ToolManager.
Definition: mitkTool.h:86
DataStorage * GetDataStorage()
#define MITK_ERROR
Definition: mitkLogMacros.h:20
void SetOverwriteExistingSegmentation(bool overwrite)
virtual Image::ConstPointer Get3DImage(const Image *image, unsigned int timestep) const
virtual void Add(DataNode *node, const DataStorage::SetOfObjects *parents=nullptr)=0
Adds a DataNode containing a data object to its internal storage.
virtual bool IsValidTimePoint(TimePointType timePoint) const =0
Tests if a given time point is covered by this object.
const mitk::TimeGeometry * GetTimeGeometry() const
Return the TimeGeometry of the data as const pointer.
Definition: mitkBaseData.h:66
unsigned int GetDimension() const
Get dimension of the image.
Definition: mitkImage.cpp:106
virtual TimeStepType TimePointToTimeStep(TimePointType timePoint) const =0
Converts a time point to the corresponding time step.
virtual Image::ConstPointer Get3DImageByTimePoint(const Image *image, TimePointType timePoint) const
Image class for storing images.
Definition: mitkImage.h:72
mitk::ScalarType TimePointType
virtual mitk::DataNode * GetTargetSegmentationNode()
Depending on the selected mode either returns the currently selected segmentation or creates a new on...
DataNode::Pointer CreateEmptySegmentationNode(const Image *original, const std::string &organName, const mitk::Color &color)
Definition: mitkTool.cpp:210
mitk::Image::Pointer image
std::string GetCurrentSegmentationName()
Gets the name of the currently selected segmentation node.
itk::RGBPixel< float > Color
Color Standard RGB color typedef (float)
DataVectorType GetReferenceData()
Get the list of reference data.
ToolManager * m_ToolManager
Definition: mitkTool.h:228
const char * GetGroup() const override
Name of a group.
Class for nodes of the DataTree.
Definition: mitkDataNode.h:57
static Pointer New()
DataVectorType GetWorkingData()
Get the list of working data.