77#include " offset.h"
88#include " fill_gaps.h"
99#include " traversal.h"
10+ #include " json_logger.h"
1011
1112#ifdef WITH_IFC
1213#include < ifcparse/IfcFile.h>
@@ -138,6 +139,7 @@ struct argument_spec {
138139class voxel_operation {
139140public:
140141 boost::optional<std::function<void (float )>> application_progress_callback;
142+ bool silent = false ;
141143
142144 virtual const std::vector<argument_spec>& arg_names () const = 0;
143145 virtual symbol_value invoke (const scope_map& scope) const = 0;
@@ -384,20 +386,22 @@ class op_create_geometry : public voxel_operation {
384386 }
385387
386388 if (old_progress != iterator.progress ()) {
387- std::cerr << " \r parsing geometry " << iterator.progress ();
388389 old_progress = iterator.progress ();
390+ if (application_progress_callback) {
391+ (*application_progress_callback)(old_progress / 100 .f );
392+ }
389393 }
390394
391395 if (!iterator.next ()) {
392- std::cerr << std::endl;
393396 break ;
394397 }
395398 }
396399
397- }
400+ }
398401
399402 if (!at_least_one_succesful) {
400- throw std::runtime_error (" Failed to generate geometry" );
403+ json_logger::message (json_logger::LOG_FATAL, " Failed to generate geometry" );
404+ abort ();
401405 }
402406
403407 std::random_shuffle (geometries->begin (), geometries->end ());
@@ -415,7 +419,7 @@ namespace {
415419 return voxels;
416420 }
417421
418- abstract_voxel_storage* voxelize (geometry_collection_t * surfaces, double vsize, int chunksize, const boost::optional<int >& threads) {
422+ abstract_voxel_storage* voxelize (geometry_collection_t * surfaces, double vsize, int chunksize, const boost::optional<int >& threads, bool silent = false ) {
419423 double x1, y1, z1, x2, y2, z2;
420424 int nx, ny, nz;
421425
@@ -439,7 +443,7 @@ namespace {
439443 nz += PADDING * 2 ;
440444
441445 if (threads) {
442- progress_writer progress (" voxelize" );
446+ progress_writer progress (" voxelize" , silent );
443447 threaded_processor p (x1, y1, z1, vsize, nx, ny, nz, chunksize, *threads, progress);
444448 p.process (surfaces->begin (), surfaces->end (), SURFACE (), output (MERGED ()));
445449 return p.voxels ();
@@ -471,7 +475,7 @@ class op_voxelize : public voxel_operation {
471475 // Just some arbitrary empty region
472476 return (abstract_voxel_storage*) new chunked_voxel_storage<bit_t >(make_vec<long >(0 ,0 ,0 ), vsize, cs, make_vec<size_t >(1U ,1U ,1U ));
473477 } else {
474- return voxelize (surfaces, vsize, cs, t);
478+ return voxelize (surfaces, vsize, cs, t, silent );
475479 }
476480 }
477481};
@@ -493,7 +497,7 @@ class op_print_components : public voxel_operation {
493497};
494498
495499namespace {
496- void dump_info (abstract_voxel_storage* voxels) {
500+ json_logger::meta_data dump_info (abstract_voxel_storage* voxels) {
497501 if (dynamic_cast <abstract_chunked_voxel_storage*>(voxels)) {
498502 auto left = dynamic_cast <abstract_chunked_voxel_storage*>(voxels)->grid_offset ();
499503 auto nc = dynamic_cast <abstract_chunked_voxel_storage*>(voxels)->num_chunks ();
@@ -502,14 +506,15 @@ namespace {
502506 auto szl = (long )dynamic_cast <abstract_chunked_voxel_storage*>(voxels)->chunk_size ();
503507 auto left_world = ((voxels->bounds ()[0 ].as <long >() + left * szl).as <double >() * sz);
504508 auto right_world = ((voxels->bounds ()[1 ].as <long >() + left * szl).as <double >() * sz);
505- std::cerr << " voxels: "
506- << left. format () << " - " << right. format ()
507- << " ; count: " << voxels->count ()
508- << " ; bounds: " << voxels-> bounds ()[ 0 ] .format ()
509- << " - " << voxels->bounds ()[1 ].format () << std::endl
510- << " ; world: " << left_world .format ()
511- << " - " << right_world. format () << std::endl ;
509+
510+ return {
511+ { " count" , ( long ) voxels->count ()},
512+ { " grid " , left. format () + " - " + right .format ()},
513+ { " bounds " , voxels-> bounds ()[ 0 ]. format () + " - " + voxels->bounds ()[1 ].format ()},
514+ { " world " , left_world. format () + " - " + right_world .format ()},
515+ } ;
512516 }
517+ return {};
513518 }
514519
515520 template <typename Fn, typename Fn2>
@@ -811,6 +816,7 @@ class op_fill_gaps : public voxel_operation {
811816 abstract_voxel_storage* voxels = scope.get_value <abstract_voxel_storage*>(" input" );
812817 threaded_post_process<fill_gaps> tpp (scope.get_value <int >(" THREADS" ));
813818 tpp.set_progress_callback (application_progress_callback);
819+ tpp.silent = silent;
814820 return tpp ((regular_voxel_storage*) voxels);
815821 }
816822};
@@ -825,6 +831,7 @@ class op_offset : public voxel_operation {
825831 abstract_voxel_storage* voxels = scope.get_value <abstract_voxel_storage*>(" input" );
826832 threaded_post_process< offset<> > tpp (scope.get_value <int >(" THREADS" ));
827833 tpp.set_progress_callback (application_progress_callback);
834+ tpp.silent = silent;
828835 return tpp ((regular_voxel_storage*)voxels);
829836 }
830837};
@@ -853,7 +860,10 @@ class op_offset_xy : public voxel_operation {
853860#else
854861 auto current = (regular_voxel_storage*) voxels->copy ();
855862 while (d) {
856- auto ofs = threaded_post_process< offset<1 , 2 > >(scope.get_value <int >(" THREADS" ))(current);
863+ threaded_post_process< offset<1 , 2 > > tpp (scope.get_value <int >(" THREADS" ));
864+ // @todo progress not propagated as it's within a loop
865+ tpp.silent = silent;
866+ auto ofs = tpp (current);
857867 auto next = (regular_voxel_storage*) current->boolean_union (ofs);
858868 delete ofs;
859869 delete current;
@@ -877,6 +887,7 @@ class op_outmost : public voxel_operation {
877887 abstract_voxel_storage* voxels = scope.get_value <abstract_voxel_storage*>(" input" );
878888 threaded_post_process<keep_outmost> tpp (1 );
879889 tpp.set_progress_callback (application_progress_callback);
890+ tpp.silent = silent;
880891 return tpp ((regular_voxel_storage*)voxels);
881892 }
882893};
@@ -904,6 +915,7 @@ class op_volume : public voxel_operation {
904915 abstract_voxel_storage* voxels = scope.get_value <abstract_voxel_storage*>(" input" );
905916 threaded_post_process<traversal_voxel_filler_separate_components> tpp (1 );
906917 tpp.set_progress_callback (application_progress_callback);
918+ tpp.silent = silent;
907919 return tpp ((regular_voxel_storage*)voxels);
908920 }
909921};
@@ -921,6 +933,7 @@ class op_volume_2 : public voxel_operation {
921933 }
922934 threaded_post_process<traversal_voxel_filler_inverse> tpp (1 );
923935 tpp.set_progress_callback (application_progress_callback);
936+ tpp.silent = silent;
924937 return ((regular_voxel_storage*)voxels);
925938 }
926939};
@@ -935,6 +948,7 @@ class op_volume_inverted : public voxel_operation {
935948 abstract_voxel_storage* voxels = scope.get_value <abstract_voxel_storage*>(" input" );
936949 threaded_post_process<traversal_voxel_filler_inverted> tpp (1 );
937950 tpp.set_progress_callback (application_progress_callback);
951+ tpp.silent = silent;
938952 return tpp ((regular_voxel_storage*)voxels);
939953 }
940954};
@@ -1327,13 +1341,15 @@ class voxel_operation_runner {
13271341public:
13281342 const statement_type& statement_;
13291343 boost::optional<std::function<void (float )>> application_progress_callback;
1344+ bool silent = false ;
13301345
13311346 voxel_operation_runner (const statement_type& statement) :
13321347 statement_ (statement) {}
13331348
13341349 symbol_value run (const statement_type& st, scope_map& context) {
13351350 voxel_operation* op = voxel_operation_map::create (statement_.call ().name ());
13361351 op->application_progress_callback = application_progress_callback;
1352+ op->silent = silent;
13371353
13381354 bool has_keyword = false ;
13391355 std::map<std::string, function_arg_value_type> function_values;
0 commit comments