Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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,
6 Division of Medical and Biological Informatics.
7 All rights reserved.
8 
9 This software is distributed WITHOUT ANY WARRANTY; without
10 even the implied warranty of MERCHANTABILITY or FITNESS FOR
11 A PARTICULAR PURPOSE.
12 
13 See LICENSE.txt or http://www.mitk.org for details.
14 
15 ===================================================================*/
16 
18 #include "mitkImage.h"
19 #include "mitkToolManager.h"
20 #include <mitkImageTimeSelector.h>
21 
22 mitk::AutoSegmentationTool::AutoSegmentationTool() : Tool("dummy"), m_OverwriteExistingSegmentation(false)
23 {
24 }
25 
27 {
28 }
29 
31 {
32  return "autoSegmentation";
33 }
34 
36 {
37  if (image->GetDimension() != 4)
38  return image;
39 
41 
42  imageTimeSelector->SetInput(image);
43  imageTimeSelector->SetTimeNr(static_cast<int>(timestep));
44 
45  imageTimeSelector->UpdateLargestPossibleRegion();
46 
47  return imageTimeSelector->GetOutput();
48 }
49 
51 {
52  m_OverwriteExistingSegmentation = overwrite;
53 }
54 
56 {
57  if (m_ToolManager->GetWorkingData(0))
58  return m_ToolManager->GetWorkingData(0)->GetName();
59  else
60  return "";
61 }
62 
64 {
65  mitk::DataNode::Pointer emptySegmentation;
66  if (m_OverwriteExistingSegmentation)
67  {
68  emptySegmentation = m_ToolManager->GetWorkingData(0);
69  }
70  else
71  {
72  mitk::DataNode::Pointer refNode = m_ToolManager->GetReferenceData(0);
73  if (refNode.IsNull())
74  {
75  // TODO create and use segmentation exceptions instead!!
76  MITK_ERROR << "No valid reference data!";
77  return NULL;
78  }
79  std::string nodename = m_ToolManager->GetReferenceData(0)->GetName() + "_" + this->GetName();
80  mitk::Color color;
81  color.SetRed(1);
82  color.SetBlue(0);
83  color.SetGreen(0);
84  emptySegmentation = CreateEmptySegmentationNode(dynamic_cast<mitk::Image *>(refNode->GetData()), nodename, color);
85  m_ToolManager->GetDataStorage()->Add(emptySegmentation, refNode);
86  }
87  return emptySegmentation;
88 }
Base class of all tools used by mitk::ToolManager.
Definition: mitkTool.h:92
#define MITK_ERROR
Definition: mitkLogMacros.h:24
void SetOverwriteExistingSegmentation(bool overwrite)
virtual mitk::DataNode * GetTargetSegmentationNode()
Depending on the selected mode either returns the currently selected segmentation or creates a new on...
std::string GetCurrentSegmentationName()
Gets the name of the currently selected segmentation node.
itk::RGBPixel< float > Color
Color Standard RGB color typedef (float)
static std::string GetName(std::string fileName, std::string suffix)
virtual itk::SmartPointer< Image > Get3DImage(itk::SmartPointer< Image > image, unsigned int timestep)
virtual const char * GetGroup() const override
Name of a group.
Class for nodes of the DataTree.
Definition: mitkDataNode.h:66
static Pointer New()