shapes.h
Go to the documentation of this file.
1 /*********************************************************************
2  * Software License Agreement (BSD License)
3  *
4  * Copyright (c) 2008, Willow Garage, Inc.
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  *
11  * * Redistributions of source code must retain the above copyright
12  * notice, this list of conditions and the following disclaimer.
13  * * Redistributions in binary form must reproduce the above
14  * copyright notice, this list of conditions and the following
15  * disclaimer in the documentation and/or other materials provided
16  * with the distribution.
17  * * Neither the name of the Willow Garage nor the names of its
18  * contributors may be used to endorse or promote products derived
19  * from this software without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32  * POSSIBILITY OF SUCH DAMAGE.
33  *********************************************************************/
34 
35 /* Author: Ioan Sucan */
36 
37 #ifndef GEOMETRIC_SHAPES_SHAPES_
38 #define GEOMETRIC_SHAPES_SHAPES_
39 
40 #if __cplusplus <= 199711L
41 #error This header requires at least C++11
42 #endif
43 
44 #include <cstdlib>
45 #include <vector>
46 #include <iostream>
47 #include <memory>
48 #include <string>
49 
50 namespace octomap
51 {
52 class OcTree;
53 }
54 
58 namespace shapes
59 {
62 {
67  BOX,
71 };
72 
73 /* convert above enum to printable */
74 std::ostream& operator<<(std::ostream& ss, ShapeType type);
75 
77 class Shape
78 {
79 public:
80  Shape();
81  virtual ~Shape();
82 
84  virtual Shape* clone() const = 0;
85 
87  virtual void print(std::ostream& out = std::cout) const;
88 
90  void scale(double scale);
91 
93  void padd(double padding);
94 
96  virtual void scaleAndPadd(double scale, double padd) = 0;
97 
99  virtual bool isFixed() const;
100 
103 };
104 
106 class Sphere : public Shape
107 {
108 public:
109  Sphere();
110 
112  Sphere(double r);
113 
115  static const std::string STRING_NAME;
116 
117  void scaleAndPadd(double scale, double padd) override;
118  Sphere* clone() const override;
119  void print(std::ostream& out = std::cout) const override;
120 
122  double radius;
123 };
124 
127 class Cylinder : public Shape
128 {
129 public:
130  using Shape::padd;
131  using Shape::scale;
132 
133  Cylinder();
134 
136  Cylinder(double r, double l);
137 
139  static const std::string STRING_NAME;
140 
146  void scale(double scaleRadius, double scaleLength);
147 
153  void padd(double paddRadius, double paddLength);
154 
162  void scaleAndPadd(double scaleRadius, double scaleLength, double paddRadius, double paddLength);
163 
164  void scaleAndPadd(double scale, double padd) override;
165  Cylinder* clone() const override;
166  void print(std::ostream& out = std::cout) const override;
167 
169  double length;
170 
172  double radius;
173 };
174 
178 class Cone : public Shape
179 {
180 public:
181  using Shape::padd;
182  using Shape::scale;
183 
184  Cone();
185  Cone(double r, double l);
186 
188  static const std::string STRING_NAME;
189 
195  void scale(double scaleRadius, double scaleLength);
196 
202  void padd(double paddRadius, double paddLength);
203 
211  void scaleAndPadd(double scaleRadius, double scaleLength, double paddRadius, double paddLength);
212 
213  void scaleAndPadd(double scale, double padd) override;
214  Cone* clone() const override;
215  void print(std::ostream& out = std::cout) const override;
216 
218  double length;
219 
221  double radius;
222 };
223 
226 class Box : public Shape
227 {
228 public:
229  using Shape::padd;
230  using Shape::scale;
231 
232  Box();
233  Box(double x, double y, double z);
234 
236  static const std::string STRING_NAME;
237 
244  void scale(double scaleX, double scaleY, double scaleZ);
245 
252  void padd(double paddX, double paddY, double paddZ);
253 
263  void scaleAndPadd(double scaleX, double scaleY, double scaleZ, double paddX, double paddY, double paddZ);
264 
265  void scaleAndPadd(double scale, double padd) override;
266  Box* clone() const override;
267  void print(std::ostream& out = std::cout) const override;
268 
270  double size[3];
271 };
272 
281 class Mesh : public Shape
282 {
283 public:
284  using Shape::padd;
285  using Shape::scale;
286 
287  Mesh();
288  Mesh(unsigned int v_count, unsigned int t_count);
289  ~Mesh() override;
290 
292  static const std::string STRING_NAME;
293 
300  void scale(double scaleX, double scaleY, double scaleZ);
301 
311  void padd(double paddX, double paddY, double paddZ);
312 
325  void scaleAndPadd(double scaleX, double scaleY, double scaleZ, double paddX, double paddY, double paddZ);
326 
327  void scaleAndPadd(double scale, double padd) override;
328  Mesh* clone() const override;
329  void print(std::ostream& out = std::cout) const override;
330 
332  void computeTriangleNormals();
333 
338  void computeVertexNormals();
339 
341  void mergeVertices(double threshold);
342 
344  unsigned int vertex_count;
345 
348  double* vertices;
349 
351  unsigned int triangle_count;
352 
355  unsigned int* triangles;
356 
360 
363  double* vertex_normals;
364 };
365 
367 class Plane : public Shape
368 {
369 public:
370  Plane();
371  Plane(double pa, double pb, double pc, double pd);
372 
374  static const std::string STRING_NAME;
375 
376  Plane* clone() const override;
377  void print(std::ostream& out = std::cout) const override;
378  void scaleAndPadd(double scale, double padd) override;
379  bool isFixed() const override;
380 
382  double a, b, c, d;
383 };
384 
386 class OcTree : public Shape
387 {
388 public:
389  OcTree();
390  OcTree(const std::shared_ptr<const octomap::OcTree>& t);
391 
393  static const std::string STRING_NAME;
394 
395  OcTree* clone() const override;
396  void print(std::ostream& out = std::cout) const override;
397  void scaleAndPadd(double scale, double padd) override;
398  bool isFixed() const override;
399 
400  std::shared_ptr<const octomap::OcTree> octree;
401 };
402 
404 typedef std::shared_ptr<Shape> ShapePtr;
405 
407 typedef std::shared_ptr<const Shape> ShapeConstPtr;
408 } // namespace shapes
409 
410 #endif
shapes::Box::Box
Box()
Definition: shapes.cpp:172
shapes::Mesh::print
void print(std::ostream &out=std::cout) const override
Print information about this shape.
Definition: shapes.cpp:486
shapes::Cone::radius
double radius
The radius of the cone.
Definition: shapes.h:221
shapes::Plane::scaleAndPadd
void scaleAndPadd(double scale, double padd) override
Uniformly scale and padd this shape.
Definition: shapes.cpp:310
shapes::Box::size
double size[3]
x, y, z dimensions of the box (axis-aligned)
Definition: shapes.h:270
shapes
Definition of various shapes. No properties such as position are included. These are simply the descr...
Definition: mesh_operations.h:47
shapes::Cone::length
double length
The length (height) of the cone.
Definition: shapes.h:218
shapes::Box::print
void print(std::ostream &out=std::cout) const override
Print information about this shape.
Definition: shapes.cpp:481
shapes::Cylinder::scaleAndPadd
void scaleAndPadd(double scaleRadius, double scaleLength, double paddRadius, double paddLength)
Scale this shape by a non-uniform factor and then add non-uniform padding.
Definition: shapes.cpp:333
shapes::OcTree::octree
std::shared_ptr< const octomap::OcTree > octree
Definition: shapes.h:400
shapes::Mesh::triangles
unsigned int * triangles
The vertex indices for each triangle triangle k has vertices at index (3k, 3k+1, 3k+2) = (v1,...
Definition: shapes.h:355
shapes::PLANE
@ PLANE
Definition: shapes.h:68
shapes::Mesh::~Mesh
~Mesh() override
Definition: shapes.cpp:210
shapes::Box::clone
Box * clone() const override
Create a copy of this shape.
Definition: shapes.cpp:262
shapes::Cylinder::print
void print(std::ostream &out=std::cout) const override
Print information about this shape.
Definition: shapes.cpp:471
shapes::UNKNOWN_SHAPE
@ UNKNOWN_SHAPE
Definition: shapes.h:63
shapes::Cone::padd
void padd(double paddRadius, double paddLength)
Add non-uniform padding to this shape.
Definition: shapes.cpp:373
shapes::Mesh::vertex_normals
double * vertex_normals
The normal to each vertex; unit vector represented as (x,y,z); If missing from the mesh,...
Definition: shapes.h:363
shapes::Cone::print
void print(std::ostream &out=std::cout) const override
Print information about this shape.
Definition: shapes.cpp:476
shapes::Cylinder
Definition of a cylinder Length is along z axis. Origin is at center of mass.
Definition: shapes.h:127
shapes::OcTree::print
void print(std::ostream &out=std::cout) const override
Print information about this shape.
Definition: shapes.cpp:496
shapes::OcTree::scaleAndPadd
void scaleAndPadd(double scale, double padd) override
Uniformly scale and padd this shape.
Definition: shapes.cpp:305
shapes::Cylinder::clone
Cylinder * clone() const override
Create a copy of this shape.
Definition: shapes.cpp:252
shapes::Cone::Cone
Cone()
Definition: shapes.cpp:157
shapes::Mesh::triangle_count
unsigned int triangle_count
The number of triangles formed with the vertices.
Definition: shapes.h:351
shapes::Sphere::print
void print(std::ostream &out=std::cout) const override
Print information about this shape.
Definition: shapes.cpp:466
shapes::operator<<
std::ostream & operator<<(std::ostream &ss, ShapeType type)
Definition: shapes.cpp:84
shapes::SPHERE
@ SPHERE
Definition: shapes.h:64
shapes::Shape::scale
void scale(double scale)
Uniformly scale this shape by a factor.
Definition: shapes.cpp:315
shapes::Shape
A basic definition of a shape. Shapes are considered centered at origin.
Definition: shapes.h:77
shapes::Mesh::mergeVertices
void mergeVertices(double threshold)
Merge vertices that are very close to each other, up to a threshold.
Definition: shapes.cpp:600
shapes::Mesh
Definition of a triangle mesh By convention the "center" of the shape is at the origin....
Definition: shapes.h:281
shapes::Mesh::scale
void scale(double scaleX, double scaleY, double scaleZ)
Scale this shape by a non-uniform factor.
Definition: shapes.cpp:446
shapes::Sphere::STRING_NAME
static const std::string STRING_NAME
The type of the shape, as a string.
Definition: shapes.h:115
shapes::Plane::isFixed
bool isFixed() const override
Return a flag indicating whether this shape can be scaled and/or padded.
Definition: shapes.cpp:521
shapes::MESH
@ MESH
Definition: shapes.h:69
shapes::Box::scale
void scale(double scaleX, double scaleY, double scaleZ)
Scale this shape by a non-uniform factor.
Definition: shapes.cpp:395
shapes::Mesh::computeVertexNormals
void computeVertexNormals()
Compute vertex normals by averaging from adjacent triangle normals, weighted using magnitude of angle...
Definition: shapes.cpp:549
shapes::Shape::padd
void padd(double padding)
Add uniform padding to this shape.
Definition: shapes.cpp:320
shapes::CONE
@ CONE
Definition: shapes.h:66
shapes::OcTree::STRING_NAME
static const std::string STRING_NAME
The type of the shape, as a string.
Definition: shapes.h:393
shapes::Sphere::Sphere
Sphere()
Definition: shapes.cpp:128
shapes::Mesh::Mesh
Mesh()
Definition: shapes.cpp:188
shapes::Sphere::radius
double radius
The radius of the sphere.
Definition: shapes.h:122
shapes::ShapePtr
std::shared_ptr< Shape > ShapePtr
Shared pointer to a Shape.
Definition: shapes.h:404
shapes::Plane
Definition of a plane with equation ax + by + cz + d = 0.
Definition: shapes.h:367
shapes::Box
Definition of a box Aligned with the XYZ axes.
Definition: shapes.h:226
shapes::Sphere
Definition of a sphere.
Definition: shapes.h:106
shapes::Cylinder::STRING_NAME
static const std::string STRING_NAME
The type of the shape, as a string.
Definition: shapes.h:139
shapes::Mesh::vertex_count
unsigned int vertex_count
The number of available vertices.
Definition: shapes.h:344
y
double y
Definition: mesh_operations.cpp:202
shapes::Shape::scaleAndPadd
virtual void scaleAndPadd(double scale, double padd)=0
Uniformly scale and padd this shape.
shapes::ShapeType
ShapeType
A list of known shape types.
Definition: shapes.h:61
shapes::Plane::a
double a
The plane equation is ax + by + cz + d = 0.
Definition: shapes.h:382
shapes::Cone::clone
Cone * clone() const override
Create a copy of this shape.
Definition: shapes.cpp:257
shapes::Cylinder::Cylinder
Cylinder()
Definition: shapes.cpp:142
shapes::Shape::type
ShapeType type
The type of the shape.
Definition: shapes.h:102
shapes::Mesh::computeTriangleNormals
void computeTriangleNormals()
Compute the normals of each triangle from its vertices via cross product.
Definition: shapes.cpp:526
shapes::Plane::d
double d
Definition: shapes.h:382
shapes::Shape::~Shape
virtual ~Shape()
Definition: shapes.cpp:124
shapes::Cone::scale
void scale(double scaleRadius, double scaleLength)
Scale this shape by a non-uniform factor.
Definition: shapes.cpp:368
shapes::Box::STRING_NAME
static const std::string STRING_NAME
The type of the shape, as a string.
Definition: shapes.h:236
shapes::Mesh::vertices
double * vertices
The position for each vertex vertex k has values at index (3k, 3k+1, 3k+2) = (x,y,...
Definition: shapes.h:348
shapes::OcTree
Representation of an octomap::OcTree as a Shape.
Definition: shapes.h:386
r
S r
shapes::OCTREE
@ OCTREE
Definition: shapes.h:70
shapes::Cylinder::padd
void padd(double paddRadius, double paddLength)
Add non-uniform padding to this shape.
Definition: shapes.cpp:348
shapes::Mesh::triangle_normals
double * triangle_normals
The normal to each triangle; unit vector represented as (x,y,z); If missing from the mesh,...
Definition: shapes.h:359
shapes::Sphere::scaleAndPadd
void scaleAndPadd(double scale, double padd) override
Uniformly scale and padd this shape.
Definition: shapes.cpp:325
shapes::Box::padd
void padd(double paddX, double paddY, double paddZ)
Add non-uniform padding to this shape.
Definition: shapes.cpp:400
shapes::Cylinder::scale
void scale(double scaleRadius, double scaleLength)
Scale this shape by a non-uniform factor.
Definition: shapes.cpp:343
shapes::Mesh::scaleAndPadd
void scaleAndPadd(double scaleX, double scaleY, double scaleZ, double paddX, double paddY, double paddZ)
Scale this shape by a non-uniform factor and then add non-uniform padding.
Definition: shapes.cpp:410
shapes::Box::scaleAndPadd
void scaleAndPadd(double scaleX, double scaleY, double scaleZ, double paddX, double paddY, double paddZ)
Scale this shape by a non-uniform factor and then add non-uniform padding.
Definition: shapes.cpp:383
shapes::Sphere::clone
Sphere * clone() const override
Create a copy of this shape.
Definition: shapes.cpp:247
shapes::Shape::isFixed
virtual bool isFixed() const
Return a flag indicating whether this shape can be scaled and/or padded.
Definition: shapes.cpp:511
shapes::Plane::STRING_NAME
static const std::string STRING_NAME
The type of the shape, as a string.
Definition: shapes.h:374
shapes::Plane::c
double c
Definition: shapes.h:382
shapes::CYLINDER
@ CYLINDER
Definition: shapes.h:65
shapes::Shape::clone
virtual Shape * clone() const =0
Create a copy of this shape.
shapes::Shape::print
virtual void print(std::ostream &out=std::cout) const
Print information about this shape.
Definition: shapes.cpp:461
shapes::Mesh::padd
void padd(double paddX, double paddY, double paddZ)
Add non-uniform padding to this shape.
Definition: shapes.cpp:451
shapes::Cone::scaleAndPadd
void scaleAndPadd(double scaleRadius, double scaleLength, double paddRadius, double paddLength)
Scale this shape by a non-uniform factor and then add non-uniform padding.
Definition: shapes.cpp:358
shapes::Cylinder::radius
double radius
The radius of the cylinder.
Definition: shapes.h:172
shapes::OcTree::clone
OcTree * clone() const override
Create a copy of this shape.
Definition: shapes.cpp:300
shapes::ShapeConstPtr
std::shared_ptr< const Shape > ShapeConstPtr
Shared pointer to a const Shape.
Definition: shapes.h:407
shapes::Mesh::clone
Mesh * clone() const override
Create a copy of this shape.
Definition: shapes.cpp:267
shapes::Shape::Shape
Shape()
Definition: shapes.cpp:119
x
double x
Definition: mesh_operations.cpp:202
shapes::Cylinder::length
double length
The length of the cylinder.
Definition: shapes.h:169
octomap
shapes::Cone
Definition of a cone Tip is on positive z axis. Center of base is on negative z axis....
Definition: shapes.h:178
shapes::Cone::STRING_NAME
static const std::string STRING_NAME
The type of the shape, as a string.
Definition: shapes.h:188
shapes::Mesh::STRING_NAME
static const std::string STRING_NAME
The type of the shape, as a string.
Definition: shapes.h:292
shapes::Plane::b
double b
Definition: shapes.h:382
shapes::Plane::clone
Plane * clone() const override
Create a copy of this shape.
Definition: shapes.cpp:295
shapes::Plane::Plane
Plane()
Definition: shapes.cpp:222
shapes::OcTree::OcTree
OcTree()
Definition: shapes.cpp:237
z
double z
Definition: mesh_operations.cpp:202
shapes::Plane::print
void print(std::ostream &out=std::cout) const override
Print information about this shape.
Definition: shapes.cpp:491
shapes::BOX
@ BOX
Definition: shapes.h:67
shapes::OcTree::isFixed
bool isFixed() const override
Return a flag indicating whether this shape can be scaled and/or padded.
Definition: shapes.cpp:516


geometric_shapes
Author(s): Ioan Sucan , Gil Jones
autogenerated on Tue Aug 13 2024 02:40:57