Medical Imaging Interaction Toolkit  2018.4.99-4c24e3cb
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 (DKFZ)
6 All rights reserved.
7 
8 Use of this source code is governed by a 3-clause BSD license that can be
9 found in the LICENSE file.
10 
11 ============================================================================*/
12 
13 #include "mitkContourSetMapper2D.h"
14 #include "mitkBaseRenderer.h"
15 #include "mitkColorProperty.h"
16 #include "mitkContourSet.h"
17 #include "mitkPlaneGeometry.h"
18 #include "mitkProperties.h"
19 #include <vtkLinearTransform.h>
20 
21 #include "mitkGL.h"
22 
24 {
25 }
26 
28 {
29 }
30 
32 {
33  float rgba[4] = { 1.0f, 1.0f, 1.0f, 1.0f };
34  // check for color prop and use it for rendering if it exists
35  GetDataNode()->GetColor(rgba, renderer, "color");
36  // check for opacity prop and use it for rendering if it exists
37  GetDataNode()->GetOpacity(rgba[3], renderer, "opacity");
38 
39  glColor4fv(rgba);
40 }
41 
43 {
44  bool visible = true;
45  GetDataNode()->GetVisibility(visible, renderer, "visible");
46 
47  if (!visible)
48  return;
49 
51  bool updateNeccesary = true;
52 
53  if (updateNeccesary)
54  {
55  // apply color and opacity read from the PropertyList
57 
58  mitk::ContourSet::Pointer input = const_cast<mitk::ContourSet *>(this->GetInput());
59  mitk::ContourSet::ContourVectorType contourVec = input->GetContours();
60  auto contourIt = contourVec.begin();
61 
62  while (contourIt != contourVec.end())
63  {
64  mitk::Contour::Pointer nextContour = (mitk::Contour::Pointer)(*contourIt).second;
65  vtkLinearTransform *transform = GetDataNode()->GetVtkTransform();
66 
67  // Contour::OutputType point;
68  Contour::BoundingBoxType::PointType point;
69 
70  mitk::Point3D p, projected_p;
71  float vtkp[3];
72 
73  glLineWidth(nextContour->GetWidth());
74 
75  if (nextContour->GetClosed())
76  {
77  glBegin(GL_LINE_LOOP);
78  }
79  else
80  {
81  glBegin(GL_LINE_STRIP);
82  }
83 
84  // float rgba[4]={1.0f,1.0f,1.0f,1.0f};
85  // if ( nextContour->GetSelected() )
86  //{
87  // rgba[0] = 1.0;
88  // rgba[1] = 0.0;
89  // rgba[2] = 0.0;
90  //}
91  // glColor4fv(rgba);
92 
93  mitk::Contour::PointsContainerPointer points = nextContour->GetPoints();
94  mitk::Contour::PointsContainerIterator pointsIt = points->Begin();
95 
96  while (pointsIt != points->End())
97  {
98  point = pointsIt.Value();
99 
100  itk2vtk(point, vtkp);
101  transform->TransformPoint(vtkp, vtkp);
102  vtk2itk(vtkp, p);
103 
104  renderer->GetCurrentWorldPlaneGeometry()->Project(p, projected_p);
105  Vector3D diff = p - projected_p;
106  if (diff.GetSquaredNorm() < 1.0)
107  {
108  Point2D pt2d, tmp;
109  renderer->WorldToDisplay(p, pt2d);
110  glVertex2f(pt2d[0], pt2d[1]);
111  }
112 
113  pointsIt++;
114  // idx += 1;
115  }
116 
117  glEnd();
118 
119  glLineWidth(1.0);
120 
121  contourIt++;
122  }
123  }
124 }
125 
127 {
128  return static_cast<const mitk::ContourSet *>(GetDataNode()->GetData());
129 }
BoundingBoxType::PointsContainerIterator PointsContainerIterator
Definition: mitkContour.h:49
const mitk::ContourSet * GetInput(void)
void MitkRender(mitk::BaseRenderer *renderer, mitk::VtkPropRenderer::RenderType type) override
virtual DataNode * GetDataNode() const
Get the DataNode containing the data to map. Method only returns valid DataNode Pointer if the mapper...
Definition: mitkMapper.cpp:31
Organizes the rendering process.
virtual const PlaneGeometry * GetCurrentWorldPlaneGeometry()
Get the current 2D-worldgeometry (m_CurrentWorldPlaneGeometry) used for 2D-rendering.
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...
bool GetOpacity(float &opacity, const mitk::BaseRenderer *renderer, const char *propertyKey="opacity") const
Convenience access method for opacity properties (instances of FloatProperty)
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...
BaseData * GetData() const
Get the data object (instance of BaseData, e.g., an Image) managed by this DataNode.
bool GetColor(float rgb[3], const mitk::BaseRenderer *renderer=nullptr, const char *propertyKey="color") const
Convenience access method for color properties (instances of ColorProperty)
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:429
void ApplyColorAndOpacityProperties(mitk::BaseRenderer *renderer, vtkActor *actor=nullptr) override
Apply specific color and opacity properties read from the PropertyList. Reimplemented in GLmapper (do...
void vtk2itk(const Tin &in, Tout &out)
vtkLinearTransform * GetVtkTransform(int t=0) const
Get the transformation applied prior to displaying the data as a vtkTransform.
std::map< unsigned long, Contour::Pointer > ContourVectorType
BoundingBoxType::PointsContainer::Pointer PointsContainerPointer
Definition: mitkContour.h:48
void itk2vtk(const Tin &in, Tout &out)
itk::SmartPointer< Self > Pointer
Definition: mitkBaseData.h:41