All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
MeshShape.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 // This code is based on David Eberly's paper:
17 // http://www.geometrictools.com/Documentation/PolyhedralMassProperties.pdf
18 // which is improving Brian Mirtich previous work (http://www.cs.berkeley.edu/~jfc/mirtich/massProps.html)
19 // by making the assumption that the polyhedral mesh is composed of triangles.
20 
21 #ifndef SURGSIM_MATH_MESHSHAPE_H
22 #define SURGSIM_MATH_MESHSHAPE_H
23 
30 #include "SurgSim/Math/Shape.h"
31 
32 namespace SurgSim
33 {
34 
35 namespace Math
36 {
38 
39 
54 {
55 public:
57  MeshShape();
58 
62  template <class VertexData, class EdgeData, class TriangleData>
64 
66 
68  virtual int getType() override;
69 
72  std::shared_ptr<SurgSim::DataStructures::TriangleMesh> getInitialMesh();
73 
76  std::shared_ptr<SurgSim::DataStructures::TriangleMesh> getMesh();
77 
81  virtual double getVolume() const override;
82 
86  virtual Vector3d getCenter() const override;
87 
92  virtual Matrix33d getSecondMomentOfVolume() const override;
93 
96  void setPose(const SurgSim::Math::RigidTransform3d &pose);
97 
99  void updateAabbTree();
100 
103  std::shared_ptr<SurgSim::DataStructures::AabbTree> getAabbTree();
104 
108  bool isValid() const;
109 
110 protected:
111  virtual bool doLoad(const std::string& filePath) override;
112 
113 private:
116  void computeVolumeIntegrals();
117 
120 
122  double m_volume;
123 
126 
128  std::shared_ptr<SurgSim::DataStructures::TriangleMesh> m_mesh;
129 
131  std::shared_ptr<SurgSim::DataStructures::TriangleMesh> m_initialMesh;
132 
134  std::shared_ptr<SurgSim::DataStructures::AabbTree> m_aabbTree;
135 };
136 
137 }; // Math
138 }; // SurgSim
139 
141 
142 #endif // SURGSIM_MATH_MESHSHAPE_H
virtual Matrix33d getSecondMomentOfVolume() const override
Get the second central moment of the volume, commonly used to calculate the moment of inertia matrix...
Definition: MeshShape.cpp:86
This class is used to facilitate file loading.
Definition: Asset.h:33
std::shared_ptr< SurgSim::DataStructures::TriangleMesh > m_initialMesh
The initial triangle mesh contained by this shape.
Definition: MeshShape.h:131
bool isValid() const
Check if this shape contains a valid mesh.
Definition: MeshShape.cpp:37
SURGSIM_STATIC_REGISTRATION(BoxShape)
virtual int getType() override
Definition: MeshShape.cpp:32
::SurgSim::Math::Vector3d Vector3d
Definition: Shape.h:62
Mesh shape: shape made of a triangle mesh The triangle mesh needs to be watertight to produce valid v...
Definition: MeshShape.h:53
std::shared_ptr< SurgSim::DataStructures::AabbTree > getAabbTree()
Get the AabbTree.
Definition: MeshShape.cpp:192
double m_volume
Volume (in m^-3)
Definition: MeshShape.h:122
void updateAabbTree()
Update the AabbTree, which is an axis-aligned bounding box r-tree used to accelerate spatial searches...
Definition: MeshShape.cpp:197
void setPose(const SurgSim::Math::RigidTransform3d &pose)
Set the object's global pose.
Definition: MeshShape.cpp:186
std::shared_ptr< SurgSim::DataStructures::TriangleMesh > m_mesh
The triangle mesh contained by this shape.
Definition: MeshShape.h:128
std::shared_ptr< SurgSim::DataStructures::TriangleMesh > getInitialMesh()
Gets the initial mesh.
Definition: MeshShape.cpp:56
std::shared_ptr< SurgSim::DataStructures::AabbTree > m_aabbTree
The aabb tree used to accelerate collision detection against the mesh.
Definition: MeshShape.h:134
Definitions of 2x2 and 3x3 rigid (isometric) transforms.
Eigen::Transform< double, 3, Eigen::Isometry > RigidTransform3d
A 3D rigid (isometric) transform, represented as doubles.
Definition: RigidTransform.h:46
std::shared_ptr< SurgSim::DataStructures::TriangleMesh > getMesh()
Get mesh.
Definition: MeshShape.cpp:61
Basic class for storing Triangle Meshes, handling basic vertex, edge, and triangle functionality...
Definition: TriangleMeshBase.h:58
SURGSIM_CLASSNAME(SurgSim::Math::MeshShape)
virtual Vector3d getCenter() const override
Get the volumetric center of the shape.
Definition: MeshShape.cpp:76
SurgSim::Math::Matrix33d m_secondMomentOfVolume
Second moment of volume.
Definition: MeshShape.h:125
virtual double getVolume() const override
Get the volume of the shape.
Definition: MeshShape.cpp:66
MeshShape()
Constructor.
Definition: MeshShape.cpp:27
virtual bool doLoad(const std::string &filePath) override
Derived classes will overwrite this method to do actual loading.
Definition: MeshShape.cpp:42
::SurgSim::Math::Matrix33d Matrix33d
Definition: Shape.h:63
SurgSim::Math::Vector3d m_center
Center (considering a uniform distribution in the mesh volume)
Definition: MeshShape.h:119
void computeVolumeIntegrals()
Compute useful volume integrals based on the triangle mesh, which are used to get the volume ...
Definition: MeshShape.cpp:116
Eigen::Matrix< double, 3, 3, Eigen::RowMajor > Matrix33d
A 3x3 matrix of doubles.
Definition: Matrix.h:51
Eigen::Matrix< double, 3, 1 > Vector3d
A 3D vector of doubles.
Definition: Vector.h:56
Generic rigid shape class defining a shape.
Definition: Shape.h:59