Skip to content

Commit 9401db7

Browse files
committed
greater_than() and less_than()
1 parent ec25b90 commit 9401db7

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

voxec.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ voxel_operation_map::map_t& voxel_operation_map::map() {
3939
m.insert(std::make_pair(std::string("keep_components"), &instantiate<op_keep_components>));
4040
m.insert(std::make_pair(std::string("dump_surfaces"), &instantiate<op_dump_surfaces>));
4141
m.insert(std::make_pair(std::string("json_stats"), &instantiate<op_json_stats>));
42+
m.insert(std::make_pair(std::string("greater_than"), &instantiate<op_greater>));
43+
m.insert(std::make_pair(std::string("less_than"), &instantiate<op_less>));
4244
#ifdef WITH_IFC
4345
m.insert(std::make_pair(std::string("export_ifc"), &instantiate<op_export_ifc>));
4446
m.insert(std::make_pair(std::string("export_json"), &instantiate<op_export_elements>));

voxec.h

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1103,6 +1103,34 @@ class op_sweep : public op_geom<sweep> {};
11031103
class op_collapse : public op_geom<collapse> {};
11041104
class op_collapse_count : public op_geom<collapse_count> {};
11051105

1106+
template <typename Pred>
1107+
class op_compare : public voxel_operation {
1108+
const std::vector<argument_spec>& arg_names() const {
1109+
// @todo this needs to be expanded to other types for rhs eventually
1110+
static std::vector<argument_spec> nm_ = { { true, "input", "voxels" }, { true, "rhs", "integer"} };
1111+
return nm_;
1112+
}
1113+
symbol_value invoke(const scope_map& scope) const {
1114+
auto* voxels = (regular_voxel_storage*) scope.get_value<abstract_voxel_storage*>("input");
1115+
auto rhs = (uint32_t)scope.get_value<int>("rhs");
1116+
1117+
auto result = voxels->empty_copy();
1118+
uint32_t val;
1119+
1120+
for (auto& pos : *voxels) {
1121+
voxels->Get(pos, &val);
1122+
if (Pred()(val, rhs)) {
1123+
result->Set(pos, &val);
1124+
}
1125+
}
1126+
1127+
return result;
1128+
}
1129+
};
1130+
1131+
class op_greater : public op_compare<std::greater<size_t>> {};
1132+
class op_less : public op_compare<std::less<size_t>> {};
1133+
11061134
class op_traverse : public voxel_operation {
11071135
public:
11081136
const std::vector<argument_spec>& arg_names() const {

0 commit comments

Comments
 (0)