@@ -2932,7 +2932,7 @@ namespace {
2932
2932
class op_segment : public voxel_operation {
2933
2933
public:
2934
2934
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 " } };
2936
2936
return nm_;
2937
2937
}
2938
2938
symbol_value invoke (const scope_map& scope) const {
@@ -2953,6 +2953,19 @@ class op_segment : public voxel_operation {
2953
2953
2954
2954
uint32_t component_index = 0 ;
2955
2955
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
+
2956
2969
while (voxels_bit->count ()) {
2957
2970
++component_index;
2958
2971
@@ -2972,15 +2985,22 @@ class op_segment : public voxel_operation {
2972
2985
2973
2986
check_curvature_and_normal_deviation lookup_curv (voxels, *seed, angular_tolerance, max_curvature);
2974
2987
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));
2976
2992
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) {
2980
2994
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
+ }
2982
3002
2983
- voxels_bit->boolean_subtraction_inplace (vis .get_visited ());
3003
+ voxels_bit->boolean_subtraction_inplace (C == 6 ? vis6. get_visited () : vis26 .get_visited ());
2984
3004
}
2985
3005
2986
3006
return result;
0 commit comments