opensurgsim
StaplerBehavior.h
1 // This file is a part of the OpenSurgSim project.
2 // Copyright 2013, SimQuest Solutions Inc.
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 // http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 
16 #ifndef EXAMPLES_STAPLING_STAPLERBEHAVIOR_H
17 #define EXAMPLES_STAPLING_STAPLERBEHAVIOR_H
18 
19 #include <array>
20 #include <memory>
21 #include <string>
22 #include <unordered_map>
23 
24 #include "SurgSim/Framework/Behavior.h"
25 #include "SurgSim/Framework/ObjectFactory.h"
26 #include "SurgSim/Collision/Representation.h"
27 
28 namespace SurgSim
29 {
30 
31 namespace DataStructures
32 {
33 struct Location;
34 }
35 
36 namespace Framework
37 {
38 class Representation;
39 }
40 
41 namespace Graphics
42 {
43 class SceneryRepresentation;
44 }
45 
46 namespace Input
47 {
48 class InputComponent;
49 }
50 
51 namespace Physics
52 {
53 class Constraint;
54 }
55 
56 }
57 
58 SURGSIM_STATIC_REGISTRATION(StaplerBehavior);
59 
64 {
65 public:
68  explicit StaplerBehavior(const std::string& name);
69 
70  SURGSIM_CLASSNAME(StaplerBehavior);
71 
74  void setInputComponent(std::shared_ptr<SurgSim::Framework::Component> inputComponent);
75 
77  std::shared_ptr<SurgSim::Input::InputComponent> getInputComponent();
78 
81  void setRepresentation(std::shared_ptr<SurgSim::Framework::Component> staplerRepresentation);
82 
84  std::shared_ptr<SurgSim::Framework::Representation> getRepresentation();
85 
88  void update(double dt) override;
89 
92  int getTargetManagerType() const override;
93 
96  void setVirtualTeeth(const std::array<std::shared_ptr<SurgSim::Collision::Representation>, 2>& virtualTeeth);
97 
99  const std::array<std::shared_ptr<SurgSim::Collision::Representation>, 2>& getVirtualTeeth();
100 
103  void enableStaplingForSceneElement(const std::string& sceneElementName);
104 
107  void setStapleEnabledSceneElements(const std::list<std::string>& stapleEnabledSceneElements);
108 
110  const std::list<std::string>& getStapleEnabledSceneElements();
111 
112 protected:
116  bool doInitialize() override;
117 
121  bool doWakeUp() override;
122 
123 private:
127  void filterCollisionMapForStapleEnabledRepresentations(SurgSim::Collision::ContactMapType *collisionsMap);
128 
132  std::shared_ptr<SurgSim::Physics::Representation> findCorrespondingPhysicsRepresentation(
133  std::shared_ptr<SurgSim::Collision::Representation> collisionRepresentation);
134 
137  void filterCollisionMapForSupportedRepresentationTypes(SurgSim::Collision::ContactMapType* collisionsMap);
138 
142  void createStaple();
143 
145  std::shared_ptr<SurgSim::Input::InputComponent> m_from;
146 
148  std::shared_ptr<SurgSim::Framework::Representation> m_representation;
149 
151  int m_numElements;
152 
154  int m_button1Index;
155 
157  bool m_button1IndexCached;
158 
160  bool m_buttonPreviouslyPressed;
161 
163  std::array<std::shared_ptr<SurgSim::Collision::Representation>, 2> m_virtualTeeth;
164 
166  std::list<std::string> m_stapleEnabledSceneElements;
167 };
168 
169 #endif // EXAMPLES_STAPLING_STAPLERBEHAVIOR_H
Wraps glewInit() to separate the glew opengl definitions from the osg opengl definitions only imgui n...
Definition: AddRandomSphereBehavior.cpp:36
This behavior is used to add staples.
Definition: StaplerBehavior.h:63
Behaviors perform actions.
Definition: Behavior.h:40