polytope.h
Go to the documentation of this file.
1 /***
2  * libccd
3  * ---------------------------------
4  * Copyright (c)2010 Daniel Fiser <danfis@danfis.cz>
5  *
6  *
7  * This file is part of libccd.
8  *
9  * Distributed under the OSI-approved BSD License (the "License");
10  * see accompanying file BDS-LICENSE for details or see
11  * <http://www.opensource.org/licenses/bsd-license.php>.
12  *
13  * This software is distributed WITHOUT ANY WARRANTY; without even the
14  * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
15  * See the License for more information.
16  */
17 
18 #ifndef __CCD_POLYTOPE_H__
19 #define __CCD_POLYTOPE_H__
20 
21 #include <stdlib.h>
22 #include <stdio.h>
23 #include "support.h"
24 #include "list.h"
25 
26 #ifdef __cplusplus
27 extern "C" {
28 #endif /* __cplusplus */
29 
30 #define CCD_PT_VERTEX 1
31 #define CCD_PT_EDGE 2
32 #define CCD_PT_FACE 3
33 
34 
35 #define __CCD_PT_EL \
36  int type; \
37  ccd_real_t dist; \
38  ccd_vec3_t witness; \
39  ccd_list_t list;
45 struct _ccd_pt_el_t {
47 };
48 typedef struct _ccd_pt_el_t ccd_pt_el_t;
49 
50 struct _ccd_pt_edge_t;
51 struct _ccd_pt_face_t;
52 
58 
59  int id;
62 };
64 
70 
72  struct _ccd_pt_face_t *faces[2];
73 
75 };
77 
83 
85 };
87 
88 
92 struct _ccd_pt_t {
96 
98  ccd_real_t nearest_dist;
100 };
101 typedef struct _ccd_pt_t ccd_pt_t;
102 
103 
104 void ccdPtInit(ccd_pt_t *pt);
105 void ccdPtDestroy(ccd_pt_t *pt);
106 
110 _ccd_inline void ccdPtFaceVec3(const ccd_pt_face_t *face,
111  ccd_vec3_t **a,
112  ccd_vec3_t **b,
113  ccd_vec3_t **c);
114 _ccd_inline void ccdPtFaceVertices(const ccd_pt_face_t *face,
115  ccd_pt_vertex_t **a,
116  ccd_pt_vertex_t **b,
117  ccd_pt_vertex_t **c);
118 _ccd_inline void ccdPtFaceEdges(const ccd_pt_face_t *f,
119  ccd_pt_edge_t **a,
120  ccd_pt_edge_t **b,
121  ccd_pt_edge_t **c);
122 
123 _ccd_inline void ccdPtEdgeVec3(const ccd_pt_edge_t *e,
124  ccd_vec3_t **a,
125  ccd_vec3_t **b);
126 _ccd_inline void ccdPtEdgeVertices(const ccd_pt_edge_t *e,
127  ccd_pt_vertex_t **a,
128  ccd_pt_vertex_t **b);
129 _ccd_inline void ccdPtEdgeFaces(const ccd_pt_edge_t *e,
130  ccd_pt_face_t **f1,
131  ccd_pt_face_t **f2);
132 
133 
139  ccd_real_t x, ccd_real_t y, ccd_real_t z);
140 
145  ccd_pt_vertex_t *v2);
146 
151  ccd_pt_edge_t *e2,
152  ccd_pt_edge_t *e3);
153 
158 _ccd_inline int ccdPtDelVertex(ccd_pt_t *pt, ccd_pt_vertex_t *);
159 _ccd_inline int ccdPtDelEdge(ccd_pt_t *pt, ccd_pt_edge_t *);
160 _ccd_inline int ccdPtDelFace(ccd_pt_t *pt, ccd_pt_face_t *);
161 
162 
167 
172 
173 
174 void ccdPtDumpSVT(ccd_pt_t *pt, const char *fn);
175 void ccdPtDumpSVT2(ccd_pt_t *pt, FILE *);
176 
177 
178 /**** INLINES ****/
180  ccd_real_t x, ccd_real_t y, ccd_real_t z)
181 {
182  ccd_support_t s;
183  ccdVec3Set(&s.v, x, y, z);
184  return ccdPtAddVertex(pt, &s);
185 }
186 
187 _ccd_inline int ccdPtDelVertex(ccd_pt_t *pt, ccd_pt_vertex_t *v)
188 {
189  // test if any edge is connected to this vertex
190  if (!ccdListEmpty(&v->edges))
191  return -1;
192 
193  // delete vertex from main list
194  ccdListDel(&v->list);
195 
196  if ((void *)pt->nearest == (void *)v){
197  pt->nearest = NULL;
198  }
199 
200  free(v);
201  return 0;
202 }
203 
204 _ccd_inline int ccdPtDelEdge(ccd_pt_t *pt, ccd_pt_edge_t *e)
205 {
206  // text if any face is connected to this edge (faces[] is always
207  // aligned to lower indices)
208  if (e->faces[0] != NULL)
209  return -1;
210 
211  // disconnect edge from lists of edges in vertex struct
212  ccdListDel(&e->vertex_list[0]);
213  ccdListDel(&e->vertex_list[1]);
214 
215  // disconnect edge from main list
216  ccdListDel(&e->list);
217 
218  if ((void *)pt->nearest == (void *)e){
219  pt->nearest = NULL;
220  }
221 
222  free(e);
223  return 0;
224 }
225 
226 _ccd_inline int ccdPtDelFace(ccd_pt_t *pt, ccd_pt_face_t *f)
227 {
228  ccd_pt_edge_t *e;
229  size_t i;
230 
231  // remove face from edges' recerence lists
232  for (i = 0; i < 3; i++){
233  e = f->edge[i];
234  if (e->faces[0] == f){
235  e->faces[0] = e->faces[1];
236  }
237  e->faces[1] = NULL;
238  }
239 
240  // remove face from list of all faces
241  ccdListDel(&f->list);
242 
243  if ((void *)pt->nearest == (void *)f){
244  pt->nearest = NULL;
245  }
246 
247  free(f);
248  return 0;
249 }
250 
251 _ccd_inline void ccdPtFaceVec3(const ccd_pt_face_t *face,
252  ccd_vec3_t **a,
253  ccd_vec3_t **b,
254  ccd_vec3_t **c)
255 {
256  *a = &face->edge[0]->vertex[0]->v.v;
257  *b = &face->edge[0]->vertex[1]->v.v;
258 
259  if (face->edge[1]->vertex[0] != face->edge[0]->vertex[0]
260  && face->edge[1]->vertex[0] != face->edge[0]->vertex[1]){
261  *c = &face->edge[1]->vertex[0]->v.v;
262  }else{
263  *c = &face->edge[1]->vertex[1]->v.v;
264  }
265 }
266 
267 _ccd_inline void ccdPtFaceVertices(const ccd_pt_face_t *face,
268  ccd_pt_vertex_t **a,
269  ccd_pt_vertex_t **b,
270  ccd_pt_vertex_t **c)
271 {
272  *a = face->edge[0]->vertex[0];
273  *b = face->edge[0]->vertex[1];
274 
275  if (face->edge[1]->vertex[0] != face->edge[0]->vertex[0]
276  && face->edge[1]->vertex[0] != face->edge[0]->vertex[1]){
277  *c = face->edge[1]->vertex[0];
278  }else{
279  *c = face->edge[1]->vertex[1];
280  }
281 }
282 
283 _ccd_inline void ccdPtFaceEdges(const ccd_pt_face_t *f,
284  ccd_pt_edge_t **a,
285  ccd_pt_edge_t **b,
286  ccd_pt_edge_t **c)
287 {
288  *a = f->edge[0];
289  *b = f->edge[1];
290  *c = f->edge[2];
291 }
292 
293 _ccd_inline void ccdPtEdgeVec3(const ccd_pt_edge_t *e,
294  ccd_vec3_t **a,
295  ccd_vec3_t **b)
296 {
297  *a = &e->vertex[0]->v.v;
298  *b = &e->vertex[1]->v.v;
299 }
300 
301 _ccd_inline void ccdPtEdgeVertices(const ccd_pt_edge_t *e,
302  ccd_pt_vertex_t **a,
303  ccd_pt_vertex_t **b)
304 {
305  *a = e->vertex[0];
306  *b = e->vertex[1];
307 }
308 
309 _ccd_inline void ccdPtEdgeFaces(const ccd_pt_edge_t *e,
310  ccd_pt_face_t **f1,
311  ccd_pt_face_t **f2)
312 {
313  *f1 = e->faces[0];
314  *f2 = e->faces[1];
315 }
316 
317 
318 #ifdef __cplusplus
319 } /* extern "C" */
320 #endif /* __cplusplus */
321 
322 #endif /* __CCD_POLYTOPE_H__ */
ccdPtAddFace
ccd_pt_face_t * ccdPtAddFace(ccd_pt_t *pt, ccd_pt_edge_t *e1, ccd_pt_edge_t *e2, ccd_pt_edge_t *e3)
_ccd_pt_t::nearest
ccd_pt_el_t * nearest
Definition: polytope.h:97
_ccd_pt_face_t::edge
__CCD_PT_EL ccd_pt_edge_t * edge[3]
Reference to surrounding edges.
Definition: polytope.h:84
_ccd_pt_vertex_t
Definition: polytope.h:56
std::tr1::f2
const T1 const T2 & f2
Definition: gtest-tuple.h:680
__CCD_PT_EL
#define __CCD_PT_EL
Definition: polytope.h:35
ccdPtFaceVec3
_ccd_inline void ccdPtFaceVec3(const ccd_pt_face_t *face, ccd_vec3_t **a, ccd_vec3_t **b, ccd_vec3_t **c)
Definition: polytope.h:251
ccdPtAddEdge
ccd_pt_edge_t * ccdPtAddEdge(ccd_pt_t *pt, ccd_pt_vertex_t *v1, ccd_pt_vertex_t *v2)
_ccd_pt_t::faces
ccd_list_t faces
List of faces.
Definition: polytope.h:95
ccdPtNearest
ccd_pt_el_t * ccdPtNearest(ccd_pt_t *pt)
_ccd_pt_vertex_t::edges
ccd_list_t edges
List of edges.
Definition: polytope.h:61
_ccd_support_t
Definition: support.h:27
ccdPtInit
void ccdPtInit(ccd_pt_t *pt)
_ccd_support_t::v
ccd_vec3_t v
Support point in minkowski sum.
Definition: support.h:43
_ccd_pt_vertex_t::id
__CCD_PT_EL int id
Definition: polytope.h:59
ccdPtEdgeVec3
_ccd_inline void ccdPtEdgeVec3(const ccd_pt_edge_t *e, ccd_vec3_t **a, ccd_vec3_t **b)
Definition: polytope.h:293
ccdPtEdgeVertices
_ccd_inline void ccdPtEdgeVertices(const ccd_pt_edge_t *e, ccd_pt_vertex_t **a, ccd_pt_vertex_t **b)
Definition: polytope.h:301
ccdPtDumpSVT
void ccdPtDumpSVT(ccd_pt_t *pt, const char *fn)
support.h
_ccd_pt_edge_t::vertex_list
ccd_list_t vertex_list[2]
List items in vertices' lists.
Definition: polytope.h:74
ccdPtDumpSVT2
void ccdPtDumpSVT2(ccd_pt_t *pt, FILE *)
_ccd_list_t
Definition: list.h:28
_ccd_pt_edge_t
Definition: polytope.h:68
_ccd_pt_el_t
Definition: polytope.h:45
_ccd_pt_face_t
Definition: polytope.h:81
_ccd_pt_t::nearest_type
int nearest_type
Definition: polytope.h:99
ccdListEmpty
_ccd_inline int ccdListEmpty(const ccd_list_t *head)
Definition: list.h:130
ccdPtEdgeFaces
_ccd_inline void ccdPtEdgeFaces(const ccd_pt_edge_t *e, ccd_pt_face_t **f1, ccd_pt_face_t **f2)
Definition: polytope.h:309
ccdPtDestroy
void ccdPtDestroy(ccd_pt_t *pt)
ccdPtDelEdge
_ccd_inline int ccdPtDelEdge(ccd_pt_t *pt, ccd_pt_edge_t *)
Definition: polytope.h:204
ccdListDel
_ccd_inline void ccdListDel(ccd_list_t *item)
Definition: list.h:143
ccdPtAddVertexCoords
_ccd_inline ccd_pt_vertex_t * ccdPtAddVertexCoords(ccd_pt_t *pt, ccd_real_t x, ccd_real_t y, ccd_real_t z)
Definition: polytope.h:179
ccdPtDelFace
_ccd_inline int ccdPtDelFace(ccd_pt_t *pt, ccd_pt_face_t *)
Definition: polytope.h:226
_ccd_pt_t::nearest_dist
ccd_real_t nearest_dist
Definition: polytope.h:98
ccdPtDelVertex
_ccd_inline int ccdPtDelVertex(ccd_pt_t *pt, ccd_pt_vertex_t *)
Definition: polytope.h:187
ccdPtAddVertex
ccd_pt_vertex_t * ccdPtAddVertex(ccd_pt_t *pt, const ccd_support_t *v)
_ccd_pt_vertex_t::v
ccd_support_t v
Definition: polytope.h:60
ccdPtFaceEdges
_ccd_inline void ccdPtFaceEdges(const ccd_pt_face_t *f, ccd_pt_edge_t **a, ccd_pt_edge_t **b, ccd_pt_edge_t **c)
Definition: polytope.h:283
_ccd_pt_t
Definition: polytope.h:92
list.h
std::tr1::f1
const T1 & f1
Definition: gtest-tuple.h:675
_ccd_pt_t::edges
ccd_list_t edges
List of edges.
Definition: polytope.h:94
_ccd_pt_edge_t::faces
struct _ccd_pt_face_t * faces[2]
Reference to faces.
Definition: polytope.h:72
ccdPtFaceVertices
_ccd_inline void ccdPtFaceVertices(const ccd_pt_face_t *face, ccd_pt_vertex_t **a, ccd_pt_vertex_t **b, ccd_pt_vertex_t **c)
Definition: polytope.h:267
ccdPtRecomputeDistances
void ccdPtRecomputeDistances(ccd_pt_t *pt)
_ccd_pt_t::vertices
ccd_list_t vertices
List of vertices.
Definition: polytope.h:93
_ccd_pt_edge_t::vertex
__CCD_PT_EL ccd_pt_vertex_t * vertex[2]
Reference to vertices.
Definition: polytope.h:71


fcl
Author(s):
autogenerated on Sat Sep 11 2021 02:37:42