Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
mitkVtkSimulationPolyDataMapper2D.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 #include "mitkISimulationService.h"
21 #include <mitkBaseRenderer.h>
23 #include <sofa/helper/system/gl.h>
24 #include <vtkObjectFactory.h>
25 #include <vtkRenderer.h>
26 #include <vtkRenderWindow.h>
27 
28 namespace mitk
29 {
30  vtkStandardNewMacro(vtkSimulationPolyDataMapper2D);
31 }
32 
33 mitk::vtkSimulationPolyDataMapper2D::vtkSimulationPolyDataMapper2D()
34  : m_SimulationService(GetSimulationService())
35 {
36 }
37 
38 mitk::vtkSimulationPolyDataMapper2D::~vtkSimulationPolyDataMapper2D()
39 {
40 }
41 
42 void mitk::vtkSimulationPolyDataMapper2D::Render(vtkRenderer* renderer, vtkActor*)
43 {
44  typedef PlaneIntersectionVisitor::Edge Edge;
45  typedef PlaneIntersectionVisitor::Intersection Intersection;
46 
47  vtkRenderWindow* renderWindow = renderer->GetRenderWindow();
48 
49  if (renderWindow->CheckAbortStatus() == 1)
50  return;
51 
52  if (renderWindow->SupportsOpenGL() == 0)
53  return;
54 
55  if (m_Simulation.IsNull())
56  return;
57 
58  if (!renderWindow->IsCurrent())
59  renderWindow->MakeCurrent();
60 
61  BaseRenderer* mitkRenderer = BaseRenderer::GetInstance(renderer->GetRenderWindow());
62 
63  if (mitkRenderer == NULL)
64  return;
65 
66  SliceNavigationController* sliceNavigationController = mitkRenderer->GetSliceNavigationController();
67 
68  if (sliceNavigationController == NULL)
69  return;
70 
71  const PlaneGeometry* planeGeometry = sliceNavigationController->GetCurrentPlaneGeometry();
72 
73  if (planeGeometry == NULL)
74  return;
75 
76  renderer->GetRenderWindow()->MakeCurrent();
77 
78  m_SimulationService->SetActiveSimulation(m_Simulation);
79 
80  PlaneIntersectionVisitor planeIntersectionVisitor(planeGeometry->GetOrigin(), planeGeometry->GetNormal());
81  m_Simulation->GetRootNode()->executeVisitor(&planeIntersectionVisitor);
82 
83  glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE);
84  glEnable(GL_COLOR_MATERIAL);
85 
86  const std::vector<Intersection>& intersections = planeIntersectionVisitor.GetIntersections();
87  std::vector<Intersection>::const_iterator intersectionsEnd = intersections.end();
88 
89  for (std::vector<Intersection>::const_iterator intersectionIt = intersections.begin(); intersectionIt != intersectionsEnd; ++intersectionIt)
90  {
91  const std::vector<Edge>& edges = intersectionIt->edges;
92  std::vector<Edge>::const_iterator edgesEnd = edges.end();
93 
94  glColor4fv(intersectionIt->color);
95  glBegin(GL_LINES);
96 
97  for (std::vector<Edge>::const_iterator edgeIt = edges.begin(); edgeIt != edgesEnd; ++edgeIt)
98  {
99  glVertex3dv(edgeIt->v0.GetDataPointer());
100  glVertex3dv(edgeIt->v1.GetDataPointer());
101  }
102 
103  glEnd();
104  }
105 
106  glDisable(GL_COLOR_MATERIAL);
107 }
108 
110 {
111 }
112 
114 {
115  m_Simulation = simulation;
116 }
117 
119 {
120  if (m_Simulation.IsNull())
121  return Superclass::GetBounds();
122 
123  sofa::simulation::Node::SPtr rootNode = m_Simulation->GetRootNode();
124  const sofa::defaulttype::BoundingBox& bbox = rootNode->f_bbox.getValue();
125  const sofa::defaulttype::Vector3& min = bbox.minBBox();
126  const sofa::defaulttype::Vector3& max = bbox.maxBBox();
127 
128  Bounds[0] = min.x();
129  Bounds[1] = max.x();
130  Bounds[2] = min.y();
131  Bounds[3] = max.y();
132  Bounds[4] = min.z();
133  Bounds[5] = max.z();
134 
135  return this->Bounds;
136 }
const Point3D GetOrigin() const
Get the origin, e.g. the upper-left corner of the plane.
static BaseRenderer * GetInstance(vtkRenderWindow *renWin)
Organizes the rendering process.
DataCollection - Class to facilitate loading/accessing structured data.
Controls the selection of the slice the associated BaseRenderer will display.
Vector3D GetNormal() const
Normal of the plane.
void RenderPiece(vtkRenderer *, vtkActor *) override
const mitk::PlaneGeometry * GetCurrentPlaneGeometry()
Returns the currently selected Plane in the current BaseGeometry (if existent).
MITKSIMULATION_EXPORT ISimulationService * GetSimulationService(us::ModuleContext *moduleContext=us::GetModuleContext())
vtkStandardNewMacro(AnatomicalStructureColorPresets)
static T max(T x, T y)
Definition: svm.cpp:70
static T min(T x, T y)
Definition: svm.cpp:67
void SetSimulation(mitk::Simulation::Pointer simulation)
itk::BoundingBox< unsigned long, 3, mitk::ScalarType > BoundingBox
virtual SliceNavigationController * GetSliceNavigationController()
Describes a two-dimensional, rectangular plane.
void Render(vtkRenderer *renderer, vtkActor *actor) override