TransferPhysicsToGraphicsMeshBehavior.h
Go to the documentation of this file.
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 
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
SurgSim::Blocks::TransferPhysicsToGraphicsMeshBehavior
Behavior to copy positions of a PhysicsRepresentation to a GraphicsMesh.
Definition: TransferPhysicsToGraphicsMeshBehavior.h:51
Macros.h
SurgSim::Blocks::TransferPhysicsToGraphicsMeshBehavior::m_source
std::shared_ptr< Physics::DeformableRepresentation > m_source
The DeformableRepresentation from which the Ode state comes.
Definition: TransferPhysicsToGraphicsMeshBehavior.h:110
SurgSim::Blocks::TransferPhysicsToGraphicsMeshBehavior::getSource
std::shared_ptr< Physics::DeformableRepresentation > getSource() const
Get the Physics representation which sends the positions.
Definition: TransferPhysicsToGraphicsMeshBehavior.cpp:109
SurgSim::Blocks::TransferPhysicsToGraphicsMeshBehavior::update
void update(double dt) override
Update the behavior.
Definition: TransferPhysicsToGraphicsMeshBehavior.cpp:119
SurgSim::Blocks::TransferPhysicsToGraphicsMeshBehavior::doWakeUp
bool doWakeUp() override
Interface to be implemented by derived classes.
Definition: TransferPhysicsToGraphicsMeshBehavior.cpp:148
SurgSim::Blocks::TransferPhysicsToGraphicsMeshBehavior::setTarget
void setTarget(const std::shared_ptr< Framework::Component > &target)
Set the representation which will receive the positions.
Definition: TransferPhysicsToGraphicsMeshBehavior.cpp:102
SurgSim::Framework::Behavior
Behaviors perform actions.
Definition: Behavior.h:40
SurgSim
Definition: CompoundShapeToGraphics.cpp:29
SurgSim::Blocks::TransferPhysicsToGraphicsMeshBehavior::setSource
void setSource(const std::shared_ptr< Framework::Component > &source)
Set the representation from which the positions are from.
Definition: TransferPhysicsToGraphicsMeshBehavior.cpp:95
SurgSim::Blocks::TransferPhysicsToGraphicsMeshBehavior::TransferPhysicsToGraphicsMeshBehavior
TransferPhysicsToGraphicsMeshBehavior(const std::string &name)
Constructor.
Definition: TransferPhysicsToGraphicsMeshBehavior.cpp:41
SurgSim::Blocks::TransferPhysicsToGraphicsMeshBehavior::doInitialize
bool doInitialize() override
Interface to be implemented by derived classes.
Definition: TransferPhysicsToGraphicsMeshBehavior.cpp:143
SurgSim::Blocks::TransferPhysicsToGraphicsMeshBehavior::getTarget
std::shared_ptr< Graphics::MeshRepresentation > getTarget() const
Get the Graphics representation which receives the positions.
Definition: TransferPhysicsToGraphicsMeshBehavior.cpp:114
SurgSim::Blocks::TransferPhysicsToGraphicsMeshBehavior::SURGSIM_CLASSNAME
SURGSIM_CLASSNAME(SurgSim::Blocks::TransferPhysicsToGraphicsMeshBehavior)
SurgSim::Blocks::TransferPhysicsToGraphicsMeshBehavior::getIndexMap
const std::vector< std::pair< size_t, size_t > > getIndexMap() const
Definition: TransferPhysicsToGraphicsMeshBehavior.cpp:206
TriangleMesh.h
SurgSim::Blocks::TransferPhysicsToGraphicsMeshBehavior::m_target
std::shared_ptr< Graphics::MeshRepresentation > m_target
The Graphics Mesh Representation to which the vertices' positions are set.
Definition: TransferPhysicsToGraphicsMeshBehavior.h:113
SurgSim::Blocks::TransferPhysicsToGraphicsMeshBehavior::setIndexMap
void setIndexMap(const std::shared_ptr< DataStructures::TriangleMeshPlain > &source, const std::shared_ptr< DataStructures::TriangleMeshPlain > &target)
Generate a mapping, for each point in source find the points target that coincide.
Definition: TransferPhysicsToGraphicsMeshBehavior.cpp:165
SurgSim::Blocks::generateIndexMap
std::vector< std::pair< size_t, size_t > > generateIndexMap(const std::shared_ptr< DataStructures::TriangleMeshPlain > &source, const std::shared_ptr< DataStructures::TriangleMeshPlain > &target)
Generate a mapping, for each point in source find the points target that coincide.
Definition: TransferPhysicsToGraphicsMeshBehavior.cpp:211
Behavior.h
SurgSim::Blocks::TransferPhysicsToGraphicsMeshBehavior::m_indexMap
std::vector< std::pair< size_t, size_t > > m_indexMap
The mapping to be used if not empty.
Definition: TransferPhysicsToGraphicsMeshBehavior.h:116