code cleanup: remove dead assignments, gave mask vars clearer names & moved some mask evaluation funcs into mask_evaluate.c

This commit is contained in:
Campbell Barton 2012-08-26 18:09:01 +00:00
parent 7b84a75a22
commit 52310bd4a7
4 changed files with 118 additions and 120 deletions

View File

@ -84,19 +84,6 @@ void BKE_mask_point_handle(struct MaskSplinePoint *point, float handle[2]);
void BKE_mask_point_set_handle(struct MaskSplinePoint *point, float loc[2], int keep_direction, void BKE_mask_point_set_handle(struct MaskSplinePoint *point, float loc[2], int keep_direction,
float orig_handle[2], float orig_vec[3][3]); float orig_handle[2], float orig_vec[3][3]);
float *BKE_mask_point_segment_diff(struct MaskSpline *spline, struct MaskSplinePoint *point,
unsigned int *tot_diff_point);
float *BKE_mask_point_segment_feather_diff(struct MaskSpline *spline, struct MaskSplinePoint *point,
unsigned int *tot_feather_point);
float *BKE_mask_point_segment_diff_with_resolution(struct MaskSpline *spline, struct MaskSplinePoint *point,
int width, int height,
unsigned int *tot_diff_point);
float *BKE_mask_point_segment_feather_diff_with_resolution(struct MaskSpline *spline, struct MaskSplinePoint *point,
int width, int height,
unsigned int *tot_feather_point);
void BKE_mask_point_segment_co(struct MaskSpline *spline, struct MaskSplinePoint *point, float u, float co[2]); void BKE_mask_point_segment_co(struct MaskSpline *spline, struct MaskSplinePoint *point, float u, float co[2]);
void BKE_mask_point_normal(struct MaskSpline *spline, struct MaskSplinePoint *point, void BKE_mask_point_normal(struct MaskSpline *spline, struct MaskSplinePoint *point,
float u, float n[2]); float u, float n[2]);
@ -189,6 +176,7 @@ int BKE_mask_get_duration(struct Mask *mask);
#define MASK_RESOL_MAX 128 #define MASK_RESOL_MAX 128
/* mask_evaluate.c */ /* mask_evaluate.c */
unsigned int BKE_mask_spline_resolution(struct MaskSpline *spline, int width, int height); unsigned int BKE_mask_spline_resolution(struct MaskSpline *spline, int width, int height);
unsigned int BKE_mask_spline_feather_resolution(struct MaskSpline *spline, int width, int height); unsigned int BKE_mask_spline_feather_resolution(struct MaskSpline *spline, int width, int height);
@ -205,9 +193,21 @@ float (*BKE_mask_spline_feather_differentiated_points_with_resolution_ex(struct
const unsigned int resol, const int do_feather_isect))[2]; const unsigned int resol, const int do_feather_isect))[2];
float (*BKE_mask_spline_feather_differentiated_points_with_resolution(struct MaskSpline *spline, int width, int height, float (*BKE_mask_spline_feather_differentiated_points_with_resolution(struct MaskSpline *spline, int width, int height,
int *tot_feather_point, const int do_feather_isect))[2]; int *tot_feather_point, const int do_feather_isect))[2];
/* *** mask point functions which involve evaluation *** */
float (*BKE_mask_spline_feather_points(struct MaskSpline *spline, int *tot_feather_point))[2]; float (*BKE_mask_spline_feather_points(struct MaskSpline *spline, int *tot_feather_point))[2];
float *BKE_mask_point_segment_diff(struct MaskSpline *spline, struct MaskSplinePoint *point,
unsigned int *tot_diff_point);
float *BKE_mask_point_segment_feather_diff(struct MaskSpline *spline, struct MaskSplinePoint *point,
unsigned int *tot_feather_point);
float *BKE_mask_point_segment_diff_with_resolution(struct MaskSpline *spline, struct MaskSplinePoint *point,
int width, int height,
unsigned int *tot_diff_point);
float *BKE_mask_point_segment_feather_diff_with_resolution(struct MaskSpline *spline, struct MaskSplinePoint *point,
int width, int height,
unsigned int *tot_feather_point);
/* mask_rasterize.c */ /* mask_rasterize.c */
struct MaskRasterHandle; struct MaskRasterHandle;

