Medical Imaging Interaction Toolkit  2018.4.99-389bf124
Medical Imaging Interaction Toolkit
mitkDoseNodeHelper.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 
13 
14 #include "mitkDoseNodeHelper.h"
15 
16 #include <mitkRTConstants.h>
21 #include <mitkIsoLevelsGenerator.h>
22 
23 #include <vtkSmartPointer.h>
24 #include <vtkMath.h>
25 #include <mitkTransferFunction.h>
28 
29 
30 void mitk::ConfigureNodeAsDoseNode(mitk::DataNode* doseNode, const mitk::IsoDoseLevelSet* colorPreset, mitk::DoseValueAbs referenceDose, bool showColorWashGlobal)
31 {
32  if (!doseNode) return;
33 
34  mitk::Image::Pointer doseImage = dynamic_cast<mitk::Image*>(doseNode->GetData());
35 
36  if (doseImage != nullptr)
37  {
38  //set some specific color wash and isoline properties
39  doseNode->SetBoolProperty(mitk::RTConstants::DOSE_SHOW_COLORWASH_PROPERTY_NAME.c_str(), showColorWashGlobal);
40 
41  //Set reference dose property
42  doseNode->SetFloatProperty(mitk::RTConstants::REFERENCE_DOSE_PROPERTY_NAME.c_str(), referenceDose);
43 
44  mitk::IsoDoseLevelSetProperty::Pointer levelSetProp = mitk::IsoDoseLevelSetProperty::New(dynamic_cast<mitk::IsoDoseLevelSet*>(colorPreset->Clone().GetPointer()));
45 
46  doseNode->SetProperty(mitk::RTConstants::DOSE_ISO_LEVELS_PROPERTY_NAME.c_str(), levelSetProp);
47 
49 
50  if (showColorWashGlobal)
51  {
52  //Generating the color wash
53  vtkSmartPointer<vtkColorTransferFunction> transferFunction = vtkSmartPointer<vtkColorTransferFunction>::New();
54 
55  for (mitk::IsoDoseLevelSet::ConstIterator itIsoDoseLevel = colorPreset->Begin(); itIsoDoseLevel != colorPreset->End(); ++itIsoDoseLevel)
56  {
57  float *hsv = new float[3];
58  //used for transfer rgb to hsv
59  vtkSmartPointer<vtkMath> cCalc = vtkSmartPointer<vtkMath>::New();
60  if (itIsoDoseLevel->GetVisibleColorWash()){
61  cCalc->RGBToHSV(itIsoDoseLevel->GetColor()[0], itIsoDoseLevel->GetColor()[1], itIsoDoseLevel->GetColor()[2], &hsv[0], &hsv[1], &hsv[2]);
62  transferFunction->AddHSVPoint(itIsoDoseLevel->GetDoseValue()*referenceDose, hsv[0], hsv[1], hsv[2], 1.0, 1.0);
63  }
64  }
65 
68  mitkTransFunc->SetColorTransferFunction(transferFunction);
69  mitkTransFuncProp->SetValue(mitkTransFunc);
70 
71  doseNode->SetProperty("Image Rendering.Transfer Function", mitkTransFuncProp);
73  }
74  else
75  {
76  //Set rendering mode to levelwindow color mode
78  }
79 
80  doseNode->SetProperty("Image Rendering.Mode", renderingModeProp);
81  doseNode->SetProperty("opacity", mitk::FloatProperty::New(0.5));
82  }
83 };
84 
85 
86 void mitk::ConfigureNodeAsIsoLineNode(mitk::DataNode* doseOutlineNode, const mitk::IsoDoseLevelSet* colorPreset, mitk::DoseValueAbs referenceDose, bool showIsolinesGlobal)
87 {
88  if (doseOutlineNode != nullptr)
89  {
90  mitk::Image::Pointer doseImage = dynamic_cast<mitk::Image*>(doseOutlineNode->GetData());
91 
92  if (doseImage != nullptr)
93  {
94  mitk::IsoDoseLevelSetProperty::Pointer levelSetProp = mitk::IsoDoseLevelSetProperty::New(dynamic_cast<mitk::IsoDoseLevelSet*>(colorPreset->Clone().GetPointer()));
95 
96  mitk::IsoDoseLevelVector::Pointer levelVector = mitk::IsoDoseLevelVector::New();
98 
99  doseOutlineNode->SetBoolProperty(mitk::RTConstants::DOSE_SHOW_ISOLINES_PROPERTY_NAME.c_str(), showIsolinesGlobal);
100  doseOutlineNode->SetFloatProperty(mitk::RTConstants::REFERENCE_DOSE_PROPERTY_NAME.c_str(), referenceDose);
101 
102  doseOutlineNode->SetProperty(mitk::RTConstants::DOSE_ISO_LEVELS_PROPERTY_NAME.c_str(), levelSetProp);
103 
104  doseOutlineNode->SetProperty(mitk::RTConstants::DOSE_FREE_ISO_VALUES_PROPERTY_NAME.c_str(), levelVecProp);
105 
106  //set the outline properties
107  doseOutlineNode->SetBoolProperty("outline binary", true);
108  doseOutlineNode->SetProperty("helper object", mitk::BoolProperty::New(true));
109  doseOutlineNode->SetProperty("includeInBoundingBox", mitk::BoolProperty::New(false));
110 
111  //set the dose mapper for outline drawing; the colorwash is realized by the imagevtkmapper2D
113  doseOutlineNode->SetMapper(1, contourMapper);
114  }
115  }
116 };
void MITKDICOMRT_EXPORT ConfigureNodeAsIsoLineNode(mitk::DataNode *doseOutlineNode, const mitk::IsoDoseLevelSet *colorPreset, mitk::DoseValueAbs referenceDose, bool showIsolinesGlobal=true)
Stores values needed for the representation/visualization of dose iso levels.
virtual void SetMapper(MapperSlotId id, mitk::Mapper *mapper)
static const std::string REFERENCE_DOSE_PROPERTY_NAME
static const std::string DOSE_FREE_ISO_VALUES_PROPERTY_NAME
static const std::string DOSE_ISO_LEVELS_PROPERTY_NAME
static Pointer New()
void SetProperty(const std::string &propertyKey, BaseProperty *property, const std::string &contextName="", bool fallBackOnDefaultContext=false) override
Add new or change existent property.
void MITKDICOMRT_EXPORT ConfigureNodeAsDoseNode(mitk::DataNode *doseNode, const mitk::IsoDoseLevelSet *colorPreset, mitk::DoseValueAbs referenceDose, bool showColorWashGlobal=true)
void SetFloatProperty(const char *propertyKey, float floatValue, const mitk::BaseRenderer *renderer=nullptr)
Convenience method for setting float properties (instances of FloatProperty)
BaseData * GetData() const
Get the data object (instance of BaseData, e.g., an Image) managed by this DataNode.
Image class for storing images.
Definition: mitkImage.h:72
static Pointer New()
static Pointer New()
void SetBoolProperty(const char *propertyKey, bool boolValue, const mitk::BaseRenderer *renderer=nullptr)
Convenience method for setting boolean properties (instances of BoolProperty)
ConstIterator Begin(void) const
static const std::string DOSE_SHOW_COLORWASH_PROPERTY_NAME
static const std::string DOSE_SHOW_ISOLINES_PROPERTY_NAME
double DoseValueAbs
Represents absolute dose values (in Gy).
Class for nodes of the DataTree.
Definition: mitkDataNode.h:57
ConstIterator End(void) const