利用开源库Triangle对二维边界点数组进行三角化
前言
将我几年前还是“小小小白”时(目前将自己定义为“小白”),编译Triangle库时的场景记录了下来,那时候算是才开始接触开源项目,很多东西都不懂,本着一颗不会不懂就瞎折腾的精神,一路走来,之前在cnblog自己的另一个账号也记录过,现在这个新注册的号,买了会员,手动搬了过来。仅以此祭奠下这几年逝去的时光。
目的
因为本身triangle库自带的,用于显示结果的showme程序是需要在LINUX,所以通过搭建LINUX环境,对triangle相应的参数开关做了简单的测试,以便在windows下开发时,先有个直观的认识。
为了简化,这里主要针二维边界点的情况(边界点所组成区域内暂不含空洞)
自定义一组边界点
//第一行:<顶点数> <维度(必须为2)> <属性数> <边界标记数(0或1)>
//其余行:<顶点号> [属性] [边界标记]
//空白行和以“#”为前缀的注释可以放在任何地方。顶点必须从1或0开始连续编号。
//这里的话,暂时先将属性和边界标记都设为0
600 2 0 0
1 -5000 0 0
2 -4950 0 0
3 -4900 0 0
4 -4850 0 0
5 -4800 0 0
6 -4750 0 0
7 -4700 0 0
8 -4650 0 0
9 -4600 0 0
10 -4550 0 0
11 -4500 0 0
12 -4450 0 0
13 -4400 0 0
14 -4350 0 0
15 -4300 0 0
16 -4250 0 0
17 -4200 0 0
18 -4150 0 0
19 -4100 0 0
20 -4050 0 0
21 -4000 0 0
22 -3950 0 0
23 -3900 0 0
24 -3850 0 0
25 -3800 0 0
26 -3750 0 0
27 -3700 0 0
28 -3650 0 0
29 -3600 0 0
30 -3550 0 0
31 -3500 0 0
32 -3450 0 0
33 -3400 0 0
34 -3350 0 0
35 -3300 0 0
36 -3250 0 0
37 -3200 0 0
38 -3150 0 0
39 -3100 0 0
40 -3050 0 0
41 -3000 0 0
42 -2950 0 0
43 -2900 0 0
44 -2850 0 0
45 -2800 0 0
46 -2750 0 0
47 -2700 0 0
48 -2650 0 0
49 -2600 0 0
50 -2550 0 0
51 -2500 0 0
52 -2450 0 0
53 -2400 0 0
54 -2350 0 0
55 -2300 0 0
56 -2250 0 0
57 -2200 0 0
58 -2150 0 0
59 -2100 0 0
60 -2050 0 0
61 -2000 0 0
62 -1950 0 0
63 -1900 0 0
64 -1850 0 0
65 -1800 0 0
66 -1750 0 0
67 -1700 0 0
68 -1650 0 0
69 -1600 0 0
70 -1550 0 0
71 -1500 0 0
72 -1450 0 0
73 -1400 0 0
74 -1350 0 0
75 -1300 0 0
76 -1250 0 0
77 -1200 0 0
78 -1150 0 0
79 -1100 0 0
80 -1050 0 0
81 -1000 0 0
82 -950 0 0
83 -900 0 0
84 -850 0 0
85 -800 0 0
86 -750 0 0
87 -700 0 0
88 -650 0 0
89 -600 0 0
90 -550 0 0
91 -500 0 0
92 -450 0 0
93 -400 0 0
94 -350 0 0
95 -300 0 0
96 -250 0 0
97 -200 0 0
98 -150 0 0
99 -100 0 0
100 -50 0 0
101 0 0 0
102 50 0 0
103 100 0 0
104 150 0 0
105 200 0 0
106 250 0 0
107 300 0 0
108 350 0 0
109 400 0 0
110 450 0 0
111 500 0 0
112 550 0 0
113 600 0 0
114 650 0 0
115 700 0 0
116 750 0 0
117 800 0 0
118 850 0 0
119 900 0 0
120 950 0 0
121 1000 0 0
122 1050 0 0
123 1100 0 0
124 1150 0 0
125 1200 0 0
126 1250 0 0
127 1300 0 0
128 1350 0 0
129 1400 0 0
130 1450 0 0
131 1500 0 0
132 1550 0 0
133 1600 0 0
134 1650 0 0
135 1700 0 0
136 1750 0 0
137 1800 0 0
138 1850 0 0
139 1900 0 0
140 1950 0 0
141 2000 0 0
142 2050 0 0
143 2100 0 0
144 2150 0 0
145 2200 0 0
146 2250 0 0
147 2300 0 0
148 2350 0 0
149 2400 0 0
150 2450 0 0
151 2500 0 0
152 2550 0 0
153 2600 0 0
154 2650 0 0
155 2700 0 0
156 2750 0 0
157 2800 0 0
158 2850 0 0
159 2900 0 0
160 2950 0 0
161 3000 0 0
162 3050 0 0
163 3100 0 0
164 3150 0 0
165 3200 0 0
166 3250 0 0
167 3300 0 0
168 3350 0 0
169 3400 0 0
170 3450 0 0
171 3500 0 0
172 3550 0 0
173 3600 0 0
174 3650 0 0
175 3700 0 0
176 3750 0 0
177 3800 0 0
178 3850 0 0
179 3900 0 0
180 3950 0 0
181 4000 0 0
182 4050 0 0
183 4100 0 0
184 4150 0 0
185 4200 0 0
186 4250 0 0
187 4300 0 0
188 4350 0 0
189 4400 0 0
190 4450 0 0
191 4500 0 0
192 4550 0 0
193 4600 0 0
194 4650 0 0
195 4700 0 0
196 4750 0 0
197 4800 0 0
198 4850 0 0
199 4900 0 0
200 4950 0 0
201 5000 0 0
202 5000 -50 0
203 5000 -100 0
204 5000 -150 0
205 5000 -200 0
206 5000 -250 0
207 5000 -300 0
208 5000 -350 0
209 5000 -400 0
210 5000 -450 0
211 5000 -500 0
212 5000 -550 0
213 5000 -600 0
214 5000 -650 0
215 5000 -700 0
216 5000 -750 0
217 5000 -800 0
218 5000 -850 0
219 5000 -900 0
220 5000 -950 0
221 5000 -1000 0
222 5000 -1050 0
223 5000 -1100 0
224 5000 -1150 0
225 5000 -1200 0
226 5000 -1250 0
227 5000 -1300 0
228 5000 -1350 0
229 5000 -1400 0
230 5000 -1450 0
231 5000 -1500 0
232 5000 -1550 0
233 5000 -1600 0
234 5000 -1650 0
235 5000 -1700 0
236 5000 -1750 0
237 5000 -1800 0
238 5000 -1850 0
239 5000 -1900 0
240 5000 -1950 0
241 5000 -2000 0
242 5000 -2050 0
243 5000 -2100 0
244 5000 -2150 0
245 5000 -2200 0
246 5000 -2250 0
247 5000 -2300 0
248 5000 -2350 0
249 5000 -2400 0
250 5000 -2450 0
251 5000 -2500 0
252 5000 -2550 0
253 5000 -2600 0
254 5000 -2650 0
255 5000 -2700 0
256 5000 -2750 0
257 5000 -2800 0
258 5000 -2850 0
259 5000 -2900 0
260 5000 -2950 0
261 5000 -3000 0
262 5000 -3050 0
263 5000 -3100 0
264 5000 -3150 0
265 5000 -3200 0
266 5000 -3250 0
267 5000 -3300 0
268 5000 -3350 0
269 5000 -3400 0
270 5000 -3450 0
271 5000 -3500 0
272 5000 -3550 0
273 5000 -3600 0
274 5000 -3650 0
275 5000 -3700 0
276 5000 -3750 0
277 5000 -3800 0
278 5000 -3850 0
279 5000 -3900 0
280 5000 -3950 0
281 5000 -4000 0
282 5000 -4050 0
283 5000 -4100 0
284 5000 -4150 0
285 5000 -4200 0
286 5000 -4250 0
287 5000 -4300 0
288 5000 -4350 0
289 5000 -4400 0
290 5000 -4450 0
291 5000 -4500 0
292 5000 -4550 0
293 5000 -4600 0
294 5000 -4650 0
295 5000 -4700 0
296 5000 -4750 0
297 5000 -4800 0
298 5000 -4850 0
299 5000 -4900 0
300 5000 -4950 0
301 5000 -5000 0
302 4950 -5000 0
303 4900 -5000 0
304 4850 -5000 0
305 4800 -5000 0
306 4750 -5000 0
307 4700 -5000 0
308 4650 -5000 0
309 4600 -5000 0
310 4550 -5000 0
311 4500 -5000 0
312 4450 -5000 0
313 4400 -5000 0
314 4350 -5000 0
315 4300 -5000 0
316 4250 -5000 0
317 4200 -5000 0
318 4150 -5000 0
319 4100 -5000 0
320 4050 -5000 0
321 4000 -5000 0
322 3950 -5000 0
323 3900 -5000 0
324 3850 -5000 0
325 3800 -5000 0
326 3750 -5000 0
327 3700 -5000 0
328 3650 -5000 0
329 3600 -5000 0
330 3550 -5000 0
331 3500 -5000 0
332 3450 -5000 0
333 3400 -5000 0
334 3350 -5000 0
335 3300 -5000 0
336 3250 -5000 0
337 3200 -5000 0
338 3150 -5000 0
339 3100 -5000 0
340 3050 -5000 0
341 3000 -5000 0
342 2950 -5000 0
343 2900 -5000 0
344 2850 -5000 0
345 2800 -5000 0
346 2750 -5000 0
347 2700 -5000 0
348 2650 -5000 0
349 2600 -5000 0
350 2550 -5000 0
351 2500 -5000 0
352 2450 -5000 0
353 2400 -5000 0
354 2350 -5000 0
355 2300 -5000 0
356 2250 -5000 0
357 2200 -5000 0
358 2150 -5000 0
359 2100 -5000 0
360 2050 -5000 0
361 2000 -5000 0
362 1950 -5000 0
363 1900 -5000 0
364 1850 -5000 0
365 1800 -5000 0
366 1750 -5000 0
367 1700 -5000 0
368 1650 -5000 0
369 1600 -5000 0
370 1550 -5000 0
371 1500 -5000 0
372 1450 -5000 0
373 1400 -5000 0
374 1350 -5000 0
375 1300 -5000 0
376 1250 -5000 0
377 1200 -5000 0
378 1150 -5000 0
379 1100 -5000 0
380 1050 -5000 0
381 1000 -5000 0
382 950 -5000 0
383 900 -5000 0
384 850 -5000 0
385 800 -5000 0
386 750 -5000 0
387 700 -5000 0
388 650 -5000 0
389 600 -5000 0
390 550 -5000 0
391 500 -5000 0
392 450 -5000 0
393 400 -5000 0
394 350 -5000 0
395 300 -5000 0
396 250 -5000 0
397 200 -5000 0
398 150 -5000 0
399 100 -5000 0
400 50 -5000 0
401 0 -5000 0
402 -50 -5000 0
403 -100 -5000 0
404 -150 -5000 0
405 -200 -5000 0
406 -250 -5000 0
407 -300 -5000 0
408 -350 -5000 0
409 -400 -5000 0
410 -450 -5000 0
411 -500 -5000 0
412 -550 -5000 0
413 -600 -5000 0
414 -650 -5000 0
415 -700 -5000 0
416 -750 -5000 0
417 -800 -5000 0
418 -850 -5000 0
419 -900 -5000 0
420 -950 -5000 0
421 -1000 -5000 0
422 -1050 -5000 0
423 -1100 -5000 0
424 -1150 -5000 0
425 -1200 -5000 0
426 -1250 -5000 0
427 -1300 -5000 0
428 -1350 -5000 0
429 -1400 -5000 0
430 -1450 -5000 0
431 -1500 -5000 0
432 -1550 -5000 0
433 -1600 -5000 0
434 -1650 -5000 0
435 -1700 -5000 0
436 -1750 -5000 0
437 -1800 -5000 0
438 -1850 -5000 0
439 -1900 -5000 0
440 -1950 -5000 0
441 -2000 -5000 0
442 -2050 -5000 0
443 -2100 -5000 0
444 -2150 -5000 0
445 -2200 -5000 0
446 -2250 -5000 0
447 -2300 -5000 0
448 -2350 -5000 0
449 -2400 -5000 0
450 -2450 -5000 0
451 -2500 -5000 0
452 -2550 -5000 0
453 -2600 -5000 0
454 -2650 -5000 0
455 -2700 -5000 0
456 -2750 -5000 0
457 -2800 -5000 0
458 -2850 -5000 0
459 -2900 -5000 0
460 -2950 -5000 0
461 -3000 -5000 0
462 -3050 -5000 0
463 -3100 -5000 0
464 -3150 -5000 0
465 -3200 -5000 0
466 -3250 -5000 0
467 -3300 -5000 0
468 -3350 -5000 0
469 -3400 -5000 0
470 -3450 -5000 0
471 -3500 -5000 0
472 -3550 -5000 0
473 -3600 -5000 0
474 -3650 -5000 0
475 -3700 -5000 0
476 -3750 -5000 0
477 -3800 -5000 0
478 -3850 -5000 0
479 -3900 -5000 0
480 -3950 -5000 0
481 -4000 -5000 0
482 -4050 -5000 0
483 -4100 -5000 0
484 -4150 -5000 0
485 -4200 -5000 0
486 -4250 -5000 0
487 -4300 -5000 0
488 -4350 -5000 0
489 -4400 -5000 0
490 -4450 -5000 0
491 -4500 -5000 0
492 -4550 -5000 0
493 -4600 -5000 0
494 -4650 -5000 0
495 -4700 -5000 0
496 -4750 -5000 0
497 -4800 -5000 0
498 -4850 -5000 0
499 -4900 -5000 0
500 -4950 -5000 0
501 -5000 -5000 0
502 -5000 -4950 0
503 -5000 -4900 0
504 -5000 -4850 0
505 -5000 -4800 0
506 -5000 -4750 0
507 -5000 -4700 0
508 -5000 -4650 0
509 -5000 -4600 0
510 -5000 -4550 0
511 -5000 -4500 0
512 -5000 -4450 0
513 -5000 -4400 0
514 -5000 -4350 0
515 -5000 -4300 0
516 -5000 -4250 0
517 -5000 -4200 0
518 -5000 -4150 0
519 -5000 -4100 0
520 -5000 -4050 0
521 -5000 -4000 0
522 -5000 -3950 0
523 -5000 -3900 0
524 -5000 -3850 0
525 -5000 -3800 0
526 -5000 -3750 0
527 -5000 -3700 0
528 -5000 -3650 0
529 -5000 -3600 0
530 -5000 -3550 0
531 -5000 -3500 0
532 -5000 -3450 0
533 -5000 -3400 0
534 -5000 -3350 0
535 -5000 -3300 0
536 -5000 -3250 0
537 -5000 -3200 0
538 -5000 -3150 0
539 -5000 -3100 0
540 -5000 -3050 0
541 -5000 -3000 0
542 -5000 -2950 0
543 -5000 -2900 0
544 -5000 -2850 0
545 -5000 -2800 0
546 -5000 -2750 0
547 -5000 -2700 0
548 -5000 -2650 0
549 -5000 -2600 0
550 -5000 -2550 0
551 -5000 -2500 0
552 -5000 -2450 0
553 -5000 -2400 0
554 -5000 -2350 0
555 -5000 -2300 0
556 -5000 -2250 0
557 -5000 -2200 0
558 -5000 -2150 0
559 -5000 -2100 0
560 -5000 -2050 0
561 -5000 -2000 0
562 -5000 -1950 0
563 -5000 -1900 0
564 -5000 -1850 0
565 -5000 -1800 0
566 -5000 -1750 0
567 -5000 -1700 0
568 -5000 -1650 0
569 -5000 -1600 0
570 -5000 -1550 0
571 -5000 -1500 0
572 -5000 -1450 0
573 -5000 -1400 0
574 -5000 -1350 0
575 -5000 -1300 0
576 -5000 -1250 0
577 -5000 -1200 0
578 -5000 -1150 0
579 -5000 -1100 0
580 -5000 -1050 0
581 -5000 -1000 0
582 -5000 -950 0
583 -5000 -900 0
584 -5000 -850 0
585 -5000 -800 0
586 -5000 -750 0
587 -5000 -700 0
588 -5000 -650 0
589 -5000 -600 0
590 -5000 -550 0
591 -5000 -500 0
592 -5000 -450 0
593 -5000 -400 0
594 -5000 -350 0
595 -5000 -300 0
596 -5000 -250 0
597 -5000 -200 0
598 -5000 -150 0
599 -5000 -100 0
600 -5000 -50 0
边界点图形化显示

