forked from mcneel/opennurbs
-
Notifications
You must be signed in to change notification settings - Fork 3
/
opennurbs_brep_isvalid.cpp
1861 lines (1740 loc) · 51.3 KB
/
opennurbs_brep_isvalid.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
/* $NoKeywords: $ */
/*
//
// Copyright (c) 1993-2012 Robert McNeel & Associates. All rights reserved.
// OpenNURBS, Rhinoceros, and Rhino3D are registered trademarks of Robert
// McNeel & Associates.
//
// THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY.
// ALL IMPLIED WARRANTIES OF FITNESS FOR ANY PARTICULAR PURPOSE AND OF
// MERCHANTABILITY ARE HEREBY DISCLAIMED.
//
// For complete openNURBS copyright information see <http://www.opennurbs.org>.
//
////////////////////////////////////////////////////////////////
*/
#include "opennurbs.h"
#if !defined(ON_COMPILING_OPENNURBS)
// This check is included in all opennurbs source .c and .cpp files to insure
// ON_COMPILING_OPENNURBS is defined when opennurbs source is compiled.
// When opennurbs source is being compiled, ON_COMPILING_OPENNURBS is defined
// and the opennurbs .h files alter what is declared and how it is declared.
#error ON_COMPILING_OPENNURBS must be defined when compiling opennurbs
#endif
bool
ON_Brep::IsValidVertexTopology( int vertex_index, ON_TextLog* text_log ) const
{
if ( vertex_index < 0 || vertex_index >= m_V.Count() )
{
if ( text_log )
text_log->Print("brep vertex_index = %d (should be >=0 and <%d=brep.m_V.Count() ).\n",
vertex_index, m_V.Count());
return false;
}
const ON_BrepVertex& vertex = m_V[vertex_index];
if ( vertex.m_vertex_index != vertex_index )
{
if ( text_log )
{
text_log->Print("brep.m_V[%d] vertex is not valid.\n",vertex_index);
text_log->PushIndent();
text_log->Print("vertex.m_vertex_index = %d (should be %d).\n",
vertex.m_vertex_index, vertex_index );
text_log->PopIndent();
}
return false;
}
const int vertex_edge_count = vertex.m_ei.Count();
int i, j, vei, ei;
for ( vei = 0; vei < vertex_edge_count; vei++ )
{
ei = vertex.m_ei[vei];
if ( ei < 0 || ei >= m_E.Count() )
{
if ( text_log )
{
text_log->Print("brep.m_V[%d] vertex is not valid.\n",vertex_index);
text_log->PushIndent();
text_log->Print("vertex.m_ei[%d] = %d (should be >=0 and <%d).\n", vei, ei, m_E.Count());
text_log->PopIndent();
}
return false;
}
const ON_BrepEdge& edge = m_E[ei];
if ( ei != edge.m_edge_index )
{
if ( text_log )
{
text_log->Print("brep.m_V[%d] vertex is not valid.\n",vertex_index);
text_log->PushIndent();
text_log->Print("vertex.m_ei[%d] = %d is a deleted edge.\n", vei, ei);
text_log->PopIndent();
}
return false;
}
if ( edge.m_vi[0] != vertex_index && edge.m_vi[1] != vertex_index )
{
if ( text_log )
{
text_log->Print("brep.m_V[%d] vertex or brep.m_E[%d] edge is not valid.\n",vertex_index,ei);
text_log->PushIndent();
text_log->Print("vertex.m_ei[%d] = %d but brep.m_E[%d].m_vi[] = [%d,%d]. "
"At least one edge m_vi[] value should be %d.\n",
vei,ei,ei,edge.m_vi[0],edge.m_vi[1],vertex_index);
text_log->PopIndent();
}
return false;
}
for ( i = 0; i < vei; i++ )
{
if ( vertex.m_ei[i] == ei )
{
// edge should be closed
if ( edge.m_vi[0] != vertex_index || edge.m_vi[1] != vertex_index )
{
if ( text_log )
{
text_log->Print("brep.m_V[%d] vertex is not valid.\n",vertex_index);
text_log->PushIndent();
text_log->Print("vertex.m_ei[%d] and vertex.m_ei[%d] = %d but brep.m_E[%d].m_vi[0] = %d",
i,vei,ei,ei,edge.m_vi[0]);
text_log->Print("and ON_Brep.m_E[%d].m_vi[1] = %d (both m_vi[] values should be %d).\n",
ei,edge.m_vi[1],vertex_index);
text_log->PopIndent();
}
return false;
}
for (j = i+1; j < vei; j++ )
{
if ( vertex.m_ei[j] == ei )
{
if ( text_log )
{
text_log->Print("brep.m_V[%d] vertex is not valid.\n",vertex_index);
text_log->PushIndent();
text_log->Print("vertex.m_ei[%d,%d,%d] = %d. An open edge index should appear once\n",i,vei,j,ei);
text_log->Print("in vertex.m_ei[] and a closed edge index should appear twice.\n");
text_log->PopIndent();
}
return false;
}
}
break;
}
}
}
return true;
}
bool
ON_Brep::IsValidFaceTopology( int face_index, ON_TextLog* text_log ) const
{
if ( face_index < 0 || face_index >= m_F.Count() )
{
if ( text_log )
{
text_log->Print("brep face_index = %d (should be >=0 and <%d=brep.m_F.Count()).\n",
face_index, m_F.Count());
}
return false;
}
const ON_BrepFace& face = m_F[face_index];
if ( face.m_face_index != face_index )
{
if ( text_log )
{
text_log->Print("brep.m_F[%d] face is not valid.\n",face_index);
text_log->PushIndent();
text_log->Print("face.m_face_index = %d (should be %d).\n",
face.m_face_index, face_index );
text_log->PopIndent();
}
return false;
}
if ( face.m_brep != this )
{
if ( text_log )
{
text_log->Print("brep.m_F[%d] face is not valid.\n",face_index);
text_log->PushIndent();
text_log->Print("face.m_brep does not point to parent brep.\n");
text_log->PopIndent();
}
return false;
}
const int face_loop_count = face.m_li.Count();
if ( face_loop_count <= 0 )
{
if ( text_log )
{
text_log->Print("brep.m_F[%d] face is not valid.\n",face_index);
text_log->PushIndent();
text_log->Print("face.m_li.Count() <= 0 (should be >= 1)\n");
text_log->PopIndent();
}
return false;
}
int i, fli, li;
for ( fli = 0; fli < face_loop_count; fli++ )
{
li = face.m_li[fli];
for ( i = 0; i < fli; i++ )
{
if ( face.m_li[i] == li )
{
if ( text_log )
{
text_log->Print("brep.m_F[%d] face is not valid.\n",face_index);
text_log->PushIndent();
text_log->Print("face.m_li[%d]=face.m_li[%d]=%d (a loop index should appear once in face.m_li[])\n",
fli,i,li);
text_log->PopIndent();
}
return false;
}
}
if ( !IsValidLoop( li, text_log ) )
{
if ( text_log )
{
text_log->Print("brep.m_F[%d] face is not valid.\n",face_index);
text_log->PushIndent();
text_log->Print("brep.m_L[face.m_li[%d]=%d] is not valid.\n",fli,li);
text_log->PopIndent();
}
return false;
}
const ON_BrepLoop& loop = m_L[li];
if ( loop.m_loop_index != li )
{
if ( text_log )
{
text_log->Print("brep.m_F[%d] face is not valid.\n",face_index);
text_log->PushIndent();
text_log->Print("face.m_li[%d]=%d is a deleted loop\n",
fli,li);
text_log->PopIndent();
}
return false;
}
if ( loop.m_fi != face_index )
{
if ( text_log )
{
text_log->Print("brep.m_F[%d] face is not valid.\n",face_index);
text_log->PushIndent();
text_log->Print("face.m_li[%d]=%d but brep.m_L[%d].m_fi=%d (m_fi should be %d)\n",
fli,li,li,loop.m_fi,face_index);
text_log->PopIndent();
}
return false;
}
if ( fli == 0 ) {
if ( loop.m_type != ON_BrepLoop::outer )
{
if ( text_log )
{
text_log->Print("brep.m_F[%d] face is not valid.\n",face_index);
text_log->PushIndent();
text_log->Print("brep.m_L[face.m_li[0]=%d].m_type is not outer.\n",li);
text_log->PopIndent();
}
return false;
}
}
else {
if ( loop.m_type != ON_BrepLoop::inner )
{
if ( text_log )
{
text_log->Print("brep.m_F[%d] face is not valid.\n",face_index);
text_log->PushIndent();
text_log->Print("brep.m_L[face.m_li[%d]=%d].m_type is not inner.\n",fli,li);
text_log->PopIndent();
}
return false;
}
}
}
const int si = face.m_si;
if ( si < 0 || si >= m_S.Count() )
{
if ( text_log )
{
text_log->Print("brep.m_F[%d] face is not valid.\n",face_index);
text_log->PushIndent();
text_log->Print("face.m_si=%d (should be >=0 and <%d=m_S.Count())\n",
face.m_si,m_S.Count());
text_log->PopIndent();
}
return false;
}
if ( 0 == m_S[si] )
{
if ( text_log )
{
text_log->Print("brep.m_F[%d] face is not valid.\n",face_index);
text_log->PushIndent();
text_log->Print("brep.m_S[face.m_si=%d] is nullptr\n",face.m_si);
text_log->PopIndent();
}
return false;
}
if ( 0 == face.ProxySurface() )
{
if ( text_log )
{
text_log->Print("brep.m_F[%d] face is not valid.\n",face_index);
text_log->PushIndent();
text_log->Print("face.ProxySurface() is nullptr\n");
text_log->PopIndent();
}
return false;
}
if ( m_S[si] != face.ProxySurface() )
{
if ( text_log )
{
text_log->Print("brep.m_F[%d] face is not valid.\n",face_index);
text_log->PushIndent();
text_log->Print("brep.m_S[face.m_si=%d] != face.ProxySurface().\n",si);
text_log->PopIndent();
}
return false;
}
if ( face.ProxySurfaceIsTransposed() )
{
if ( text_log )
{
text_log->Print("brep.m_F[%d] face is not valid.\n",face_index);
text_log->PushIndent();
text_log->Print("face.ProxySurfaceIsTransposed() is true.\n");
text_log->PopIndent();
}
return false;
}
return true;
}
bool
ON_Brep::IsValidEdgeTopology( int edge_index, ON_TextLog* text_log ) const
{
if ( edge_index < 0 || edge_index >= m_E.Count() )
{
if ( text_log )
text_log->Print("brep edge_index = %d (should be >=0 and <%d=brep.m_E.Count() ).\n",
edge_index, m_E.Count());
return false;
}
const ON_BrepEdge& edge = m_E[edge_index];
if ( edge.m_edge_index != edge_index )
{
if ( text_log )
{
text_log->Print("brep.m_E[%d] edge is not valid.\n",edge_index);
text_log->PushIndent();
text_log->Print("edge.m_edge_index = %d (should be %d).\n",
edge.m_edge_index, edge_index );
text_log->PopIndent();
}
return false;
}
if ( edge.m_brep != this )
{
if ( text_log )
{
text_log->Print("brep.m_E[%d] edge is not valid.\n",edge_index);
text_log->PushIndent();
text_log->Print("edge.m_brep does not point to parent brep\n");
text_log->PopIndent();
}
return false;
}
if ( !edge.IsValid(text_log) )
{
if ( text_log )
{
text_log->Print("brep.m_E[%d] edge is not valid.\n",edge_index);
text_log->PushIndent();
text_log->Print("edge is not a valid.\n");
text_log->PopIndent();
}
return false;
}
// This checks to make sure that m_C3[] and the edge's proxy information is valid.
// This isn't exactly "topology", but if this stuff isn't set right, then the
// "geometry" checks might crash.
const int c3i = edge.m_c3i;
if ( c3i < 0 || c3i >= m_C3.Count() )
{
if ( text_log )
{
text_log->Print("brep.m_E[%d] edge is not valid.\n",edge_index);
text_log->PushIndent();
text_log->Print("edge.m_c3i = %d (should be >=0 and <%d=m_C3.Count()\n",
edge.m_c3i,m_C3.Count() );
text_log->PopIndent();
}
return false;
}
if ( 0 == m_C3[c3i] )
{
if ( text_log )
text_log->Print("ON_Brep.m_E[%d].m_c3i = %d, but m_C3[%d] is nullptr.\n",edge_index,c3i,c3i);
return false;
}
if ( 0 == edge.ProxyCurve() )
{
if ( text_log )
text_log->Print("brep.m_E[%d].m_c3i = %d, but edge.ProxyCurve() is nullptr.\n",edge_index,c3i);
return false;
}
if ( m_C3[c3i] != edge.ProxyCurve() )
{
if ( text_log )
{
text_log->Print("brep.m_E[%d] edge is not valid.\n",edge_index);
text_log->PushIndent();
text_log->Print("m_E[%d].m_c3i=%d, m_C3[%d] != m_E[%d].ProxyCurve()\n",edge_index,c3i,c3i,edge_index);
text_log->PopIndent();
}
return false;
}
ON_Interval proxy_sub_dom = edge.ProxyCurveDomain();
if ( !proxy_sub_dom.IsIncreasing() )
{
if ( text_log )
{
text_log->Print("brep.m_E[%d] edge is not valid.\n",edge_index);
text_log->PushIndent();
text_log->Print("m_E[%d].ProxyCurveDomain() = (%g,%g) is not increasing\n",edge_index,proxy_sub_dom[0],proxy_sub_dom[1]);
text_log->PopIndent();
}
return false;
}
ON_Interval c3_dom = m_C3[c3i]->Domain();
if ( !c3_dom.Includes(proxy_sub_dom) )
{
if ( text_log )
{
text_log->Print("brep.m_E[%d] edge is not valid.\n",edge_index);
text_log->PushIndent();
text_log->Print("m_C3[%d].Domain() = (%g,%g) does not inlclude m_E[%d].ProxyCurveDomain() = (%g,%g) is not increasing\n",
c3i,c3_dom[0],c3_dom[1],edge_index,proxy_sub_dom[0],proxy_sub_dom[1]);
text_log->PopIndent();
}
return false;
}
ON_Interval edge_dom = edge.Domain();
if ( !edge_dom.IsIncreasing() )
{
if ( text_log )
{
text_log->Print("brep.m_E[%d] trim is not valid.\n",edge_index);
text_log->PushIndent();
text_log->Print("m_E[%d].Domain() = (%g,%g) is not increasing\n",edge_index,edge_dom[0],edge_dom[1]);
text_log->PopIndent();
}
return false;
}
const int vi0 = edge.m_vi[0];
const int vi1 = edge.m_vi[1];
if ( vi0 < 0 || vi0 >= m_V.Count() )
{
if ( text_log )
{
text_log->Print("brep.m_E[%d] edge is not valid.\n",edge_index);
text_log->PushIndent();
text_log->Print("edge.m_vi[0]=%d (should be >=0 and <%d=m_V.Count()\n",
vi0, m_V.Count() );
text_log->PopIndent();
}
return false;
}
if ( vi1 < 0 || vi1 >= m_V.Count() )
{
if ( text_log )
{
text_log->Print("brep.m_E[%d] edge is not valid.\n",edge_index);
text_log->PushIndent();
text_log->Print("edge.m_vi[1]=%d (should be >=0 and <%d=m_V.Count()\n",
vi1, m_V.Count() );
text_log->PopIndent();
}
return false;
}
int evi;
for ( evi = 0; evi < 2; evi++ )
{
const ON_BrepVertex& vertex = m_V[edge.m_vi[evi]];
if ( edge.m_vi[evi] != vertex.m_vertex_index )
{
if ( text_log )
{
text_log->Print("brep.m_E[%d] edge is not valid.\n",edge_index);
text_log->PushIndent();
text_log->Print("edge.m_vi[%d]=%d is a deleted vertex\n",
evi,edge.m_vi[evi] );
text_log->PopIndent();
}
return false;
}
const int vertex_edge_count = vertex.m_ei.Count();
bool bFoundIt = false;
int vei;
for ( vei = 0; vei < vertex_edge_count && !bFoundIt; vei++ )
{
bFoundIt = (vertex.m_ei[vei] == edge_index);
}
if ( !bFoundIt )
{
if ( text_log )
{
text_log->Print("brep.m_E[%d] edge is not valid.\n",edge_index);
text_log->PushIndent();
text_log->Print("edge.m_vi[%d]=%d but edge is not referenced in m_V[%d].m_ei[]\n",
evi,edge.m_vi[evi],edge.m_vi[evi] );
text_log->PopIndent();
}
return false;
}
}
const int edge_trim_count = edge.m_ti.Count();
if ( edge_trim_count < 0 )
{
if ( text_log )
{
text_log->Print("brep.m_E[%d] edge is not valid.\n",edge_index);
text_log->PushIndent();
text_log->Print("edge.m_ti.Count() < 0\n");
text_log->PopIndent();
}
return false;
}
int i, eti, ti;
for (eti = 0; eti < edge_trim_count; eti++ )
{
ti = edge.m_ti[eti];
if ( ti < 0 || ti >= m_T.Count() )
{
if ( text_log )
{
text_log->Print("brep.m_E[%d] edge is not valid.\n",edge_index);
text_log->PushIndent();
text_log->Print("edge.m_ti[%d]=%d (should be >=0 and <%d=m_T.Count())\n",eti,ti);
text_log->PopIndent();
}
return false;
}
if ( m_T[ti].m_trim_index != ti )
{
if ( text_log )
{
text_log->Print("brep.m_E[%d] edge is not valid.\n",edge_index);
text_log->PushIndent();
text_log->Print("edge.m_ti[%d]=%d is a deleted trim\n",eti,ti);
text_log->PopIndent();
}
return false;
}
for ( i = 0; i < eti; i++ )
{
if ( edge.m_ti[i] == ti )
{
if ( text_log )
{
text_log->Print("brep.m_E[%d] edge is not valid.\n",edge_index);
text_log->PushIndent();
text_log->Print("edge.m_ti[%d]=edge.m_ti[%d]=%d (a trim should be referenced once).\n",i,eti,ti);
text_log->PopIndent();
}
return false;
}
}
const ON_BrepTrim& trim = m_T[ti];
if ( trim.m_ei != edge_index )
{
if ( text_log )
{
text_log->Print("brep.m_E[%d] edge is not valid.\n",edge_index);
text_log->PushIndent();
text_log->Print("edge.m_ti[%d]=%d but brep.m_T[%d].m_ei=%d\n",eti,ti,ti,trim.m_ei);
text_log->PopIndent();
}
return false;
}
}
return true;
}
bool
ON_Brep::IsValidLoopTopology( int loop_index, ON_TextLog* text_log ) const
{
int lti, ti;
if ( loop_index < 0 || loop_index >= m_L.Count() )
{
if ( text_log )
text_log->Print("brep loop_index = %d (should be >=0 and <%d=brep.m_L.Count() ).\n",
loop_index, m_L.Count());
return false;
}
const ON_BrepLoop& loop = m_L[loop_index];
if ( loop.m_loop_index != loop_index )
{
if ( text_log )
{
text_log->Print("brep.m_L[%d] loop is not valid.\n",loop_index);
text_log->PushIndent();
text_log->Print("loop.m_loop_index = %d (should be %d).\n",
loop.m_loop_index, loop_index );
text_log->PopIndent();
}
return false;
}
if ( loop.m_brep != this )
{
if ( text_log )
{
text_log->Print("brep.m_L[%d] loop is not valid.\n",loop_index);
text_log->PushIndent();
text_log->Print("loop.m_brep does not point to parent brep\n");
text_log->PopIndent();
}
return false;
}
if ( loop.m_fi < 0 || loop.m_fi >= m_F.Count() )
{
if ( text_log )
text_log->Print("ON_Brep.m_L[%d].m_fi = %d is not invalid.\n",loop_index,loop.m_fi);
return false;
}
if ( m_F[loop.m_fi].m_face_index != loop.m_fi )
{
if ( text_log )
text_log->Print("ON_Brep.m_L[%d].m_fi = %d is a deleted face.\n",loop_index,loop.m_fi);
return false;
}
if ( loop.m_ti.Count() < 1 )
{
if ( text_log )
text_log->Print("ON_Brep.m_L[%d].m_ti.Count() = %d (should be > 0 )\n",loop_index,loop.m_ti.Count());
return false;
}
for ( lti = 0; lti < loop.m_ti.Count(); lti++ )
{
ti = loop.m_ti[lti];
if ( ti < 0 || ti >= m_T.Count() )
{
if ( text_log )
text_log->Print("ON_Brep.m_L[%d].m_ti[%d] = %d is not invalid.\n",loop_index,lti,ti);
return false;
}
const ON_BrepTrim& trim = m_T[ti];
if ( trim.m_trim_index != ti )
{
if ( text_log )
text_log->Print("ON_Brep.m_L[%d].m_ti[%d] = %d is a deleted trim.\n",loop_index,lti,ti);
return false;
}
if ( trim.m_li != loop_index )
{
if ( text_log )
{
text_log->Print("brep loop m_L[%d] or trim m_T[%d] is not valid.\n",loop_index,ti);
text_log->PushIndent();
text_log->Print("loop.m_ti[%d] = %d != %d =trim.m_li\n",lti,ti,trim.m_li);
text_log->PopIndent();
}
return false;
}
}
int first_trim_ti = -4;
int first_trim_vi0 = -3;
int prev_trim_vi1 = -2;
int prev_trim_ti=-9;
for ( lti = 0; lti < loop.m_ti.Count(); lti++ )
{
const ON_BrepTrim& trim = m_T[loop.m_ti[lti]];
if ( 0 == lti )
{
first_trim_ti = loop.m_ti[lti];
first_trim_vi0 = trim.m_vi[0];
}
else if ( prev_trim_vi1 != trim.m_vi[0] )
{
// 23 May 2003 Dale Lear
// Added this test to make sure adjacent trims
// in a loop shared vertices.
if ( text_log )
{
text_log->Print("brep loop m_L[%d] is not valid.\n",loop_index);
text_log->PushIndent();
text_log->Print("m_T[loop.m_ti[%d]=%d].m_vi[1] = %d != m_T[loop.m_ti[%d]=%d].m_vi[0]=%d.\n",
lti-1,prev_trim_ti,prev_trim_vi1,lti,loop.m_ti[lti],trim.m_vi[0]);
text_log->PopIndent();
}
return false;
}
prev_trim_ti = loop.m_ti[lti];
prev_trim_vi1 = trim.m_vi[1];
}
if ( first_trim_ti >= 0 && first_trim_vi0 != prev_trim_vi1 )
{
// 23 May 2003 Dale Lear
// Added this test to make sure adjacent trims
// in a loop shared vertices.
if ( text_log )
{
text_log->Print("brep loop m_L[%d] is not valid.\n",loop_index);
text_log->PushIndent();
text_log->Print("m_T[loop.m_ti[%d]=%d].m_vi[1] = %d != m_T[loop.m_ti[0]=%d].m_vi[0]=%d.\n",
loop.m_ti.Count()-1,prev_trim_ti,prev_trim_vi1,first_trim_ti,first_trim_vi0);
text_log->PopIndent();
}
return false;
}
return true;
}
bool
ON_Brep::IsValidTrimTopology( int trim_index, ON_TextLog* text_log ) const
{
if ( trim_index < 0 || trim_index >= m_T.Count() )
{
if ( text_log )
text_log->Print("brep trim_index = %d (should be >=0 and <%d=brep.m_T.Count() ).\n",
trim_index, m_T.Count());
return false;
}
const ON_BrepTrim& trim = m_T[trim_index];
if ( trim.m_trim_index != trim_index )
{
if ( text_log )
{
text_log->Print("brep.m_T[%d] trim is not valid.\n",trim_index);
text_log->PushIndent();
text_log->Print("trim.m_trim_index = %d (should be %d).\n",
trim.m_trim_index, trim_index );
text_log->PopIndent();
}
return false;
}
if ( trim.m_brep != this )
{
if ( text_log )
{
text_log->Print("brep.m_T[%d] trim is not valid.\n",trim_index);
text_log->PushIndent();
text_log->Print("trim.m_brep does not point to parent brep\n");
text_log->PopIndent();
}
return false;
}
if ( trim.m_vi[0] < 0 || trim.m_vi[0] >= m_V.Count() )
{
if ( text_log )
text_log->Print("ON_Brep.m_T[%d].m_vi[0] = %d is not invalid.\n",trim_index,trim.m_vi[0]);
return false;
}
if ( trim.m_vi[1] < 0 || trim.m_vi[1] >= m_V.Count() )
{
if ( text_log )
text_log->Print("ON_Brep.m_T[%d].m_vi[1] = %d is not invalid.\n",trim_index,trim.m_vi[1]);
return false;
}
if ( m_V[trim.m_vi[0]].m_vertex_index != trim.m_vi[0] )
{
if ( text_log )
text_log->Print("ON_Brep.m_T[%d].m_vi[0] is deleted.\n",trim_index);
return false;
}
if ( m_V[trim.m_vi[1]].m_vertex_index != trim.m_vi[1] )
{
if ( text_log )
text_log->Print("ON_Brep.m_T[%d].m_vi[1] is deleted.\n",trim_index);
return false;
}
if ( trim.m_c2i < 0 || trim.m_c2i >= m_C2.Count() )
{
if ( text_log )
text_log->Print("ON_Brep.m_T[%d].m_c2i = %d is not valid.\n",trim_index,trim.m_c2i);
return false;
}
if ( 0 == m_C2[trim.m_c2i] )
{
if ( text_log )
text_log->Print("ON_Brep.m_T[%d].m_c2i = %d, but m_C2[%d] is nullptr.\n",trim_index,trim.m_c2i,trim.m_c2i);
return false;
}
if ( 0 == trim.ProxyCurve() )
{
if ( text_log )
text_log->Print("brep.m_T[%d].m_c2i = %d, but trim.ProxyCurve() is nullptr.\n",trim_index,trim.m_c2i);
return false;
}
if ( m_C2[trim.m_c2i] != trim.ProxyCurve() )
{
if ( text_log )
{
text_log->Print("brep.m_T[%d] trim is not valid.\n",trim_index);
text_log->PushIndent();
text_log->Print("m_T[%d].m_c2i=%d, m_C2[%d] != m_T[%d].ProxyCurve()\n",
trim_index, trim.m_c2i, trim.m_c2i, trim_index);
text_log->PopIndent();
}
return false;
}
ON_Interval proxy_sub_dom = trim.ProxyCurveDomain();
if ( !proxy_sub_dom.IsIncreasing() )
{
if ( text_log )
{
text_log->Print("brep.m_T[%d] trim is not valid.\n",trim_index);
text_log->PushIndent();
text_log->Print("m_T[%d].ProxyCurveDomain() = (%g,%g) is not increasing\n",trim_index,proxy_sub_dom[0],proxy_sub_dom[1]);
text_log->PopIndent();
}
return false;
}
ON_Interval c2_dom = m_C2[trim.m_c2i]->Domain();
if ( !c2_dom.Includes(proxy_sub_dom) )
{
if ( text_log )
{
text_log->Print("brep.m_T[%d] trim is not valid.\n",trim_index);
text_log->PushIndent();
text_log->Print("m_C2[%d].Domain() = (%g,%g) does not include m_T[%d].ProxyCurveDomain() = (%g,%g) is not increasing\n",
trim.m_c2i,c2_dom[0],c2_dom[1],
trim_index,proxy_sub_dom[0],proxy_sub_dom[1]);
text_log->PopIndent();
}
return false;
}
ON_Interval trim_dom = trim.Domain();
if ( !trim_dom.IsIncreasing() )
{
if ( text_log )
{
text_log->Print("brep.m_T[%d] trim is not valid.\n",trim_index);
text_log->PushIndent();
text_log->Print("m_T[%d].Domain() = (%g,%g) is not increasing\n",trim_index,trim_dom[0],trim_dom[1]);
text_log->PopIndent();
}
return false;
}
if ( trim.m_li < 0 || trim.m_li >= m_L.Count() )
{
if ( text_log )
text_log->Print("ON_Brep.m_T[%d].m_li = %d is not valid.\n",trim_index,trim.m_li);
return false;
}
const ON_BrepLoop& loop = m_L[trim.m_li];
if ( loop.m_loop_index != trim.m_li )
{
if ( text_log )
text_log->Print("ON_Brep.m_T[%d].m_li = %d is a deleted loop.\n",trim_index,trim.m_li);
return false;
}
bool bFoundTrim = false;
int lti, loop_trim_count = loop.m_ti.Count();
for ( lti = 0; lti < loop_trim_count && !bFoundTrim; lti++ )
{
if ( loop.m_ti[lti] == trim_index )
{
bFoundTrim = true;
break;
}
}
if ( !bFoundTrim )
{
if ( text_log )
{
text_log->Print("brep.m_T[%d] trim or brep.m_L[%d] loop is not valid.\n",trim_index,trim.m_li);
text_log->PushIndent();
text_log->Print("trim.m_li = %d but loop.m_ti[] does not contain %d (should appear once in).\n",
trim.m_li,trim_index);
text_log->PopIndent();
}
return false;
}
if ( trim.m_type == ON_BrepTrim::singular )
{
// trim has no 3d edge
if ( trim.m_ei != -1 )
{
if ( text_log )
text_log->Print("ON_Brep.m_T[%d].m_type = singular, but m_ei = %d (should be -1).\n",trim_index,trim.m_ei);
return false;
}
if ( trim.m_bRev3d )
{
if ( text_log )
text_log->Print("ON_Brep.m_T[%d].m_type = singular, but m_bRev3d = %d (should be 0).\n",trim_index,trim.m_bRev3d);
return false;
}
if ( trim.m_vi[0] != trim.m_vi[1] )
{
if ( text_log )
text_log->Print("ON_Brep.m_T[%d].m_type = singular, but m_vi = (%d,%d) (should be same vertex index).\n",
trim_index,trim.m_vi[0],trim.m_vi[1]);
return false;
}
}
else
{
// trim should be connected to a 3d edge
if ( trim.m_ei < 0 || trim.m_ei >= m_E.Count() )
{
if ( text_log )
text_log->Print("ON_Brep.m_T[%d].m_ei = %d is not invalid.\n",trim_index,trim.m_ei);
return false;
}
const ON_BrepEdge& edge = m_E[trim.m_ei];
if ( edge.m_edge_index != trim.m_ei )
{
if ( text_log )
text_log->Print("ON_Brep.m_T[%d].m_ei is deleted.\n",trim_index);
return false;
}
const int evi0 = trim.m_bRev3d ? 1 : 0;
const int evi1 = trim.m_bRev3d ? 0 : 1;
if ( trim.m_vi[0] != edge.m_vi[evi0] )
{
if ( text_log )
text_log->Print("ON_Brep.m_T[%d].m_bRev3d = %d, but m_vi[0] != m_E[m_ei].m_vi[%d].\n",trim_index,trim.m_bRev3d,evi0);
return false;
}
if ( trim.m_vi[1] != edge.m_vi[evi1] )
{
if ( text_log )
text_log->Print("ON_Brep.m_T[%d].m_bRev3d = %d, but m_vi[0] != m_E[m_ei].m_vi[%d].\n",trim_index,trim.m_bRev3d,evi1);
return false;
}
}
return true;
}
bool
ON_Brep::IsValidTopology( ON_TextLog* text_log ) const
{
const int curve2d_count = m_C2.Count();
const int curve3d_count = m_C3.Count();
const int surface_count = m_S.Count();
const int vertex_count = m_V.Count();
const int edge_count = m_E.Count();
const int trim_count = m_T.Count();
const int loop_count = m_L.Count();
const int face_count = m_F.Count();
int vi, ei, fi, ti, li;
if ( 0 == face_count && 0 == edge_count && 0 == vertex_count )
{
if ( text_log )
text_log->Print( "ON_Brep has no faces, edges, or vertices\n");
return false;
}
if ( 0 != face_count )
{