View File

@ -483,73 +483,6 @@ void BKE_mask_point_set_handle(MaskSplinePoint *point, float loc[2], int keep_di
} }
} }
float *BKE_mask_point_segment_feather_diff_with_resolution(MaskSpline *spline, MaskSplinePoint *point,
int width, int height,
unsigned int *tot_feather_point)
{
float *feather, *fp;
unsigned int resol = BKE_mask_spline_feather_resolution(spline, width, height);
unsigned int i;
feather = fp = MEM_callocN(2 * resol * sizeof(float), "mask point spline feather diff points");
for (i = 0; i < resol; i++, fp += 2) {
float u = (float)(i % resol) / resol, weight;
float co[2], n[2];
BKE_mask_point_segment_co(spline, point, u, co);
BKE_mask_point_normal(spline, point, u, n);
weight = BKE_mask_point_weight(spline, point, u);
fp[0] = co[0] + n[0] * weight;
fp[1] = co[1] + n[1] * weight;
}
*tot_feather_point = resol;
return feather;
}
float *BKE_mask_point_segment_feather_diff(MaskSpline *spline, MaskSplinePoint *point, unsigned int *tot_feather_point)
{
return BKE_mask_point_segment_feather_diff_with_resolution(spline, point, 0, 0, tot_feather_point);
}
float *BKE_mask_point_segment_diff_with_resolution(MaskSpline *spline, MaskSplinePoint *point,
int width, int height, unsigned int *tot_diff_point)
{
MaskSplinePoint *points_array = BKE_mask_spline_point_array_from_point(spline, point);
BezTriple *bezt, *bezt_next;
float *diff_points, *fp;
int j, resol = BKE_mask_spline_resolution(spline, width, height);
bezt = &point->bezt;
bezt_next = BKE_mask_spline_point_next_bezt(spline, points_array, point);
if (!bezt_next)
return NULL;
/* resol+1 because of 'forward_diff_bezier' function */
*tot_diff_point = resol + 1;
diff_points = fp = MEM_callocN((resol + 1) * 2 * sizeof(float), "mask segment vets");
for (j = 0; j < 2; j++) {
BKE_curve_forward_diff_bezier(bezt->vec[1][j], bezt->vec[2][j],
bezt_next->vec[0][j], bezt_next->vec[1][j],
fp + j, resol, 2 * sizeof(float));
}
copy_v2_v2(fp + 2 * resol, bezt_next->vec[1]);
return diff_points;
}
float *BKE_mask_point_segment_diff(MaskSpline *spline, MaskSplinePoint *point, unsigned int *tot_diff_point)
{
return BKE_mask_point_segment_diff_with_resolution(spline, point, 0, 0, tot_diff_point);
}
void BKE_mask_point_segment_co(MaskSpline *spline, MaskSplinePoint *point, float u, float co[2]) void BKE_mask_point_segment_co(MaskSpline *spline, MaskSplinePoint *point, float u, float co[2])
{ {
MaskSplinePoint *points_array = BKE_mask_spline_point_array_from_point(spline, point); MaskSplinePoint *points_array = BKE_mask_spline_point_array_from_point(spline, point);

View File

@ -70,27 +70,24 @@ unsigned int BKE_mask_spline_resolution(MaskSpline *spline, int width, int heigh
unsigned int i, resol = 1; unsigned int i, resol = 1;
if (width != 0 && height != 0) { if (width != 0 && height != 0) {
if (width >= height) max_segment = 1.0f / (float)maxi(width, height);
max_segment = 1.0f / (float) width;
else
max_segment = 1.0f / (float) height;
} }
for (i = 0; i < spline->tot_point; i++) { for (i = 0; i < spline->tot_point; i++) {
MaskSplinePoint *point = &spline->points[i]; MaskSplinePoint *point = &spline->points[i];
BezTriple *bezt, *bezt_next; BezTriple *bezt_curr, *bezt_next;
float a, b, c, len; float a, b, c, len;
unsigned int cur_resol; unsigned int cur_resol;
bezt = &point->bezt; bezt_curr = &point->bezt;
bezt_next = BKE_mask_spline_point_next_bezt(spline, spline->points, point); bezt_next = BKE_mask_spline_point_next_bezt(spline, spline->points, point);
if (bezt_next == NULL) { if (bezt_next == NULL) {
break; break;
} }
a = len_v3v3(bezt->vec[1], bezt->vec[2]); a = len_v3v3(bezt_curr->vec[1], bezt_curr->vec[2]);
b = len_v3v3(bezt->vec[2], bezt_next->vec[0]); b = len_v3v3(bezt_curr->vec[2], bezt_next->vec[0]);
c = len_v3v3(bezt_next->vec[0], bezt_next->vec[1]); c = len_v3v3(bezt_next->vec[0], bezt_next->vec[1]);
len = a + b + c; len = a + b + c;
@ -165,7 +162,7 @@ float (*BKE_mask_spline_differentiate_with_resolution_ex(MaskSpline *spline,
{ {
MaskSplinePoint *points_array = BKE_mask_spline_point_array(spline); MaskSplinePoint *points_array = BKE_mask_spline_point_array(spline);
MaskSplinePoint *point, *prev; MaskSplinePoint *point_curr, *point_prev;
float (*diff_points)[2], (*fp)[2]; float (*diff_points)[2], (*fp)[2];
const int tot = BKE_mask_spline_differentiate_calc_total(spline, resol); const int tot = BKE_mask_spline_differentiate_calc_total(spline, resol);
int a; int a;
@ -184,34 +181,34 @@ float (*BKE_mask_spline_differentiate_with_resolution_ex(MaskSpline *spline,
if (spline->flag & MASK_SPLINE_CYCLIC) if (spline->flag & MASK_SPLINE_CYCLIC)
a++; a++;
prev = points_array; point_prev = points_array;
point = prev + 1; point_curr = point_prev + 1;
while (a--) { while (a--) {
BezTriple *prevbezt; BezTriple *bezt_prev;
BezTriple *bezt; BezTriple *bezt_curr;
int j; int j;
if (a == 0 && (spline->flag & MASK_SPLINE_CYCLIC)) if (a == 0 && (spline->flag & MASK_SPLINE_CYCLIC))
point = points_array; point_curr = points_array;
prevbezt = &prev->bezt; bezt_prev = &point_prev->bezt;
bezt = &point->bezt; bezt_curr = &point_curr->bezt;
for (j = 0; j < 2; j++) { for (j = 0; j < 2; j++) {
BKE_curve_forward_diff_bezier(prevbezt->vec[1][j], prevbezt->vec[2][j], BKE_curve_forward_diff_bezier(bezt_prev->vec[1][j], bezt_prev->vec[2][j],
bezt->vec[0][j], bezt->vec[1][j], bezt_curr->vec[0][j], bezt_curr->vec[1][j],
&(*fp)[j], resol, 2 * sizeof(float)); &(*fp)[j], resol, 2 * sizeof(float));
} }
fp += resol; fp += resol;
if (a == 0 && (spline->flag & MASK_SPLINE_CYCLIC) == 0) { if (a == 0 && (spline->flag & MASK_SPLINE_CYCLIC) == 0) {
copy_v2_v2(*fp, bezt->vec[1]); copy_v2_v2(*fp, bezt_curr->vec[1]);
} }
prev = point; point_prev = point_curr;
point++; point_curr++;
} }
return diff_points; return diff_points;
@ -521,7 +518,7 @@ float (*BKE_mask_spline_feather_differentiated_points_with_resolution_ex(MaskSpl
))[2] ))[2]
{ {
MaskSplinePoint *points_array = BKE_mask_spline_point_array(spline); MaskSplinePoint *points_array = BKE_mask_spline_point_array(spline);
MaskSplinePoint *point, *prev; MaskSplinePoint *point_curr, *point_prev;
float (*feather)[2], (*fp)[2]; float (*feather)[2], (*fp)[2];
const int tot = BKE_mask_spline_differentiate_calc_total(spline, resol); const int tot = BKE_mask_spline_differentiate_calc_total(spline, resol);
@ -534,20 +531,20 @@ float (*BKE_mask_spline_feather_differentiated_points_with_resolution_ex(MaskSpl
if (spline->flag & MASK_SPLINE_CYCLIC) if (spline->flag & MASK_SPLINE_CYCLIC)
a++; a++;
prev = points_array; point_prev = points_array;
point = prev + 1; point_curr = point_prev + 1;
while (a--) { while (a--) {
/* BezTriple *prevbezt; */ /* UNUSED */ /* BezTriple *bezt_prev; */ /* UNUSED */
/* BezTriple *bezt; */ /* UNUSED */ /* BezTriple *bezt_curr; */ /* UNUSED */
int j; int j;
if (a == 0 && (spline->flag & MASK_SPLINE_CYCLIC)) if (a == 0 && (spline->flag & MASK_SPLINE_CYCLIC))
point = points_array; point_curr = points_array;
/* prevbezt = &prev->bezt; */ /* bezt_prev = &point_prev->bezt; */
/* bezt = &point->bezt; */ /* bezt_curr = &point_curr->bezt; */
for (j = 0; j < resol; j++, fp++) { for (j = 0; j < resol; j++, fp++) {
float u = (float) j / resol, weight; float u = (float) j / resol, weight;
@ -555,9 +552,9 @@ float (*BKE_mask_spline_feather_differentiated_points_with_resolution_ex(MaskSpl
/* TODO - these calls all calculate similar things /* TODO - these calls all calculate similar things
* could be unified for some speed */ * could be unified for some speed */
BKE_mask_point_segment_co(spline, prev, u, co); BKE_mask_point_segment_co(spline, point_prev, u, co);
BKE_mask_point_normal(spline, prev, u, n); BKE_mask_point_normal(spline, point_prev, u, n);
weight = BKE_mask_point_weight(spline, prev, u); weight = BKE_mask_point_weight(spline, point_prev, u);
madd_v2_v2v2fl(*fp, co, n, weight); madd_v2_v2v2fl(*fp, co, n, weight);
} }
@ -566,15 +563,15 @@ float (*BKE_mask_spline_feather_differentiated_points_with_resolution_ex(MaskSpl
float u = 1.0f, weight; float u = 1.0f, weight;
float co[2], n[2]; float co[2], n[2];
BKE_mask_point_segment_co(spline, prev, u, co); BKE_mask_point_segment_co(spline, point_prev, u, co);
BKE_mask_point_normal(spline, prev, u, n); BKE_mask_point_normal(spline, point_prev, u, n);
weight = BKE_mask_point_weight(spline, prev, u); weight = BKE_mask_point_weight(spline, point_prev, u);
madd_v2_v2v2fl(*fp, co, n, weight); madd_v2_v2v2fl(*fp, co, n, weight);
} }
prev = point; point_prev = point_curr;
point++; point_curr++;
} }
*tot_feather_point = tot; *tot_feather_point = tot;
@ -645,3 +642,71 @@ float (*BKE_mask_spline_feather_points(MaskSpline *spline, int *tot_feather_poin
return feather; return feather;
} }
/* *** mask point functions which involve evaluation *** */
float *BKE_mask_point_segment_feather_diff_with_resolution(MaskSpline *spline, MaskSplinePoint *point,
int width, int height,
unsigned int *tot_feather_point)
{
float *feather, *fp;
unsigned int resol = BKE_mask_spline_feather_resolution(spline, width, height);
unsigned int i;
feather = fp = MEM_callocN(2 * resol * sizeof(float), "mask point spline feather diff points");
for (i = 0; i < resol; i++, fp += 2) {
float u = (float)(i % resol) / resol, weight;
float co[2], n[2];
BKE_mask_point_segment_co(spline, point, u, co);
BKE_mask_point_normal(spline, point, u, n);
weight = BKE_mask_point_weight(spline, point, u);
fp[0] = co[0] + n[0] * weight;
fp[1] = co[1] + n[1] * weight;
}
*tot_feather_point = resol;
return feather;
}
float *BKE_mask_point_segment_feather_diff(MaskSpline *spline, MaskSplinePoint *point, unsigned int *tot_feather_point)
{
return BKE_mask_point_segment_feather_diff_with_resolution(spline, point, 0, 0, tot_feather_point);
}
float *BKE_mask_point_segment_diff_with_resolution(MaskSpline *spline, MaskSplinePoint *point,
int width, int height, unsigned int *tot_diff_point)
{
MaskSplinePoint *points_array = BKE_mask_spline_point_array_from_point(spline, point);
BezTriple *bezt, *bezt_next;
float *diff_points, *fp;
int j, resol = BKE_mask_spline_resolution(spline, width, height);
bezt = &point->bezt;
bezt_next = BKE_mask_spline_point_next_bezt(spline, points_array, point);
if (!bezt_next)
return NULL;
/* resol+1 because of 'forward_diff_bezier' function */
*tot_diff_point = resol + 1;
diff_points = fp = MEM_callocN((resol + 1) * 2 * sizeof(float), "mask segment vets");
for (j = 0; j < 2; j++) {
BKE_curve_forward_diff_bezier(bezt->vec[1][j], bezt->vec[2][j],
bezt_next->vec[0][j], bezt_next->vec[1][j],
fp + j, resol, 2 * sizeof(float));
}
copy_v2_v2(fp + 2 * resol, bezt_next->vec[1]);
return diff_points;
}
float *BKE_mask_point_segment_diff(MaskSpline *spline, MaskSplinePoint *point, unsigned int *tot_diff_point)
{
return BKE_mask_point_segment_diff_with_resolution(spline, point, 0, 0, tot_diff_point);
}

View File

@ -6239,7 +6239,7 @@ static void createTransMaskingData(bContext *C, TransInfo *t)
/* count */ /* count */
for (masklay = mask->masklayers.first; masklay; masklay = masklay->next) { for (masklay = mask->masklayers.first; masklay; masklay = masklay->next) {
MaskSpline *spline = masklay->splines.first; MaskSpline *spline;
if (masklay->restrictflag & (MASK_RESTRICT_VIEW | MASK_RESTRICT_SELECT)) { if (masklay->restrictflag & (MASK_RESTRICT_VIEW | MASK_RESTRICT_SELECT)) {
continue; continue;
@ -6282,7 +6282,7 @@ static void createTransMaskingData(bContext *C, TransInfo *t)
/* create data */ /* create data */
for (masklay = mask->masklayers.first; masklay; masklay = masklay->next) { for (masklay = mask->masklayers.first; masklay; masklay = masklay->next) {
MaskSpline *spline = masklay->splines.first; MaskSpline *spline;
if (masklay->restrictflag & (MASK_RESTRICT_VIEW | MASK_RESTRICT_SELECT)) { if (masklay->restrictflag & (MASK_RESTRICT_VIEW | MASK_RESTRICT_SELECT)) {
continue; continue;