-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathiogOccKernelTools.cpp
1883 lines (1732 loc) · 55.3 KB
/
iogOccKernelTools.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) China Automotive Innovation Corporation.
//
// Author : Xia Lei
// Date : 2022/09/14
//
//=============================================================================
#include "core.h"
#include "comobj.h"
#include "appinterface.h"
#include "config.h"
#include "iogOccKernelTools.h"
//////////////////////////////////////////////////////////////////
//
struct struShellFaces
{
TopTools_ListOfShape faceList;
std::string name;
};
iogOccKernelTools::iogOccKernelTools()
{
}
iogOccKernelTools::~iogOccKernelTools()
{
}
//////////////////////////////////////////////////////////////////
//
bool iogOccKernelTools::shapeFilter(const TopoDS_Shape& origShape, TopAbs_ShapeEnum targetType,
TopoDS_Shape& filterShape)
{
if (origShape.NbChildren() == 1 && origShape.ShapeType() < targetType)
{
TopoDS_Iterator iter(origShape);
return shapeFilter(iter.Value(), targetType, filterShape);
}
else if (origShape.ShapeType() == targetType)
{
filterShape = origShape;
return true;
}
else
{
return false;
}
}
bool iogOccKernelTools::AIsContainedInB(TopoDS_Shape aShape, TopoDS_Shape bShape)
{
TopAbs_ShapeEnum judgetype = aShape.ShapeType();
TopExp_Explorer ex(bShape, judgetype);
for (; ex.More(); ex.Next())
{
if (aShape.IsEqual(ex.Current()))
{
return true;
}
}
return false;
}
bool iogOccKernelTools::IsAIndipendentInTheList(TopoDS_Shape aShape, TopTools_ListOfShape shapeList)
{
for (auto iter : shapeList)
{
bool overlap = false;
if (iter.IsSame(aShape))
{
continue;
}
if (IsShapeGeomSame(iter, aShape, aShape.ShapeType()))
{
continue;
}
TopoDS_Shape commonShape = BRepAlgoAPI_Common(aShape, iter);
TopoDS_Iterator topoiter(commonShape);
for (; topoiter.More(); topoiter.Next())
{
overlap = true;
break;
}
bool connect = false;
TopExp_Explorer edgeex;
for (edgeex.Init(aShape, TopAbs_EDGE); edgeex.More(); edgeex.Next())
{
TopoDS_Edge edge1 = TopoDS::Edge(edgeex.Current());
TopExp_Explorer edgeex2;
for (edgeex2.Init(iter, TopAbs_EDGE); edgeex2.More(); edgeex2.Next())
{
TopoDS_Edge edge2 = TopoDS::Edge(edgeex2.Current());
if (IsShapeGeomSame(edge1, edge2, TopAbs_EDGE))
{
connect = true;
break;
}
}
if (connect)
{
break;
}
}
if (connect || overlap)
{
return false;
}
}
return true;
}
bool iogOccKernelTools::IsShapeGeomSame(const TopoDS_Shape shape1, const TopoDS_Shape shape2,
const TopAbs_ShapeEnum type)
{
try
{
if (shape1.ShapeType() > type || shape2.ShapeType() > type)
return false;
TopoDS_Shape filterShape1, filterShape2;
shapeFilter(shape1, type, filterShape1);
shapeFilter(shape2, type, filterShape2);
if (type == TopAbs_VERTEX)
{
if (BRep_Tool::Pnt(TopoDS::Vertex(filterShape1)).IsEqual(BRep_Tool::Pnt(TopoDS::Vertex(filterShape2)), Precision::Confusion()))
return true;
}
else if (type == TopAbs_EDGE)
{
double start1, end1, start2, end2;
Handle(Geom_Curve) curve1 = BRep_Tool::Curve(TopoDS::Edge(filterShape1), start1, end1);
Handle(Geom_Curve) curve2 = BRep_Tool::Curve(TopoDS::Edge(filterShape2), start2, end2);
if (!curve1 || !curve2)
return false;
if (curve1->Value(start1).IsEqual(curve2->Value(start2), Precision::Confusion()) &&
curve1->Value(end1).IsEqual(curve2->Value(end2), Precision::Confusion()) &&
curve1->Value(0.5 * (start1 + end1)).IsEqual(curve2->Value(0.5 * (start2 + end2)), Precision::Confusion()))
return true;
else if (curve1->Value(start1).IsEqual(curve2->Value(end2), Precision::Confusion()) &&
curve1->Value(end1).IsEqual(curve2->Value(start2), Precision::Confusion()) &&
curve1->Value(0.5 * (start1 + end1)).IsEqual(curve2->Value(0.5 * (start2 + end2)), Precision::Confusion()))
return true;
}
else if (type == TopAbs_FACE)
{
double ustart1, uend1, vstart1, vend1;
double ustart2, uend2, vstart2, vend2;
Handle(Geom_Surface) surface1 = BRep_Tool::Surface(TopoDS::Face(filterShape1));
Handle(Geom_Surface) surface2 = BRep_Tool::Surface(TopoDS::Face(filterShape2));
BRepAdaptor_Surface adp_sur1(TopoDS::Face(filterShape1));
BRepAdaptor_Surface adp_sur2(TopoDS::Face(filterShape2));
ustart1 = adp_sur1.FirstUParameter();
uend1 = adp_sur1.LastUParameter();
vstart1 = adp_sur1.FirstVParameter();
vend1 = adp_sur1.LastVParameter();
ustart2 = adp_sur2.FirstUParameter();
uend2 = adp_sur2.LastUParameter();
vstart2 = adp_sur2.FirstVParameter();
vend2 = adp_sur2.LastVParameter();
if (surface1->Value(ustart1, vstart1).IsEqual(surface2->Value(ustart2, vstart2), Precision::Confusion()) &&
surface1->Value(uend1, vstart1).IsEqual(surface2->Value(uend2, vstart2), Precision::Confusion()) &&
surface1->Value(ustart1, vend1).IsEqual(surface2->Value(ustart2, vend2), Precision::Confusion()) &&
surface1->Value(uend1, vend1).IsEqual(surface2->Value(uend2, vend2), Precision::Confusion()) &&
surface1->Value(0.5 * (ustart1 + uend1), 0.5 * (vstart1 + vend1)).IsEqual(surface2->Value(0.5 * (ustart2 + uend2), 0.5 * (vstart2 + vend2)), Precision::Confusion()))
return true;
}
return false;
}
catch (...)
{
return false;
}
}
//bool iogOccKernelTools::IsFaceSameRole(const TopoDS_Shape shape1, const TopoDS_Shape shape2)
//{
// //Handle(BRepAdaptor_Surface) brepSurf1 = new BRepAdaptor_Surface(TopoDS::Face(shape1));
// //Handle(BRepAdaptor_Surface) brepSurf2 = new BRepAdaptor_Surface(TopoDS::Face(shape1));
//
// //GeomAbs_SurfaceType surfType1 = brepSurf1->GetType();
// //GeomAbs_SurfaceType surfType2 = brepSurf1->GetType();
//
// ///*Handle(Geom_BSplineSurface) bsSurf1 = brepSurf1->BSpline();
// //Handle(Geom_BSplineSurface) bsSurf2 = brepSurf2->BSpline();*/
//
// //int nUDegree1 = brepSurf1->UDegree();
// //int nUDegree2 = brepSurf2->UDegree();
//
// //int nVDegree1 = brepSurf1->VDegree();
// //int nVDegree2 = brepSurf2->VDegree();
//
// //int nUKnots1 = brepSurf1->NbUKnots();
// //int nUKnots2 = brepSurf2->NbUKnots();
//
// //int nVKnots1 = brepSurf1->NbVKnots();
// //int nVKnots2 = brepSurf2->NbVKnots();
//
// //if (nUDegree1 == nUDegree2 && nVDegree1 == nVDegree2 &&
// // nUKnots1 == nUKnots2 && nVKnots1 == nVKnots2)
// //{
// // return true;
// //}
//}
bool iogOccKernelTools::IsFaceSameRole(const TopoDS_Shape shape1, const TopoDS_Shape shape2)
{
if (shape1.ShapeType() != TopAbs_FACE || shape2.ShapeType() != TopAbs_FACE)
{
return false;
}
BRepAdaptor_Surface adp_sur1(TopoDS::Face(shape1));
BRepAdaptor_Surface adp_sur2(TopoDS::Face(shape2));
double ustart1 = adp_sur1.FirstUParameter();
double uend1 = adp_sur1.LastUParameter();
double vstart1 = adp_sur1.FirstVParameter();
double vend1 = adp_sur1.LastVParameter();
double ustart2 = adp_sur2.FirstUParameter();
double uend2 = adp_sur2.LastUParameter();
double vstart2 = adp_sur2.FirstVParameter();
double vend2 = adp_sur2.LastVParameter();
gp_Pnt pntUsVsSurf1 = adp_sur1.Value(ustart1, vstart1);
gp_Pnt pntUsVsSurf2 = adp_sur2.Value(ustart2, vstart2);
double dXPntUsVsSurf1 = pntUsVsSurf1.X();
double dYPntUsVsSurf1 = pntUsVsSurf1.Y();
double dZPntUsVsSurf1 = pntUsVsSurf1.Z();
double dXPntUsVsSurf2 = pntUsVsSurf2.X();
double dYPntUsVsSurf2 = pntUsVsSurf2.Y();
double dZPntUsVsSurf2 = pntUsVsSurf2.Z();
QString qstr1 = QString::number(dXPntUsVsSurf1, 'f', 5) + ","
+ QString::number(dYPntUsVsSurf1, 'f', 5) + ","
+ QString::number(dZPntUsVsSurf1, 'f', 5);
QString qstr2 = QString::number(dXPntUsVsSurf2, 'f', 5) + ","
+ QString::number(dYPntUsVsSurf2, 'f', 5) + ","
+ QString::number(dZPntUsVsSurf2, 'f', 5);
/*if (qstr1 != qstr2)
return false;*/
gp_Pnt pntUeVsSurf1 = adp_sur1.Value(uend1, vstart1);
gp_Pnt pntUeVsSurf2 = adp_sur2.Value(uend2, vstart2);
double dXPntUeVsSurf1 = pntUeVsSurf1.X();
double dYPntUeVsSurf1 = pntUeVsSurf1.Y();
double dZPntUeVsSurf1 = pntUeVsSurf1.Z();
double dXPntUeVsSurf2 = pntUeVsSurf2.X();
double dYPntUeVsSurf2 = pntUeVsSurf2.Y();
double dZPntUeVsSurf2 = pntUeVsSurf2.Z();
QString qstr3 = QString::number(dXPntUeVsSurf1, 'f', 5) + ","
+ QString::number(dYPntUeVsSurf1, 'f', 5) + ","
+ QString::number(dZPntUeVsSurf1, 'f', 5);
QString qstr4 = QString::number(dXPntUeVsSurf2, 'f', 5) + ","
+ QString::number(dYPntUeVsSurf2, 'f', 5) + ","
+ QString::number(dZPntUeVsSurf2, 'f', 5);
/*if (qstr3 != qstr4)
return false;*/
gp_Pnt pntUsVeSurf1 = adp_sur1.Value(ustart1, vend1);
gp_Pnt pntUsVeSurf2 = adp_sur2.Value(ustart2, vend2);
double dXPntUsVeSurf1 = pntUsVeSurf1.X();
double dYPntUsVeSurf1 = pntUsVeSurf1.Y();
double dZPntUsVeSurf1 = pntUsVeSurf1.Z();
double dXPntUsVeSurf2 = pntUsVeSurf2.X();
double dYPntUsVeSurf2 = pntUsVeSurf2.Y();
double dZPntUsVeSurf2 = pntUsVeSurf2.Z();
QString qstr5 = QString::number(dXPntUsVeSurf1, 'f', 5) + ","
+ QString::number(dYPntUsVeSurf1, 'f', 5) + ","
+ QString::number(dZPntUsVeSurf1, 'f', 5);
QString qstr6 = QString::number(dXPntUsVeSurf2, 'f', 5) + ","
+ QString::number(dYPntUsVeSurf2, 'f', 5) + ","
+ QString::number(dZPntUsVeSurf2, 'f', 5);
/*if (qstr5 != qstr6)
return false;*/
gp_Pnt pntUeVeSurf1 = adp_sur1.Value(vend1, vend1);
gp_Pnt pntUeVeSurf2 = adp_sur2.Value(vend2, vend2);
double dXPntUeVeSurf1 = pntUeVeSurf1.X();
double dYPntUeVeSurf1 = pntUeVeSurf1.Y();
double dZPntUeVeSurf1 = pntUeVeSurf1.Z();
double dXPntUeVeSurf2 = pntUeVeSurf2.X();
double dYPntUeVeSurf2 = pntUeVeSurf2.Y();
double dZPntUeVeSurf2 = pntUeVeSurf2.Z();
QString qstr7 = QString::number(dXPntUeVeSurf1, 'f', 5) + ","
+ QString::number(dYPntUeVeSurf1, 'f', 5) + ","
+ QString::number(dZPntUeVeSurf1, 'f', 5);
QString qstr8 = QString::number(dXPntUeVeSurf2, 'f', 5) + ","
+ QString::number(dYPntUeVeSurf2, 'f', 5) + ","
+ QString::number(dZPntUeVeSurf2, 'f', 5);
/*if (qstr7 != qstr8)
return false;*/
gp_Pnt pntUfVfSurf1 = adp_sur1.Value(0.5 * (ustart1 + uend1), 0.5 * (ustart1 + uend1));
gp_Pnt pntUfVfSurf2 = adp_sur2.Value(0.5 * (ustart2 + uend2), 0.5 * (ustart2 + uend2));
double dXPntUfVfSurf1 = pntUfVfSurf1.X();
double dYPntUfVfSurf1 = pntUfVfSurf1.Y();
double dZPntUfVfSurf1 = pntUfVfSurf1.Z();
double dXPntUfVfSurf2 = pntUfVfSurf2.X();
double dYPntUfVfSurf2 = pntUfVfSurf2.Y();
double dZPntUfVfSurf2 = pntUfVfSurf2.Z();
QString qstr9 = QString::number(dXPntUfVfSurf1, 'f', 5) + ","
+ QString::number(dYPntUfVfSurf1, 'f', 5) + ","
+ QString::number(dZPntUfVfSurf1, 'f', 5);
QString qstr10 = QString::number(dXPntUfVfSurf2, 'f', 5) + ","
+ QString::number(dYPntUfVfSurf2, 'f', 5) + ","
+ QString::number(dZPntUfVfSurf2, 'f', 5);
/*if (qstr9 != qstr10)
return false;*/
return false;
}
TopoDS_Shape iogOccKernelTools::makeSpiralHelix(double radiusbottom, double radiustop,
double height, double nbturns,
double breakperiod, bool leftHanded)
{
// 1000 periods is an OCCT limit. The 3D curve gets truncated
// if the 2D curve spans beyond this limit.
if ((breakperiod < 0) || (breakperiod > 1000))
Standard_Failure::Raise("Break period must be in [0, 1000]");
if (breakperiod == 0)
breakperiod = 1000;
if (nbturns <= 0)
Standard_Failure::Raise("Number of turns must be greater than 0");
Standard_Real nbPeriods = nbturns / breakperiod;
Standard_Real nbFullPeriods = floor(nbPeriods);
Standard_Real partPeriod = nbPeriods - nbFullPeriods;
// A Bezier curve is used below, to get a periodic surface also for spirals.
TColgp_Array1OfPnt poles(1, 2);
poles(1) = gp_Pnt(radiusbottom, 0, 0);
poles(2) = gp_Pnt(radiustop, 0, height);
Handle(Geom_BezierCurve) meridian = new Geom_BezierCurve(poles);
gp_Ax1 axis(gp_Pnt(0.0, 0.0, 0.0), gp::DZ());
Handle(Geom_Surface) surf = new Geom_SurfaceOfRevolution(meridian, axis);
gp_Pnt2d beg(0, 0);
gp_Pnt2d end(0, 0);
gp_Vec2d dir(breakperiod * 2.0 * M_PI, 1 / nbPeriods);
if (leftHanded == Standard_True)
dir = gp_Vec2d(-breakperiod * 2.0 * M_PI, 1 / nbPeriods);
Handle(Geom2d_TrimmedCurve) segm;
TopoDS_Edge edgeOnSurf;
BRepBuilderAPI_MakeWire mkWire;
for (unsigned long i = 0; i < nbFullPeriods; i++) {
end = beg.Translated(dir);
segm = GCE2d_MakeSegment(beg, end);
edgeOnSurf = BRepBuilderAPI_MakeEdge(segm, surf);
mkWire.Add(edgeOnSurf);
beg = end;
}
if (partPeriod > Precision::Confusion()) {
dir.Scale(partPeriod);
end = beg.Translated(dir);
segm = GCE2d_MakeSegment(beg, end);
edgeOnSurf = BRepBuilderAPI_MakeEdge(segm, surf);
mkWire.Add(edgeOnSurf);
}
TopoDS_Wire wire = mkWire.Wire();
BRepLib::BuildCurves3d(wire, Precision::Confusion(), GeomAbs_Shape::GeomAbs_C1, 14, 10000);
return TopoDS_Shape(std::move(wire));
}
bool iogOccKernelTools::GetPlanarFaceApexs(TopoDS_Face face, TopTools_ListOfShape& vtxs,
TopTools_ListOfShape& uselessEdges)
{
std::vector<TopoDS_Edge> vecEdges;
TopExp_Explorer edgex(face, TopAbs_EDGE);
for (; edgex.More(); edgex.Next())
{
vecEdges.push_back(TopoDS::Edge(edgex.Current()));
}
for (int i = 0; i < vecEdges.size(); i++)
{
TopoDS_Edge edge1 = vecEdges[i];
ShapeAnalysis_Edge sae;
TopoDS_Vertex vtx11 = sae.FirstVertex(edge1);
gp_Pnt pt11 = BRep_Tool::Pnt(vtx11);
TopoDS_Vertex vtx12 = sae.LastVertex(edge1);
gp_Pnt pt12 = BRep_Tool::Pnt(vtx12);
for (int j = 0; j < vecEdges.size(); j++)
{
TopoDS_Edge edge2 = vecEdges[j];
if (edge1.IsSame(edge2))
{
continue;
}
TopoDS_Vertex vtx21 = sae.FirstVertex(edge2);
gp_Pnt pt21 = BRep_Tool::Pnt(vtx21);
TopoDS_Vertex vtx22 = sae.LastVertex(edge2);
gp_Pnt pt22 = BRep_Tool::Pnt(vtx22);
bool ifcontinue = true;
if (pt12.X() == pt21.X() &&
pt12.Y() == pt21.Y() &&
pt12.Z() == pt21.Z())
{
ifcontinue = false;
}
if (ifcontinue)
{
continue;
}
gp_Dir dir1(pt12.X() - pt11.X(), pt12.Y() - pt11.Y(), pt12.Z() - pt11.Z());
gp_Dir dir2(pt22.X() - pt21.X(), pt22.Y() - pt21.Y(), pt22.Z() - pt21.Z());
if (!dir1.IsParallel(dir2, 0.1))
{
if (!vtxs.Contains(vtx21))
{
vtxs.Append(vtx21);
}
}
else
{
if (!uselessEdges.Contains(edge2))
{
uselessEdges.Append(edge2);
}
}
}
}
return true;
}
bool iogOccKernelTools::ReOrgnizeEdgeOrderWire(TopTools_ListOfShape& edges, TopoDS_Vertex vtx,
std::vector<TopoDS_Shape>& newOrderEdges)
{
std::vector<TopoDS_Shape> vecOrder;
for (auto iter : edges)
{
vecOrder.push_back(iter);
}
int count = -1;
for (int i = 0; i < vecOrder.size(); i++)
{
count++;
TopoDS_Edge edge1 = TopoDS::Edge(vecOrder[i]);
ShapeAnalysis_Edge sae;
TopoDS_Vertex vtx11 = sae.FirstVertex(edge1);
if (IsShapeGeomSame(vtx11, vtx, TopAbs_VERTEX))
{
break;
}
}
for (int i = count; i < vecOrder.size(); i++)
{
newOrderEdges.push_back(vecOrder[i]);
}
for (int i = 0; i < count; i++)
{
newOrderEdges.push_back(vecOrder[i]);
}
return true;
}
bool iogOccKernelTools::GroupEdgesInWire(std::vector<TopoDS_Shape>& edges,
std::vector<std::vector<TopoDS_Shape>>& groups)
{
if (edges.size() <= 0)
return false;
std::vector<TopoDS_Shape> group;
group.push_back(edges[0]);
int count = -1;
for (int i = 0; i < edges.size() - 1; i++)
{
TopoDS_Edge edge1 = TopoDS::Edge(edges[i]);
ShapeAnalysis_Edge sae1;
TopoDS_Vertex vtx11 = sae1.FirstVertex(edge1);
gp_Pnt pt11 = BRep_Tool::Pnt(vtx11);
TopoDS_Vertex vtx12 = sae1.LastVertex(edge1);
gp_Pnt pt12 = BRep_Tool::Pnt(vtx12);
TopoDS_Edge edge2 = TopoDS::Edge(edges[i+1]);
ShapeAnalysis_Edge sae2;
TopoDS_Vertex vtx21 = sae2.FirstVertex(edge2);
gp_Pnt pt21 = BRep_Tool::Pnt(vtx21);
TopoDS_Vertex vtx22 = sae2.LastVertex(edge2);
gp_Pnt pt22 = BRep_Tool::Pnt(vtx22);
gp_Dir dir1(pt12.X() - pt11.X(), pt12.Y() - pt11.Y(), pt12.Z() - pt11.Z());
gp_Dir dir2(pt22.X() - pt21.X(), pt22.Y() - pt21.Y(), pt22.Z() - pt21.Z());
if (dir1.IsParallel(dir2, 0.1))
{
group.push_back(edges[i + 1]);
}
else
{
count = i + 1;
break;
}
}
std::vector<TopoDS_Shape> newEdges;
for (int i = count; i < edges.size(); i++)
{
newEdges.push_back(edges[i]);
}
groups.push_back(group);
GroupEdgesInWire(newEdges, groups);
return true;
}
bool iogOccKernelTools::ReOrderEdgesInWire(std::vector<std::vector<TopoDS_Shape>>& groups, TopoDS_Wire &wire)
{
BRepBuilderAPI_MakeWire mkwire;
for (int i = 0; i < groups.size(); i++)
{
std::vector<TopoDS_Shape> group = groups[i];
if (group.size() == 1)
{
mkwire.Add(TopoDS::Edge(group[0]));
}
else if (group.size() > 1)
{
GeomConvert_CompCurveToBSplineCurve gcc;
for (int j = 0; j < group.size(); j++)
{
TopoDS_Edge xedge = TopoDS::Edge(group[j]);
BRepAdaptor_Curve bac(xedge);
double start, end;
start = bac.FirstParameter();
end = bac.LastParameter();
Handle(Geom_Curve) gc = bac.Curve().Curve();
Handle(Geom_TrimmedCurve) gtc = new Geom_TrimmedCurve(gc, start, end);
gcc.Add(gtc, Precision::Confusion());
}
TopoDS_Edge xedge = BRepBuilderAPI_MakeEdge(gcc.BSplineCurve()).Edge();
mkwire.Add(xedge);
}
}
if (mkwire.IsDone())
{
wire = mkwire.Wire();
}
else
{
return false;
}
return true;
}
//分离step文件各特征方法 start
bool iogOccKernelTools::STPSeperateBodies(TopoDS_Shape input, TopoDS_Compound& structuredRegroupShape)
{
//存一下所有面
TopTools_ListOfShape allfaces;
TopExp_Explorer faceex;
for (faceex.Init(input, TopAbs_FACE); faceex.More(); faceex.Next())
{
allfaces.Append(faceex.Current());
}
//存放各个独立体的面
std::vector<std::vector<TopoDS_Face>> independentbodyfaces;
GetIndependentFeatureFacesAndStore(input, allfaces, independentbodyfaces);
if (independentbodyfaces.size() < 1)
{
return false;
}
BRep_Builder bMain;
bMain.MakeCompound(structuredRegroupShape);
for (int i = 0; i < independentbodyfaces.size(); i++)
{
BRep_Builder b;
TopoDS_Compound currentComp;
b.MakeCompound(currentComp);
std::vector<TopoDS_Face> currentFaceList = independentbodyfaces[i];
if (currentFaceList.size() < 1)
{
continue;
}
for (int j = 0; j < currentFaceList.size(); j++)
{
TopoDS_Face cuurentFace = currentFaceList[j];
b.Add(currentComp, cuurentFace);
}
bMain.Add(structuredRegroupShape, currentComp);
}
return true;
}
bool iogOccKernelTools::GetIndependentFeatureFacesAndStore(TopoDS_Shape shape, TopTools_ListOfShape& facepackage,
std::vector<std::vector<TopoDS_Face>>& independentbodyfaces)
{
while (facepackage.Size() > 0)
{
std::vector<TopoDS_Face> featurefaces;
if (!LoopOperate(shape, featurefaces, facepackage))
{
continue;
}
independentbodyfaces.push_back(featurefaces);
}
return true;
}
bool iogOccKernelTools::LoopOperate(TopoDS_Shape shape, std::vector<TopoDS_Face>& featurefaces,
TopTools_ListOfShape& facepackage)
{
if (facepackage.Size() == 0)
return false;
if (facepackage.Size() == 1)
{
featurefaces.push_back(TopoDS::Face(*facepackage.begin()));
return true;
}
TopTools_ListOfShape usedfeatures, reffeaturefaces;
for (auto iter : facepackage)
{
if (usedfeatures.Contains(iter))
continue;
BRepAdaptor_Surface brs(TopoDS::Face(iter));
double uf = brs.FirstUParameter();
double vf = brs.FirstVParameter();
double ue = brs.LastUParameter();
double ve = brs.LastVParameter();
gp_Pnt midFace1 = brs.Value((ue + uf) / 2, (ve + vf) / 2);
/*gp_Dir dir;
if (!FaceNormal(TopoDS::Face(iter), (ue + uf) / 2, (ve + vf) / 2, dir))
continue;*/
for (auto iter2 : facepackage)
{
if (iter2.IsSame(iter))
continue;
if (usedfeatures.Contains(iter))
continue;
TopoDS_Shape common = BRepAlgoAPI_Section(iter, iter2).Shape();
TopoDS_Edge commonedge = TopoDS::Edge(common);
BRepAdaptor_Curve bac(commonedge);
gp_Dir edgedir = bac.DN(bac.FirstParameter(), 1);
gp_Pnt midEdge = bac.Value((bac.FirstParameter() + bac.LastParameter()) / 2);
if (!common.IsNull())
{
BRepAdaptor_Surface xbrs(TopoDS::Face(iter2));
double xuf = xbrs.FirstUParameter();
double xvf = xbrs.FirstVParameter();
double xue = xbrs.LastUParameter();
double xve = xbrs.LastVParameter();
gp_Pnt midFace2 = xbrs.Value((xue + xuf) / 2, (xve + xvf) / 2);
/*gp_Dir xdir;
if (!FaceNormal(TopoDS::Face(iter2), (xue + xuf) / 2, (xve + xvf) / 2, xdir))
continue;
gp_Dir newdir = xdir.Crossed(dir);*/
gp_Dir edgeFace1(midFace1.X() - midEdge.X(),
midFace1.Y() - midEdge.Y(),
midFace1.Z() - midEdge.Z());
gp_Dir edgeFace2(midFace2.X() - midEdge.X(),
midFace2.Y() - midEdge.Y(),
midFace2.Z() - midEdge.Z());
if (edgeFace2.Angle(edgeFace1)>M_PI)
{
if (!usedfeatures.Contains(iter))
{
usedfeatures.Append(iter);
featurefaces.push_back(TopoDS::Face(iter));
}
if (!usedfeatures.Contains(iter2))
{
usedfeatures.Append(iter2);
featurefaces.push_back(TopoDS::Face(iter2));
}
}
}
}
}
for (auto iter : facepackage)
{
if (!usedfeatures.Contains(iter))
reffeaturefaces.Append(iter);
}
facepackage = reffeaturefaces;
return true;
}
//分离step文件各特征方法 end
bool iogOccKernelTools::FaceNormal(const TopoDS_Face face, const double& u,
const double& v, gp_Dir& dir)
{
BRepGProp_Face anaface(face);
double umin, umax, vmin, vmax;
anaface.Bounds(umin, umax, vmin, vmax);
gp_Pnt pnt;
gp_Vec normal;
anaface.Normal(u, v, pnt, normal);
if (normal.Magnitude() == 0)
{
Handle(Geom_Surface) surface = BRep_Tool::Surface(TopoDS::Face(face));
GeomAbs_SurfaceType type;
Handle(Geom_Surface) basicSurf = GetBasicSurface(surface, type);
if (basicSurf->IsKind(STANDARD_TYPE(Geom_SurfaceOfRevolution)))
{
Handle(Geom_SurfaceOfRevolution) finalSurf = Handle(Geom_SurfaceOfRevolution)::DownCast(basicSurf);
normal = finalSurf->Axis().Direction();
}
else if (basicSurf->IsKind(STANDARD_TYPE(Geom_ConicalSurface)))
{
Handle(Geom_ConicalSurface) finalSurf = Handle(Geom_ConicalSurface)::DownCast(basicSurf);
normal = finalSurf->Axis().Direction();
}
else if (basicSurf->IsKind(STANDARD_TYPE(Geom_SphericalSurface)))
{
Handle(Geom_SphericalSurface) finalSurf = Handle(Geom_SphericalSurface)::DownCast(basicSurf);
normal = finalSurf->Axis().Direction();
}
else
return false;
}
dir = gp_Dir(normal);
return true;
}
Handle(Geom_Surface) iogOccKernelTools::GetBasicSurface(Handle(Geom_Surface) surf, GeomAbs_SurfaceType& type)
{
const Handle(Standard_Type)& thetype = surf->DynamicType();
if (thetype == STANDARD_TYPE(Geom_RectangularTrimmedSurface))
{
return GetBasicSurface(Handle(Geom_RectangularTrimmedSurface)::DownCast(surf)->BasisSurface(), type);
}
else if (thetype == STANDARD_TYPE(Geom_Plane))
type = GeomAbs_Plane;
else if (thetype == STANDARD_TYPE(Geom_CylindricalSurface))
type = GeomAbs_Cylinder;
else if (thetype == STANDARD_TYPE(Geom_ConicalSurface))
type = GeomAbs_Cone;
else if (thetype == STANDARD_TYPE(Geom_SphericalSurface))
type = GeomAbs_Sphere;
else if (thetype == STANDARD_TYPE(Geom_ToroidalSurface))
type = GeomAbs_Torus;
else if (thetype == STANDARD_TYPE(Geom_SurfaceOfRevolution))
type = GeomAbs_SurfaceOfRevolution;
else if (thetype == STANDARD_TYPE(Geom_SurfaceOfLinearExtrusion))
type = GeomAbs_SurfaceOfExtrusion;
else if (thetype == STANDARD_TYPE(Geom_BezierSurface))
type = GeomAbs_BezierSurface;
else if (thetype == STANDARD_TYPE(Geom_BSplineSurface))
type = GeomAbs_BSplineSurface;
else if (thetype == STANDARD_TYPE(Geom_OffsetSurface))
type = GeomAbs_OffsetSurface;
else
type = GeomAbs_OtherSurface;
return surf;
}
bool iogOccKernelTools::GroupEdgesInTrianglestest(std::vector<TopoDS_Edge>& vecEdges,
int& stop)
{
if (stop < 3)
{
return false;
}
for (int j = 1; j < vecEdges.size(); j++)
{
for (int k = 1; k < vecEdges.size(); k++)
{
int a = 0;
}
}
stop--;
return GroupEdgesInTrianglestest(vecEdges, stop);
}
bool iogOccKernelTools::GroupEdgesInTriangles(double dPointEqual, std::vector<TopoDS_Edge>& vecEdges,
std::vector<std::vector<TopoDS_Edge>>& vecvecGroups)
{
if (vecEdges.size() == 0)
{
return false;
}
if (vecEdges.size() < 3)
{
vecvecGroups.push_back(vecEdges);
vecEdges.clear();
return false;
}
std::vector<int>* vecUsedIdx = new std::vector<int>;
std::vector<TopoDS_Edge>* vecTopoEdges = new std::vector<TopoDS_Edge>;
ShapeAnalysis_Edge sae;
TopoDS_Edge eg1 = vecEdges[0];
TopoDS_Vertex v11 = sae.FirstVertex(eg1);
gp_Pnt pt11 = BRep_Tool::Pnt(v11);
TopoDS_Vertex v12 = sae.LastVertex(eg1);
gp_Pnt pt12 = BRep_Tool::Pnt(v12);
for (int j = 1; j < vecEdges.size(); j++)
{
bool ifbreak = false;
TopoDS_Edge eg2 = vecEdges[j];
TopoDS_Vertex v21 = sae.FirstVertex(eg2);
gp_Pnt pt21 = BRep_Tool::Pnt(v21);
TopoDS_Vertex v22 = sae.LastVertex(eg2);
gp_Pnt pt22 = BRep_Tool::Pnt(v22);
if (pt12.IsEqual(pt21, dPointEqual))
{
for (int k = 1; k < vecEdges.size(); k++)
{
if (k == j)
{
continue;
}
TopoDS_Edge eg3 = vecEdges[k];
TopoDS_Vertex v31 = sae.FirstVertex(eg3);
gp_Pnt pt31 = BRep_Tool::Pnt(v31);
TopoDS_Vertex v32 = sae.LastVertex(eg3);
gp_Pnt pt32 = BRep_Tool::Pnt(v32);
if ((pt31.IsEqual(pt11, dPointEqual) && pt32.IsEqual(pt22, dPointEqual)) ||
(pt31.IsEqual(pt22, dPointEqual) && pt32.IsEqual(pt11, dPointEqual)))
{
vecTopoEdges->push_back(eg1);
vecTopoEdges->push_back(eg2);
vecTopoEdges->push_back(eg3);
vecUsedIdx->push_back(0);
vecUsedIdx->push_back(j);
vecUsedIdx->push_back(k);
ifbreak = true;
break;
}
}
}
else if (pt11.IsEqual(pt22, dPointEqual))
{
for (int k = 1; k < vecEdges.size(); k++)
{
if (k == j)
{
continue;
}
TopoDS_Edge eg3 = vecEdges[k];
TopoDS_Vertex v31 = sae.FirstVertex(eg3);
gp_Pnt pt31 = BRep_Tool::Pnt(v31);
TopoDS_Vertex v32 = sae.LastVertex(eg3);
gp_Pnt pt32 = BRep_Tool::Pnt(v32);
if ((pt31.IsEqual(pt12, dPointEqual) && pt32.IsEqual(pt21, dPointEqual)) ||
(pt31.IsEqual(pt21, dPointEqual) && pt32.IsEqual(pt12, dPointEqual)))
{
vecTopoEdges->push_back(eg1);
vecTopoEdges->push_back(eg2);
vecTopoEdges->push_back(eg3);
vecUsedIdx->push_back(0);
vecUsedIdx->push_back(j);
vecUsedIdx->push_back(k);
ifbreak = true;
break;
}
}
}
else if (pt11.IsEqual(pt21, dPointEqual))
{
for (int k = 1; k < vecEdges.size(); k++)
{
if (k == j)
{
continue;
}
TopoDS_Edge eg3 = vecEdges[k];
TopoDS_Vertex v31 = sae.FirstVertex(eg3);
gp_Pnt pt31 = BRep_Tool::Pnt(v31);
TopoDS_Vertex v32 = sae.LastVertex(eg3);
gp_Pnt pt32 = BRep_Tool::Pnt(v32);
if ((pt31.IsEqual(pt12, dPointEqual) && pt32.IsEqual(pt22, dPointEqual)) ||
(pt31.IsEqual(pt22, dPointEqual) && pt32.IsEqual(pt12, dPointEqual)))
{
vecTopoEdges->push_back(eg1);
vecTopoEdges->push_back(eg2);
vecTopoEdges->push_back(eg3);
vecUsedIdx->push_back(0);
vecUsedIdx->push_back(j);
vecUsedIdx->push_back(k);
ifbreak = true;
break;
}
}
}
else if (pt12.IsEqual(pt22, dPointEqual))
{
for (int k = 1; k < vecEdges.size(); k++)
{
if (k == j)
{
continue;
}
TopoDS_Edge eg3 = vecEdges[k];
TopoDS_Vertex v31 = sae.FirstVertex(eg3);
gp_Pnt pt31 = BRep_Tool::Pnt(v31);
TopoDS_Vertex v32 = sae.LastVertex(eg3);
gp_Pnt pt32 = BRep_Tool::Pnt(v32);
if ((pt31.IsEqual(pt11, dPointEqual) && pt32.IsEqual(pt21, dPointEqual)) ||
(pt31.IsEqual(pt21, dPointEqual) && pt32.IsEqual(pt11, dPointEqual)))
{
vecTopoEdges->push_back(eg1);
vecTopoEdges->push_back(eg2);
vecTopoEdges->push_back(eg3);
vecUsedIdx->push_back(0);
vecUsedIdx->push_back(j);
vecUsedIdx->push_back(k);
ifbreak = true;
break;
}
}
}
if (ifbreak)
break;
}
if (vecTopoEdges->size() == 0)
{
vecTopoEdges->push_back(eg1);
vecvecGroups.push_back(*vecTopoEdges);
std::vector<TopoDS_Edge>* nextEdges = new std::vector<TopoDS_Edge>;
for (int i = 1; i < vecEdges.size(); i++)
{
nextEdges->push_back(vecEdges[i]);
}
vecEdges = *nextEdges;
delete nextEdges;
nextEdges = NULL;
delete vecUsedIdx;
vecUsedIdx = NULL;
delete vecTopoEdges;
vecTopoEdges = NULL;
return GroupEdgesInTriangles(dPointEqual, vecEdges, vecvecGroups);
}
else if (vecTopoEdges->size() == 3)
{
vecvecGroups.push_back(*vecTopoEdges);
std::vector<TopoDS_Edge>* nextEdges = new std::vector<TopoDS_Edge>;
for (int i = 0; i < vecEdges.size(); i++)
{
bool ifcontinue = false;
for (int j = 0; j < vecUsedIdx->size(); j++)
{
if (i == (*vecUsedIdx)[j])
{
ifcontinue = true;
break;
}
}
if (ifcontinue)
continue;
nextEdges->push_back(vecEdges[i]);