[Bf-blender-cvs] [db7c4d7a1cf] master: Cleanup: Use new enum for NURBS curve knots modes

Hans Goudey noreply at git.blender.org
Fri Mar 11 21:56:04 CET 2022


Commit: db7c4d7a1cf3a4aab7d40df9de5f3f3d33e88cb6
Author: Hans Goudey
Date:   Fri Mar 11 14:55:42 2022 -0600
Branches: master
https://developer.blender.org/rBdb7c4d7a1cf3a4aab7d40df9de5f3f3d33e88cb6

Cleanup: Use new enum for NURBS curve knots modes

Move the definition of the enum to `Curves` DNA, since the values
will be saved in files, and ongoing development needs to use this.

===================================================================

M	source/blender/blenkernel/BKE_spline.hh
M	source/blender/blenkernel/intern/curve_eval.cc
M	source/blender/blenkernel/intern/spline_nurbs.cc
M	source/blender/makesdna/DNA_curves_types.h
M	source/blender/nodes/geometry/nodes/legacy/node_geo_legacy_curve_spline_type.cc
M	source/blender/nodes/geometry/nodes/node_geo_curve_spline_type.cc

===================================================================

diff --git a/source/blender/blenkernel/BKE_spline.hh b/source/blender/blenkernel/BKE_spline.hh
index ed9b743b524..1e3134020c6 100644
--- a/source/blender/blenkernel/BKE_spline.hh
+++ b/source/blender/blenkernel/BKE_spline.hh
@@ -449,13 +449,6 @@ class BezierSpline final : public Spline {
  */
 class NURBSpline final : public Spline {
  public:
-  enum class KnotsMode {
-    Normal,
-    EndPoint,
-    Bezier,
-    EndPointBezier,
-  };
-
   /** Method used to recalculate the knots vector when points are added or removed. */
   KnotsMode knots_mode;
 
diff --git a/source/blender/blenkernel/intern/curve_eval.cc b/source/blender/blenkernel/intern/curve_eval.cc
index 59c2155255b..191a510947e 100644
--- a/source/blender/blenkernel/intern/curve_eval.cc
+++ b/source/blender/blenkernel/intern/curve_eval.cc
@@ -203,21 +203,21 @@ static Spline::NormalCalculationMode normal_mode_from_dna_curve(const int twist_
   return Spline::NormalCalculationMode::Minimum;
 }
 
-static NURBSpline::KnotsMode knots_mode_from_dna_nurb(const short flag)
+static KnotsMode knots_mode_from_dna_nurb(const short flag)
 {
   switch (flag & (CU_NURB_ENDPOINT | CU_NURB_BEZIER)) {
     case CU_NURB_ENDPOINT:
-      return NURBSpline::KnotsMode::EndPoint;
+      return NURBS_KNOT_MODE_ENDPOINT;
     case CU_NURB_BEZIER:
-      return NURBSpline::KnotsMode::Bezier;
+      return NURBS_KNOT_MODE_BEZIER;
     case CU_NURB_ENDPOINT | CU_NURB_BEZIER:
-      return NURBSpline::KnotsMode::EndPointBezier;
+      return NURBS_KNOT_MODE_ENDPOINT_BEZIER;
     default:
-      return NURBSpline::KnotsMode::Normal;
+      return NURBS_KNOT_MODE_NORMAL;
   }
 
   BLI_assert_unreachable();
-  return NURBSpline::KnotsMode::Normal;
+  return NURBS_KNOT_MODE_NORMAL;
 }
 
 static SplinePtr spline_from_dna_bezier(const Nurb &nurb)
@@ -421,8 +421,7 @@ std::unique_ptr<CurveEval> curves_to_curve_eval(const Curves &curves)
         nurb_spline->resize(point_range.size());
         nurb_spline->weights().copy_from(nurbs_weights.slice(point_range));
         nurb_spline->set_order(nurbs_orders[curve_index]);
-        nurb_spline->knots_mode = static_cast<NURBSpline::KnotsMode>(
-            nurbs_knots_modes[curve_index]);
+        nurb_spline->knots_mode = static_cast<KnotsMode>(nurbs_knots_modes[curve_index]);
 
         spline = std::move(nurb_spline);
         break;
diff --git a/source/blender/blenkernel/intern/spline_nurbs.cc b/source/blender/blenkernel/intern/spline_nurbs.cc
index 2146a4309ab..7dc5ac3ea12 100644
--- a/source/blender/blenkernel/intern/spline_nurbs.cc
+++ b/source/blender/blenkernel/intern/spline_nurbs.cc
@@ -142,8 +142,8 @@ bool NURBSpline::check_valid_size_and_order() const
     return false;
   }
 
-  if (ELEM(this->knots_mode, KnotsMode::Bezier, KnotsMode::EndPointBezier)) {
-    if (this->knots_mode == KnotsMode::Bezier && this->size() <= order_) {
+  if (ELEM(this->knots_mode, NURBS_KNOT_MODE_BEZIER, NURBS_KNOT_MODE_ENDPOINT_BEZIER)) {
+    if (this->knots_mode == NURBS_KNOT_MODE_BEZIER && this->size() <= order_) {
       return false;
     }
     return (!is_cyclic_ || this->size() % (order_ - 1) == 0);
@@ -162,10 +162,8 @@ void NURBSpline::calculate_knots() const
 {
   const KnotsMode mode = this->knots_mode;
   const int order = order_;
-  const bool is_bezier = ELEM(
-      mode, NURBSpline::KnotsMode::Bezier, NURBSpline::KnotsMode::EndPointBezier);
-  const bool is_end_point = ELEM(
-      mode, NURBSpline::KnotsMode::EndPoint, NURBSpline::KnotsMode::EndPointBezier);
+  const bool is_bezier = ELEM(mode, NURBS_KNOT_MODE_BEZIER, NURBS_KNOT_MODE_ENDPOINT_BEZIER);
+  const bool is_end_point = ELEM(mode, NURBS_KNOT_MODE_ENDPOINT, NURBS_KNOT_MODE_ENDPOINT_BEZIER);
   /* Inner knots are always repeated once except on Bezier case. */
   const int repeat_inner = is_bezier ? order - 1 : 1;
   /* How many times to repeat 0.0 at the beginning of knot. */
diff --git a/source/blender/makesdna/DNA_curves_types.h b/source/blender/makesdna/DNA_curves_types.h
index d3e69315265..f1626781fc6 100644
--- a/source/blender/makesdna/DNA_curves_types.h
+++ b/source/blender/makesdna/DNA_curves_types.h
@@ -40,6 +40,14 @@ typedef enum HandleType {
   BEZIER_HANDLE_ALIGN = 3,
 } HandleType;
 
+/** Method used to calculate a NURBS curve's knot vector. */
+typedef enum KnotsMode {
+  NURBS_KNOT_MODE_NORMAL = 0,
+  NURBS_KNOT_MODE_ENDPOINT = 1,
+  NURBS_KNOT_MODE_BEZIER = 2,
+  NURBS_KNOT_MODE_ENDPOINT_BEZIER = 3,
+} KnotsMode;
+
 /**
  * A reusable data structure for geometry consisting of many curves. All control point data is
  * stored contiguously for better efficiency. Data for each curve is stored as a slice of the
diff --git a/source/blender/nodes/geometry/nodes/legacy/node_geo_legacy_curve_spline_type.cc b/source/blender/nodes/geometry/nodes/legacy/node_geo_legacy_curve_spline_type.cc
index 4e3b0839da7..002c42c4c82 100644
--- a/source/blender/nodes/geometry/nodes/legacy/node_geo_legacy_curve_spline_type.cc
+++ b/source/blender/nodes/geometry/nodes/legacy/node_geo_legacy_curve_spline_type.cc
@@ -100,7 +100,7 @@ static SplinePtr poly_to_nurbs(const Spline &input)
   output->set_resolution(12);
   output->set_order(4);
   Spline::copy_base_settings(input, *output);
-  output->knots_mode = NURBSpline::KnotsMode::Bezier;
+  output->knots_mode = NURBS_KNOT_MODE_BEZIER;
   output->attributes = input.attributes;
   return output;
 }
@@ -128,7 +128,7 @@ static SplinePtr bezier_to_nurbs(const Spline &input)
   output->set_resolution(12);
   output->set_order(4);
   output->set_cyclic(input.is_cyclic());
-  output->knots_mode = NURBSpline::KnotsMode::Bezier;
+  output->knots_mode = NURBS_KNOT_MODE_BEZIER;
   output->attributes.reallocate(output->size());
   copy_attributes(input, *output, [](GSpan src, GMutableSpan dst) {
     attribute_math::convert_to_static_type(src.type(), [&](auto dummy) {
diff --git a/source/blender/nodes/geometry/nodes/node_geo_curve_spline_type.cc b/source/blender/nodes/geometry/nodes/node_geo_curve_spline_type.cc
index 1b4429cc527..4118448b237 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_curve_spline_type.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_curve_spline_type.cc
@@ -58,22 +58,22 @@ static void scale_output_assign(const Span<T> input,
 template<class T>
 static void nurbs_to_bezier_assign(const Span<T> input,
                                    const MutableSpan<T> r_output,
-                                   const NURBSpline::KnotsMode knotsMode)
+                                   const KnotsMode knotsMode)
 {
   const int input_size = input.size();
   const int output_size = r_output.size();
 
   switch (knotsMode) {
-    case NURBSpline::KnotsMode::Bezier:
+    case NURBS_KNOT_MODE_BEZIER:
       scale_input_assign<T>(input, 3, 1, r_output);
       break;
-    case NURBSpline::KnotsMode::Normal:
+    case NURBS_KNOT_MODE_NORMAL:
       for (const int i : IndexRange(output_size)) {
         r_output[i] = input[(i + 1) % input_size];
       }
       break;
-    case NURBSpline::KnotsMode::EndPointBezier:
-    case NURBSpline::KnotsMode::EndPoint:
+    case NURBS_KNOT_MODE_ENDPOINT_BEZIER:
+    case NURBS_KNOT_MODE_ENDPOINT:
       for (const int i : IndexRange(1, output_size - 2)) {
         r_output[i] = input[i + 1];
       }
@@ -108,11 +108,11 @@ static void copy_attributes(const Spline &input_spline, Spline &output_spline, C
 }
 
 static Vector<float3> create_nurbs_to_bezier_handles(const Span<float3> nurbs_positions,
-                                                     const NURBSpline::KnotsMode knots_mode)
+                                                     const KnotsMode knots_mode)
 {
   const int nurbs_positions_size = nurbs_positions.size();
   Vector<float3> handle_positions;
-  if (knots_mode == NURBSpline::KnotsMode::Bezier) {
+  if (knots_mode == NURBS_KNOT_MODE_BEZIER) {
     for (const int i : IndexRange(nurbs_positions_size)) {
       if (i % 3 == 1) {
         continue;
@@ -128,7 +128,7 @@ static Vector<float3> create_nurbs_to_bezier_handles(const Span<float3> nurbs_po
     }
   }
   else {
-    const bool is_periodic = knots_mode == NURBSpline::KnotsMode::Normal;
+    const bool is_periodic = knots_mode == NURBS_KNOT_MODE_NORMAL;
     if (is_periodic) {
       handle_positions.append(nurbs_positions[1] +
                               ((nurbs_positions[0] - nurbs_positions[1]) / 3));
@@ -170,9 +170,9 @@ static Vector<float3> create_nurbs_to_bezier_handles(const Span<float3> nurbs_po
 
 static Array<float3> create_nurbs_to_bezier_positions(const Span<float3> nurbs_positions,
                                                       const Span<float3> handle_positions,
-                                                      const NURBSpline::KnotsMode knots_mode)
+                                                      const KnotsMode knots_mode)
 {
-  if (knots_mode == NURBSpline::KnotsMode::Bezier) {
+  if (knots_mode == NURBS_KNOT_MODE_BEZIER) {
     /* Every third NURBS position (starting from index 1) should be converted to Bezier position */
     const int scale = 3;
     const int offset = 1;
@@ -212,7 +212,7 @@ static SplinePtr poly_to_nurbs(const Spline &input)
   output->set_resolution(12);
   output->set_order(4);
   Spline::copy_base_settings(input, *output);
-  output->knots_mode = NURBSpline::KnotsMode::Bezier;
+  output->knots_mode = NURBS_KNOT_MODE_BEZIER;
   output->attributes = input.attributes;
   return output;
 }
@@ -240,7 +240,7 @@ static SplinePtr bezier_to_nurbs(const Spline &input)
   output->set_resolution(12);
   output->set_order(4);
   output->set_cyclic(input.is_cyclic());
-  output->knots_mode = NURBSpline::KnotsMode::Bezier;
+  output->knots_mode = NURBS_KNOT_MODE_BEZIER;
   output->attributes.reallocate(output->size());
   copy_attributes(input, *output, [](GSpan src, GMutableSpan dst) {
     attribute_math::convert_to_static_type(src.type(), [&](auto dummy) {
@@ -273,13 +273,13 @@ static SplinePtr nurbs_to_bezier(const Spline &input)
   const NURBSpline &nurbs_spline = static_cast<const NURBSpline &>(input);
   Span<float3> nurbs_positions;
   Vector<float3> nurbs_positions_vector;
-  NURBSpline::KnotsMode knots_mode;
+  KnotsMode knots_mode;
   if (nurbs_spline.is_cyclic()) {
     nurbs_positions_vector 

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list