#ifndef hedge_H #define hedge_H /* Copyright (C) 2023 Jorge Stolfi, UNICAMP */ /* Last edited on 2025-05-07 17:31:55 by stolfi */ #include #include #include typedef struct hedge_face_t { struct hedge_arc_t *side; /* One {arc_t} on the perimeter. */ r3_t ctr; /* Nominal center, for plotting. */ bool_t show; /* True to draw the record. */ uint32_t id; /* Sequential number. */ } hedge_face_t; /* A record of the half-edge structure representing a face of the mesh. The {ctr} and {show} attributes are used when drawing the structure. */ vec_typedef(hedge_face_vec_t, hedge_face_vec, hedge_face_t*); /* A vector of pointers to {Vace_t} records. */ typedef struct hedge_arc_t { struct hedge_arc_t *twin; /* Same edge in opposite orientation. */ struct hedge_arc_t *next; /* Next edge around left face. */ struct hedge_face_t *left; /* face on left side. */ struct hedge_vert_t *org; /* Origin vertex. */ double bend; /* Modifies the direction at endpoints. */ uint32_t id; /* Sequential number. */ } hedge_arc_t; /* A record of the half-edge structure representing a directed edge of the mesh. The {bow} attribute is used when drawing the structure. */ vec_typedef(hedge_arc_vec_t, hedge_arc_vec, hedge_arc_t*); /* A vector of pointers to {hedge_arc_t} records. The twin of an arc {a[i]} is {a[i^1]}. */ typedef struct hedge_vert_t { struct hedge_arc_t *out; /* One arc out the vertex. */ r3_t pos; /* Nominal position. */ bool_t show; /* True to draw the record. */ uint32_t id; /* Sequential number. */ } hedge_vert_t; /* A record of the half-edge structure representing a vertex of the mesh. The {pos} and {show} attributes are used when drawing the structure. */ vec_typedef(hedge_vert_vec_t, hedge_vert_vec, hedge_vert_t*); /* A vector of pointers to {vert_t} records. */ typedef struct hedge_t { uint32_t nv; hedge_vert_vec_t V; /* The vertices are V.e[0..nv-1]. */ uint32_t na; hedge_arc_vec_t A; /* The arcs are A.e[0..na-1]. */ uint32_t nf; hedge_face_vec_t F; /* The faces are F.e[0..nf-1]. */ double dunit; /* Unit of detail dimensions, in mm. */ } hedge_t; /* A half-edge structure. */ hedge_t *hedge_new(int32_t nf_alloc, int32_t ne_alloc, int32_t nv_alloc); /* Creates a new half-edge structure, with tables initially allocatde for the give number of faces, edges, and vertices. */ hedge_vert_t *hedge_add_vert(hedge_t *H, double X, double Y, double Z, bool_t show); /* Adds to {H} a new vertex record {v} to the end of {H.V}, expanding it if needed. The position {v.pos} is set to {(X,Y,Z)}, and {v.show} is set to {show}. The pointer {v.out} is set to {NULL}. */ hedge_arc_t *hedge_add_edge ( hedge_t *H, hedge_vert_t *org, hedge_vert_t *dst, double bend ); /* Adds to {H} an edge, consisting of two {arc_t} records {a,b}, each the {twin} of the other, respectively from {org} to {dst} (with left face {left}) and from {dst} to {org} (with left face {right}). The arcs are added at the end of {H.A}, expanding it if needed. Returns the arc {a}. The parameters {org} and {dst} may not be {NULL}. The pointers {org.out} and {dst.out} are set to {a} and {b}, respectively. The {.next} pointers and {.left} pointers of both arcs are set to {NULL}. These pointers should be eventually set to non-{NULL} values. See {hedge_set_next} and {hedge_set_lefts} below. */ hedge_face_t *hedge_add_face(hedge_t *H, double X, double Y, double Z, bool_t show, hedge_arc_t *a); /* Adds to {H} a new face record {f} to the end of {H.F}, expanding it if needed. The nominal centroid {f.pos} is set to {(X,Y,Z)}, and {f.show} is set to {show}. If {a} is not {NULL}, also does {hedge_set_lefts(a, f)}, which sets {f.side} to {a} and {a.next^k.left} to {f} for all {k}; otherwise the pointer {f.side} is set to {NULL}. */ void hedge_set_next(hedge_arc_t *a, hedge_arc_t *b); /* Sets the pointer {a.next} (which must be {NULL}) to point to {b}. */ void hedge_set_lefts(hedge_arc_t *a, hedge_face_t *f); /* Enumerates every arc {e} in the {.next} cycle of {a} and sets all the pointers {e.left} (which must be {NULL}) to point to {f}. Also sets {f.side} (which must be {NULL} to point to {a}. */ void hedge_check_topology(hedge_t *H); /* Topological consistency checks. */ #endif