[Bf-blender-cvs] [59164b91516] soc-2019-bevel-profiles: Reverted CurveMapping code to master. Replaced by ProfileWidget code, so my changes to it are not necessary.

Hans Goudey noreply at git.blender.org
Sat Jun 22 01:26:21 CEST 2019


Commit: 59164b91516463259a6c3c5d26f9bd7157295e7c
Author: Hans Goudey
Date:   Fri Jun 21 19:25:57 2019 -0400
Branches: soc-2019-bevel-profiles
https://developer.blender.org/rB59164b91516463259a6c3c5d26f9bd7157295e7c

Reverted CurveMapping code to master. Replaced by ProfileWidget code, so my
changes to it are not necessary.

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

M	source/blender/blenkernel/BKE_colortools.h
M	source/blender/blenkernel/intern/colortools.c
M	source/blender/blenkernel/intern/profile_path.c
M	source/blender/editors/interface/interface_handlers.c
M	source/blender/makesdna/DNA_color_types.h

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

diff --git a/source/blender/blenkernel/BKE_colortools.h b/source/blender/blenkernel/BKE_colortools.h
index a0816244661..a6eb12c3708 100644
--- a/source/blender/blenkernel/BKE_colortools.h
+++ b/source/blender/blenkernel/BKE_colortools.h
@@ -46,27 +46,6 @@ void curvemapping_set_black_white(struct CurveMapping *cumap,
                                   const float black[3],
                                   const float white[3]);
 
-/* Used for a path where the curve isn't necessarily a function. */
-
-/* Initialized with the number of segments to fill the table with */
-void curvemapping_path_initialize(
-    struct CurveMapping *cumap,
-    int nsegments);  // HANS-TODO: Hmm, this assumes there is only one curve
-/* Evaluates along the length of the path rather than with X coord */
-void curvemapping_path_evaluate(const struct CurveMapping *cumap,
-                                int segment,
-                                float *x_out,
-                                float *y_out);
-/* Length portion is the fraction of the total path length where we want the location */
-void curvemap_path_evaluate(const struct CurveMap *cuma,
-                            float length_portion,
-                            float *x_out,
-                            float *y_out);
-/* Need to find the total length of the curve to sample a portion of it */
-float curvemap_path_total_length(const struct CurveMap *cuma);
-/* Distance in 2D to the next point */
-float curvemap_path_linear_distance_to_next_point(const struct CurveMap *cuma, int i);
-
 enum {
   CURVEMAP_SLOPE_NEGATIVE = 0,
   CURVEMAP_SLOPE_POSITIVE = 1,
diff --git a/source/blender/blenkernel/intern/colortools.c b/source/blender/blenkernel/intern/colortools.c
index be50f0a500b..45cb5e817d2 100644
--- a/source/blender/blenkernel/intern/colortools.c
+++ b/source/blender/blenkernel/intern/colortools.c
@@ -904,7 +904,7 @@ void curvemapping_changed(CurveMapping *cumap, const bool rem_doubles)
     }
   }
 
-//   qsort(cmp, cuma->totpoint, sizeof(CurveMapPoint), sort_curvepoints);
+  qsort(cmp, cuma->totpoint, sizeof(CurveMapPoint), sort_curvepoints);
 
   /* remove doubles, threshold set on 1% of default range */
   if (rem_doubles && cuma->totpoint > 2) {
@@ -1211,178 +1211,6 @@ void curvemapping_table_RGBA(const CurveMapping *cumap, float **array, int *size
   }
 }
 
