Main Page Class List Class Members

btConvexHullComputer.h
Go to the documentation of this file.
1 /*
2 Copyright (c) 2011 Ole Kniemeyer, MAXON, www.maxon.net
3
4 This software is provided 'as-is', without any express or implied warranty.
5 In no event will the authors be held liable for any damages arising from the use of this software.
6 Permission is granted to anyone to use this software for any purpose,
7 including commercial applications, and to alter it and redistribute it freely,
8 subject to the following restrictions:
9
10 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
11 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
12 3. This notice may not be removed or altered from any source distribution.
13 */
14
15 #ifndef BT_CONVEX_HULL_COMPUTER_H
16 #define BT_CONVEX_HULL_COMPUTER_H
17
18 #include "btAlignedObjectArray.h"
19 #include "btVector3.h"
20
24 class btConvexHullComputer {
25 private:
26 btScalar compute(const void* coords, bool doubleCoords, int32_t stride, int32_t count, btScalar shrink, btScalar shrinkClamp);
27
28 public:
29 class Edge {
30 private:
31 int32_t next;
32 int32_t reverse;
33 int32_t targetVertex;
34
35 friend class btConvexHullComputer;
36
37 public:
38 int32_t getSourceVertex() const
39 {
40 return (this + reverse)->targetVertex;
41 }
42
43 int32_t getTargetVertex() const
44 {
45 return targetVertex;
46 }
47
48 const Edge* getNextEdgeOfVertex() const // clockwise list of all edges of a vertex
49 {
50 return this + next;
51 }
52
53 const Edge* getNextEdgeOfFace() const // counter-clockwise list of all edges of a face
54 {
55 return (this + reverse)->getNextEdgeOfVertex();
56 }
57
58 const Edge* getReverseEdge() const
59 {
60 return this + reverse;
61 }
62 };
63
64 // Vertices of the output hull
65 btAlignedObjectArray<btVector3> vertices;
66
67 // Edges of the output hull
68 btAlignedObjectArray<Edge> edges;
69
70 // Faces of the convex hull. Each entry is an index into the "edges" array pointing to an edge of the face. Faces are planar n-gons
71 btAlignedObjectArray<int32_t> faces;
72
73 /*
74 Compute convex hull of "count" vertices stored in "coords". "stride" is the difference in bytes
75 between the addresses of consecutive vertices. If "shrink" is positive, the convex hull is shrunken
76 by that amount (each face is moved by "shrink" length units towards the center along its normal).
77 If "shrinkClamp" is positive, "shrink" is clamped to not exceed "shrinkClamp * innerRadius", where "innerRadius"
78 is the minimum distance of a face to the center of the convex hull.
79
80 The returned value is the amount by which the hull has been shrunken. If it is negative, the amount was so large
81 that the resulting convex hull is empty.
82
83 The output convex hull can be found in the member variables "vertices", "edges", "faces".
84 */
85 btScalar compute(const float* coords, int32_t stride, int32_t count, btScalar shrink, btScalar shrinkClamp)
86 {
87 return compute(coords, false, stride, count, shrink, shrinkClamp);
88 }
89
90 // same as above, but double precision
91 btScalar compute(const double* coords, int32_t stride, int32_t count, btScalar shrink, btScalar shrinkClamp)
92 {
93 return compute(coords, true, stride, count, shrink, shrinkClamp);
94 }
95 };
96
97 #endif //BT_CONVEX_HULL_COMPUTER_H
btConvexHullComputer::edges
btAlignedObjectArray< Edge > edges
Definition: btConvexHullComputer.h:68
btConvexHullComputer::Edge
Definition: btConvexHullComputer.h:29
btAlignedObjectArray< btVector3 >
btConvexHullComputer
Definition: btConvexHullComputer.h:24
btVector3.h
btConvexHullComputer::vertices
btAlignedObjectArray< btVector3 > vertices
Definition: btConvexHullComputer.h:65
btConvexHullComputer::Edge::getNextEdgeOfFace
const Edge * getNextEdgeOfFace() const
Definition: btConvexHullComputer.h:53
btConvexHullComputer::Edge::getReverseEdge
const Edge * getReverseEdge() const
Definition: btConvexHullComputer.h:58
btScalar
float btScalar
The btScalar type abstracts floating point numbers, to easily switch between double and single floati...
Definition: btScalar.h:208
btConvexHullComputer::faces
btAlignedObjectArray< int32_t > faces
Definition: btConvexHullComputer.h:71
btConvexHullComputer::Edge::getTargetVertex
int32_t getTargetVertex() const
Definition: btConvexHullComputer.h:43
btConvexHullComputer::Edge::getNextEdgeOfVertex
const Edge * getNextEdgeOfVertex() const
Definition: btConvexHullComputer.h:48
btConvexHullComputer::compute
btScalar compute(const float *coords, int32_t stride, int32_t count, btScalar shrink, btScalar shrinkClamp)
Definition: btConvexHullComputer.h:85
btAlignedObjectArray.h
btConvexHullComputer::compute
btScalar compute(const double *coords, int32_t stride, int32_t count, btScalar shrink, btScalar shrinkClamp)
Definition: btConvexHullComputer.h:91
btConvexHullComputer::Edge::getSourceVertex
int32_t getSourceVertex() const
Definition: btConvexHullComputer.h:38