@@ -2932,7 +2932,7 @@ namespace {
29322932class op_segment : public voxel_operation {
29332933public:
29342934 const std::vector<argument_spec>& arg_names () const {
2935- static std::vector<argument_spec> nm_ = { { true , " input" , " voxels" }, { false , " angular_tolerance" , " real" }, { false , " max_curvature" , " real" } };
2935+ static std::vector<argument_spec> nm_ = { { true , " input" , " voxels" }, { false , " angular_tolerance" , " real" }, { false , " max_curvature" , " real" }, { false , " connectedness " , " integer " } };
29362936 return nm_;
29372937 }
29382938 symbol_value invoke (const scope_map& scope) const {
@@ -2953,6 +2953,19 @@ class op_segment : public voxel_operation {
29532953
29542954 uint32_t component_index = 0 ;
29552955
2956+ // @nb connectedness defaults to 26 here for backwards compat, most other commands
2957+ // have 6 as the default.
2958+ int C = 26 ;
2959+ try {
2960+ C = scope.get_value <int >(" connectedness" );
2961+ } catch (scope_map::not_in_scope&) {
2962+ // default 26 connectedness
2963+ }
2964+
2965+ if (C != 6 && C != 26 ) {
2966+ throw std::runtime_error (" Connectedness should be 6 or 26" );
2967+ }
2968+
29562969 while (voxels_bit->count ()) {
29572970 ++component_index;
29582971
@@ -2972,15 +2985,22 @@ class op_segment : public voxel_operation {
29722985
29732986 check_curvature_and_normal_deviation lookup_curv (voxels, *seed, angular_tolerance, max_curvature);
29742987
2975- visitor<26 , DOF_XYZ, std::function<bool (const vec_n<3 , size_t >&)>> vis;
2988+ visitor<6 , DOF_XYZ, std::function<bool (const vec_n<3 , size_t >&)>> vis6;
2989+ visitor<26 , DOF_XYZ, std::function<bool (const vec_n<3 , size_t >&)>> vis26;
2990+ vis6.set_postcondition (std::ref (lookup_curv));
2991+ vis26.set_postcondition (std::ref (lookup_curv));
29762992
2977- vis.set_postcondition (std::ref (lookup_curv));
2978-
2979- vis ([&result, &component_index](const tagged_index& pos) {
2993+ auto callback = [&result, &component_index](const tagged_index& pos) {
29802994 result->Set (pos.pos , &component_index);
2981- }, voxels_bit, *seed);
2995+ };
2996+
2997+ if (C == 6 ) {
2998+ vis6 (callback, voxels_bit, *seed);
2999+ } else {
3000+ vis26 (callback, voxels_bit, *seed);
3001+ }
29823002
2983- voxels_bit->boolean_subtraction_inplace (vis .get_visited ());
3003+ voxels_bit->boolean_subtraction_inplace (C == 6 ? vis6. get_visited () : vis26 .get_visited ());
29843004 }
29853005
29863006 return result;
0 commit comments