-#define DEBUG_CUMAP 0
-
-/* *********** Curvemapping for paths /non-functions (Bevel) *************/
-
-/* HANS-TODO: Maybe this should check index out of bound */
-/* HANS-TODO: This falls back to linear interpolation for all points for now */
-/* This might be a little less efficient because it has to get fetch x and y */
-/*   rather than carrying them over from the last point while travelling */
-float curvemap_path_linear_distance_to_next_point(const struct CurveMap *cuma, int i)
-{
-  float x = cuma->curve[i].x;
-  float y = cuma->curve[i].y;
-  float x_next = cuma->curve[i + 1].x;
-  float y_next = cuma->curve[i + 1].y;
-
-  return sqrtf(powf(y_next - y, 2) + powf(x_next - x, 2));
-}
-
-/* Calculate the total length of the path (between all of the nodes and the ends at 0 and 1 */
-float curvemap_path_total_length(const struct CurveMap *cuma)
-{
-  float total_length = 0;
-  /*printf("Here are the locations of all of %d points in the list:\n", cuma->totpoint);
-  for (int i = 0; i < cuma->totpoint; i++) {
-    printf("(%f, %f)\n", cuma->curve[i].x, cuma->curve[i].y);
-  }*/
-
-  for (int i = 0; i < cuma->totpoint - 1; i++) {
-    total_length += curvemap_path_linear_distance_to_next_point(cuma, i);
-  }
-
-  return total_length;
-}
-
-static inline float lerp(float a, float b, float f)
-{
-  return a + (b - a) * f;
-}
-
-/* CurveMap should have already been initialized */
-void curvemap_path_evaluate(const struct CurveMap *cuma,
-                            float length_portion,
-                            float *x_out,
-                            float *y_out)
-{
-  /* HANS-TODO: For now I'm skipping the table and doing the evaluation here, */
-  /*   but it should be moved later on so I don't have to travel down node list every call */
-  float total_length = cuma->total_length;
-  float requested_length = length_portion * total_length;
-
-  /* Find the last point along the path with a lower length portion than the input */
-  int i = 0;
-  float length_travelled = 0.0f;
-  while (length_travelled < requested_length) {
-    /* Check if we reached the last point before the final one */
-    if (i == cuma->totpoint - 2) {
-      break;
-    }
-    float new_length = curvemap_path_linear_distance_to_next_point(cuma, i);
-    if (length_travelled + new_length >= requested_length) {
-      break;
-    }
-    length_travelled += new_length;
-    i++;
-  }
-
-  /* Now travel the rest of the length portion down the path to the next point and find the
-   * location there */
-  float distance_to_next_point = curvemap_path_linear_distance_to_next_point(cuma, i);
-  float lerp_factor = (requested_length - length_travelled) / distance_to_next_point;
-
-#if DEBUG_CUMAP
-  printf("  length portion input: %f\n", length_portion);
-  printf("  requested path length: %f\n", requested_length);
-  printf("  distance to next point: %f\n", distance_to_next_point);
-  printf("  length travelled: %f\n", length_travelled);
-  printf("  lerp-factor: %f\n", lerp_factor);
-  printf("  ith point  (%f, %f)\n", cuma->curve[i].x, cuma->curve[i].y);
-  printf("  next point (%f, %f)\n", cuma->curve[i + 1].x, cuma->curve[i + 1].y);
-#endif
-
-  *x_out = lerp(cuma->curve[i].x, cuma->curve[i + 1].x, lerp_factor);
-  *y_out = lerp(cuma->curve[i].y, cuma->curve[i + 1].y, lerp_factor);
-}
-
-/* HANS-TODO: Test this! (And start using it) */
-static void curvemap_path_make_table(struct CurveMap *cuma)
-{
-  /* Fill table with values for the position of the graph at each of the segments */
-  //  const float segment_length = cuma->total_length / cuma->nsegments;
-  //  float length_travelled = 0.0f;
-  //  float distance_to_next_point = curvemap_path_linear_distance_to_next_point(cuma, 0);
-  //  float distance_to_previous_point = 0.0f;
-  //  float travelled_since_last_point = 0.0f;
-  //  float segment_left = segment_length;
-  //  float f;
-  //  int i_point = 0;
-
-  //  cuma->x_segment_vals = MEM_callocN((size_t)cuma->nsegments * sizeof(float), "segment table
-  //  x"); cuma->y_segment_vals = MEM_callocN((size_t)cuma->nsegments * sizeof(float), "segment
-  //  table y"); /* HANS-TODO: Free these!! Where?? */
-
-  //  /* Travel along the path, recording locations of segments as we pass where they should be */
-  //  for (int i = 0; i < cuma->nsegments; i++) {
-  //    /* Travel over all of the points that could be inside this segment */
-  //    while (distance_to_next_point > segment_length * (i + 1) - length_travelled) {
-  //      length_travelled += distance_to_next_point;
-  //      segment_left -= distance_to_next_point;
-  //      travelled_since_last_point += distance_to_next_point;
-  //      i_point++;
-  //      distance_to_next_point = curvemap_path_linear_distance_to_next_point(cuma, i_point);
-  //      distance_to_previous_point = 0.0f;
-  //    }
-  //    /* We're now at the last point that fits inside the current segment */
-
-  //    f = segment_left / (distance_to_previous_point + distance_to_next_point);
-  //    cuma->x_segment_vals[i] = lerp(cuma->curve[i_point].x, cuma->curve[i_point+1].x, f);
-  //    cuma->y_segment_vals[i] = lerp(cuma->curve[i_point].x, cuma->curve[i_point+1].x, f);
-  //    distance_to_next_point -= segment_left;
-  //    distance_to_previous_point += segment_left;
-
-  //    length_travelled += segment_left;
-  //  }
-}
-
-/* Used for a path where the curve isn't necessarily a function. */
-/* Initialized with the number of segments to fill the table with */
-void curvemapping_path_initialize(struct CurveMapping *cumap, int nsegments)
-{
-  CurveMap *cuma = cumap->cm;
-
-  cuma->nsegments = nsegments;
-  float total_length = curvemap_path_total_length(cumap->cm);
-  cuma->total_length = total_length;
-
-#if DEBUG_CUMAP
-  printf("Total length of the curve is: %f\n", (double)total_length);
-#endif
-
-  /* Fill a table with the position at nssegments steps along the total length of the path */
-  curvemap_path_make_table(cumap->cm);
-}
-
-/* Evaluates along the length of the path rather than with X coord */
-/* Must initialize the table with the right amount of segments first! */
-void curvemapping_path_evaluate(const struct CurveMapping *cumap,
-                                int segment,
-                                float *x_out,
-                                float *y_out)
-{
-  /* Return the location in the table of the input segment */
-
-  const CurveMap *cuma = cumap->cm;
-  curvemap_path_evaluate(cuma, ((float)segment / (float)cuma->nsegments), x_out, y_out);
-
-  /* Clip down to 0 to 1 range for both coords */
-  if (cumap->flag & CUMA_DO_CLIP) {
-    if (*x_out < cumap->curr.xmin) {
-      *x_out = cumap->curr.xmin;
-    }
-    else if (*x_out > cumap->curr.xmax) {
-      *x_out = cumap->curr.xmax;
-    }
-    if (*y_out < cumap->curr.ymin) {
-      *y_out = cumap->curr.ymin;
-    }
-    else if (*y_out > cumap->curr.ymax) {
-      *y_out = cumap->curr.ymax;
-    }
-  }
-}
-
 /* ***************** Histogram **************** */
 
 #define INV_255 (1.f / 255.f)
diff --git a/source/blender/blenkernel/intern/profile_path.c b/source/blender/blenkernel/intern/profile_path.c
index 3038c812850..364545bfc41 100644
--- a/source/blender/blenkernel/intern/profile_path.c
+++ b/source/blender/blenkernel/intern/profile_path.c
@@ -235,10 +235,19 @@ ProfilePoint *profilepath_insert(ProfilePath *prpath, float x, float y)
   printf("(begin total points = %d)", prpath->total_points);
 #endif
 
-  /* HANS-TODO: New insertion algorithm? */
+  /* HANS-TODO: New insertion algorithm. Find closest points in 2D and then insert them in the
+   * middle of those. Maybe just lengthen the size of the array instead of allocating a new one
+   * too, but that probbaly doesn't matter so much.
+   *
+   * New algorithm would probably be: Sort the points by their proximity to the new location. Then
+   * find the two points closest to the n

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list