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
virtual double getVolume() const =0
Get the volume of the shape.
PosedShapeMotion()
Definition: Shape.h:147
PosedShape(const T &shapeInput, const Math::RigidTransform3d &poseInput)
Definition: Shape.h:123
Definition: CompoundShapeToGraphics.cpp:29
PosedShape()
Definition: Shape.h:119
virtual Vector3d getCenter() const =0
Get the volumetric center of the shape.
PosedShapeMotion(const PosedShape< T > &posedShapeFirst, const PosedShape< T > &posedShapeSecond)
Definition: Shape.h:148
::SurgSim::Math::Vector3d Vector3d
Definition: Shape.h:68
ShapeDirection
Type defining the shape direction for certain templatized shape (i.e.
Definition: Shape.h:35
void invalidate()
Definition: Shape.h:125
void invalidate()
Definition: Shape.h:154
Math::Aabbd m_aabb
Definition: Shape.h:112
Definition: Shape.h:48
Shape()
Constructor.
Definition: Shape.cpp:26
virtual std::string getClassName() const
Get class name.
Definition: Shape.cpp:47
Math::RigidTransform3d pose
Definition: Shape.h:140
virtual bool isTransformable() const
Definition: Shape.cpp:35
virtual ~Shape()
Destructor.
Definition: Shape.cpp:31
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
virtual Matrix33d getSecondMomentOfVolume() const =0
Get the second central moment of the volume, commonly used to calculate the moment of inertia matrix...
Eigen::AlignedBox< double, 3 > Aabbd
Wrapper around the Eigen type.
Definition: Aabb.h:30
Definition: Shape.h:59
virtual int getType() const =0
const Math::RigidTransform3d & getPose() const
Definition: Shape.h:133
Definitions of 2x2 and 3x3 rigid (isometric) transforms.
Definitions of small fixed-size square matrix types.
Eigen::Transform< double, 3, Eigen::Isometry > RigidTransform3d
A 3D rigid (isometric) transform, represented as doubles.
Definition: RigidTransform.h:46
PosedShape is a transformed shape with a record of the pose used to transform it. ...
Definition: Shape.h:117
Definitions of small fixed-size vector types.
const T & getShape() const
Definition: Shape.h:129
Definition: Shape.h:47
PosedShapeMotion is embedding the motion of a PosedShape, providing a posed shape at 2 different inst...
Definition: Shape.h:145
Mixin class for enabling a property system on OSS classes, the instance still needs to initialize pro...
Definition: Accessible.h:37
::SurgSim::Math::Matrix33d Matrix33d
Definition: Shape.h:69
Eigen::Matrix< double, 3, 3, Eigen::RowMajor > Matrix33d
A 3x3 matrix of doubles.
Definition: Matrix.h:51
T shape
Definition: Shape.h:139
CRTP Base class to implement Object Factory functionality on a base class, use this rather than writi...
Definition: ObjectFactory.h:122
Definition: Shape.h:52
Definition: Shape.h:55
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
Eigen::Matrix< double, 3, 1 > Vector3d
A 3D vector of doubles.
Definition: Vector.h:57
Definition: Shape.h:46
Definition: Shape.h:51
virtual bool isValid() const =0
Check if the shape is valid.
virtual const Math::Aabbd & getBoundingBox() const
Definition: Shape.cpp:55
Generic rigid shape class defining a shape.
Definition: Shape.h:65
Definition: Shape.h:54