Geometry.hh
Go to the documentation of this file.
1 /*
2  * Copyright 2018 Open Source Robotics Foundation
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  */
17 #ifndef SDF_GEOMETRY_HH_
18 #define SDF_GEOMETRY_HH_
19 
20 #include <vector>
21 #include <optional>
22 
23 #include <gz/utils/ImplPtr.hh>
24 #include <gz/math/Inertial.hh>
25 #include <gz/math/AxisAlignedBox.hh>
26 #include <sdf/Error.hh>
27 #include <sdf/Element.hh>
28 #include <sdf/sdf_config.h>
29 #include <sdf/ParserConfig.hh>
30 #include <sdf/Types.hh>
31 
32 namespace sdf
33 {
34  // Inline bracket to help doxygen filtering.
35  inline namespace SDF_VERSION_NAMESPACE {
36  //
37 
38  // Forward declare private data class.
39  class Box;
40  class Capsule;
41  class Cone;
42  class Cylinder;
43  class Ellipsoid;
44  class Heightmap;
45  class Mesh;
46  class ParserConfig;
47  class Plane;
48  class Polyline;
49  class Sphere;
50 
53  enum class GeometryType
54  {
56  EMPTY = 0,
57 
59  BOX = 1,
60 
62  CYLINDER = 2,
63 
65  PLANE = 3,
66 
68  SPHERE = 4,
69 
71  MESH = 5,
72 
74  HEIGHTMAP = 6,
75 
77  CAPSULE = 7,
78 
80  ELLIPSOID = 8,
81 
83  POLYLINE = 9,
84 
86  CONE = 10,
87  };
88 
94  {
96  public: Geometry();
97 
104  public: Errors Load(ElementPtr _sdf);
105 
113  public: Errors Load(sdf::ElementPtr _sdf, const ParserConfig &_config);
114 
117  public: GeometryType Type() const;
118 
121  public: void SetType(const GeometryType _type);
122 
128  public: const Box *BoxShape() const;
129 
132  public: void SetBoxShape(const Box &_box);
133 
139  public: const Capsule *CapsuleShape() const;
140 
143  public: void SetCapsuleShape(const Capsule &_capsule);
144 
150  public: const Cone *ConeShape() const;
151 
154  public: void SetConeShape(const Cone &_cone);
155 
161  public: const Cylinder *CylinderShape() const;
162 
165  public: void SetCylinderShape(const Cylinder &_cylinder);
166 
172  public: const Ellipsoid *EllipsoidShape() const;
173 
176  public: void SetEllipsoidShape(const Ellipsoid &_ellipsoid);
177 
183  public: const Sphere *SphereShape() const;
184 
187  public: void SetSphereShape(const Sphere &_sphere);
188 
193  public: const std::vector<Polyline> &PolylineShape() const;
194 
197  public: void SetPolylineShape(const std::vector<Polyline> &_polyline);
198 
204  public: const Plane *PlaneShape() const;
205 
208  public: void SetPlaneShape(const Plane &_plane);
209 
215  public: const Mesh *MeshShape() const;
216 
219  public: void SetMeshShape(const Mesh &_mesh);
220 
226  public: const Heightmap *HeightmapShape() const;
227 
230  public: void SetHeightmapShape(const Heightmap &_heightmap);
231 
239  public: std::optional<gz::math::Inertiald> CalculateInertial(
240  sdf::Errors &_errors, const ParserConfig &_config,
241  double _density, sdf::ElementPtr _autoInertiaParams);
242 
247  public: std::optional<gz::math::AxisAlignedBox> AxisAlignedBox(
248  const Mesh::AxisAlignedBoxCalculator &_meshAabbCalculator) const;
249 
254  public: sdf::ElementPtr Element() const;
255 
261  public: sdf::ElementPtr ToElement() const;
262 
269  public: sdf::ElementPtr ToElement(sdf::Errors &_errors) const;
270 
272  GZ_UTILS_IMPL_PTR(dataPtr)
273  };
274  }
275 }
276 #endif
Box represents a box shape, and is usually accessed through a Geometry.
Definition: Box.hh:38
Capsule represents a capsule shape, and is usually accessed through a Geometry.
Definition: Capsule.hh:37
Cone represents a cone shape, and is usually accessed through a Geometry.
Definition: Cone.hh:39
Cylinder represents a cylinder shape, and is usually accessed through a Geometry.
Definition: Cylinder.hh:37
Ellipsoid represents a ellipsoid shape, and is usually accessed through a Geometry.
Definition: Ellipsoid.hh:37
Geometry provides access to a shape, such as a Box.
Definition: Geometry.hh:94
void SetConeShape(const Cone &_cone)
Set the cone shape.
const Sphere * SphereShape() const
Get the sphere geometry, or nullptr if the contained geometry is not a sphere.
const Cone * ConeShape() const
Get the cone geometry, or nullptr if the contained geometry is not a cone.
sdf::ElementPtr Element() const
Get a pointer to the SDF element that was used during load.
const Ellipsoid * EllipsoidShape() const
Get the ellipsoid geometry, or nullptr if the contained geometry is not an ellipsoid.
std::optional< gz::math::Inertiald > CalculateInertial(sdf::Errors &_errors, const ParserConfig &_config, double _density, sdf::ElementPtr _autoInertiaParams)
Calculate and return the Inertial values for the Geometry.
const Plane * PlaneShape() const
Get the plane geometry, or nullptr if the contained geometry is not a plane.
sdf::ElementPtr ToElement() const
Create and return an SDF element filled with data from this geometry.
void SetEllipsoidShape(const Ellipsoid &_ellipsoid)
Set the ellipsoid shape.
sdf::ElementPtr ToElement(sdf::Errors &_errors) const
Create and return an SDF element filled with data from this geometry.
GeometryType Type() const
Get the type of geometry.
const std::vector< Polyline > & PolylineShape() const
Get the polyline geometry.
void SetPolylineShape(const std::vector< Polyline > &_polyline)
Set the polyline shape.
const Box * BoxShape() const
Get the box geometry, or nullptr if the contained geometry is not a box.
const Cylinder * CylinderShape() const
Get the cylinder geometry, or nullptr if the contained geometry is not a cylinder.
void SetSphereShape(const Sphere &_sphere)
Set the sphere shape.
const Capsule * CapsuleShape() const
Get the capsule geometry, or nullptr if the contained geometry is not a capsule.
const Mesh * MeshShape() const
Get the mesh geometry, or nullptr if the contained geometry is not a mesh.
void SetCapsuleShape(const Capsule &_capsule)
Set the capsule shape.
Errors Load(ElementPtr _sdf)
Load the geometry based on a element pointer.
void SetHeightmapShape(const Heightmap &_heightmap)
Set the heightmap shape.
const Heightmap * HeightmapShape() const
Get the heightmap geometry, or nullptr if the contained geometry is not a heightmap.
std::optional< gz::math::AxisAlignedBox > AxisAlignedBox(const Mesh::AxisAlignedBoxCalculator &_meshAabbCalculator) const
Calculate and return the AxisAlignedBox for the Geometry.
Errors Load(sdf::ElementPtr _sdf, const ParserConfig &_config)
Load the geometry based on a element pointer.
void SetPlaneShape(const Plane &_plane)
Set the plane shape.
void SetCylinderShape(const Cylinder &_cylinder)
Set the cylinder shape.
void SetMeshShape(const Mesh &_mesh)
Set the mesh shape.
void SetType(const GeometryType _type)
Set the type of geometry.
void SetBoxShape(const Box &_box)
Set the box shape.
Heightmap represents a shape defined by a 2D field, and is usually accessed through a Geometry.
Definition: Heightmap.hh:134
Mesh represents a mesh shape, and is usually accessed through a Geometry.
Definition: Mesh.hh:97
std::function< std::optional< gz::math::AxisAlignedBox >(const sdf::Mesh &_sdfMesh)> AxisAlignedBoxCalculator
Definition: Mesh.hh:100
This class contains configuration options for the libsdformat parser.
Definition: ParserConfig.hh:121
Plane represents a plane shape, and is usually accessed through a Geometry.
Definition: Plane.hh:37
Sphere represents a sphere shape, and is usually accessed through a Geometry.
Definition: Sphere.hh:38
GeometryType
The set of geometry types.
Definition: Geometry.hh:54
@ EMPTY
Empty geometry. This means no shape has been defined.
std::vector< Error > Errors
A vector of Error.
Definition: Types.hh:95
std::shared_ptr< Element > ElementPtr
Definition: Element.hh:55
namespace for Simulation Description Format parser
Definition: Actor.hh:35
#define SDFORMAT_VISIBLE
Use to represent "symbol visible" if supported.
Definition: system_util.hh:25