Skip to content
Navigation Menu
{{ message }}
-
-
Notifications
You must be signed in to change notification settings - Fork 925
Expand file tree
/
Copy pathtaxonomy.cpp
More file actions
888 lines (750 loc) · 28.6 KB
/
Copy pathtaxonomy.cpp
File metadata and controls
888 lines (750 loc) · 28.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
#include "../ifcparse/IfcLogger.h"
#include "taxonomy.h"
#include "profile_helper.h"
#include "function_item_evaluator.h"
using namespace ifcopenshell::geometry::taxonomy;
namespace {
bool compare(const trimmed_curve& a, const trimmed_curve& b);
bool compare(const collection& a, const collection& b);
bool compare(const loop& a, const loop& b);
bool compare(const face& a, const face& b);
bool compare(const shell& a, const shell& b);
bool compare(const solid& a, const solid& b);
bool compare(const loft& a, const loft& b);
bool compare(const boolean_result& a, const boolean_result& b);
template <typename T>
bool compare(const eigen_base<T>& t, const eigen_base<T>& u) {
if (t.components_ == nullptr && u.components_ == nullptr) {
return false;
}
else if (t.components_ == nullptr && u.components_ != nullptr) {
return true;
}
else if (t.components_ != nullptr && u.components_ == nullptr) {
return false;
}
auto t_begin = t.components_->data();
auto t_end = t.components_->data() + t.components_->size();
auto u_begin = u.components_->data();
auto u_end = u.components_->data() + u.components_->size();
return std::lexicographical_compare(t_begin, t_end, u_begin, u_end);
}
bool compare(const line& a, const line& b) {
return compare(*a.matrix, *b.matrix);
}
bool compare(const plane& a, const plane& b) {
return compare(*a.matrix, *b.matrix);
}
bool compare(const circle& a, const circle& b) {
if (a.radius == b.radius) {
return compare(*a.matrix, *b.matrix);
}
return a.radius < b.radius;
}
bool compare(const ellipse& a, const ellipse& b) {
if (a.radius == b.radius && a.radius2 == b.radius2) {
return compare(*a.matrix, *b.matrix);
}
return
std::tie(a.radius, a.radius2) <
std::tie(b.radius, b.radius2);
}
bool compare(const bspline_curve&, const bspline_curve&) {
throw std::runtime_error("not implemented");
}
template <typename T>
typename std::enable_if<std::is_base_of<item, T>::value, int>::type less_to_order(const T& a, const T& b) {
const bool a_lt_b = compare(a, b);
const bool b_lt_a = compare(b, a);
return a_lt_b ?
-1 : (!b_lt_a ? 0 : 1);
}
template <typename T>
typename std::enable_if<!std::is_base_of<item, T>::value, int>::type less_to_order(const T& a, const T& b) {
const bool a_lt_b = a < b;
const bool b_lt_a = b < a;
return a_lt_b ?
-1 : (!b_lt_a ? 0 : 1);
}
template <typename T>
int less_to_order_optional(const boost::optional<T>& a, const boost::optional<T>& b) {
if (a && b) {
return less_to_order(*a, *b);
}
else if (!a && !b) {
return 0;
}
else if (a) {
return 1;
}
else {
return -1;
}
}
int compare(const boost::variant<boost::blank, point3::ptr, double>& a, const boost::variant<boost::blank, point3::ptr, double>& b) {
bool a_lt_b, b_lt_a;
if (a.which() == 0) {
return 0;
} else if (a.which() == 1) {
a_lt_b = compare(*boost::get<point3::ptr>(a), *boost::get<point3::ptr>(b));
b_lt_a = compare(*boost::get<point3::ptr>(b), *boost::get<point3::ptr>(a));
} else {
a_lt_b = std::less<double>()(boost::get<double>(a), boost::get<double>(b));
b_lt_a = std::less<double>()(boost::get<double>(b), boost::get<double>(a));
}
return a_lt_b ?
-1 : (!b_lt_a ? 0 : 1);
}
bool compare(const extrusion& a, const extrusion& b) {
// @todo extrusions can also have non-identity matrices right? perhaps it's time
// for a dedicated transform node and not on the abstract geom_item.
const int order[3] = {
less_to_order(a.basis, b.basis),
less_to_order(a.direction, b.direction),
a.depth < b.depth ? -1 : (a.depth == b.depth ? 0 : 1)
};
auto it = std::find_if(std::begin(order), std::end(order), [](int x) { return x; });
if (it == std::end(order)) return false;
return *it == -1;
}
bool compare(const node&, const node&) {
throw std::runtime_error("not implemented");
}
bool compare(const offset_curve&, const offset_curve&) {
throw std::runtime_error("not implemented");
}
bool compare(const revolve&, const revolve&) {
throw std::runtime_error("not implemented");
}
bool compare(const bspline_surface&, const bspline_surface&) {
throw std::runtime_error("not implemented");
}
bool compare(const cylinder&, const cylinder&) {
throw std::runtime_error("not implemented");
}
bool compare(const sphere&, const sphere&) {
throw std::runtime_error("not implemented");
}
bool compare(const torus&, const torus&) {
throw std::runtime_error("not implemented");
}
bool compare(const sweep_along_curve&, const sweep_along_curve&) {
throw std::runtime_error("not implemented");
}
bool compare(const function_item&, const function_item&) {
throw std::runtime_error("not implemented");
}
bool compare(const functor_item&, const functor_item&) {
throw std::runtime_error("not implemented");
}
bool compare(const piecewise_function&, const piecewise_function&) {
throw std::runtime_error("not implemented");
}
bool compare(const gradient_function&, const gradient_function&) {
throw std::runtime_error("not implemented");
}
bool compare(const cant_function&, const cant_function&) {
throw std::runtime_error("not implemented");
}
bool compare(const offset_function&, const offset_function&) {
throw std::runtime_error("not implemented");
}
bool compare(const style& a, const style& b) {
const int order[5] = {
less_to_order(a.name, b.name),
less_to_order(a.diffuse, b.diffuse),
less_to_order(a.specular, b.specular),
less_to_order(a.specularity, b.specularity),
less_to_order(a.transparency, b.transparency)
};
auto it = std::find_if(std::begin(order), std::end(order), [](int x) { return x; });
if (it == std::end(order)) return false;
return *it == -1;
}
/* A compile-time for loop over the taxonomy kinds */
template <size_t N>
struct dispatch_comparison {
static bool dispatch(const item* a, const item* b) {
if (N == a->kind() && N == b->kind()) {
auto A = static_cast<const type_by_kind::type<N>*>(a);
auto B = static_cast<const type_by_kind::type<N>*>(b);
return compare(*A, *B);
}
else {
return dispatch_comparison<N + 1>::dispatch(a, b);
}
}
};
template <>
struct dispatch_comparison<type_by_kind::max> {
static bool dispatch(const item*, const item*) {
return false;
}
};
}
ifcopenshell::geometry::taxonomy::topology_error::~topology_error() = default;
bool ifcopenshell::geometry::taxonomy::less(item::const_ptr a, item::const_ptr b) {
if (a == b) {
return false;
}
int a_kind = a->kind();
int b_kind = b->kind();
if (a_kind != b_kind) {
return a_kind < b_kind;
}
#ifdef TAXONOMY_USE_SHARED_PTR
return dispatch_comparison<0>::dispatch(a.get(), b.get());
#endif
}
namespace {
bool compare(const trimmed_curve& a, const trimmed_curve& b) {
int a_which_start = a.start.which();
int a_which_end = a.end.which();
int b_which_start = b.start.which();
int b_which_end = b.end.which();
if (std::tie(a.orientation, a_which_start, a_which_end) ==
std::tie(b.orientation, b_which_start, b_which_end)) {
int start_state = compare(a.start, b.start);
if (start_state == 0) {
int end_state = compare(a.end, b.end);
if (end_state == 0) {
int a_has_basis = !!a.basis;
int b_has_basis = !!a.basis;
if (a_has_basis == b_has_basis) {
if (!a_has_basis) {
// Finally, equality
return false;
}
else {
return less(a.basis, b.basis);
}
}
else {
return a_has_basis < b_has_basis;
}
}
else {
return end_state == -1;
}
}
else {
return start_state == -1;
}
}
else {
return
std::tie(a.orientation, a_which_start, a_which_end) <
std::tie(b.orientation, b_which_start, b_which_end);
}
}
template <typename T>
bool compare_collection(const collection_base<T>& a, const collection_base<T>& b) {
if (a.children.size() == b.children.size()) {
auto at = a.children.begin();
auto bt = b.children.begin();
for (; at != a.children.end(); ++at, ++bt) {
const bool a_lt_b = less(*at, *bt);
const bool b_lt_a = less(*bt, *at);
if (!a_lt_b && !b_lt_a) {
// Elements equal.
continue;
}
return a_lt_b;
}
// Vectors equal, compare matrix (in case of mapped items).
return compare(*a.matrix, *b.matrix);
}
else {
return a.children.size() < b.children.size();
}
}
bool compare(const loop& a, const loop& b) {
return compare_collection<edge>(a, b);
}
bool compare(const face& a, const face& b) {
return compare_collection<loop>(a, b);
}
bool compare(const shell& a, const shell& b) {
return compare_collection<face>(a, b);
}
bool compare(const solid& a, const solid& b) {
return compare_collection<shell>(a, b);
}
bool compare(const loft& a, const loft& b) {
return compare_collection<geom_item>(a, b);
}
bool compare(const collection& a, const collection& b) {
return compare_collection<geom_item>(a, b);
}
bool compare(const boolean_result& a, const boolean_result& b) {
return compare_collection<geom_item>(a, b);
}
}
ifcopenshell::geometry::taxonomy::solid::ptr ifcopenshell::geometry::create_box(double dx, double dy, double dz) {
return create_box(0., 0., 0., dx, dy, dz);
}
ifcopenshell::geometry::taxonomy::solid::ptr ifcopenshell::geometry::create_box(double x, double y, double z, double dx, double dy, double dz) {
auto solid = make<taxonomy::solid>();
auto shell = make<taxonomy::shell>();
solid->children.push_back(shell);
// x = 0
{
auto face = make<taxonomy::face>();
auto loop = make<taxonomy::loop>();
face->children.push_back(loop);
loop->external = true;
shell->children.push_back(face);
std::array<taxonomy::point3::ptr, 4> points{
taxonomy::make<taxonomy::point3>(x + 0, y + 0, z + 0),
taxonomy::make<taxonomy::point3>(x + 0, y + dy, z + 0),
taxonomy::make<taxonomy::point3>(x + 0, y + dy, z + dz),
taxonomy::make<taxonomy::point3>(x + 0, y + 0, z + dz)
};
loop->children.push_back(make<taxonomy::edge>(points[0], points[1]));
loop->children.push_back(make<taxonomy::edge>(points[1], points[2]));
loop->children.push_back(make<taxonomy::edge>(points[2], points[3]));
loop->children.push_back(make<taxonomy::edge>(points[3], points[0]));
}
// x = dx
{
auto face = make<taxonomy::face>();
auto loop = make<taxonomy::loop>();
face->children.push_back(loop);
loop->external = true;
shell->children.push_back(face);
std::array<taxonomy::point3::ptr, 4> points{
taxonomy::make<taxonomy::point3>(x + dx, y + 0, z + 0),
taxonomy::make<taxonomy::point3>(x + dx, y + 0, z + dz),
taxonomy::make<taxonomy::point3>(x + dx, y + dy, z + dz),
taxonomy::make<taxonomy::point3>(x + dx, y + dy, z + 0)
};
loop->children.push_back(make<taxonomy::edge>(points[0], points[1]));
loop->children.push_back(make<taxonomy::edge>(points[1], points[2]));
loop->children.push_back(make<taxonomy::edge>(points[2], points[3]));
loop->children.push_back(make<taxonomy::edge>(points[3], points[0]));
}
// y = 0
{
auto face = make<taxonomy::face>();
auto loop = make<taxonomy::loop>();
face->children.push_back(loop);
loop->external = true;
shell->children.push_back(face);
std::array<taxonomy::point3::ptr, 4> points{
taxonomy::make<taxonomy::point3>(x + 0, y + 0, z + 0),
taxonomy::make<taxonomy::point3>(x + 0, y + 0, z + dz),
taxonomy::make<taxonomy::point3>(x + dx, y + 0, z + dz),
taxonomy::make<taxonomy::point3>(x + dx, y + 0, z + 0)
};
loop->children.push_back(make<taxonomy::edge>(points[0], points[1]));
loop->children.push_back(make<taxonomy::edge>(points[1], points[2]));
loop->children.push_back(make<taxonomy::edge>(points[2], points[3]));
loop->children.push_back(make<taxonomy::edge>(points[3], points[0]));
}
// y = dy
{
auto face = make<taxonomy::face>();
auto loop = make<taxonomy::loop>();
face->children.push_back(loop);
loop->external = true;
shell->children.push_back(face);
std::array<taxonomy::point3::ptr, 4> points{
taxonomy::make<taxonomy::point3>(x + 0, y + dy, z + 0),
taxonomy::make<taxonomy::point3>(x + dx, y + dy, z + 0),
taxonomy::make<taxonomy::point3>(x + dx, y + dy, z + dz),
taxonomy::make<taxonomy::point3>(x + 0, y + dy, z + dz)
};
loop->children.push_back(make<taxonomy::edge>(points[0], points[1]));
loop->children.push_back(make<taxonomy::edge>(points[1], points[2]));
loop->children.push_back(make<taxonomy::edge>(points[2], points[3]));
loop->children.push_back(make<taxonomy::edge>(points[3], points[0]));
}
// z = 0
{
auto face = make<taxonomy::face>();
auto loop = make<taxonomy::loop>();
face->children.push_back(loop);
loop->external = true;
shell->children.push_back(face);
std::array<taxonomy::point3::ptr, 4> points{
taxonomy::make<taxonomy::point3>(x + 0, y + 0, z + 0),
taxonomy::make<taxonomy::point3>(x + dx, y + 0, z + 0),
taxonomy::make<taxonomy::point3>(x + dx, y + dy, z + 0),
taxonomy::make<taxonomy::point3>(x + 0, y + dy, z + 0)
};
loop->children.push_back(make<taxonomy::edge>(points[0], points[1]));
loop->children.push_back(make<taxonomy::edge>(points[1], points[2]));
loop->children.push_back(make<taxonomy::edge>(points[2], points[3]));
loop->children.push_back(make<taxonomy::edge>(points[3], points[0]));
}
// z = dz
{
auto face = make<taxonomy::face>();
auto loop = make<taxonomy::loop>();
face->children.push_back(loop);
loop->external = true;
shell->children.push_back(face);
std::array<taxonomy::point3::ptr, 4> points{
taxonomy::make<taxonomy::point3>(x + 0, y + 0, z + dz),
taxonomy::make<taxonomy::point3>(x + 0, y + dy, z + dz),
taxonomy::make<taxonomy::point3>(x + dx, y + dy, z + dz),
taxonomy::make<taxonomy::point3>(x + dx, y + 0, z + dz)
};
loop->children.push_back(make<taxonomy::edge>(points[0], points[1]));
loop->children.push_back(make<taxonomy::edge>(points[1], points[2]));
loop->children.push_back(make<taxonomy::edge>(points[2], points[3]));
loop->children.push_back(make<taxonomy::edge>(points[3], points[0]));
}
return solid;
}
///////////////////
piecewise_function::piecewise_function(double start, const spans_t& s, const IfcUtil::IfcBaseInterface* instance) : function_item(instance), start_(start), spans_(s) {
}
piecewise_function::piecewise_function(double start, const std::vector<piecewise_function::ptr>& pwfs, const IfcUtil::IfcBaseInterface* instance) : function_item(instance), start_(start) {
for (auto& pwf : pwfs) {
spans_.insert(spans_.end(), pwf->spans().begin(), pwf->spans().end());
}
};
const piecewise_function::spans_t& piecewise_function::spans() const { return spans_; }
bool piecewise_function::is_empty() const { return spans_.empty(); }
double piecewise_function::start() const { return start_; }
double piecewise_function::end() const { return start_ + length(); }
double piecewise_function::length() const {
return std::accumulate(spans_.begin(), spans_.end(), 0.0, [](const auto& v, const auto& s) { return v + s->length(); });
// this is a secondary option where we only compute length once and cache it.
// mutex is needed to prevent interruption of the accumulation if there is multi-threading
// skipping this detail for now and just adding up the span lengths every time
//if (!length_.has_value()) {
// length_ = std::accumulate(spans_.begin(), spans_.end(), 0.0, [](const auto& v, const auto& s) { return v + s->length(); });
//}
//return *length_;
}
gradient_function::gradient_function(piecewise_function::const_ptr horizontal, piecewise_function::const_ptr vertical, const IfcUtil::IfcBaseInterface* instance) :
function_item(instance), horizontal_(horizontal), vertical_(vertical) {
}
double gradient_function::start() const { return std::max(horizontal_->start(), vertical_->start()); }
double gradient_function::end() const { return std::min(horizontal_->end(), vertical_->end()); }
piecewise_function::const_ptr gradient_function::get_horizontal() const { return horizontal_; }
piecewise_function::const_ptr gradient_function::get_vertical() const { return vertical_; }
cant_function::cant_function(gradient_function::const_ptr gradient, piecewise_function::const_ptr cant, const IfcUtil::IfcBaseInterface* instance) :
function_item(instance), gradient_(gradient), cant_(cant) {
}
double cant_function::start() const { return std::max(gradient_->start(), cant_->start()); }
double cant_function::end() const { return std::min(gradient_->end(), cant_->end()); }
gradient_function::const_ptr cant_function::get_gradient() const { return gradient_; }
piecewise_function::const_ptr cant_function::get_cant() const { return cant_; }
offset_function::offset_function(function_item::const_ptr basis, piecewise_function::const_ptr offset, const IfcUtil::IfcBaseInterface* instance) : function_item(instance),
basis_(basis),
offset_(offset) {
}
double offset_function::start() const { return basis_->start(); }
double offset_function::end() const { return basis_->end(); }
function_item::const_ptr offset_function::get_basis() const { return basis_; }
piecewise_function::const_ptr offset_function::get_offset() const { return offset_; }
ifcopenshell::geometry::taxonomy::collection::ptr ifcopenshell::geometry::flatten(const taxonomy::collection::ptr& deep) {
auto flat = make<taxonomy::collection>();
ifcopenshell::geometry::visit<taxonomy::collection>(deep, [&flat](taxonomy::ptr i) {
flat->children.push_back(std::static_pointer_cast<taxonomy::geom_item>(clone(i)));
});
return flat;
}
const std::string& ifcopenshell::geometry::taxonomy::kind_to_string(kinds k) {
using namespace std::string_literals;
static std::string values[] = {
"matrix4"s,
"point3"s,
"direction3"s,
"line"s,
"circle"s,
"ellipse"s,
"bspline_curve"s,
"offset_curve"s,
"plane"s,
"cylinder"s,
"sphere"s,
"torus"s,
"bspline_surface"s,
"edge"s,
"loop"s,
"face"s,
"shell"s,
"solid"s,
"loft"s,
"extrusion"s,
"revolve"s,
"sweep_along_curve"s,
"node"s,
"collection"s,
"boolean_result"s,
"function_item"s,
"functor_item"s,
"piecewise_function"s,
"gradient_function"s,
"cant_function"s,
"offset_function"s,
"colour"s,
"style"s,
};
return values[k];
}
std::atomic_uint32_t item::counter_(0);
void ifcopenshell::geometry::taxonomy::item::print(std::ostream& o, int indent) const {
o << std::string(indent, ' ') << kind_to_string(kind()) << std::endl;
}
void ifcopenshell::geometry::taxonomy::matrix4::print(std::ostream& o, int indent) const {
print_impl(o, kind_to_string(kind()), indent);
}
void ifcopenshell::geometry::taxonomy::colour::print(std::ostream& o, int indent) const {
print_impl(o, kind_to_string(kind()), indent);
}
void ifcopenshell::geometry::taxonomy::style::print(std::ostream& o, int indent) const {
o << std::string(indent, ' ') << "style" << std::endl;
o << std::string(indent, ' ') << " " << "name " << (name) << std::endl;
if (diffuse.components_) {
o << std::string(indent, ' ') << " " << "diffuse" << std::endl;
diffuse.print(o, indent + 5 + 7);
}
if (specular.components_) {
o << std::string(indent, ' ') << " " << "specular" << std::endl;
specular.print(o, indent + 5 + 8);
}
// @todo
}
void ifcopenshell::geometry::taxonomy::point3::print(std::ostream& o, int indent) const {
print_impl(o, kind_to_string(kind()), indent);
}
void ifcopenshell::geometry::taxonomy::direction3::print(std::ostream& o, int indent) const {
print_impl(o, kind_to_string(kind()), indent);
}
void ifcopenshell::geometry::taxonomy::line::print(std::ostream& o, int indent) const {
print_impl(o, kind_to_string(kind()), indent);
}
void ifcopenshell::geometry::taxonomy::circle::print(std::ostream& o, int indent) const {
print_impl(o, kind_to_string(kind()), indent);
o << std::string(indent + 4, ' ') << "radius " << radius << std::endl;
}
void ifcopenshell::geometry::taxonomy::ellipse::print(std::ostream& o, int indent) const {
print_impl(o, kind_to_string(kind()), indent);
o << std::string(indent + 4, ' ') << "radii " << radius << " " << radius2 << std::endl;
}
void ifcopenshell::geometry::taxonomy::trimmed_curve::print(std::ostream& o, int indent) const {
o << std::string(indent, ' ') << kind_to_string(kind());
if (!this->orientation.get_value_or(true)) {
o << " [R]";
} else {
o << " [ ]";
}
if (!this->curve_sense.get_value_or(true)) {
o << " [R]";
} else {
o << " [ ]";
}
o << std::endl;
if (basis) {
basis->print(o, indent + 4);
}
const boost::variant<boost::blank, point3::ptr, double>* const start_end[2] = { &start, &end };
for (int i = 0; i < 2; ++i) {
o << std::string(indent + 4, ' ') << (i == 0 ? "start" : "end") << std::endl;
if (start_end[i]->which() == 1) {
boost::get<point3::ptr>(*start_end[i])->print(o, indent + 4);
} else if (start_end[i]->which() == 2) {
o << std::string(indent + 4, ' ') << "parameter " << boost::get<double>(*start_end[i]) << std::endl;
}
}
if (this->instance) {
std::ostringstream oss;
this->instance->as<IfcUtil::IfcBaseClass>()->toString(oss);
o << std::string(indent + 4, ' ') << oss.str() << std::endl;
}
}
void ifcopenshell::geometry::taxonomy::extrusion::print(std::ostream& o, int indent) const {
o << std::string(indent, ' ') << "extrusion " << depth << std::endl;
direction->print(o, indent + 4);
basis->print(o, indent + 4);
}
boost::optional<face::ptr> ifcopenshell::geometry::taxonomy::loop_to_face_upgrade_impl(ptr item) {
boost::optional<face::ptr> face_;
auto loop_ = dcast<loop>(item);
if (loop_) {
loop_->external = true;
face_ = make<face>();
(*face_)->instance = loop_->instance;
(*face_)->matrix = loop_->matrix;
(*face_)->children = { clone(loop_) };
}
return face_;
}
boost::optional<edge::ptr> ifcopenshell::geometry::taxonomy::curve_to_edge_upgrade_impl(ptr item) {
boost::optional<edge::ptr> edge_;
auto circle_ = dcast<circle>(item);
auto ellipse_ = dcast<ellipse>(item);
auto line_ = dcast<line>(item);
auto bspline_curve_ = dcast<bspline_curve>(item);
if (circle_ || ellipse_ || line_ || bspline_curve_) {
edge_ = make<edge>();
if (circle_) {
(*edge_)->basis = circle_;
(*edge_)->instance = circle_->instance;
} else if (ellipse_) {
(*edge_)->basis = ellipse_;
(*edge_)->instance = ellipse_->instance;
} else if (line_) {
(*edge_)->basis = line_;
(*edge_)->instance = line_->instance;
} else if (bspline_curve_) {
(*edge_)->basis = bspline_curve_;
(*edge_)->instance = bspline_curve_->instance;
}
if (circle_ || ellipse_) {
// @todo
(*edge_)->start = 0.;
(*edge_)->end = 2 * boost::math::constants::pi<double>();
}
}
return edge_;
}
boost::optional<loop::ptr> ifcopenshell::geometry::taxonomy::curve_to_loop_upgrade_impl(ptr item) {
boost::optional<loop::ptr> loop_;
auto circle_ = dcast<circle>(item);
auto ellipse_ = dcast<ellipse>(item);
auto line_ = dcast<line>(item);
auto bspline_curve_ = dcast<bspline_curve>(item);
if (circle_ || ellipse_ || line_ || bspline_curve_) {
auto edge_ = make<edge>();
if (circle_) {
edge_->basis = circle_;
} else if (ellipse_) {
edge_->basis = ellipse_;
} else if (line_) {
edge_->basis = line_;
} else if (bspline_curve_) {
edge_->basis = bspline_curve_;
}
if (circle_ || ellipse_) {
// @todo
edge_->start = 0.;
edge_->end = 2 * boost::math::constants::pi<double>();
}
loop_ = make<loop>();
(*loop_)->children.push_back(edge_);
}
return loop_;
}
boost::optional<loop::ptr> ifcopenshell::geometry::taxonomy::edge_to_loop_upgrade_impl(ptr item) {
boost::optional<loop::ptr> loop_;
auto edge_ = dcast<edge>(item);
if (edge_) {
loop_ = make<loop>();
(*loop_)->children.push_back(edge_);
}
return loop_;
}
boost::optional<face::ptr> ifcopenshell::geometry::taxonomy::curve_to_face_upgrade_impl(ptr item) {
boost::optional<face::ptr> face_;
auto circle_ = dcast<circle>(item);
auto ellipse_ = dcast<ellipse>(item);
auto line_ = dcast<line>(item);
auto bspline_curve_ = dcast<bspline_curve>(item);
if (circle_ || ellipse_ || line_ || bspline_curve_) {
auto edge_ = make<edge>();
if (circle_) {
edge_->basis = circle_;
} else if (ellipse_) {
edge_->basis = ellipse_;
} else if (line_) {
edge_->basis = line_;
} else if (bspline_curve_) {
edge_->basis = bspline_curve_;
}
if (circle_ || ellipse_) {
// @todo
edge_->start = 0.;
edge_->end = 2 * boost::math::constants::pi<double>();
}
auto loop_ = make<loop>();
loop_->children.push_back(edge_);
face_ = make<face>();
(*face_)->instance = loop_->instance;
(*face_)->matrix = loop_->matrix;
(*face_)->children = { clone(loop_) };
}
return face_;
}
namespace {
// @todo eliminate redundancy with cgal kernel
void evaluate_curve(const circle::ptr& c, double u, point3& p) {
Eigen::Vector4d xy{ c->radius * std::cos(u), c->radius * std::sin(u), 0, 1. };
p.components() = (c->matrix->ccomponents() * xy).head<3>();
}
// @todo eliminate redundancy with cgal kernel
void evaluate_curve_d1(const circle::ptr& c, double u, direction3& p) {
Eigen::Vector4d xy{ -std::sin(u), cos(u), 0, 0. };
p.components() = (c->matrix->ccomponents() * xy).head<3>();
}
double project_onto_curve(const circle::ptr& c, const point3& p) {
Eigen::Vector2d xy = (c->matrix->ccomponents().inverse() * p.ccomponents().homogeneous()).head<2>();
return std::atan2(xy(1), xy(0));
}
}
boost::optional<function_item::ptr> ifcopenshell::geometry::taxonomy::loop_to_function_item_upgrade_impl(ptr item) {
boost::optional<function_item::ptr> function_item_;
auto loop_ = dcast<loop>(item);
if (loop_) {
if (loop_->function_item.is_initialized()) {
function_item_ = loop_->function_item;
} else {
// piecewise_function is a specialization of function_item - callers don't need to know this detail
piecewise_function::spans_t spans;
spans.reserve(loop_->children.size());
for (auto& edge_ : loop_->children) {
if (edge_->basis && edge_->basis->kind() == CIRCLE) {
const circle::ptr circ = std::static_pointer_cast<circle>(edge_->basis);
auto* s_pnt = boost::get<point3::ptr>(&edge_->start);
auto* e_pnt = boost::get<point3::ptr>(&edge_->end);
auto* s_param = boost::get<double>(&edge_->start);
auto* e_param = boost::get<double>(&edge_->end);
if (!s_pnt && !s_param) {
return boost::none;
}
if (!e_pnt && !e_param) {
return boost::none;
}
double s = s_pnt ? project_onto_curve(circ, **s_pnt) : *s_param;
double e = e_pnt ? project_onto_curve(circ, **e_pnt) : *e_param;
auto l = std::fabs(s - e) * circ->radius;
std::function<Eigen::Matrix4d(double)> fn = [circ, s](double u) {
point3 P;
direction3 d;
evaluate_curve(circ, u / circ->radius + s, P);
evaluate_curve_d1(circ, u / circ->radius + s, d);
return matrix4(P.ccomponents(), circ->matrix->ccomponents().col(2).head<3>(), d.ccomponents()).components();
};
spans.emplace_back(taxonomy::make<taxonomy::functor_item>(l, fn));
} else if (edge_->start.which() == 1 && edge_->end.which() == 1) {
if (edge_->basis && edge_->basis->kind() != LINE) {
Logger::Root().Message(Logger::Severity::LOG_WARNING, "UNS", 20, "Basis curve not supported - edge is treated as a straight line edge");
}
const auto& s = boost::get<point3::ptr>(edge_->start)->ccomponents();
const auto& e = boost::get<point3::ptr>(edge_->end)->ccomponents();
Eigen::Vector3d v = e - s;
auto l = v.norm(); // the norm of a vector is a measure of its length
v.normalize(); // normalize the vector so that it is a unit direction vector
std::function<Eigen::Matrix4d(double)> fn = [s, v](double u) {
Eigen::Vector3d o(s + u * v), axis(0, 0, 1), refDirection(v);
auto Y = axis.cross(refDirection).normalized();
axis = refDirection.cross(Y).normalized();
return make<matrix4>(o, axis, refDirection)->components();
};
spans.emplace_back(taxonomy::make<taxonomy::functor_item>(l, fn));
} else {
Logger::Root().Message(Logger::Severity::LOG_ERROR, "UNS", 21, "Basis curve not supported");
return boost::none;
}
}
function_item_ = make<piecewise_function>(0.0, spans);
loop_->function_item = function_item_;
}
}
return function_item_;
}
You can’t perform that action at this time.
