Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
mitkVtkSimulationPolyDataMapper3D.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"
20 #include <sofa/core/visual/VisualParams.h>
21 #include <vtkObjectFactory.h>
22 #include <vtkRenderer.h>
23 #include <vtkRenderWindow.h>
24 
25 namespace mitk
26 {
27  vtkStandardNewMacro(vtkSimulationPolyDataMapper3D);
28 }
29 
30 mitk::vtkSimulationPolyDataMapper3D::vtkSimulationPolyDataMapper3D()
31  : m_SimulationService(GetSimulationService())
32 {
33 }
34 
35 mitk::vtkSimulationPolyDataMapper3D::~vtkSimulationPolyDataMapper3D()
36 {
37 }
38 
39 void mitk::vtkSimulationPolyDataMapper3D::Render(vtkRenderer* renderer, vtkActor*)
40 {
41  vtkRenderWindow* renderWindow = renderer->GetRenderWindow();
42 
43  if (renderWindow->CheckAbortStatus() == 1)
44  return;
45 
46  if (renderWindow->SupportsOpenGL() == 0)
47  return;
48 
49  if (m_Simulation.IsNull())
50  return;
51 
52  if (!renderWindow->IsCurrent())
53  renderWindow->MakeCurrent();
54 
55  m_SimulationService->SetActiveSimulation(m_Simulation);
56 
57  sofa::core::visual::VisualParams* vParams = sofa::core::visual::VisualParams::defaultInstance();
58  sofa::simulation::Simulation::SPtr sofaSimulation = m_Simulation->GetSOFASimulation();
59  sofa::simulation::Node::SPtr rootNode = m_Simulation->GetRootNode();
60 
61  sofaSimulation->updateVisual(rootNode.get());
62  sofaSimulation->draw(vParams, rootNode.get());
63 
64  // SOFA potentially disables GL_BLEND but VTK relies on it.
65  glEnable(GL_BLEND);
66 }
67 
69 {
70 }
71 
73 {
74  m_Simulation = simulation;
75 }
76 
78 {
79  if (m_Simulation.IsNull())
80  return Superclass::GetBounds();
81 
82  sofa::simulation::Node::SPtr rootNode = m_Simulation->GetRootNode();
83  const sofa::defaulttype::BoundingBox& bbox = rootNode->f_bbox.getValue();
84  const sofa::defaulttype::Vector3& min = bbox.minBBox();
85  const sofa::defaulttype::Vector3& max = bbox.maxBBox();
86 
87  Bounds[0] = min.x();
88  Bounds[1] = max.x();
89  Bounds[2] = min.y();
90  Bounds[3] = max.y();
91  Bounds[4] = min.z();
92  Bounds[5] = max.z();
93 
94  return this->Bounds;
95 }
void Render(vtkRenderer *renderer, vtkActor *actor) override
DataCollection - Class to facilitate loading/accessing structured data.
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
itk::BoundingBox< unsigned long, 3, mitk::ScalarType > BoundingBox
void RenderPiece(vtkRenderer *, vtkActor *) override
void SetSimulation(mitk::Simulation::Pointer simulation)