rNd.h
Go to the documentation of this file.
1 /*
2  *
3  * rNd.h
4  *
5  * Routines for fast, geometrically robust clipping operations
6  * and analytic volume/moment computations over
7  * polytopes of arbitrary dimensionality.
8  *
9  * Devon Powell
10  * 31 August 2015
11  *
12  * This program was prepared by Los Alamos National Security, LLC at Los Alamos National
13  * Laboratory (LANL) under contract No. DE-AC52-06NA25396 with the U.S. Department of Energy (DOE).
14  * All rights in the program are reserved by the DOE and Los Alamos National Security, LLC.
15  * Permission is granted to the public to copy and use this software without charge, provided that
16  * this Notice and any statement of authorship are reproduced on all copies. Neither the U.S.
17  * Government nor LANS makes any warranty, express or implied, or assumes any liability
18  * or responsibility for the use of this software.
19  *
20  */
21 
22 #ifndef _RND_H_
23 #define _RND_H_
24 
25 #ifdef __cplusplus
26 extern "C" {
27 #endif
28 
29 #include <stdint.h>
30 
38 /*
39  * \brief Dimensionality of the geometric calculations.
40  */
41 #define RND_DIM 4
42 
49 #ifdef SINGLE_PRECISION
50 typedef float rNd_real;
51 #else
52 typedef double rNd_real;
53 #endif
54 
58 typedef int32_t rNd_int;
59 typedef int64_t rNd_long;
60 
64 typedef struct {
65  rNd_real xyz[RND_DIM];
66 } rNd_rvec;
67 
71 typedef struct {
72  rNd_int ijk[RND_DIM];
73 } rNd_dvec;
74 
78 typedef struct {
80  rNd_real d;
81 } rNd_plane;
82 
86 typedef struct {
87  rNd_int pnbrs[RND_DIM];
88  rNd_int finds[RND_DIM][RND_DIM];
90 } rNd_vertex;
91 
95 typedef struct {
96 #define RND_MAX_VERTS 1024
98  rNd_int nverts, nfaces;
99 } rNd_poly;
100 
114 void rNd_clip(rNd_poly* poly, rNd_plane* planes, rNd_int nplanes);
115 
131 //#define RND_NUM_MOMENTS(order) ((order+1)*(order+2)*(order+3)/6)
132 void rNd_reduce(rNd_poly* poly, rNd_real* moments, rNd_int polyorder);
133 
145 rNd_int rNd_is_good(rNd_poly* poly);
146 
157 rNd_real rNd_orient(rNd_rvec verts[RND_DIM+1]);
158 
166 void rNd_print(rNd_poly* poly);
167 
184 void rNd_rotate(rNd_poly* poly, rNd_real theta, rNd_int ax1, rNd_int ax2);
185 
196 void rNd_translate(rNd_poly* poly, rNd_rvec shift);
197 
208 void rNd_scale(rNd_poly* poly, rNd_rvec scale);
209 
227 void rNd_shear(rNd_poly* poly, rNd_real shear, rNd_int axb, rNd_int axs);
228 
239 void rNd_affine(rNd_poly* poly, rNd_real mat[RND_DIM+1][RND_DIM+1]);
240 
251 void rNd_init_simplex(rNd_poly* poly, rNd_rvec verts[RND_DIM+1]);
252 
263 void rNd_init_box(rNd_poly* poly, rNd_rvec rbounds[2]);
264 
276 //void rNd_simplex_faces_from_verts(rNd_plane* faces, rNd_rvec3* verts);
277 
289 //void rNd_box_faces_from_verts(rNd_plane* faces, rNd_rvec3* rbounds);
290 
291 #ifdef __cplusplus
292 }
293 #endif
294 
295 #endif // _RND_H_
#define RND_MAX_VERTS
Definition: rNd.h:96
rNd_rvec pos
Definition: rNd.h:89
rNd_int rNd_is_good(rNd_poly *poly)
Checks a polytope to see if it is a valid RND_DIM-polyhedral graph, by testing compliance with Balins...
double rNd_real
Real type specifying the precision to be used in calculations.
Definition: rNd.h:52
rNd_int nverts
Definition: rNd.h:98
A N-vector.
Definition: rNd.h:64
int64_t rNd_long
Definition: rNd.h:59
void rNd_scale(rNd_poly *poly, rNd_rvec scale)
Scale a polytope.
void rNd_clip(rNd_poly *poly, rNd_plane *planes, rNd_int nplanes)
Clip a polytope against an arbitrary number of hyperplanes (find its intersection with a set of half-...
rNd_rvec n
Definition: rNd.h:79
void rNd_affine(rNd_poly *poly, rNd_real mat[RND_DIM+1][RND_DIM+1])
Apply a general affine transformation to a polytope.
void rNd_print(rNd_poly *poly)
Prints the vertices and connectivity of a polytope. For debugging.
A hyperplane.
Definition: rNd.h:78
int32_t rNd_int
Integer type used for indexing.
Definition: rNd.h:58
rNd_real d
Definition: rNd.h:80
void rNd_init_box(rNd_poly *poly, rNd_rvec rbounds[2])
Initialize a polytope as an axis-aligned hyperrectangle.
void rNd_init_simplex(rNd_poly *poly, rNd_rvec verts[RND_DIM+1])
Initialize a polytope as an RND_DIM-simplex.
An RND_DIM-dimensional polytope.
Definition: rNd.h:95
void rNd_reduce(rNd_poly *poly, rNd_real *moments, rNd_int polyorder)
Integrate a polynomial density over a polytope. Still under development.
#define RND_DIM
Definition: rNd.h:41
void rNd_translate(rNd_poly *poly, rNd_rvec shift)
Translate a polytope.
rNd_real rNd_orient(rNd_rvec verts[RND_DIM+1])
Get the signed volume of the RND_DIM-simplex defined by the input vertices.
void rNd_rotate(rNd_poly *poly, rNd_real theta, rNd_int ax1, rNd_int ax2)
Rotate a polytope about one axis.
An integer N-vector for grid indexing.
Definition: rNd.h:71
void rNd_shear(rNd_poly *poly, rNd_real shear, rNd_int axb, rNd_int axs)
Shear a polytope. Each vertex undergoes the transformation pos.xyz[axb] += shear*pos.xyz[axs].
A doubly-linked vertex.
Definition: rNd.h:86