Revision: 50243
          
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=50243
Author:   campbellbarton
Date:     2012-08-27 09:44:56 +0000 (Mon, 27 Aug 2012)
Log Message:
-----------
Alternate mask spline feather offset calculation method: now there are 2 [Even 
| Smooth]

- Even preserves thickness but can give unsightly loops
- Smooth gives nicer shape but can give unsightly feather/spline mismatch for 
'S' shapes created by beziers.

This is an example where smooth works much nicer.

http://www.graphicall.org/ftp/ideasman42/mask_compare.png

Modified Paths:
--------------
    trunk/blender/release/scripts/startup/bl_ui/properties_mask_common.py
    trunk/blender/source/blender/blenkernel/intern/mask.c
    trunk/blender/source/blender/blenkernel/intern/mask_evaluate.c
    trunk/blender/source/blender/blenlib/BLI_math_vector.h
    trunk/blender/source/blender/blenlib/intern/math_vector.c
    trunk/blender/source/blender/makesdna/DNA_mask_types.h
    trunk/blender/source/blender/makesrna/intern/rna_mask.c

Modified: trunk/blender/release/scripts/startup/bl_ui/properties_mask_common.py
===================================================================
--- trunk/blender/release/scripts/startup/bl_ui/properties_mask_common.py       
2012-08-27 09:15:48 UTC (rev 50242)
+++ trunk/blender/release/scripts/startup/bl_ui/properties_mask_common.py       
2012-08-27 09:44:56 UTC (rev 50243)
@@ -121,6 +121,7 @@
         spline = mask.layers.active.splines.active
 
         col = layout.column()
+        col.prop(spline, "offset_mode")
         col.prop(spline, "weight_interpolation")
 
         row = col.row()

Modified: trunk/blender/source/blender/blenkernel/intern/mask.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/mask.c       2012-08-27 
09:15:48 UTC (rev 50242)
+++ trunk/blender/source/blender/blenkernel/intern/mask.c       2012-08-27 
09:44:56 UTC (rev 50243)
@@ -1194,17 +1194,6 @@
        mask_calc_point_handle(point, point_prev, point_next);
 }
 
-static void enforce_dist_v2_v2fl(float v1[2], const float v2[2], const float 
dist)
-{
-       if (!equals_v2v2(v2, v1)) {
-               float nor[2];
-
-               sub_v2_v2v2(nor, v1, v2);
-               normalize_v2(nor);
-               madd_v2_v2v2fl(v1, v2, nor, dist);
-       }
-}
-
 void BKE_mask_calc_handle_adjacent_interp(MaskSpline *spline, MaskSplinePoint 
*point, const float u)
 {
        /* TODO! - make this interpolate between siblings - not always 
midpoint! */
@@ -1246,8 +1235,8 @@
                length_average /= (float)length_tot;
                weight_average /= (float)length_tot;
 
-               enforce_dist_v2_v2fl(point->bezt.vec[0], point->bezt.vec[1], 
length_average);
-               enforce_dist_v2_v2fl(point->bezt.vec[2], point->bezt.vec[1], 
length_average);
+               dist_ensure_v2_v2fl(point->bezt.vec[0], point->bezt.vec[1], 
length_average);
+               dist_ensure_v2_v2fl(point->bezt.vec[2], point->bezt.vec[1], 
length_average);
                point->bezt.weight = weight_average;
        }
 }
@@ -1279,8 +1268,8 @@
 
        /* preserve length by applying it back */
        if (do_recalc_length == FALSE) {
-               enforce_dist_v2_v2fl(point->bezt.vec[0], point->bezt.vec[1], 
length_average);
-               enforce_dist_v2_v2fl(point->bezt.vec[2], point->bezt.vec[1], 
length_average);
+               dist_ensure_v2_v2fl(point->bezt.vec[0], point->bezt.vec[1], 
length_average);
+               dist_ensure_v2_v2fl(point->bezt.vec[2], point->bezt.vec[1], 
length_average);
        }
 }
 

Modified: trunk/blender/source/blender/blenkernel/intern/mask_evaluate.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/mask_evaluate.c      
2012-08-27 09:15:48 UTC (rev 50242)
+++ trunk/blender/source/blender/blenkernel/intern/mask_evaluate.c      
2012-08-27 09:44:56 UTC (rev 50243)
@@ -507,15 +507,12 @@
 #undef BUCKET_INDEX
 }
 
