r3d.h
Go to the documentation of this file.
1 /*
2  *
3  * r3d.h
4  *
5  * Routines for fast, geometrically robust clipping operations and analytic
6  * volume/moment computations over polyhedra in 3D.
7  *
8  * Devon Powell 31 August 2015
9  *
10  * This program was prepared by Los Alamos National Security, LLC at Los
11  * Alamos National Laboratory (LANL) under contract No. DE-AC52-06NA25396
12  * with the U.S. Department of Energy (DOE). All rights in the program are
13  * reserved by the DOE and Los Alamos National Security, LLC. Permission is
14  * granted to the public to copy and use this software without charge,
15  * provided that this Notice and any statement of authorship are reproduced
16  * on all copies. Neither the U.S. Government nor LANS makes any warranty,
17  * express or implied, or assumes any liability or responsibility for the use
18  * of this software.
19  *
20  */
21 
22 #ifndef _R3D_H_
23 #define _R3D_H_
24 
25 #include <stdint.h>
26 #include <stdlib.h>
27 
39 #ifdef SINGLE_PRECISION
40 typedef float r3d_real;
41 #else
42 typedef double r3d_real;
43 #endif
44 
48 typedef int32_t r3d_int;
49 typedef int64_t r3d_long;
50 
53 typedef union {
54  struct
55  {
56  r3d_real x,
57  y,
58  z;
59  };
60  r3d_real xyz[3];
61 } r3d_rvec3;
62 
65 typedef union {
66  struct
67  {
68  r3d_int i,
69  j,
70  k;
71  };
72  r3d_int ijk[3];
73 } r3d_dvec3;
74 
77 typedef struct
78 {
79  r3d_rvec3 n;
80  r3d_real d;
81 } r3d_plane;
82 
85 typedef struct
86 {
87  r3d_int pnbrs[3];
88  r3d_rvec3 pos;
89 } r3d_vertex;
90 
94 typedef struct
95 {
96 #define R3D_MAX_VERTS 512
97  r3d_vertex verts[R3D_MAX_VERTS];
98  r3d_int nverts;
99 } r3d_poly;
100 
112 void r3d_clip(r3d_poly *poly, r3d_plane *planes, r3d_int nplanes);
113 
134 void r3d_split(r3d_poly *inpolys, r3d_int npolys, r3d_plane plane,
135  r3d_poly *out_pos, r3d_poly *out_neg);
136 
155 #define R3D_NUM_MOMENTS(order) ((order + 1) * (order + 2) * (order + 3) / 6)
156 void r3d_reduce(r3d_poly *poly, r3d_real *moments, r3d_int polyorder);
157 
171 
183 
197 void r3d_shift_moments(r3d_real* moments, r3d_int polyorder, r3d_rvec3 vc);
198 
210 
217 void r3d_print(r3d_poly *poly);
218 
230 void r3d_rotate(r3d_poly *poly, r3d_real theta, r3d_int axis);
231 
240 void r3d_translate(r3d_poly *poly, r3d_rvec3 shift);
241 
250 void r3d_scale(r3d_poly *poly, r3d_real scale);
251 
267 void r3d_shear(r3d_poly *poly, r3d_real shear, r3d_int axb, r3d_int axs);
268 
278 void r3d_affine(r3d_poly *poly, r3d_real mat[4][4]);
279 
289 void r3d_init_tet(r3d_poly *poly, r3d_rvec3 *verts);
290 
300 void r3d_init_box(r3d_poly *poly, r3d_rvec3 *rbounds);
301 
322 void r3d_init_poly(r3d_poly *poly, r3d_rvec3 *vertices, r3d_int numverts,
323  r3d_int **faceinds, r3d_int *numvertsperface,
324  r3d_int numfaces);
325 
337 void r3d_tet_faces_from_verts(r3d_plane *faces, r3d_rvec3 *verts);
338 
349 void r3d_box_faces_from_verts(r3d_plane *faces, r3d_rvec3 *rbounds);
350 
372 void r3d_poly_faces_from_verts(r3d_plane *faces, r3d_rvec3 *vertices,
373  r3d_int numverts, r3d_int **faceinds,
374  r3d_int *numvertsperface, r3d_int numfaces);
375 
379 typedef struct r3d_brep
380 {
386 } r3d_brep;
387 
401 void r3d_init_brep(r3d_poly *poly, r3d_brep **brep, r3d_int *numcomponents);
402 
403 
414 void r3d_print_brep(r3d_brep **brep, r3d_int numcomponents);
415 
425 void r3d_free_brep(r3d_brep **brep, r3d_int numcomponents);
426 
427 #endif // _R3D_H_
void r3d_tet_faces_from_verts(r3d_plane *faces, r3d_rvec3 *verts)
Get four faces (unit normals and distances to the origin) from a four-vertex description of a tetrahe...
r3d_int numfaces
Definition: r3d.h:385
Definition: r3d.h:379
void r3d_free_brep(r3d_brep **brep, r3d_int numcomponents)
Free all the memory associated with the boundary representation array.
void r3d_clip(r3d_poly *poly, r3d_plane *planes, r3d_int nplanes)
Clip a polyhedron against an arbitrary number of clip planes (find its intersection with a set of hal...
void r3d_init_poly(r3d_poly *poly, r3d_rvec3 *vertices, r3d_int numverts, r3d_int **faceinds, r3d_int *numvertsperface, r3d_int numfaces)
Initialize a general polyhedron from a full boundary description. Can use r3d_is_good to check that t...
#define R3D_MAX_VERTS
Definition: r3d.h:96
struct r3d_brep r3d_brep
void r3d_translate(r3d_poly *poly, r3d_rvec3 shift)
Translate a polyhedron.
Integer vector struct for grid indexing.
Definition: r3d.h:65
r3d_rvec3 r3d_poly_center(r3d_poly *poly)
Calculates a center of a polyhedron.
void r3d_scale(r3d_poly *poly, r3d_real scale)
Scale a polyhedron.
void r3d_init_brep(r3d_poly *poly, r3d_brep **brep, r3d_int *numcomponents)
Convert from R3D&#39;s internal vertex-edge format to the boundary representation.
void r3d_shift_moments(r3d_real *moments, r3d_int polyorder, r3d_rvec3 vc)
Adjust moments according to the shift of polyhedron vertices to the origin.
void r3d_box_faces_from_verts(r3d_plane *faces, r3d_rvec3 *rbounds)
Get six faces (unit normals and distances to the origin) from a two-vertex description of an axis-ali...
void r3d_reduce(r3d_poly *poly, r3d_int polyorder, r3d_real *moments)
Integrate a polynomial density over a convex polyhedron using simplicial decomposition.
r3d_int * numvertsperface
Definition: r3d.h:384
r3d_int r3d_is_good(r3d_poly *poly)
Checks a polyhedron to see if all vertices have three valid edges, that all vertices are pointed to b...
r3d_rvec3 * vertices
Definition: r3d.h:381
Vector struct.
Definition: r3d.h:56
void r3d_init_box(r3d_poly *poly, r3d_rvec3 *rbounds)
Initialize a polyhedron as an axis-aligned cube.
r3d_int numvertices
Definition: r3d.h:382
void r3d_init_tet(r3d_poly *poly, r3d_rvec3 *verts)
Initialize a polyhedron as a tetrahedron.
r3d_real r3d_orient(r3d_rvec3 *verts)
Get the signed volume of the tetrahedron defined by the input vertices.
r3d_int ** faceinds
Definition: r3d.h:383
A plane.
Definition: r3d.h:74
void r3d_poly_faces_from_verts(r3d_plane *faces, r3d_rvec3 *vertices, r3d_int numverts, r3d_int **faceinds, r3d_int *numvertsperface, r3d_int numfaces)
Get all faces (unit normals and distances to the origin) from a full boundary description of a polyhe...
int32_t r3d_int
Integer type used for grid indexing and bit flags.
Definition: r3d.h:46
void r3d_shear(r3d_poly *poly, r3d_real shear, r3d_int axb, r3d_int axs)
Shear a polyhedron. Each vertex undergoes the transformation pos.xyz[axb] += shear*pos.xyz[axs].
void r3d_affine(r3d_poly *poly, r3d_real mat[4][4])
Apply a general affine transformation to a polyhedron.
A polyhedron.
Definition: r3d.h:99
void r3d_rotate(r3d_poly *poly, r3d_real theta, r3d_int axis)
Rotate a polyhedron about one axis.
A doubly-linked vertex.
Definition: r3d.h:90
int64_t r3d_long
Long integer type used for grid indexing.
Definition: r3d.h:51
void r3d_print_brep(r3d_brep **brep, r3d_int numcomponents)
Prints the boundary representation of an array of polyhedons given in boundary representation form...
double r3d_real
Real type specifying the precision to be used in calculations.
Definition: r3d.h:40
void r3d_split(r3d_poly *inpolys, r3d_int npolys, r3d_plane plane, r3d_poly *out_pos, r3d_poly *out_neg)
Splits a list of polyhedra across a single plane.
void r3d_print(r3d_poly *poly)
Prints the vertices and connectivity of a polyhedron. For debugging.