Shape.h
Go to the documentation of this file.
1 // This file is a part of the OpenSurgSim project.
2 // Copyright 2013-2016, 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_SHAPE_H
17 #define SURGSIM_MATH_SHAPE_H
18 
21 #include "SurgSim/Math/Matrix.h"
23 #include "SurgSim/Math/Vector.h"
24 #include "SurgSim/Math/Aabb.h"
26 
27 namespace SurgSim
28 {
29 
30 namespace Math
31 {
32 
35 typedef enum
36 {
41 
44 typedef enum
45 {
60 } ShapeType;
61 
65 class Shape : virtual public SurgSim::Framework::Accessible, public Framework::FactoryBase<Shape>
66 {
67 public:
70 
72  Shape();
73 
75  virtual ~Shape();
76 
78  virtual int getType() const = 0;
79 
82  virtual double getVolume() const = 0;
83 
86  virtual Vector3d getCenter() const = 0;
87 
91  virtual Matrix33d getSecondMomentOfVolume() const = 0;
92 
94  virtual bool isTransformable() const;
95 
99  virtual std::shared_ptr<Shape> getTransformed(const RigidTransform3d& pose) const;
100 
102  virtual std::string getClassName() const;
103 
106  virtual bool isValid() const = 0;
107 
109  virtual const Math::Aabbd& getBoundingBox() const;
110 
111 protected:
113 };
114 
116 template <class T>
118 {
120  {
121  pose = Math::RigidTransform3d::Identity();
122  }
123  PosedShape(const T& shapeInput, const Math::RigidTransform3d& poseInput) : shape(shapeInput), pose(poseInput) {}
124 
125  void invalidate()
126  {
127  shape = nullptr;
128  }
129  const T& getShape() const
130  {
131  return shape;
132  }
134  {
135  return pose;
136  }
137 
138 protected:
139  T shape;
141 };
142 
144 template <class T>
145 struct PosedShapeMotion : public std::pair<PosedShape<T>, PosedShape<T>>
146 {
148  PosedShapeMotion(const PosedShape<T>& posedShapeFirst, const PosedShape<T>& posedShapeSecond)
149  {
150  this->first = posedShapeFirst;
151  this->second = posedShapeSecond;
152  }
153 
154  void invalidate()
155  {
156  this->first.invalidate();
157  this->second.invalidate();
158  }
159 };
160 
161 }; // Math
162 }; // SurgSim
163 
164 #endif // SURGSIM_MATH_SHAPE_H
SurgSim::Math::Shape::~Shape
virtual ~Shape()
Destructor.
Definition: Shape.cpp:31
SurgSim::Math::ShapeDirection
ShapeDirection
Type defining the shape direction for certain templatized shape (i.e.
Definition: Shape.h:35
SurgSim::Math::Shape::m_aabb
Math::Aabbd m_aabb
Definition: Shape.h:112
SurgSim::Math::SHAPE_TYPE_SEGMENTMESH
Definition: Shape.h:57
SurgSim::Math::SHAPE_TYPE_BOX
Definition: Shape.h:47
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
Vector.h
SurgSim::Math::PosedShape::PosedShape
PosedShape(const T &shapeInput, const Math::RigidTransform3d &poseInput)
Definition: Shape.h:123
SurgSim::Math::PosedShapeMotion::PosedShapeMotion
PosedShapeMotion(const PosedShape< T > &posedShapeFirst, const PosedShape< T > &posedShapeSecond)
Definition: Shape.h:148
SurgSim::Math::SHAPE_DIRECTION_AXIS_Z
Definition: Shape.h:39
SurgSim::Math::Shape::isValid
virtual bool isValid() const =0
Check if the shape is valid.
SurgSim::Math::PosedShapeMotion::PosedShapeMotion
PosedShapeMotion()
Definition: Shape.h:147
SurgSim::Math::PosedShapeMotion
PosedShapeMotion is embedding the motion of a PosedShape, providing a posed shape at 2 different inst...
Definition: Shape.h:145
SurgSim::Math::RigidTransform3d
Eigen::Transform< double, 3, Eigen::Isometry > RigidTransform3d
A 3D rigid (isometric) transform, represented as doubles.
Definition: RigidTransform.h:46
SurgSim::Math::SHAPE_TYPE_DOUBLESIDEDPLANE
Definition: Shape.h:50
SurgSim::Math::Shape::Matrix33d
::SurgSim::Math::Matrix33d Matrix33d
Definition: Shape.h:69
SurgSim::Math::PosedShape
PosedShape is a transformed shape with a record of the pose used to transform it.
Definition: Shape.h:117
SurgSim::Math::Shape::getClassName
virtual std::string getClassName() const
Get class name.
Definition: Shape.cpp:47
Matrix.h
SurgSim::Math::SHAPE_TYPE_SPHERE
Definition: Shape.h:55
SurgSim::Math::SHAPE_TYPE_PARTICLES
Definition: Shape.h:53
SurgSim::Math::SHAPE_TYPE_CYLINDER
Definition: Shape.h:49
OptionalValue.h
SurgSim::Math::Shape::getCenter
virtual Vector3d getCenter() const =0
Get the volumetric center of the shape.
SurgSim::Math::Vector3d
Eigen::Matrix< double, 3, 1 > Vector3d
A 3D vector of doubles.
Definition: Vector.h:57
ObjectFactory.h
SurgSim
Definition: CompoundShapeToGraphics.cpp:29
SurgSim::Math::PosedShapeMotion::invalidate
void invalidate()
Definition: Shape.h:154
SurgSim::Math::Shape::getBoundingBox
virtual const Math::Aabbd & getBoundingBox() const
Definition: Shape.cpp:55
SurgSim::Math::ShapeType
ShapeType
Fixed List of enums for the available Shape types, do not explicitly assign values,...
Definition: Shape.h:44
SurgSim::Math::PosedShape::pose
Math::RigidTransform3d pose
Definition: Shape.h:140
SurgSim::Math::SHAPE_TYPE_NONE
Definition: Shape.h:46
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_DIRECTION_AXIS_Y
Definition: Shape.h:38
SurgSim::Math::PosedShape::PosedShape
PosedShape()
Definition: Shape.h:119
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::SHAPE_TYPE_MESH
Definition: Shape.h:51
SurgSim::Math::SHAPE_TYPE_OCTREE
Definition: Shape.h:52
SurgSim::Math::SHAPE_TYPE_COMPOUNDSHAPE
Definition: Shape.h:58
SurgSim::Math::PosedShape::getShape
const T & getShape() const
Definition: Shape.h:129
SurgSim::Math::Shape::isTransformable
virtual bool isTransformable() const
Definition: Shape.cpp:35
RigidTransform.h
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_PLANE
Definition: Shape.h:54
SurgSim::Math::Shape::getVolume
virtual double getVolume() const =0
Get the volume of the shape.
Accessible.h
Aabb.h
SurgSim::Math::PosedShape::getPose
const Math::RigidTransform3d & getPose() const
Definition: Shape.h:133
SurgSim::Math::Shape
Generic rigid shape class defining a shape.
Definition: Shape.h:65
SurgSim::Math::Shape::Vector3d
::SurgSim::Math::Vector3d Vector3d
Definition: Shape.h:68
SurgSim::Math::PosedShape::invalidate
void invalidate()
Definition: Shape.h:125
SurgSim::Math::Shape::getType
virtual int getType() const =0
SurgSim::Math::SHAPE_DIRECTION_AXIS_X
Definition: Shape.h:37
SurgSim::Math::Shape::Shape
Shape()
Constructor.
Definition: Shape.cpp:26
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::SHAPE_TYPE_SURFACEMESH
Definition: Shape.h:56
SurgSim::Math::SHAPE_TYPE_CAPSULE
Definition: Shape.h:48
SurgSim::Math::PosedShape::shape
T shape
Definition: Shape.h:139
SurgSim::Math::SHAPE_TYPE_COUNT
Definition: Shape.h:59