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
Shape.h
SurgSim::Math::CompoundShape::SubShape
std::pair< std::shared_ptr< Shape >, RigidTransform3d > SubShape
Definition: CompoundShape.h:47
SurgSim::Math::CompoundShape::isValid
bool isValid() const override
Check if the shape is valid.
Definition: CompoundShape.cpp:146
SurgSim::Math::CompoundShape::getCenter
Vector3d getCenter() const override
Get the volumetric center of the shape.
Definition: CompoundShape.cpp:71
SurgSim::Math::CompoundShape::m_secondMoment
DataStructures::OptionalValue< Matrix33d > m_secondMoment
Definition: CompoundShape.h:126
SurgSim::Math::CompoundShape::clearShapes
void clearShapes()
clears all the enclosed shapes
Definition: CompoundShape.cpp:246
SurgSim::DataStructures::OptionalValue< Vector3d >
SurgSim::Math::CompoundShape::m_center
DataStructures::OptionalValue< Vector3d > m_center
Definition: CompoundShape.h:124
SurgSim::Math::RigidTransform3d
Eigen::Transform< double, 3, Eigen::Isometry > RigidTransform3d
A 3D rigid (isometric) transform, represented as doubles.
Definition: RigidTransform.h:46
SurgSim::Math::CompoundShape::getPose
RigidTransform3d getPose(size_t index) const
Definition: CompoundShape.cpp:212
SurgSim::Math::CompoundShape::setPose
void setPose(size_t index, const RigidTransform3d &pose)
Set the pose for the specified shape.
Definition: CompoundShape.cpp:232
OptionalValue.h
SurgSim::Math::Vector3d
Eigen::Matrix< double, 3, 1 > Vector3d
A 3D vector of doubles.
Definition: Vector.h:57
SurgSim::Math::CompoundShape::m_mutex
boost::shared_mutex m_mutex
Definition: CompoundShape.h:118
SurgSim::Math::CompoundShape::getTransformed
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
SurgSim::Math::CompoundShape::getType
int getType() const override
Definition: CompoundShape.cpp:39
SurgSim
Definition: CompoundShapeToGraphics.cpp:30
SurgSim::Math::CompoundShape::m_shapes
std::vector< SubShape > m_shapes
Definition: CompoundShape.h:113
SurgSim::Math::CompoundShape::getShapes
const std::vector< SubShape > & getShapes() const
Definition: CompoundShape.cpp:199
SurgSim::Math::CompoundShape::ReadLock
boost::shared_lock< boost::shared_mutex > ReadLock
Definition: CompoundShape.h:115
SurgSim::Math::CompoundShape::~CompoundShape
~CompoundShape()
Destructor.
Definition: CompoundShape.cpp:35
SurgSim::Math::Matrix33d
Eigen::Matrix< double, 3, 3, Eigen::RowMajor > Matrix33d
A 3x3 matrix of doubles.
Definition: Matrix.h:51
SurgSim::Math::Aabbd
Eigen::AlignedBox< double, 3 > Aabbd
Wrapper around the Eigen type.
Definition: Aabb.h:30
SurgSim::Math::CompoundShape
Definition: CompoundShape.h:37
SurgSim::Math::CompoundShape::setPoses
void setPoses(const std::vector< RigidTransform3d > &poses)
Sets the poses for all shapes.
Definition: CompoundShape.cpp:219
SurgSim::Math::CompoundShape::getSecondMomentOfVolume
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
RigidTransform.h
Definitions of 2x2 and 3x3 rigid (isometric) transforms.
SurgSim::Math::CompoundShape::getNumShapes
size_t getNumShapes() const
Definition: CompoundShape.cpp:240
SurgSim::Math::CompoundShape::CompoundShape
CompoundShape()
Constructor.
Definition: CompoundShape.cpp:27
SurgSim::Math::CompoundShape::setShapes
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
SurgSim::Math::CompoundShape::SURGSIM_CLASSNAME
SURGSIM_CLASSNAME(SurgSim::Math::CompoundShape)
SurgSim::Math::Shape
Generic rigid shape class defining a shape.
Definition: Shape.h:66
SurgSim::Math::CompoundShape::m_volume
DataStructures::OptionalValue< double > m_volume
Definition: CompoundShape.h:125
SurgSim::Math::CompoundShape::WriteLock
boost::unique_lock< boost::shared_mutex > WriteLock
Definition: CompoundShape.h:116
SurgSim::Math::CompoundShape::addShape
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
SurgSim::Math::CompoundShape::m_localAabb
DataStructures::OptionalValue< Math::Aabbd > m_localAabb
Definition: CompoundShape.h:127
SurgSim::Math::CompoundShape::getShape
const std::shared_ptr< Shape > & getShape(size_t index) const
Definition: CompoundShape.cpp:205
SurgSim::Math::CompoundShape::getBoundingBox
const Math::Aabbd & getBoundingBox() const override
Definition: CompoundShape.cpp:151
SurgSim::Math::CompoundShape::getVolume
double getVolume() const override
Definition: CompoundShape.cpp:44
SurgSim::Math::CompoundShape::invalidateData
void invalidateData()
Clears the data for the volume, center and secondMoment and aabb so it can be recalculated when neede...
Definition: CompoundShape.cpp:176
SurgSim::Math::CompoundShape::isTransformable
bool isTransformable() const override
Definition: CompoundShape.cpp:253