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 
37 #ifndef GEOMETRIC_SHAPES_SHAPES_
38 #define GEOMETRIC_SHAPES_SHAPES_
39 
40 #include <cstdlib>
41 #include <vector>
42 #include <tf/LinearMath/Vector3.h>
43 
47 namespace robot_self_filter
48 {
49 namespace shapes
50 {
51 
54 
56 
57 
59  class Shape
60  {
61  public:
62  Shape(void)
63  {
65  }
66 
67  virtual ~Shape(void)
68  {
69  }
70 
72  };
73 
76  {
77  public:
79  {
81  }
82 
83  virtual ~StaticShape(void)
84  {
85  }
86 
88  };
89 
91  class Sphere : public Shape
92  {
93  public:
94  Sphere(void) : Shape()
95  {
96  type = SPHERE;
97  radius = 0.0;
98  }
99 
100  Sphere(double r) : Shape()
101  {
102  type = SPHERE;
103  radius = r;
104  }
105 
106  double radius;
107  };
108 
110  class Cylinder : public Shape
111  {
112  public:
113  Cylinder(void) : Shape()
114  {
115  type = CYLINDER;
116  length = radius = 0.0;
117  }
118 
119  Cylinder(double r, double l) : Shape()
120  {
121  type = CYLINDER;
122  length = l;
123  radius = r;
124  }
125 
126  double length, radius;
127  };
128 
130  class Box : public Shape
131  {
132  public:
133  Box(void) : Shape()
134  {
135  type = BOX;
136  size[0] = size[1] = size[2] = 0.0;
137  }
138 
139  Box(double x, double y, double z) : Shape()
140  {
141  type = BOX;
142  size[0] = x;
143  size[1] = y;
144  size[2] = z;
145  }
146 
148  double size[3];
149  };
150 
152  class Mesh : public Shape
153  {
154  public:
155  Mesh(void) : Shape()
156  {
157  type = MESH;
158  vertexCount = 0;
159  vertices = NULL;
160  triangleCount = 0;
161  triangles = NULL;
162  normals = NULL;
163  }
164 
165  Mesh(unsigned int vCount, unsigned int tCount) : Shape()
166  {
167  type = MESH;
168  vertexCount = vCount;
169  vertices = new double[vCount * 3];
170  triangleCount = tCount;
171  triangles = new unsigned int[tCount * 3];
172  normals = new double[tCount * 3];
173  }
174 
175  virtual ~Mesh(void)
176  {
177  if (vertices)
178  delete[] vertices;
179  if (triangles)
180  delete[] triangles;
181  if (normals)
182  delete[] normals;
183  }
184 
186  unsigned int vertexCount;
187 
190  double *vertices;
191 
193  unsigned int triangleCount;
194 
197  unsigned int *triangles;
198 
201  double *normals;
202  };
203 
205  class Plane : public StaticShape
206  {
207  public:
208 
209  Plane(void) : StaticShape()
210  {
211  type = PLANE;
212  a = b = c = d = 0.0;
213  }
214 
215  Plane(double pa, double pb, double pc, double pd) : StaticShape()
216  {
217  type = PLANE;
218  a = pa; b = pb; c = pc; d = pd;
219  }
220 
221  double a, b, c, d;
222  };
223 
224 
229  Mesh* createMeshFromVertices(const std::vector<tf::Vector3> &vertices, const std::vector<unsigned int> &triangles);
230 
235  Mesh* createMeshFromVertices(const std::vector<tf::Vector3> &source);
236 
239  Mesh* createMeshFromBinaryStl(const char *filename);
240 
243  Mesh* createMeshFromBinaryStlData(const char *data, unsigned int size);
244 
247  Mesh* createMeshFromBinaryDAE(const char* filename);
248 
249 
251  Shape* cloneShape(const Shape *shape);
252 
254  StaticShape* cloneShape(const StaticShape *shape);
255 
256 }
257 
258 }
259 #endif
d
Definition of a box.
Definition: shapes.h:130
A basic definition of a static shape. Static shapes do not have a pose.
Definition: shapes.h:75
Plane(double pa, double pb, double pc, double pd)
Definition: shapes.h:215
Definition of a cylinder.
Definition: shapes.h:110
double * normals
the normal to each triangle unit vector represented as (x,y,z)
Definition: shapes.h:201
ShapeType
A list of known shape types.
Definition: shapes.h:53
Definition of a plane with equation ax + by + cz + d = 0.
Definition: shapes.h:205
Definition of a mesh.
Definition: shapes.h:152
Mesh(unsigned int vCount, unsigned int tCount)
Definition: shapes.h:165
double * vertices
the position for each vertex vertex k has values at index (3k, 3k+1, 3k+2) = (x,y,z)
Definition: shapes.h:190
Shape * cloneShape(const Shape *shape)
Create a copy of a shape.
Definition: shapes.cpp:41
Mesh * createMeshFromBinaryStl(const char *filename)
Load a mesh from a binary STL file. Normals are recomputed and repeating vertices are identified...
Definition: load_mesh.cpp:535
Definition of a sphere.
Definition: shapes.h:91
Mesh * createMeshFromBinaryDAE(const char *filename)
Load a mesh from a binary DAE file. Normals are recomputed and repeating vertices are identified...
Definition: load_mesh.cpp:521
A basic definition of a shape. Shapes are considered centered at origin.
Definition: shapes.h:59
Cylinder(double r, double l)
Definition: shapes.h:119
TFSIMD_FORCE_INLINE tfScalar length(const Quaternion &q)
Mesh * createMeshFromBinaryStlData(const char *data, unsigned int size)
Load a mesh from a binary STL stream. Normals are recomputed and repeating vertices are identified...
Definition: load_mesh.cpp:463
unsigned int * triangles
the vertex indices for each triangle triangle k has vertices at index (3k, 3k+1, 3k+2) = (v1...
Definition: shapes.h:197
unsigned int vertexCount
the number of available vertices
Definition: shapes.h:186
unsigned int triangleCount
the number of triangles formed with the vertices
Definition: shapes.h:193
Box(double x, double y, double z)
Definition: shapes.h:139
Mesh * createMeshFromVertices(const std::vector< tf::Vector3 > &vertices, const std::vector< unsigned int > &triangles)
Load a mesh from a set of vertices. Triangles are constructed using index values from the triangles v...
Definition: load_mesh.cpp:355


robot_self_filter
Author(s): Eitan Marder-Eppstein
autogenerated on Thu Jun 6 2019 19:59:05