void dt_save (const char path_name[], int type, Trist *s, const Trist_num *q) { Dt dt; int h1, h2; int saved_max = s->max_triangle; Assert_always (s->magic == MAGIC); ; { /* using binary format */ FILE *f = basic_fopen (path_name, "w"); print ("Saving binary file \"%s\" ...\n", path_name); ; h2 = trist_pack (); h1 = EdFacet (1, 0); /* trist_pack*() moves hull facets to: [1..h2] */ if (NOT trist_hull_facet (h1)) h1 = Sym (h1); #ifdef __DEBUG__ trist_io_check (s, *q); #endif ; dt.bpt = (short) sizeof (Trist_record); dt.type = (short) type; dt.hull_ef = h1; dt.last_hull = h2; dt.num = *q; dt.n = s->max_org; dt.redundant = s->max_org - dt.num.v; dt.trist = NULL; s->max_triangle = s->last_triangle; Assert_always (dt.n == dt.num.v + dt.redundant); ; /* binfwrite (&dt, 1, f); */ Write1f (dt.type); Write1f (dt.bpt); Write1f (dt.n); Write1f (dt.redundant); Write1f (dt.hull_ef); Write1f (dt.last_hull); Write1f (dt.num); Write1f (dummy_word); ; /* binfwrite (s, 1, f); */ Write1f (s->magic); Write1f (dummy_word); Write1f (s->last_triangle); Write1f (s->max_triangle); Write1f (s->max_org); Write1f (dummy_word); Write1f (s->used_triangles); Write1f (s->next_reusable_triangle); ; binfwrite (s->triangle, s->max_triangle + 1, f); ; basic_fclose (f); } s->max_triangle = saved_max; /* such that s leaves unchanged! */ }
Dt_input_scan *dt_input_scan (const char data_path[]) /* ... scans the ASCII input file data_path for the fields in the return structure (see dt.h file). See also dt_input_load() which actually loads the data and sets the has_weights field if necessary. */ /* NOTE: The returned address, which points to the return structure, is a constant. DO NOT FREE() IT and consider the fields of the structure as read-only. */ { static Dt_input_scan data; FILE *inp = basic_fopen (data_path, "r"); char *r; ; /* default values */ data.name = STRDUP (data_path); data.title = NULL; data.lines = 0; data.n = 0; data.scale = 1.0; /* ie, no scaling */ data.fix_w = 0; data.fix_a = 0; data.decimals = 10; /* ie, int coordinates */ data.has_weights = 0; /* ie, unknown; see dt_input_load() */ ; /* scan the file */ print ("Scanning ASCII file \"%s\" ... ", If (basic_fopen_zpath, basic_fopen_zpath, data_path)); flush (); while ((r = basic_cb_getline (inp))) { data.lines ++; if (basic_strip (r) AND (r[0] != '#')) { /* a data line: <x> <y> <z> */ data.n ++; } else if (is_command (&data, r, "title", 5)) { /* # title: %s */ r = basic_strip (index (r, 'e') + 1); if (r) { int i = -1; data.title = STRDUP (r); do { i ++; } until (data.title[i] == '\n'); data.title[i] = 0; } } else if (is_command (&data, r, "scale", 5))
/* * alf_w_begin () -- Initializes the module by allocating partial result * storage. */ void alf_w_begin () { int a, b; upfor (a, 0, 3) size[a] = hidden[a] = 0; upfor (a, 0, 4) upfor (b, 0, 4) results[a][b] = MALLOC (Lia, lia_get_maximum()); d0 = MALLOC (Lia, lia_get_maximum()); d1 = MALLOC (Lia, lia_get_maximum()); d2 = MALLOC (Lia, lia_get_maximum()); d3 = MALLOC (Lia, lia_get_maximum()); d4 = MALLOC (Lia, lia_get_maximum()); m123 = MALLOC (Lia, lia_get_maximum()); if (math_test) check_file = basic_fopen (basic_cb_frmt ("mkalf.math"), "w"); }
Dt* dt_load (const char path_name[]) { Dt *dt = MALLOC (Dt, 1); Trist *s = MALLOC (Trist, 1); ; { /* using binary format */ FILE *f = basic_fopen (path_name, "r"); print ("Reading Delaunay triangulation from binary file \"%s\" ...\n", If (basic_fopen_zpath, basic_fopen_zpath, path_name)); ; Read1f (dt->type); Read1f (dt->bpt); Read1f (dt->n); Read1f (dt->redundant); Read1f (dt->hull_ef); Read1f (dt->last_hull); Read1f (dt->num); Read1f (dummy_word); ; Read1f (s->magic); Read1f (dummy_word); Read1f (s->last_triangle); Read1f (s->max_triangle); Read1f (s->max_org); Read1f (dummy_word); Read1f (s->used_triangles); Read1f (s->next_reusable_triangle); s->data_size = 0; s->data = NULL; ; dt->trist = s; ; /* just checking... */ if (s->magic != MAGIC) basic_error ("dt_load: wrong magic number (%d != %d)\n", s->magic, MAGIC); if (dt->bpt != (short) sizeof (Trist_record)) basic_error ("dt_load: wrong Trist record size (%d != %d)\n", dt->bpt, (short) sizeof (Trist_record)); if (NOT ( (dt->n == dt->trist->max_org) AND (dt->n == dt->num.v + dt->redundant))) basic_error ("dt_load: corrupted header\n"); if (dt->redundant) { print ("%15d redundant vertices dumped.\n", dt->redundant); print ("%15d actual vertices remain.\n", dt->num.v); } ; s->triangle = MALLOC (Trist_record, s->max_triangle + 1); binfread (s->triangle, s->max_triangle + 1, f); ; if (offset > 0) { dt->sos_offset = offset; s->max_org += offset; trist_set(s); trist_modify_vertices (offset); offset = 0; } else dt->sos_offset = 0; #ifdef __DEBUG__ trist_io_check (s, dt->num); #endif basic_fclose (f); } return (dt); }