Skip to content

Commit cf2da61

Browse files
committed
32 bit in voxec
1 parent 9e5f993 commit cf2da61

File tree

1 file changed

+39
-15
lines changed

1 file changed

+39
-15
lines changed

voxec.h

Lines changed: 39 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,7 @@ class op_create_geometry : public voxel_operation {
405405
#endif
406406

407407
namespace {
408+
template <typename V = bit_t>
408409
abstract_voxel_storage* voxelize(geometry_collection_t* surfaces, double vsize, int chunksize, const boost::optional<int>& threads) {
409410
double x1, y1, z1, x2, y2, z2;
410411
int nx, ny, nz;
@@ -428,26 +429,36 @@ namespace {
428429
ny += PADDING * 2;
429430
nz += PADDING * 2;
430431

431-
if (threads) {
432+
if (std::is_same<V, voxel_uint32_t>::value) {
433+
chunked_voxel_storage<voxel_uint32_t>* storage = new chunked_voxel_storage<voxel_uint32_t>(x1, y1, z1, d, nx, ny, nz, 64);
432434
progress_writer progress("voxelize");
433-
threaded_processor p(x1, y1, z1, vsize, nx, ny, nz, chunksize, *threads, progress);
434-
p.process(surfaces->begin(), surfaces->end(), SURFACE(), output(MERGED()));
435-
return p.voxels();
435+
processor pr(storage, progress);
436+
pr.use_scanline() = false;
437+
// @uint32 defaults to VOLUME_PRODUCT_ID
438+
pr.process(geoms.begin(), geoms.end(), VOLUME_PRODUCT_ID(), output(MERGED()));
439+
return storage;
436440
} else {
437-
progress_writer progress;
438-
auto voxels = factory().chunk_size(chunksize).create(x1, y1, z1, vsize, nx, ny, nz);
439-
// nb: the other constructor would tell the constructor to delete the created voxels
440-
processor p(voxels, progress);
441-
p.process(surfaces->begin(), surfaces->end(), SURFACE(), output(MERGED()));
442-
return voxels;
441+
if (threads) {
442+
progress_writer progress("voxelize");
443+
threaded_processor p(x1, y1, z1, vsize, nx, ny, nz, chunksize, *threads, progress);
444+
p.process(surfaces->begin(), surfaces->end(), SURFACE(), output(MERGED()));
445+
return p.voxels();
446+
} else {
447+
progress_writer progress;
448+
auto voxels = factory().chunk_size(chunksize).create(x1, y1, z1, vsize, nx, ny, nz);
449+
// nb: the other constructor would tell the constructor to delete the created voxels
450+
processor p(voxels, progress);
451+
p.process(surfaces->begin(), surfaces->end(), SURFACE(), output(MERGED()));
452+
return voxels;
453+
}
443454
}
444455
}
445456
}
446457

447458
class op_voxelize : public voxel_operation {
448459
public:
449460
const std::vector<argument_spec>& arg_names() const {
450-
static std::vector<argument_spec> nm_ = { { true, "input", "surfaceset" }, {false, "VOXELSIZE", "real"} };
461+
static std::vector<argument_spec> nm_ = { { true, "input", "surfaceset" }, {false, "VOXELSIZE", "real"}, {false, "type", "string"} };
451462
return nm_;
452463
}
453464
symbol_value invoke(const scope_map& scope) const {
@@ -456,12 +467,21 @@ class op_voxelize : public voxel_operation {
456467
double vsize = scope.get_value<double>("VOXELSIZE");
457468
int cs = scope.get_value<int>("CHUNKSIZE");
458469
int t = scope.get_value<int>("THREADS");
470+
std::string ty = scope.get_value_or<std::string>("type", "bit");
459471

460472
if (surfaces->size() == 0) {
461473
// Just some arbitrary empty region
462-
return new chunked_voxel_storage<bit_t>(make_vec<long>(0,0,0), vsize, cs, make_vec<size_t>(1U,1U,1U));
474+
if (ty == "bit") {
475+
return new chunked_voxel_storage<bit_t>(make_vec<long>(0, 0, 0), vsize, cs, make_vec<size_t>(1U, 1U, 1U));
476+
} else {
477+
return new chunked_voxel_storage<voxel_uint32_t>(make_vec<long>(0, 0, 0), vsize, cs, make_vec<size_t>(1U, 1U, 1U));
478+
}
463479
} else {
464-
return voxelize(surfaces, vsize, cs, t);
480+
if (ty == "bit") {
481+
return voxelize<bit_t>(surfaces, vsize, cs, t);
482+
} else {
483+
return voxelize<voxel_uint32_t>(surfaces, vsize, cs, t);
484+
}
465485
}
466486
}
467487
};
@@ -539,7 +559,7 @@ class op_dump_surfaces : public voxel_operation {
539559
B.Add(C, exp.Current());
540560
geometry_collection_t single = { { pair.first, C} };
541561

542-
auto vs = voxelize(&single, vsize, cs, boost::none);
562+
auto vs = voxelize<>(&single, vsize, cs, boost::none);
543563
auto x = vs->boolean_intersection(voxels);
544564

545565
// std::cout << "#" << pair.first << std::endl;
@@ -979,7 +999,11 @@ class op_mesh : public voxel_operation {
979999
auto voxels = scope.get_value<abstract_voxel_storage*>("input");
9801000
auto filename = scope.get_value<std::string>("filename");
9811001
std::ofstream ofs(filename.c_str());
982-
((regular_voxel_storage*)voxels)->obj_export(ofs);
1002+
if (voxels->value_bits() == 1) {
1003+
((regular_voxel_storage*)voxels)->obj_export(ofs);
1004+
} else {
1005+
((regular_voxel_storage*)voxels)->obj_export(ofs, false, true);
1006+
}
9831007
symbol_value v;
9841008
return v;
9851009
}

0 commit comments

Comments
 (0)