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 #ifndef SURGSIM_MATH_MESHSHAPE_H
17 #define SURGSIM_MATH_MESHSHAPE_H
18 
19 #include <memory>
20 
26 #include "SurgSim/Math/Shape.h"
27 
28 namespace SurgSim
29 {
30 namespace DataStructures
31 {
32 class AabbTree;
33 }
34 
35 namespace Math
36 {
37 
38 SURGSIM_STATIC_REGISTRATION(MeshShape);
39 
54 class MeshShape : public Shape, public SurgSim::DataStructures::TriangleMesh<SurgSim::DataStructures::EmptyData,
55  SurgSim::DataStructures::EmptyData, SurgSim::DataStructures::NormalData>
56 {
57 public:
59  MeshShape();
60 
63  explicit MeshShape(const MeshShape& other);
64 
70  template <class V, class E, class T>
72 
74 
75  int getType() const override;
76 
80  const SurgSim::Math::Vector3d& getNormal(size_t triangleId) const;
81 
82  double getVolume() const override;
83 
84  Vector3d getCenter() const override;
85 
86  Matrix33d getSecondMomentOfVolume() const override;
87 
88  std::shared_ptr<Shape> getTransformed(const RigidTransform3d& pose) const override;
89 
92  const std::shared_ptr<const SurgSim::DataStructures::AabbTree> getAabbTree() const;
93 
94  bool isValid() const override;
95 
96  bool isTransformable() const override;
97 
98 protected:
99  bool doUpdate() override;
100 
101  bool doLoad(const std::string& fileName) override;
102 
106  bool calculateNormals();
107 
109  void updateAabbTree();
110 
113  virtual void computeVolumeIntegrals();
114 
117 
119  double m_volume;
120 
123 
124 private:
126  std::shared_ptr<SurgSim::DataStructures::AabbTree> m_aabbTree;
127 };
128 
129 }; // Math
130 }; // SurgSim
131 
133 
134 #endif // SURGSIM_MATH_MESHSHAPE_H
Definition: CompoundShapeToGraphics.cpp:29
::SurgSim::Math::Vector3d Vector3d
Definition: Shape.h:68
Mesh shape: shape made of a triangle mesh The triangle mesh needs to be watertight to produce valid v...
Definition: MeshShape.h:54
double m_volume
Volume (in m^-3)
Definition: MeshShape.h:119
#define SURGSIM_CLASSNAME(ClassName)
Declare the class name of a class with the appropriate function header, do not use quotes...
Definition: Macros.h:21
bool isValid(float value)
Check if a float value is valid.
Definition: Valid-inl.h:98
std::shared_ptr< SurgSim::DataStructures::AabbTree > m_aabbTree
The aabb tree used to accelerate collision detection against the mesh.
Definition: MeshShape.h:126
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
SurgSim::Math::Matrix33d m_secondMomentOfVolume
Second moment of volume.
Definition: MeshShape.h:122
Basic class for storing Triangle Meshes, handling basic vertex, edge, and triangle functionality...
Definition: TriangleMesh.h:62
::SurgSim::Math::Matrix33d Matrix33d
Definition: Shape.h:69
SurgSim::Math::Vector3d m_center
Center (considering a uniform distribution in the mesh volume)
Definition: MeshShape.h: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:57
Generic rigid shape class defining a shape.
Definition: Shape.h:65