[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [47417] trunk/blender/source/blender/ blenkernel/intern/mask.c: copy mask file from tomato branch, sorry dont know how to do multiple of these at a time...

Campbell Barton ideasman42 at gmail.com
Mon Jun 4 17:44:53 CEST 2012


Revision: 47417
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=47417
Author:   campbellbarton
Date:     2012-06-04 15:44:42 +0000 (Mon, 04 Jun 2012)
Log Message:
-----------
copy mask file from tomato branch, sorry dont know how to do multiple of these at a time...

Added Paths:
-----------
    trunk/blender/source/blender/blenkernel/intern/mask.c

Copied: trunk/blender/source/blender/blenkernel/intern/mask.c (from rev 47416, branches/soc-2011-tomato/source/blender/blenkernel/intern/mask.c)
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/mask.c	                        (rev 0)
+++ trunk/blender/source/blender/blenkernel/intern/mask.c	2012-06-04 15:44:42 UTC (rev 47417)
@@ -0,0 +1,2095 @@
+/*
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * The Original Code is Copyright (C) 2012 Blender Foundation.
+ * All rights reserved.
+ *
+ * Contributor(s): Blender Foundation,
+ *                 Sergey Sharybin
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file blender/blenkernel/intern/mask.c
+ *  \ingroup bke
+ */
+
+#include <stddef.h>
+#include <string.h>
+
+#include "MEM_guardedalloc.h"
+
+#include "BLI_utildefines.h"
+#include "BLI_path_util.h"
+#include "BLI_string.h"
+#include "BLI_listbase.h"
+#include "BLI_math.h"
+
+#include "DNA_mask_types.h"
+#include "DNA_scene_types.h"
+#include "DNA_object_types.h"
+#include "DNA_screen_types.h"
+#include "DNA_space_types.h"
+#include "DNA_movieclip_types.h"
+#include "DNA_tracking_types.h"
+
+#include "BKE_curve.h"
+#include "BKE_global.h"
+#include "BKE_library.h"
+#include "BKE_main.h"
+#include "BKE_mask.h"
+#include "BKE_tracking.h"
+#include "BKE_movieclip.h"
+#include "BKE_utildefines.h"
+
+#include "raskter.h"
+
+MaskSplinePoint *BKE_mask_spline_point_array(MaskSpline *spline)
+{
+	return spline->points_deform ? spline->points_deform : spline->points;
+}
+
+MaskSplinePoint *BKE_mask_spline_point_array_from_point(MaskSpline *spline, MaskSplinePoint *point_ref)
+{
+	if ((point_ref >= spline->points) && (point_ref < &spline->points[spline->tot_point])) {
+		return spline->points;
+	}
+
+	if ((point_ref >= spline->points_deform) && (point_ref < &spline->points_deform[spline->tot_point])) {
+		return spline->points_deform;
+	}
+
+	BLI_assert(!"wrong array");
+	return NULL;
+}
+
+/* mask layers */
+
+MaskLayer *BKE_mask_layer_new(Mask *mask, const char *name)
+{
+	MaskLayer *masklay = MEM_callocN(sizeof(MaskLayer), __func__);
+
+	if (name && name[0])
+		BLI_strncpy(masklay->name, name, sizeof(masklay->name));
+	else
+		strcpy(masklay->name, "MaskLayer");
+
+	BLI_addtail(&mask->masklayers, masklay);
+
+	BKE_mask_layer_unique_name(mask, masklay);
+
+	mask->masklay_tot++;
+
+	masklay->alpha = 1.0f;
+
+	return masklay;
+}
+
+/* note: may still be hidden, caller needs to check */
+MaskLayer *BKE_mask_layer_active(Mask *mask)
+{
+	return BLI_findlink(&mask->masklayers, mask->masklay_act);
+}
+
+void BKE_mask_layer_active_set(Mask *mask, MaskLayer *masklay)
+{
+	mask->masklay_act = BLI_findindex(&mask->masklayers, masklay);
+}
+
+void BKE_mask_layer_remove(Mask *mask, MaskLayer *masklay)
+{
+	BLI_remlink(&mask->masklayers, masklay);
+	BKE_mask_layer_free(masklay);
+
+	mask->masklay_tot--;
+
+	if (mask->masklay_act >= mask->masklay_tot)
+		mask->masklay_act = mask->masklay_tot - 1;
+}
+
+void BKE_mask_layer_unique_name(Mask *mask, MaskLayer *masklay)
+{
+	BLI_uniquename(&mask->masklayers, masklay, "MaskLayer", '.', offsetof(MaskLayer, name), sizeof(masklay->name));
+}
+
+/* splines */
+
+MaskSpline *BKE_mask_spline_add(MaskLayer *masklay)
+{
+	MaskSpline *spline;
+
+	spline = MEM_callocN(sizeof(MaskSpline), "new mask spline");
+	BLI_addtail(&masklay->splines, spline);
+
+	/* spline shall have one point at least */
+	spline->points = MEM_callocN(sizeof(MaskSplinePoint), "new mask spline point");
+	spline->tot_point = 1;
+
+	/* cyclic shapes are more usually used */
+	// spline->flag |= MASK_SPLINE_CYCLIC; // disable because its not so nice for drawing. could be done differently
+
+	spline->weight_interp = MASK_SPLINE_INTERP_LINEAR;
+
+	BKE_mask_parent_init(&spline->parent);
+
+	return spline;
+}
+
+static int BKE_mask_spline_resolution(MaskSpline *spline, int width, int height)
+{
+	float max_segment = 0.01f;
+	int i, resol = 1;
+
+	if (width != 0 && height != 0) {
+		if (width >= height)
+			max_segment = 1.0f / (float) width;
+		else
+			max_segment = 1.0f / (float) height;
+	}
+
+	for (i = 0; i < spline->tot_point; i++) {
+		MaskSplinePoint *point = &spline->points[i];
+		MaskSplinePoint *next_point;
+		BezTriple *bezt, *next_bezt;
+		float a, b, c, len;
+		int cur_resol;
+
+		if (i == spline->tot_point - 1) {
+			if (spline->flag & MASK_SPLINE_CYCLIC)
+				next_point = &spline->points[0];
+			else
+				break;
+		}
+		else
+			next_point = &spline->points[i + 1];
+
+		bezt = &point->bezt;
+		next_bezt = &next_point->bezt;
+
+		a = len_v3v3(bezt->vec[1], bezt->vec[2]);
+		b = len_v3v3(bezt->vec[2], next_bezt->vec[0]);
+		c = len_v3v3(next_bezt->vec[0], next_bezt->vec[1]);
+
+		len = a + b + c;
+		cur_resol = len / max_segment;
+
+		resol = MAX2(resol, cur_resol);
+	}
+
+	return resol;
+}
+
+static int BKE_mask_spline_feather_resolution(MaskSpline *spline, int width, int height)
+{
+	const float max_segment = 0.005;
+	int resol = BKE_mask_spline_resolution(spline, width, height);
+	float max_jump = 0.0f;
+	int i;
+
+	for (i = 0; i < spline->tot_point; i++) {
+		MaskSplinePoint *point = &spline->points[i];
+		float prev_u, prev_w;
+		int j;
+
+		prev_u = 0.0f;
+		prev_w = point->bezt.weight;
+
+		for (j = 0; j < point->tot_uw; j++) {
+			float jump = fabsf((point->uw[j].w - prev_w) / (point->uw[j].u - prev_u));
+
+			max_jump = MAX2(max_jump, jump);
+
+			prev_u = point->uw[j].u;
+			prev_w = point->uw[j].w;
+		}
+	}
+
+	resol += max_jump / max_segment;
+
+	return resol;
+}
+
+float (*BKE_mask_spline_differentiate_with_resolution(MaskSpline *spline, int width, int height,
+                                                      int *tot_diff_point))[2]
+{
+	MaskSplinePoint *points_array = BKE_mask_spline_point_array(spline);
+
+	MaskSplinePoint *point, *prev;
+	float (*diff_points)[2], (*fp)[2];
+	int a, len, resol = BKE_mask_spline_resolution(spline, width, height);
+
+	if (spline->tot_point <= 1) {
+		/* nothing to differentiate */
+		*tot_diff_point = 0;
+		return NULL;
+	}
+
+	/* count */
+	len = (spline->tot_point - 1) * resol;
+
+	if (spline->flag & MASK_SPLINE_CYCLIC)
+		len += resol;
+	else
+		len++;
+
+	/* len+1 because of 'forward_diff_bezier' function */
+	*tot_diff_point = len;
+	diff_points = fp = MEM_mallocN((len + 1) * sizeof(*diff_points), "mask spline vets");
+
+	a = spline->tot_point - 1;
+	if (spline->flag & MASK_SPLINE_CYCLIC)
+		a++;
+
+	prev = points_array;
+	point = prev + 1;
+
+	while (a--) {
+		BezTriple *prevbezt;
+		BezTriple *bezt;
+		int j;
+
+		if (a == 0 && (spline->flag & MASK_SPLINE_CYCLIC))
+			point = points_array;
+
+		prevbezt = &prev->bezt;
+		bezt = &point->bezt;
+
+		for (j = 0; j < 2; j++) {
+			BKE_curve_forward_diff_bezier(prevbezt->vec[1][j], prevbezt->vec[2][j],
+			                              bezt->vec[0][j], bezt->vec[1][j],
+			                              &(*fp)[j], resol, 2 * sizeof(float));
+		}
+
+		fp += resol;
+
+		if (a == 0 && (spline->flag & MASK_SPLINE_CYCLIC) == 0) {
+			copy_v2_v2(*fp, bezt->vec[1]);
+		}
+
+		prev = point;
+		point++;
+	}
+
+	return diff_points;
+}
+
+float (*BKE_mask_spline_differentiate(MaskSpline *spline, int *tot_diff_point))[2]
+{
+	return BKE_mask_spline_differentiate_with_resolution(spline, 0, 0, tot_diff_point);
+}
+
+float (*BKE_mask_spline_feather_differentiated_points_with_resolution(MaskSpline *spline, int width, int height,
+                                                                      int *tot_feather_point))[2]
+{
+	MaskSplinePoint *points_array = BKE_mask_spline_point_array(spline);
+
+	float (*feather)[2], (*fp)[2];
+	int i, j, tot, resol = BKE_mask_spline_feather_resolution(spline, width, height);
+
+	tot = resol * spline->tot_point;
+	feather = fp = MEM_mallocN(tot * sizeof(*feather), "mask spline feather diff points");
+
+	for (i = 0; i < spline->tot_point; i++) {
+		MaskSplinePoint *point = &points_array[i];
+
+		for (j = 0; j < resol; j++, fp++) {
+			float u = (float) j / resol, weight;
+			float co[2], n[2];
+
+			/* TODO - these calls all calculate similar things
+			 * could be unified for some speed */
+			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);
+
+			madd_v2_v2v2fl(*fp, co, n, weight);
+		}
+	}
+
+	*tot_feather_point = tot;
+
+	return feather;
+}
+
+float (*BKE_mask_spline_feather_differentiated_points(MaskSpline *spline, int *tot_feather_point))[2]
+{
+	return BKE_mask_spline_feather_differentiated_points_with_resolution(spline, 0, 0, tot_feather_point);
+}
+
+float (*BKE_mask_spline_feather_points(MaskSpline *spline, int *tot_feather_point))[2]
+{
+	MaskSplinePoint *points_array = BKE_mask_spline_point_array(spline);
+
+	int i, tot = 0;
+	float (*feather)[2], (*fp)[2];
+
+	/* count */
+	for (i = 0; i < spline->tot_point; i++) {
+		MaskSplinePoint *point = &points_array[i];
+
+		tot += point->tot_uw + 1;
+	}
+
+	/* create data */
+	feather = fp = MEM_mallocN(tot * sizeof(*feather), "mask spline feather points");
+
+	for (i = 0; i < spline->tot_point; i++) {
+		MaskSplinePoint *point = &points_array[i];
+		BezTriple *bezt = &point->bezt;
+		float weight, n[2];
+		int j;
+
+		BKE_mask_point_normal(spline, point, 0.0f, n);
+		weight = BKE_mask_point_weight(spline, point, 0.0f);
+
+		madd_v2_v2v2fl(*fp, bezt->vec[1], n, weight);
+		fp++;
+
+		for (j = 0; j < point->tot_uw; j++) {
+			float u = point->uw[j].u;
+			float co[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);
+
+			madd_v2_v2v2fl(*fp, co, n, weight);
+			fp++;
+		}
+	}
+
+	*tot_feather_point = tot;
+
+	return feather;
+}
+
+void BKE_mask_point_direction_switch(MaskSplinePoint *point)
+{
+	const int tot_uw = point->tot_uw;

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list