opensurgsim
TransferPhysicsToGraphicsMeshBehavior.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 SURGSIM_BLOCKS_TRANSFERPHYSICSTOGRAPHICSMESHBEHAVIOR_H
17 #define SURGSIM_BLOCKS_TRANSFERPHYSICSTOGRAPHICSMESHBEHAVIOR_H
18 
19 #include "SurgSim/DataStructures/TriangleMesh.h"
20 #include "SurgSim/Framework/Behavior.h"
21 #include "SurgSim/Framework/Macros.h"
22 
23 namespace SurgSim
24 {
25 
26 namespace Framework
27 {
28 class Component;
29 class Asset;
30 }
31 
32 namespace Graphics
33 {
34 class MeshRepresentation;
35 }
36 
37 namespace Physics
38 {
39 class DeformableRepresentation;
40 }
41 
42 namespace Blocks
43 {
44 SURGSIM_STATIC_REGISTRATION(TransferPhysicsToGraphicsMeshBehavior);
45 
52 {
53 public:
56  explicit TransferPhysicsToGraphicsMeshBehavior(const std::string& name);
57 
59 
62  void setSource(const std::shared_ptr<Framework::Component>& source);
63 
66  void setTarget(const std::shared_ptr<Framework::Component>& target);
67 
70  std::shared_ptr<Physics::DeformableRepresentation> getSource() const;
71 
74  std::shared_ptr<Graphics::MeshRepresentation> getTarget() const;
75 
80  void setIndexMap(
81  const std::shared_ptr<DataStructures::TriangleMeshPlain>& source,
82  const std::shared_ptr<DataStructures::TriangleMeshPlain>& target);
83 
88  void setIndexMap(const std::string& sourceFile, const std::string& targetFile);
89 
93  void setIndexMap(const std::vector<std::pair<size_t, size_t>>& indexMap);
94 
96  const std::vector<std::pair<size_t, size_t>> getIndexMap() const;
97 
98  void update(double dt) override;
99 
100 private:
101  bool doInitialize() override;
102  bool doWakeUp() override;
103 
104 
105  void setIndexMap(const std::pair<std::string, std::string>& fileName);
106 
107  void setIndexMap(const std::pair<std::shared_ptr<Framework::Asset>, std::shared_ptr<Framework::Asset>>& meshes);
108 
110  std::shared_ptr<Physics::DeformableRepresentation> m_source;
111 
113  std::shared_ptr<Graphics::MeshRepresentation> m_target;
114 
116  std::vector<std::pair<size_t, size_t>> m_indexMap;
117 };
118 
124 std::vector<std::pair<size_t, size_t>> generateIndexMap(
125  const std::shared_ptr<DataStructures::TriangleMeshPlain>& source,
126  const std::shared_ptr<DataStructures::TriangleMeshPlain>& target);
127 
128 }; // namespace Blocks
129 }; // namespace SurgSim
130 
131 #endif // SURGSIM_BLOCKS_TRANSFERPHYSICSTOGRAPHICSMESHBEHAVIOR_H
Wraps glewInit() to separate the glew opengl definitions from the osg opengl definitions only imgui n...
Definition: AddRandomSphereBehavior.cpp:36
Behaviors perform actions.
Definition: Behavior.h:40
Behavior to copy positions of a PhysicsRepresentation to a GraphicsMesh.
Definition: TransferPhysicsToGraphicsMeshBehavior.h:51