/
TopoAlgorithm.cpp
1743 lines (1499 loc) · 65.4 KB
/
TopoAlgorithm.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/***************************************************************************
* Copyright (c) 2005 Imetric 3D GmbH *
* *
* This file is part of the FreeCAD CAx development system. *
* *
* This library is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Library General Public *
* License as published by the Free Software Foundation; either *
* version 2 of the License, or (at your option) any later version. *
* *
* This library is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU Library General Public License for more details. *
* *
* You should have received a copy of the GNU Library General Public *
* License along with this library; see the file COPYING.LIB. If not, *
* write to the Free Software Foundation, Inc., 59 Temple Place, *
* Suite 330, Boston, MA 02111-1307, USA *
* *
***************************************************************************/
#include "PreCompiled.h"
#ifndef _PreComp_
# include <algorithm>
# include <utility>
# include <queue>
#endif
#include <Mod/Mesh/App/WildMagic4/Wm4MeshCurvature.h>
#include <Mod/Mesh/App/WildMagic4/Wm4Vector3.h>
#include "TopoAlgorithm.h"
#include "Iterator.h"
#include "MeshKernel.h"
#include "Algorithm.h"
#include "Evaluation.h"
#include "Triangulation.h"
#include "Definitions.h"
#include <Base/Console.h>
using namespace MeshCore;
MeshTopoAlgorithm::MeshTopoAlgorithm (MeshKernel &rclM)
: _rclMesh(rclM), _needsCleanup(false), _cache(0)
{
}
MeshTopoAlgorithm::~MeshTopoAlgorithm (void)
{
if ( _needsCleanup )
Cleanup();
EndCache();
}
bool MeshTopoAlgorithm::InsertVertex(unsigned long ulFacetPos, const Base::Vector3f& rclPoint)
{
MeshFacet& rclF = _rclMesh._aclFacetArray[ulFacetPos];
MeshFacet clNewFacet1, clNewFacet2;
// insert new point
unsigned long ulPtCnt = _rclMesh._aclPointArray.size();
unsigned long ulPtInd = this->GetOrAddIndex(rclPoint);
unsigned long ulSize = _rclMesh._aclFacetArray.size();
if ( ulPtInd < ulPtCnt )
return false; // the given point is already part of the mesh => creating new facets would be an illegal operation
// adjust the facets
//
// first new facet
clNewFacet1._aulPoints[0] = rclF._aulPoints[1];
clNewFacet1._aulPoints[1] = rclF._aulPoints[2];
clNewFacet1._aulPoints[2] = ulPtInd;
clNewFacet1._aulNeighbours[0] = rclF._aulNeighbours[1];
clNewFacet1._aulNeighbours[1] = ulSize+1;
clNewFacet1._aulNeighbours[2] = ulFacetPos;
// second new facet
clNewFacet2._aulPoints[0] = rclF._aulPoints[2];
clNewFacet2._aulPoints[1] = rclF._aulPoints[0];
clNewFacet2._aulPoints[2] = ulPtInd;
clNewFacet2._aulNeighbours[0] = rclF._aulNeighbours[2];
clNewFacet2._aulNeighbours[1] = ulFacetPos;
clNewFacet2._aulNeighbours[2] = ulSize;
// adjust the neighbour facet
if (rclF._aulNeighbours[1] != ULONG_MAX)
_rclMesh._aclFacetArray[rclF._aulNeighbours[1]].ReplaceNeighbour(ulFacetPos, ulSize);
if (rclF._aulNeighbours[2] != ULONG_MAX)
_rclMesh._aclFacetArray[rclF._aulNeighbours[2]].ReplaceNeighbour(ulFacetPos, ulSize+1);
// original facet
rclF._aulPoints[2] = ulPtInd;
rclF._aulNeighbours[1] = ulSize;
rclF._aulNeighbours[2] = ulSize+1;
// insert new facets
_rclMesh._aclFacetArray.push_back(clNewFacet1);
_rclMesh._aclFacetArray.push_back(clNewFacet2);
return true;
}
bool MeshTopoAlgorithm::SnapVertex(unsigned long ulFacetPos, const Base::Vector3f& rP)
{
MeshFacet& rFace = _rclMesh._aclFacetArray[ulFacetPos];
if (!rFace.HasOpenEdge())
return false;
Base::Vector3f cNo1 = _rclMesh.GetNormal(rFace);
for (unsigned short i=0; i<3; i++)
{
if (rFace._aulNeighbours[i]==ULONG_MAX)
{
const Base::Vector3f& rPt1 = _rclMesh._aclPointArray[rFace._aulPoints[i]];
const Base::Vector3f& rPt2 = _rclMesh._aclPointArray[rFace._aulPoints[(i+1)%3]];
Base::Vector3f cNo2 = (rPt2 - rPt1) % cNo1;
Base::Vector3f cNo3 = (rP - rPt1) % (rPt2 - rPt1);
float fD2 = Base::DistanceP2(rPt1, rPt2);
float fTV = (rP-rPt1) * (rPt2-rPt1);
// Point is on the edge
if ( cNo3.Length() < FLOAT_EPS )
{
unsigned long uCt = _rclMesh.CountFacets();
SplitOpenEdge(ulFacetPos, i, rP);
return uCt < _rclMesh.CountFacets();
}
else if ( (rP - rPt1)*cNo2 > 0.0f && fD2 >= fTV && fTV >= 0.0f )
{
MeshFacet cTria;
cTria._aulPoints[0] = this->GetOrAddIndex(rP);
cTria._aulPoints[1] = rFace._aulPoints[(i+1)%3];
cTria._aulPoints[2] = rFace._aulPoints[i];
cTria._aulNeighbours[1] = ulFacetPos;
rFace._aulNeighbours[i] = _rclMesh.CountFacets();
_rclMesh._aclFacetArray.push_back(cTria);
return true;
}
}
}
return false;
}
void MeshTopoAlgorithm::OptimizeTopology(float fMaxAngle)
{
// For each internal edge get the adjacent facets. When doing an edge swap we must update
// this structure.
std::map<std::pair<unsigned long, unsigned long>, std::vector<unsigned long> > aEdge2Face;
for (MeshFacetArray::_TIterator pI = _rclMesh._aclFacetArray.begin(); pI != _rclMesh._aclFacetArray.end(); ++pI) {
for (int i = 0; i < 3; i++) {
// ignore open edges
if (pI->_aulNeighbours[i] != ULONG_MAX) {
unsigned long ulPt0 = std::min<unsigned long>(pI->_aulPoints[i], pI->_aulPoints[(i+1)%3]);
unsigned long ulPt1 = std::max<unsigned long>(pI->_aulPoints[i], pI->_aulPoints[(i+1)%3]);
aEdge2Face[std::pair<unsigned long, unsigned long>(ulPt0, ulPt1)].push_back(pI - _rclMesh._aclFacetArray.begin());
}
}
}
// fill up this list with all internal edges and perform swap edges until this list is empty
std::list<std::pair<unsigned long, unsigned long> > aEdgeList;
std::map<std::pair<unsigned long, unsigned long>, std::vector<unsigned long> >::iterator pE;
for (pE = aEdge2Face.begin(); pE != aEdge2Face.end(); ++pE) {
if (pE->second.size() == 2) // make sure that we really have an internal edge
aEdgeList.push_back(pE->first);
}
// to be sure to avoid an endless loop
unsigned long uMaxIter = 5 * aEdge2Face.size();
// Perform a swap edge where needed
while (!aEdgeList.empty() && uMaxIter > 0) {
// get the first edge and remove it from the list
std::pair<unsigned long, unsigned long> aEdge = aEdgeList.front();
aEdgeList.pop_front();
uMaxIter--;
// get the adjacent facets to this edge
pE = aEdge2Face.find( aEdge );
// this edge has been removed some iterations before
if (pE == aEdge2Face.end())
continue;
// Is swap edge allowed and sensible?
if (!ShouldSwapEdge(pE->second[0], pE->second[1], fMaxAngle))
continue;
// ok, here we should perform a swap edge to minimize the maximum angle
if ( /*fMax12 > fMax34*/true ) {
// swap the edge
SwapEdge(pE->second[0], pE->second[1]);
MeshFacet& rF1 = _rclMesh._aclFacetArray[pE->second[0]];
MeshFacet& rF2 = _rclMesh._aclFacetArray[pE->second[1]];
unsigned short side1 = rF1.Side(aEdge.first, aEdge.second);
unsigned short side2 = rF2.Side(aEdge.first, aEdge.second);
// adjust the edge list
for (int i=0; i<3; i++) {
std::map<std::pair<unsigned long, unsigned long>, std::vector<unsigned long> >::iterator it;
// first facet
unsigned long ulPt0 = std::min<unsigned long>(rF1._aulPoints[i], rF1._aulPoints[(i+1)%3]);
unsigned long ulPt1 = std::max<unsigned long>(rF1._aulPoints[i], rF1._aulPoints[(i+1)%3]);
it = aEdge2Face.find( std::make_pair(ulPt0, ulPt1) );
if (it != aEdge2Face.end()) {
if (it->second[0] == pE->second[1])
it->second[0] = pE->second[0];
else if (it->second[1] == pE->second[1])
it->second[1] = pE->second[0];
aEdgeList.push_back( it->first );
}
// second facet
ulPt0 = std::min<unsigned long>(rF2._aulPoints[i], rF2._aulPoints[(i+1)%3]);
ulPt1 = std::max<unsigned long>(rF2._aulPoints[i], rF2._aulPoints[(i+1)%3]);
it = aEdge2Face.find( std::make_pair(ulPt0, ulPt1) );
if (it != aEdge2Face.end()) {
if (it->second[0] == pE->second[0])
it->second[0] = pE->second[1];
else if (it->second[1] == pE->second[0])
it->second[1] = pE->second[1];
aEdgeList.push_back( it->first );
}
}
// Now we must remove the edge and replace it through the new edge
unsigned long ulPt0 = std::min<unsigned long>(rF1._aulPoints[(side1+1)%3], rF2._aulPoints[(side2+1)%3]);
unsigned long ulPt1 = std::max<unsigned long>(rF1._aulPoints[(side1+1)%3], rF2._aulPoints[(side2+1)%3]);
std::pair<unsigned long, unsigned long> aNewEdge = std::make_pair(ulPt0, ulPt1);
aEdge2Face[aNewEdge] = pE->second;
aEdge2Face.erase(pE);
}
}
}
// Cosine of the maximum angle in triangle (v1,v2,v3)
static float cos_maxangle(const Base::Vector3f &v1,
const Base::Vector3f &v2,
const Base::Vector3f &v3)
{
float a = Base::Distance(v2,v3);
float b = Base::Distance(v3,v1);
float c = Base::Distance(v1,v2);
float A = a * (b*b + c*c - a*a);
float B = b * (c*c + a*a - b*b);
float C = c * (a*a + b*b - c*c);
return 0.5f * std::min<float>(std::min<float>(A,B),C) / (a*b*c); // min cosine == max angle
}
static float swap_benefit(const Base::Vector3f &v1, const Base::Vector3f &v2,
const Base::Vector3f &v3, const Base::Vector3f &v4)
{
Base::Vector3f n124 = (v4 - v2) % (v1 - v2);
Base::Vector3f n234 = (v3 - v2) % (v4 - v2);
if ((n124 * n234) <= 0.0f)
return 0.0f; // avoid normal flip
return std::max<float>(-cos_maxangle(v1,v2,v3), -cos_maxangle(v1,v3,v4)) -
std::max<float>(-cos_maxangle(v1,v2,v4), -cos_maxangle(v2,v3,v4));
}
float MeshTopoAlgorithm::SwapEdgeBenefit(unsigned long f, int e) const
{
const MeshFacetArray& faces = _rclMesh.GetFacets();
const MeshPointArray& vertices = _rclMesh.GetPoints();
unsigned long n = faces[f]._aulNeighbours[e];
if (n == ULONG_MAX)
return 0.0f; // border edge
unsigned long v1 = faces[f]._aulPoints[e];
unsigned long v2 = faces[f]._aulPoints[(e+1)%3];
unsigned long v3 = faces[f]._aulPoints[(e+2)%3];
unsigned short s = faces[n].Side(faces[f]);
if (s == USHRT_MAX) {
std::cerr << "MeshTopoAlgorithm::SwapEdgeBenefit: error in neighbourhood "
<< "of faces " << f << " and " << n << std::endl;
return 0.0f; // topological error
}
unsigned long v4 = faces[n]._aulPoints[(s+2)%3];
if (v3 == v4) {
std::cerr << "MeshTopoAlgorithm::SwapEdgeBenefit: duplicate faces "
<< f << " and " << n << std::endl;
return 0.0f; // duplicate faces
}
return swap_benefit(vertices[v2], vertices[v3],
vertices[v1], vertices[v4]);
}
typedef std::pair<unsigned long,int> FaceEdge; // (face, edge) pair
typedef std::pair<float, FaceEdge> FaceEdgePriority;
void MeshTopoAlgorithm::OptimizeTopology()
{
// Find all edges that can be swapped and insert them into a
// priority queue
const MeshFacetArray& faces = _rclMesh.GetFacets();
unsigned long nf = _rclMesh.CountFacets();
std::priority_queue<FaceEdgePriority> todo;
for (unsigned long i = 0; i < nf; i++) {
for (int j = 0; j < 3; j++) {
float b = SwapEdgeBenefit(i, j);
if (b > 0.0f)
todo.push(std::make_pair(b, std::make_pair(i, j)));
}
}
// Edges are sorted in decreasing order with respect to their benefit
while (!todo.empty()) {
unsigned long f = todo.top().second.first;
int e = todo.top().second.second;
todo.pop();
// Check again if the swap should still be done
if (SwapEdgeBenefit(f, e) <= 0.0f)
continue;
// OK, swap the edge
unsigned long f2 = faces[f]._aulNeighbours[e];
SwapEdge(f, f2);
// Insert new edges into queue, if necessary
for (int j = 0; j < 3; j++) {
float b = SwapEdgeBenefit(f, j);
if (b > 0.0f)
todo.push(std::make_pair(b, std::make_pair(f, j)));
}
for (int j = 0; j < 3; j++) {
float b = SwapEdgeBenefit(f2, j);
if (b > 0.0f)
todo.push(std::make_pair(b, std::make_pair(f2, j)));
}
}
}
void MeshTopoAlgorithm::DelaunayFlip(float fMaxAngle)
{
// For each internal edge get the adjacent facets.
std::set<std::pair<unsigned long, unsigned long> > aEdge2Face;
unsigned long index = 0;
for (MeshFacetArray::_TIterator pI = _rclMesh._aclFacetArray.begin(); pI != _rclMesh._aclFacetArray.end(); ++pI, index++) {
for (int i = 0; i < 3; i++) {
// ignore open edges
if (pI->_aulNeighbours[i] != ULONG_MAX) {
unsigned long ulFt0 = std::min<unsigned long>(index, pI->_aulNeighbours[i]);
unsigned long ulFt1 = std::max<unsigned long>(index, pI->_aulNeighbours[i]);
aEdge2Face.insert(std::pair<unsigned long, unsigned long>(ulFt0, ulFt1));
}
}
}
Base::Vector3f center;
while (!aEdge2Face.empty()) {
std::set<std::pair<unsigned long, unsigned long> >::iterator it = aEdge2Face.begin();
std::pair<unsigned long, unsigned long> edge = *it;
aEdge2Face.erase(it);
if (ShouldSwapEdge(edge.first, edge.second, fMaxAngle)) {
float radius = _rclMesh.GetFacet(edge.first).CenterOfCircumCircle(center);
radius *= radius;
const MeshFacet& face_1 = _rclMesh._aclFacetArray[edge.first];
const MeshFacet& face_2 = _rclMesh._aclFacetArray[edge.second];
unsigned short side = face_2.Side(edge.first);
Base::Vector3f vertex = _rclMesh.GetPoint(face_2._aulPoints[(side+1)%3]);
if (Base::DistanceP2(center, vertex) < radius) {
SwapEdge(edge.first, edge.second);
for (int i=0; i<3; i++) {
if (face_1._aulNeighbours[i] != ULONG_MAX && face_1._aulNeighbours[i] != edge.second) {
unsigned long ulFt0 = std::min<unsigned long>(edge.first, face_1._aulNeighbours[i]);
unsigned long ulFt1 = std::max<unsigned long>(edge.first, face_1._aulNeighbours[i]);
aEdge2Face.insert(std::pair<unsigned long, unsigned long>(ulFt0, ulFt1));
}
if (face_2._aulNeighbours[i] != ULONG_MAX && face_2._aulNeighbours[i] != edge.first) {
unsigned long ulFt0 = std::min<unsigned long>(edge.second, face_2._aulNeighbours[i]);
unsigned long ulFt1 = std::max<unsigned long>(edge.second, face_2._aulNeighbours[i]);
aEdge2Face.insert(std::pair<unsigned long, unsigned long>(ulFt0, ulFt1));
}
}
}
}
}
}
int MeshTopoAlgorithm::DelaunayFlip()
{
int cnt_swap=0;
_rclMesh._aclFacetArray.ResetFlag(MeshFacet::TMP0);
size_t cnt_facets = _rclMesh._aclFacetArray.size();
for (unsigned long i=0;i<cnt_facets;i++) {
const MeshFacet& f_face = _rclMesh._aclFacetArray[i];
if (f_face.IsFlag(MeshFacet::TMP0))
continue;
for (int j=0;j<3;j++) {
unsigned long n = f_face._aulNeighbours[j];
if (n != ULONG_MAX) {
const MeshFacet& n_face = _rclMesh._aclFacetArray[n];
if (n_face.IsFlag(MeshFacet::TMP0))
continue;
unsigned short k = n_face.Side(f_face);
MeshGeomFacet f1 = _rclMesh.GetFacet(f_face);
MeshGeomFacet f2 = _rclMesh.GetFacet(n_face);
Base::Vector3f c1, c2, p1, p2;
p1 = f1._aclPoints[(j+2)%3];
p2 = f2._aclPoints[(k+2)%3];
float r1 = f1.CenterOfCircumCircle(c1);
r1 = r1*r1;
float r2 = f2.CenterOfCircumCircle(c2);
r2 = r2*r2;
float d1 = Base::DistanceP2(c1, p2);
float d2 = Base::DistanceP2(c2, p1);
if (d1 < r1 || d2 < r2) {
SwapEdge(i, n);
cnt_swap++;
f_face.SetFlag(MeshFacet::TMP0);
n_face.SetFlag(MeshFacet::TMP0);
}
}
}
}
return cnt_swap;
}
void MeshTopoAlgorithm::AdjustEdgesToCurvatureDirection()
{
std::vector< Wm4::Vector3<float> > aPnts;
MeshPointIterator cPIt( _rclMesh );
aPnts.reserve(_rclMesh.CountPoints());
for ( cPIt.Init(); cPIt.More(); cPIt.Next() )
aPnts.emplace_back( cPIt->x, cPIt->y, cPIt->z );
// get all point connections
std::vector<int> aIdx;
const MeshFacetArray& raFts = _rclMesh.GetFacets();
aIdx.reserve( 3*raFts.size() );
// Build map of edges to the referencing facets
unsigned long k = 0;
std::map<std::pair<unsigned long, unsigned long>, std::list<unsigned long> > aclEdgeMap;
for ( std::vector<MeshFacet>::const_iterator jt = raFts.begin(); jt != raFts.end(); ++jt, k++ )
{
for (int i=0; i<3; i++)
{
unsigned long ulT0 = jt->_aulPoints[i];
unsigned long ulT1 = jt->_aulPoints[(i+1)%3];
unsigned long ulP0 = std::min<unsigned long>(ulT0, ulT1);
unsigned long ulP1 = std::max<unsigned long>(ulT0, ulT1);
aclEdgeMap[std::make_pair(ulP0, ulP1)].push_front(k);
aIdx.push_back( static_cast<int>(jt->_aulPoints[i]) );
}
}
// compute vertex based curvatures
Wm4::MeshCurvature<float> meshCurv(static_cast<int>(_rclMesh.CountPoints()), &(aPnts[0]),
static_cast<int>(_rclMesh.CountFacets()), &(aIdx[0]));
// get curvature information now
const Wm4::Vector3<float>* aMaxCurvDir = meshCurv.GetMaxDirections();
const Wm4::Vector3<float>* aMinCurvDir = meshCurv.GetMinDirections();
const float* aMaxCurv = meshCurv.GetMaxCurvatures();
const float* aMinCurv = meshCurv.GetMinCurvatures();
raFts.ResetFlag(MeshFacet::VISIT);
const MeshPointArray& raPts = _rclMesh.GetPoints();
for ( std::map<std::pair<unsigned long, unsigned long>, std::list<unsigned long> >::iterator kt = aclEdgeMap.begin(); kt != aclEdgeMap.end(); ++kt )
{
if ( kt->second.size() == 2 ) {
unsigned long uPt1 = kt->first.first;
unsigned long uPt2 = kt->first.second;
unsigned long uFt1 = kt->second.front();
unsigned long uFt2 = kt->second.back();
const MeshFacet& rFace1 = raFts[uFt1];
const MeshFacet& rFace2 = raFts[uFt2];
if ( rFace1.IsFlag(MeshFacet::VISIT) || rFace2.IsFlag(MeshFacet::VISIT) )
continue;
unsigned long uPt3, uPt4;
unsigned short side = rFace1.Side(uPt1, uPt2);
uPt3 = rFace1._aulPoints[(side+2)%3];
side = rFace2.Side(uPt1, uPt2);
uPt4 = rFace2._aulPoints[(side+2)%3];
Wm4::Vector3<float> dir;
float fActCurvature;
if ( fabs(aMinCurv[uPt1]) > fabs(aMaxCurv[uPt1]) ) {
fActCurvature = aMinCurv[uPt1];
dir = aMaxCurvDir[uPt1];
} else {
fActCurvature = aMaxCurv[uPt1];
dir = aMinCurvDir[uPt1];
}
Base::Vector3f cMinDir(dir.X(), dir.Y(), dir.Z());
Base::Vector3f cEdgeDir1 = raPts[uPt1] - raPts[uPt2];
Base::Vector3f cEdgeDir2 = raPts[uPt3] - raPts[uPt4];
cMinDir.Normalize(); cEdgeDir1.Normalize(); cEdgeDir2.Normalize();
// get the plane and calculate the distance to the fourth point
MeshGeomFacet cPlane(raPts[uPt1], raPts[uPt2], raPts[uPt3]);
// positive or negative distance
float fDist = raPts[uPt4].DistanceToPlane(cPlane._aclPoints[0], cPlane.GetNormal());
float fLength12 = Base::Distance(raPts[uPt1], raPts[uPt2]);
float fLength34 = Base::Distance(raPts[uPt3], raPts[uPt4]);
if ( fabs(cEdgeDir1*cMinDir) < fabs(cEdgeDir2*cMinDir) )
{
if ( IsSwapEdgeLegal(uFt1, uFt2) && fLength34 < 1.05f*fLength12 && fActCurvature*fDist > 0.0f) {
SwapEdge(uFt1, uFt2);
rFace1.SetFlag(MeshFacet::VISIT);
rFace2.SetFlag(MeshFacet::VISIT);
}
}
}
}
}
bool MeshTopoAlgorithm::InsertVertexAndSwapEdge(unsigned long ulFacetPos, const Base::Vector3f& rclPoint, float fMaxAngle)
{
if ( !InsertVertex(ulFacetPos, rclPoint) )
return false;
// get the created elements
unsigned long ulF1Ind = _rclMesh._aclFacetArray.size()-2;
unsigned long ulF2Ind = _rclMesh._aclFacetArray.size()-1;
MeshFacet& rclF1 = _rclMesh._aclFacetArray[ulFacetPos];
MeshFacet& rclF2 = _rclMesh._aclFacetArray[ulF1Ind];
MeshFacet& rclF3 = _rclMesh._aclFacetArray[ulF2Ind];
// first facet
int i;
for ( i=0; i<3; i++ )
{
unsigned long uNeighbour = rclF1._aulNeighbours[i];
if ( uNeighbour!=ULONG_MAX && uNeighbour!=ulF1Ind && uNeighbour!=ulF2Ind )
{
if ( ShouldSwapEdge(ulFacetPos, uNeighbour, fMaxAngle) ) {
SwapEdge(ulFacetPos, uNeighbour);
break;
}
}
}
for ( i=0; i<3; i++ )
{
// second facet
unsigned long uNeighbour = rclF2._aulNeighbours[i];
if ( uNeighbour!=ULONG_MAX && uNeighbour!=ulFacetPos && uNeighbour!=ulF2Ind )
{
if ( ShouldSwapEdge(ulF1Ind, uNeighbour, fMaxAngle) ) {
SwapEdge(ulF1Ind, uNeighbour);
break;
}
}
}
// third facet
for ( i=0; i<3; i++ )
{
unsigned long uNeighbour = rclF3._aulNeighbours[i];
if ( uNeighbour!=ULONG_MAX && uNeighbour!=ulFacetPos && uNeighbour!=ulF1Ind )
{
if ( ShouldSwapEdge(ulF2Ind, uNeighbour, fMaxAngle) ) {
SwapEdge(ulF2Ind, uNeighbour);
break;
}
}
}
return true;
}
bool MeshTopoAlgorithm::IsSwapEdgeLegal(unsigned long ulFacetPos, unsigned long ulNeighbour) const
{
MeshFacet& rclF = _rclMesh._aclFacetArray[ulFacetPos];
MeshFacet& rclN = _rclMesh._aclFacetArray[ulNeighbour];
unsigned short uFSide = rclF.Side(rclN);
unsigned short uNSide = rclN.Side(rclF);
if (uFSide == USHRT_MAX || uNSide == USHRT_MAX)
return false; // not neighbours
Base::Vector3f cP1 = _rclMesh._aclPointArray[rclF._aulPoints[uFSide]];
Base::Vector3f cP2 = _rclMesh._aclPointArray[rclF._aulPoints[(uFSide+1)%3]];
Base::Vector3f cP3 = _rclMesh._aclPointArray[rclF._aulPoints[(uFSide+2)%3]];
Base::Vector3f cP4 = _rclMesh._aclPointArray[rclN._aulPoints[(uNSide+2)%3]];
// do not allow to create degenerated triangles
MeshGeomFacet cT3(cP4, cP3, cP1);
if (cT3.IsDegenerated(MeshDefinitions::_fMinPointDistanceP2))
return false;
MeshGeomFacet cT4(cP3, cP4, cP2);
if (cT4.IsDegenerated(MeshDefinitions::_fMinPointDistanceP2))
return false;
// We must make sure that the two adjacent triangles builds a convex polygon, otherwise
// the swap edge operation is illegal
Base::Vector3f cU = cP2-cP1;
Base::Vector3f cV = cP4-cP3;
// build a helper plane through cP1 that must separate cP3 and cP4
Base::Vector3f cN1 = (cU % cV) % cU;
if (((cP3-cP1)*cN1)*((cP4-cP1)*cN1) >= 0.0f)
return false; // not convex
// build a helper plane through cP3 that must separate cP1 and cP2
Base::Vector3f cN2 = (cU % cV) % cV;
if (((cP1-cP3)*cN2)*((cP2-cP3)*cN2) >= 0.0f)
return false; // not convex
return true;
}
bool MeshTopoAlgorithm::ShouldSwapEdge(unsigned long ulFacetPos, unsigned long ulNeighbour, float fMaxAngle) const
{
if (!IsSwapEdgeLegal(ulFacetPos, ulNeighbour))
return false;
MeshFacet& rclF = _rclMesh._aclFacetArray[ulFacetPos];
MeshFacet& rclN = _rclMesh._aclFacetArray[ulNeighbour];
unsigned short uFSide = rclF.Side(rclN);
unsigned short uNSide = rclN.Side(rclF);
Base::Vector3f cP1 = _rclMesh._aclPointArray[rclF._aulPoints[uFSide]];
Base::Vector3f cP2 = _rclMesh._aclPointArray[rclF._aulPoints[(uFSide+1)%3]];
Base::Vector3f cP3 = _rclMesh._aclPointArray[rclF._aulPoints[(uFSide+2)%3]];
Base::Vector3f cP4 = _rclMesh._aclPointArray[rclN._aulPoints[(uNSide+2)%3]];
MeshGeomFacet cT1(cP1, cP2, cP3); float fMax1 = cT1.MaximumAngle();
MeshGeomFacet cT2(cP2, cP1, cP4); float fMax2 = cT2.MaximumAngle();
MeshGeomFacet cT3(cP4, cP3, cP1); float fMax3 = cT3.MaximumAngle();
MeshGeomFacet cT4(cP3, cP4, cP2); float fMax4 = cT4.MaximumAngle();
// get the angle between the triangles
Base::Vector3f cN1 = cT1.GetNormal();
Base::Vector3f cN2 = cT2.GetNormal();
if (cN1.GetAngle(cN2) > fMaxAngle)
return false;
float fMax12 = std::max<float>(fMax1, fMax2);
float fMax34 = std::max<float>(fMax3, fMax4);
return fMax12 > fMax34;
}
void MeshTopoAlgorithm::SwapEdge(unsigned long ulFacetPos, unsigned long ulNeighbour)
{
MeshFacet& rclF = _rclMesh._aclFacetArray[ulFacetPos];
MeshFacet& rclN = _rclMesh._aclFacetArray[ulNeighbour];
unsigned short uFSide = rclF.Side(rclN);
unsigned short uNSide = rclN.Side(rclF);
if (uFSide == USHRT_MAX || uNSide == USHRT_MAX)
return; // not neighbours
// adjust the neighbourhood
if (rclF._aulNeighbours[(uFSide+1)%3] != ULONG_MAX)
_rclMesh._aclFacetArray[rclF._aulNeighbours[(uFSide+1)%3]].ReplaceNeighbour(ulFacetPos, ulNeighbour);
if (rclN._aulNeighbours[(uNSide+1)%3] != ULONG_MAX)
_rclMesh._aclFacetArray[rclN._aulNeighbours[(uNSide+1)%3]].ReplaceNeighbour(ulNeighbour, ulFacetPos);
// swap the point and neighbour indices
rclF._aulPoints[(uFSide+1)%3] = rclN._aulPoints[(uNSide+2)%3];
rclN._aulPoints[(uNSide+1)%3] = rclF._aulPoints[(uFSide+2)%3];
rclF._aulNeighbours[uFSide] = rclN._aulNeighbours[(uNSide+1)%3];
rclN._aulNeighbours[uNSide] = rclF._aulNeighbours[(uFSide+1)%3];
rclF._aulNeighbours[(uFSide+1)%3] = ulNeighbour;
rclN._aulNeighbours[(uNSide+1)%3] = ulFacetPos;
}
bool MeshTopoAlgorithm::SplitEdge(unsigned long ulFacetPos, unsigned long ulNeighbour, const Base::Vector3f& rP)
{
MeshFacet& rclF = _rclMesh._aclFacetArray[ulFacetPos];
MeshFacet& rclN = _rclMesh._aclFacetArray[ulNeighbour];
unsigned short uFSide = rclF.Side(rclN);
unsigned short uNSide = rclN.Side(rclF);
if (uFSide == USHRT_MAX || uNSide == USHRT_MAX)
return false; // not neighbours
unsigned long uPtCnt = _rclMesh._aclPointArray.size();
unsigned long uPtInd = this->GetOrAddIndex(rP);
unsigned long ulSize = _rclMesh._aclFacetArray.size();
// the given point is already part of the mesh => creating new facets would
// be an illegal operation
if (uPtInd < uPtCnt)
return false;
// adjust the neighbourhood
if (rclF._aulNeighbours[(uFSide+1)%3] != ULONG_MAX)
_rclMesh._aclFacetArray[rclF._aulNeighbours[(uFSide+1)%3]].ReplaceNeighbour(ulFacetPos, ulSize);
if (rclN._aulNeighbours[(uNSide+2)%3] != ULONG_MAX)
_rclMesh._aclFacetArray[rclN._aulNeighbours[(uNSide+2)%3]].ReplaceNeighbour(ulNeighbour, ulSize+1);
MeshFacet cNew1, cNew2;
cNew1._aulPoints[0] = uPtInd;
cNew1._aulPoints[1] = rclF._aulPoints[(uFSide+1)%3];
cNew1._aulPoints[2] = rclF._aulPoints[(uFSide+2)%3];
cNew1._aulNeighbours[0] = ulSize+1;
cNew1._aulNeighbours[1] = rclF._aulNeighbours[(uFSide+1)%3];
cNew1._aulNeighbours[2] = ulFacetPos;
cNew2._aulPoints[0] = rclN._aulPoints[uNSide];
cNew2._aulPoints[1] = uPtInd;
cNew2._aulPoints[2] = rclN._aulPoints[(uNSide+2)%3];
cNew2._aulNeighbours[0] = ulSize;
cNew2._aulNeighbours[1] = ulNeighbour;
cNew2._aulNeighbours[2] = rclN._aulNeighbours[(uNSide+2)%3];
// adjust the facets
rclF._aulPoints[(uFSide+1)%3] = uPtInd;
rclF._aulNeighbours[(uFSide+1)%3] = ulSize;
rclN._aulPoints[uNSide] = uPtInd;
rclN._aulNeighbours[(uNSide+2)%3] = ulSize+1;
// insert new facets
_rclMesh._aclFacetArray.push_back(cNew1);
_rclMesh._aclFacetArray.push_back(cNew2);
return true;
}
void MeshTopoAlgorithm::SplitOpenEdge(unsigned long ulFacetPos, unsigned short uSide, const Base::Vector3f& rP)
{
MeshFacet& rclF = _rclMesh._aclFacetArray[ulFacetPos];
if (rclF._aulNeighbours[uSide] != ULONG_MAX)
return; // not open
unsigned long uPtCnt = _rclMesh._aclPointArray.size();
unsigned long uPtInd = this->GetOrAddIndex(rP);
unsigned long ulSize = _rclMesh._aclFacetArray.size();
if (uPtInd < uPtCnt)
return; // the given point is already part of the mesh => creating new facets would be an illegal operation
// adjust the neighbourhood
if (rclF._aulNeighbours[(uSide+1)%3] != ULONG_MAX)
_rclMesh._aclFacetArray[rclF._aulNeighbours[(uSide+1)%3]].ReplaceNeighbour(ulFacetPos, ulSize);
MeshFacet cNew;
cNew._aulPoints[0] = uPtInd;
cNew._aulPoints[1] = rclF._aulPoints[(uSide+1)%3];
cNew._aulPoints[2] = rclF._aulPoints[(uSide+2)%3];
cNew._aulNeighbours[0] = ULONG_MAX;
cNew._aulNeighbours[1] = rclF._aulNeighbours[(uSide+1)%3];
cNew._aulNeighbours[2] = ulFacetPos;
// adjust the facets
rclF._aulPoints[(uSide+1)%3] = uPtInd;
rclF._aulNeighbours[(uSide+1)%3] = ulSize;
// insert new facets
_rclMesh._aclFacetArray.push_back(cNew);
}
bool MeshTopoAlgorithm::Vertex_Less::operator ()(const Base::Vector3f& u,
const Base::Vector3f& v) const
{
if (fabs (u.x - v.x) > FLOAT_EPS)
return u.x < v.x;
if (fabs (u.y - v.y) > FLOAT_EPS)
return u.y < v.y;
if (fabs (u.z - v.z) > FLOAT_EPS)
return u.z < v.z;
return false;
}
void MeshTopoAlgorithm::BeginCache()
{
if (_cache) {
delete _cache;
}
_cache = new tCache();
unsigned long nbPoints = _rclMesh._aclPointArray.size();
for (unsigned int pntCpt = 0 ; pntCpt < nbPoints ; ++pntCpt) {
_cache->insert(std::make_pair(_rclMesh._aclPointArray[pntCpt],pntCpt));
}
}
void MeshTopoAlgorithm::EndCache()
{
if (_cache) {
_cache->clear();
delete _cache;
_cache = 0;
}
}
unsigned long MeshTopoAlgorithm::GetOrAddIndex (const MeshPoint &rclPoint)
{
if (!_cache)
return _rclMesh._aclPointArray.GetOrAddIndex(rclPoint);
unsigned long sz = _rclMesh._aclPointArray.size();
std::pair<tCache::iterator,bool> retval = _cache->insert(std::make_pair(rclPoint,sz));
if (retval.second)
_rclMesh._aclPointArray.push_back(rclPoint);
return retval.first->second;
}
std::vector<unsigned long> MeshTopoAlgorithm::GetFacetsToPoint(unsigned long uFacetPos, unsigned long uPointPos) const
{
// get all facets this point is referenced by
std::list<unsigned long> aReference;
aReference.push_back(uFacetPos);
std::set<unsigned long> aRefFacet;
while (!aReference.empty()) {
unsigned long uIndex = aReference.front();
aReference.pop_front();
aRefFacet.insert(uIndex);
MeshFacet& rFace = _rclMesh._aclFacetArray[uIndex];
for (int i=0; i<3; i++) {
if (rFace._aulPoints[i] == uPointPos) {
if (rFace._aulNeighbours[i] != ULONG_MAX) {
if (aRefFacet.find(rFace._aulNeighbours[i]) == aRefFacet.end())
aReference.push_back( rFace._aulNeighbours[i] );
}
if (rFace._aulNeighbours[(i+2)%3] != ULONG_MAX) {
if (aRefFacet.find(rFace._aulNeighbours[(i+2)%3]) == aRefFacet.end())
aReference.push_back( rFace._aulNeighbours[(i+2)%3] );
}
break;
}
}
}
//copy the items
std::vector<unsigned long> aRefs;
aRefs.insert(aRefs.end(), aRefFacet.begin(), aRefFacet.end());
return aRefs;
}
void MeshTopoAlgorithm::Cleanup()
{
_rclMesh.RemoveInvalids();
_needsCleanup = false;
}
bool MeshTopoAlgorithm::CollapseVertex(const VertexCollapse& vc)
{
if (vc._circumFacets.size() != vc._circumPoints.size())
return false;
if (vc._circumFacets.size() != 3)
return false;
if (!_rclMesh._aclPointArray[vc._point].IsValid())
return false; // the point is marked invalid from a previous run
MeshFacet& rFace1 = _rclMesh._aclFacetArray[vc._circumFacets[0]];
MeshFacet& rFace2 = _rclMesh._aclFacetArray[vc._circumFacets[1]];
MeshFacet& rFace3 = _rclMesh._aclFacetArray[vc._circumFacets[2]];
// get the point that is not shared by rFace1
unsigned long ptIndex = ULONG_MAX;
std::vector<unsigned long>::const_iterator it;
for (it = vc._circumPoints.begin(); it != vc._circumPoints.end(); ++it) {
if (!rFace1.HasPoint(*it)) {
ptIndex = *it;
break;
}
}
if (ptIndex == ULONG_MAX)
return false;
unsigned long neighbour1 = ULONG_MAX;
unsigned long neighbour2 = ULONG_MAX;
const std::vector<unsigned long>& faces = vc._circumFacets;
// get neighbours that are not part of the faces to be removed
for (int i=0; i<3; i++) {
if (std::find(faces.begin(), faces.end(), rFace2._aulNeighbours[i]) == faces.end()) {
neighbour1 = rFace2._aulNeighbours[i];
}
if (std::find(faces.begin(), faces.end(), rFace3._aulNeighbours[i]) == faces.end()) {
neighbour2 = rFace3._aulNeighbours[i];
}
}
// adjust point and neighbour indices
rFace1.Transpose(vc._point, ptIndex);
rFace1.ReplaceNeighbour(vc._circumFacets[1], neighbour1);
rFace1.ReplaceNeighbour(vc._circumFacets[2], neighbour2);
if (neighbour1 != ULONG_MAX) {
MeshFacet& rFace4 = _rclMesh._aclFacetArray[neighbour1];
rFace4.ReplaceNeighbour(vc._circumFacets[1], vc._circumFacets[0]);
}
if (neighbour2 != ULONG_MAX) {
MeshFacet& rFace5 = _rclMesh._aclFacetArray[neighbour2];
rFace5.ReplaceNeighbour(vc._circumFacets[2], vc._circumFacets[0]);
}
// the two facets and the point can be marked for removal
rFace2.SetInvalid();
rFace3.SetInvalid();
_rclMesh._aclPointArray[vc._point].SetInvalid();
_needsCleanup = true;
return true;
}
bool MeshTopoAlgorithm::CollapseEdge(unsigned long ulFacetPos, unsigned long ulNeighbour)
{
MeshFacet& rclF = _rclMesh._aclFacetArray[ulFacetPos];
MeshFacet& rclN = _rclMesh._aclFacetArray[ulNeighbour];
unsigned short uFSide = rclF.Side(rclN);
unsigned short uNSide = rclN.Side(rclF);
if (uFSide == USHRT_MAX || uNSide == USHRT_MAX)
return false; // not neighbours
if (!rclF.IsValid() || !rclN.IsValid())
return false; // the facets are marked invalid from a previous run
// get the point index we want to remove
unsigned long ulPointPos = rclF._aulPoints[uFSide];
unsigned long ulPointNew = rclN._aulPoints[uNSide];
// get all facets this point is referenced by
std::vector<unsigned long> aRefs = GetFacetsToPoint(ulFacetPos, ulPointPos);
for ( std::vector<unsigned long>::iterator it = aRefs.begin(); it != aRefs.end(); ++it )
{
MeshFacet& rFace = _rclMesh._aclFacetArray[*it];
rFace.Transpose( ulPointPos, ulPointNew );
}
// set the new neighbourhood
if (rclF._aulNeighbours[(uFSide+1)%3] != ULONG_MAX)
_rclMesh._aclFacetArray[rclF._aulNeighbours[(uFSide+1)%3]].ReplaceNeighbour(ulFacetPos, rclF._aulNeighbours[(uFSide+2)%3]);
if (rclF._aulNeighbours[(uFSide+2)%3] != ULONG_MAX)
_rclMesh._aclFacetArray[rclF._aulNeighbours[(uFSide+2)%3]].ReplaceNeighbour(ulFacetPos, rclF._aulNeighbours[(uFSide+1)%3]);
if (rclN._aulNeighbours[(uNSide+1)%3] != ULONG_MAX)
_rclMesh._aclFacetArray[rclN._aulNeighbours[(uNSide+1)%3]].ReplaceNeighbour(ulNeighbour, rclN._aulNeighbours[(uNSide+2)%3]);
if (rclN._aulNeighbours[(uNSide+2)%3] != ULONG_MAX)
_rclMesh._aclFacetArray[rclN._aulNeighbours[(uNSide+2)%3]].ReplaceNeighbour(ulNeighbour, rclN._aulNeighbours[(uNSide+1)%3]);
// isolate the both facets and the point
rclF._aulNeighbours[0] = ULONG_MAX;
rclF._aulNeighbours[1] = ULONG_MAX;
rclF._aulNeighbours[2] = ULONG_MAX;
rclF.SetInvalid();
rclN._aulNeighbours[0] = ULONG_MAX;
rclN._aulNeighbours[1] = ULONG_MAX;
rclN._aulNeighbours[2] = ULONG_MAX;
rclN.SetInvalid();
_rclMesh._aclPointArray[ulPointPos].SetInvalid();
_needsCleanup = true;
return true;
}
bool MeshTopoAlgorithm::IsCollapseEdgeLegal(const EdgeCollapse& ec) const
{
// http://stackoverflow.com/a/27049418/148668
// Check connectivity
//
std::vector<unsigned long> commonPoints;
std::set_intersection(ec._adjacentFrom.begin(), ec._adjacentFrom.end(),
ec._adjacentTo.begin(), ec._adjacentTo.end(),
std::back_insert_iterator<std::vector<unsigned long> >(commonPoints));
if (commonPoints.size() > 2) {
return false;
}
// Check geometry
std::vector<unsigned long>::const_iterator it;
for (it = ec._changeFacets.begin(); it != ec._changeFacets.end(); ++it) {
MeshFacet f = _rclMesh._aclFacetArray[*it];
if (!f.IsValid())
return false;
// ignore the facet(s) at this edge
if (f.HasPoint(ec._fromPoint) && f.HasPoint(ec._toPoint))
continue;
MeshGeomFacet tria1 = _rclMesh.GetFacet(f);
f.Transpose(ec._fromPoint, ec._toPoint);
MeshGeomFacet tria2 = _rclMesh.GetFacet(f);
if (tria1.GetNormal() * tria2.GetNormal() < 0.0f)
return false;
}
// If the data structure is valid and the algorithm works as expected
// it should never happen to reject the edge-collapse here!
for (it = ec._removeFacets.begin(); it != ec._removeFacets.end(); ++it) {
MeshFacet f = _rclMesh._aclFacetArray[*it];
if (!f.IsValid())
return false;
}
if (!_rclMesh._aclPointArray[ec._fromPoint].IsValid())
return false;
if (!_rclMesh._aclPointArray[ec._toPoint].IsValid())