shapes.cpp
Go to the documentation of this file.
1 /*********************************************************************
2  * Software License Agreement (BSD License)
3  *
4  * Copyright (c) 2011, 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 
39 #include <octomap/octomap.h>
40 #include <console_bridge/console.h>
41 
42 namespace shapes
43 {
44 const std::string Sphere::STRING_NAME = "sphere";
45 const std::string Box::STRING_NAME = "box";
46 const std::string Cylinder::STRING_NAME = "cylinder";
47 const std::string Cone::STRING_NAME = "cone";
48 const std::string Mesh::STRING_NAME = "mesh";
49 const std::string Plane::STRING_NAME = "plane";
50 const std::string OcTree::STRING_NAME = "octree";
51 
52 std::ostream& operator<<(std::ostream& ss, ShapeType type)
53 {
54  switch (type)
55  {
56  case UNKNOWN_SHAPE:
57  ss << "unknown";
58  break;
59  case SPHERE:
60  ss << Sphere::STRING_NAME;
61  break;
62  case CYLINDER:
64  break;
65  case CONE:
66  ss << Cone::STRING_NAME;
67  break;
68  case BOX:
69  ss << Box::STRING_NAME;
70  break;
71  case PLANE:
72  ss << Plane::STRING_NAME;
73  break;
74  case MESH:
75  ss << Mesh::STRING_NAME;
76  break;
77  case OCTREE:
78  ss << OcTree::STRING_NAME;
79  break;
80  default:
81  ss << "impossible";
82  break;
83  }
84  return ss;
85 }
86 
88 {
90 }
91 
93 {
94 }
95 
97 {
98  type = SPHERE;
99  radius = 0.0;
100 }
101 
102 Sphere::Sphere(double r) : Shape()
103 {
104  if (r < 0)
105  throw std::runtime_error("Sphere radius must be non-negative.");
106  type = SPHERE;
107  radius = r;
108 }
109 
111 {
112  type = CYLINDER;
113  length = radius = 0.0;
114 }
115 
116 Cylinder::Cylinder(double r, double l) : Shape()
117 {
118  if (r < 0 || l < 0)
119  throw std::runtime_error("Cylinder dimensions must be non-negative.");
120  type = CYLINDER;
121  length = l;
122  radius = r;
123 }
124 
126 {
127  type = CONE;
128  length = radius = 0.0;
129 }
130 
131 Cone::Cone(double r, double l) : Shape()
132 {
133  if (r < 0 || l < 0)
134  throw std::runtime_error("Cone dimensions must be non-negative.");
135  type = CONE;
136  length = l;
137  radius = r;
138 }
139 
141 {
142  type = BOX;
143  size[0] = size[1] = size[2] = 0.0;
144 }
145 
146 Box::Box(double x, double y, double z) : Shape()
147 {
148  if (x < 0 || y < 0 || z < 0)
149  throw std::runtime_error("Box dimensions must be non-negative.");
150  type = BOX;
151  size[0] = x;
152  size[1] = y;
153  size[2] = z;
154 }
155 
157 {
158  type = MESH;
159  vertex_count = 0;
160  vertices = nullptr;
161  triangle_count = 0;
162  triangles = nullptr;
163  triangle_normals = nullptr;
164  vertex_normals = nullptr;
165 }
166 
167 Mesh::Mesh(unsigned int v_count, unsigned int t_count) : Shape()
168 {
169  type = MESH;
170  vertex_count = v_count;
171  vertices = new double[v_count * 3];
172  triangle_count = t_count;
173  triangles = new unsigned int[t_count * 3];
174  triangle_normals = new double[t_count * 3];
175  vertex_normals = new double[v_count * 3];
176 }
177 
179 {
180  if (vertices)
181  delete[] vertices;
182  if (triangles)
183  delete[] triangles;
184  if (triangle_normals)
185  delete[] triangle_normals;
186  if (vertex_normals)
187  delete[] vertex_normals;
188 }
189 
191 {
192  type = PLANE;
193  a = b = c = d = 0.0;
194 }
195 
196 Plane::Plane(double pa, double pb, double pc, double pd) : Shape()
197 {
198  type = PLANE;
199  a = pa;
200  b = pb;
201  c = pc;
202  d = pd;
203 }
204 
206 {
207  type = OCTREE;
208 }
209 
210 OcTree::OcTree(const std::shared_ptr<const octomap::OcTree>& t) : octree(t)
211 {
212  type = OCTREE;
213 }
214 
216 {
217  return new Sphere(radius);
218 }
219 
221 {
222  return new Cylinder(radius, length);
223 }
224 
226 {
227  return new Cone(radius, length);
228 }
229 
230 Box* Box::clone() const
231 {
232  return new Box(size[0], size[1], size[2]);
233 }
234 
236 {
237  Mesh* dest = new Mesh(vertex_count, triangle_count);
238  unsigned int n = 3 * vertex_count;
239  for (unsigned int i = 0; i < n; ++i)
240  dest->vertices[i] = vertices[i];
241  if (vertex_normals)
242  for (unsigned int i = 0; i < n; ++i)
243  dest->vertex_normals[i] = vertex_normals[i];
244  else
245  {
246  delete[] dest->vertex_normals;
247  dest->vertex_normals = nullptr;
248  }
249  n = 3 * triangle_count;
250  for (unsigned int i = 0; i < n; ++i)
251  dest->triangles[i] = triangles[i];
252  if (triangle_normals)
253  for (unsigned int i = 0; i < n; ++i)
254  dest->triangle_normals[i] = triangle_normals[i];
255  else
256  {
257  delete[] dest->triangle_normals;
258  dest->triangle_normals = nullptr;
259  }
260  return dest;
261 }
262 
264 {
265  return new Plane(a, b, c, d);
266 }
267 
269 {
270  return new OcTree(octree);
271 }
272 
273 void OcTree::scaleAndPadd(double /* scale */, double /* padd */)
274 {
275  CONSOLE_BRIDGE_logWarn("OcTrees cannot be scaled or padded");
276 }
277 
278 void Plane::scaleAndPadd(double /* scale */, double /* padd */)
279 {
280  CONSOLE_BRIDGE_logWarn("Planes cannot be scaled or padded");
281 }
282 
283 void Shape::scale(double scale)
284 {
285  scaleAndPadd(scale, 0.0);
286 }
287 
288 void Shape::padd(double padding)
289 {
290  scaleAndPadd(1.0, padding);
291 }
292 
293 void Sphere::scaleAndPadd(double scale, double padding)
294 {
295  const auto tmpRadius = radius * scale + padding;
296  if (tmpRadius < 0)
297  throw std::runtime_error("Sphere radius must be non-negative.");
298  radius = tmpRadius;
299 }
300 
301 void Cylinder::scaleAndPadd(double scaleRadius, double scaleLength, double paddRadius, double paddLength)
302 {
303  const auto tmpRadius = radius * scaleRadius + paddRadius;
304  const auto tmpLength = length * scaleLength + 2.0 * paddLength;
305  if (tmpRadius < 0 || tmpLength < 0)
306  throw std::runtime_error("Cylinder dimensions must be non-negative.");
307  radius = tmpRadius;
308  length = tmpLength;
309 }
310 
311 void Cylinder::scale(double scaleRadius, double scaleLength)
312 {
313  scaleAndPadd(scaleRadius, scaleLength, 0.0, 0.0);
314 }
315 
316 void Cylinder::padd(double paddRadius, double paddLength)
317 {
318  scaleAndPadd(1.0, 1.0, paddRadius, paddLength);
319 }
320 
321 void Cylinder::scaleAndPadd(double scale, double padd)
322 {
323  scaleAndPadd(scale, scale, padd, padd);
324 }
325 
326 void Cone::scaleAndPadd(double scaleRadius, double scaleLength, double paddRadius, double paddLength)
327 {
328  const auto tmpRadius = radius * scaleRadius + paddRadius;
329  const auto tmpLength = length * scaleLength + 2.0 * paddLength;
330  if (tmpRadius < 0 || tmpLength < 0)
331  throw std::runtime_error("Cone dimensions must be non-negative.");
332  radius = tmpRadius;
333  length = tmpLength;
334 }
335 
336 void Cone::scale(double scaleRadius, double scaleLength)
337 {
338  scaleAndPadd(scaleRadius, scaleLength, 0.0, 0.0);
339 }
340 
341 void Cone::padd(double paddRadius, double paddLength)
342 {
343  scaleAndPadd(1.0, 1.0, paddRadius, paddLength);
344 }
345 
346 void Cone::scaleAndPadd(double scale, double padd)
347 {
348  scaleAndPadd(scale, scale, padd, padd);
349 }
350 
351 void Box::scaleAndPadd(double scaleX, double scaleY, double scaleZ, double paddX, double paddY, double paddZ)
352 {
353  const auto tmpSize0 = size[0] * scaleX + paddX * 2.0;
354  const auto tmpSize1 = size[1] * scaleY + paddY * 2.0;
355  const auto tmpSize2 = size[2] * scaleZ + paddZ * 2.0;
356  if (tmpSize0 < 0 || tmpSize1 < 0 || tmpSize2 < 0)
357  throw std::runtime_error("Box dimensions must be non-negative.");
358  size[0] = tmpSize0;
359  size[1] = tmpSize1;
360  size[2] = tmpSize2;
361 }
362 
363 void Box::scale(double scaleX, double scaleY, double scaleZ)
364 {
365  scaleAndPadd(scaleX, scaleY, scaleZ, 0.0, 0.0, 0.0);
366 }
367 
368 void Box::padd(double paddX, double paddY, double paddZ)
369 {
370  scaleAndPadd(1.0, 1.0, 1.0, paddX, paddY, paddZ);
371 }
372 
373 void Box::scaleAndPadd(double scale, double padd)
374 {
375  scaleAndPadd(scale, scale, scale, padd, padd, padd);
376 }
377 
378 void Mesh::scaleAndPadd(double scaleX, double scaleY, double scaleZ, double paddX, double paddY, double paddZ)
379 {
380  // find the center of the mesh
381  double sx = 0.0, sy = 0.0, sz = 0.0;
382  for (unsigned int i = 0; i < vertex_count; ++i)
383  {
384  unsigned int i3 = i * 3;
385  sx += vertices[i3];
386  sy += vertices[i3 + 1];
387  sz += vertices[i3 + 2];
388  }
389  sx /= (double)vertex_count;
390  sy /= (double)vertex_count;
391  sz /= (double)vertex_count;
392 
393  // scale the mesh
394  for (unsigned int i = 0; i < vertex_count; ++i)
395  {
396  unsigned int i3 = i * 3;
397 
398  // vector from center to the vertex
399  double dx = vertices[i3] - sx;
400  double dy = vertices[i3 + 1] - sy;
401  double dz = vertices[i3 + 2] - sz;
402 
403  // length of vector
404  double norm = sqrt(dx * dx + dy * dy + dz * dz);
405  if (norm > 1e-6)
406  {
407  vertices[i3] = sx + dx * (scaleX + paddX / norm);
408  vertices[i3 + 1] = sy + dy * (scaleY + paddY / norm);
409  vertices[i3 + 2] = sz + dz * (scaleZ + paddZ / norm);
410  }
411  else
412  {
413  double ndx = ((dx > 0) ? dx + paddX : dx - paddX);
414  double ndy = ((dy > 0) ? dy + paddY : dy - paddY);
415  double ndz = ((dz > 0) ? dz + paddZ : dz - paddZ);
416  vertices[i3] = sx + ndx;
417  vertices[i3 + 1] = sy + ndy;
418  vertices[i3 + 2] = sz + ndz;
419  }
420  }
421 }
422 
423 void Mesh::scale(double scaleX, double scaleY, double scaleZ)
424 {
425  scaleAndPadd(scaleX, scaleY, scaleZ, 0.0, 0.0, 0.0);
426 }
427 
428 void Mesh::padd(double paddX, double paddY, double paddZ)
429 {
430  scaleAndPadd(1.0, 1.0, 1.0, paddX, paddY, paddZ);
431 }
432 
433 void Mesh::scaleAndPadd(double scale, double padd)
434 {
435  scaleAndPadd(scale, scale, scale, padd, padd, padd);
436 }
437 
438 void Shape::print(std::ostream& out) const
439 {
440  out << this << std::endl;
441 }
442 
443 void Sphere::print(std::ostream& out) const
444 {
445  out << "Sphere[radius=" << radius << "]" << std::endl;
446 }
447 
448 void Cylinder::print(std::ostream& out) const
449 {
450  out << "Cylinder[radius=" << radius << ", length=" << length << "]" << std::endl;
451 }
452 
453 void Cone::print(std::ostream& out) const
454 {
455  out << "Cone[radius=" << radius << ", length=" << length << "]" << std::endl;
456 }
457 
458 void Box::print(std::ostream& out) const
459 {
460  out << "Box[x=length=" << size[0] << ", y=width=" << size[1] << "z=height=" << size[2] << "]" << std::endl;
461 }
462 
463 void Mesh::print(std::ostream& out) const
464 {
465  out << "Mesh[vertices=" << vertex_count << ", triangles=" << triangle_count << "]" << std::endl;
466 }
467 
468 void Plane::print(std::ostream& out) const
469 {
470  out << "Plane[a=" << a << ", b=" << b << ", c=" << c << ", d=" << d << "]" << std::endl;
471 }
472 
473 void OcTree::print(std::ostream& out) const
474 {
475  if (octree)
476  {
477  double minx, miny, minz, maxx, maxy, maxz;
478  octree->getMetricMin(minx, miny, minz);
479  octree->getMetricMax(maxx, maxy, maxz);
480  out << "OcTree[depth = " << octree->getTreeDepth() << ", resolution = " << octree->getResolution()
481  << " inside box (minx=" << minx << ", miny=" << miny << ", minz=" << minz << ", maxx=" << maxx
482  << ", maxy=" << maxy << ", maxz=" << maxz << ")]" << std::endl;
483  }
484  else
485  out << "OcTree[NULL]" << std::endl;
486 }
487 
488 bool Shape::isFixed() const
489 {
490  return false;
491 }
492 
493 bool OcTree::isFixed() const
494 {
495  return true;
496 }
497 
498 bool Plane::isFixed() const
499 {
500  return true;
501 }
502 
504 {
505  if (triangle_count && !triangle_normals)
506  triangle_normals = new double[triangle_count * 3];
507 
508  // compute normals
509  for (unsigned int i = 0; i < triangle_count; ++i)
510  {
511  unsigned int i3 = i * 3;
512  Eigen::Vector3d s1(vertices[triangles[i3] * 3] - vertices[triangles[i3 + 1] * 3],
513  vertices[triangles[i3] * 3 + 1] - vertices[triangles[i3 + 1] * 3 + 1],
514  vertices[triangles[i3] * 3 + 2] - vertices[triangles[i3 + 1] * 3 + 2]);
515  Eigen::Vector3d s2(vertices[triangles[i3 + 1] * 3] - vertices[triangles[i3 + 2] * 3],
516  vertices[triangles[i3 + 1] * 3 + 1] - vertices[triangles[i3 + 2] * 3 + 1],
517  vertices[triangles[i3 + 1] * 3 + 2] - vertices[triangles[i3 + 2] * 3 + 2]);
518  Eigen::Vector3d normal = s1.cross(s2);
519  normal.normalize();
520  triangle_normals[i3] = normal.x();
521  triangle_normals[i3 + 1] = normal.y();
522  triangle_normals[i3 + 2] = normal.z();
523  }
524 }
525 
527 {
528  if (!triangle_normals)
529  computeTriangleNormals();
530  if (vertex_count && !vertex_normals)
531  vertex_normals = new double[vertex_count * 3];
532  EigenSTL::vector_Vector3d avg_normals(vertex_count, Eigen::Vector3d(0, 0, 0));
533 
534  for (unsigned int tIdx = 0; tIdx < triangle_count; ++tIdx)
535  {
536  unsigned int tIdx3 = 3 * tIdx;
537  unsigned int tIdx3_1 = tIdx3 + 1;
538  unsigned int tIdx3_2 = tIdx3 + 2;
539 
540  unsigned int v1 = triangles[tIdx3];
541  unsigned int v2 = triangles[tIdx3_1];
542  unsigned int v3 = triangles[tIdx3_2];
543 
544  avg_normals[v1][0] += triangle_normals[tIdx3];
545  avg_normals[v1][1] += triangle_normals[tIdx3_1];
546  avg_normals[v1][2] += triangle_normals[tIdx3_2];
547 
548  avg_normals[v2][0] += triangle_normals[tIdx3];
549  avg_normals[v2][1] += triangle_normals[tIdx3_1];
550  avg_normals[v2][2] += triangle_normals[tIdx3_2];
551 
552  avg_normals[v3][0] += triangle_normals[tIdx3];
553  avg_normals[v3][1] += triangle_normals[tIdx3_1];
554  avg_normals[v3][2] += triangle_normals[tIdx3_2];
555  }
556  for (std::size_t i = 0; i < avg_normals.size(); ++i)
557  {
558  if (avg_normals[i].squaredNorm() > 0.0)
559  avg_normals[i].normalize();
560  unsigned int i3 = i * 3;
561  vertex_normals[i3] = avg_normals[i][0];
562  vertex_normals[i3 + 1] = avg_normals[i][1];
563  vertex_normals[i3 + 2] = avg_normals[i][2];
564  }
565 }
566 
567 void Mesh::mergeVertices(double threshold)
568 {
569  const double thresholdSQR = threshold * threshold;
570 
571  std::vector<unsigned int> vertex_map(vertex_count);
572  EigenSTL::vector_Vector3d orig_vertices(vertex_count);
573  EigenSTL::vector_Vector3d compressed_vertices;
574 
575  for (unsigned int vIdx = 0; vIdx < vertex_count; ++vIdx)
576  {
577  orig_vertices[vIdx][0] = vertices[3 * vIdx];
578  orig_vertices[vIdx][1] = vertices[3 * vIdx + 1];
579  orig_vertices[vIdx][2] = vertices[3 * vIdx + 2];
580  vertex_map[vIdx] = vIdx;
581  }
582 
583  for (unsigned int vIdx1 = 0; vIdx1 < vertex_count; ++vIdx1)
584  {
585  if (vertex_map[vIdx1] != vIdx1)
586  continue;
587 
588  vertex_map[vIdx1] = compressed_vertices.size();
589  compressed_vertices.push_back(orig_vertices[vIdx1]);
590 
591  for (unsigned int vIdx2 = vIdx1 + 1; vIdx2 < vertex_count; ++vIdx2)
592  {
593  double distanceSQR = (orig_vertices[vIdx1] - orig_vertices[vIdx2]).squaredNorm();
594  if (distanceSQR <= thresholdSQR)
595  vertex_map[vIdx2] = vertex_map[vIdx1];
596  }
597  }
598 
599  if (compressed_vertices.size() == orig_vertices.size())
600  return;
601 
602  // redirect triangles to new vertices!
603  for (unsigned int tIdx = 0; tIdx < triangle_count; ++tIdx)
604  {
605  unsigned int i3 = 3 * tIdx;
606  triangles[i3] = vertex_map[triangles[i3]];
607  triangles[i3 + 1] = vertex_map[triangles[i3 + 1]];
608  triangles[i3 + 2] = vertex_map[triangles[i3 + 2]];
609  }
610 
611  vertex_count = compressed_vertices.size();
612  delete[] vertices;
613  vertices = new double[vertex_count * 3];
614 
615  for (unsigned int vIdx = 0; vIdx < vertex_count; ++vIdx)
616  {
617  unsigned int i3 = 3 * vIdx;
618  vertices[i3] = compressed_vertices[vIdx][0];
619  vertices[i3 + 1] = compressed_vertices[vIdx][1];
620  vertices[i3 + 2] = compressed_vertices[vIdx][2];
621  }
622 
623  if (triangle_normals)
624  computeTriangleNormals();
625  if (vertex_normals)
626  computeVertexNormals();
627 }
628 
629 } /* namespace shapes */
d
Definition of various shapes. No properties such as position are included. These are simply the descr...
double radius
The radius of the cylinder.
Definition: shapes.h:172
Cylinder * clone() const override
Create a copy of this shape.
Definition: shapes.cpp:220
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:351
void scale(double scaleX, double scaleY, double scaleZ)
Scale this shape by a non-uniform factor.
Definition: shapes.cpp:363
void scale(double scale)
Uniformly scale this shape by a factor.
Definition: shapes.cpp:283
void mergeVertices(double threshold)
Merge vertices that are very close to each other, up to a threshold.
Definition: shapes.cpp:567
Definition of a cylinder Length is along z axis. Origin is at center of mass.
Definition: shapes.h:127
std::vector< Eigen::Vector3d, Eigen::aligned_allocator< Eigen::Vector3d > > vector_Vector3d
void print(std::ostream &out=std::cout) const override
Print information about this shape.
Definition: shapes.cpp:453
double length
The length (height) of the cone.
Definition: shapes.h:218
Sphere * clone() const override
Create a copy of this shape.
Definition: shapes.cpp:215
double size[3]
x, y, z dimensions of the box (axis-aligned)
Definition: shapes.h:270
double b
Definition: shapes.h:381
Plane * clone() const override
Create a copy of this shape.
Definition: shapes.cpp:263
ShapeType type
The type of the shape.
Definition: shapes.h:102
static double distanceSQR(const Eigen::Vector3d &p, const Eigen::Vector3d &origin, const Eigen::Vector3d &dir)
Compute the square of the distance between a ray and a point Note: this requires &#39;dir&#39; to be normaliz...
Definition: bodies.cpp:82
double radius
The radius of the cone.
Definition: shapes.h:221
static const std::string STRING_NAME
The type of the shape, as a string.
Definition: shapes.h:139
double d
Definition: shapes.h:381
double length
The length of the cylinder.
Definition: shapes.h:169
void scale(double scaleX, double scaleY, double scaleZ)
Scale this shape by a non-uniform factor.
Definition: shapes.cpp:423
double c
Definition: shapes.h:381
void scaleAndPadd(double scale, double padd) override
Uniformly scale and padd this shape.
Definition: shapes.cpp:293
unsigned int * triangles
The vertex indices for each triangle triangle k has vertices at index (3k, 3k+1, 3k+2) = (v1...
Definition: shapes.h:354
void scaleAndPadd(double scale, double padd) override
Uniformly scale and padd this shape.
Definition: shapes.cpp:278
~Mesh() override
Definition: shapes.cpp:178
void print(std::ostream &out=std::cout) const override
Print information about this shape.
Definition: shapes.cpp:458
double y
Definition of a plane with equation ax + by + cz + d = 0.
Definition: shapes.h:366
double a
The plane equation is ax + by + cz + d = 0.
Definition: shapes.h:381
void padd(double paddRadius, double paddLength)
Add non-uniform padding to this shape.
Definition: shapes.cpp:341
double * vertex_normals
The normal to each vertex; unit vector represented as (x,y,z); If missing from the mesh...
Definition: shapes.h:362
Representation of an octomap::OcTree as a Shape.
Definition: shapes.h:385
std::ostream & operator<<(std::ostream &ss, ShapeType type)
Definition: shapes.cpp:52
std::shared_ptr< const octomap::OcTree > octree
Definition: shapes.h:399
Definition of a cone Tip is on positive z axis. Center of base is on negative z axis. Origin is halway between tip and center of base.
Definition: shapes.h:178
unsigned int vertex_count
The number of available vertices.
Definition: shapes.h:343
void padd(double padding)
Add uniform padding to this shape.
Definition: shapes.cpp:288
A basic definition of a shape. Shapes are considered centered at origin.
Definition: shapes.h:77
void padd(double paddX, double paddY, double paddZ)
Add non-uniform padding to this shape.
Definition: shapes.cpp:428
OcTree * clone() const override
Create a copy of this shape.
Definition: shapes.cpp:268
void scale(double scaleRadius, double scaleLength)
Scale this shape by a non-uniform factor.
Definition: shapes.cpp:311
bool isFixed() const override
Return a flag indicating whether this shape can be scaled and/or padded.
Definition: shapes.cpp:493
unsigned int triangle_count
The number of triangles formed with the vertices.
Definition: shapes.h:350
virtual bool isFixed() const
Return a flag indicating whether this shape can be scaled and/or padded.
Definition: shapes.cpp:488
double z
ShapeType
A list of known shape types.
Definition: shapes.h:61
double * vertices
The position for each vertex vertex k has values at index (3k, 3k+1, 3k+2) = (x,y,z)
Definition: shapes.h:347
Cone * clone() const override
Create a copy of this shape.
Definition: shapes.cpp:225
double * triangle_normals
The normal to each triangle; unit vector represented as (x,y,z); If missing from the mesh...
Definition: shapes.h:358
void print(std::ostream &out=std::cout) const override
Print information about this shape.
Definition: shapes.cpp:473
void computeVertexNormals()
Compute vertex normals by averaging from adjacent triangle normals.
Definition: shapes.cpp:526
void print(std::ostream &out=std::cout) const override
Print information about this shape.
Definition: shapes.cpp:443
Definition of a sphere.
Definition: shapes.h:106
virtual ~Shape()
Definition: shapes.cpp:92
void print(std::ostream &out=std::cout) const override
Print information about this shape.
Definition: shapes.cpp:448
void computeTriangleNormals()
Compute the normals of each triangle from its vertices via cross product.
Definition: shapes.cpp:503
static const std::string STRING_NAME
The type of the shape, as a string.
Definition: shapes.h:373
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:326
static const std::string STRING_NAME
The type of the shape, as a string.
Definition: shapes.h:392
Definition of a triangle mesh By convention the "center" of the shape is at the origin. For a mesh this implies that the AABB of the mesh is centered at the origin. Some methods may not work with arbitrary meshes whose AABB is not centered at the origin. Padding is not applied to vertices plainly coordinate-wise, but instead the padding value is added to the length of the direction vector between centroid and each vertex.
Definition: shapes.h:281
Definition of a box Aligned with the XYZ axes.
Definition: shapes.h:226
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:378
void padd(double paddX, double paddY, double paddZ)
Add non-uniform padding to this shape.
Definition: shapes.cpp:368
void padd(double paddRadius, double paddLength)
Add non-uniform padding to this shape.
Definition: shapes.cpp:316
static const std::string STRING_NAME
The type of the shape, as a string.
Definition: shapes.h:292
void scale(double scaleRadius, double scaleLength)
Scale this shape by a non-uniform factor.
Definition: shapes.cpp:336
bool isFixed() const override
Return a flag indicating whether this shape can be scaled and/or padded.
Definition: shapes.cpp:498
Box * clone() const override
Create a copy of this shape.
Definition: shapes.cpp:230
double radius
The radius of the sphere.
Definition: shapes.h:122
void print(std::ostream &out=std::cout) const override
Print information about this shape.
Definition: shapes.cpp:463
void print(std::ostream &out=std::cout) const override
Print information about this shape.
Definition: shapes.cpp:468
static const std::string STRING_NAME
The type of the shape, as a string.
Definition: shapes.h:115
virtual void print(std::ostream &out=std::cout) const
Print information about this shape.
Definition: shapes.cpp:438
void scaleAndPadd(double scale, double padd) override
Uniformly scale and padd this shape.
Definition: shapes.cpp:273
static const std::string STRING_NAME
The type of the shape, as a string.
Definition: shapes.h:236
double x
Mesh * clone() const override
Create a copy of this shape.
Definition: shapes.cpp:235
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:301
static const std::string STRING_NAME
The type of the shape, as a string.
Definition: shapes.h:188


geometric_shapes
Author(s): Ioan Sucan , Gil Jones
autogenerated on Wed Sep 2 2020 03:15:00