-/**
- * values align with #BKE_mask_spline_differentiate_with_resolution_ex
- * when \a resol arguments match.
- */
-float 
(*BKE_mask_spline_feather_differentiated_points_with_resolution_ex(MaskSpline 
*spline,
-                                                                         int 
*tot_feather_point,
-                                                                         const 
unsigned int resol,
-                                                                         const 
int do_feather_isect
-                                                                         ))[2]
+/** only called from 
#BKE_mask_spline_feather_differentiated_points_with_resolution_ex() ! */
+static float 
(*mask_spline_feather_differentiated_points_with_resolution_ex__even(MaskSpline 
*spline,
+                                                                               
   int *tot_feather_point,
+                                                                               
   const unsigned int resol,
+                                                                               
   const int do_feather_isect
+                                                                               
   ))[2]
 {
        MaskSplinePoint *points_array = BKE_mask_spline_point_array(spline);
        MaskSplinePoint *point_curr, *point_prev;
@@ -583,6 +580,161 @@
        return feather;
 }
 
+/** only called from 
#BKE_mask_spline_feather_differentiated_points_with_resolution_ex() ! */
+static float 
(*mask_spline_feather_differentiated_points_with_resolution_ex__double(MaskSpline
 *spline,
+                                                                               
     int *tot_feather_point,
+                                                                               
     const unsigned int resol,
+                                                                               
     const int do_feather_isect
+                                                                               
     ))[2]
