1 #include "gts.h"
2
edge_collapse(GtsSurface * s,GtsEdge * e,GtsCoarsenFunc coarsen_func,gpointer coarsen_data)3 static GtsVertex * edge_collapse (GtsSurface * s,
4 GtsEdge * e,
5 GtsCoarsenFunc coarsen_func,
6 gpointer coarsen_data)
7 {
8 GtsVertex * v1 = GTS_SEGMENT (e)->v1, * v2 = GTS_SEGMENT (e)->v2, * mid;
9 GtsSplit * vs;
10 GtsObject * o1, * o2;
11
12 /* if the edge is degenerate (i.e. v1 == v2), destroy and return */
13 if (v1 == v2) {
14 gts_object_destroy (GTS_OBJECT (e));
15 return NULL;
16 }
17
18 mid = (*coarsen_func) (e, s->vertex_class, coarsen_data);
19 o1 = GTS_OBJECT (v1);
20 o2 = GTS_OBJECT (v2);
21 vs = gts_split_new (gts_split_class (), mid, o1, o2);
22 gts_split_collapse (vs, s->edge_class, NULL);
23
24 return mid;
25 }
26
main(int argc,char * argv[])27 int main (int argc, char * argv[])
28 {
29 GtsSurface * surface = gts_surface_new (gts_surface_class (),
30 gts_face_class (),
31 gts_edge_class (),
32 gts_vertex_class ());
33
34 GtsVertex * v1 = gts_vertex_new (gts_vertex_class (),
35 11640, 15867.5, 1080);
36 GtsVertex * v2 = gts_vertex_new (gts_vertex_class (),
37 11700, 15720, 1070);
38 GtsVertex * v3 = gts_vertex_new (gts_vertex_class (),
39 11616, 15728.8, 1084);
40 GtsVertex * v4 = gts_vertex_new (gts_vertex_class (),
41 11580, 15840, 1090);
42 GtsVertex * v5 = gts_vertex_new (gts_vertex_class (),
43 11460, 15840, 1100);
44 GtsVertex * v6 = gts_vertex_new (gts_vertex_class (),
45 11520, 15840, 1100);
46 GtsVertex * v7 = gts_vertex_new (gts_vertex_class (),
47 11520, 15780, 1100);
48 GtsVertex * v8 = gts_vertex_new (gts_vertex_class (),
49 11700, 15660, 1070);
50 GtsVertex * v9 = gts_vertex_new (gts_vertex_class (),
51 11672.4, 15600.1, 1074.6);
52 GtsVertex * v10 = gts_vertex_new (gts_vertex_class (),
53 11520, 15751.7, 1100);
54 GtsVertex * v11 = gts_vertex_new (gts_vertex_class (),
55 11569.5, 15646.1, 1091.75);
56 GtsVertex * v;
57
58 GtsEdge * e1 = gts_edge_new (gts_edge_class (), v1, v2);
59 GtsEdge * e2 = gts_edge_new (gts_edge_class (), v1, v3);
60 GtsEdge * e3 = gts_edge_new (gts_edge_class (), v3, v2);
61 GtsEdge * e4 = gts_edge_new (gts_edge_class (), v4, v1);
62 GtsEdge * e5 = gts_edge_new (gts_edge_class (), v3, v4);
63 GtsEdge * e6 = gts_edge_new (gts_edge_class (), v5, v6);
64 GtsEdge * e7 = gts_edge_new (gts_edge_class (), v5, v7);
65 GtsEdge * e8 = gts_edge_new (gts_edge_class (), v6, v7);
66 GtsEdge * e9 = gts_edge_new (gts_edge_class (), v8, v2);
67 GtsEdge * e10 = gts_edge_new (gts_edge_class (), v8, v3);
68 GtsEdge * e11 = gts_edge_new (gts_edge_class (), v6, v4);
69 GtsEdge * e12 = gts_edge_new (gts_edge_class (), v6, v3);
70 GtsEdge * e13 = gts_edge_new (gts_edge_class (), v8, v9);
71 GtsEdge * e14 = gts_edge_new (gts_edge_class (), v3, v9);
72 GtsEdge * e15 = gts_edge_new (gts_edge_class (), v7, v10);
73 GtsEdge * e16 = gts_edge_new (gts_edge_class (), v10, v5);
74 GtsEdge * e17 = gts_edge_new (gts_edge_class (), v11, v3);
75 GtsEdge * e18 = gts_edge_new (gts_edge_class (), v9, v11);
76 GtsEdge * e19 = gts_edge_new (gts_edge_class (), v10, v11);
77 GtsEdge * e20 = gts_edge_new (gts_edge_class (), v11, v7);
78 GtsEdge * e21 = gts_edge_new (gts_edge_class (), v7, v3);
79
80 GtsFace * f1 = gts_face_new (gts_face_class (),
81 e1, e2, e3);
82 GtsFace * f2 = gts_face_new (gts_face_class (),
83 e4, e5, e2);
84 GtsFace * f3 = gts_face_new (gts_face_class (),
85 e6, e7, e8);
86 GtsFace * f4 = gts_face_new (gts_face_class (),
87 e9, e3, e10);
88 GtsFace * f5 = gts_face_new (gts_face_class (),
89 e11, e12, e5);
90 GtsFace * f6 = gts_face_new (gts_face_class (),
91 e13, e10, e14);
92 GtsFace * f7 = gts_face_new (gts_face_class (),
93 e15, e7, e16);
94 GtsFace * f8 = gts_face_new (gts_face_class (),
95 e17, e18, e14);
96 GtsFace * f9 = gts_face_new (gts_face_class (),
97 e19, e20, e15);
98 GtsFace * f10 = gts_face_new (gts_face_class (),
99 e21, e12, e8);
100 GtsFace * f11 = gts_face_new (gts_face_class (),
101 e21, e20, e17);
102
103 GtsVolumeOptimizedParams params = { 0.5, 0.5, 0. };
104
105 gts_surface_add_face (surface, f1);
106 gts_surface_add_face (surface, f2);
107 gts_surface_add_face (surface, f3);
108 gts_surface_add_face (surface, f4);
109 gts_surface_add_face (surface, f5);
110 gts_surface_add_face (surface, f6);
111 gts_surface_add_face (surface, f7);
112 gts_surface_add_face (surface, f8);
113 gts_surface_add_face (surface, f9);
114 gts_surface_add_face (surface, f10);
115 gts_surface_add_face (surface, f11);
116
117 gts_surface_print_stats (surface, stderr);
118 fprintf (stderr, "volume: %g\n", gts_surface_volume (surface));
119
120 #if 0
121 v = edge_collapse (surface, e21,
122 (GtsCoarsenFunc) gts_volume_optimized_vertex,
123 ¶ms);
124 #else
125 v = gts_volume_optimized_vertex (e21, gts_vertex_class (), ¶ms);
126 fprintf (stderr, "v: %.10g %.10g %.10g\n",
127 GTS_POINT (v)->x, GTS_POINT (v)->y, GTS_POINT (v)->z);
128 fprintf (stderr, "before: check for folds...\n");
129 gts_edge_collapse_creates_fold (e21, v, 0.999695413509);
130 v = edge_collapse (surface, e21,
131 (GtsCoarsenFunc) gts_volume_optimized_vertex,
132 ¶ms);
133 fprintf (stderr, "after: check for folds...\n");
134 {
135 GSList * i = v->segments;
136 while (i) {
137 GtsEdge * e = i->data;
138 gts_triangles_are_folded (e->triangles,
139 GTS_SEGMENT (e)->v1,
140 GTS_SEGMENT (e)->v2,
141 0.999695413509);
142 i = i->next;
143 }
144 }
145 #endif
146
147 gts_surface_print_stats (surface, stderr);
148 fprintf (stderr, "volume: %g\n", gts_surface_volume (surface));
149
150 gts_surface_write (surface, stdout);
151
152 return 0;
153 }
154