opensurgsim
MeshShape.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_MATH_MESHSHAPE_H
17 #define SURGSIM_MATH_MESHSHAPE_H
18 
19 #include <memory>
20 
21 #include "SurgSim/DataStructures/EmptyData.h"
22 #include "SurgSim/DataStructures/NormalData.h"
23 #include "SurgSim/DataStructures/TriangleMesh.h"
24 #include "SurgSim/Framework/ObjectFactory.h"
26 #include "SurgSim/Math/Shape.h"
27 #include "SurgSim/Math/VerticesShape.h"
28 
29 namespace SurgSim
30 {
31 namespace DataStructures
32 {
33 class AabbTree;
34 class AabbTreeNode;
35 }
36 
37 namespace Math
38 {
39 
40 SURGSIM_STATIC_REGISTRATION(MeshShape);
41 
56 class MeshShape : public VerticesShape, public SurgSim::DataStructures::TriangleMesh<SurgSim::DataStructures::EmptyData,
57  SurgSim::DataStructures::EmptyData, SurgSim::DataStructures::NormalData>
58 {
59 public:
61  MeshShape();
62 
65  explicit MeshShape(const MeshShape& other);
66 
72  template <class V, class E, class T>
74 
75  SURGSIM_CLASSNAME(SurgSim::Math::MeshShape);
76 
77  int getType() const override;
78 
82  const SurgSim::Math::Vector3d& getNormal(size_t triangleId) const;
83 
84  double getVolume() const override;
85 
86  Vector3d getCenter() const override;
87 
88  Matrix33d getSecondMomentOfVolume() const override;
89 
90  std::shared_ptr<Shape> getTransformed(const RigidTransform3d& pose) const override;
91 
94  const std::shared_ptr<const SurgSim::DataStructures::AabbTree> getAabbTree() const;
95 
96  bool isValid() const override;
97 
98  void setPose(const RigidTransform3d& pose) override;
99 
101  void buildAabbTree();
102 
105  void updateAabbTree();
106 
110  bool calculateNormals();
111 
112  void updateShape() override;
113  void updateShapePartial() override;
114 
115 protected:
116  bool doUpdate() override;
117 
118  bool doLoad(const std::string& fileName) override;
119 
122  virtual void computeVolumeIntegrals();
123 
126 
128  double m_volume;
129 
132 
133 private:
135  std::shared_ptr<SurgSim::DataStructures::AabbTree> m_aabbTree;
136  std::vector<SurgSim::Math::Aabbd> m_aabbCache;
137 };
138 
139 }; // Math
140 }; // SurgSim
141 
142 #include "SurgSim/Math/MeshShape-inl.h"
143 
144 #endif // SURGSIM_MATH_MESHSHAPE_H
Wraps glewInit() to separate the glew opengl definitions from the osg opengl definitions only imgui n...
Definition: AddRandomSphereBehavior.cpp:36
Eigen::Transform< double, 3, Eigen::Isometry > RigidTransform3d
A 3D rigid (isometric) transform, represented as doubles.
Definition: RigidTransform.h:46
Mesh shape: shape made of a triangle mesh The triangle mesh needs to be watertight to produce valid v...
Definition: MeshShape.h:56
double m_volume
Volume (in m^-3)
Definition: MeshShape.h:128
Eigen::Matrix< double, 3, 1 > Vector3d
A 3D vector of doubles.
Definition: Vector.h:57
A Shape that also inherits from Vertices is transformable and carries a member variable of the initia...
Definition: VerticesShape.h:30
Definitions of 2x2 and 3x3 rigid (isometric) transforms.
SurgSim::Math::Matrix33d m_secondMomentOfVolume
Second moment of volume.
Definition: MeshShape.h:131
bool isValid(float value)
Check if a float value is valid.
Definition: Valid-inl.h:97
Basic class for storing Triangle Meshes, handling basic vertex, edge, and triangle functionality...
Definition: TriangleMesh.h:62
SurgSim::Math::Vector3d m_center
Center (considering a uniform distribution in the mesh volume)
Definition: MeshShape.h:125
Eigen::Matrix< double, 3, 3, Eigen::RowMajor > Matrix33d
A 3x3 matrix of doubles.
Definition: Matrix.h:51