Skip to content

Instantly share code, notes, and snippets.

@amatus
Created June 23, 2017 17:24
Show Gist options
  • Save amatus/64174ffe82ed5200404246b1d8076523 to your computer and use it in GitHub Desktop.
Save amatus/64174ffe82ed5200404246b1d8076523 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <math.h>
#include <glib/gtypes.h> // srsly guys?
#include <gts.h>
int main(int argc, char **argv)
{
GtsVolumeOptimizedParams params;
guint min_number = 500000;
gdouble min_angle = 3.14159 / 180 / 60;
GtsSurface *s;
GtsFile *f;
guint rc;
if(argc > 1)
min_number = atol(argv[1]);
if(argc > 2)
min_angle = atof(argv[2]);
s = gts_surface_new(gts_surface_class(), gts_face_class(),
gts_edge_class(), gts_vertex_class());
f = gts_file_new(stdin);
rc = gts_surface_read(s, f);
if(rc != 0)
{
fprintf(stderr, "%u: %s\n", rc, f->error);
return -1;
}
params.volume_weight = 0.5;
params.boundary_weight = 0.5;
params.shape_weight = 0;
gts_surface_coarsen(s, (GtsKeyFunc)gts_volume_optimized_cost, &params,
(GtsCoarsenFunc)gts_volume_optimized_vertex, &params,
(GtsStopFunc)gts_coarsen_stop_number, &min_number, min_angle);
fprintf(stderr, "Optimized surface:\n");
gts_surface_print_stats(s, stderr);
gts_surface_write(s, stdout);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment