Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
mitkPointSetVtkMapper2D.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 // mitk includes
20 #include "mitkVtkPropRenderer.h"
21 #include <mitkDataNode.h>
22 #include <mitkPlaneGeometry.h>
23 #include <mitkPointSet.h>
24 #include <mitkProperties.h>
25 
26 // vtk includes
27 #include <vtkActor.h>
28 #include <vtkCellArray.h>
29 #include <vtkFloatArray.h>
30 #include <vtkGlyph3D.h>
31 #include <vtkGlyphSource2D.h>
32 #include <vtkLine.h>
33 #include <vtkPointData.h>
34 #include <vtkPolyDataMapper.h>
35 #include <vtkPropAssembly.h>
36 #include <vtkTextActor.h>
37 #include <vtkTextProperty.h>
38 #include <vtkTransform.h>
39 #include <vtkTransformFilter.h>
40 
41 #include <stdlib.h>
42 
43 // constructor LocalStorage
45 {
46  // points
50 
51  // scales
54 
55  // distances
57 
58  // lines
60 
61  // glyph source (provides the different shapes)
64 
65  // glyphs
68 
69  // polydata
73 
74  // actors
78 
79  // mappers
83 
84  // propassembly
86 }
87 // destructor LocalStorage
89 {
90 }
91 
92 // input for this mapper ( = point set)
94 {
95  return static_cast<const mitk::PointSet *>(GetDataNode()->GetData());
96 }
97 
98 // constructor PointSetVtkMapper2D
100  : m_ShowContour(false),
101  m_CloseContour(false),
102  m_ShowPoints(true),
103  m_ShowDistances(false),
105  m_ShowAngles(false),
106  m_ShowDistantLines(false),
107  m_LineWidth(1),
108  m_PointLineWidth(1),
109  m_Point2DSize(6),
111  m_FillShape(false),
112  m_DistanceToPlane(4.0f)
113 {
114 }
115 
116 // destructor
118 {
119 }
120 
121 // reset mapper so that nothing is displayed e.g. toggle visiblity of the propassembly
123 {
124  LocalStorage *ls = m_LSH.GetLocalStorage(renderer);
125  ls->m_PropAssembly->VisibilityOff();
126 }
127 
128 // returns propassembly
130 {
131  LocalStorage *ls = m_LSH.GetLocalStorage(renderer);
132  return ls->m_PropAssembly;
133 }
134 
136 {
137  // The dot product of orthogonal vectors is zero.
138  // In two dimensions the slopes of perpendicular lines are negative reciprocals.
139  if ((fabs(in[0]) > 0) && ((fabs(in[0]) > fabs(in[1])) || (in[1] == 0)))
140  {
141  // negative reciprocal
142  out[0] = -in[1] / in[0];
143  out[1] = 1;
144  out.Normalize();
145  return true;
146  }
147  else if (fabs(in[1]) > 0)
148  {
149  out[0] = 1;
150  // negative reciprocal
151  out[1] = -in[0] / in[1];
152  out.Normalize();
153  return true;
154  }
155  else
156  return false;
157 }
158 
160 {
161  LocalStorage *ls = m_LSH.GetLocalStorage(renderer);
162 
163  unsigned i = 0;
164 
165  // The vtk text actors need to be removed manually from the propassembly
166  // since the same vtk text actors are not overwriten within this function,
167  // but new actors are added to the propassembly each time this function is executed.
168  // Thus, the actors from the last call must be removed in the beginning.
169  for (i = 0; i < ls->m_VtkTextLabelActors.size(); i++)
170  {
171  if (ls->m_PropAssembly->GetParts()->IsItemPresent(ls->m_VtkTextLabelActors.at(i)))
172  ls->m_PropAssembly->RemovePart(ls->m_VtkTextLabelActors.at(i));
173  }
174 
175  for (i = 0; i < ls->m_VtkTextDistanceActors.size(); i++)
176  {
177  if (ls->m_PropAssembly->GetParts()->IsItemPresent(ls->m_VtkTextDistanceActors.at(i)))
178  ls->m_PropAssembly->RemovePart(ls->m_VtkTextDistanceActors.at(i));
179  }
180 
181  for (i = 0; i < ls->m_VtkTextAngleActors.size(); i++)
182  {
183  if (ls->m_PropAssembly->GetParts()->IsItemPresent(ls->m_VtkTextAngleActors.at(i)))
184  ls->m_PropAssembly->RemovePart(ls->m_VtkTextAngleActors.at(i));
185  }
186 
187  // initialize polydata here, otherwise we have update problems when
188  // executing this function again
192 
193  // get input point set and update the PointSet
194  mitk::PointSet::Pointer input = const_cast<mitk::PointSet *>(this->GetInput());
195 
196  // only update the input data, if the property tells us to
197  bool update = true;
198  this->GetDataNode()->GetBoolProperty("updateDataOnRender", update);
199  if (update == true)
200  input->Update();
201 
202  int timestep = this->GetTimestep();
203  mitk::PointSet::DataType::Pointer itkPointSet = input->GetPointSet(timestep);
204 
205  if (itkPointSet.GetPointer() == NULL)
206  {
207  ls->m_PropAssembly->VisibilityOff();
208  return;
209  }
210 
211  // iterator for point set
212  mitk::PointSet::PointsContainer::Iterator pointsIter = itkPointSet->GetPoints()->Begin();
213 
214  // PointDataContainer has additional information to each point, e.g. whether
215  // it is selected or not
216  mitk::PointSet::PointDataContainer::Iterator pointDataIter;
217  pointDataIter = itkPointSet->GetPointData()->Begin();
218 
219  // check if the list for the PointDataContainer is the same size as the PointsContainer.
220  // If not, then the points were inserted manually and can not be visualized according to the PointData
221  // (selected/unselected)
222  bool pointDataBroken = (itkPointSet->GetPointData()->Size() != itkPointSet->GetPoints()->Size());
223 
224  if (itkPointSet->GetPointData()->size() == 0 || pointDataBroken)
225  {
226  ls->m_PropAssembly->VisibilityOff();
227  return;
228  }
229 
230  ls->m_PropAssembly->VisibilityOn();
231 
232  // empty point sets, cellarrays, scalars
233  ls->m_UnselectedPoints->Reset();
234  ls->m_SelectedPoints->Reset();
235 
236  ls->m_ContourPoints->Reset();
237  ls->m_ContourLines->Reset();
238 
239  ls->m_UnselectedScales->Reset();
240  ls->m_SelectedScales->Reset();
241 
242  ls->m_DistancesBetweenPoints->Reset();
243 
244  ls->m_VtkTextLabelActors.clear();
245  ls->m_VtkTextDistanceActors.clear();
246  ls->m_VtkTextAngleActors.clear();
247 
248  ls->m_UnselectedScales->SetNumberOfComponents(3);
249  ls->m_SelectedScales->SetNumberOfComponents(3);
250 
251  int NumberContourPoints = 0;
252  bool pointsOnSameSideOfPlane = false;
253 
254  const int text2dDistance = 10;
255 
256  // initialize points with a random start value
257 
258  // current point in point set
259  itk::Point<ScalarType> point = pointsIter->Value();
260 
261  mitk::Point3D p = point; // currently visited point
262  mitk::Point3D lastP = point; // last visited point (predecessor in point set of "point")
263  mitk::Vector3D vec; // p - lastP
264  mitk::Vector3D lastVec; // lastP - point before lastP
265  vec.Fill(0.0);
266  lastVec.Fill(0.0);
267 
268  mitk::Point2D pt2d;
269  pt2d[0] = point[0]; // projected_p in display coordinates
270  pt2d[1] = point[1];
271  mitk::Point2D lastPt2d = pt2d; // last projected_p in display coordinates (predecessor in point set of "pt2d")
272  mitk::Point2D preLastPt2d = pt2d; // projected_p in display coordinates before lastPt2
273 
274  const mitk::PlaneGeometry *geo2D = renderer->GetCurrentWorldPlaneGeometry();
275 
276  vtkLinearTransform *dataNodeTransform = input->GetGeometry()->GetVtkTransform();
277 
278  int count = 0;
279 
280  for (pointsIter = itkPointSet->GetPoints()->Begin(); pointsIter != itkPointSet->GetPoints()->End(); pointsIter++)
281  {
282  lastP = p; // valid for number of points count > 0
283  preLastPt2d = lastPt2d; // valid only for count > 1
284  lastPt2d = pt2d; // valid for number of points count > 0
285 
286  lastVec = vec; // valid only for counter > 1
287 
288  // get current point in point set
289  point = pointsIter->Value();
290 
291  // transform point
292  {
293  float vtkp[3];
294  itk2vtk(point, vtkp);
295  dataNodeTransform->TransformPoint(vtkp, vtkp);
296  vtk2itk(vtkp, point);
297  }
298 
299  p[0] = point[0];
300  p[1] = point[1];
301  p[2] = point[2];
302 
303  renderer->WorldToDisplay(p, pt2d);
304 
305  vec = p - lastP; // valid only for counter > 0
306 
307  // compute distance to current plane
308  float dist = geo2D->Distance(point);
309 
310  // draw markers on slices a certain distance away from the points
311  // location according to the tolerance threshold (m_DistanceToPlane)
312  if (dist < m_DistanceToPlane)
313  {
314  // is point selected or not?
315  if (pointDataIter->Value().selected)
316  {
317  ls->m_SelectedPoints->InsertNextPoint(point[0], point[1], point[2]);
318  // point is scaled according to its distance to the plane
319  ls->m_SelectedScales->InsertNextTuple3(std::max(0.0f, m_Point2DSize - (2 * dist)), 0, 0);
320  }
321  else
322  {
323  ls->m_UnselectedPoints->InsertNextPoint(point[0], point[1], point[2]);
324  // point is scaled according to its distance to the plane
325  ls->m_UnselectedScales->InsertNextTuple3(std::max(0.0f, m_Point2DSize - (2 * dist)), 0, 0);
326  }
327 
328  //---- LABEL -----//
329  // paint label for each point if available
330  if (dynamic_cast<mitk::StringProperty *>(this->GetDataNode()->GetProperty("label")) != NULL)
331  {
332  const char *pointLabel =
333  dynamic_cast<mitk::StringProperty *>(this->GetDataNode()->GetProperty("label"))->GetValue();
334  std::string l = pointLabel;
335  if (input->GetSize() > 1)
336  {
337  std::stringstream ss;
338  ss << pointsIter->Index();
339  l.append(ss.str());
340  }
341 
343 
344  ls->m_VtkTextActor->SetDisplayPosition(pt2d[0] + text2dDistance, pt2d[1] + text2dDistance);
345  ls->m_VtkTextActor->SetInput(l.c_str());
346  ls->m_VtkTextActor->GetTextProperty()->SetOpacity(100);
347 
348  float unselectedColor[4] = {1.0, 1.0, 0.0, 1.0};
349 
350  // check if there is a color property
351  GetDataNode()->GetColor(unselectedColor);
352 
353  ls->m_VtkTextActor->GetTextProperty()->SetColor(unselectedColor[0], unselectedColor[1], unselectedColor[2]);
354 
355  ls->m_VtkTextLabelActors.push_back(ls->m_VtkTextActor);
356  }
357  }
358 
359  // draw contour, distance text and angle text in render window
360 
361  // lines between points, which intersect the current plane, are drawn
362  if (m_ShowContour && count > 0)
363  {
364  ScalarType distance = renderer->GetCurrentWorldPlaneGeometry()->SignedDistance(point);
365  ScalarType lastDistance = renderer->GetCurrentWorldPlaneGeometry()->SignedDistance(lastP);
366 
367  pointsOnSameSideOfPlane = (distance * lastDistance) > 0.5;
368 
369  // Points must be on different side of plane in order to draw a contour.
370  // If "show distant lines" is enabled this condition is disregarded.
371  if (!pointsOnSameSideOfPlane || m_ShowDistantLines)
372  {
373  vtkSmartPointer<vtkLine> line = vtkSmartPointer<vtkLine>::New();
374 
375  ls->m_ContourPoints->InsertNextPoint(lastP[0], lastP[1], lastP[2]);
376  line->GetPointIds()->SetId(0, NumberContourPoints);
377  NumberContourPoints++;
378 
379  ls->m_ContourPoints->InsertNextPoint(point[0], point[1], point[2]);
380  line->GetPointIds()->SetId(1, NumberContourPoints);
381  NumberContourPoints++;
382 
383  ls->m_ContourLines->InsertNextCell(line);
384 
385  if (m_ShowDistances) // calculate and print distance between adjacent points
386  {
387  float distancePoints = point.EuclideanDistanceTo(lastP);
388 
389  std::stringstream buffer;
390  buffer << std::fixed << std::setprecision(m_DistancesDecimalDigits) << distancePoints << " mm";
391 
392  // compute desired display position of text
393  Vector2D vec2d = pt2d - lastPt2d;
395  vec2d); // text is rendered within text2dDistance perpendicular to current line
396  Vector2D pos2d = (lastPt2d.GetVectorFromOrigin() + pt2d.GetVectorFromOrigin()) * 0.5 + vec2d * text2dDistance;
397 
399 
400  ls->m_VtkTextActor->SetDisplayPosition(pos2d[0], pos2d[1]);
401  ls->m_VtkTextActor->SetInput(buffer.str().c_str());
402  ls->m_VtkTextActor->GetTextProperty()->SetColor(0.0, 1.0, 0.0);
403 
404  ls->m_VtkTextDistanceActors.push_back(ls->m_VtkTextActor);
405  }
406 
407  if (m_ShowAngles && count > 1) // calculate and print angle between connected lines
408  {
409  std::stringstream buffer;
410  buffer << angle(vec.GetVnlVector(), -lastVec.GetVnlVector()) * 180 / vnl_math::pi << "°";
411 
412  // compute desired display position of text
413  Vector2D vec2d = pt2d - lastPt2d; // first arm enclosing the angle
414  vec2d.Normalize();
415  Vector2D lastVec2d = lastPt2d - preLastPt2d; // second arm enclosing the angle
416  lastVec2d.Normalize();
417  vec2d = vec2d - lastVec2d; // vector connecting both arms
418  vec2d.Normalize();
419 
420  // middle between two vectors that enclose the angle
421  Vector2D pos2d = lastPt2d.GetVectorFromOrigin() + vec2d * text2dDistance * text2dDistance;
422 
424 
425  ls->m_VtkTextActor->SetDisplayPosition(pos2d[0], pos2d[1]);
426  ls->m_VtkTextActor->SetInput(buffer.str().c_str());
427  ls->m_VtkTextActor->GetTextProperty()->SetColor(0.0, 1.0, 0.0);
428 
429  ls->m_VtkTextAngleActors.push_back(ls->m_VtkTextActor);
430  }
431  }
432  }
433 
434  if (pointDataIter != itkPointSet->GetPointData()->End())
435  {
436  pointDataIter++;
437  count++;
438  }
439  }
440 
441  // add each single text actor to the assembly
442  for (i = 0; i < ls->m_VtkTextLabelActors.size(); i++)
443  {
444  ls->m_PropAssembly->AddPart(ls->m_VtkTextLabelActors.at(i));
445  }
446 
447  for (i = 0; i < ls->m_VtkTextDistanceActors.size(); i++)
448  {
449  ls->m_PropAssembly->AddPart(ls->m_VtkTextDistanceActors.at(i));
450  }
451 
452  for (i = 0; i < ls->m_VtkTextAngleActors.size(); i++)
453  {
454  ls->m_PropAssembly->AddPart(ls->m_VtkTextAngleActors.at(i));
455  }
456 
457  //---- CONTOUR -----//
458 
459  // create lines between the points which intersect the plane
460  if (m_ShowContour)
461  {
462  // draw line between first and last point which is rendered
463  if (m_CloseContour && NumberContourPoints > 1)
464  {
465  vtkSmartPointer<vtkLine> closingLine = vtkSmartPointer<vtkLine>::New();
466  closingLine->GetPointIds()->SetId(0, 0); // index of first point
467  closingLine->GetPointIds()->SetId(1, NumberContourPoints - 1); // index of last point
468  ls->m_ContourLines->InsertNextCell(closingLine);
469  }
470 
471  ls->m_VtkContourPolyData->SetPoints(ls->m_ContourPoints);
472  ls->m_VtkContourPolyData->SetLines(ls->m_ContourLines);
473 
474  ls->m_VtkContourPolyDataMapper->SetInputData(ls->m_VtkContourPolyData);
475  ls->m_ContourActor->SetMapper(ls->m_VtkContourPolyDataMapper);
476  ls->m_ContourActor->GetProperty()->SetLineWidth(m_LineWidth);
477 
478  ls->m_PropAssembly->AddPart(ls->m_ContourActor);
479  }
480 
481  // the point set must be transformed in order to obtain the appropriate glyph orientation
482  // according to the current view
483  vtkSmartPointer<vtkTransform> transform = vtkSmartPointer<vtkTransform>::New();
484  vtkSmartPointer<vtkMatrix4x4> a, b = vtkSmartPointer<vtkMatrix4x4>::New();
485 
486  a = geo2D->GetVtkTransform()->GetMatrix();
487  b->DeepCopy(a);
488 
489  // delete transformation from matrix, only take orientation
490  b->SetElement(3, 3, 1);
491  b->SetElement(2, 3, 0);
492  b->SetElement(1, 3, 0);
493  b->SetElement(0, 3, 0);
494  b->SetElement(3, 2, 0);
495  b->SetElement(3, 1, 0);
496  b->SetElement(3, 0, 0);
497 
498  Vector3D spacing = geo2D->GetSpacing();
499 
500  // If you find a way to simplyfy the following, feel free to change!
501  b->SetElement(0, 0, b->GetElement(0, 0) / spacing[0]);
502  b->SetElement(1, 0, b->GetElement(1, 0) / spacing[0]);
503  b->SetElement(2, 0, b->GetElement(2, 0) / spacing[0]);
504  b->SetElement(1, 1, b->GetElement(1, 1) / spacing[1]);
505  b->SetElement(2, 1, b->GetElement(2, 1) / spacing[1]);
506 
507  b->SetElement(0, 2, b->GetElement(0, 2) / spacing[2]);
508  b->SetElement(1, 2, b->GetElement(1, 2) / spacing[2]);
509  b->SetElement(2, 2, b->GetElement(2, 2) / spacing[2]);
510 
511  transform->SetMatrix(b);
512 
513  //---- UNSELECTED POINTS -----//
514 
515  // apply properties to glyph
516  ls->m_UnselectedGlyphSource2D->SetGlyphType(m_IDShapeProperty);
517 
518  if (m_FillShape)
519  ls->m_UnselectedGlyphSource2D->FilledOn();
520  else
521  ls->m_UnselectedGlyphSource2D->FilledOff();
522 
523  // apply transform
524  vtkSmartPointer<vtkTransformFilter> transformFilterU = vtkSmartPointer<vtkTransformFilter>::New();
525  transformFilterU->SetInputConnection(ls->m_UnselectedGlyphSource2D->GetOutputPort());
526  transformFilterU->SetTransform(transform);
527 
529  ls->m_VtkUnselectedPointListPolyData->GetPointData()->SetVectors(ls->m_UnselectedScales);
530 
531  // apply transform of current plane to glyphs
532  ls->m_UnselectedGlyph3D->SetSourceConnection(transformFilterU->GetOutputPort());
534  ls->m_UnselectedGlyph3D->SetScaleModeToScaleByVector();
535  ls->m_UnselectedGlyph3D->SetVectorModeToUseVector();
536 
537  ls->m_VtkUnselectedPolyDataMapper->SetInputConnection(ls->m_UnselectedGlyph3D->GetOutputPort());
539  ls->m_UnselectedActor->GetProperty()->SetLineWidth(m_PointLineWidth);
540 
541  ls->m_PropAssembly->AddPart(ls->m_UnselectedActor);
542 
543  //---- SELECTED POINTS -----//
544 
545  ls->m_SelectedGlyphSource2D->SetGlyphTypeToDiamond();
546  ls->m_SelectedGlyphSource2D->CrossOn();
547  ls->m_SelectedGlyphSource2D->FilledOff();
548 
549  // apply transform
550  vtkSmartPointer<vtkTransformFilter> transformFilterS = vtkSmartPointer<vtkTransformFilter>::New();
551  transformFilterS->SetInputConnection(ls->m_SelectedGlyphSource2D->GetOutputPort());
552  transformFilterS->SetTransform(transform);
553 
555  ls->m_VtkSelectedPointListPolyData->GetPointData()->SetVectors(ls->m_SelectedScales);
556 
557  // apply transform of current plane to glyphs
558  ls->m_SelectedGlyph3D->SetSourceConnection(transformFilterS->GetOutputPort());
559  ls->m_SelectedGlyph3D->SetInputData(ls->m_VtkSelectedPointListPolyData);
560  ls->m_SelectedGlyph3D->SetScaleModeToScaleByVector();
561  ls->m_SelectedGlyph3D->SetVectorModeToUseVector();
562 
563  ls->m_VtkSelectedPolyDataMapper->SetInputConnection(ls->m_SelectedGlyph3D->GetOutputPort());
564  ls->m_SelectedActor->SetMapper(ls->m_VtkSelectedPolyDataMapper);
565  ls->m_SelectedActor->GetProperty()->SetLineWidth(m_PointLineWidth);
566 
567  ls->m_PropAssembly->AddPart(ls->m_SelectedActor);
568 }
569 
571 {
572  const mitk::DataNode *node = GetDataNode();
573  if (node == NULL)
574  return;
575 
576  LocalStorage *ls = m_LSH.GetLocalStorage(renderer);
577 
578  // check whether the input data has been changed
579  bool needGenerateData = ls->IsGenerateDataRequired(renderer, this, GetDataNode());
580 
581  // toggle visibility
582  bool visible = true;
583  node->GetVisibility(visible, renderer, "visible");
584  if (!visible)
585  {
586  ls->m_UnselectedActor->VisibilityOff();
587  ls->m_SelectedActor->VisibilityOff();
588  ls->m_ContourActor->VisibilityOff();
589  ls->m_PropAssembly->VisibilityOff();
590  return;
591  }
592  else
593  {
594  ls->m_PropAssembly->VisibilityOn();
595  }
596 
597  node->GetBoolProperty("show contour", m_ShowContour, renderer);
598  node->GetBoolProperty("close contour", m_CloseContour, renderer);
599  node->GetBoolProperty("show points", m_ShowPoints, renderer);
600  node->GetBoolProperty("show distances", m_ShowDistances, renderer);
601  node->GetIntProperty("distance decimal digits", m_DistancesDecimalDigits, renderer);
602  node->GetBoolProperty("show angles", m_ShowAngles, renderer);
603  node->GetBoolProperty("show distant lines", m_ShowDistantLines, renderer);
604  node->GetIntProperty("line width", m_LineWidth, renderer);
605  node->GetIntProperty("point line width", m_PointLineWidth, renderer);
606  if (!node->GetFloatProperty(
607  "point 2D size", m_Point2DSize, renderer)) // re-defined to float 2015-08-13, keep a fallback
608  {
609  int oldPointSize = m_Point2DSize;
610  if (node->GetIntProperty("point 2D size", oldPointSize, renderer))
611  {
612  m_Point2DSize = oldPointSize;
613  }
614  }
615  node->GetBoolProperty("Pointset.2D.fill shape", m_FillShape, renderer);
616  node->GetFloatProperty("Pointset.2D.distance to plane", m_DistanceToPlane, renderer);
617 
619  dynamic_cast<mitk::PointSetShapeProperty *>(this->GetDataNode()->GetProperty("Pointset.2D.shape", renderer));
620  if (shape.IsNotNull())
621  {
622  m_IDShapeProperty = shape->GetPointSetShape();
623  }
624 
625  // check for color props and use it for rendering of selected/unselected points and contour
626  // due to different params in VTK (double/float) we have to convert
627 
628  float opacity = 1.0;
629 
630  GetDataNode()->GetOpacity(opacity, renderer);
631 
632  // apply color and opacity
633  if (m_ShowPoints)
634  {
635  float unselectedColor[4];
636  double selectedColor[4] = {1.0f, 0.0f, 0.0f, 1.0f}; // red
637 
638  ls->m_UnselectedActor->VisibilityOn();
639  ls->m_SelectedActor->VisibilityOn();
640 
641  // check if there is a color property
642  GetDataNode()->GetColor(unselectedColor);
643 
644  // get selected color property
645  if (dynamic_cast<mitk::ColorProperty *>(
646  this->GetDataNode()->GetPropertyList(renderer)->GetProperty("selectedcolor")) != NULL)
647  {
648  mitk::Color tmpColor = dynamic_cast<mitk::ColorProperty *>(
649  this->GetDataNode()->GetPropertyList(renderer)->GetProperty("selectedcolor"))
650  ->GetValue();
651  selectedColor[0] = tmpColor[0];
652  selectedColor[1] = tmpColor[1];
653  selectedColor[2] = tmpColor[2];
654  selectedColor[3] = 1.0f; // alpha value
655  }
656  else if (dynamic_cast<mitk::ColorProperty *>(
657  this->GetDataNode()->GetPropertyList(NULL)->GetProperty("selectedcolor")) != NULL)
658  {
659  mitk::Color tmpColor =
660  dynamic_cast<mitk::ColorProperty *>(this->GetDataNode()->GetPropertyList(NULL)->GetProperty("selectedcolor"))
661  ->GetValue();
662  selectedColor[0] = tmpColor[0];
663  selectedColor[1] = tmpColor[1];
664  selectedColor[2] = tmpColor[2];
665  selectedColor[3] = 1.0f; // alpha value
666  }
667 
668  ls->m_SelectedActor->GetProperty()->SetColor(selectedColor);
669  ls->m_SelectedActor->GetProperty()->SetOpacity(opacity);
670 
671  ls->m_UnselectedActor->GetProperty()->SetColor(unselectedColor[0], unselectedColor[1], unselectedColor[2]);
672  ls->m_UnselectedActor->GetProperty()->SetOpacity(opacity);
673  }
674  else
675  {
676  ls->m_UnselectedActor->VisibilityOff();
677  ls->m_SelectedActor->VisibilityOff();
678  }
679 
680  if (m_ShowContour)
681  {
682  double contourColor[4] = {1.0f, 0.0f, 0.0f, 1.0f}; // red
683  ls->m_ContourActor->VisibilityOn();
684 
685  // get contour color property
686  if (dynamic_cast<mitk::ColorProperty *>(
687  this->GetDataNode()->GetPropertyList(renderer)->GetProperty("contourcolor")) != NULL)
688  {
689  mitk::Color tmpColor =
690  dynamic_cast<mitk::ColorProperty *>(this->GetDataNode()->GetPropertyList(renderer)->GetProperty("contourcolor"))
691  ->GetValue();
692  contourColor[0] = tmpColor[0];
693  contourColor[1] = tmpColor[1];
694  contourColor[2] = tmpColor[2];
695  contourColor[3] = 1.0f;
696  }
697  else if (dynamic_cast<mitk::ColorProperty *>(
698  this->GetDataNode()->GetPropertyList(NULL)->GetProperty("contourcolor")) != NULL)
699  {
700  mitk::Color tmpColor =
701  dynamic_cast<mitk::ColorProperty *>(this->GetDataNode()->GetPropertyList(NULL)->GetProperty("contourcolor"))
702  ->GetValue();
703  contourColor[0] = tmpColor[0];
704  contourColor[1] = tmpColor[1];
705  contourColor[2] = tmpColor[2];
706  contourColor[3] = 1.0f;
707  }
708 
709  ls->m_ContourActor->GetProperty()->SetColor(contourColor);
710  ls->m_ContourActor->GetProperty()->SetOpacity(opacity);
711  }
712  else
713  {
714  ls->m_ContourActor->VisibilityOff();
715  }
716 
717  if (needGenerateData)
718  {
719  // create new vtk render objects (e.g. a circle for a point)
720  this->CreateVTKRenderObjects(renderer);
721  }
722 }
723 
725 {
726  node->AddProperty("line width", mitk::IntProperty::New(2), renderer, overwrite);
727  node->AddProperty("point line width", mitk::IntProperty::New(1), renderer, overwrite);
728  node->AddProperty("point 2D size", mitk::FloatProperty::New(6), renderer, overwrite);
729  node->AddProperty("show contour", mitk::BoolProperty::New(false), renderer, overwrite);
730  node->AddProperty("close contour", mitk::BoolProperty::New(false), renderer, overwrite);
731  node->AddProperty("show points", mitk::BoolProperty::New(true), renderer, overwrite);
732  node->AddProperty("show distances", mitk::BoolProperty::New(false), renderer, overwrite);
733  node->AddProperty("distance decimal digits", mitk::IntProperty::New(2), renderer, overwrite);
734  node->AddProperty("show angles", mitk::BoolProperty::New(false), renderer, overwrite);
735  node->AddProperty("show distant lines", mitk::BoolProperty::New(false), renderer, overwrite);
736  node->AddProperty("layer", mitk::IntProperty::New(1), renderer, overwrite);
737  node->AddProperty("Pointset.2D.fill shape",
739  renderer,
740  overwrite); // fill or do not fill the glyph shape
742  node->AddProperty("Pointset.2D.shape", pointsetShapeProperty, renderer, overwrite);
743  node->AddProperty("Pointset.2D.distance to plane",
745  renderer,
746  overwrite); // show the point at a certain distance above/below the 2D imaging plane.
747 
748  Superclass::SetDefaultProperties(node, renderer, overwrite);
749 }
std::vector< vtkSmartPointer< vtkTextActor > > m_VtkTextLabelActors
static char * line
Definition: svm.cpp:2884
itk::SmartPointer< Self > Pointer
vtkSmartPointer< vtkPropAssembly > m_PropAssembly
double ScalarType
bool GetIntProperty(const char *propertyKey, int &intValue, const mitk::BaseRenderer *renderer=nullptr) const
Convenience access method for int properties (instances of IntProperty)
vtkSmartPointer< vtkPolyDataMapper > m_VtkSelectedPolyDataMapper
Organizes the rendering process.
virtual ScalarType SignedDistance(const Point3D &pt3d_mm) const
bool GetBoolProperty(const char *propertyKey, bool &boolValue, const mitk::BaseRenderer *renderer=nullptr) const
Convenience access method for bool properties (instances of BoolProperty)
virtual const mitk::PointSet * GetInput() const
vtkSmartPointer< vtkGlyph3D > m_UnselectedGlyph3D
DataCollection - Class to facilitate loading/accessing structured data.
ScalarType Distance(const Point3D &pt3d_mm) const
Distance of the point from the geometry (bounding-box not considered)
const mitk::Vector3D GetSpacing() const
Get the spacing (size of a pixel).
virtual const PlaneGeometry * GetCurrentWorldPlaneGeometry()
Get the current 2D-worldgeometry (m_CurrentWorldPlaneGeometry) used for 2D-rendering.
vtkSmartPointer< vtkPolyData > m_VtkUnselectedPointListPolyData
BaseData * GetData() const
Get the data object (instance of BaseData, e.g., an Image) managed by this DataNode.
vtkSmartPointer< vtkFloatArray > m_DistancesBetweenPoints
static void SetDefaultProperties(mitk::DataNode *node, mitk::BaseRenderer *renderer=NULL, bool overwrite=false)
set the default properties for this mapper
virtual vtkProp * GetVtkProp(mitk::BaseRenderer *renderer) override
returns the a prop assembly
vtkSmartPointer< vtkFloatArray > m_UnselectedScales
vtkSmartPointer< vtkPolyDataMapper > m_VtkContourPolyDataMapper
std::vector< vtkSmartPointer< vtkTextActor > > m_VtkTextAngleActors
vtkSmartPointer< vtkPolyDataMapper > m_VtkUnselectedPolyDataMapper
vtkSmartPointer< vtkFloatArray > m_SelectedScales
static Pointer New()
vtkSmartPointer< vtkPoints > m_UnselectedPoints
The ColorProperty class RGB color property.
vtkSmartPointer< vtkPolyData > m_VtkSelectedPointListPolyData
void WorldToDisplay(const Point3D &worldIndex, Point2D &displayPoint) const
This method converts a 3D world index to the display point using the geometry of the renderWindow...
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
Data structure which stores a set of points. Superclass of mitk::Mesh.
Definition: mitkPointSet.h:79
vtkSmartPointer< vtkPolyData > m_VtkContourPolyData
Internal class holding the mapper, actor, etc. for each of the 3 2D render windows.
bool GetFloatProperty(const char *propertyKey, float &floatValue, const mitk::BaseRenderer *renderer=nullptr) const
Convenience access method for float properties (instances of FloatProperty)
vtkSmartPointer< vtkCellArray > m_ContourLines
void vtk2itk(const Tin &in, Tout &out)
vtkSmartPointer< vtkGlyphSource2D > m_SelectedGlyphSource2D
vtkSmartPointer< vtkGlyph3D > m_SelectedGlyph3D
static T max(T x, T y)
Definition: svm.cpp:70
vtkSmartPointer< vtkTextActor > m_VtkTextActor
itk::RGBPixel< float > Color
Color Standard RGB color typedef (float)
static Pointer New()
static bool in(Reader::Char c, Reader::Char c1, Reader::Char c2, Reader::Char c3, Reader::Char c4)
Definition: jsoncpp.cpp:244
static Pointer New()
void itk2vtk(const Tin &in, Tout &out)
vtkSmartPointer< vtkGlyphSource2D > m_UnselectedGlyphSource2D
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)
const float selectedColor[]
virtual void CreateVTKRenderObjects(mitk::BaseRenderer *renderer)
Describes a two-dimensional, rectangular plane.
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
vtkLinearTransform * GetVtkTransform() const
Get the m_IndexToWorldTransform as a vtkLinearTransform.
std::vector< vtkSmartPointer< vtkTextActor > > m_VtkTextDistanceActors
virtual void GenerateDataForRenderer(mitk::BaseRenderer *renderer) override
Generate the data needed for rendering into renderer.
bool GetVisibility(bool &visible, const mitk::BaseRenderer *renderer, const char *propertyKey="visible") const
Convenience access method for visibility properties (instances of BoolProperty with property-key "vis...
Definition: mitkDataNode.h:413
Class for nodes of the DataTree.
Definition: mitkDataNode.h:66
static bool makePerpendicularVector2D(const mitk::Vector2D &in, mitk::Vector2D &out)
static itkEventMacro(BoundingShapeInteractionEvent, itk::AnyEvent) class MITKBOUNDINGSHAPE_EXPORT BoundingShapeInteractor Pointer New()
Basic interaction methods for mitk::GeometryData.