Skip to content

Commit b441989

Browse files
committed
Describe voxel min and max values; option to retain values in group_by()
1 parent ad94978 commit b441989

File tree

1 file changed

+36
-6
lines changed

1 file changed

+36
-6
lines changed

voxec.h

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -183,14 +183,31 @@ namespace {
183183
auto left_world = ((voxels->bounds()[0].as<long>() + left * szl).as<double>() * sz);
184184
auto right_world = ((voxels->bounds()[1].as<long>() + left * szl).as<double>() * sz);
185185

186-
return {
186+
json_logger::meta_data md = {
187187
{"count", (long)voxels->count()},
188188
{"grid", left.format() + " - " + right.format()},
189189
{"bounds", voxels->bounds()[0].format() + " - " + voxels->bounds()[1].format()},
190190
{"world", left_world.format() + " - " + right_world.format()},
191191
{"bits", (long)voxels->value_bits()},
192192
{"chunk_size", (long) csize}
193193
};
194+
195+
if (voxels->value_bits() == 32) {
196+
uint32_t v, mi = std::numeric_limits<uint32_t>::max(), ma = std::numeric_limits<uint32_t>::min();
197+
for (auto& ijk : *(regular_voxel_storage*)voxels) {
198+
voxels->Get(ijk, &v);
199+
if (v < mi) {
200+
mi = v;
201+
}
202+
if (v > ma) {
203+
ma = v;
204+
}
205+
}
206+
md.insert({ "min_value", (long)mi });
207+
md.insert({ "max_value", (long)ma });
208+
}
209+
210+
return md;
194211
}
195212
return {};
196213
}
@@ -758,13 +775,12 @@ namespace {
758775
}
759776
#else
760777
template <typename Fn>
761-
void group_by(regular_voxel_storage* groups, abstract_voxel_storage* voxels, Fn fn) {
778+
void group_by(regular_voxel_storage* groups, abstract_voxel_storage* voxels, Fn fn, bool use_bits=true) {
762779

763780
uint32_t v;
764781

765782
std::map<uint32_t, abstract_voxel_storage*> map;
766783

767-
// @todo this flattens to bits, make this configurable.
768784
// @todo use regions for multi threading
769785
for (auto& ijk : *(regular_voxel_storage*)voxels) {
770786
groups->Get(ijk, &v);
@@ -774,11 +790,21 @@ namespace {
774790
abstract_voxel_storage* r;
775791
auto it = map.find(v);
776792
if (it == map.end()) {
777-
map.insert({ v, r = voxels->empty_copy() });
793+
if (use_bits) {
794+
static bit_t fmt;
795+
map.insert({ v, r = voxels->empty_copy_as(&fmt) });
796+
} else {
797+
map.insert({ v, r = voxels->empty_copy() });
798+
}
778799
} else {
779800
r = it->second;
780801
}
781-
r->Set(ijk);
802+
if (use_bits) {
803+
r->Set(ijk);
804+
} else {
805+
voxels->Get(ijk, &v);
806+
r->Set(ijk, &v);
807+
}
782808
}
783809

784810
for (auto& r : map) {
@@ -791,7 +817,7 @@ namespace {
791817
class op_describe_group_by : public voxel_operation {
792818
public:
793819
const std::vector<argument_spec>& arg_names() const {
794-
static std::vector<argument_spec> nm_ = { { true, "output_path", "string" }, { true, "input", "voxels" }, { true, "groups", "voxels" } };
820+
static std::vector<argument_spec> nm_ = { { true, "output_path", "string" }, { true, "input", "voxels" }, { true, "groups", "voxels" }, { false, "use_bits", "integer" } };
795821
return nm_;
796822
}
797823
symbol_value invoke(const scope_map& scope) const {
@@ -807,6 +833,8 @@ class op_describe_group_by : public voxel_operation {
807833
throw std::runtime_error("Expected a uint stored dataset for groups");
808834
}
809835

836+
bool use_bits = scope.get_value_or<int>("use_bits", 1) == 1;
837+
810838
group_by(groups, voxels, [&ofs, &first](uint32_t id, abstract_voxel_storage* c) {
811839
if (!first) {
812840
ofs << ",";
@@ -821,6 +849,8 @@ class op_describe_group_by : public voxel_operation {
821849
}
822850
#ifdef OLD_GROUP_BY
823851
,scope.get_value_or<int>("THREADS", 1)
852+
#else
853+
, use_bits
824854
#endif
825855
);
826856

0 commit comments

Comments
 (0)