-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathCurvedBlocking.cpp
More file actions
1964 lines (1796 loc) · 80.6 KB
/
Copy pathCurvedBlocking.cpp
File metadata and controls
1964 lines (1796 loc) · 80.6 KB
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
/*----------------------------------------------------------------------------*/
#include "gmds/blocking/CurvedBlocking.h"
/*----------------------------------------------------------------------------*/
using namespace gmds;
using namespace gmds::blocking;
/*----------------------------------------------------------------------------*/
//int CellInfo::m_counter_global_id = 0;
/*----------------------------------------------------------------------------*/
CurvedBlocking::CurvedBlocking(cad::GeomManager *AGeomModel, bool AInitAsBoundingBox)
: m_geom_model(AGeomModel), m_counter(0)
{
if (AInitAsBoundingBox) {
TCoord min[3] = {MAXFLOAT, MAXFLOAT, MAXFLOAT};
TCoord max[3] = {-MAXFLOAT, -MAXFLOAT, -MAXFLOAT};
std::vector<cad::GeomVolume *> vols;
m_geom_model->getVolumes(vols);
for (auto v: vols) {
TCoord v_min[3], v_max[3];
v->computeBoundingBox(v_min, v_max);
for (auto i = 0; i < 3; i++)
if (v_min[i] < min[i]) min[i] = v_min[i];
for (auto i = 0; i < 3; i++)
if (v_max[i] > max[i]) max[i] = v_max[i];
}
math::Point p1(min[0], min[1], min[2]);
math::Point p2(min[0], max[1], min[2]);
math::Point p3(max[0], max[1], min[2]);
math::Point p4(max[0], min[1], min[2]);
math::Point p5(min[0], min[1], max[2]);
math::Point p6(min[0], max[1], max[2]);
math::Point p7(max[0], max[1], max[2]);
math::Point p8(max[0], min[1], max[2]);
create_block(p1, p2, p3, p4, p5, p6, p7, p8);
}
}
/*----------------------------------------------------------------------------*/
CurvedBlocking::CurvedBlocking(const CurvedBlocking &ABl)
: m_geom_model(ABl.m_geom_model), m_gmap(ABl.m_gmap), m_counter(ABl.m_counter)
{
auto listBlocks = get_all_blocks();
for(auto b : listBlocks){
b->info().counter = &m_counter;
}
auto listFaces = get_all_faces();
for(auto b : listFaces){
b->info().counter = &m_counter;
}
auto listEdges = get_all_edges();
for(auto b : listEdges){
b->info().counter = &m_counter;
}
auto listNodes = get_all_nodes();
for(auto b : listNodes){
b->info().counter = &m_counter;
}
}
/*----------------------------------------------------------------------------*/
CurvedBlocking::~CurvedBlocking() {}
/*----------------------------------------------------------------------------*/
GMap3 *
CurvedBlocking::gmap() {
return &m_gmap;
}
/*----------------------------------------------------------------------------*/
cad::GeomManager *
CurvedBlocking::geom_model() {
return m_geom_model;
}
/*----------------------------------------------------------------------------*/
CurvedBlocking::Node
CurvedBlocking::create_node(const int AGeomDim, const int AGeomId, const math::Point &APoint) {
return m_gmap.create_attribute<0>(NodeInfo(this->getCounter(),m_geom_model,AGeomDim, AGeomId, APoint));
}
/*----------------------------------------------------------------------------*/
CurvedBlocking::Edge
CurvedBlocking::create_edge(const int AGeomDim, const int AGeomId) {
return m_gmap.create_attribute<1>(CellInfo(this->getCounter(),m_geom_model,1, AGeomDim, AGeomId));
}
/*----------------------------------------------------------------------------*/
CurvedBlocking::Face
CurvedBlocking::create_face(const int AGeomDim, const int AGeomId) {
return m_gmap.create_attribute<2>(CellInfo(this->getCounter(),m_geom_model,2, AGeomDim, AGeomId));
}
/*----------------------------------------------------------------------------*/
CurvedBlocking::Block
CurvedBlocking::create_block(const int AGeomDim, const int AGeomId) {
return m_gmap.create_attribute<3>(CellInfo(this->getCounter(),m_geom_model,3, AGeomDim, AGeomId));
}
/*----------------------------------------------------------------------------*/
std::vector<CurvedBlocking::Face>
CurvedBlocking::get_faces_of_block(const CurvedBlocking::Block AB) {
Dart3 d1 = AB->dart();
std::vector<CurvedBlocking::Face> faces;
faces.resize(6);
faces[0] = m_gmap.attribute<2>(d1);
faces[1] = m_gmap.attribute<2>(m_gmap.alpha<2, 1, 0, 1, 2>(d1));
faces[2] = m_gmap.attribute<2>(m_gmap.alpha<2>(d1));
faces[3] = m_gmap.attribute<2>(m_gmap.alpha<1, 0, 1, 2>(d1));
faces[4] = m_gmap.attribute<2>(m_gmap.alpha<1, 2>(d1));
faces[5] = m_gmap.attribute<2>(m_gmap.alpha<0, 1, 2>(d1));
return faces;
}
/*----------------------------------------------------------------------------*/
std::vector<CurvedBlocking::Block>
CurvedBlocking::get_all_blocks() {
std::vector<CurvedBlocking::Block> blocks;
for (auto it = m_gmap.attributes<3>().begin(), itend = m_gmap.attributes<3>().end(); it != itend; ++it) {
blocks.push_back(it);
}
return blocks;
}
/*----------------------------------------------------------------------------*/
std::vector<CurvedBlocking::Face>
CurvedBlocking::get_all_faces() {
std::vector<CurvedBlocking::Face> faces;
for (auto it = m_gmap.attributes<2>().begin(), itend = m_gmap.attributes<2>().end(); it != itend; ++it) {
faces.push_back(it);
}
return faces;
}
/*----------------------------------------------------------------------------*/
std::vector<TCellID> CurvedBlocking::get_all_id_nodes() {
auto nodes = get_all_nodes();
std::vector<TCellID> ids;
ids.reserve(nodes.size());
for (auto n: nodes)
ids.push_back(n->info().topo_id);
return ids;
}
/*----------------------------------------------------------------------------*/
std::vector<TCellID> CurvedBlocking::get_all_id_edges() {
auto edges = get_all_edges();
std::vector<TCellID> ids;
ids.reserve(edges.size());
for (auto e: edges)
ids.push_back(e->info().topo_id);
return ids;
}
/*----------------------------------------------------------------------------*/
std::vector<TCellID> CurvedBlocking::get_all_id_faces() {
auto faces = get_all_faces();
std::vector<TCellID> ids;
ids.reserve(faces.size());
for (auto f: faces)
ids.push_back(f->info().topo_id);
return ids;
}
/*----------------------------------------------------------------------------*/
std::vector<TCellID> CurvedBlocking::get_all_id_blocks() {
auto blocks = get_all_blocks();
std::vector<TCellID> ids;
ids.reserve(blocks.size());
for (auto b: blocks)
ids.push_back(b->info().topo_id);
return ids;
}
/*----------------------------------------------------------------------------*/
std::vector<CurvedBlocking::Edge>
CurvedBlocking::get_edges_of_node(const Node AN) {
std::vector<Edge> edges;
Dart3 d = AN->dart();
for (auto it = m_gmap.one_dart_per_incident_cell<1, 0>(d).begin(),
itend = m_gmap.one_dart_per_incident_cell<1, 0>(d).end(); it != itend; ++it) {
edges.push_back(m_gmap.attribute<1>(it));
}
return edges;
}
/*----------------------------------------------------------------------------*/
std::vector<CurvedBlocking::Face>
CurvedBlocking::get_faces_of_node(const Node AN) {
std::vector<Face> faces;
Dart3 d = AN->dart();
for (auto it = m_gmap.one_dart_per_incident_cell<2, 0>(d).begin(),
itend = m_gmap.one_dart_per_incident_cell<2, 0>(d).end(); it != itend; ++it) {
faces.push_back(m_gmap.attribute<2>(it));
}
return faces;
}
/*----------------------------------------------------------------------------*/
std::vector<CurvedBlocking::Edge>
CurvedBlocking::get_edges_of_face(const Face AF) {
std::vector<Edge> edges;
Dart3 d = AF->dart();
for (auto it = m_gmap.one_dart_per_incident_cell<1, 2>(d).begin(),
itend = m_gmap.one_dart_per_incident_cell<1, 2>(d).end(); it != itend; ++it) {
edges.push_back(m_gmap.attribute<1>(it));
}
return edges;
}
/*----------------------------------------------------------------------------*/
std::vector<CurvedBlocking::Block>
CurvedBlocking::get_blocks_of_node(const Node AN) {
std::vector<Block> blocks;
Dart3 d = AN->dart();
for (auto it = m_gmap.one_dart_per_incident_cell<3, 0>(d).begin(),
itend = m_gmap.one_dart_per_incident_cell<3, 0>(d).end(); it != itend; ++it) {
blocks.push_back(m_gmap.attribute<3>(it));
}
return blocks;
}
/*----------------------------------------------------------------------------*/
std::vector<CurvedBlocking::Face>
CurvedBlocking::get_faces_of_edge(const Edge AE) {
std::vector<Face> faces;
Dart3 d = AE->dart();
for (auto it = m_gmap.one_dart_per_incident_cell<2, 1>(d).begin(),
itend = m_gmap.one_dart_per_incident_cell<2, 1>(d).end(); it != itend; ++it) {
faces.push_back(m_gmap.attribute<2>(it));
}
return faces;
}
/*----------------------------------------------------------------------------*/
std::vector<CurvedBlocking::Block>
CurvedBlocking::get_blocks_of_edge(const Edge AE) {
std::vector<Block> blocks;
Dart3 d = AE->dart();
for (auto it = m_gmap.one_dart_per_incident_cell<3, 1>(d).begin(),
itend = m_gmap.one_dart_per_incident_cell<3, 1>(d).end(); it != itend; ++it) {
blocks.push_back(m_gmap.attribute<3>(it));
}
return blocks;
}
/*----------------------------------------------------------------------------*/
std::vector<CurvedBlocking::Block>
CurvedBlocking::get_blocks_of_face(const Face AF) {
std::vector<Block> blocks;
Dart3 d = AF->dart();
for (auto it = m_gmap.one_dart_per_incident_cell<3, 2>(d).begin(),
itend = m_gmap.one_dart_per_incident_cell<3, 2>(d).end(); it != itend; ++it) {
blocks.push_back(m_gmap.attribute<3>(it));
}
return blocks;
}
/*----------------------------------------------------------------------------*/
std::vector<CurvedBlocking::Edge>
CurvedBlocking::get_all_edges() {
std::vector<CurvedBlocking::Edge> edges;
for (auto it = m_gmap.attributes<1>().begin(), itend = m_gmap.attributes<1>().end(); it != itend; ++it) {
edges.push_back(it);
}
return edges;
}
/*----------------------------------------------------------------------------*/
std::vector<CurvedBlocking::Node>
CurvedBlocking::get_all_nodes() {
std::vector<CurvedBlocking::Node> nodes;
for (auto it = m_gmap.attributes<0>().begin(), itend = m_gmap.attributes<0>().end(); it != itend; ++it) {
nodes.push_back(it);
}
return nodes;
}
/*----------------------------------------------------------------------------*/
std::vector<CurvedBlocking::Edge>
CurvedBlocking::get_edges_of_block(const CurvedBlocking::Block AB) {
Dart3 d = AB->dart();
std::vector<CurvedBlocking::Edge> edges;
edges.resize(12);
edges[0] = m_gmap.attribute<1>(d);
edges[1] = m_gmap.attribute<1>(m_gmap.alpha<1, 0, 1>(d));
edges[2] = m_gmap.attribute<1>(m_gmap.alpha<2, 1, 0, 1>(d));
edges[3] = m_gmap.attribute<1>(m_gmap.alpha<1, 0, 1, 2, 1, 0, 1>(d));
d = m_gmap.alpha<1>(d);
edges[4] = m_gmap.attribute<1>(d);
edges[5] = m_gmap.attribute<1>(m_gmap.alpha<1, 0, 1>(d));
edges[6] = m_gmap.attribute<1>(m_gmap.alpha<2, 1, 0, 1>(d));
edges[7] = m_gmap.attribute<1>(m_gmap.alpha<1, 0, 1, 2, 1, 0, 1>(d));
d = m_gmap.alpha<1>(d);
d = m_gmap.alpha<2, 1>(d);
edges[8] = m_gmap.attribute<1>(d);
edges[9] = m_gmap.attribute<1>(m_gmap.alpha<1, 0, 1>(d));
edges[10] = m_gmap.attribute<1>(m_gmap.alpha<2, 1, 0, 1>(d));
edges[11] = m_gmap.attribute<1>(m_gmap.alpha<1, 0, 1, 2, 1, 0, 1>(d));
return edges;
}
/*----------------------------------------------------------------------------*/
std::vector<CurvedBlocking::Node>
CurvedBlocking::get_nodes_of_block(const CurvedBlocking::Block AB) {
Dart3 d1 = AB->dart();
std::vector<CurvedBlocking::Node> nodes;
nodes.resize(8);
nodes[0] = m_gmap.attribute<0>(d1);
nodes[1] = m_gmap.attribute<0>(m_gmap.alpha<0, 1>(d1));
nodes[2] = m_gmap.attribute<0>(m_gmap.alpha<0, 1, 0, 1>(d1));
nodes[3] = m_gmap.attribute<0>(m_gmap.alpha<1, 0>(d1));
Dart3 d2 = m_gmap.alpha<2, 1, 0, 1, 2>(d1);
nodes[4] = m_gmap.attribute<0>(d2);
nodes[5] = m_gmap.attribute<0>(m_gmap.alpha<0, 1>(d2));
nodes[6] = m_gmap.attribute<0>(m_gmap.alpha<0, 1, 0, 1>(d2));
nodes[7] = m_gmap.attribute<0>(m_gmap.alpha<1, 0>(d2));
return nodes;
}
/*----------------------------------------------------------------------------*/
std::vector<CurvedBlocking::Node>
CurvedBlocking::get_nodes_of_face(const CurvedBlocking::Face AF) {
Dart3 d1 = AF->dart();
std::vector<CurvedBlocking::Node> nodes;
Dart3 d = d1;
do {
nodes.push_back(m_gmap.attribute<0>(d));
d = m_gmap.alpha<0, 1>(d);
} while (d != d1);
return nodes;
}
/*----------------------------------------------------------------------------*/
std::vector<CurvedBlocking::Node>
CurvedBlocking::get_nodes_of_edge(const CurvedBlocking::Edge AE) {
std::vector<CurvedBlocking::Node> nodes;
nodes.resize(2);
Dart3 d = AE->dart();
nodes[0] = m_gmap.attribute<0>(d);
nodes[1] = m_gmap.attribute<0>(m_gmap.alpha<0>(d));
return nodes;
}
/*----------------------------------------------------------------------------*/
math::Point
CurvedBlocking::get_center_of_edge(const Edge AE) {
std::vector<Node> n = get_nodes_of_edge(AE);
return 0.5 * (n[0]->info().point + n[1]->info().point);
}
/*----------------------------------------------------------------------------*/
math::Point
CurvedBlocking::get_center_of_face(const Face AF) {
std::vector<Node> nodes = get_nodes_of_face(AF);
math::Point center(0, 0, 0);
for (auto n: nodes) {
center = center + n->info().point;
}
return (1.0 / nodes.size()) * center;
}
/*----------------------------------------------------------------------------*/
math::Vector3d
CurvedBlocking::get_normal_of_face(const Face AF) {
std::vector<Node> nodes = get_nodes_of_face(AF);
math::Point center = get_center_of_face(AF);
math::Vector3d n({0, 0, 0});
for (auto i = 0; i < nodes.size(); i++) {
Node prev_node = (i == 0) ? nodes[nodes.size() - 1] : nodes[i - 1];
Node curr_node = nodes[i];
math::Vector3d vp = prev_node->info().point - center;
math::Vector3d vc = curr_node->info().point - center;
n = n + vp.cross(vc);
}
n.normalize();
return n;
}
/*----------------------------------------------------------------------------*/
math::Point
CurvedBlocking::get_center_of_block(const Block AB) {
std::vector<Node> nodes = get_nodes_of_block(AB);
math::Point center(0, 0, 0);
for (auto n: nodes) {
center = center + n->info().point;
}
return (1.0 / nodes.size()) * center;
}
/*----------------------------------------------------------------------------*/
void
CurvedBlocking::move_node(Node AN, math::Point &ALoc) {
AN->info().point = ALoc;
if (AN->info().geom_dim == 0) {
// classified onto a point
cad::GeomPoint *geom_pnt = m_geom_model->getPoint(AN->info().geom_id);
AN->info().point = geom_pnt->point();
} else if (AN->info().geom_dim == 1) {
// classified onto a curve
cad::GeomCurve *geom_curve = m_geom_model->getCurve(AN->info().geom_id);
geom_curve->project(AN->info().point);
} else if (AN->info().geom_dim == 2) {
// classified onto a surface
cad::GeomSurface *geom_surf = m_geom_model->getSurface(AN->info().geom_id);
geom_surf->project(AN->info().point);
}
// otherwise nothing else to do
}
/*----------------------------------------------------------------------------*/
CurvedBlocking::Block
CurvedBlocking::create_block(
const math::Point &AP1, const math::Point &AP2,
const math::Point &AP3, const math::Point &AP4,
const math::Point &AP5, const math::Point &AP6,
const math::Point &AP7, const math::Point &AP8) {
// Initialize attribute for the created hexahedron
Dart3 d1 = m_gmap.make_combinatorial_hexahedron();
// 0D attribute
m_gmap.set_attribute<0>(d1, create_node(4, NullID, AP1));
m_gmap.set_attribute<0>(m_gmap.alpha<0>(d1), create_node(4, NullID, AP2));
m_gmap.set_attribute<0>(m_gmap.alpha<0, 1, 0>(d1), create_node(4, NullID, AP3));
m_gmap.set_attribute<0>(m_gmap.alpha<1, 0>(d1), create_node(4, NullID, AP4));
m_gmap.set_attribute<0>(m_gmap.alpha<2, 1, 0, 1, 2>(d1), create_node(4, NullID, AP5));
m_gmap.set_attribute<0>(m_gmap.alpha<2, 1, 0, 1, 2, 0, 1>(d1), create_node(4, NullID, AP6));
m_gmap.set_attribute<0>(m_gmap.alpha<2, 1, 0, 1, 2, 0, 1, 0, 1>(d1), create_node(4, NullID, AP7));
m_gmap.set_attribute<0>(m_gmap.alpha<2, 1, 0, 1, 2, 1, 0>(d1), create_node(4, NullID, AP8));
// go through all the edges
for (auto it = m_gmap.one_dart_per_incident_cell<1, 3>(d1).begin(), itend = m_gmap.one_dart_per_incident_cell<1, 3>(
d1).end(); it != itend; ++it) {
m_gmap.set_attribute<1>(it, create_edge(4, NullID));
}
// go through all the faces
for (auto it = m_gmap.one_dart_per_incident_cell<2, 3>(d1).begin(), itend = m_gmap.one_dart_per_incident_cell<2, 3>(
d1).end(); it != itend; ++it) {
m_gmap.set_attribute<2>(it, create_face(4, NullID));
}
Block b = create_block(3, NullID);
m_gmap.set_attribute<3>(d1, b);
return b;
}
/*----------------------------------------------------------------------------*/
void
CurvedBlocking::remove_block(const TCellID ABlockId)
{
Block AB = get_block(ABlockId);
Dart3 d = AB->dart();
m_gmap.remove_cell<3>(d);
}
/*----------------------------------------------------------------------------*/
void
CurvedBlocking::remove_block(CurvedBlocking::Block AB) {
Dart3 d = AB->dart();
m_gmap.remove_cell<3>(d);
}
/*----------------------------------------------------------------------------*/
std::tuple<int, int, math::Point>
CurvedBlocking::get_node_info(const int ANodeId) {
for (auto it = m_gmap.attributes<0>().begin(), itend = m_gmap.attributes<0>().end(); it != itend; ++it) {
if (it->info().topo_id == ANodeId) {
return std::make_tuple(it->info().geom_dim, it->info().geom_id, it->info().point);
}
}
return std::make_tuple(-1, -1, math::Point(0, 0, 0));
}
/*----------------------------------------------------------------------------*/
std::tuple<int, int>
CurvedBlocking::get_edge_info(const int AEdgeId) {
for (auto it = m_gmap.attributes<1>().begin(), itend = m_gmap.attributes<1>().end(); it != itend; ++it) {
if (it->info().topo_id == AEdgeId) {
return std::make_tuple(it->info().geom_dim, it->info().geom_id);
}
}
return std::make_tuple(-1, -1);
}
/*----------------------------------------------------------------------------*/
std::tuple<int, int>
CurvedBlocking::get_face_info(const int AFaceId) {
for (auto it = m_gmap.attributes<2>().begin(), itend = m_gmap.attributes<2>().end(); it != itend; ++it) {
if (it->info().topo_id == AFaceId) {
return std::make_tuple(it->info().geom_dim, it->info().geom_id);
}
}
return std::make_tuple(-1, -1);
}
/*----------------------------------------------------------------------------*/
std::tuple<int, int>
CurvedBlocking::get_block_info(const int ABlockId) {
for (auto it = m_gmap.attributes<3>().begin(), itend = m_gmap.attributes<3>().end(); it != itend; ++it) {
if (it->info().topo_id == ABlockId) {
return std::make_tuple(it->info().geom_dim, it->info().geom_id);
}
}
return std::make_tuple(-1, -1);
}
/*----------------------------------------------------------------------------*/
CurvedBlocking::Block
CurvedBlocking::get_block(const int ABlockId)
{
auto listBlocks = get_all_blocks();
bool found = false;
for(auto b : listBlocks){
if(b->info().topo_id == ABlockId){
return b;
}
}
std::cout<<"ID NO VALIDE"<<std::endl;
assert(found);
}
/*----------------------------------------------------------------------------*/
int
CurvedBlocking::get_node_id(CurvedBlocking::Node &ANode){
return ANode->info().topo_id;
}
/*----------------------------------------------------------------------------*/
int
CurvedBlocking::get_edge_id(CurvedBlocking::Edge &AEdge){
return AEdge->info().topo_id;
}
/*----------------------------------------------------------------------------*/
int
CurvedBlocking::get_face_id(CurvedBlocking::Face &AFace){
return AFace->info().topo_id;
}
/*----------------------------------------------------------------------------*/
int
CurvedBlocking::get_block_id(CurvedBlocking::Block &ABlock){
return ABlock->info().topo_id;
}
/*----------------------------------------------------------------------------*/
bool
CurvedBlocking::is_valid_topology() const {
return m_gmap.is_valid();
}
/*----------------------------------------------------------------------------*/
std::string
CurvedBlocking::info() const {
std::ostringstream mess;
mess << "Blocking Info: " << std::endl;
m_gmap.display_characteristics(mess);
mess << ", validity=" << (is_valid_topology() ? "true" : "false");
mess << "\nOd-attributes: ";
for (auto at: m_gmap.attributes<0>()) {
mess << "[" << at.info().point << ",(dim:" << at.info().geom_dim << ",id:" << at.info().geom_id << ")]; ";
}
mess << "\n1d-attributes: ";
for (auto at: m_gmap.attributes<1>()) {
mess << "(dim:" << at.info().geom_dim << ",id:" << at.info().geom_id << "); ";
}
mess << "\n2d-attributes: ";
for (auto at: m_gmap.attributes<2>()) {
mess << "(dim:" << at.info().geom_dim << ",id:" << at.info().geom_id << "); ";
}
mess << "\n3d-attributes: ";
for (auto at: m_gmap.attributes<3>()) {
mess << "(dim:" << at.info().geom_dim << ",id:" << at.info().geom_id << "); ";
}
return mess.str();
}
/*----------------------------------------------------------------------------*/
void
CurvedBlocking::convert_to_mesh(Mesh &AMesh) {
MeshModel model = AMesh.getModel();
if (!model.has(N) || !model.has(E) || !model.has(F) || !model.has(R) || !model.has(E2N) || !model.has(F2N) ||
!model.has(R2N))
throw GMDSException("Wrong mesh model for block->mesh conversion");
AMesh.clear();
Variable<int> *var_node_topo_id = AMesh.newVariable<int, GMDS_NODE>("blocking_topo_id");
Variable<int> *var_node_topo_dim = AMesh.newVariable<int, GMDS_NODE>("blocking_topo_dim");
Variable<int> *var_node_geom_id = AMesh.newVariable<int, GMDS_NODE>("blocking_geom_id");
Variable<int> *var_node_geom_dim = AMesh.newVariable<int, GMDS_NODE>("blocking_geom_dim");
Variable<int> *var_edge_topo_id = AMesh.newVariable<int, GMDS_EDGE>("blocking_topo_id");
Variable<int> *var_edge_topo_dim = AMesh.newVariable<int, GMDS_EDGE>("blocking_topo_dim");
Variable<int> *var_edge_geom_id = AMesh.newVariable<int, GMDS_EDGE>("blocking_geom_id");
Variable<int> *var_edge_geom_dim = AMesh.newVariable<int, GMDS_EDGE>("blocking_geom_dim");
Variable<int> *var_face_topo_id = AMesh.newVariable<int, GMDS_FACE>("blocking_topo_id");
Variable<int> *var_face_topo_dim = AMesh.newVariable<int, GMDS_FACE>("blocking_topo_dim");
Variable<int> *var_face_geom_id = AMesh.newVariable<int, GMDS_FACE>("blocking_geom_id");
Variable<int> *var_face_geom_dim = AMesh.newVariable<int, GMDS_FACE>("blocking_geom_dim");
Variable<int> *var_region_topo_id = AMesh.newVariable<int, GMDS_REGION>("blocking_topo_id");
Variable<int> *var_region_topo_dim = AMesh.newVariable<int, GMDS_REGION>("blocking_topo_dim");
Variable<int> *var_region_geom_id = AMesh.newVariable<int, GMDS_REGION>("blocking_geom_id");
Variable<int> *var_region_geom_dim = AMesh.newVariable<int, GMDS_REGION>("blocking_geom_dim");
// mapping from blocking node ids to mesh node ids
std::map<int, TCellID> n2n;
// nodes
for (auto at: m_gmap.attributes<0>()) {
gmds::Node n = AMesh.newNode(at.info().point);
var_node_topo_id->set(n.id(), at.info().topo_id);
var_node_topo_dim->set(n.id(), at.info().topo_dim);
var_node_geom_id->set(n.id(), at.info().geom_id);
var_node_geom_dim->set(n.id(), at.info().geom_dim);
n2n[at.info().topo_id] = n.id();
}
// edges
for (auto it = m_gmap.attributes<1>().begin(), itend = m_gmap.attributes<1>().end(); it != itend; ++it) {
auto att = m_gmap.info_of_attribute<1>(it);
std::vector<Node> cell_nodes = get_nodes_of_edge(it);
gmds::Edge e = AMesh.newEdge(n2n[cell_nodes[0]->info().topo_id], n2n[cell_nodes[1]->info().topo_id]);
var_edge_topo_id->set(e.id(), att.topo_id);
var_edge_topo_dim->set(e.id(), att.topo_dim);
var_edge_geom_id->set(e.id(), att.geom_id);
var_edge_geom_dim->set(e.id(), att.geom_dim);
}
// faces
for (auto it = m_gmap.attributes<2>().begin(), itend = m_gmap.attributes<2>().end(); it != itend; ++it) {
auto att = m_gmap.info_of_attribute<2>(it);
std::vector<Node> cell_nodes = get_nodes_of_face(it);
if (cell_nodes.size() != 4) throw GMDSException("Only quad blocking faces can be converted into mesh");
gmds::Face f = AMesh.newQuad(n2n[cell_nodes[0]->info().topo_id], n2n[cell_nodes[1]->info().topo_id],
n2n[cell_nodes[2]->info().topo_id],
n2n[cell_nodes[3]->info().topo_id]);
var_face_topo_id->set(f.id(), att.topo_id);
var_face_topo_dim->set(f.id(), att.topo_dim);
var_face_geom_id->set(f.id(), att.geom_id);
var_face_geom_dim->set(f.id(), att.geom_dim);
}
// blocks
for (auto it = m_gmap.attributes<3>().begin(), itend = m_gmap.attributes<3>().end(); it != itend; ++it) {
auto att = m_gmap.info_of_attribute<3>(it);
std::vector<Node> cell_nodes = get_nodes_of_block(it);
if (cell_nodes.size() != 8) throw GMDSException("Only hex blocks can be converted into mesh");
gmds::Region r = AMesh.newHex(n2n[cell_nodes[0]->info().topo_id], n2n[cell_nodes[1]->info().topo_id],
n2n[cell_nodes[2]->info().topo_id],
n2n[cell_nodes[3]->info().topo_id], n2n[cell_nodes[4]->info().topo_id],
n2n[cell_nodes[5]->info().topo_id],
n2n[cell_nodes[6]->info().topo_id], n2n[cell_nodes[7]->info().topo_id]);
var_region_topo_id->set(r.id(), att.topo_id);
var_region_topo_dim->set(r.id(), att.topo_dim);
var_region_geom_id->set(r.id(), att.geom_id);
var_region_geom_dim->set(r.id(), att.geom_dim);
}
}
/*----------------------------------------------------------------------------*/
void
CurvedBlocking::init_from_mesh(Mesh &AMesh) {
MeshModel model = AMesh.getModel();
if (!model.has(N) || !model.has(R) || !model.has(R2N))
throw GMDSException("Wrong mesh model for mesh->block->mesh conversion");
//map from gmap node ids to init mesh id
std::map<TCellID, TCellID> n2n;
for (auto r_id: AMesh.regions()) {
Region r = AMesh.get<Region>(r_id);
//only hex cells are converted
if (r.type() == GMDS_HEX) {
std::vector<gmds::Node> ns = r.get<gmds::Node>();
Block b = create_block(ns[0].point(), ns[1].point(), ns[2].point(), ns[3].point(),
ns[4].point(), ns[5].point(), ns[6].point(), ns[7].point());
std::vector<Node> b_nodes = get_nodes_of_block(b);
for (auto i = 0; i < 8; i++) {
math::Point pi = ns[i].point();
auto min_dist = pi.distance2(b_nodes[0]->info().point);
auto min_id = b_nodes[0]->info().topo_id;
for (auto j = 1; j < 8; j++) {
auto dist_j = pi.distance2(b_nodes[j]->info().point);
if (dist_j < min_dist) {
min_dist = dist_j;
min_id = b_nodes[j]->info().topo_id;
}
}
n2n[min_id] = ns[i].id();
}
}
}
// now we glue blocks;
for (auto it_r = m_gmap.attributes<3>().begin(), it_rend = m_gmap.attributes<3>().end(); it_r != it_rend; ++it_r) {
std::vector<Face> cell_faces = get_faces_of_block(it_r);
for (auto f: cell_faces) {
Dart3 d = f->dart();
if (m_gmap.is_free<3>(d)) {
//means the face is not connected
std::vector<Node> f_nodes = get_nodes_of_face(f);
//We go through all the 3-free faces and try to connect to f
bool found_and_glue = false;
for (auto it_f = m_gmap.attributes<2>().begin(), it_fend = m_gmap.attributes<2>().end();
it_f != it_fend; ++it_f) {
auto att = m_gmap.info_of_attribute<2>(it_f);
Dart3 d2 = it_f->dart();
if (d2 != d && m_gmap.is_free<3>(d2)) {
//free dart and different face, we check if this face can be connected
std::vector<Node> f2_nodes = get_nodes_of_face(it_f);
//same nodes?
bool one_missing = false;
for (auto i = 0; i < f_nodes.size() && !one_missing; i++) {
bool found_same = false;
for (auto j = 0; j < f2_nodes.size() && !found_same; j++) {
if (n2n[f_nodes[i]->info().topo_id] == n2n[f2_nodes[j]->info().topo_id]) {
found_same = true;
}
}
if (!found_same)
one_missing = true;
}
if (!one_missing) {
//we have the same ids, we need to glue in the right order
found_and_glue = true;
//Dart of the initial face d, and the face to glue d2
TCellID ref_id = n2n[m_gmap.attribute<0>(d)->info().topo_id];
TCellID ref_id_0 = n2n[m_gmap.attribute<0>(m_gmap.alpha<0>(d))->info().topo_id];
//starting from d2, we move to find the one that correspond to ref_id
Dart3 d_glue = d2;
while (n2n[m_gmap.attribute<0>(d_glue)->info().topo_id] != ref_id) {
d_glue = m_gmap.alpha<1, 0>(d_glue);
}
if (n2n[m_gmap.attribute<0>(m_gmap.alpha<0>(d_glue))->info().topo_id] == ref_id_0) {
m_gmap.sew<3>(d_glue, d);
} else {
m_gmap.sew<3>(m_gmap.alpha<1>(d_glue), d);
}
}
}
}
}
}
}
}
/*----------------------------------------------------------------------------*/
void
CurvedBlocking::save_vtk_blocking(const std::string &AFileName)
{
gmds::Mesh m(gmds::MeshModel(gmds::DIM3|gmds::N|gmds::E|gmds::F|gmds::R|gmds::E2N|gmds::F2N|gmds::R2N));
convert_to_mesh(m);
gmds::IGMeshIOService ios(&m);
gmds::VTKWriter vtk_writer(&ios);
vtk_writer.setCellOptions(gmds::N|gmds::R);
vtk_writer.setDataOptions(gmds::N|gmds::R);
vtk_writer.write(AFileName);
}
/*----------------------------------------------------------------------------*/
std::vector<std::vector<CurvedBlocking::Edge> >
CurvedBlocking::get_all_sheet_edge_sets() {
std::vector<std::vector<Edge> > edges;
std::vector<Edge> all_edges = get_all_edges();
std::map<TCellID, bool> edge_done;
for (auto e: all_edges) {
edge_done[e->info().topo_id] = false;
}
bool remain_edge_to_do = true;
while (remain_edge_to_do) {
remain_edge_to_do = false;
//we try and find the first that is not already put into a sheet set
bool found_edge = false;
auto edge_index = 0;
for (auto i = 0; i < all_edges.size() && !found_edge; i++) {
//we found an edge to treat
if (edge_done[all_edges[i]->info().topo_id] == false) {
found_edge = true;
edge_index = i;
}
}
if (found_edge) {
//work to do, we will do another iteration
remain_edge_to_do = true;
std::vector<Edge> sh_edges;
get_all_sheet_edges(all_edges[edge_index], sh_edges);
//we store the sheet edges
edges.push_back(sh_edges);
//now we mark them as treated
for (auto e: sh_edges) {
edge_done[e->info().topo_id] = true;
}
}
}
return edges;
}
/*----------------------------------------------------------------------------*/
void
CurvedBlocking::get_all_sheet_edges(const Edge AE, std::vector<Edge> &AEdges) {
AEdges.clear();
std::vector<Dart3> sheet_darts;
get_all_sheet_darts(AE, sheet_darts);
AEdges.resize(sheet_darts.size());
for (auto i = 0; i < sheet_darts.size(); i++) {
AEdges[i] = m_gmap.attribute<1>(sheet_darts[i]);
}
}
/*----------------------------------------------------------------------------*/
void
CurvedBlocking::get_all_sheet_darts(const Edge AE, std::vector<Dart3> &ADarts) {
ADarts.clear();
// we allocate a mark to know all the edges we go through
auto edge_mark = m_gmap.get_new_mark();
std::vector<Dart3> front;
front.push_back(AE->dart());
// the current dart belongs to the final set of darts
ADarts.push_back(AE->dart());
// we mark all the dart of the inital edge to avoid to traverse it twice
m_gmap.mark_cell<1>(AE->dart(), edge_mark);
// Now we propagate along topological parallel edges in each adjacent hexahedral cell
while (!front.empty()) {
// we pick the last dart of the front
Dart3 d = front.back();
front.pop_back();
// we traverse all the darts of the orbit<2,3> starting from d
for (GMap3::Dart_of_orbit_range<2, 3>::iterator it(m_gmap.darts_of_orbit<2, 3>(d).begin()), itend(
m_gmap.darts_of_orbit<2, 3>(d).end()); it != itend;
++it) {
auto d_next_edge = m_gmap.alpha<1, 0, 1>(it);
if (!m_gmap.is_marked(d_next_edge, edge_mark)) {
// it means that the edge containing the dart d_next_edge has not been traversed already.
// We mark the dart of the corresponding edge, and we add it to the front
front.push_back(d_next_edge);
m_gmap.mark_cell<1>(d_next_edge, edge_mark);
// We also add it to the set of darts to return
ADarts.push_back(d_next_edge);
}
}
}
// We must unmark all the marked edges. As we stored one dart per edge, it is straightforward
for (auto d: ADarts) {
m_gmap.unmark_cell<1>(d, edge_mark);
}
m_gmap.free_mark(edge_mark);
}
/*----------------------------------------------------------------------------*/
std::vector<CurvedBlocking::Block> CurvedBlocking::get_all_chord_blocks(const Face AF) {
std::vector<CurvedBlocking::Block> bls;
auto block_mark = m_gmap.get_new_mark();
std::vector<Dart3> face_darts;
get_all_chord_darts(AF, face_darts);
for (auto d: face_darts) {
if (!m_gmap.is_marked(d, block_mark)) {
bls.push_back(m_gmap.attribute<3>(d));
m_gmap.mark_cell<3>(d, block_mark);
}
if (!m_gmap.is_marked(m_gmap.alpha<3>(d), block_mark)) {
bls.push_back(m_gmap.attribute<3>(m_gmap.alpha<3>(d)));
m_gmap.mark_cell<3>(m_gmap.alpha<3>(d), block_mark);
}
}
// We must unmark all the marked edges. As we stored one dart per edge, it is straightforward
for (auto b: bls) {
m_gmap.unmark_cell<3>(b->dart(), block_mark);
}
m_gmap.free_mark(block_mark);
return bls;
}
/*----------------------------------------------------------------------------*/
void
CurvedBlocking::get_all_chord_darts(const Face AF, std::vector<Dart3> &ADarts) {
ADarts.clear();
// we allocate a mark to know all the faces we go through
auto face_mark = m_gmap.get_new_mark();
std::vector<Dart3> front;
front.push_back(AF->dart());
if (!m_gmap.is_free<3>(AF->dart()))
front.push_back(m_gmap.alpha<3>(AF->dart()));
// the current dart belongs to the final set of darts
ADarts.push_back(AF->dart());
// we mark all the dart of the initial face to avoid to traverse it twice
m_gmap.mark_cell<2>(AF->dart(), face_mark);
// Now we propagate along topological parallel faces in each adjacent block
while (!front.empty()) {
// we pick the last dart of the front
Dart3 d = front.back();
front.pop_back();
auto d_next_face = m_gmap.alpha<2, 1, 0, 1, 2, 3>(d);
if (!m_gmap.is_marked(d_next_face, face_mark)) {
// it means that the edge containing the dart d_next_edge has not been traversed already.
// We mark the dart of the corresponding edge, and we add it to the front
front.push_back(d_next_face);
m_gmap.mark_cell<2>(d_next_face, face_mark);
// We also add it to the set of darts to return
ADarts.push_back(d_next_face);
if (!m_gmap.is_free<3>(d_next_face))
front.push_back(m_gmap.alpha<3>(d_next_face));
}
}
// We must unmark all the marked edges. As we stored one dart per edge, it is straightforward
for (auto d: ADarts) {
m_gmap.unmark_cell<2>(d, face_mark);
}
m_gmap.free_mark(face_mark);
}
/*----------------------------------------------------------------------------*/
bool
CurvedBlocking::check_capt_element(const int AnIdElement, const int ADim) {
bool captPossible = false;
auto listEdgesPara = get_all_sheet_edge_sets();
auto allEdges = get_all_edges();
if(ADim == 0){
if(check_cut_possible(AnIdElement,listEdgesPara)){
captPossible=true;
}
}
else{
auto theCurve = m_geom_model->getCurve(AnIdElement);
gmds::TCoord minXYX[3];
gmds::TCoord maxXYX[3];
theCurve->computeBoundingBox(minXYX,maxXYX);
gmds::math::Point minPoint(minXYX[0],minXYX[1],minXYX[2]);
auto projMinPoint = get_projection_info(minPoint,allEdges);
for(int i =0; i< projMinPoint.size();i++){
if(projMinPoint[i].second<1 && projMinPoint[i].second>0){
captPossible=true;
break;
}
}
gmds::math::Point maxPoint(maxXYX[0],maxXYX[1],maxXYX[2]);
auto paramCutMaxPoint = get_cut_info(maxPoint);
auto projMaxPoint = get_projection_info(maxPoint,allEdges);
for(int i =0; i< projMaxPoint.size();i++){
if(projMaxPoint[i].second<1 && projMaxPoint[i].second>0){
captPossible=true;
break;
}
}
}
return captPossible;
}
/*----------------------------------------------------------------------------*/
void
CurvedBlocking::capt_element(const int AnIdElement, const int ADim) {
auto listEdgesPara = get_all_sheet_edge_sets();
if(ADim == 0){
auto paramCut = get_cut_info(AnIdElement);
cut_sheet(paramCut.first,paramCut.second);
}
else{
auto theCurve = m_geom_model->getCurve(AnIdElement);
gmds::TCoord minXYX[3];
gmds::TCoord maxXYX[3];
theCurve->computeBoundingBox(minXYX,maxXYX);
gmds::math::Point minPoint(minXYX[0],minXYX[1],minXYX[2]);
auto paramCutMinPoint = get_cut_info(minPoint);
gmds::math::Point maxPoint(maxXYX[0],maxXYX[1],maxXYX[2]);
auto paramCutMaxPoint = get_cut_info(maxPoint);
}
}
/*----------------------------------------------------------------------------*/
bool
CurvedBlocking::check_cut_possible(int pointId, std::vector<std::vector<CurvedBlocking::Edge>> &AllEdges) {
bool cutPossible = false;
//============================================
auto noCaptPoint0 = m_geom_model->getPoint(pointId);
gmds::math::Point p(noCaptPoint0->X(),noCaptPoint0->Y(),noCaptPoint0->Z());