opensurgsim
SegmentMeshShape.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_SEGMENTMESHSHAPE_H
17 #define SURGSIM_MATH_SEGMENTMESHSHAPE_H
18 
19 #include "SurgSim/DataStructures/AabbTree.h"
20 #include "SurgSim/DataStructures/SegmentMesh.h"
21 #include "SurgSim/Framework/ObjectFactory.h"
22 #include "SurgSim/Math/Geometry.h"
23 #include "SurgSim/Math/Shape.h"
24 #include "SurgSim/Math/VerticesShape.h"
25 
26 namespace SurgSim
27 {
28 
29 namespace Math
30 {
31 SURGSIM_STATIC_REGISTRATION(SegmentMeshShape);
32 
38 {
39 public:
42 
45  explicit SegmentMeshShape(const SegmentMeshShape& other);
46 
51  template <class VertexData, class EdgeData>
53  double radius = Geometry::DistanceEpsilon);
54 
55  SURGSIM_CLASSNAME(SurgSim::Math::SegmentMeshShape);
56 
57  int getType() const override;
58  double getVolume() const override;
59  Vector3d getCenter() const override;
60  Matrix33d getSecondMomentOfVolume() const override;
61  bool isValid() const override;
62 
64  void setRadius(double radius);
65 
67  double getRadius() const;
68 
70  std::shared_ptr<const DataStructures::AabbTree> getAabbTree() const;
71 
72  std::shared_ptr<Shape> getTransformed(const RigidTransform3d& pose) const override;
73 
74  void setPose(const RigidTransform3d& pose) override;
75 
77  void buildAabbTree();
78 
80  void updateAabbTree();
81 
82  void updateShape() override;
83  void updateShapePartial() override;
84 
85 protected:
86  bool doUpdate() override;
87  bool doLoad(const std::string& fileName) override;
88 
89 
90 
91 private:
93  double m_radius;
94 
96  std::shared_ptr<DataStructures::AabbTree> m_aabbTree;
97  std::vector<SurgSim::Math::Aabbd> m_aabbCache;
98 
100  Vector3d m_segmentEndBoundingBoxHalfExtent;
101 };
102 
103 } // Math
104 } // SurgSim
105 
106 #include "SurgSim/Math/SegmentMeshShape-inl.h"
107 
108 #endif // SURGSIM_MATH_SEGMENTMESHSHAPE_H
Wraps glewInit() to separate the glew opengl definitions from the osg opengl definitions only imgui n...
Definition: AddRandomSphereBehavior.cpp:36
std::shared_ptr< const DataStructures::AabbTree > getAabbTree() const
Definition: SegmentMeshShape.cpp:126
Eigen::Transform< double, 3, Eigen::Isometry > RigidTransform3d
A 3D rigid (isometric) transform, represented as doubles.
Definition: RigidTransform.h:46
void setRadius(double radius)
Definition: SegmentMeshShape.cpp:77
void buildAabbTree()
Build the AabbTree, which is an axis-aligned bounding box r-tree used to accelerate spatial searches...
Definition: SegmentMeshShape.cpp:139
SegmentMeshShape()
Constructor.
Definition: SegmentMeshShape.cpp:32
bool isValid() const override
Check if the shape is valid.
Definition: SegmentMeshShape.cpp:69
void setPose(const RigidTransform3d &pose) override
Set the pose on a transformable shape.
Definition: SegmentMeshShape.cpp:184
A Shape that also inherits from Vertices is transformable and carries a member variable of the initia...
Definition: VerticesShape.h:30
void updateShapePartial() override
Update some of the internals of a transformable shape.
Definition: SegmentMeshShape.cpp:93
Class to hold the type of a SegmentMesh.
Definition: SegmentMesh.h:33
void updateShape() override
Update the internals of a transformable shape.
Definition: SegmentMeshShape.cpp:88
Vector3d getCenter() const override
Get the volumetric center of the shape.
Definition: SegmentMeshShape.cpp:57
bool doLoad(const std::string &fileName) override
Derived classes will overwrite this method to do actual loading.
Definition: SegmentMeshShape.cpp:104
double getRadius() const
Definition: SegmentMeshShape.cpp:83
SegmentMeshShape defines a shape based on a mesh, like MeshShape.
Definition: SegmentMeshShape.h:37
int getType() const override
Definition: SegmentMeshShape.cpp:46
void updateAabbTree()
Update the AabbTree, which is an axis-aligned bounding box r-tree used to accelerate spatial searches...
Definition: SegmentMeshShape.cpp:163
std::shared_ptr< Shape > getTransformed(const RigidTransform3d &pose) const override
Get a copy of this shape with an applied rigid transform.
Definition: SegmentMeshShape.cpp:131
Matrix33d getSecondMomentOfVolume() const override
Get the second central moment of the volume, commonly used to calculate the moment of inertia matrix...
Definition: SegmentMeshShape.cpp:63
double getVolume() const override
Get the volume of the shape.
Definition: SegmentMeshShape.cpp:51
bool doUpdate() override
Performs any updates that are required when the vertices are modified.
Definition: SegmentMeshShape.cpp:98
a collection of functions that calculation geometric properties of various basic geometric shapes...