Skip to content

Commit 36bb4c7

Browse files
committed
new group_by implementation
1 parent 9130aab commit 36bb4c7

File tree

1 file changed

+40
-2
lines changed

1 file changed

+40
-2
lines changed

voxec.h

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919

2020
#include <boost/filesystem.hpp>
2121

22+
// #define OLD_GROUP_BY
23+
2224
struct instance_filter_t {
2325
virtual bool operator()(const IfcUtil::IfcBaseEntity*) const = 0;
2426
};
@@ -700,6 +702,7 @@ namespace {
700702
}
701703
};
702704

705+
#ifdef OLD_GROUP_BY
703706
template <typename Fn>
704707
void group_by(regular_voxel_storage* groups, abstract_voxel_storage* voxels, Fn fn, int threads=1) {
705708

@@ -753,6 +756,33 @@ namespace {
753756
}
754757
}
755758
}
759+
#else
760+
template <typename Fn>
761+
void group_by(regular_voxel_storage* groups, abstract_voxel_storage* voxels, Fn fn) {
762+
763+
uint32_t v;
764+
765+
std::map<uint32_t, abstract_voxel_storage*> map;
766+
767+
// @todo this flattens to bits, make this configurable.
768+
// @todo use regions for multi threading
769+
for (auto& ijk : *(regular_voxel_storage*)voxels) {
770+
groups->Get(ijk, &v);
771+
abstract_voxel_storage* r;
772+
auto it = map.find(v);
773+
if (it == map.end()) {
774+
map.insert({ v, r = voxels->empty_copy() });
775+
} else {
776+
r = it->second;
777+
}
778+
r->Set(ijk);
779+
}
780+
781+
for (auto& r : map) {
782+
fn(r.first, r.second);
783+
}
784+
}
785+
#endif
756786
}
757787

758788
class op_describe_group_by : public voxel_operation {
@@ -785,7 +815,11 @@ class op_describe_group_by : public voxel_operation {
785815
delete c;
786816

787817
first = false;
788-
}, scope.get_value_or<int>("THREADS", 1));
818+
}
819+
#ifdef OLD_GROUP_BY
820+
,scope.get_value_or<int>("THREADS", 1)
821+
#endif
822+
);
789823

790824
ofs << "]";
791825

@@ -1816,7 +1850,11 @@ class op_mesh : public voxel_operation {
18161850
group_by(groups, voxels, [&helper, &ofs](uint32_t id, abstract_voxel_storage* c) {
18171851
ofs << "g id-" << id << "\n";
18181852
((regular_voxel_storage*)c)->obj_export(helper, false, false);
1819-
}, scope.get_value_or<int>("THREADS", 1));
1853+
}
1854+
#ifdef OLD_GROUP_BY
1855+
, scope.get_value_or<int>("THREADS", 1)
1856+
#endif
1857+
);
18201858
} else {
18211859

18221860
if (voxels->value_bits() == 1) {

0 commit comments

Comments
 (0)