CompoundShape.h
Go to the documentation of this file.
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"
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 
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 
69  RigidTransform3d getPose(size_t index) const;
70 
74  void setPoses(const std::vector<RigidTransform3d>& poses);
75 
80  void setPose(size_t index, const RigidTransform3d& pose);
81 
83  size_t getNumShapes() const;
84 
86  void clearShapes();
87 
88  int getType() const override;
89 
93  double getVolume() const override;
94 
95  Vector3d getCenter() const override;
96 
97  Matrix33d getSecondMomentOfVolume() const override;
98 
99  bool isValid() const override;
100 
101  const Math::Aabbd& getBoundingBox() const override;
102 
103  bool isTransformable() const override;
104 
105  std::shared_ptr<Shape> getTransformed(const RigidTransform3d& pose) const override;
106 
107 private:
108 
111  void invalidateData();
112 
113  std::vector<SubShape> m_shapes;
114 
115  typedef boost::shared_lock<boost::shared_mutex> ReadLock;
116  typedef boost::unique_lock<boost::shared_mutex> WriteLock;
117 
118  mutable boost::shared_mutex m_mutex;
119 
129 
130 };
131 
132 }
133 }
134 
135 #endif
Definition: CompoundShapeToGraphics.cpp:29
const std::vector< SubShape > & getShapes() const
Definition: CompoundShape.cpp:199
Vector3d getCenter() const override
Get the volumetric center of the shape.
Definition: CompoundShape.cpp:71
DataStructures::OptionalValue< double > m_volume
Definition: CompoundShape.h:125
boost::unique_lock< boost::shared_mutex > WriteLock
Definition: CompoundShape.h:116
DataStructures::OptionalValue< Math::Aabbd > m_localAabb
Definition: CompoundShape.h:127
SURGSIM_CLASSNAME(SurgSim::Math::CompoundShape)
RigidTransform3d getPose(size_t index) const
Definition: CompoundShape.cpp:212
boost::shared_lock< boost::shared_mutex > ReadLock
Definition: CompoundShape.h:115
int getType() const override
Definition: CompoundShape.cpp:39
const std::shared_ptr< Shape > & getShape(size_t index) const
Definition: CompoundShape.cpp:205
std::vector< SubShape > m_shapes
Definition: CompoundShape.h:113
std::shared_ptr< Shape > getTransformed(const RigidTransform3d &pose) const override
Get a copy of this shape with an applied rigid transform.
Definition: CompoundShape.cpp:258
Eigen::AlignedBox< double, 3 > Aabbd
Wrapper around the Eigen type.
Definition: Aabb.h:30
Definition: CompoundShape.h:36
double getVolume() const override
Definition: CompoundShape.cpp:44
DataStructures::OptionalValue< Matrix33d > m_secondMoment
Definition: CompoundShape.h:126
DataStructures::OptionalValue< Vector3d > m_center
Definition: CompoundShape.h:124
~CompoundShape()
Destructor.
Definition: CompoundShape.cpp:35
Definitions of 2x2 and 3x3 rigid (isometric) transforms.
void setPose(size_t index, const RigidTransform3d &pose)
Set the pose for the specified shape.
Definition: CompoundShape.cpp:232
Eigen::Transform< double, 3, Eigen::Isometry > RigidTransform3d
A 3D rigid (isometric) transform, represented as doubles.
Definition: RigidTransform.h:46
bool isValid() const override
Check if the shape is valid.
Definition: CompoundShape.cpp:146
size_t getNumShapes() const
Definition: CompoundShape.cpp:240
bool isTransformable() const override
Definition: CompoundShape.cpp:253
boost::shared_mutex m_mutex
Definition: CompoundShape.h:118
void setPoses(const std::vector< RigidTransform3d > &poses)
Sets the poses for all shapes.
Definition: CompoundShape.cpp:219
void invalidateData()
Clears the data for the volume, center and secondMoment and aabb so it can be recalculated when neede...
Definition: CompoundShape.cpp:176
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:192
CompoundShape()
Constructor.
Definition: CompoundShape.cpp:27
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 pose for the added shape.
Definition: CompoundShape.cpp:184
Eigen::Matrix< double, 3, 1 > Vector3d
A 3D vector of doubles.
Definition: Vector.h:57
const Math::Aabbd & getBoundingBox() const override
Definition: CompoundShape.cpp:151
Matrix33d getSecondMomentOfVolume() const override
Get the second central moment of the volume, commonly used to calculate the moment of inertia matrix...
Definition: CompoundShape.cpp:106
void clearShapes()
clears all the enclosed shapes
Definition: CompoundShape.cpp:246
std::pair< std::shared_ptr< Shape >, RigidTransform3d > SubShape
Definition: CompoundShape.h:47
Generic rigid shape class defining a shape.
Definition: Shape.h:65