[Bf-blender-cvs] [733a764b079] temp-sculpt-roll-mapping: temp-sculpt-roll-mapping: Implement symmetry/tile/radial modes

Joseph Eagar noreply at git.blender.org
Sun Nov 20 09:59:23 CET 2022


Commit: 733a764b079fa9c97e02b3d741467fb530bc8da7
Author: Joseph Eagar
Date:   Sun Nov 20 00:58:27 2022 -0800
Branches: temp-sculpt-roll-mapping
https://developer.blender.org/rB733a764b079fa9c97e02b3d741467fb530bc8da7

temp-sculpt-roll-mapping: Implement symmetry/tile/radial modes

* Note that tile + radial does not work
* Also cleaned up the code a bit.

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

M	source/blender/blenlib/BLI_even_spline.hh
M	source/blender/editors/sculpt_paint/paint_stroke.cc
M	source/blender/editors/sculpt_paint/sculpt.cc
M	source/blender/editors/sculpt_paint/sculpt_intern.h

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

diff --git a/source/blender/blenlib/BLI_even_spline.hh b/source/blender/blenlib/BLI_even_spline.hh
index 95a16a6edba..4b98d51db37 100644
--- a/source/blender/blenlib/BLI_even_spline.hh
+++ b/source/blender/blenlib/BLI_even_spline.hh
@@ -53,455 +53,6 @@ namespace blender {
 
 */
 
-/*
-Quadratic curves. Not sure we need this.
-*/
-
-template<typename Float, int axes = 2, int table_size = 512> class QuadBezier {
-  using Vector = vec_base<Float, axes>;
-
- public:
-  Vector ps[3];
-
-  static const int TableSize = table_size;
-
-  QuadBezier(Vector a, Vector b, Vector c)
-  {
-    ps[0] = a;
-    ps[1] = b;
-    ps[2] = c;
-
-    deleted = false;
-    _arc_to_t = new Float[table_size];
-    _t_to_arc = new Float[table_size];
-  }
-
-  ~QuadBezier()
-  {
-    deleted = true;
-
-    if (_arc_to_t) {
-      delete[] _arc_to_t;
-      _arc_to_t = nullptr;
-    }
-
-    if (_t_to_arc) {
-      delete[] _t_to_arc;
-      _t_to_arc = nullptr;
-    }
-  }
-
-  QuadBezier()
-  {
-    deleted = false;
-    _arc_to_t = new Float[table_size];
-    _t_to_arc = new Float[table_size];
-  }
-
-  QuadBezier(const QuadBezier &b)
-  {
-    _arc_to_t = new Float[table_size];
-    _t_to_arc = new Float[table_size];
-
-    *this = b;
-    deleted = false;
-  }
-
-  QuadBezier &operator=(const QuadBezier &b)
-  {
-    ps[0] = b.ps[0];
-    ps[1] = b.ps[1];
-    ps[2] = b.ps[2];
-
-    length = b.length;
-
-    if (!_arc_to_t) {
-      _arc_to_t = new Float[table_size];
-    }
-    if (!_arc_to_t) {
-      _t_to_arc = new Float[table_size];
-    }
-
-    if (b._arc_to_t) {
-      for (int i = 0; i < table_size; i++) {
-        _arc_to_t[i] = b._arc_to_t[i];
-      }
-    }
-
-    if (b._t_to_arc) {
-      for (int i = 0; i < table_size; i++) {
-        _t_to_arc[i] = b._t_to_arc[i];
-      }
-    }
-
-    return *this;
-  }
-
-#if 1
-  QuadBezier(QuadBezier &&b)
-  {
-    *this = b;
-  }
-
-  QuadBezier &operator=(QuadBezier &&b)
-  {
-    ps[0] = b.ps[0];
-    ps[1] = b.ps[1];
-    ps[2] = b.ps[2];
-
-    length = b.length;
-
-    if (b._arc_to_t) {
-      _arc_to_t = std::move(b._arc_to_t);
-      _t_to_arc = std::move(b._t_to_arc);
-
-      b._arc_to_t = nullptr;
-      b._t_to_arc = nullptr;
-    }
-    else {
-      _arc_to_t = new Float[table_size];
-      _t_to_arc = new Float[table_size];
-    }
-
-    return *this;
-  }
-#endif
-
-  Float length;
-
-  void update()
-  {
-    Float t = 0.0, dt = 1.0 / (Float)table_size;
-    Float s = 0.0;
-
-    if (!_arc_to_t) {
-      _arc_to_t = new Float[table_size];
-      _t_to_arc = new Float[table_size];
-    }
-
-    for (int i : IndexRange(table_size)) {
-      _arc_to_t[i] = -1.0;
-    }
-
-    length = 0.0;
-
-    for (int i = 0; i < table_size; i++, t += dt) {
-      Float dlen = 0.0;
-      for (int j = 0; j < axes; j++) {
-        float dv = dquad(ps[0][j], ps[1][j], ps[2][j], t);
-
-        dlen += dv * dv;
-      }
-
-      dlen = sqrt(dlen) * dt;
-
-      length += dlen;
-    }
-
-    t = 0.0;
-    s = 0.0;
-
-    for (int i = 0; i < table_size; i++, t += dt) {
-      Float dlen = 0.0;
-      for (int j = 0; j < axes; j++) {
-        float dv = dquad(ps[0][j], ps[1][j], ps[2][j], t);
-
-        dlen += dv * dv;
-      }
-
-      dlen = sqrt(dlen) * dt;
-
-      int j = (int)((s / length) * (Float)table_size * 0.999999);
-      j = min_ii(j, table_size - 1);
-
-      _t_to_arc[i] = s;
-      _arc_to_t[j] = t;
-
-      s += dlen;
-    }
-
-    _arc_to_t[0] = 0.0;
-    _arc_to_t[table_size - 1] = 1.0;
-
-#if 1
-    /* Interpolate gaps in table. */
-    for (int i = 0; i < table_size - 1; i++) {
-      if (_arc_to_t[i] == -1.0 || _arc_to_t[i + 1] != -1.0) {
-        continue;
-      }
-
-      int i1 = i;
-      int i2 = i + 1;
-
-      while (i2 < table_size - 1 && _arc_to_t[i2] == -1.0) {
-        i2++;
-      }
-
-      Float start = _arc_to_t[i1];
-      Float end = _arc_to_t[i2];
-      Float dt2 = 1.0 / (i2 - i1);
-
-      for (int j = i1 + 1; j < i2; j++) {
-        Float factor = (Float)(j - i1) * dt2;
-        _arc_to_t[j] = start + (end - start) * factor;
-      }
-
-      i = i2 - 1;
-    }
-
-#  if 0
-    for (int i = 0; i < table_size; i++) {
-      printf("%.3f ", _arc_to_t[i]);
-      if (_arc_to_t[i] == -1.0) {
-        printf("BLI_even_spline.hh: error!\n");
-      }
-    }
-
-    printf("\n\n");
-#  endif
-#endif
-  }
-
-  inline Vector evaluate(Float s)
-  {
-    Float t = arc_to_t(s);
-    Vector r;
-
-    for (int i = 0; i < axes; i++) {
-      r[i] = quad(ps[0][i], ps[1][i], ps[2][i], t);
-    }
-
-    return r;
-  }
-
-  Vector derivative(Float s, bool exact = true)
-  {
-    Float t = arc_to_t(s);
-    Vector r;
-
-    for (int i = 0; i < axes; i++) {
-      r[i] = dquad(ps[0][i], ps[1][i], ps[2][i], t) * length;
-    }
-
-    /* Real arc length parameterized tangent has unit length. */
-    if (exact) {
-      Float len = sqrt(_dot(r, r));
-
-      if (len > 0.00001) {
-        r = r / len;
-      }
-    }
-
-    return r;
-  }
-
-  Vector derivative2(Float s)
-  {
-#ifdef FINITE_DIFF
-    const Float df = 0.0005;
-    Float s1, s2;
-
-    if (s >= 1.0 - df) {
-      s1 = s - df;
-      s2 = s;
-    }
-    else {
-      s1 = s;
-      s2 = s + df;
-    }
-
-    Vector a = derivative(s1);
-    Vector b = derivative(s2);
-
-    return (b - a) / df;
-#else
-    Float t = arc_to_t(s);
-    Vector r;
-
-    Float dx = dquad(ps[0][0], ps[1][0], ps[2][0], t);
-    Float d2x = d2quad(ps[0][0], ps[1][0], ps[2][0], t);
-    Float dy = dquad(ps[0][1], ps[1][1], ps[2][1], t);
-    Float d2y = d2quad(ps[0][1], ps[1][1], ps[2][1], t);
-
-    /*
-    comment: arc length second derivative;
-
-    operator x, y, z, dx, dy, dz, d2x, d2y, d2z;
-    forall t let df(x(t), t) = dx(t);
-    forall t let df(y(t), t) = dy(t);
-    forall t let df(z(t), t) = dz(t);
-    forall t let df(dx(t), t) = d2x(t);
-    forall t let df(dy(t), t) = d2y(t);
-    forall t let df(dz(t), t) = d2z(t);
-
-    comment: arc length first derivative is just the normalized tangent;
-
-    comment: 2d case;
-
-    dlen := sqrt(df(x(t), t)**2 + df(y(t), t)**2);
-
-    df(df(x(t), t) / dlen, t);
-    df(df(y(t), t) / dlen, t);
-
-    comment: 3d case;
-
-    dlen := sqrt(df(x(t), t)**2 + df(y(t), t)**2 + df(z(t), t)**2);
-
-    comment: final derivatives;
-
-    df(df(x(t), t) / dlen, t);
-    df(df(y(t), t) / dlen, t);
-    df(df(z(t), t) / dlen, t);
-    */
-    if constexpr (axes == 2) {
-      /* Basically the 2d perpidicular normalized tangent multiplied by the curvature. */
-
-      Float div = sqrt(dx * dx + dy * dy) * (dx * dx + dy * dy);
-
-      r[0] = ((d2x * dy - d2y * dx) * dy) / div;
-      r[1] = (-(d2x * dy - d2y * dx) * dx) / div;
-    }
-    else if constexpr (axes == 3) {
-      Float dz = dquad(ps[0][2], ps[1][2], ps[2][2], t);
-      Float d2z = d2quad(ps[0][2], ps[1][2], ps[2][2], t);
-
-      Float div = sqrt(dx * dx + dy * dy + dz * dz) * (dy * dy + dz * dz + dx * dx);
-
-      r[0] = (d2x * dy * dy + d2x * dz * dz - d2y * dx * dy - d2z * dx * dz) / div;
-      r[1] = (-(d2x * dx * dy - d2y * dx * dx - d2y * dz * dz + d2z * dy * dz)) / div;
-      r[2] = (-(d2x * dx * dz + d2y * dy * dz - d2z * dx * dx - d2z * dy * dy)) / div;
-    }
-    else {
-      for (int i = 0; i < axes; i++) {
-        r[i] = d2quad(ps[0][i], ps[1][i], ps[2][i], t) * length;
-      }
-    }
-
-    return r;
-#endif
-  }
-
-  Float curvature(Float s)
-  {
-    Vector dv2 = derivative2(s);
-
-    if constexpr (axes == 2) {
-      Vector dv = derivative(s, true);
-
-      /* Calculate signed curvature. Remember that dv is normalized. */
-      return dv[0] * dv2[1] - dv[1] * dv2[0];
-    }
-
-    return sqrt(_dot(dv2, dv2));
-  }
-
-  Float dcurvature(Float s)
-  {
-    const Float ds = 0.0001;
-    Float s1, s2;
-
-    if (s > 1.0 - ds) {
-      s1 = s - ds;
-      s2 = s;
-    }
-    else {
-      s1 = s;
-      s2 = s + ds;
-    }
-
-    Float a = curvature(s1);
-    Float b = curvature(s2);
-
-    return (b - a) / ds;
-  }
-
- private:
-  Float *_arc_to_t;
-  Float *_t_to_arc;
-  bool deleted = false;
-
-  Float quad(Float k1, Float k2, Float k3, Float t)
-  {
-    return -((k1 - k2 + (k2 - k3) * t - (k1 - k2) * t) * t + (k1 - k2) * t - k1);
-  }
-
-  Float dquad(Float k1, Float k2, Float k3, Float t)
-  {
-    return -((k1 - k2 + (k2 - k3) * t - (k1 - k2) * t) * t + (k1 - k2) * t - k1);
-  }
-
-  Float d2quad(Float k1, Float k2, Float k3, Float t)
-  {
-    return -2 * (2 * k2 - k3 - k1);
-  }
-
-  Float _dot(Vector a, Vector b)
-  {
-    Float sum = 0.0;
-
-    for (int i = 0; i < axes; i++) {
-      sum += a[i] * b[i];
-    }
-
-    return sum;
-  }
-
-  Float clamp_s(Float s)
-  {
-    s = s < 0.0 ? 0.0 : s;
-    s = s >= length ? length * 0.999999 : s;
-
-    return s;
-  }
-
-  Float arc_to_t(Float s)
-  {
-    if (length == 0.0) {
-      return 0.0;
-    }
-
-    s = clamp_s(s);
-
-    Float t = s * (Float)(table_size - 1) / length;
-
-    int i1 = floorf(t);
-
-    i1 = max_ii(i1, 0);
-
-    int i2 = min_ii(i1 + 1, table_size - 1);
-
-    t -= (Float)i1;
-
-    Float s1 = _arc_to_t[i1];
-    Float s2 = _arc_to_t[i2];
-
-    return s1 + (s2 - s1) * t;
-  }
-
-  Float t_to_arc(Float s)
-  {
-    // return s * length; //XXX
-
-    if (length == 0.0) {
-      return 0.0;
-    }
-
-    s = clamp_s(s);
-
-    Float t = s * (Float)(table_size - 1) / length;
-
-    int i1 = floorf(t);
-    int i2 = min_ii(i1 + 1, table_size - 1);
-
-    t -= (Float)i1;
-
-    Float s1 = _t_to_arc[i1];
-    Float s2 = _t_to_arc[i2];
-
-    return s1 + (s2 - s1) * t;
-  }
-};
-
 /** Cubic curves */
 
 /*
@@ -515,40 +66,13 @@ procedure bez(a, b);
 
 lin := bez(k1, k2);
 quad := bez(lin, sub(k2=k3, k1=k2, lin));
-
 cubic := bez(quad, sub(k3=k4, k2=k3, k1=k2, quad));
-dcubic := df(cubic, t);
-icubic := int(cubic, t);
-
-x1 := 0;
-y1 := 0;
-
-dx := sub(k1=x1, k2=x2, k3=x3, k4=x4, dcubic);
-dy := sub(k1=y1, k2=y2, k3=y3, k4=y4, dcubic);
-darc := sqrt(dx**2 + dy**2);
-
-arcstep := darc*dt + 0.5*df(darc, t)*dt*dt;
 
-d2x := df(dx / darc, t);
-d2y := df(dy / darc, t);
-
-gentran
-begin
-declare <<
-x1,x2,x3,x4 : float;
-y1,y2,y3,y4 : float;
-dt,t : float;
->>;
-return eval(arcstep)
-end;
+dcubic := df(cubic, t);
 
 on fort;
 cubic;
 dcubic;
-icubic;
-arcstep;
-d2x;
-

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list