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