Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
mitkContourSetMapper2D.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 "mitkContourSetMapper2D.h"
18 #include "mitkBaseRenderer.h"
19 #include "mitkColorProperty.h"
20 #include "mitkContourSet.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  // apply color and opacity read from the PropertyList
49  ApplyColorAndOpacityProperties(renderer);
50 
51  mitk::ContourSet::Pointer input = const_cast<mitk::ContourSet *>(this->GetInput());
52  mitk::ContourSet::ContourVectorType contourVec = input->GetContours();
53  mitk::ContourSet::ContourIterator contourIt = contourVec.begin();
54 
55  while (contourIt != contourVec.end())
56  {
57  mitk::Contour::Pointer nextContour = (mitk::Contour::Pointer)(*contourIt).second;
58  vtkLinearTransform *transform = GetDataNode()->GetVtkTransform();
59 
60  // Contour::OutputType point;
62 
63  mitk::Point3D p, projected_p;
64  float vtkp[3];
65 
66  glLineWidth(nextContour->GetWidth());
67 
68  if (nextContour->GetClosed())
69  {
70  glBegin(GL_LINE_LOOP);
71  }
72  else
73  {
74  glBegin(GL_LINE_STRIP);
75  }
76 
77  // float rgba[4]={1.0f,1.0f,1.0f,1.0f};
78  // if ( nextContour->GetSelected() )
79  //{
80  // rgba[0] = 1.0;
81  // rgba[1] = 0.0;
82  // rgba[2] = 0.0;
83  //}
84  // glColor4fv(rgba);
85 
86  mitk::Contour::PointsContainerPointer points = nextContour->GetPoints();
87  mitk::Contour::PointsContainerIterator pointsIt = points->Begin();
88 
89  while (pointsIt != points->End())
90  {
91  point = pointsIt.Value();
92 
93  itk2vtk(point, vtkp);
94  transform->TransformPoint(vtkp, vtkp);
95  vtk2itk(vtkp, p);
96 
97  renderer->GetCurrentWorldPlaneGeometry()->Project(p, projected_p);
98  Vector3D diff = p - projected_p;
99  if (diff.GetSquaredNorm() < 1.0)
100  {
101  Point2D pt2d, tmp;
102  renderer->WorldToDisplay(p, pt2d);
103  glVertex2f(pt2d[0], pt2d[1]);
104  }
105 
106  pointsIt++;
107  // idx += 1;
108  }
109 
110  glEnd();
111 
112  glLineWidth(1.0);
113 
114  contourIt++;
115  }
116  }
117 }
118 
120 {
121  return static_cast<const mitk::ContourSet *>(GetDataNode()->GetData());
122 }
mitk::Point3D PointType
BoundingBoxType::PointsContainerIterator PointsContainerIterator
Definition: mitkContour.h:53
const mitk::ContourSet * GetInput(void)
ContourVectorType::iterator ContourIterator
Organizes the rendering process.
virtual const PlaneGeometry * GetCurrentWorldPlaneGeometry()
Get the current 2D-worldgeometry (m_CurrentWorldPlaneGeometry) used for 2D-rendering.
virtual void Paint(mitk::BaseRenderer *renderer) override
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 vtk2itk(const Tin &in, Tout &out)
std::map< unsigned long, Contour::Pointer > ContourVectorType
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)
itk::SmartPointer< Self > Pointer
Definition: mitkBaseData.h:42