Shape.h
Go to the documentation of this file.
// This file is a part of the OpenSurgSim project.
// Copyright 2013-2016, 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_SHAPE_H
#define SURGSIM_MATH_SHAPE_H
#include "SurgSim/Framework/Accessible.h"
#include "SurgSim/Framework/ObjectFactory.h"
#include "SurgSim/Math/Matrix.h"
#include "SurgSim/Math/RigidTransform.h"
#include "SurgSim/Math/Vector.h"
#include "SurgSim/Math/Aabb.h"
#include "SurgSim/DataStructures/OptionalValue.h"
namespace SurgSim
{
namespace Math
{
typedef enum
{
SHAPE_DIRECTION_AXIS_X = 0,
SHAPE_DIRECTION_AXIS_Y = 1,
SHAPE_DIRECTION_AXIS_Z = 2
} ShapeDirection;
typedef enum
{
SHAPE_TYPE_NONE = -1,
SHAPE_TYPE_BOX,
SHAPE_TYPE_CAPSULE,
SHAPE_TYPE_CYLINDER,
SHAPE_TYPE_DOUBLESIDEDPLANE,
SHAPE_TYPE_MESH,
SHAPE_TYPE_OCTREE,
SHAPE_TYPE_PARTICLES,
SHAPE_TYPE_PLANE,
SHAPE_TYPE_SPHERE,
SHAPE_TYPE_SURFACEMESH,
SHAPE_TYPE_SEGMENTMESH,
SHAPE_TYPE_COMPOUNDSHAPE,
SHAPE_TYPE_COUNT
} ShapeType;
class Shape : virtual public SurgSim::Framework::Accessible, public Framework::FactoryBase<Shape>
{
public:
typedef ::SurgSim::Math::Vector3d Vector3d;
typedef ::SurgSim::Math::Matrix33d Matrix33d;
Shape();
virtual ~Shape();
virtual int getType() const = 0;
virtual double getVolume() const = 0;
virtual Vector3d getCenter() const = 0;
virtual Matrix33d getSecondMomentOfVolume() const = 0;
virtual bool isTransformable() const;
virtual std::shared_ptr<Shape> getTransformed(const RigidTransform3d& pose) const;
virtual std::string getClassName() const;
virtual bool isValid() const = 0;
virtual const Math::Aabbd& getBoundingBox() const;
protected:
Math::Aabbd m_aabb;
};
template <class T>
struct PosedShape
{
PosedShape()
{
pose = Math::RigidTransform3d::Identity();
}
PosedShape(const T& shapeInput, const Math::RigidTransform3d& poseInput) : shape(shapeInput), pose(poseInput) {}
void invalidate()
{
shape = nullptr;
}
const T& getShape() const
{
return shape;
}
const Math::RigidTransform3d& getPose() const
{
return pose;
}
protected:
T shape;
Math::RigidTransform3d pose;
};
template <class T>
struct PosedShapeMotion : public std::pair<PosedShape<T>, PosedShape<T>>
{
PosedShapeMotion() {}
PosedShapeMotion(const PosedShape<T>& posedShapeFirst, const PosedShape<T>& posedShapeSecond)
{
this->first = posedShapeFirst;
this->second = posedShapeSecond;
}
void invalidate()
{
this->first.invalidate();
this->second.invalidate();
}
};
}; // Math
}; // SurgSim
#endif // SURGSIM_MATH_SHAPE_H
SurgSim::Math::Shape::getVolume
virtual double getVolume() const =0
Get the volume of the shape.
SurgSim::Math::PosedShapeMotion::PosedShapeMotion
PosedShapeMotion()
Definition: Shape.h:147
SurgSim::Math::PosedShape::PosedShape
PosedShape(const T &shapeInput, const Math::RigidTransform3d &poseInput)
Definition: Shape.h:123
SurgSim
Definition: CompoundShapeToGraphics.cpp:29
SurgSim::Math::PosedShape::PosedShape
PosedShape()
Definition: Shape.h:119
SurgSim::Math::Shape::getCenter
virtual Vector3d getCenter() const =0
Get the volumetric center of the shape.
SurgSim::Math::SHAPE_TYPE_COMPOUNDSHAPE
Definition: Shape.h:58
SurgSim::Math::PosedShapeMotion::PosedShapeMotion
PosedShapeMotion(const PosedShape< T > &posedShapeFirst, const PosedShape< T > &posedShapeSecond)
Definition: Shape.h:148
SurgSim::Math::Shape::Vector3d
::SurgSim::Math::Vector3d Vector3d
Definition: Shape.h:68
SurgSim::Math::ShapeDirection
ShapeDirection
Type defining the shape direction for certain templatized shape (i.e.
Definition: Shape.h:35
Aabb.h
SurgSim::Math::PosedShape::invalidate
void invalidate()
Definition: Shape.h:125
SurgSim::Math::SHAPE_TYPE_SURFACEMESH
Definition: Shape.h:56
Accessible.h
SurgSim::Math::PosedShapeMotion::invalidate
void invalidate()
Definition: Shape.h:154
SurgSim::Math::SHAPE_DIRECTION_AXIS_X
Definition: Shape.h:37
SurgSim::Math::Shape::m_aabb
Math::Aabbd m_aabb
Definition: Shape.h:112
SurgSim::Math::SHAPE_TYPE_CAPSULE
Definition: Shape.h:48
ObjectFactory.h
SurgSim::Math::Shape::Shape
Shape()
Constructor.
Definition: Shape.cpp:26
SurgSim::Math::Shape::getClassName
virtual std::string getClassName() const
Get class name.
Definition: Shape.cpp:47
SurgSim::Math::PosedShape::pose
Math::RigidTransform3d pose
Definition: Shape.h:140
SurgSim::Math::Shape::isTransformable
virtual bool isTransformable() const
Definition: Shape.cpp:35
SurgSim::Math::Shape::~Shape
virtual ~Shape()
Destructor.
Definition: Shape.cpp:31
SurgSim::Math::ShapeType
ShapeType
Fixed List of enums for the available Shape types, do not explicitly assign values, ShapeCount is used to determine the number of actual shape types.
Definition: Shape.h:44
SurgSim::Math::Shape::getSecondMomentOfVolume
virtual Matrix33d getSecondMomentOfVolume() const =0
Get the second central moment of the volume, commonly used to calculate the moment of inertia matrix...
SurgSim::Math::Aabbd
Eigen::AlignedBox< double, 3 > Aabbd
Wrapper around the Eigen type.
Definition: Aabb.h:30
SurgSim::Math::SHAPE_TYPE_COUNT
Definition: Shape.h:59
SurgSim::Math::Shape::getType
virtual int getType() const =0
SurgSim::Math::PosedShape::getPose
const Math::RigidTransform3d & getPose() const
Definition: Shape.h:133
RigidTransform.h
Definitions of 2x2 and 3x3 rigid (isometric) transforms.
SurgSim::Math::SHAPE_TYPE_SEGMENTMESH
Definition: Shape.h:57
Matrix.h
Definitions of small fixed-size square matrix types.
SurgSim::Math::RigidTransform3d
Eigen::Transform< double, 3, Eigen::Isometry > RigidTransform3d
A 3D rigid (isometric) transform, represented as doubles.
Definition: RigidTransform.h:46
SurgSim::Math::PosedShape
PosedShape is a transformed shape with a record of the pose used to transform it. ...
Definition: Shape.h:117
Vector.h
Definitions of small fixed-size vector types.
SurgSim::Math::SHAPE_DIRECTION_AXIS_Z
Definition: Shape.h:39
SurgSim::Math::PosedShape::getShape
const T & getShape() const
Definition: Shape.h:129
SurgSim::Math::SHAPE_TYPE_PARTICLES
Definition: Shape.h:53
SurgSim::Math::SHAPE_TYPE_BOX
Definition: Shape.h:47
SurgSim::Math::PosedShapeMotion
PosedShapeMotion is embedding the motion of a PosedShape, providing a posed shape at 2 different inst...
Definition: Shape.h:145
SurgSim::Framework::Accessible
Mixin class for enabling a property system on OSS classes, the instance still needs to initialize pro...
Definition: Accessible.h:37
SurgSim::Math::Shape::Matrix33d
::SurgSim::Math::Matrix33d Matrix33d
Definition: Shape.h:69
SurgSim::Math::SHAPE_TYPE_DOUBLESIDEDPLANE
Definition: Shape.h:50
SurgSim::Math::SHAPE_DIRECTION_AXIS_Y
Definition: Shape.h:38
OptionalValue.h
SurgSim::Math::Matrix33d
Eigen::Matrix< double, 3, 3, Eigen::RowMajor > Matrix33d
A 3x3 matrix of doubles.
Definition: Matrix.h:51
SurgSim::Math::SHAPE_TYPE_CYLINDER
Definition: Shape.h:49
SurgSim::Math::PosedShape::shape
T shape
Definition: Shape.h:139
SurgSim::Framework::FactoryBase
CRTP Base class to implement Object Factory functionality on a base class, use this rather than writi...
Definition: ObjectFactory.h:122
SurgSim::Math::SHAPE_TYPE_OCTREE
Definition: Shape.h:52
SurgSim::Math::SHAPE_TYPE_SPHERE
Definition: Shape.h:55
SurgSim::Math::Shape::getTransformed
virtual std::shared_ptr< Shape > getTransformed(const RigidTransform3d &pose) const
Get a copy of this shape with an applied rigid transform.
Definition: Shape.cpp:40
SurgSim::Math::Vector3d
Eigen::Matrix< double, 3, 1 > Vector3d
A 3D vector of doubles.
Definition: Vector.h:57
SurgSim::Math::SHAPE_TYPE_NONE
Definition: Shape.h:46
SurgSim::Math::SHAPE_TYPE_MESH
Definition: Shape.h:51
SurgSim::Math::Shape::isValid
virtual bool isValid() const =0
Check if the shape is valid.
SurgSim::Math::Shape::getBoundingBox
virtual const Math::Aabbd & getBoundingBox() const
Definition: Shape.cpp:55
SurgSim::Math::Shape
Generic rigid shape class defining a shape.
Definition: Shape.h:65
SurgSim::Math::SHAPE_TYPE_PLANE
Definition: Shape.h:54