Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
mitkContourMapper2D.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 #include "mitkContourMapper2D.h"
18 #include "mitkBaseRenderer.h"
19 #include "mitkColorProperty.h"
20 #include "mitkContour.h"
21 #include "mitkPlaneGeometry.h"
22 #include "mitkProperties.h"
23 #include <vtkLinearTransform.h>
24 
25 #include "mitkGL.h"
26 
28 {
29 }
30 
32 {
33 }
34 
36 {
37  bool visible = true;
38  GetDataNode()->GetVisibility(visible, renderer, "visible");
39 
40  if (!visible)
41  return;
42 
44  bool updateNeccesary = true;
45 
46  if (updateNeccesary)
47  {
48  mitk::Contour::Pointer input = const_cast<mitk::Contour *>(this->GetInput());
49 
50  // apply color and opacity read from the PropertyList
51  ApplyColorAndOpacityProperties(renderer);
52 
53  vtkLinearTransform *transform = GetDataNode()->GetVtkTransform();
54 
55  // Contour::OutputType point;
57 
58  mitk::Point3D p, projected_p;
59  float vtkp[3];
60  float lineWidth = 3.0;
61 
62  if (dynamic_cast<mitk::FloatProperty *>(this->GetDataNode()->GetProperty("Width")) != NULL)
63  lineWidth = dynamic_cast<mitk::FloatProperty *>(this->GetDataNode()->GetProperty("Width"))->GetValue();
64  glLineWidth(lineWidth);
65 
66  if (input->GetClosed())
67  {
68  glBegin(GL_LINE_LOOP);
69  }
70  else
71  {
72  glBegin(GL_LINE_STRIP);
73  }
74 
75  // Contour::InputType end = input->GetContourPath()->EndOfInput();
76  // if (end > 50000) end = 0;
77 
78  mitk::Contour::PointsContainerPointer points = input->GetPoints();
79  mitk::Contour::PointsContainerIterator pointsIt = points->Begin();
80 
81  while (pointsIt != points->End())
82  {
83  // while ( idx != end )
84  //{
85  // point = input->GetContourPath()->Evaluate(idx);
86  point = pointsIt.Value();
87 
88  itk2vtk(point, vtkp);
89  transform->TransformPoint(vtkp, vtkp);
90  vtk2itk(vtkp, p);
91 
92  renderer->GetCurrentWorldPlaneGeometry()->Project(p, projected_p);
93  bool projectmode = false;
94  GetDataNode()->GetVisibility(projectmode, renderer, "project");
95  bool drawit = false;
96  if (projectmode)
97  drawit = true;
98  else
99  {
100  Vector3D diff = p - projected_p;
101  if (diff.GetSquaredNorm() < 1.0)
102  drawit = true;
103  }
104  if (drawit)
105  {
106  Point2D pt2d, tmp;
107  renderer->WorldToDisplay(p, pt2d);
108  glVertex2f(pt2d[0], pt2d[1]);
109  }
110 
111  pointsIt++;
112  // idx += 1;
113  }
114  glEnd();
115 
116  glLineWidth(1.0);
117  }
118 }
119 
121 {
122  return static_cast<const mitk::Contour *>(GetDataNode()->GetData());
123 }
mitk::Point3D PointType
BoundingBoxType::PointsContainerIterator PointsContainerIterator
Definition: mitkContour.h:53
Organizes the rendering process.
virtual const PlaneGeometry * GetCurrentWorldPlaneGeometry()
Get the current 2D-worldgeometry (m_CurrentWorldPlaneGeometry) used for 2D-rendering.
Stores vertices for drawing a contour.
Definition: mitkContour.h:35
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...
const Contour * GetInput(void)
void vtk2itk(const Tin &in, Tout &out)
BoundingBoxType::PointsContainer::Pointer PointsContainerPointer
Definition: mitkContour.h:52
virtual bool Project(const mitk::Point3D &pt3d_mm, mitk::Point3D &projectedPt3d_mm) const
Project a 3D point given in mm (pt3d_mm) onto the 2D geometry. The result is a 3D point in mm (projec...
void itk2vtk(const Tin &in, Tout &out)
virtual void Paint(BaseRenderer *renderer) override