/* General-purpose geometric models. */ /* Last edited on 2020-10-03 20:34:19 by jstolfi */ #ifndef gmo_H #define gmo_H #include #include #include #include #include /* A geometric model {gmo_t} is the union of solid /items/. Each item is described by one or more /knots/. Each knot has a point, a radius, a a tangent plane, and an /opto/ (an object that defines its optical properties; basically a BRDF). */ typedef enum { gmo_item_kind_DOT = 0, gmo_item_kind_SLUG = 1, gmo_item_kind_TRI = 2, gmo_item_kind_COUNT = 3 } gmo_item_kind_t; /* King of a plottable item in a geometric model. See {gmo_{xxx}_t} for a description of items with kind {gmo_item_kind_{XXX}}. The kind {gmo_item_kind_COUNT} is not a valid kind, only the limit for {for} loops and such. */ typedef void *gmo_item_addr_t; /* Pointer to a plottable item; actually to a {gmo_dot_t}, {gmo_slug_t}, or {gmo_tri_t}. */ typedef struct gmo_t { int npoints; /* Number of points. */ hr3_point_t *point; /* {point[0..npoints-1]} are homog coords of key points. */ int nplanes; /* Number of planes. */ hr3_plane_t *plane; /* {plane[0..nplanes-1]} are homog coeffs of key planes. */ int noptos; /* Number of optos. */ gmo_opto_t *opto; /* Opto list. */ int nknots; /* Number of knots. */ struct gmo_knot_t *knot; /* Knot list. */ int nitems; /* Number of plottable items. */ gmo_item_kind_t *iknd; /* {kind[0..nitems-1]} are the item types. */ gmo_item_addr_t *item; /* {item[0..nitems-1]} are the addresses of the items. */ } gmo_t; typedef int gmo_knot_ix_t; typedef int gmo_point_ix_t; typedef int gmo_plane_ix_t; typedef int gmo_color_ix_t; typedef int gmo_opto_ix_t; typedef int gmo_item_ix_t; /* Indices into {knot}, {point}, {plane}, {color}, {opto}, and {item} tables of a {gmo_t} model. */ /* KNOTS */ typedef struct gmo_knot_t { gmo_point_ix_t pt; /* Position (index into {point} list) or -1 if none. */ gmo_point_ix_t tp; /* Tangent plane (index into {plane} list) or -1 if none. */ gmo_opto_ix_t opto; /* Optical operator (index into {opto} list). */ float radius; /* Radius/thickness. */ } gmo_knot_t; /* A `knot' is an infinitesimal surface element, that is, a point of space, a tangent plane, a radius, and an opto. */ /* ITEM KINDS */ typedef struct gmo_item_dot_t { gmo_knot_ix_t kn; } gmo_item_dot_t; /* A `dot' element, that is, a small sphere. The knot specifies the center, radius, and opto of the sphere. The tangent plane of the knot is irrelevant. */ typedef struct gmo_item_slug_t { gmo_knot_ix_t kn[2]; } gmo_item_slug_t; /* A `slug' item, that is, a sphere-capped cone. The knots specify the centers, radii, and optos of the two end-spheres. The tangent planes of the knots are irrelevant. */ typedef struct gmo_item_tri_t { gmo_knot_ix_t kn[3]; /* Positions, optos, radii and tangent planes of corners. */ } gmo_item_tri_t; /* A `tri' element, that is, a triangle with rounded edges and corners. The knots specify the centers, radii, and optos of the three end-spheres. The tangent planes of the knots are irrelevant. */ /* I/O */ void gmo_write(FILE *wr, gmo_t *P); /* Writes a description of {P} {wr}, in a format that can be read back with {gmo_read} below.. */ gmo_t *gmo_read(FILE *rd); /* Reads a plot list {P} from the reader {rd}. Assumes the format used by {Write} above. */ /* ITEM ENUMERATION */ typedef bool_t gmo_item_dot_proc_t(gmo_item_ix_t ix, gmo_item_dot_t *t); typedef bool_t gmo_item_slug_proc_t(gmo_item_ix_t ix, gmo_item_slug_t *t); typedef bool_t gmo_item_tri_proc_t(gmo_item_ix_t ix, gmo_item_tri_t *t); /* Client procedures for {gmo_enum_items}. */ gmo_item_ix_t gmo_enum_items ( gmo_t *P, gmo_item_dot_proc_t visit_dot, gmo_item_slug_proc_t visit_slug, gmo_item_tri_proc_t visit_tri ); /* Enumerates all items of {P} in order, calling the appropriate {visit_XXX} procedure on each. If any of the procedures returns {TRUE}, stops the enumeration and returns that element's index. Otherwise returns -1. */ /* INPUT/OUTPUT */ gmo_item_kind_t gmo_item_kind_from_char(char c); char gmo_item_kind_to_char(gmo_item_kind_t iknd); #endif