opensurgsim
CompoundShape.h
1 // This file is a part of the OpenSurgSim project.
2 // Copyright 2013-2015, 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_COMPOUNDSHAPE_H
17 #define SURGSIM_MATH_COMPOUNDSHAPE_H
18 
19 #include <memory>
20 #include <utility>
21 
22 #include <boost/thread.hpp>
23 
24 #include "SurgSim/Math/Shape.h"
26 #include "SurgSim/DataStructures/OptionalValue.h"
27 
28 namespace SurgSim
29 {
30 
31 namespace Math
32 {
33 
34 SURGSIM_STATIC_REGISTRATION(CompoundShape);
35 
36 class CompoundShape : public Shape
37 {
38 public:
40  CompoundShape();
41 
44 
45  SURGSIM_CLASSNAME(SurgSim::Math::CompoundShape);
46 
47  typedef std::pair<std::shared_ptr<Shape>, RigidTransform3d> SubShape;
48 
53  size_t addShape(const std::shared_ptr<Shape>& shape, const RigidTransform3d& pose = RigidTransform3d::Identity());
54 
58  void setShapes(const std::vector<SubShape>& shapes);
59 
61  const std::vector<SubShape>& getShapes() const;
62 
65  const std::shared_ptr<Shape>& getShape(size_t index) const;
66 
70  RigidTransform3d getCompoundPose(size_t index) const;
71 
74  RigidTransform3d getPose(size_t index) const;
75 
77  const std::vector<RigidTransform3d>& getPoses() const;
78 
82  void setPoses(const std::vector<RigidTransform3d>& poses);
83 
88  void setPose(size_t index, const RigidTransform3d& pose);
89 
91  size_t getNumShapes() const;
92 
94  void clearShapes();
95 
96  int getType() const override;
97 
101  double getVolume() const override;
102 
103  Vector3d getCenter() const override;
104 
105  Matrix33d getSecondMomentOfVolume() const override;
106 
107  bool isValid() const override;
108 
109  const Math::Aabbd& getBoundingBox() const override;
110 
111  bool isTransformable() const override;
112  std::shared_ptr<Shape> getTransformed(const RigidTransform3d& pose) const override;
113  void setPose(const RigidTransform3d& pose) override;
114  void updateShape() override;
115  void updateShapePartial() override;
116 
117 private:
118 
121  void invalidateData();
122 
123  std::vector<SubShape> m_shapes;
125  std::vector<RigidTransform3d> m_poses;
126  RigidTransform3d m_lastSetPose;
127 
128  typedef boost::shared_lock<boost::shared_mutex> ReadLock;
129  typedef boost::unique_lock<boost::shared_mutex> WriteLock;
130 
131  mutable boost::shared_mutex m_mutex;
132 
138  mutable DataStructures::OptionalValue<double> m_volume;
139  mutable DataStructures::OptionalValue<Matrix33d> m_secondMoment;
140  mutable DataStructures::OptionalValue<Math::Aabbd> m_localAabb;
142 
143 };
144 
145 }
146 }
147 
148 #endif
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
const std::vector< SubShape > & getShapes() const
Definition: CompoundShape.cpp:226
Vector3d getCenter() const override
Get the volumetric center of the shape.
Definition: CompoundShape.cpp:72
Eigen::Matrix< double, 3, 1 > Vector3d
A 3D vector of doubles.
Definition: Vector.h:57
RigidTransform3d getPose(size_t index) const
Definition: CompoundShape.cpp:246
void updateShape() override
Update the internals of a transformable shape.
Definition: CompoundShape.cpp:367
const std::vector< RigidTransform3d > & getPoses() const
Definition: CompoundShape.cpp:253
int getType() const override
Definition: CompoundShape.cpp:40
const std::shared_ptr< Shape > & getShape(size_t index) const
Definition: CompoundShape.cpp:232
std::shared_ptr< Shape > getTransformed(const RigidTransform3d &pose) const override
Get a copy of this shape with an applied rigid transform.
Definition: CompoundShape.cpp:320
RigidTransform3d getCompoundPose(size_t index) const
Definition: CompoundShape.cpp:239
Definition: CompoundShape.h:36
double getVolume() const override
Definition: CompoundShape.cpp:45
~CompoundShape()
Destructor.
Definition: CompoundShape.cpp:36
Definitions of 2x2 and 3x3 rigid (isometric) transforms.
void setPose(size_t index, const RigidTransform3d &pose)
Set the local pose for the specified shape with respect to this CompoundShape.
Definition: CompoundShape.cpp:283
bool isValid() const override
Check if the shape is valid.
Definition: CompoundShape.cpp:147
size_t getNumShapes() const
Definition: CompoundShape.cpp:302
bool isTransformable() const override
Definition: CompoundShape.cpp:315
void updateShapePartial() override
Update some of the internals of a transformable shape.
Definition: CompoundShape.cpp:376
void setPoses(const std::vector< RigidTransform3d > &poses)
Sets the local poses for all subshapes with respect to this CompoundShape.
Definition: CompoundShape.cpp:259
Eigen::Matrix< double, 3, 3, Eigen::RowMajor > Matrix33d
A 3x3 matrix of doubles.
Definition: Matrix.h:51
void setShapes(const std::vector< SubShape > &shapes)
Sets the shapes for this object, the shapes should be a list of shapes together with their respective...
Definition: CompoundShape.cpp:205
CompoundShape()
Constructor.
Definition: CompoundShape.cpp:28
size_t addShape(const std::shared_ptr< Shape > &shape, const RigidTransform3d &pose=RigidTransform3d::Identity())
Add a shape to this shape, you can optionally supply a local pose for the added shape w...
Definition: CompoundShape.cpp:185
const Math::Aabbd & getBoundingBox() const override
Definition: CompoundShape.cpp:152
Matrix33d getSecondMomentOfVolume() const override
Get the second central moment of the volume, commonly used to calculate the moment of inertia matrix...
Definition: CompoundShape.cpp:107
void clearShapes()
clears all the enclosed shapes
Definition: CompoundShape.cpp:308
Generic rigid shape class defining a shape.
Definition: Shape.h:65