r3d.h File Reference
#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]polyThe polyhedron over which to integrate.
[in]polyorderOrder of the polynomial density field. 0 for constant (1 moment), 1 for linear (4 moments), 2 for quadratic (10 moments), etc.
[in,out]momentsArray 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

typedef struct r3d_brep r3d_brep

create a type for the boundary representation

◆ 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()

void r3d_affine ( r3d_poly poly,
r3d_real  mat[4][4] 
)

Apply a general affine transformation to a polyhedron.

Parameters
[in,out]polyThe polyhedron to transform.
[in]matThe 4x4 homogeneous transformation matrix by which to transform the vertices of the polyhedron.

◆ r3d_box_faces_from_verts()

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.

Parameters
[out]facesArray of six planes defining the faces of the box.
[in]rboundsArray of two vectors defining the bounds of the axis-aligned box

◆ r3d_clip()

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).

Parameters
[in,out]polyThe polyehdron to be clipped.
[in]planesAn array of planes against which to clip this polyhedron.
[in]nplanesThe number of planes in the input array.

◆ r3d_free_brep()

void r3d_free_brep ( r3d_brep **  brep,
r3d_int  numcomponents 
)

Free all the memory associated with the boundary representation array.

Parameters
[in]brepPointer to an array of boundary representations.
[in]numcomponentsThe number of disconnected components in the boundary representation array.

◆ r3d_init_box()

void r3d_init_box ( r3d_poly poly,
r3d_rvec3 rbounds 
)

Initialize a polyhedron as an axis-aligned cube.

Parameters
[out]polyThe polyhedron to initialize.
[in]rboundsAn array of two vectors, giving the lower and upper corners of the box.

◆ r3d_init_brep()

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.

Parameters
[in]polyPointer to a single R3D polyhedron.
[out]brepPointer to an array of boundary representations that will hold the different boundary representations for the different components.
[out]numcomponentsPointer 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]polyThe polyhedron to initialize.
[in]verticesArray of length numverts giving the vertices of the input polyhedron.
[in]numvertsNumber of vertices in the input polyhedron.
[in]faceindsConnectivity array, giving the indices of vertices in the order they appear around each face of the input polyhedron.
[in]numvertsperfaceAn array of length numfaces giving the number of vertices for each face of the input polyhedron.
[in]numfacesNumber of faces in the input polyhedron.

◆ r3d_init_tet()

void r3d_init_tet ( r3d_poly poly,
r3d_rvec3 verts 
)

Initialize a polyhedron as a tetrahedron.

Parameters
[out]polyThe polyhedron to initialize.
[in]vertsAn array of four vectors, giving the vertices of the tetrahedron.

◆ r3d_is_good()

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.

Parameters
[in]polyThe polyhedron to check.
Returns
1 if the polyhedron is good, 0 if not.

◆ r3d_orient()

r3d_real r3d_orient ( r3d_rvec3 verts)

Get the signed volume of the tetrahedron defined by the input vertices.

Parameters
[in]vertsFour vertices defining a tetrahedron from which to calculate a volume.
Returns
The signed volume of the input tetrahedron.

◆ r3d_poly_center()

r3d_rvec3 r3d_poly_center ( r3d_poly poly)

Calculates a center of a polyhedron.

Parameters
[in]polyThe 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]facesArray of planes of length numfaces defining the faces of the polyhedron.
[in]verticesArray of length numverts giving the vertices of the input polyhedron.
[in]numvertsNumber of vertices in the input polyhedron.
[in]faceindsConnectivity array, giving the indices of vertices in the order they appear around each face of the input polyhedron.
[in]numvertsperfaceAn array of length numfaces giving the number of vertices for each face of the input polyhedron.
[in]numfacesNumber 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]polyThe polyhedron to print.

◆ r3d_print_brep()

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.

Parameters
[in]brepPointer to an array of boundary representations.
[in]numcomponentsThe number of disconnected components in the boundary representation array.

◆ r3d_reduce()

void r3d_reduce ( r3d_poly poly,
r3d_real moments,
r3d_int  polyorder 
)

◆ r3d_rotate()

void r3d_rotate ( r3d_poly poly,
r3d_real  theta,
r3d_int  axis 
)

Rotate a polyhedron about one axis.

Parameters
[in,out]polyThe polyehdron to rotate.
[in]thetaThe angle, in radians, by which to rotate the polyhedron.
[in]axisThe axis (0, 1, or 2 corresponding to x, y, or z) about which to rotate the polyhedron.

◆ r3d_scale()

void r3d_scale ( r3d_poly poly,
r3d_real  scale 
)

Scale a polyhedron.

Parameters
[in,out]polyThe polyhedron to scale.
[in]shiftThe factor by which to scale the polyhedron.

◆ r3d_shear()

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].

Parameters
[in,out]polyThe polyhedron to shear.
[in]shearThe factor by which to shear the polyhedron.
[in]axbThe axis (0, 1, or 2 corresponding to x, y, or z) along which to shear the polyhedron.
[in]axsThe axis (0, 1, or 2 corresponding to x, y, or z) across which to shear the polyhedron.

◆ r3d_shift_moments()

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.

Parameters
[in,out]momentsThe moments of the shifted polygon.
[in]polyorderOrder of the polygon.
[in]vcCoordinates 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]inpolysArray of input polyhedra to be split
[in]npolysThe number of input polyhedra
[in]planeThe plane about which to split the input polys
[out]out_posThe 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_negThe output array of fragments on the negitive side of the clip plane. Must be at least npolys long.

◆ r3d_tet_faces_from_verts()

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.

Parameters
[out]facesArray of four planes defining the faces of the tetrahedron.
[in]vertsArray of four vectors defining the vertices of the tetrahedron.

◆ r3d_translate()

void r3d_translate ( r3d_poly poly,
r3d_rvec3  shift 
)

Translate a polyhedron.

Parameters
[in,out]polyThe polyhedron to translate.
[in]shiftThe vector by which to translate the polyhedron.