#include <stdint.h>
#include <stdlib.h>
Go to the source code of this file.
Classes | |
struct | r3d_rvec3 |
Vector struct. More... | |
struct | r3d_dvec3 |
Integer vector struct for grid indexing. More... | |
struct | r3d_plane |
A plane. More... | |
struct | r3d_vertex |
A doubly-linked vertex. More... | |
struct | r3d_poly |
A polyhedron. More... | |
struct | r3d_brep |
Macros | |
#define | R3D_MAX_VERTS 512 |
#define | R3D_NUM_MOMENTS(order) ((order + 1) * (order + 2) * (order + 3) / 6) |
Integrate a polynomial density over a polyhedron using simplicial decomposition. Uses the fast recursive method of Koehl (2012) to carry out the integration. More... | |
Typedefs | |
typedef double | r3d_real |
Real type specifying the precision to be used in calculations. More... | |
typedef int32_t | r3d_int |
Integer types used for indexing. More... | |
typedef int64_t | r3d_long |
typedef struct r3d_brep | r3d_brep |
Functions | |
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 half-spaces). More... | |
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. More... | |
void | r3d_reduce (r3d_poly *poly, r3d_real *moments, r3d_int polyorder) |
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 by three other vertices, and that there are no sets of two vertices with more than one edge between them. Overall, checks that the graph is 3-vertex-connected (an O(nverts^2) operation), which is required by Steinitz' theorem to be a valid polyhedral graph. More... | |
r3d_rvec3 | r3d_poly_center (r3d_poly *poly) |
Calculates a center of a polyhedron. More... | |
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. More... | |
r3d_real | r3d_orient (r3d_rvec3 *verts) |
Get the signed volume of the tetrahedron defined by the input vertices. More... | |
void | r3d_print (r3d_poly *poly) |
Prints the vertices and connectivity of a polyhedron. For debugging. More... | |
void | r3d_rotate (r3d_poly *poly, r3d_real theta, r3d_int axis) |
Rotate a polyhedron about one axis. More... | |
void | r3d_translate (r3d_poly *poly, r3d_rvec3 shift) |
Translate a polyhedron. More... | |
void | r3d_scale (r3d_poly *poly, r3d_real scale) |
Scale a polyhedron. More... | |
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] . More... | |
void | r3d_affine (r3d_poly *poly, r3d_real mat[4][4]) |
Apply a general affine transformation to a polyhedron. More... | |
void | r3d_init_tet (r3d_poly *poly, r3d_rvec3 *verts) |
Initialize a polyhedron as a tetrahedron. More... | |
void | r3d_init_box (r3d_poly *poly, r3d_rvec3 *rbounds) |
Initialize a polyhedron as an axis-aligned cube. More... | |
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 the output is valid. More... | |
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 tetrahedron. More... | |
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-aligned box. More... | |
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 polyhedron. More... | |
void | r3d_init_brep (r3d_poly *poly, r3d_brep **brep, r3d_int *numcomponents) |
Convert from R3D's internal vertex-edge format to the boundary representation. More... | |
void | r3d_print_brep (r3d_brep **brep, r3d_int numcomponents) |
Prints the boundary representation of an array of polyhedons given in boundary representation form. For debugging. More... | |
void | r3d_free_brep (r3d_brep **brep, r3d_int numcomponents) |
Free all the memory associated with the boundary representation array. More... | |
Macro Definition Documentation
◆ R3D_MAX_VERTS
#define R3D_MAX_VERTS 512 |
◆ R3D_NUM_MOMENTS
#define R3D_NUM_MOMENTS | ( | order | ) | ((order + 1) * (order + 2) * (order + 3) / 6) |
Integrate a polynomial density over a polyhedron using simplicial decomposition. Uses the fast recursive method of Koehl (2012) to carry out the integration.
- Parameters
-
[in] poly The polyhedron over which to integrate. [in] polyorder Order of the polynomial density field. 0 for constant (1 moment), 1 for linear (4 moments), 2 for quadratic (10 moments), etc. [in,out] moments Array to be filled with the integration results, up to the specified polyorder
. Must be at least(polyorder+1)*(polyorder+2)*(polyorder+3)/6
long. A conventient macro,R3D_NUM_MOMENTS()
is provided to compute the number of moments for a given order. Order of moments is row-major, i.e.1
,x
,y
,z
,x^2
,x*y
,x*z
,y^2
,y*z
,z^2
,x^3
,x^2*y
...
Typedef Documentation
◆ r3d_brep
◆ r3d_int
typedef int32_t r3d_int |
Integer types used for indexing.
◆ r3d_long
typedef int64_t r3d_long |
◆ r3d_real
typedef double r3d_real |
Real type specifying the precision to be used in calculations.
Default is double
. float
precision is enabled by compiling with -DSINGLE_PRECISION
.
Function Documentation
◆ r3d_affine()
Apply a general affine transformation to a polyhedron.
- Parameters
-
[in,out] poly The polyhedron to transform. [in] mat The 4x4 homogeneous transformation matrix by which to transform the vertices of the polyhedron.
◆ r3d_box_faces_from_verts()
Get six faces (unit normals and distances to the origin) from a two-vertex description of an axis-aligned box.
- Parameters
-
[out] faces Array of six planes defining the faces of the box. [in] rbounds Array of two vectors defining the bounds of the axis-aligned box
◆ r3d_clip()
Clip a polyhedron against an arbitrary number of clip planes (find its intersection with a set of half-spaces).
- Parameters
-
[in,out] poly The polyehdron to be clipped. [in] planes An array of planes against which to clip this polyhedron. [in] nplanes The number of planes in the input array.
◆ r3d_free_brep()
Free all the memory associated with the boundary representation array.
- Parameters
-
[in] brep Pointer to an array of boundary representations. [in] numcomponents The number of disconnected components in the boundary representation array.
◆ r3d_init_box()
Initialize a polyhedron as an axis-aligned cube.
- Parameters
-
[out] poly The polyhedron to initialize. [in] rbounds An array of two vectors, giving the lower and upper corners of the box.
◆ r3d_init_brep()
Convert from R3D's internal vertex-edge format to the boundary representation.
- Parameters
-
[in] poly Pointer to a single R3D polyhedron. [out] brep Pointer to an array of boundary representations that will hold the different boundary representations for the different components. [out] numcomponents Pointer to an integer that will hold the number of determined components.
◆ r3d_init_poly()
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 the output is valid.
- Parameters
-
[out] poly The polyhedron to initialize. [in] vertices Array of length numverts
giving the vertices of the input polyhedron.[in] numverts Number of vertices in the input polyhedron. [in] faceinds Connectivity array, giving the indices of vertices in the order they appear around each face of the input polyhedron. [in] numvertsperface An array of length numfaces
giving the number of vertices for each face of the input polyhedron.[in] numfaces Number of faces in the input polyhedron.
◆ r3d_init_tet()
Initialize a polyhedron as a tetrahedron.
- Parameters
-
[out] poly The polyhedron to initialize. [in] verts An array of four vectors, giving the vertices of the tetrahedron.
◆ r3d_is_good()
Checks a polyhedron to see if all vertices have three valid edges, that all vertices are pointed to by three other vertices, and that there are no sets of two vertices with more than one edge between them. Overall, checks that the graph is 3-vertex-connected (an O(nverts^2)
operation), which is required by Steinitz' theorem to be a valid polyhedral graph.
- Parameters
-
[in] poly The polyhedron to check.
- Returns
- 1 if the polyhedron is good, 0 if not.
◆ r3d_orient()
Get the signed volume of the tetrahedron defined by the input vertices.
- Parameters
-
[in] verts Four vertices defining a tetrahedron from which to calculate a volume.
- Returns
- The signed volume of the input tetrahedron.
◆ r3d_poly_center()
Calculates a center of a polyhedron.
- Parameters
-
[in] poly The polygon to check.
- Returns
- coordinates of a polygon center.
◆ r3d_poly_faces_from_verts()
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 polyhedron.
- Parameters
-
[out] faces Array of planes of length numfaces
defining the faces of the polyhedron.[in] vertices Array of length numverts
giving the vertices of the input polyhedron.[in] numverts Number of vertices in the input polyhedron. [in] faceinds Connectivity array, giving the indices of vertices in the order they appear around each face of the input polyhedron. [in] numvertsperface An array of length numfaces
giving the number of vertices for each face of the input polyhedron.[in] numfaces Number of faces in the input polyhedron.
◆ r3d_print()
void r3d_print | ( | r3d_poly * | poly | ) |
Prints the vertices and connectivity of a polyhedron. For debugging.
- Parameters
-
[in] poly The polyhedron to print.
◆ r3d_print_brep()
Prints the boundary representation of an array of polyhedons given in boundary representation form. For debugging.
- Parameters
-
[in] brep Pointer to an array of boundary representations. [in] numcomponents The number of disconnected components in the boundary representation array.
◆ r3d_reduce()
◆ r3d_rotate()
Rotate a polyhedron about one axis.
- Parameters
-
[in,out] poly The polyehdron to rotate. [in] theta The angle, in radians, by which to rotate the polyhedron. [in] axis The axis (0, 1, or 2 corresponding to x, y, or z) about which to rotate the polyhedron.
◆ r3d_scale()
Scale a polyhedron.
- Parameters
-
[in,out] poly The polyhedron to scale. [in] shift The factor by which to scale the polyhedron.
◆ r3d_shear()
Shear a polyhedron. Each vertex undergoes the transformation pos.xyz[axb] += shear*pos.xyz[axs]
.
- Parameters
-
[in,out] poly The polyhedron to shear. [in] shear The factor by which to shear the polyhedron. [in] axb The axis (0, 1, or 2 corresponding to x, y, or z) along which to shear the polyhedron. [in] axs The axis (0, 1, or 2 corresponding to x, y, or z) across which to shear the polyhedron.
◆ r3d_shift_moments()
Adjust moments according to the shift of polyhedron vertices to the origin.
- Parameters
-
[in,out] moments The moments of the shifted polygon. [in] polyorder Order of the polygon. [in] vc Coordinates of the polygon center, which are used to shift the polygon.
◆ r3d_split()
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.
- Parameters
-
[in] inpolys Array of input polyhedra to be split [in] npolys The number of input polyhedra [in] plane The plane about which to split the input polys [out] out_pos The output array of fragments on the positive side of the clip plane. Must be at least npolys long. out_pos[i] and out_neg[i] correspond to inpolys[i], where out_neg[i].nverts or out.pos[i].nverts are set to zero if the poly lies entirely in the positive or negative side of the plane, respectively. [out] out_neg The output array of fragments on the negitive side of the clip plane. Must be at least npolys long.
◆ r3d_tet_faces_from_verts()
Get four faces (unit normals and distances to the origin) from a four-vertex description of a tetrahedron.
- Parameters
-
[out] faces Array of four planes defining the faces of the tetrahedron. [in] verts Array of four vectors defining the vertices of the tetrahedron.