Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
mitkPointSetVtkMapper3D.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 "mitkColorProperty.h"
19 #include "mitkDataNode.h"
20 #include "mitkPointSet.h"
21 #include "mitkProperties.h"
22 #include "mitkVtkPropRenderer.h"
23 
24 #include <vtkActor.h>
25 #include <vtkAppendPolyData.h>
26 #include <vtkCellArray.h>
27 #include <vtkConeSource.h>
28 #include <vtkCubeSource.h>
29 #include <vtkCylinderSource.h>
30 #include <vtkPolyDataAlgorithm.h>
31 #include <vtkPolyDataMapper.h>
32 #include <vtkPropAssembly.h>
33 #include <vtkProperty.h>
34 #include <vtkRenderer.h>
35 #include <vtkSphereSource.h>
36 #include <vtkTransform.h>
37 #include <vtkTransformPolyDataFilter.h>
38 #include <vtkTubeFilter.h>
39 #include <vtkVectorText.h>
40 
41 #include <stdlib.h>
42 
43 #include <vtkgl.h>
44 
45 #include <mitkPropertyObserver.h>
46 
48 {
49  return static_cast<const mitk::PointSet *>(GetDataNode()->GetData());
50 }
51 
53  : m_vtkSelectedPointList(NULL),
54  m_vtkUnselectedPointList(NULL),
55  m_VtkSelectedPolyDataMapper(NULL),
56  m_VtkUnselectedPolyDataMapper(NULL),
57  m_vtkTextList(NULL),
58  m_NumberOfSelectedAdded(0),
59  m_NumberOfUnselectedAdded(0),
60  m_PointSize(1.0),
61  m_ContourRadius(0.5),
62  m_VertexRendering(false)
63 {
64  // propassembly
66 
67  // creating actors to be able to set transform
71 }
72 
74 {
75 }
76 
78 {
79  m_PointsAssembly->ReleaseGraphicsResources(renWin);
80 
81  m_SelectedActor->ReleaseGraphicsResources(renWin);
82  m_UnselectedActor->ReleaseGraphicsResources(renWin);
83  m_ContourActor->ReleaseGraphicsResources(renWin);
84 }
85 
87 {
88  m_PointsAssembly->ReleaseGraphicsResources(renderer->GetRenderWindow());
89 
90  m_SelectedActor->ReleaseGraphicsResources(renderer->GetRenderWindow());
91  m_UnselectedActor->ReleaseGraphicsResources(renderer->GetRenderWindow());
92  m_ContourActor->ReleaseGraphicsResources(renderer->GetRenderWindow());
93 }
94 
96 {
97  m_vtkSelectedPointList = vtkSmartPointer<vtkAppendPolyData>::New();
98  m_vtkUnselectedPointList = vtkSmartPointer<vtkAppendPolyData>::New();
99 
100  m_PointsAssembly->VisibilityOn();
101 
102  if (m_PointsAssembly->GetParts()->IsItemPresent(m_SelectedActor))
103  m_PointsAssembly->RemovePart(m_SelectedActor);
104  if (m_PointsAssembly->GetParts()->IsItemPresent(m_UnselectedActor))
105  m_PointsAssembly->RemovePart(m_UnselectedActor);
106  if (m_PointsAssembly->GetParts()->IsItemPresent(m_ContourActor))
107  m_PointsAssembly->RemovePart(m_ContourActor);
108 
109  // exceptional displaying for PositionTracker -> MouseOrientationTool
110  int mapperID;
111  bool isInputDevice = false;
112  if (this->GetDataNode()->GetBoolProperty("inputdevice", isInputDevice) && isInputDevice)
113  {
114  if (this->GetDataNode()->GetIntProperty("BaseRendererMapperID", mapperID) && mapperID == BaseRenderer::Standard3D)
115  return; // The event for the PositionTracker came from the 3d widget and not needs to be displayed
116  }
117 
118  // get and update the PointSet
119  mitk::PointSet::Pointer input = const_cast<mitk::PointSet *>(this->GetInput());
120 
121  /* only update the input data, if the property tells us to */
122  bool update = true;
123  this->GetDataNode()->GetBoolProperty("updateDataOnRender", update);
124  if (update == true)
125  input->Update();
126 
127  int timestep = this->GetTimestep();
128 
129  mitk::PointSet::DataType::Pointer itkPointSet = input->GetPointSet(timestep);
130 
131  if (itkPointSet.GetPointer() == NULL)
132  {
133  m_PointsAssembly->VisibilityOff();
134  return;
135  }
136 
137  // now fill selected and unselected pointList
138  // get size of Points in Property
139  m_PointSize = 2;
140  mitk::FloatProperty::Pointer pointSizeProp =
141  dynamic_cast<mitk::FloatProperty *>(this->GetDataNode()->GetProperty("pointsize"));
142  if (pointSizeProp.IsNotNull())
143  m_PointSize = pointSizeProp->GetValue();
144 
145  // get the property for creating a label onto every point only once
146  bool showLabel = true;
147  this->GetDataNode()->GetBoolProperty("show label", showLabel);
148  const char *pointLabel = NULL;
149  if (showLabel)
150  {
151  if (dynamic_cast<mitk::StringProperty *>(this->GetDataNode()->GetPropertyList()->GetProperty("label")) != NULL)
152  pointLabel =
153  dynamic_cast<mitk::StringProperty *>(this->GetDataNode()->GetPropertyList()->GetProperty("label"))->GetValue();
154  else
155  showLabel = false;
156  }
157 
158  // whether or not to creat a "contour" - connecting lines between all the points
159  int nbPoints = itkPointSet->GetPointData()->Size();
160  bool makeContour = false;
161  this->GetDataNode()->GetBoolProperty("show contour", makeContour);
162 
163  bool closeContour = false;
164  this->GetDataNode()->GetBoolProperty("close contour", closeContour);
165  int contourPointLimit = 0; // NO contour
166  if (makeContour)
167  {
168  if (closeContour)
169  contourPointLimit = nbPoints;
170  else
171  contourPointLimit = nbPoints - 1;
172  }
173 
174  // build list of all positions for later transform in one go
175  mitk::PointSet::PointsContainer::Iterator pointsIter;
176  int ptIdx;
177 
178  m_NumberOfSelectedAdded = 0;
179  m_NumberOfUnselectedAdded = 0;
180  vtkSmartPointer<vtkPoints> localPoints = vtkSmartPointer<vtkPoints>::New();
181  m_WorldPositions = vtkSmartPointer<vtkPoints>::New();
182  m_PointConnections = vtkSmartPointer<vtkCellArray>::New(); // m_PointConnections between points
183  for (ptIdx = 0, pointsIter = itkPointSet->GetPoints()->Begin(); pointsIter != itkPointSet->GetPoints()->End();
184  pointsIter++, ptIdx++)
185  {
186  itk::Point<float> currentPoint = pointsIter->Value();
187  localPoints->InsertPoint(ptIdx, currentPoint[0], currentPoint[1], currentPoint[2]);
188 
189  if (makeContour && ptIdx < contourPointLimit)
190  {
191  vtkIdType cell[2] = {(ptIdx + 1) % nbPoints, ptIdx};
192  m_PointConnections->InsertNextCell(2, cell);
193  }
194  }
195 
196  vtkSmartPointer<vtkLinearTransform> vtktransform = this->GetDataNode()->GetVtkTransform(this->GetTimestep());
197  vtktransform->TransformPoints(localPoints, m_WorldPositions);
198 
199  // create contour
200  if (makeContour)
201  {
202  this->CreateContour(m_WorldPositions, m_PointConnections);
203  }
204 
205  // check if the list for the PointDataContainer is the same size as the PointsContainer. Is not, then the points were
206  // inserted manually and can not be visualized according to the PointData (selected/unselected)
207  bool pointDataBroken = (itkPointSet->GetPointData()->Size() != itkPointSet->GetPoints()->Size());
208 
209  // now add an object for each point in data
210  mitk::PointSet::PointDataContainer::Iterator pointDataIter = itkPointSet->GetPointData()->Begin();
211  for (ptIdx = 0; ptIdx < nbPoints; ++ptIdx) // pointDataIter moved at end of loop
212  {
213  double currentPoint[3];
214  m_WorldPositions->GetPoint(ptIdx, currentPoint);
215  vtkSmartPointer<vtkPolyDataAlgorithm> source;
216 
217  // check for the pointtype in data and decide which geom-object to take and then add to the selected or unselected
218  // list
219  int pointType;
220  if (itkPointSet->GetPointData()->size() == 0 || pointDataBroken)
221  pointType = mitk::PTUNDEFINED;
222  else
223  pointType = pointDataIter.Value().pointSpec;
224 
225  switch (pointType)
226  {
227  case mitk::PTUNDEFINED:
228  {
229  vtkSmartPointer<vtkSphereSource> sphere = vtkSmartPointer<vtkSphereSource>::New();
230  sphere->SetRadius(m_PointSize / 2.0f);
231  sphere->SetCenter(currentPoint);
232  // sphere->SetCenter(pointsIter.Value()[0],pointsIter.Value()[1],pointsIter.Value()[2]);
233 
234  // MouseOrientation Tool (PositionTracker)
235  if (isInputDevice)
236  {
237  sphere->SetThetaResolution(10);
238  sphere->SetPhiResolution(10);
239  }
240  else
241  {
242  sphere->SetThetaResolution(20);
243  sphere->SetPhiResolution(20);
244  }
245  source = sphere;
246  }
247  break;
248  case mitk::PTSTART:
249  {
250  vtkSmartPointer<vtkCubeSource> cube = vtkSmartPointer<vtkCubeSource>::New();
251  cube->SetXLength(m_PointSize / 2);
252  cube->SetYLength(m_PointSize / 2);
253  cube->SetZLength(m_PointSize / 2);
254  cube->SetCenter(currentPoint);
255  source = cube;
256  }
257  break;
258  case mitk::PTCORNER:
259  {
260  vtkSmartPointer<vtkConeSource> cone = vtkSmartPointer<vtkConeSource>::New();
261  cone->SetRadius(m_PointSize / 2.0f);
262  cone->SetCenter(currentPoint);
263  cone->SetResolution(20);
264  source = cone;
265  }
266  break;
267  case mitk::PTEDGE:
268  {
269  vtkSmartPointer<vtkCylinderSource> cylinder = vtkSmartPointer<vtkCylinderSource>::New();
270  cylinder->SetRadius(m_PointSize / 2.0f);
271  cylinder->SetCenter(currentPoint);
272  cylinder->SetResolution(20);
273  source = cylinder;
274  }
275  break;
276  case mitk::PTEND:
277  {
278  vtkSmartPointer<vtkSphereSource> sphere = vtkSmartPointer<vtkSphereSource>::New();
279  sphere->SetRadius(m_PointSize / 2.0f);
280  // no SetCenter?? this functionality should be explained!
281  // otherwise: join with default block!
282  sphere->SetThetaResolution(20);
283  sphere->SetPhiResolution(20);
284  source = sphere;
285  }
286  break;
287  default:
288  {
289  vtkSmartPointer<vtkSphereSource> sphere = vtkSmartPointer<vtkSphereSource>::New();
290  sphere->SetRadius(m_PointSize / 2.0f);
291  sphere->SetCenter(currentPoint);
292  sphere->SetThetaResolution(20);
293  sphere->SetPhiResolution(20);
294  source = sphere;
295  }
296  break;
297  }
298 
299  if (pointDataIter.Value().selected && !pointDataBroken)
300  {
301  m_vtkSelectedPointList->AddInputConnection(source->GetOutputPort());
302  ++m_NumberOfSelectedAdded;
303  }
304  else
305  {
306  m_vtkUnselectedPointList->AddInputConnection(source->GetOutputPort());
307  ++m_NumberOfUnselectedAdded;
308  }
309  if (showLabel)
310  {
311  char buffer[20];
312  std::string l = pointLabel;
313  if (input->GetSize() > 1)
314  {
315  sprintf(buffer, "%d", ptIdx + 1);
316  l.append(buffer);
317  }
318  // Define the text for the label
319  vtkSmartPointer<vtkVectorText> label = vtkSmartPointer<vtkVectorText>::New();
320  label->SetText(l.c_str());
321 
322  //# Set up a transform to move the label to a new position.
323  vtkSmartPointer<vtkTransform> aLabelTransform = vtkSmartPointer<vtkTransform>::New();
324  aLabelTransform->Identity();
325  aLabelTransform->Translate(currentPoint[0] + 2, currentPoint[1] + 2, currentPoint[2]);
326  aLabelTransform->Scale(5.7, 5.7, 5.7);
327 
328  //# Move the label to a new position.
329  vtkSmartPointer<vtkTransformPolyDataFilter> labelTransform = vtkSmartPointer<vtkTransformPolyDataFilter>::New();
330  labelTransform->SetTransform(aLabelTransform);
331  labelTransform->SetInputConnection(label->GetOutputPort());
332 
333  // add it to the wright PointList
334  if (pointType)
335  {
336  m_vtkSelectedPointList->AddInputConnection(labelTransform->GetOutputPort());
337  ++m_NumberOfSelectedAdded;
338  }
339  else
340  {
341  m_vtkUnselectedPointList->AddInputConnection(labelTransform->GetOutputPort());
342  ++m_NumberOfUnselectedAdded;
343  }
344  }
345 
346  if (pointDataIter != itkPointSet->GetPointData()->End())
347  pointDataIter++;
348  } // end FOR
349 
350  // now according to number of elements added to selected or unselected, build up the rendering pipeline
351  if (m_NumberOfSelectedAdded > 0)
352  {
353  m_VtkSelectedPolyDataMapper = vtkSmartPointer<vtkPolyDataMapper>::New();
354  m_VtkSelectedPolyDataMapper->SetInputConnection(m_vtkSelectedPointList->GetOutputPort());
355 
356  // create a new instance of the actor
357  m_SelectedActor = vtkSmartPointer<vtkActor>::New();
358 
359  m_SelectedActor->SetMapper(m_VtkSelectedPolyDataMapper);
360  m_PointsAssembly->AddPart(m_SelectedActor);
361  }
362 
363  if (m_NumberOfUnselectedAdded > 0)
364  {
365  m_VtkUnselectedPolyDataMapper = vtkSmartPointer<vtkPolyDataMapper>::New();
366  m_VtkUnselectedPolyDataMapper->SetInputConnection(m_vtkUnselectedPointList->GetOutputPort());
367 
368  // create a new instance of the actor
369  m_UnselectedActor = vtkSmartPointer<vtkActor>::New();
370 
371  m_UnselectedActor->SetMapper(m_VtkUnselectedPolyDataMapper);
372  m_PointsAssembly->AddPart(m_UnselectedActor);
373  }
374 }
375 
377 {
378  // get and update the PointSet
379  mitk::PointSet::Pointer input = const_cast<mitk::PointSet *>(this->GetInput());
380 
381  /* only update the input data, if the property tells us to */
382  bool update = true;
383  this->GetDataNode()->GetBoolProperty("updateDataOnRender", update);
384  if (update == true)
385  input->Update();
386  int timestep = this->GetTimestep();
387 
388  mitk::PointSet::DataType::Pointer itkPointSet = input->GetPointSet(timestep);
389 
390  // turn off standard actors
391  m_UnselectedActor->VisibilityOff();
392  m_SelectedActor->VisibilityOff();
393 
394  // point size
395  m_PointSize = 2.0;
396  mitk::FloatProperty::Pointer pointSizeProp =
397  dynamic_cast<mitk::FloatProperty *>(this->GetDataNode()->GetProperty("pointsize"));
398  if (pointSizeProp.IsNotNull())
399  m_PointSize = pointSizeProp->GetValue();
400 
401  double *color = m_UnselectedActor->GetProperty()->GetColor();
402  double opacity = m_UnselectedActor->GetProperty()->GetOpacity();
403 
404  glClearColor(0.0, 0.0, 0.0, 0.0);
405  glDisable(GL_COLOR_MATERIAL);
406  glDisable(GL_LIGHTING);
407  glEnable(GL_POINT_SMOOTH);
408 
409  glPointSize(m_PointSize);
410  glBegin(GL_POINTS);
411 
412  glColor4d(color[0], color[1], color[2], opacity);
413 
414  for (auto pointsIter = itkPointSet->GetPoints()->Begin(); pointsIter != itkPointSet->GetPoints()->End(); pointsIter++)
415  {
416  const itk::Point<mitk::ScalarType> &point = pointsIter->Value();
417  glVertex3d(point[0], point[1], point[2]);
418  }
419 
420  glEnd();
421 
422  // reset context
423  glPointSize(1.0);
424  glDisable(GL_POINT_SMOOTH);
425  glEnable(GL_COLOR_MATERIAL);
426  glEnable(GL_LIGHTING);
427 }
428 
430 {
431  bool visible = true;
432  GetDataNode()->GetVisibility(visible, renderer, "visible");
433  if (!visible)
434  {
435  m_UnselectedActor->VisibilityOff();
436  m_SelectedActor->VisibilityOff();
437  m_ContourActor->VisibilityOff();
438  return;
439  }
440 
441  // create new vtk render objects (e.g. sphere for a point)
442 
443  SetVtkMapperImmediateModeRendering(m_VtkSelectedPolyDataMapper);
444  SetVtkMapperImmediateModeRendering(m_VtkUnselectedPolyDataMapper);
445 
446  BaseLocalStorage *ls = m_LSH.GetLocalStorage(renderer);
447  bool needGenerateData = ls->IsGenerateDataRequired(renderer, this, GetDataNode());
448 
449  if (!needGenerateData)
450  {
451  mitk::FloatProperty *pointSizeProp =
452  dynamic_cast<mitk::FloatProperty *>(this->GetDataNode()->GetProperty("pointsize"));
453  mitk::FloatProperty *contourSizeProp =
454  dynamic_cast<mitk::FloatProperty *>(this->GetDataNode()->GetProperty("contoursize"));
455 
456  bool useVertexRendering = false;
457  this->GetDataNode()->GetBoolProperty("Vertex Rendering", useVertexRendering);
458 
459  // only create new vtk render objects if property values were changed
460  if (pointSizeProp && m_PointSize != pointSizeProp->GetValue())
461  needGenerateData = true;
462  if (contourSizeProp && m_ContourRadius != contourSizeProp->GetValue())
463  needGenerateData = true;
464 
465  // when vertex rendering is enabled the pointset is always
466  // drawn with opengl, thus we leave needGenerateData always false
467  if (useVertexRendering && m_VertexRendering != useVertexRendering)
468  {
469  needGenerateData = false;
470  m_VertexRendering = true;
471  }
472  else if (!useVertexRendering && m_VertexRendering)
473  {
474  m_VertexRendering = false;
475  needGenerateData = true;
476  }
477  }
478 
479  if (needGenerateData)
480  {
481  this->CreateVTKRenderObjects();
483  }
484 
485  this->ApplyAllProperties(renderer, m_ContourActor);
486 
487  bool showPoints = true;
488  this->GetDataNode()->GetBoolProperty("show points", showPoints);
489 
490  m_UnselectedActor->SetVisibility(showPoints && !m_VertexRendering);
491  m_SelectedActor->SetVisibility(showPoints && !m_VertexRendering);
492 
493  if (false && dynamic_cast<mitk::FloatProperty *>(this->GetDataNode()->GetProperty("opacity")) != NULL)
494  {
495  mitk::FloatProperty::Pointer pointOpacity =
496  dynamic_cast<mitk::FloatProperty *>(this->GetDataNode()->GetProperty("opacity"));
497  float opacity = pointOpacity->GetValue();
498  m_ContourActor->GetProperty()->SetOpacity(opacity);
499  m_UnselectedActor->GetProperty()->SetOpacity(opacity);
500  m_SelectedActor->GetProperty()->SetOpacity(opacity);
501  }
502 
503  bool showContour = false;
504  this->GetDataNode()->GetBoolProperty("show contour", showContour);
505  m_ContourActor->SetVisibility(showContour);
506 
507  // use vertex rendering
508  if (m_VertexRendering)
509  {
510  VertexRendering();
512  }
513 }
514 
516 {
517  m_PointsAssembly->VisibilityOff();
518 }
519 
521 {
522  return m_PointsAssembly;
523 }
524 
526 {
527 }
528 
530 {
531  Superclass::ApplyColorAndOpacityProperties(renderer, actor);
532  // check for color props and use it for rendering of selected/unselected points and contour
533  // due to different params in VTK (double/float) we have to convert!
534 
535  // vars to convert to
536  double unselectedColor[4] = {1.0f, 1.0f, 0.0f, 1.0f}; // yellow
537  double selectedColor[4] = {1.0f, 0.0f, 0.0f, 1.0f}; // red
538  double contourColor[4] = {1.0f, 0.0f, 0.0f, 1.0f}; // red
539 
540  // different types for color!!!
541  mitk::Color tmpColor;
542  double opacity = 1.0;
543 
544  // check if there is an unselected property
545  if (dynamic_cast<mitk::ColorProperty *>(
546  this->GetDataNode()->GetPropertyList(renderer)->GetProperty("unselectedcolor")) != NULL)
547  {
548  tmpColor = dynamic_cast<mitk::ColorProperty *>(
549  this->GetDataNode()->GetPropertyList(renderer)->GetProperty("unselectedcolor"))
550  ->GetValue();
551  unselectedColor[0] = tmpColor[0];
552  unselectedColor[1] = tmpColor[1];
553  unselectedColor[2] = tmpColor[2];
554  unselectedColor[3] = 1.0f;
555  }
556  else if (dynamic_cast<mitk::ColorProperty *>(
557  this->GetDataNode()->GetPropertyList(NULL)->GetProperty("unselectedcolor")) != NULL)
558  {
559  tmpColor =
560  dynamic_cast<mitk::ColorProperty *>(this->GetDataNode()->GetPropertyList(NULL)->GetProperty("unselectedcolor"))
561  ->GetValue();
562  unselectedColor[0] = tmpColor[0];
563  unselectedColor[1] = tmpColor[1];
564  unselectedColor[2] = tmpColor[2];
565  unselectedColor[3] = 1.0f;
566  }
567  else
568  {
569  // check if the node has a color
570  float unselectedColorTMP[4] = {1.0f, 1.0f, 0.0f, 1.0f}; // yellow
571  m_DataNode->GetColor(unselectedColorTMP, NULL);
572  unselectedColor[0] = unselectedColorTMP[0];
573  unselectedColor[1] = unselectedColorTMP[1];
574  unselectedColor[2] = unselectedColorTMP[2];
575  // unselectedColor[3] stays 1.0f
576  }
577 
578  // get selected property
579  if (dynamic_cast<mitk::ColorProperty *>(
580  this->GetDataNode()->GetPropertyList(renderer)->GetProperty("selectedcolor")) != NULL)
581  {
582  tmpColor =
583  dynamic_cast<mitk::ColorProperty *>(this->GetDataNode()->GetPropertyList(renderer)->GetProperty("selectedcolor"))
584  ->GetValue();
585  selectedColor[0] = tmpColor[0];
586  selectedColor[1] = tmpColor[1];
587  selectedColor[2] = tmpColor[2];
588  selectedColor[3] = 1.0f;
589  }
590  else if (dynamic_cast<mitk::ColorProperty *>(
591  this->GetDataNode()->GetPropertyList(NULL)->GetProperty("selectedcolor")) != NULL)
592  {
593  tmpColor =
594  dynamic_cast<mitk::ColorProperty *>(this->GetDataNode()->GetPropertyList(NULL)->GetProperty("selectedcolor"))
595  ->GetValue();
596  selectedColor[0] = tmpColor[0];
597  selectedColor[1] = tmpColor[1];
598  selectedColor[2] = tmpColor[2];
599  selectedColor[3] = 1.0f;
600  }
601 
602  // get contour property
603  if (dynamic_cast<mitk::ColorProperty *>(
604  this->GetDataNode()->GetPropertyList(renderer)->GetProperty("contourcolor")) != NULL)
605  {
606  tmpColor =
607  dynamic_cast<mitk::ColorProperty *>(this->GetDataNode()->GetPropertyList(renderer)->GetProperty("contourcolor"))
608  ->GetValue();
609  contourColor[0] = tmpColor[0];
610  contourColor[1] = tmpColor[1];
611  contourColor[2] = tmpColor[2];
612  contourColor[3] = 1.0f;
613  }
614  else if (dynamic_cast<mitk::ColorProperty *>(
615  this->GetDataNode()->GetPropertyList(NULL)->GetProperty("contourcolor")) != NULL)
616  {
617  tmpColor =
618  dynamic_cast<mitk::ColorProperty *>(this->GetDataNode()->GetPropertyList(NULL)->GetProperty("contourcolor"))
619  ->GetValue();
620  contourColor[0] = tmpColor[0];
621  contourColor[1] = tmpColor[1];
622  contourColor[2] = tmpColor[2];
623  contourColor[3] = 1.0f;
624  }
625 
626  if (dynamic_cast<mitk::FloatProperty *>(this->GetDataNode()->GetPropertyList(renderer)->GetProperty("opacity")) !=
627  NULL)
628  {
629  mitk::FloatProperty::Pointer pointOpacity =
630  dynamic_cast<mitk::FloatProperty *>(this->GetDataNode()->GetPropertyList(renderer)->GetProperty("opacity"));
631  opacity = pointOpacity->GetValue();
632  }
633  else if (dynamic_cast<mitk::FloatProperty *>(this->GetDataNode()->GetPropertyList(NULL)->GetProperty("opacity")) !=
634  NULL)
635  {
636  mitk::FloatProperty::Pointer pointOpacity =
637  dynamic_cast<mitk::FloatProperty *>(this->GetDataNode()->GetPropertyList(NULL)->GetProperty("opacity"));
638  opacity = pointOpacity->GetValue();
639  }
640  // finished color / opacity fishing!
641 
642  // check if a contour shall be drawn
643  bool showContour = false;
644  this->GetDataNode()->GetBoolProperty("show contour", showContour, renderer);
645  if (showContour && (m_ContourActor != NULL))
646  {
647  this->CreateContour(m_WorldPositions, m_PointConnections);
648  m_ContourActor->GetProperty()->SetColor(contourColor);
649  m_ContourActor->GetProperty()->SetOpacity(opacity);
650  }
651 
652  m_SelectedActor->GetProperty()->SetColor(selectedColor);
653  m_SelectedActor->GetProperty()->SetOpacity(opacity);
654 
655  m_UnselectedActor->GetProperty()->SetColor(unselectedColor);
656  m_UnselectedActor->GetProperty()->SetOpacity(opacity);
657 }
658 
659 void mitk::PointSetVtkMapper3D::CreateContour(vtkPoints *points, vtkCellArray *m_PointConnections)
660 {
661  vtkSmartPointer<vtkAppendPolyData> vtkContourPolyData = vtkSmartPointer<vtkAppendPolyData>::New();
662  vtkSmartPointer<vtkPolyDataMapper> vtkContourPolyDataMapper = vtkSmartPointer<vtkPolyDataMapper>::New();
663 
664  vtkSmartPointer<vtkPolyData> contour = vtkSmartPointer<vtkPolyData>::New();
665  contour->SetPoints(points);
666  contour->SetLines(m_PointConnections);
667 
668  vtkSmartPointer<vtkTubeFilter> tubeFilter = vtkSmartPointer<vtkTubeFilter>::New();
669  tubeFilter->SetNumberOfSides(12);
670  tubeFilter->SetInputData(contour);
671 
672  // check for property contoursize.
673  m_ContourRadius = 0.5;
674  mitk::FloatProperty::Pointer contourSizeProp =
675  dynamic_cast<mitk::FloatProperty *>(this->GetDataNode()->GetProperty("contoursize"));
676 
677  if (contourSizeProp.IsNotNull())
678  m_ContourRadius = contourSizeProp->GetValue();
679 
680  tubeFilter->SetRadius(m_ContourRadius);
681  tubeFilter->Update();
682 
683  // add to pipeline
684  vtkContourPolyData->AddInputConnection(tubeFilter->GetOutputPort());
685  vtkContourPolyDataMapper->SetInputConnection(vtkContourPolyData->GetOutputPort());
686 
687  m_ContourActor->SetMapper(vtkContourPolyDataMapper);
688  m_PointsAssembly->AddPart(m_ContourActor);
689 }
690 
692 {
693  node->AddProperty("line width", mitk::IntProperty::New(2), renderer, overwrite);
694  node->AddProperty("pointsize", mitk::FloatProperty::New(1.0), renderer, overwrite);
695  node->AddProperty("selectedcolor", mitk::ColorProperty::New(1.0f, 0.0f, 0.0f), renderer, overwrite); // red
696  node->AddProperty("color", mitk::ColorProperty::New(1.0f, 1.0f, 0.0f), renderer, overwrite); // yellow
697  node->AddProperty("opacity", mitk::FloatProperty::New(1.0f), renderer, overwrite);
698  node->AddProperty("show contour", mitk::BoolProperty::New(false), renderer, overwrite);
699  node->AddProperty("close contour", mitk::BoolProperty::New(false), renderer, overwrite);
700  node->AddProperty("contourcolor", mitk::ColorProperty::New(1.0f, 0.0f, 0.0f), renderer, overwrite);
701  node->AddProperty("contoursize", mitk::FloatProperty::New(0.5), renderer, overwrite);
702  node->AddProperty("show points", mitk::BoolProperty::New(true), renderer, overwrite);
703  node->AddProperty("updateDataOnRender", mitk::BoolProperty::New(true), renderer, overwrite);
704  node->AddProperty("Vertex Rendering", mitk::BoolProperty::New(false), renderer, overwrite);
705  Superclass::SetDefaultProperties(node, renderer, overwrite);
706 }
vtkSmartPointer< vtkPropAssembly > m_PointsAssembly
itk::SmartPointer< Self > Pointer
Base class for mapper specific rendering ressources.
Definition: mitkMapper.h:200
void ReleaseGraphicsResources(vtkWindow *renWin)
virtual void ResetMapper(BaseRenderer *renderer) override
Reset the mapper (i.e., make sure that nothing is displayed) if no valid data is present. In most cases the reimplemented function disables the according actors (toggling visibility off)
static Pointer New()
Organizes the rendering process.
vtkSmartPointer< vtkActor > m_ContourActor
BaseData * GetData() const
Get the data object (instance of BaseData, e.g., an Image) managed by this DataNode.
virtual const mitk::PointSet * GetInput()
virtual void ApplyAllProperties(mitk::BaseRenderer *renderer, vtkActor *actor)
virtual void CreateContour(vtkPoints *points, vtkCellArray *connections)
static Pointer New()
The ColorProperty class RGB color property.
void AddProperty(const char *propertyKey, BaseProperty *property, const mitk::BaseRenderer *renderer=nullptr, bool overwrite=false)
Add the property (instance of BaseProperty) if it does not exist (or always ifoverwrite istrue) with ...
bool IsGenerateDataRequired(mitk::BaseRenderer *renderer, mitk::Mapper *mapper, mitk::DataNode *dataNode) const
Definition: mitkMapper.cpp:129
vtkSmartPointer< vtkActor > m_UnselectedActor
Data structure which stores a set of points. Superclass of mitk::Mesh.
Definition: mitkPointSet.h:79
const mitk::Color & GetColor() const
itk::RGBPixel< float > Color
Color Standard RGB color typedef (float)
virtual void GenerateDataForRenderer(mitk::BaseRenderer *renderer) override
Generate the data needed for rendering into renderer.
static Pointer New()
static void SetDefaultProperties(mitk::DataNode *node, mitk::BaseRenderer *renderer=NULL, bool overwrite=false)
static Pointer New()
vtkSmartPointer< vtkActor > m_SelectedActor
const float selectedColor[]
Property for strings.
virtual DataNode * GetDataNode() const
Get the DataNode containing the data to map. Method only returns valid DataNode Pointer if the mapper...
Definition: mitkMapper.cpp:36
virtual void UpdateVtkTransform(mitk::BaseRenderer *renderer) override
Set the vtkTransform of the m_Prop3D for the current time step of renderer.
virtual vtkProp * GetVtkProp(mitk::BaseRenderer *renderer) override
vtkRenderWindow * GetRenderWindow() const
Access the RenderWindow into which this renderer renders.
Class for nodes of the DataTree.
Definition: mitkDataNode.h:66
virtual T GetValue() const
static itkEventMacro(BoundingShapeInteractionEvent, itk::AnyEvent) class MITKBOUNDINGSHAPE_EXPORT BoundingShapeInteractor Pointer New()
Basic interaction methods for mitk::GeometryData.