Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
mitkSimulationVtkMapper3D.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 "mitkSimulation.h"
21 #include <sofa/component/visualmodel/VisualStyle.h>
22 #include <sofa/core/visual/VisualParams.h>
23 
24 mitk::SimulationVtkMapper3D::LocalStorage::LocalStorage()
25  : m_Actor(vtkSmartPointer<vtkActor>::New())
26 {
27 }
28 
29 mitk::SimulationVtkMapper3D::LocalStorage::~LocalStorage()
30 {
31 }
32 
34 {
35  if (node != NULL)
36  {
37  Simulation* simulation = dynamic_cast<Simulation*>(node->GetData());
38 
39  if (simulation != NULL)
40  {
41  sofa::simulation::Node::SPtr rootNode = simulation->GetRootNode();
42  sofa::component::visualmodel::VisualStyle::SPtr visualStyle;
43 
44  rootNode->get(visualStyle);
45 
46  if (!visualStyle)
47  {
48  visualStyle = sofa::core::objectmodel::New<sofa::component::visualmodel::VisualStyle>();
49 
50  sofa::core::visual::DisplayFlags* displayFlags = visualStyle->displayFlags.beginEdit();
51  displayFlags->setShowVisualModels();
52  visualStyle->displayFlags.endEdit();
53 
54  rootNode->addObject(visualStyle);
55  }
56 
57  const sofa::core::visual::DisplayFlags& displayFlags = visualStyle->displayFlags.getValue();
58 
59  node->AddProperty("Simulation.Behavior.Behavior Models", BoolProperty::New(displayFlags.getShowBehaviorModels()), renderer, overwrite);
60  node->AddProperty("Simulation.Behavior.Force Fields", BoolProperty::New(displayFlags.getShowForceFields()), renderer, overwrite);
61  node->AddProperty("Simulation.Behavior.Interactions", BoolProperty::New(displayFlags.getShowInteractionForceFields()), renderer, overwrite);
62  node->AddProperty("Simulation.Collision.Bounding Trees", BoolProperty::New(displayFlags.getShowBoundingCollisionModels()), renderer, overwrite);
63  node->AddProperty("Simulation.Collision.Collision Models", BoolProperty::New(displayFlags.getShowCollisionModels()), renderer, overwrite);
64  node->AddProperty("Simulation.Mapping.Mechanical Mappings", BoolProperty::New(displayFlags.getShowMechanicalMappings()), renderer, overwrite);
65  node->AddProperty("Simulation.Mapping.Visual Mappings", BoolProperty::New(displayFlags.getShowMappings()), renderer, overwrite);
66  node->AddProperty("Simulation.Options.Normals", BoolProperty::New(displayFlags.getShowNormals()), renderer, overwrite);
67  node->AddProperty("Simulation.Options.Wire Frame", BoolProperty::New(displayFlags.getShowWireFrame()), renderer, overwrite);
68  node->AddProperty("Simulation.Visual.Visual Models", BoolProperty::New(displayFlags.getShowVisualModels() != sofa::core::visual::tristate::false_value), renderer, overwrite);
69  }
70 
71  Superclass::SetDefaultProperties(node, renderer, overwrite);
72  }
73 }
74 
75 mitk::SimulationVtkMapper3D::SimulationVtkMapper3D()
76 {
77 }
78 
79 mitk::SimulationVtkMapper3D::~SimulationVtkMapper3D()
80 {
81 }
82 
84 {
85 }
86 
88 {
89  DataNode* node = this->GetDataNode();
90 
91  bool showBehaviorModels;
92  bool showForceFields;
93  bool showInteractionForceFields;
94  bool showBoundingCollisionModels;
95  bool showCollisionModels;
96  bool showMechanicalMappings;
97  bool showMappings;
98  bool showNormals;
99  bool showWireFrame;
100  bool showVisualModels;
101 
102  node->GetBoolProperty("Simulation.Behavior.Behavior Models", showBehaviorModels, renderer);
103  node->GetBoolProperty("Simulation.Behavior.Force Fields", showForceFields, renderer);
104  node->GetBoolProperty("Simulation.Behavior.Interactions", showInteractionForceFields, renderer);
105  node->GetBoolProperty("Simulation.Collision.Bounding Trees", showBoundingCollisionModels, renderer);
106  node->GetBoolProperty("Simulation.Collision.Collision Models", showCollisionModels, renderer);
107  node->GetBoolProperty("Simulation.Mapping.Mechanical Mappings", showMechanicalMappings, renderer);
108  node->GetBoolProperty("Simulation.Mapping.Visual Mappings", showMappings, renderer);
109  node->GetBoolProperty("Simulation.Options.Normals", showNormals, renderer);
110  node->GetBoolProperty("Simulation.Options.Wire Frame", showWireFrame, renderer);
111  node->GetBoolProperty("Simulation.Visual.Visual Models", showVisualModels, renderer);
112 
113  Simulation* simulation = static_cast<Simulation*>(node->GetData());
114  sofa::component::visualmodel::VisualStyle::SPtr visualStyle;
115  simulation->GetRootNode()->get(visualStyle);
116 
117  sofa::core::visual::DisplayFlags* displayFlags = visualStyle->displayFlags.beginEdit();
118 
119  displayFlags->setShowBehaviorModels(showBehaviorModels);
120  displayFlags->setShowForceFields(showForceFields);
121  displayFlags->setShowInteractionForceFields(showInteractionForceFields);
122  displayFlags->setShowBoundingCollisionModels(showBoundingCollisionModels);
123  displayFlags->setShowCollisionModels(showCollisionModels);
124  displayFlags->setShowMechanicalMappings(showMechanicalMappings);
125  displayFlags->setShowMappings(showMappings);
126  displayFlags->setShowNormals(showNormals);
127  displayFlags->setShowWireFrame(showWireFrame);
128  displayFlags->setShowVisualModels(showVisualModels);
129 
130  visualStyle->displayFlags.endEdit();
131 }
132 
134 {
135  DataNode* dataNode = this->GetDataNode();
136 
137  if (dataNode == NULL)
138  return;
139 
140  Simulation* simulation = dynamic_cast<Simulation*>(dataNode->GetData());
141 
142  if (simulation == NULL)
143  return;
144 
145  LocalStorage* localStorage = m_LocalStorageHandler.GetLocalStorage(renderer);
146 
147  if (localStorage->m_Mapper == NULL)
148  {
149  localStorage->m_Mapper = vtkSmartPointer<vtkSimulationPolyDataMapper3D>::New();
150  localStorage->m_Mapper->SetSimulation(simulation);
151 
152  localStorage->m_Actor->SetMapper(localStorage->m_Mapper);
153 
154  SetVtkRendererVisitor setVtkRendererVisitor(renderer->GetVtkRenderer());
155  simulation->GetRootNode()->executeVisitor(&setVtkRendererVisitor);
156  }
157 
158  this->ApplySimulationProperties(renderer);
159 }
160 
162 {
163  return m_LocalStorageHandler.GetLocalStorage(renderer)->m_Actor;
164 }
vtkProp * GetVtkProp(BaseRenderer *renderer) override
static void SetDefaultProperties(DataNode *node, BaseRenderer *renderer=NULL, bool overwrite=false)
Organizes the rendering process.
bool GetBoolProperty(const char *propertyKey, bool &boolValue, const mitk::BaseRenderer *renderer=nullptr) const
Convenience access method for bool properties (instances of BoolProperty)
void ApplySimulationProperties(BaseRenderer *renderer)
BaseData * GetData() const
Get the data object (instance of BaseData, e.g., an Image) managed by this DataNode.
void ApplyColorAndOpacityProperties(BaseRenderer *, vtkActor *) override
Apply color and opacity properties read from the PropertyList. Called by mapper subclasses.
static Pointer New()
void AddProperty(const char *propertyKey, BaseProperty *property, const mitk::BaseRenderer *renderer=nullptr, bool overwrite=false)
Add the property (instance of BaseProperty) if it does not exist (or always ifoverwrite istrue) with ...
void GenerateDataForRenderer(BaseRenderer *renderer) override
Generate the data needed for rendering into renderer.
sofa::simulation::Node::SPtr GetRootNode() const
vtkRenderer * GetVtkRenderer() const
Class for nodes of the DataTree.
Definition: mitkDataNode.h:66
static itkEventMacro(BoundingShapeInteractionEvent, itk::AnyEvent) class MITKBOUNDINGSHAPE_EXPORT BoundingShapeInteractor Pointer New()
Basic interaction methods for mitk::GeometryData.