Medical Imaging Interaction Toolkit  2018.4.99-4c24e3cb
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 (image->GetDimension() != 4)
34  return image;
35 
37 
38  imageTimeSelector->SetInput(image);
39  imageTimeSelector->SetTimeNr(static_cast<int>(timestep));
40 
41  imageTimeSelector->UpdateLargestPossibleRegion();
42 
43  return imageTimeSelector->GetOutput();
44 }
45 
47 {
49 }
50 
52 {
54  return m_ToolManager->GetWorkingData(0)->GetName();
55  else
56  return "";
57 }
58 
60 {
61  mitk::DataNode::Pointer emptySegmentation;
63  {
64  emptySegmentation = m_ToolManager->GetWorkingData(0);
65  }
66  else
67  {
69  if (refNode.IsNull())
70  {
71  // TODO create and use segmentation exceptions instead!!
72  MITK_ERROR << "No valid reference data!";
73  return nullptr;
74  }
75  std::string nodename = m_ToolManager->GetReferenceData(0)->GetName() + "_" + this->GetName();
76  mitk::Color color;
77  color.SetRed(1);
78  color.SetBlue(0);
79  color.SetGreen(0);
80  emptySegmentation = CreateEmptySegmentationNode(dynamic_cast<mitk::Image *>(refNode->GetData()), nodename, color);
81  m_ToolManager->GetDataStorage()->Add(emptySegmentation, refNode);
82  }
83  return emptySegmentation;
84 }
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:88
DataStorage * GetDataStorage()
#define MITK_ERROR
Definition: mitkLogMacros.h:20
void SetOverwriteExistingSegmentation(bool overwrite)
virtual void Add(DataNode *node, const DataStorage::SetOfObjects *parents=nullptr)=0
Adds a DataNode containing a data object to its internal storage.
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()
ToolManager * m_ToolManager
Definition: mitkTool.h:230
virtual itk::SmartPointer< Image > Get3DImage(itk::SmartPointer< Image > image, unsigned int timestep)
const char * GetGroup() const override
Name of a group.
Class for nodes of the DataTree.
Definition: mitkDataNode.h:64
static Pointer New()
DataVectorType GetWorkingData()