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

Method apply_mapping

src/exterior-shell-extractor/main.py:831–886  ·  view source on GitHub ↗
(self, data, mapping, from_disk=False)

Source from the content-addressed store, hash-verified

829
830 @utils.trace
831 def apply_mapping(self, data, mapping, from_disk=False):
832 if from_disk:
833 by_id = mapping
834 else:
835 by_id = defaultdict(lambda: (list(), list()))
836 for a, b, idxs in mapping:
837 fr, to = (" ".join(map(lambda n: n.to_string(), utils.to_tuple(x))) for x in (a,b))
838 if fr == to:
839 continue
840 for idx in idxs:
841 by_id[idx][0].append(a)
842 by_id[idx][1].append(b)
843
844 if self.settings.store_mapping:
845 # can be used to store global mapping and apply to individually extracted elements
846 mapping = defaultdict(list)
847 for k, vs in by_id.items():
848 guid = data.convex_halfspace_trees[k][0].GlobalId
849 for ab in zip(*vs):
850 from_to = tuple(" ".join(map(lambda n: n.to_string(), utils.to_tuple(x))) for x in ab)
851 mapping[guid].append(from_to)
852 json.dump(mapping, open('epeck_mapping.json', 'w'))
853
854 for i, (elem, ps) in enumerate(data.convex_halfspace_trees):
855
856 if from_disk:
857 maps = by_id[elem.GlobalId]
858 else:
859 maps = by_id[i]
860
861 for j, p in enumerate(ps):
862
863 if self.settings.verbose:
864 pps = p.solid()
865 old_area = pps.area().to_double()
866 old_volume = pps.volume().to_double()
867 open(f'{i}_{j}_before.obj', 'w').write(pps.serialize_obj())
868
869 p.map(*maps)
870
871 if self.settings.verbose:
872 for ab in zip(*maps):
873 c, d = map(utils.to_double, ab)
874 print(*c, '->', *d)
875 c, d = map(to_str, ab)
876 print(*c, '->', *d)
877
878 pps = p.solid()
879 new_area = pps.area().to_double()
880 new_volume = pps.volume().to_double()
881 open(f'{i}_{j}_after.obj', 'w').write(pps.serialize_obj())
882 if new_area:
883 print(i, j, new_area / old_area, old_area, new_area, old_volume, new_volume)
884
885 if new_area / old_area > 100:
886 breakpoint()
887
888 @staticmethod

Callers 1

__init__Method · 0.95

Calls 13

printFunction · 0.85
to_tupleMethod · 0.80
openFunction · 0.50
joinMethod · 0.45
to_stringMethod · 0.45
appendMethod · 0.45
itemsMethod · 0.45
dumpMethod · 0.45
solidMethod · 0.45
areaMethod · 0.45
volumeMethod · 0.45
writeMethod · 0.45

Tested by

no test coverage detected