MCPcopy Create free account
hub / github.com/IfcOpenShell/IfcOpenShell / remove_narrow

Method remove_narrow

src/exterior-shell-extractor/main.py:622–680  ·  view source on GitHub ↗
(self, data)

Source from the content-addressed store, hash-verified

620
621 @utils.trace
622 def remove_narrow(self, data):
623 negate = lambda x: utils.to_opaque(utils.negate(-1)(x))
624
625 astuple_nocopy = lambda dc: list(map(functools.partial(getattr, dc), map(operator.attrgetter('name'), fields(dc))))
626 datas = [model_geometry(*map(lambda x: [x], xs)) for xs in zip(*astuple_nocopy(data))]
627 by_elem_id = lambda i_d: i_d[1].convex_halfspace_trees[0][0].id()
628
629 datas2 = [(k, list(vs)) for k, vs in itertools.groupby(sorted(enumerate(datas), key=by_elem_id), key=by_elem_id)]
630
631 to_remove = []
632
633 for i, rest in datas2:
634 decomps = list(map(lambda d_i: d_i[1].convex_halfspace_trees[0][1], rest))
635 orig_ids = list(map(lambda d_i: d_i[0], rest))
636 # only tested on align inner
637 assert all(len(parts) == 1 for parts in decomps)
638
639 internal_mapping = []
640
641 for j, parts in zip(orig_ids, decomps):
642
643 hs = parts[0]
644 epecks = [h.plane_equation() for h in hs.facets()]
645
646 # print('I', original_index)
647 # for eq in epecks:
648 # print('eq', *(x.to_string() for x in utils.to_tuple(eq)))
649
650 rounded_negated = [tuple(-int(round(v * 10000)) for v in utils.to_double(eq)) for eq in epecks]
651 # for v in rounded_negated:
652 # print('ap', *v)
653
654 for eq in epecks:
655 try:
656 abcd_idx = rounded_negated.index(tuple(int(round(v * 10000)) for v in utils.to_double(eq)))
657 except ValueError as e:
658 continue
659
660 internal_mapping.append((eq, negate(epecks[abcd_idx])))
661 internal_mapping.append((negate(eq), epecks[abcd_idx]))
662 to_remove.append(j)
663
664 # print('removing', original_index)
665 break
666
667 for j, parts in zip(orig_ids, decomps):
668
669 if j in to_remove:
670 continue
671
672 hs = parts[0]
673 for ab in internal_mapping:
674 hs.map(*ab)
675
676 datas_filtered = [d for i, d in enumerate(datas) if i not in to_remove]
677 if not datas_filtered:
678 return model_geometry()
679 else:

Callers 1

__init__Method · 0.95

Calls 8

model_geometryClass · 0.85
negateFunction · 0.85
indexMethod · 0.80
idMethod · 0.45
plane_equationMethod · 0.45
facetsMethod · 0.45
appendMethod · 0.45
mapMethod · 0.45

Tested by

no test coverage detected