Triangle库参数开关设置(利用google自动翻译了一下,大概意思差不多)
p
Triangulates a Planar Straight Line Graph (.poly file).
三角化平面直线图
r
Refines a previously generated mesh.
细化之前生成的网格
q
Quality mesh generation with no angles smaller than 20 degrees. An alternate minimum angle may be specified after the `q'.
质量网格生成不小于20度的角度。可在“q”后面指定另一个最小角度。
a
Imposes a maximum triangle area constraint. A fixed area constraint (that applies to every triangle) may be specified after the `a', or varying area constraints may be read from a .poly file or .area file.
施加最大三角形面积约束。固定的区域约束(适用于每个三角形)可以在“a”后面指定,或者可以从.poly文件或.area文件中读取不同的区域约束
u
Imposes a user-defined constraint on triangle size.
对三角形大小施加用户定义的约束。
A
Assigns a regional attribute to each triangle that identifies what segment-bounded region it belongs to.
为每个三角形分配一个区域属性,该属性标识它属于哪个分段边界区域。
c
Encloses the convex hull with segments.
用部分包围凸壳。
D
Conforming Delaunay: use this switch if you want all triangles in the mesh to be Delaunay, and not just constrained Delaunay; or if you want to ensure that all Voronoi vertices lie within the triangulation.
符合Delaunay:如果你想要网格中的所有三角形都是Delaunay,而不只是受约束的Delaunay,请使用这个开关;或者,如果你想确保所有Voronoi顶点都在三角形中
j
Jettisons vertices that are not part of the final triangulation from the output .node file (including duplicate input vertices and vertices ``eaten'' by holes).
抛弃不属于输出的最终三角剖分的顶点。节点文件(包括重复的输入顶点和被洞吃掉的顶点)。
e
Outputs (to an .edge file) a list of edges of the triangulation.
输出三角剖分的边列表(到.edge文件)。
v
Outputs the Voronoi diagram associated with the triangulation. Does not attempt to detect degeneracies, so some Voronoi vertices may be duplicated.
输出与三角剖分相关联的Voronoi图。不尝试检测退化,因此一些Voronoi顶点可能会被复制。
n
Outputs (to a .neigh file) a list of triangles neighboring each triangle.
输出(到.neigh文件)与每个三角形相邻的三角形列表。
g
Outputs the mesh to an Object File Format (.off) file, suitable for viewing with the Geometry Center's Geomview package.
输出网格到一个对象文件格式(.off)文件,适合使用几何中心的Geomview包查看。
B
Suppresses boundary markers in the output .node, .poly, and .edge output files.
取消输出.node、.poly和.edge输出文件中的边界标记。
P
Suppresses the output .poly file. Saves disk space, but you lose the ability to maintain constraining segments on later refinements of the mesh.
抑制输出.poly文件。节省了磁盘空间,但是在以后对网格进行细化时,您将失去维护受限段的能力。
N
Suppresses the output .node file.
抑制输出.node文件。
E
Suppresses the output .ele file.
抑制输出.ele文件。
I
Suppresses mesh iteration numbers.
抑制网格迭代数。
O
Suppresses holes: ignores the holes in the .poly file.
抑制孔:忽略.poly文件中的孔。
X
Suppresses exact arithmetic.
抑制的算术。
z
Numbers all items starting from zero (rather than one). Note that this switch is normally overrided by the value used to number the first vertex of the input .node or .poly file. However, this switch is useful when calling Triangle from another program.
对所有项目从零开始编号(而不是1)。注意,这个开关通常会被用于为输入的.node或.poly文件的第一个顶点编号的值覆盖。但是,当从另一个程序调用Triangle时,这个开关很有用。
o2 |
Generates second-order subparametric elements with six nodes each.
生成每个6个节点的二阶子参数元。
Y
Prohibits the insertion of Steiner points on the mesh boundary. If specified twice (-YY), it prohibits the insertion of Steiner points on any segment, including internal segments.
禁止在网格边界上插入斯坦纳点。如果指定两次(-YY),则禁止在任何段(包括内部段)上插入斯坦纳点。
S
Specifies the maximum number of added Steiner points.
指定添加斯坦纳点的最大数目。
i
Uses the incremental algorithm for Delaunay triangulation, rather than the divide-and-conquer algorithm.
使用增量算法进行Delaunay三角剖分,而不是分治算法。
F
Uses Steven Fortune's sweepline algorithm for Delaunay triangulation, rather than the divide-and-conquer algorithm.
使用Steven Fortune的sweepline算法来进行Delaunay三角剖分,而不是分治算法。
l
Uses only vertical cuts in the divide-and-conquer algorithm. By default, Triangle uses alternating vertical and horizontal cuts, which usually improve the speed except with vertex sets that are small or short and wide. This switch is primarily of theoretical interest.
在分治算法中只使用垂直切割。默认情况下,三角形使用垂直和水平交替切割,这通常会提高速度,除非顶点集较小或较短和较宽。这种转换主要是理论意义上的。
s
Specifies that segments should be forced into the triangulation by recursively splitting them at their midpoints, rather than by generating a constrained Delaunay triangulation. Segment splitting is true to Ruppert's original algorithm, but can create needlessly small triangles. This switch is primarily of theoretical interest.
指定段应该通过递归地在它们的中点分割它们来强制进行三角剖分,而不是通过生成一个受限的Delaunay三角剖分。分段分割是真实的Ruppert的原始算法,但可以创建不必要的小三角形。这种转换主要是理论意义上的。
C
Check the consistency of the final mesh. Uses exact arithmetic for checking, even if the -X switch is used. Useful if you suspect Triangle is buggy.
检查最终网格的一致性。使用精确的算法进行检查,即使使用了-X开关。如果你怀疑三角形有问题,这很有用。
Q
Quiet: Suppresses all explanation of what Triangle is doing, unless an error occurs.
安静:除非出现错误,否则取消所有关于三角的解释。
V
Verbose: Gives detailed information about what Triangle is doing. Add more V's for increasing amount of detail. -V' gives information on algorithmic progress and detailed statistics.
冗长:给出关于Triangle正在做什么的详细信息。增加更多的V来增加细节。' -V'提供有关算法进展和详细统计的信息。
不同开关设置下的三角化显示
triangle C.node


triangle -p C.node

triangle -r C.node

triangle -q C.node




triangle -q35 C.node
















浙公网安备 33010602011771号