/[zanavi_public1]/navit/navit/maptool/poly_to_tri002/tricall.c
ZANavi

Contents of /navit/navit/maptool/poly_to_tri002/tricall.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 31 - (show annotations) (download)
Mon Feb 4 17:41:59 2013 UTC (11 years, 2 months ago) by zoff99
File MIME type: text/plain
File size: 10300 byte(s)
new map version, lots of fixes and experimental new features
1 /*****************************************************************************/
2 /* */
3 /* (tricall.c) */
4 /* */
5 /* Example program that demonstrates how to call Triangle. */
6 /* */
7 /* Accompanies Triangle Version 1.6 */
8 /* July 19, 1996 */
9 /* */
10 /* This file is placed in the public domain (but the file that it calls */
11 /* is still copyrighted!) by */
12 /* Jonathan Richard Shewchuk */
13 /* 2360 Woolsey #H */
14 /* Berkeley, California 94705-1927 */
15 /* jrs@cs.berkeley.edu */
16 /* */
17 /*****************************************************************************/
18
19 /* If SINGLE is defined when triangle.o is compiled, it should also be */
20 /* defined here. If not, it should not be defined here. */
21
22 /* #define SINGLE */
23
24 #ifdef SINGLE
25 #define REAL float
26 #else /* not SINGLE */
27 #define REAL double
28 #endif /* not SINGLE */
29
30 #include <stdio.h>
31 #include <stdlib.h>
32 #include "triangle.h"
33
34 /*****************************************************************************/
35 /* */
36 /* report() Print the input or output. */
37 /* */
38 /*****************************************************************************/
39
40 void report(io, markers, reporttriangles, reportneighbors, reportsegments,
41 reportedges, reportnorms)
42 struct triangulateio *io;
43 int markers;
44 int reporttriangles;
45 int reportneighbors;
46 int reportsegments;
47 int reportedges;
48 int reportnorms;
49 {
50 int i, j;
51
52 for (i = 0; i < io->numberofpoints; i++) {
53 printf("Point %4d:", i);
54 for (j = 0; j < 2; j++) {
55 printf(" %.6g", io->pointlist[i * 2 + j]);
56 }
57 if (io->numberofpointattributes > 0) {
58 printf(" attributes");
59 }
60 for (j = 0; j < io->numberofpointattributes; j++) {
61 printf(" %.6g",
62 io->pointattributelist[i * io->numberofpointattributes + j]);
63 }
64 if (markers) {
65 printf(" marker %d\n", io->pointmarkerlist[i]);
66 } else {
67 printf("\n");
68 }
69 }
70 printf("\n");
71
72 if (reporttriangles || reportneighbors) {
73 for (i = 0; i < io->numberoftriangles; i++) {
74 if (reporttriangles) {
75 printf("Triangle %4d points:", i);
76 for (j = 0; j < io->numberofcorners; j++) {
77 printf(" %4d", io->trianglelist[i * io->numberofcorners + j]);
78 }
79 if (io->numberoftriangleattributes > 0) {
80 printf(" attributes");
81 }
82 for (j = 0; j < io->numberoftriangleattributes; j++) {
83 printf(" %.6g", io->triangleattributelist[i *
84 io->numberoftriangleattributes + j]);
85 }
86 printf("\n");
87 }
88 if (reportneighbors) {
89 printf("Triangle %4d neighbors:", i);
90 for (j = 0; j < 3; j++) {
91 printf(" %4d", io->neighborlist[i * 3 + j]);
92 }
93 printf("\n");
94 }
95 }
96 printf("\n");
97 }
98
99 if (reportsegments) {
100 for (i = 0; i < io->numberofsegments; i++) {
101 printf("Segment %4d points:", i);
102 for (j = 0; j < 2; j++) {
103 printf(" %4d", io->segmentlist[i * 2 + j]);
104 }
105 if (markers) {
106 printf(" marker %d\n", io->segmentmarkerlist[i]);
107 } else {
108 printf("\n");
109 }
110 }
111 printf("\n");
112 }
113
114 if (reportedges) {
115 for (i = 0; i < io->numberofedges; i++) {
116 printf("Edge %4d points:", i);
117 for (j = 0; j < 2; j++) {
118 printf(" %4d", io->edgelist[i * 2 + j]);
119 }
120 if (reportnorms && (io->edgelist[i * 2 + 1] == -1)) {
121 for (j = 0; j < 2; j++) {
122 printf(" %.6g", io->normlist[i * 2 + j]);
123 }
124 }
125 if (markers) {
126 printf(" marker %d\n", io->edgemarkerlist[i]);
127 } else {
128 printf("\n");
129 }
130 }
131 printf("\n");
132 }
133 }
134
135 /*****************************************************************************/
136 /* */
137 /* main() Create and refine a mesh. */
138 /* */
139 /*****************************************************************************/
140
141 int main()
142 {
143 struct triangulateio in, mid, out, vorout;
144
145 /* Define input points. */
146
147 in.numberofpoints = 4;
148 in.numberofpointattributes = 1;
149 in.pointlist = (REAL *) malloc(in.numberofpoints * 2 * sizeof(REAL));
150 in.pointlist[0] = 0.0;
151 in.pointlist[1] = 0.0;
152 in.pointlist[2] = 1.0;
153 in.pointlist[3] = 0.0;
154 in.pointlist[4] = 1.0;
155 in.pointlist[5] = 10.0;
156 in.pointlist[6] = 0.0;
157 in.pointlist[7] = 10.0;
158 in.pointattributelist = (REAL *) malloc(in.numberofpoints *
159 in.numberofpointattributes *
160 sizeof(REAL));
161 in.pointattributelist[0] = 0.0;
162 in.pointattributelist[1] = 1.0;
163 in.pointattributelist[2] = 11.0;
164 in.pointattributelist[3] = 10.0;
165 in.pointmarkerlist = (int *) malloc(in.numberofpoints * sizeof(int));
166 in.pointmarkerlist[0] = 0;
167 in.pointmarkerlist[1] = 2;
168 in.pointmarkerlist[2] = 0;
169 in.pointmarkerlist[3] = 0;
170
171 in.numberofsegments = 0;
172 in.numberofholes = 0;
173 in.numberofregions = 1;
174 in.regionlist = (REAL *) malloc(in.numberofregions * 4 * sizeof(REAL));
175 in.regionlist[0] = 0.5;
176 in.regionlist[1] = 5.0;
177 in.regionlist[2] = 7.0; /* Regional attribute (for whole mesh). */
178 in.regionlist[3] = 0.1; /* Area constraint that will not be used. */
179
180 printf("Input point set:\n\n");
181 report(&in, 1, 0, 0, 0, 0, 0);
182
183 /* Make necessary initializations so that Triangle can return a */
184 /* triangulation in `mid' and a voronoi diagram in `vorout'. */
185
186 mid.pointlist = (REAL *) NULL; /* Not needed if -N switch used. */
187 /* Not needed if -N switch used or number of point attributes is zero: */
188 mid.pointattributelist = (REAL *) NULL;
189 mid.pointmarkerlist = (int *) NULL; /* Not needed if -N or -B switch used. */
190 mid.trianglelist = (int *) NULL; /* Not needed if -E switch used. */
191 /* Not needed if -E switch used or number of triangle attributes is zero: */
192 mid.triangleattributelist = (REAL *) NULL;
193 mid.neighborlist = (int *) NULL; /* Needed only if -n switch used. */
194 /* Needed only if segments are output (-p or -c) and -P not used: */
195 mid.segmentlist = (int *) NULL;
196 /* Needed only if segments are output (-p or -c) and -P and -B not used: */
197 mid.segmentmarkerlist = (int *) NULL;
198 mid.edgelist = (int *) NULL; /* Needed only if -e switch used. */
199 mid.edgemarkerlist = (int *) NULL; /* Needed if -e used and -B not used. */
200
201 vorout.pointlist = (REAL *) NULL; /* Needed only if -v switch used. */
202 /* Needed only if -v switch used and number of attributes is not zero: */
203 vorout.pointattributelist = (REAL *) NULL;
204 vorout.edgelist = (int *) NULL; /* Needed only if -v switch used. */
205 vorout.normlist = (REAL *) NULL; /* Needed only if -v switch used. */
206
207 /* Triangulate the points. Switches are chosen to read and write a */
208 /* PSLG (p), preserve the convex hull (c), number everything from */
209 /* zero (z), assign a regional attribute to each element (A), and */
210 /* produce an edge list (e), a Voronoi diagram (v), and a triangle */
211 /* neighbor list (n). */
212
213 triangulate("pczAevn", &in, &mid, &vorout);
214
215 printf("Initial triangulation:\n\n");
216 report(&mid, 1, 1, 1, 1, 1, 0);
217 printf("Initial Voronoi diagram:\n\n");
218 report(&vorout, 0, 0, 0, 0, 1, 1);
219
220 /* Attach area constraints to the triangles in preparation for */
221 /* refining the triangulation. */
222
223 /* Needed only if -r and -a switches used: */
224 mid.trianglearealist = (REAL *) malloc(mid.numberoftriangles * sizeof(REAL));
225 mid.trianglearealist[0] = 3.0;
226 mid.trianglearealist[1] = 1.0;
227
228 /* Make necessary initializations so that Triangle can return a */
229 /* triangulation in `out'. */
230
231 out.pointlist = (REAL *) NULL; /* Not needed if -N switch used. */
232 /* Not needed if -N switch used or number of attributes is zero: */
233 out.pointattributelist = (REAL *) NULL;
234 out.trianglelist = (int *) NULL; /* Not needed if -E switch used. */
235 /* Not needed if -E switch used or number of triangle attributes is zero: */
236 out.triangleattributelist = (REAL *) NULL;
237
238 /* Refine the triangulation according to the attached */
239 /* triangle area constraints. */
240
241 triangulate("prazBP", &mid, &out, (struct triangulateio *) NULL);
242
243 printf("Refined triangulation:\n\n");
244 report(&out, 0, 1, 0, 0, 0, 0);
245
246 /* Free all allocated arrays, including those allocated by Triangle. */
247
248 free(in.pointlist);
249 free(in.pointattributelist);
250 free(in.pointmarkerlist);
251 free(in.regionlist);
252 free(mid.pointlist);
253 free(mid.pointattributelist);
254 free(mid.pointmarkerlist);
255 free(mid.trianglelist);
256 free(mid.triangleattributelist);
257 free(mid.trianglearealist);
258 free(mid.neighborlist);
259 free(mid.segmentlist);
260 free(mid.segmentmarkerlist);
261 free(mid.edgelist);
262 free(mid.edgemarkerlist);
263 free(vorout.pointlist);
264 free(vorout.pointattributelist);
265 free(vorout.edgelist);
266 free(vorout.normlist);
267 free(out.pointlist);
268 free(out.pointattributelist);
269 free(out.trianglelist);
270 free(out.triangleattributelist);
271
272 return 0;
273 }

   
Visit the ZANavi Wiki