opensurgsim
Shape.h
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 
19 #include "SurgSim/Framework/Accessible.h"
20 #include "SurgSim/Framework/ObjectFactory.h"
21 #include "SurgSim/Math/Matrix.h"
23 #include "SurgSim/Math/Vector.h"
24 #include "SurgSim/Math/Aabb.h"
25 #include "SurgSim/DataStructures/OptionalValue.h"
26 
27 namespace SurgSim
28 {
29 
30 namespace Math
31 {
32 
35 typedef enum
36 {
37  SHAPE_DIRECTION_AXIS_X = 0,
38  SHAPE_DIRECTION_AXIS_Y = 1,
39  SHAPE_DIRECTION_AXIS_Z = 2
40 } ShapeDirection;
41 
44 typedef enum
45 {
46  SHAPE_TYPE_NONE = -1,
47  SHAPE_TYPE_BOX,
48  SHAPE_TYPE_CAPSULE,
49  SHAPE_TYPE_CYLINDER,
50  SHAPE_TYPE_DOUBLESIDEDPLANE,
51  SHAPE_TYPE_MESH,
52  SHAPE_TYPE_OCTREE,
53  SHAPE_TYPE_PARTICLES,
54  SHAPE_TYPE_PLANE,
55  SHAPE_TYPE_SPHERE,
56  SHAPE_TYPE_SURFACEMESH,
57  SHAPE_TYPE_SEGMENTMESH,
58  SHAPE_TYPE_COMPOUNDSHAPE,
59  SHAPE_TYPE_COUNT
60 } ShapeType;
61 
65 class Shape : virtual public SurgSim::Framework::Accessible, public Framework::FactoryBase<Shape>
66 {
67 public:
68  typedef ::SurgSim::Math::Vector3d Vector3d;
69  typedef ::SurgSim::Math::Matrix33d Matrix33d;
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 
103  virtual void setPose(const RigidTransform3d& pose);
104 
106  virtual void updateShape();
107 
110  virtual void updateShapePartial();
111 
113  virtual std::string getClassName() const;
114 
117  virtual bool isValid() const = 0;
118 
120  virtual const Math::Aabbd& getBoundingBox() const;
121 
122 protected:
123  Math::Aabbd m_aabb;
124 };
125 
127 template <class T>
129 {
130  PosedShape()
131  {
132  pose = Math::RigidTransform3d::Identity();
133  }
134  PosedShape(const T& shapeInput, const Math::RigidTransform3d& poseInput) : shape(shapeInput), pose(poseInput) {}
135 
136  void invalidate()
137  {
138  shape = nullptr;
139  }
140  const T& getShape() const
141  {
142  return shape;
143  }
144  const Math::RigidTransform3d& getPose() const
145  {
146  return pose;
147  }
148 
149 protected:
150  T shape;
152 };
153 
155 template <class T>
156 struct PosedShapeMotion : public std::pair<PosedShape<T>, PosedShape<T>>
157 {
158  PosedShapeMotion() {}
159  PosedShapeMotion(const PosedShape<T>& posedShapeFirst, const PosedShape<T>& posedShapeSecond)
160  {
161  this->first = posedShapeFirst;
162  this->second = posedShapeSecond;
163  }
164 
165  void invalidate()
166  {
167  this->first.invalidate();
168  this->second.invalidate();
169  }
170 };
171 
172 }; // Math
173 }; // SurgSim
174 
175 #endif // SURGSIM_MATH_SHAPE_H
virtual double getVolume() const =0
Get the volume of the shape.
Wraps glewInit() to separate the glew opengl definitions from the osg opengl definitions only imgui n...
Definition: AddRandomSphereBehavior.cpp:36
virtual Vector3d getCenter() const =0
Get the volumetric center of the shape.
Eigen::Transform< double, 3, Eigen::Isometry > RigidTransform3d
A 3D rigid (isometric) transform, represented as doubles.
Definition: RigidTransform.h:46
Shape()
Constructor.
Definition: Shape.cpp:26
virtual std::string getClassName() const
Get class name.
Definition: Shape.cpp:51
virtual bool isTransformable() const
Definition: Shape.cpp:35
virtual ~Shape()
Destructor.
Definition: Shape.cpp:31
virtual void setPose(const RigidTransform3d &pose)
Set the pose on a transformable shape.
Definition: Shape.cpp:46
virtual Matrix33d getSecondMomentOfVolume() const =0
Get the second central moment of the volume, commonly used to calculate the moment of inertia matrix...
virtual int getType() const =0
Definitions of 2x2 and 3x3 rigid (isometric) transforms.
Definitions of small fixed-size square matrix types.
PosedShape is a transformed shape with a record of the pose used to transform it. ...
Definition: Shape.h:128
Definitions of small fixed-size vector types.
virtual void updateShapePartial()
Update some of the internals of a transformable shape.
Definition: Shape.cpp:68
PosedShapeMotion is embedding the motion of a PosedShape, providing a posed shape at 2 different inst...
Definition: Shape.h:156
Mixin class for enabling a property system on OSS classes, the instance still needs to initialize pro...
Definition: Accessible.h:37
CRTP Base class to implement Object Factory functionality on a base class, use this rather than writi...
Definition: ObjectFactory.h:122
virtual void updateShape()
Update the internals of a transformable shape.
Definition: Shape.cpp:64
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
virtual bool isValid() const =0
Check if the shape is valid.
virtual const Math::Aabbd & getBoundingBox() const
Definition: Shape.cpp:59
Generic rigid shape class defining a shape.
Definition: Shape.h:65