Blender  V2.93
rb_convex_hull_api.cpp
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  *
16  * The Original Code is Copyright (C) 2020 Blender Foundation,
17  * All rights reserved.
18  */
19 
21 #include "RBI_hull_api.h"
22 
23 plConvexHull plConvexHullCompute(float (*coords)[3], int count)
24 {
26  computer->compute(reinterpret_cast<float *>(coords), sizeof(*coords), count, 0, 0);
27  return reinterpret_cast<plConvexHull>(computer);
28 }
29 
31 {
32  btConvexHullComputer *computer(reinterpret_cast<btConvexHullComputer *>(hull));
33  delete computer;
34 }
35 
37 {
38  btConvexHullComputer *computer(reinterpret_cast<btConvexHullComputer *>(hull));
39  return computer->vertices.size();
40 }
41 
43 {
44  btConvexHullComputer *computer(reinterpret_cast<btConvexHullComputer *>(hull));
45  return computer->faces.size();
46 }
47 
48 void plConvexHullGetVertex(plConvexHull hull, int n, float coords[3], int *original_index)
49 {
50  btConvexHullComputer *computer(reinterpret_cast<btConvexHullComputer *>(hull));
51  const btVector3 &v(computer->vertices[n]);
52  coords[0] = v[0];
53  coords[1] = v[1];
54  coords[2] = v[2];
55  (*original_index) = computer->original_vertex_index[n];
56 }
57 
59 {
60  btConvexHullComputer *computer(reinterpret_cast<btConvexHullComputer *>(hull));
61  const btConvexHullComputer::Edge *e_orig, *e;
62  int count;
63 
64  for (e_orig = &computer->edges[computer->faces[n]], e = e_orig, count = 0;
65  count == 0 || e != e_orig;
66  e = e->getNextEdgeOfFace(), count++) {
67  ;
68  }
69  return count;
70 }
71 
72 void plConvexHullGetFaceVertices(plConvexHull hull, int n, int *vertices)
73 {
74  btConvexHullComputer *computer(reinterpret_cast<btConvexHullComputer *>(hull));
75  const btConvexHullComputer::Edge *e_orig, *e;
76  int count;
77 
78  for (e_orig = &computer->edges[computer->faces[n]], e = e_orig, count = 0;
79  count == 0 || e != e_orig;
80  e = e->getNextEdgeOfFace(), count++) {
81  vertices[count] = e->getTargetVertex();
82  }
83 }
ATTR_WARN_UNUSED_RESULT const BMVert const BMEdge * e
ATTR_WARN_UNUSED_RESULT const BMVert * v
btVector3
btVector3 can be used to represent 3D points and vectors. It has an un-used w component to suit 16-by...
Definition: btVector3.h:82
SIMD_FORCE_INLINE int size() const
return the number of elements in the array
btAlignedObjectArray< btVector3 > vertices
btAlignedObjectArray< int > original_vertex_index
btAlignedObjectArray< int > faces
btAlignedObjectArray< Edge > edges
int count
int plConvexHullGetFaceSize(plConvexHull hull, int n)
void plConvexHullGetVertex(plConvexHull hull, int n, float coords[3], int *original_index)
int plConvexHullNumVertices(plConvexHull hull)
plConvexHull plConvexHullCompute(float(*coords)[3], int count)
void plConvexHullDelete(plConvexHull hull)
int plConvexHullNumFaces(plConvexHull hull)
void plConvexHullGetFaceVertices(plConvexHull hull, int n, int *vertices)