r2d.h
Go to the documentation of this file.
1 /**************************************************************
2  *
3  * r2d.h
4  *
5  * Devon Powell
6  * 8 February 2015
7  *
8  * Routines for fast, geometrically robust clipping operations
9  * and analytic area/moment computations over convex
10  * polygons in 2D. Includes a wrapper function for
11  * physically conservative rasterization (area sampling)
12  * of quadrilaterals to a Cartesian grid.
13  *
14  * Copyright (C) 2014 Stanford University.
15  * See License.txt for more information.
16  *
17  *************************************************************/
18 
19 #ifndef _R2D_H_
20 #define _R2D_H_
21 
22 #include <stdint.h>
23 
37 #ifdef SINGLE_PRECISION
38 typedef float r2d_real;
39 #else
40 typedef double r2d_real;
41 #endif
42 
46 typedef int32_t r2d_int;
47 
51 typedef int64_t r2d_long;
52 
56 typedef struct {
58  y;
59 } r2d_rvec2;
60 
64 typedef struct {
65  r2d_int i,
66  j;
67 } r2d_dvec2;
68 
72 typedef struct {
75 } r2d_plane;
76 
80 typedef struct {
81  r2d_real fdist[4];
82  unsigned char fflags;
84 
88 typedef struct {
90  unsigned char pnbrs[2];
92 } r2d_vertex;
93 
97 typedef struct {
98 #define R2D_MAX_VERTS 64
102 } r2d_poly;
103 
107 typedef struct {
108  r2d_real* moments[6];
117 } r2d_dest_grid;
118 
122 const static r2d_int r2d_num_moments[3] = {1, 3, 6};
123 
124 
136 void r2d_rasterize_quad(r2d_plane* faces, r2d_dest_grid* grid);
137 
150 void r2d_clip_quad(r2d_poly* poly, unsigned char andcmp);
151 
152 
168 void r2d_reduce(r2d_poly* poly, r2d_int polyorder, r2d_real* moments);
169 
170 
181 void r2du_init_box(r2d_poly* poly, r2d_rvec2 rbounds[2]);
182 
183 
198 void r2du_faces_from_verts(r2d_rvec2* verts, r2d_int nverts, r2d_plane* faces);
199 
211 
212 
213 #endif // _R2D_H_
Perpendicular distances and bit flags for up to 6 faces.
Definition: r2d.h:80
r2d_real r2du_orient(r2d_rvec2 pa, r2d_rvec2 pb, r2d_rvec2 pc)
Get the signed area of the triangle defined by the input vertices.
Destination grid information.
Definition: r2d.h:107
int64_t r2d_long
Long integer type used for grid indexing.
Definition: r2d.h:51
r2d_orientation * orient
Definition: r2d.h:111
r2d_rvec2 n
Definition: r2d.h:73
r2d_dvec2 n
Definition: r2d.h:115
A polygon.
Definition: r2d.h:97
r2d_int polyorder
Definition: r2d.h:110
r2d_int funclip
Definition: r2d.h:101
void r2d_reduce(r2d_poly *poly, r2d_int polyorder, r2d_real *moments)
Integrate a polynomial density over a polygon using simplicial decomposition.
void r2du_faces_from_verts(r2d_rvec2 *verts, r2d_int nverts, r2d_plane *faces)
Get faces (unit normals and distances to the origin) from an ordered-vertex description of a convex p...
r2d_rvec2 d
Definition: r2d.h:116
r2d_int j
Definition: r2d.h:65
r2d_real d
Definition: r2d.h:74
r2d_int nverts
Definition: r2d.h:100
r2d_rvec2 pos
Definition: r2d.h:89
void r2du_init_box(r2d_poly *poly, r2d_rvec2 rbounds[2])
Initialize a polygon as an axis-aligned box.
Integer vector struct for grid indexing.
Definition: r2d.h:64
#define R2D_MAX_VERTS
Definition: r2d.h:98
r2d_long bufsz
Definition: r2d.h:114
void r2d_clip_quad(r2d_poly *poly, unsigned char andcmp)
Clip a polygon against four clip planes (find its intersection with a quadrilateral).
r2d_orientation orient
Definition: r2d.h:91
A plane.
Definition: r2d.h:72
unsigned char fflags
Definition: r2d.h:82
Vector struct.
Definition: r2d.h:56
void r2d_rasterize_quad(r2d_plane *faces, r2d_dest_grid *grid)
Rasterize a convex quadrilateral to the destination grid.
A doubly-linked vertex.
Definition: r2d.h:88
double r2d_real
Real type specifying the precision to be used in calculations.
Definition: r2d.h:40
r2d_real y
Definition: r2d.h:57
int32_t r2d_int
Integer type used for grid indexing and bit flags.
Definition: r2d.h:46