r3d.h
Go to the documentation of this file.
1 /**************************************************************
2  *
3  * r3d.h
4  *
5  * Devon Powell
6  * 8 February 2015
7  *
8  * Routines for fast, geometrically robust clipping operations
9  * and analytic volume/moment computations over convex
10  * polyhedra in 3D. Includes a wrapper function for
11  * physically conservative voxelization (volume sampling)
12  * of tetrahedra to a Cartesian grid.
13  *
14  * Copyright (C) 2014 Stanford University.
15  * See License.txt for more information.
16  *
17  *************************************************************/
18 
19 #ifndef _R3D_H_
20 #define _R3D_H_
21 
22 #include <stdint.h>
23 
37 #ifdef SINGLE_PRECISION
38 typedef float r3d_real;
39 #else
40 typedef double r3d_real;
41 #endif
42 
46 typedef int32_t r3d_int;
47 
51 typedef int64_t r3d_long;
52 
56 typedef struct {
58  y,
59  z;
60 } r3d_rvec3;
61 
65 typedef struct {
66  r3d_int i,
67  j,
68  k;
69 } r3d_dvec3;
70 
74 typedef struct {
77 } r3d_plane;
78 
82 typedef struct {
83  r3d_real fdist[4];
84  unsigned char fflags;
86 
90 typedef struct {
92  unsigned char pnbrs[3];
94 } r3d_vertex;
95 
99 typedef struct {
100 #define R3D_MAX_VERTS 64
104 } r3d_poly;
105 
109 typedef struct {
110  r3d_real* moments[10];
119 } r3d_dest_grid;
120 
124 const static r3d_int r3d_num_moments[3] = {1, 4, 10};
125 
137 void r3d_voxelize_tet(r3d_plane* faces, r3d_dest_grid* grid);
138 
139 
152 void r3d_clip_tet(r3d_poly* poly, unsigned char andcmp);
153 
154 
170 void r3d_reduce(r3d_poly* poly, r3d_int polyorder, r3d_real* moments);
171 
182 void r3du_init_box(r3d_poly* poly, r3d_rvec3 rbounds[2]);
183 
184 
196 void r3du_tet_faces_from_verts(r3d_rvec3* verts, r3d_plane* faces);
197 
198 
210 
211 #endif // _R3D_H_
Perpendicular distances and bit flags for up to 6 faces.
Definition: r3d.h:82
r3d_rvec3 d
Definition: r3d.h:118
r3d_real d
Definition: r3d.h:76
r3d_rvec3 n
Definition: r3d.h:75
void r3du_tet_faces_from_verts(r3d_rvec3 *verts, r3d_plane *faces)
Get four faces (unit normals and distances to the origin) i from a four-vertex description of a tetra...
Integer vector struct for grid indexing.
Definition: r3d.h:65
r3d_int polyorder
Definition: r3d.h:112
r3d_int k
Definition: r3d.h:66
void r3du_init_box(r3d_poly *poly, r3d_rvec3 rbounds[2])
Initialize a polyhedron as an axis-aligned cube.
r3d_int funclip
Definition: r3d.h:103
void r3d_reduce(r3d_poly *poly, r3d_int polyorder, r3d_real *moments)
Integrate a polynomial density over a convex polyhedron using simplicial decomposition.
r3d_real r3du_orient(r3d_rvec3 pa, r3d_rvec3 pb, r3d_rvec3 pc, r3d_rvec3 pd)
Get the signed volume of the tetrahedron defined by the input vertices.
r3d_orientation orient
Definition: r3d.h:93
Vector struct.
Definition: r3d.h:56
r3d_real z
Definition: r3d.h:57
void r3d_clip_tet(r3d_poly *poly, unsigned char andcmp)
Clip a polyhedron against four clip planes (find its intersection with a tetrahedron).
Destination grid information.
Definition: r3d.h:109
unsigned char fflags
Definition: r3d.h:84
A plane.
Definition: r3d.h:74
r3d_int nverts
Definition: r3d.h:102
r3d_long bufsz
Definition: r3d.h:116
int32_t r3d_int
Integer type used for grid indexing and bit flags.
Definition: r3d.h:46
A polyhedron.
Definition: r3d.h:99
#define R3D_MAX_VERTS
Definition: r3d.h:100
r3d_orientation * orient
Definition: r3d.h:113
r3d_rvec3 pos
Definition: r3d.h:91
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_voxelize_tet(r3d_plane *faces, r3d_dest_grid *grid)
Voxelize a tetrahedron to the destination grid.
double r3d_real
Real type specifying the precision to be used in calculations.
Definition: r3d.h:40
r3d_dvec3 n
Definition: r3d.h:117