#ifndef rdo_site_H #define rdo_site_H /* Tools for handling sites (point/normal pairs). */ #define rdo_site_H_COPYRIGHT "Copyright © 2008 Danillo Pereira and J. Stolfi, UNICAMP" /* Last edited on 2024-12-21 11:51:25 by stolfi */ #include #include #include #include #include typedef struct site_t { point3_t position; /* A point on the scene's surface. */ vector3_t normal; /* Unit outwards-pointing normal vector at that point. */ int isd; /* Index into some list of solid objects. */ } site_t; /* A site is a point and a normal vector on the scene's surface. */ void rdo_site_from_point(solid_t *sd, int isd, point3_t *position, site_t *sP); /* Assumes that point {position} lies on the surface of solid object {sd}, whose index is {isd}. Finds the normal direction of the solid objects's surface at that point, and assembles the site {*sP} from those elements. */ void rdo_site_write(FILE *wr, site_t *st); /* Writes site {*st} to file {wr}. */ site_t rdo_site_read(FILE *rd); /* Reads a file {rd}, in the format created by {rdo_site_write}. */ /* DISTANCE BETWEEN SITES */ typedef enum { dist_type_Euclidean, /* Euclidean distance between positions. */ dist_type_Directional /* Euclidean distance divided by cosine of angle. */ } dist_type_t; /* A code that specifies a kind of metric between sites. */ double rdo_site_distance(site_t *sA, site_t *sB, dist_type_t td); /* Distance between the two given sites, in the metric {td}. */ /* LIST OF SITES */ vec_typedef(site_vec_t, site_vec, site_t); /* Defines the type {site_vec_t} as a self-delimited array of sites, {A.e[0..A.ne-1]}. Also defines the functions {site_vec_new()}, {site_vec_expand()}, {site_vec_trim()}, and {site_vec_free()}. */ void rdo_site_vec_write(FILE *wr, site_vec_t *sts); /* Writes the site list {sts} to file {wr}. */ site_vec_t rdo_site_vec_read(FILE *rd); /* Reads a list of sites from file {rd}, in the format produced by {rdo_site_vec_write}. */ void rdo_site_vec_scramble(site_vec_t *sts); /* Permutes the sites {s[0..n-1]} in random order. */ void rdo_site_find_closest_sites ( site_t *sr, site_vec_t *sts, int max_nc, dist_type_t tpDist, bool_t same_solid, int ind[], double dst[], int *ncP ); /* Scans the list {sts->e[0..sts->ne-1]} for the {max_nc} sites that xslie at finite nonzero distance from {sr}, and are closest to {sr} in the metric {tpDist}. Stores into {*ncP} the number of sites actually found (which may be {max_nc} or less, possibly zero); stores the indices of those sites into {ind[0..*ncP-1]}; and their distances from {sr} into {dst[0..*ncP-1]}. If {same_site} is TRUE, considers only sites that lie on the same solid object as {sr}, according to their {.isd} fields. Two sites {sa} and {sb} are assuem to be on the same object if and only if {sa.isd >= 0}, {sb.isd >= 0}, and {sa.isd == sb.isd}. */ void rdo_site_remove_closest(site_vec_t *sts, double minDist, dist_type_t td); /* Removes some sites from the list {sts->e[0..sts->ne-1]} so that the distance between any two sites is not less than {minDist} in the metric {td}. Re-sizes {*sts} so that {sts->e[0..sts->ne-1]} are all and only the surviving sites. */ double rdo_site_estimate_effective_area(site_t *sr, site_vec_t *sts); /* Estimates the approximate area ``owned'' by site {*sr} among the sites {sts->e[i]}. This is computed by finding a few sites in {sts} that are closest to {sts->e[i]}, in the Euclidean metric, and analyzing their distances to that site. Whenever possible, considers only sites that lie on the same solid object as {*sr}. Uses the {.isd} field to identify the sites that are on the same object. May return {NAN} if there is no valid candidate for the nearest site. */ double *rdo_site_estimate_all_effective_areas(site_vec_t *sts); /* Returns a vector {ar[0..sts->ne-1]} where {ar[i]} is the approximate area ``owned'' by each site {sts->e[i]}, as computed by {rdo_site_estimate_effective_area}. Bombs out if any of the areas comes out as {NAN}. */ #endif