+{
+       MaskSplinePoint *points_array = BKE_mask_spline_point_array(spline);
+
+       MaskSplinePoint *point_curr, *point_prev;
+       float (*feather)[2], (*fp)[2];
+       const int tot = BKE_mask_spline_differentiate_calc_total(spline, resol);
+       int a;
+
+       if (spline->tot_point <= 1) {
+               /* nothing to differentiate */
+               *tot_feather_point = 0;
+               return NULL;
+       }
+
+       /* len+1 because of 'forward_diff_bezier' function */
+       *tot_feather_point = tot;
+       feather = fp = MEM_mallocN((tot + 1) * sizeof(*feather), "mask spline 
vets");
+
+       a = spline->tot_point - 1;
+       if (spline->flag & MASK_SPLINE_CYCLIC)
+               a++;
+
+       point_prev = points_array;
+       point_curr = point_prev + 1;
+
+       while (a--) {
+               BezTriple local_prevbezt;
+               BezTriple local_bezt;
+               float point_prev_n[2], point_curr_n[2], tvec[2];
+               float weight_prev, weight_curr;
+               float len_base, len_feather, len_scalar;
+
+               BezTriple *bezt_prev;
+               BezTriple *bezt_curr;
+               int j;
+
+               if (a == 0 && (spline->flag & MASK_SPLINE_CYCLIC))
+                       point_curr = points_array;
+
+               bezt_prev = &point_prev->bezt;
+               bezt_curr = &point_curr->bezt;
+
+               /* modified copy for feather */
+               local_prevbezt = *bezt_prev;
+               local_bezt     = *bezt_curr;
+
+               bezt_prev = &local_prevbezt;
+               bezt_curr = &local_bezt;
+
+               /* calc the normals */
+               sub_v2_v2v2(tvec, bezt_prev->vec[1], bezt_prev->vec[0]);
+               normalize_v2(tvec);
+               point_prev_n[0] = -tvec[1];
+               point_prev_n[1] =  tvec[0];
+
+               sub_v2_v2v2(tvec, bezt_curr->vec[1], bezt_curr->vec[0]);
+               normalize_v2(tvec);
+               point_curr_n[0] = -tvec[1];
+               point_curr_n[1] =  tvec[0];
+
+               weight_prev = bezt_prev->weight;
+               weight_curr = bezt_curr->weight;
+
+               mul_v2_fl(point_prev_n, weight_prev);
+               mul_v2_fl(point_curr_n, weight_curr);
+
+               /* before we transform verts */
+               len_base = len_v2v2(bezt_prev->vec[1], bezt_curr->vec[1]);
+
+               // add_v2_v2(bezt_prev->vec[0], point_prev_n);  // not needed
+               add_v2_v2(bezt_prev->vec[1], point_prev_n);
+               add_v2_v2(bezt_prev->vec[2], point_prev_n);
+
+               add_v2_v2(bezt_curr->vec[0], point_curr_n);
+               add_v2_v2(bezt_curr->vec[1], point_curr_n);
+               // add_v2_v2(bezt_curr->vec[2], point_curr_n); // not needed
+
+               len_feather = len_v2v2(bezt_prev->vec[1], bezt_curr->vec[1]);
+
+               /* scale by chane in length */
+               len_scalar = len_feather / len_base;
+               dist_ensure_v2_v2fl(bezt_prev->vec[2], bezt_prev->vec[1], 
len_scalar * len_v2v2(bezt_prev->vec[2], bezt_prev->vec[1]));
+               dist_ensure_v2_v2fl(bezt_curr->vec[0], bezt_curr->vec[1], 
len_scalar * len_v2v2(bezt_curr->vec[0], bezt_curr->vec[1]));
+
+
+               for (j = 0; j < 2; j++) {
+                       BKE_curve_forward_diff_bezier(bezt_prev->vec[1][j], 
bezt_prev->vec[2][j],
+                                                     bezt_curr->vec[0][j], 
bezt_curr->vec[1][j],
+                                                     &(*fp)[j], resol, 2 * 
sizeof(float));
+               }
+
+
+               /* scale by the uw's */
+               if (point_prev->tot_uw) {
+                       for (j = 0; j < resol; j++, fp++) {
+                               float u = (float) j / resol;
+                               float weight_uw, weight_scalar;
+                               float co[2];
+
+                               /* TODO - these calls all calculate similar 
things
+                                * could be unified for some speed */
+                               BKE_mask_point_segment_co(spline, point_prev, 
u, co);
+
+                               weight_uw     = BKE_mask_point_weight(spline, 
point_prev, u);
+                               weight_scalar = 
BKE_mask_point_weight_scalar(spline, point_prev, u);
+
+                               dist_ensure_v2_v2fl(*fp, co, len_v2v2(*fp, co) 
* (weight_uw / weight_scalar));
+                       }
+               }
+               else {
+                       fp += resol;
+               }
+
+               if (a == 0 && (spline->flag & MASK_SPLINE_CYCLIC) == 0) {
+                       copy_v2_v2(*fp, bezt_curr->vec[1]);
+               }
+
+               point_prev = point_curr;
+               point_curr++;
+       }
+
+       if ((spline->flag & MASK_SPLINE_NOINTERSECT) && do_feather_isect) {
+               BKE_mask_spline_feather_collapse_inner_loops(spline, feather, 
tot);
+       }
+
+       return feather;
+}
+
+/**
+ * values align with #BKE_mask_spline_differentiate_with_resolution_ex
+ * when \a resol arguments match.
+ */
+float 
(*BKE_mask_spline_feather_differentiated_points_with_resolution_ex(MaskSpline 
*spline,
+                                                                         int 
*tot_feather_point,
+                                                                         const 
unsigned int resol,
+                                                                         const 
int do_feather_isect
+                                                                         ))[2]
+{
+       switch (spline->offset_mode) {
+               case MASK_SPLINE_OFFSET_EVEN:
+                       return 
mask_spline_feather_differentiated_points_with_resolution_ex__even(spline, 
tot_feather_point, resol, do_feather_isect);
+                       break;
+               case MASK_SPLINE_OFFSET_SMOOTH:
+               default:
+                       return 
mask_spline_feather_differentiated_points_with_resolution_ex__double(spline, 
tot_feather_point, resol, do_feather_isect);
+                       break;
+       }
+}
+
 float 
(*BKE_mask_spline_feather_differentiated_points_with_resolution(MaskSpline 
*spline, int width, int height,
                                                                       int 
*tot_feather_point, const int do_feather_isect))[2]
 {

Modified: trunk/blender/source/blender/blenlib/BLI_math_vector.h
===================================================================
--- trunk/blender/source/blender/blenlib/BLI_math_vector.h      2012-08-27 
09:15:48 UTC (rev 50242)
+++ trunk/blender/source/blender/blenlib/BLI_math_vector.h      2012-08-27 
09:44:56 UTC (rev 50243)
@@ -220,6 +220,9 @@
 
 void minmax_v3v3_v3(float min[3], float max[3], const float vec[3]);
 
+void dist_ensure_v3_v3fl(float v1[3], const float v2[3], const float dist);
+void dist_ensure_v2_v2fl(float v1[2], const float v2[2], const float dist);
+
 /***************************** Array Functions *******************************/
 /* attempted to follow fixed length vertex functions. names could be improved*/

@@ Diff output truncated at 10240 characters. @@
_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to