Medical Imaging Interaction Toolkit  2018.4.99-3e3f1a6e
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 (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 "mitkContourMapper2D.h"
14 #include "mitkBaseRenderer.h"
15 #include "mitkColorProperty.h"
16 #include "mitkContour.h"
17 #include "mitkPlaneGeometry.h"
18 #include "mitkProperties.h"
19 #include <vtkLinearTransform.h>
20 #include "vtk_glew.h"
21 
23 {
24 }
25 
27 {
28 }
29 
31 {
32  float rgba[4] = { 1.0f, 1.0f, 1.0f, 1.0f };
33  // check for color prop and use it for rendering if it exists
34  GetDataNode()->GetColor(rgba, renderer, "color");
35  // check for opacity prop and use it for rendering if it exists
36  GetDataNode()->GetOpacity(rgba[3], renderer, "opacity");
37 
38  glColor4fv(rgba);
39 }
40 
42 {
43  bool visible = true;
44  GetDataNode()->GetVisibility(visible, renderer, "visible");
45 
46  if (!visible)
47  return;
48 
50  bool updateNeccesary = true;
51 
52  if (updateNeccesary)
53  {
54  mitk::Contour::Pointer input = const_cast<mitk::Contour *>(this->GetInput());
55 
56  // apply color and opacity read from the PropertyList
58 
59  vtkLinearTransform *transform = GetDataNode()->GetVtkTransform();
60 
61  // Contour::OutputType point;
62  Contour::BoundingBoxType::PointType point;
63 
64  mitk::Point3D p, projected_p;
65  float vtkp[3];
66  float lineWidth = 3.0;
67 
68  if (dynamic_cast<mitk::FloatProperty *>(this->GetDataNode()->GetProperty("Width")) != nullptr)
69  lineWidth = dynamic_cast<mitk::FloatProperty *>(this->GetDataNode()->GetProperty("Width"))->GetValue();
70  glLineWidth(lineWidth);
71 
72  if (input->GetClosed())
73  {
74  glBegin(GL_LINE_LOOP);
75  }
76  else
77  {
78  glBegin(GL_LINE_STRIP);
79  }
80 
81  // Contour::InputType end = input->GetContourPath()->EndOfInput();
82  // if (end > 50000) end = 0;
83 
84  mitk::Contour::PointsContainerPointer points = input->GetPoints();
85  mitk::Contour::PointsContainerIterator pointsIt = points->Begin();
86 
87  while (pointsIt != points->End())
88  {
89  // while ( idx != end )
90  //{
91  // point = input->GetContourPath()->Evaluate(idx);
92  point = pointsIt.Value();
93 
94  itk2vtk(point, vtkp);
95  transform->TransformPoint(vtkp, vtkp);
96  vtk2itk(vtkp, p);
97 
98  renderer->GetCurrentWorldPlaneGeometry()->Project(p, projected_p);
99  bool projectmode = false;
100  GetDataNode()->GetVisibility(projectmode, renderer, "project");
101  bool drawit = false;
102  if (projectmode)
103  drawit = true;
104  else
105  {
106  Vector3D diff = p - projected_p;
107  if (diff.GetSquaredNorm() < 1.0)
108  drawit = true;
109  }
110  if (drawit)
111  {
112  Point2D pt2d, tmp;
113  renderer->WorldToDisplay(p, pt2d);
114  glVertex2f(pt2d[0], pt2d[1]);
115  }
116 
117  pointsIt++;
118  // idx += 1;
119  }
120  glEnd();
121 
122  glLineWidth(1.0);
123  }
124 }
125 
127 {
128  return static_cast<const mitk::Contour *>(GetDataNode()->GetData());
129 }
mitk::BaseProperty * GetProperty(const char *propertyKey, const mitk::BaseRenderer *renderer=nullptr, bool fallBackOnDataProperties=true) const
Get the property (instance of BaseProperty) with key propertyKey from the PropertyList of the rendere...
BoundingBoxType::PointsContainerIterator PointsContainerIterator
Definition: mitkContour.h:51
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...
Stores vertices for drawing a contour.
Definition: mitkContour.h:31
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)
void ApplyColorAndOpacityProperties(mitk::BaseRenderer *renderer, vtkActor *actor=nullptr) override
Apply specific color and opacity properties read from the PropertyList. Reimplemented in GLmapper (do...
const Contour * GetInput(void)
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:422
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.
BoundingBoxType::PointsContainer::Pointer PointsContainerPointer
Definition: mitkContour.h:50
void MitkRender(mitk::BaseRenderer *renderer, mitk::VtkPropRenderer::RenderType type) override
void itk2vtk(const Tin &in, Tout &out)