@@ -426,7 +426,7 @@ namespace {
426426 }
427427
428428 template <typename V = bit_t >
429- abstract_voxel_storage* voxelize (geometry_collection_t * surfaces, double vsize, int chunksize, const boost::optional<int >& threads, bool silent = false ) {
429+ abstract_voxel_storage* voxelize (geometry_collection_t * surfaces, double vsize, int chunksize, const boost::optional<int >& threads, bool use_volume, bool silent = false ) {
430430 double x1, y1, z1, x2, y2, z2;
431431 int nx, ny, nz;
432432
@@ -449,26 +449,33 @@ namespace {
449449 ny += PADDING * 2 ;
450450 nz += PADDING * 2 ;
451451
452+ std::unique_ptr<fill_volume_t > method;
453+ if (use_volume) {
454+ method = std::make_unique<VOLUME>();
455+ } else {
456+ method = std::make_unique<SURFACE>();
457+ }
458+
452459 if (std::is_same<V, voxel_uint32_t >::value) {
453460 chunked_voxel_storage<voxel_uint32_t >* storage = new chunked_voxel_storage<voxel_uint32_t >(x1, y1, z1, vsize, nx, ny, nz, 64 );
454461 progress_writer progress (" voxelize" );
455462 processor pr (storage, progress);
456463 pr.use_scanline () = false ;
457- // @uint32 defaults to VOLUME_PRODUCT_ID
464+ // @todo, uint32 defaults to VOLUME_PRODUCT_ID, make this explicit
458465 pr.process (surfaces->begin (), surfaces->end (), VOLUME_PRODUCT_ID (), output (MERGED ()));
459466 return storage;
460467 } else {
461468 if (threads) {
462469 progress_writer progress (" voxelize" , silent);
463470 threaded_processor p (x1, y1, z1, vsize, nx, ny, nz, chunksize, *threads, progress);
464- p.process (surfaces->begin (), surfaces->end (), SURFACE () , output (MERGED ()));
471+ p.process (surfaces->begin (), surfaces->end (), *method , output (MERGED ()));
465472 return p.voxels ();
466473 } else {
467474 progress_writer progress;
468475 auto voxels = factory ().chunk_size (chunksize).create (x1, y1, z1, vsize, nx, ny, nz);
469476 // nb: the other constructor would tell the constructor to delete the created voxels
470477 processor p (voxels, progress);
471- p.process (surfaces->begin (), surfaces->end (), SURFACE () , output (MERGED ()));
478+ p.process (surfaces->begin (), surfaces->end (), *method , output (MERGED ()));
472479 return voxels;
473480 }
474481 }
@@ -478,7 +485,7 @@ namespace {
478485class op_voxelize : public voxel_operation {
479486public:
480487 const std::vector<argument_spec>& arg_names () const {
481- static std::vector<argument_spec> nm_ = { { true , " input" , " surfaceset" }, {false , " VOXELSIZE" , " real" }, {false , " type" , " string" } };
488+ static std::vector<argument_spec> nm_ = { { true , " input" , " surfaceset" }, {false , " VOXELSIZE" , " real" }, {false , " type" , " string" }, { false , " method " , " string " } };
482489 return nm_;
483490 }
484491 symbol_value invoke (const scope_map& scope) const {
@@ -488,6 +495,13 @@ class op_voxelize : public voxel_operation {
488495 int cs = scope.get_value <int >(" CHUNKSIZE" );
489496 int t = scope.get_value <int >(" THREADS" );
490497 std::string ty = scope.get_value_or <std::string>(" type" , " bit" );
498+ std::string method = scope.get_value_or <std::string>(" method" , " surface" );
499+
500+ if (method != " surface" && method != " volume" ) {
501+ throw std::runtime_error (" Unsupported method " + method);
502+ }
503+
504+ bool use_volume = method == " volume" ;
491505
492506 if (surfaces->size () == 0 ) {
493507 // Just some arbitrary empty region
@@ -498,9 +512,9 @@ class op_voxelize : public voxel_operation {
498512 }
499513 } else {
500514 if (ty == " bit" ) {
501- return voxelize<bit_t >(surfaces, vsize, cs, t);
515+ return voxelize<bit_t >(surfaces, vsize, cs, t, use_volume, silent );
502516 } else {
503- return voxelize<voxel_uint32_t >(surfaces, vsize, cs, t);
517+ return voxelize<voxel_uint32_t >(surfaces, vsize, cs, t, use_volume, silent );
504518 }
505519 }
506520 }
0 commit comments