Medical Imaging Interaction Toolkit  2018.4.99-dcb22cd7
Medical Imaging Interaction Toolkit
mitkCalculateVolumetryTool.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 
15 #include "mitkCalculateVolumetryTool.xpm"
16 
17 #include "mitkProperties.h"
18 #include "mitkToolManager.h"
19 #include "mitkVolumeCalculator.h"
20 
21 namespace mitk
22 {
24 }
25 
27 {
28 }
29 
31 {
32 }
33 
35 {
36  return mitkCalculateVolumetryTool_xpm;
37 }
38 
40 {
41  return "Volumetry";
42 }
43 
45 {
46  return "Volume could not be calculated for these nodes:";
47 }
48 
50 {
51  if (node)
52  {
53  Image::Pointer image = dynamic_cast<Image *>(node->GetData());
54  if (image.IsNull())
55  return false;
56 
57  if (image->GetDimension() == 4)
58  {
59  Tool::ErrorMessage("Volumetry only valid for timestep 0! Bug #1280");
60  }
61 
63  volumetryFilter->SetImage(image);
64  volumetryFilter->SetThreshold(1); // comparison is >=
65  try
66  {
67  volumetryFilter->ComputeVolume();
68 
69  float volumeInTimeStep0 = volumetryFilter->GetVolume();
70 
71  node->SetProperty("volume", FloatProperty::New(volumeInTimeStep0));
72  }
73  catch (...)
74  {
75  return false;
76  }
77  }
78 
79  return true;
80 }
81 
83 {
84  Superclass::FinishProcessingAllData();
85  m_ToolManager->NodePropertiesChanged();
86 }
std::string GetErrorMessage() override
Describes the error (if one occurred during processing).
#define MITKSEGMENTATION_EXPORT
DataCollection - Class to facilitate loading/accessing structured data.
Message1< std::string > ErrorMessage
To send error messages (to be shown by some GUI)
Definition: mitkTool.h:99
void SetProperty(const std::string &propertyKey, BaseProperty *property, const std::string &contextName="", bool fallBackOnDefaultContext=false) override
Add new or change existent property.
MITK_TOOL_MACRO(MITKSEGMENTATION_EXPORT, LiveWireTool2D, "LiveWire tool")
BaseData * GetData() const
Get the data object (instance of BaseData, e.g., an Image) managed by this DataNode.
void FinishProcessingAllData() override
Subclasses should override this method.
bool ProcessOneWorkingData(DataNode *node) override
Subclasses should override this method.
Image class for storing images.
Definition: mitkImage.h:72
mitk::Image::Pointer image
static Pointer New()
const char * GetName() const override
Returns the name of this tool. Make it short!
Calculates the segmented volumes for binary images.
const char ** GetXPM() const override
Returns an icon in the XPM format.
Class for nodes of the DataTree.
Definition: mitkDataNode.h:57
static Pointer New()