Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
mitkRegistrationWrapperMapperBase.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 
17 
18 #include <vtkPropAssembly.h>
19 #include <vtkPointData.h>
20 #include <vtkProperty.h>
21 #include <vtkCellArray.h>
22 #include <vtkColorTransferFunction.h>
23 #include <vtkPolyDataMapper.h>
24 #include <vtkPolyData.h>
25 #include <vtkActor.h>
26 
27 #include <mitkProperties.h>
28 #include <mitkExceptionMacro.h>
29 #include <mitkException.h>
30 
34 #include "mitkRegVisHelper.h"
35 #include "mitkRegVisPropertyTags.h"
36 
38 {
39 
40 }
41 
42 
44 {
45 
46 }
47 
49 {
50  if ( !this->IsVisible( renderer ) )
51  return;
52 
53  RegWrapperLocalStorage *localStorage = m_LSH.GetLocalStorage(renderer);
54 
55  //check if updates occured in the node or on the display
56  const DataNode *node = this->GetDataNode();
57  bool outdatedRendererGeometry = RendererGeometryIsOutdated(renderer,localStorage->m_LastUpdateTime);
58 
59  if ( (localStorage->m_LastUpdateTime < node->GetMTime())
60  || (localStorage->m_LastUpdateTime < node->GetPropertyList()->GetMTime()) //was a property modified?
61  || (localStorage->m_LastUpdateTime < node->GetPropertyList(renderer)->GetMTime())
62  || outdatedRendererGeometry)
63  {
64  MITK_DEBUG << "UPDATE NEEDED FOR _ " << renderer->GetName();
65 
66  bool isGridActive = false;
67  node->GetBoolProperty(mitk::nodeProp_RegVisGrid,isGridActive);
68 
69  bool isGlyphActive = false;
70  node->GetBoolProperty(mitk::nodeProp_RegVisGlyph,isGlyphActive);
71 
72  bool isPointsActive = false;
73  node->GetBoolProperty(mitk::nodeProp_RegVisPoints,isPointsActive);
74 
75  bool showStartGrid = false;
77 
78  bool isGridActiveOutdated = mitk::PropertyIsOutdated(node,mitk::nodeProp_RegVisGrid,localStorage->m_LastUpdateTime);
79  bool isGlyphActiveOutdated = mitk::PropertyIsOutdated(node,mitk::nodeProp_RegVisGlyph,localStorage->m_LastUpdateTime);
80  bool isPointsActiveOutdated = mitk::PropertyIsOutdated(node,mitk::nodeProp_RegVisPoints,localStorage->m_LastUpdateTime);
81  bool showStartGridOutdated = mitk::PropertyIsOutdated(node,mitk::nodeProp_RegVisGridShowStart,localStorage->m_LastUpdateTime);
82 
83  const mitk::BaseData* baseData = this->GetData();
84  if (baseData == NULL)
85  return;
86 
87  const DataNode *node = this->GetDataNode();
88  if (node == NULL)
89  return;
90 
91  const mitk::MAPRegistrationWrapper* regWrapper = dynamic_cast<const mitk::MAPRegistrationWrapper*>(baseData);
92  if (regWrapper == NULL)
93  return;
94 
96  //1. Check the FOV and presentation styles
97  bool outdatedFOV = mitk::GridIsOutdated(node,localStorage->m_LastUpdateTime);
98  if (outdatedFOV ||isGridActiveOutdated || isGlyphActiveOutdated || isPointsActiveOutdated || outdatedRendererGeometry)
99  { // we need to generate the grids/presentation again
100  const map::core::RegistrationKernelBase<3,3>* regKernel= mitk::GetRelevantRegKernelOfNode(node);
101 
102  if(!regKernel)
103  {
104  mitkThrow() << "No reg kernel for visualization";
105  }
106 
108  unsigned int gridFrequ =5;
109 
110  if (!GetGeometryDescription(renderer,gridDesc, gridFrequ))
111  {
112  return;
113  };
114 
115  if(isGridActive)
116  {
117  localStorage->m_DeformedGridData = mitk::Generate3DDeformationGrid(gridDesc, gridFrequ, regKernel);
118  localStorage->m_StartGridData = mitk::Generate3DDeformationGrid(gridDesc,gridFrequ);
119  localStorage->m_DeformedGridMapper->SetInputData(localStorage->m_DeformedGridData);
120  localStorage->m_StartGridMapper->SetInputData(localStorage->m_StartGridData);
121  }
122  else if (isGlyphActive)
123  {
124  localStorage->m_DeformedGridData = mitk::Generate3DDeformationGlyph(gridDesc, regKernel);
125  localStorage->m_StartGridData = NULL;
126  localStorage->m_DeformedGridMapper->SetInputData(localStorage->m_DeformedGridData);
127  }
128  else
129  {
130  mitkThrow() << "No reg kernel visualization style activated.";
131  }
132  }
133 
135  //2.Check if the mappers or actors must be modified
136  bool isColorStyleOutdated = mitk::PropertyIsOutdated(node,mitk::nodeProp_RegVisColorStyle,localStorage->m_LastUpdateTime);
137  bool isColorUniOutdated = mitk::PropertyIsOutdated(node,mitk::nodeProp_RegVisColorUni,localStorage->m_LastUpdateTime);
138  bool isColor1Outdated = mitk::PropertyIsOutdated(node,mitk::nodeProp_RegVisColor1Value,localStorage->m_LastUpdateTime);
139  bool isColor2Outdated = mitk::PropertyIsOutdated(node,mitk::nodeProp_RegVisColor2Value,localStorage->m_LastUpdateTime);
140  bool isColor3Outdated = mitk::PropertyIsOutdated(node,mitk::nodeProp_RegVisColor3Value,localStorage->m_LastUpdateTime);
141  bool isColor4Outdated = mitk::PropertyIsOutdated(node,mitk::nodeProp_RegVisColor4Value,localStorage->m_LastUpdateTime);
142  bool isColor2MagOutdated = mitk::PropertyIsOutdated(node,mitk::nodeProp_RegVisColor2Magnitude,localStorage->m_LastUpdateTime);
143  bool isColor3MagOutdated = mitk::PropertyIsOutdated(node,mitk::nodeProp_RegVisColor3Magnitude,localStorage->m_LastUpdateTime);
144  bool isColor4MagOutdated = mitk::PropertyIsOutdated(node,mitk::nodeProp_RegVisColor4Magnitude,localStorage->m_LastUpdateTime);
145  bool isColorInterpolateOutdated = mitk::PropertyIsOutdated(node,mitk::nodeProp_RegVisColorInterpolate,localStorage->m_LastUpdateTime);
146 
147  if(isColorStyleOutdated || isColorUniOutdated || isColor1Outdated ||
148  isColor2Outdated || isColor2MagOutdated || isColor3Outdated || isColor3MagOutdated ||
149  isColor4Outdated || isColor4MagOutdated || isColorInterpolateOutdated)
150  {
151  localStorage->m_DeformedGridMapper->ScalarVisibilityOn();
152  localStorage->m_DeformedGridMapper->SetScalarModeToUsePointData();
153  localStorage->m_DeformedGridMapper->SelectColorArray( "VectorMagnitude" );
154 
155  mitk::RegVisColorStyleProperty* colorStyleProp = NULL;
156  node->GetProperty(colorStyleProp, mitk::nodeProp_RegVisColorStyle);
157 
158  float color1[3] = {0.0,0.0,0.0};
159  node->GetColor( color1, NULL, mitk::nodeProp_RegVisColor1Value );
160  float color2[3] = {0.25,0.25,0.25};
161  node->GetColor( color2, NULL, mitk::nodeProp_RegVisColor2Value );
162  float color3[3] = {0.5,0.5,0.5};
163  node->GetColor( color3, NULL, mitk::nodeProp_RegVisColor3Value );
164  float color4[3] = {1.0,1.0,1.0};
165  node->GetColor( color4, NULL, mitk::nodeProp_RegVisColor4Value );
166 
167  double mag2 = 0;
169  double mag3 = 0;
171  double mag4 = 0;
173 
174  bool interpolate = true;
176 
177  //default :color by vector magnitude
178  localStorage->m_DeformedGridMapper->SelectColorArray( "VectorMagnitude" );
179  localStorage->m_DeformedGridMapper->SetUseLookupTableScalarRange(true);
180 
182 
183  if (!colorStyleProp || colorStyleProp->GetValueAsId()==0)
184  { //uni color mode
185  float temprgb[3] = {1.0,1.0,1.0};
186  node->GetColor( temprgb, NULL, mitk::nodeProp_RegVisColorUni );
187  localStorage->m_LUT->AddRGBSegment(0.0,temprgb[0],temprgb[1],temprgb[2],1.0,temprgb[0],temprgb[1],temprgb[2]);
188  localStorage->m_LUT->Build();
189  localStorage->m_DeformedGridMapper->SetLookupTable(localStorage->m_LUT);
190  }
191  else
192  {
193  localStorage->m_LUT->AddRGBPoint(0.0,color1[0],color1[1],color1[2]);
194  localStorage->m_LUT->AddRGBPoint(mag2,color2[0],color2[1],color2[2]);
195  localStorage->m_LUT->AddRGBPoint(mag3,color3[0],color3[1],color3[2]);
196  localStorage->m_LUT->AddRGBPoint(mag4,color4[0],color4[1],color4[2]);
197  if (!interpolate)
198  {
199  localStorage->m_LUT->AddRGBPoint(0.99*mag2,color1[0],color1[1],color1[2]);
200  localStorage->m_LUT->AddRGBPoint(0.99*mag3,color2[0],color2[1],color2[2]);
201  localStorage->m_LUT->AddRGBPoint(0.99*mag4,color3[0],color3[1],color3[2]);
202  };
203  }
204 
205  localStorage->m_LUT->Build();
206  localStorage->m_DeformedGridMapper->SetLookupTable(localStorage->m_LUT);
207  localStorage->m_DeformedGridMapper->Update();
208  }
209 
210  bool isGridStartColorOutdated = mitk::PropertyIsOutdated(node,mitk::nodeProp_RegVisGridStartColor,localStorage->m_LastUpdateTime);
211 
212  if(isGridStartColorOutdated)
213  {
214  localStorage->m_StartGridMapper->ScalarVisibilityOn();
215  localStorage->m_StartGridMapper->SetScalarModeToUsePointFieldData();
216 
217  float temprgb[3];
218  if (node->GetColor( temprgb, NULL, mitk::nodeProp_RegVisGridStartColor ))
219  {
220  double trgb[3] = { (double) temprgb[0], (double) temprgb[1], (double) temprgb[2] };
221  localStorage->m_StartGridActor->GetProperty()->SetColor(trgb);
222  }
223  }
224 
226  //3. Check if Assembly must be updated
227  if(isGridActiveOutdated||isGlyphActiveOutdated||isPointsActiveOutdated||showStartGridOutdated)
228  {
230 
231  if (isGridActive)
232  {
233  localStorage->m_RegAssembly->AddPart(localStorage->m_DeformedGridActor);
234  if (showStartGrid)
235  {
236  localStorage->m_RegAssembly->AddPart(localStorage->m_StartGridActor);
237  }
238  }
239  else if (isGlyphActive)
240  {
241  localStorage->m_RegAssembly->AddPart(localStorage->m_DeformedGridActor);
242  }
243  }
244 
245  localStorage->m_LastUpdateTime.Modified();
246 
247  }
248 }
249 
250 
252 {
253  Superclass::SetDefaultProperties(node, renderer, overwrite);
254 }
255 
257 {
258  return m_LSH.GetLocalStorage(renderer)->m_RegAssembly;
259 }
260 
262 {
263 
264 }
265 
267 {
268  m_DeformedGridActor = vtkSmartPointer<vtkActor>::New();
269  m_DeformedGridMapper = vtkSmartPointer<vtkPolyDataMapper>::New();
270  m_DeformedGridActor->SetMapper(m_DeformedGridMapper);
271 
272  m_StartGridActor = vtkSmartPointer<vtkActor>::New();
273  m_StartGridMapper = vtkSmartPointer<vtkPolyDataMapper>::New();
274  m_StartGridActor->SetMapper(m_StartGridMapper);
275 
276  m_RegAssembly = vtkSmartPointer<vtkPropAssembly>::New();
277 
279 
280  m_DeformedGridData = NULL;
281  m_StartGridData = NULL;
282 }
283 
mitk::PropertyList * GetPropertyList(const mitk::BaseRenderer *renderer=nullptr) const
Get the PropertyList of the renderer. If renderer is NULL, the BaseRenderer-independent PropertyList ...
const char *const nodeProp_RegVisGrid
virtual unsigned long GetMTime() const override
Get the timestamp of the last change of the map or the last change of one of the properties store in ...
Base of all data objects.
Definition: mitkBaseData.h:39
Organizes the rendering process.
bool GetBoolProperty(const char *propertyKey, bool &boolValue, const mitk::BaseRenderer *renderer=nullptr) const
Convenience access method for bool properties (instances of BoolProperty)
const char *const nodeProp_RegVisColorInterpolate
static void SetDefaultProperties(DataNode *node, BaseRenderer *renderer=NULL, bool overwrite=false)
#define MITK_DEBUG
Definition: mitkLogMacros.h:26
MAPRegistrationWrapper Wrapper class to allow the handling of MatchPoint registration objects as mitk...
mitk::BaseProperty * GetProperty(const char *propertyKey, const mitk::BaseRenderer *renderer=nullptr) const
Get the property (instance of BaseProperty) with key propertyKey from the PropertyList of the rendere...
virtual unsigned long GetMTime() const override
Get the timestamp of the last change of the contents of this node or the referenced BaseData...
T::Pointer GetData(const std::string &name)
const char *const nodeProp_RegVisColorStyle
vtkSmartPointer< vtkPolyData > MITKMATCHPOINTREGISTRATION_EXPORT Generate3DDeformationGrid(const mitk::BaseGeometry *gridDesc, unsigned int gridFrequence, const map::core::RegistrationKernelBase< 3, 3 > *regKernel)
const char *const nodeProp_RegVisGridStartColor
const char *const nodeProp_RegVisColor3Value
#define mitkThrow()
bool PropertyIsOutdated(const mitk::DataNode *regNode, const std::string &propName, const itk::TimeStamp &reference)
bool GridIsOutdated(const mitk::DataNode *regNode, const itk::TimeStamp &reference)
const char *const nodeProp_RegVisPoints
vtkSmartPointer< vtkPolyData > Generate3DDeformationGlyph(const mitk::BaseGeometry *gridDesc, const map::core::RegistrationKernelBase< 3, 3 > *regKernel)
const char *const nodeProp_RegVisColor1Value
bool GetPropertyValue(const char *propertyKey, T &value, const mitk::BaseRenderer *renderer=nullptr) const
Convenience access method for GenericProperty properties (T being the type of the second parameter...
Definition: mitkDataNode.h:275
const char *const nodeProp_RegVisColor2Value
virtual void GenerateDataForRenderer(mitk::BaseRenderer *renderer)
Generate the data needed for rendering into renderer.
const char *const nodeProp_RegVisColor4Magnitude
const char *const nodeProp_RegVisColor2Magnitude
const char *const nodeProp_RegVisGridShowStart
const char * GetName() const
get the name of the Renderer
const char *const nodeProp_RegVisGlyph
RegWrapperLocalStorage()
Constructor of the local storage. Do as much actions as possible in here to avoid double executions...
const char *const nodeProp_RegVisColor4Value
const char *const nodeProp_RegVisColor3Magnitude
const char *const nodeProp_RegVisColorUni
itk::TimeStamp m_LastUpdateTime
Timestamp of last update of stored data.
virtual vtkProp * GetVtkProp(mitk::BaseRenderer *renderer)
bool GetColor(float rgb[3], const mitk::BaseRenderer *renderer=nullptr, const char *propertyKey="color") const
Convenience access method for color properties (instances of ColorProperty)
Class for nodes of the DataTree.
Definition: mitkDataNode.h:66
virtual IdType GetValueAsId() const
const map::core::RegistrationKernelBase< 3, 3 > * GetRelevantRegKernelOfNode(const mitk::DataNode *regNode)
static itkEventMacro(BoundingShapeInteractionEvent, itk::AnyEvent) class MITKBOUNDINGSHAPE_EXPORT BoundingShapeInteractor Pointer New()
Basic interaction methods for mitk::GeometryData.