CompoundShape.h
Go to the documentation of this file.
// This file is a part of the OpenSurgSim project.
// Copyright 2013-2015, SimQuest Solutions Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef SURGSIM_MATH_COMPOUNDSHAPE_H
#define SURGSIM_MATH_COMPOUNDSHAPE_H
#include <memory>
#include <utility>
#include <boost/thread.hpp>
#include "SurgSim/Math/Shape.h"
#include "SurgSim/Math/RigidTransform.h"
#include "SurgSim/DataStructures/OptionalValue.h"
namespace SurgSim
{
namespace Math
{
SURGSIM_STATIC_REGISTRATION(CompoundShape);
class CompoundShape : public Shape
{
public:
CompoundShape();
~CompoundShape();
SURGSIM_CLASSNAME(SurgSim::Math::CompoundShape);
typedef std::pair<std::shared_ptr<Shape>, RigidTransform3d> SubShape;
size_t addShape(const std::shared_ptr<Shape>& shape, const RigidTransform3d& pose = RigidTransform3d::Identity());
void setShapes(const std::vector<SubShape>& shapes);
const std::vector<SubShape>& getShapes() const;
const std::shared_ptr<Shape>& getShape(size_t index) const;
RigidTransform3d getPose(size_t index) const;
void setPoses(const std::vector<RigidTransform3d>& poses);
void setPose(size_t index, const RigidTransform3d& pose);
size_t getNumShapes() const;
void clearShapes();
int getType() const override;
double getVolume() const override;
Vector3d getCenter() const override;
Matrix33d getSecondMomentOfVolume() const override;
bool isValid() const override;
const Math::Aabbd& getBoundingBox() const override;
bool isTransformable() const override;
std::shared_ptr<Shape> getTransformed(const RigidTransform3d& pose) const override;
private:
void invalidateData();
std::vector<SubShape> m_shapes;
typedef boost::shared_lock<boost::shared_mutex> ReadLock;
typedef boost::unique_lock<boost::shared_mutex> WriteLock;
mutable boost::shared_mutex m_mutex;
mutable DataStructures::OptionalValue<Vector3d> m_center;
mutable DataStructures::OptionalValue<double> m_volume;
mutable DataStructures::OptionalValue<Matrix33d> m_secondMoment;
mutable DataStructures::OptionalValue<Math::Aabbd> m_localAabb;
};
}
}
#endif
SurgSim
Definition: CompoundShapeToGraphics.cpp:29
SurgSim::Math::CompoundShape::getShapes
const std::vector< SubShape > & getShapes() const
Definition: CompoundShape.cpp:199
SurgSim::Math::CompoundShape::getCenter
Vector3d getCenter() const override
Get the volumetric center of the shape.
Definition: CompoundShape.cpp:71
SurgSim::DataStructures::OptionalValue< Vector3d >
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::m_localAabb
DataStructures::OptionalValue< Math::Aabbd > m_localAabb
Definition: CompoundShape.h:127
SurgSim::Math::CompoundShape::SURGSIM_CLASSNAME
SURGSIM_CLASSNAME(SurgSim::Math::CompoundShape)
SurgSim::Math::CompoundShape::getPose
RigidTransform3d getPose(size_t index) const
Definition: CompoundShape.cpp:212
SurgSim::Math::CompoundShape::ReadLock
boost::shared_lock< boost::shared_mutex > ReadLock
Definition: CompoundShape.h:115
SurgSim::Math::CompoundShape::getType
int getType() const override
Definition: CompoundShape.cpp:39
SurgSim::Math::CompoundShape::getShape
const std::shared_ptr< Shape > & getShape(size_t index) const
Definition: CompoundShape.cpp:205
SurgSim::Math::CompoundShape::m_shapes
std::vector< SubShape > m_shapes
Definition: CompoundShape.h:113
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::Aabbd
Eigen::AlignedBox< double, 3 > Aabbd
Wrapper around the Eigen type.
Definition: Aabb.h:30
SurgSim::Math::CompoundShape
Definition: CompoundShape.h:36
SurgSim::Math::CompoundShape::getVolume
double getVolume() const override
Definition: CompoundShape.cpp:44
SurgSim::Math::CompoundShape::m_secondMoment
DataStructures::OptionalValue< Matrix33d > m_secondMoment
Definition: CompoundShape.h:126
SurgSim::Math::CompoundShape::m_center
DataStructures::OptionalValue< Vector3d > m_center
Definition: CompoundShape.h:124
SurgSim::Math::CompoundShape::~CompoundShape
~CompoundShape()
Destructor.
Definition: CompoundShape.cpp:35
RigidTransform.h
Definitions of 2x2 and 3x3 rigid (isometric) transforms.
SurgSim::Math::CompoundShape::setPose
void setPose(size_t index, const RigidTransform3d &pose)
Set the pose for the specified shape.
Definition: CompoundShape.cpp:232
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::isValid
bool isValid() const override
Check if the shape is valid.
Definition: CompoundShape.cpp:146
SurgSim::Math::CompoundShape::getNumShapes
size_t getNumShapes() const
Definition: CompoundShape.cpp:240
SurgSim::Math::CompoundShape::isTransformable
bool isTransformable() const override
Definition: CompoundShape.cpp:253
SurgSim::Math::CompoundShape::m_mutex
boost::shared_mutex m_mutex
Definition: CompoundShape.h:118
SurgSim::Math::CompoundShape::setPoses
void setPoses(const std::vector< RigidTransform3d > &poses)
Sets the poses for all shapes.
Definition: CompoundShape.cpp:219
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
OptionalValue.h
SurgSim::Math::Matrix33d
Eigen::Matrix< double, 3, 3, Eigen::RowMajor > Matrix33d
A 3x3 matrix of doubles.
Definition: Matrix.h:51
Shape.h
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::CompoundShape
CompoundShape()
Constructor.
Definition: CompoundShape.cpp:27
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::Vector3d
Eigen::Matrix< double, 3, 1 > Vector3d
A 3D vector of doubles.
Definition: Vector.h:57
SurgSim::Math::CompoundShape::getBoundingBox
const Math::Aabbd & getBoundingBox() const override
Definition: CompoundShape.cpp:151
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
SurgSim::Math::CompoundShape::clearShapes
void clearShapes()
clears all the enclosed shapes
Definition: CompoundShape.cpp:246
SurgSim::Math::CompoundShape::SubShape
std::pair< std::shared_ptr< Shape >, RigidTransform3d > SubShape
Definition: CompoundShape.h:47
SurgSim::Math::Shape
Generic rigid shape class defining a shape.
Definition: Shape.h:65