Exemplo n.º 1
0
Arquivo: dt.c Projeto: pkuwwt/Detri
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! */
}
Exemplo n.º 2
0
/*
 * alf_w_end () -- Closes the module by freeing partial result
 *                 storage.
 */
void alf_w_end ()
{
  int a, b;

  /* Free up memory */

  upfor (a, 0, 4)
    upfor (b, 0, 4)
      FREE(results[a][b]);

  FREE(d0);
  FREE(d1);
  FREE(d2);
  FREE(d3);
  FREE(d4);
  FREE(m123);

  if (math_test)
    basic_fclose (check_file);
}
Exemplo n.º 3
0
Arquivo: dt.c Projeto: pkuwwt/Detri
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);
}