[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [47410] branches/soc-2011-tomato/source/ blender: split mask add functions into their own file.
Campbell Barton
ideasman42 at gmail.com
Mon Jun 4 16:27:26 CEST 2012
Revision: 47410
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=47410
Author: campbellbarton
Date: 2012-06-04 14:27:13 +0000 (Mon, 04 Jun 2012)
Log Message:
-----------
split mask add functions into their own file.
Modified Paths:
--------------
branches/soc-2011-tomato/source/blender/blenkernel/BKE_mask.h
branches/soc-2011-tomato/source/blender/blenkernel/intern/mask.c
branches/soc-2011-tomato/source/blender/editors/mask/CMakeLists.txt
branches/soc-2011-tomato/source/blender/editors/mask/mask_edit.c
branches/soc-2011-tomato/source/blender/editors/mask/mask_intern.h
branches/soc-2011-tomato/source/blender/editors/mask/mask_ops.c
Added Paths:
-----------
branches/soc-2011-tomato/source/blender/editors/mask/mask_add.c
Modified: branches/soc-2011-tomato/source/blender/blenkernel/BKE_mask.h
===================================================================
--- branches/soc-2011-tomato/source/blender/blenkernel/BKE_mask.h 2012-06-04 13:51:36 UTC (rev 47409)
+++ branches/soc-2011-tomato/source/blender/blenkernel/BKE_mask.h 2012-06-04 14:27:13 UTC (rev 47410)
@@ -69,6 +69,7 @@
void BKE_mask_point_direction_switch(struct MaskSplinePoint *point);
void BKE_mask_spline_direction_switch(struct MaskLayer *masklay, struct MaskSpline *spline);
+float BKE_mask_spline_project_co(struct MaskSpline *spline, struct MaskSplinePoint *point, float start_u, const float co[2]);
/* point */
int BKE_mask_point_has_handle(struct MaskSplinePoint *point);
Modified: branches/soc-2011-tomato/source/blender/blenkernel/intern/mask.c
===================================================================
--- branches/soc-2011-tomato/source/blender/blenkernel/intern/mask.c 2012-06-04 13:51:36 UTC (rev 47409)
+++ branches/soc-2011-tomato/source/blender/blenkernel/intern/mask.c 2012-06-04 14:27:13 UTC (rev 47410)
@@ -455,6 +455,69 @@
}
}
+
+float BKE_mask_spline_project_co(MaskSpline *spline, MaskSplinePoint *point, float start_u, const float co[2])
+{
+ const float proj_eps = 1e-3;
+ const float proj_eps_squared = proj_eps * proj_eps;
+ const int N = 1000;
+ float u = -1.0f, du = 1.0f / N, u1 = start_u, u2 = start_u;
+ float ang = -1.0f;
+
+ while (u1 > 0.0f || u2 < 1.0f) {
+ float n1[2], n2[2], co1[2], co2[2];
+ float v1[2], v2[2];
+ float ang1, ang2;
+
+ if (u1 >= 0.0f) {
+ BKE_mask_point_segment_co(spline, point, u1, co1);
+ BKE_mask_point_normal(spline, point, u1, n1);
+ sub_v2_v2v2(v1, co, co1);
+
+ if (len_squared_v2(v1) > proj_eps_squared) {
+ ang1 = angle_v2v2(v1, n1);
+ if (ang1 > M_PI / 2.0f)
+ ang1 = M_PI - ang1;
+
+ if (ang < 0.0f || ang1 < ang) {
+ ang = ang1;
+ u = u1;
+ }
+ }
+ else {
+ u = u1;
+ break;
+ }
+ }
+
+ if (u2 <= 1.0f) {
+ BKE_mask_point_segment_co(spline, point, u2, co2);
+ BKE_mask_point_normal(spline, point, u2, n2);
+ sub_v2_v2v2(v2, co, co2);
+
+ if (len_squared_v2(v2) > proj_eps_squared) {
+ ang2 = angle_v2v2(v2, n2);
+ if (ang2 > M_PI / 2.0f)
+ ang2 = M_PI - ang2;
+
+ if (ang2 < ang) {
+ ang = ang2;
+ u = u2;
+ }
+ }
+ else {
+ u = u2;
+ break;
+ }
+ }
+
+ u1 -= du;
+ u2 += du;
+ }
+
+ return u;
+}
+
/* point */
int BKE_mask_point_has_handle(MaskSplinePoint *point)
Modified: branches/soc-2011-tomato/source/blender/editors/mask/CMakeLists.txt
===================================================================
--- branches/soc-2011-tomato/source/blender/editors/mask/CMakeLists.txt 2012-06-04 13:51:36 UTC (rev 47409)
+++ branches/soc-2011-tomato/source/blender/editors/mask/CMakeLists.txt 2012-06-04 14:27:13 UTC (rev 47410)
@@ -37,6 +37,7 @@
)
set(SRC
+ mask_add.c
mask_draw.c
mask_edit.c
mask_ops.c
Added: branches/soc-2011-tomato/source/blender/editors/mask/mask_add.c
===================================================================
--- branches/soc-2011-tomato/source/blender/editors/mask/mask_add.c (rev 0)
+++ branches/soc-2011-tomato/source/blender/editors/mask/mask_add.c 2012-06-04 14:27:13 UTC (rev 47410)
@@ -0,0 +1,707 @@
+/*
+ * ***** 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/editors/mask/mask_add.c
+ * \ingroup edmask
+ */
+
+#include "MEM_guardedalloc.h"
+
+#include "BLI_utildefines.h"
+#include "BLI_listbase.h"
+#include "BLI_math.h"
+
+#include "BKE_context.h"
+#include "BKE_curve.h"
+#include "BKE_depsgraph.h"
+#include "BKE_mask.h"
+
+#include "DNA_scene_types.h"
+#include "DNA_mask_types.h"
+#include "DNA_object_types.h" /* SELECT */
+
+#include "WM_api.h"
+#include "WM_types.h"
+
+#include "ED_screen.h"
+#include "ED_mask.h"
+#include "ED_clip.h"
+#include "ED_keyframing.h"
+
+#include "RNA_access.h"
+#include "RNA_define.h"
+
+#include "mask_intern.h" /* own include */
+
+
+static int find_nearest_diff_point(bContext *C, Mask *mask, const float normal_co[2], int threshold, int feather,
+ MaskLayer **masklay_r, MaskSpline **spline_r, MaskSplinePoint **point_r,
+ float *u_r, float tangent[2])
+{
+ MaskLayer *masklay, *point_masklay;
+ MaskSpline *point_spline;
+ MaskSplinePoint *point = NULL;
+ float dist, co[2];
+ int width, height;
+ float u;
+ float scalex, scaley, aspx, aspy;
+
+ ED_mask_size(C, &width, &height);
+ ED_mask_aspect(C, &aspx, &aspy);
+ ED_mask_pixelspace_factor(C, &scalex, &scaley);
+
+ co[0] = normal_co[0] * scalex;
+ co[1] = normal_co[1] * scaley;
+
+ for (masklay = mask->masklayers.first; masklay; masklay = masklay->next) {
+ MaskSpline *spline;
+
+ if (masklay->restrictflag & (MASK_RESTRICT_VIEW | MASK_RESTRICT_SELECT)) {
+ continue;
+ }
+
+ for (spline = masklay->splines.first; spline; spline = spline->next) {
+ int i;
+
+ for (i = 0; i < spline->tot_point; i++) {
+ MaskSplinePoint *cur_point = &spline->points[i];
+ float *diff_points;
+ int tot_diff_point;
+
+ diff_points = BKE_mask_point_segment_diff_with_resolution(spline, cur_point, width, height,
+ &tot_diff_point);
+
+ if (diff_points) {
+ int i, tot_feather_point, tot_point;
+ float *feather_points = NULL, *points;
+
+ if (feather) {
+ feather_points = BKE_mask_point_segment_feather_diff_with_resolution(spline, cur_point,
+ width, height,
+ &tot_feather_point);
+
+ points = feather_points;
+ tot_point = tot_feather_point;
+ }
+ else {
+ points = diff_points;
+ tot_point = tot_diff_point;
+ }
+
+ for (i = 0; i < tot_point - 1; i++) {
+ float cur_dist, a[2], b[2];
+
+ a[0] = points[2 * i] * scalex;
+ a[1] = points[2 * i + 1] * scaley;
+
+ b[0] = points[2 * i + 2] * scalex;
+ b[1] = points[2 * i + 3] * scaley;
+
+ cur_dist = dist_to_line_segment_v2(co, a, b);
+
+ if (point == NULL || cur_dist < dist) {
+ if (tangent)
+ sub_v2_v2v2(tangent, &diff_points[2 * i + 2], &diff_points[2 * i]);
+
+ point_masklay = masklay;
+ point_spline = spline;
+ point = cur_point;
+ dist = cur_dist;
+ u = (float)i / tot_point;
+
+ }
+ }
+
+ if (feather_points)
+ MEM_freeN(feather_points);
+
+ MEM_freeN(diff_points);
+ }
+ }
+ }
+ }
+
+ if (point && dist < threshold) {
+ if (masklay_r)
+ *masklay_r = point_masklay;
+
+ if (spline_r)
+ *spline_r = point_spline;
+
+ if (point_r)
+ *point_r = point;
+
+ if (u_r) {
+ u = BKE_mask_spline_project_co(point_spline, point, u, normal_co);
+
+ *u_r = u;
+ }
+
+ return TRUE;
+ }
+
+ if (masklay_r)
+ *masklay_r = NULL;
+
+ if (spline_r)
+ *spline_r = NULL;
+
+ if (point_r)
+ *point_r = NULL;
+
+ return FALSE;
+}
+
+/******************** add vertex *********************/
+
+static void setup_vertex_point(bContext *C, Mask *mask, MaskSpline *spline, MaskSplinePoint *new_point,
+ const float point_co[2], const float tangent[2], const float u,
+ MaskSplinePoint *reference_point, const short reference_adjacent)
+{
+ MaskSplinePoint *prev_point = NULL;
+ MaskSplinePoint *next_point = NULL;
+ BezTriple *bezt;
+ int width, height;
+ float co[3];
+ const float len = 20.0; /* default length of handle in pixel space */
+
+ copy_v2_v2(co, point_co);
+ co[2] = 0.0f;
+
+ ED_mask_size(C, &width, &height);
+
+ /* point coordinate */
+ bezt = &new_point->bezt;
+
+ bezt->h1 = bezt->h2 = HD_ALIGN;
+
+ if (reference_point) {
+ bezt->h1 = bezt->h2 = MAX2(reference_point->bezt.h2, reference_point->bezt.h1);
+ }
+ else if (reference_adjacent) {
+ if (spline->tot_point != 1) {
+ int index = (int)(new_point - spline->points);
+ prev_point = &spline->points[(index - 1) % spline->tot_point];
+ next_point = &spline->points[(index + 1) % spline->tot_point];
+
+ bezt->h1 = bezt->h2 = MAX2(prev_point->bezt.h2, next_point->bezt.h1);
+
+ /* note, we may want to copy other attributes later, radius? pressure? color? */
+ }
+ }
+
+ copy_v3_v3(bezt->vec[0], co);
+ copy_v3_v3(bezt->vec[1], co);
+ copy_v3_v3(bezt->vec[2], co);
+
+ /* initial offset for handles */
+ if (spline->tot_point == 1) {
+ /* first point of splien is aligned horizontally */
+ bezt->vec[0][0] -= len / width;
+ bezt->vec[2][0] += len / width;
+ }
+ else if (tangent) {
+ float vec[2];
+
+ copy_v2_v2(vec, tangent);
+
+ vec[0] *= width;
+ vec[1] *= height;
+
+ mul_v2_fl(vec, len / len_v2(vec));
+
+ vec[0] /= width;
+ vec[1] /= height;
+
+ sub_v2_v2(bezt->vec[0], vec);
+ add_v2_v2(bezt->vec[2], vec);
+
+ if (reference_adjacent) {
+ BKE_mask_calc_handle_adjacent_interp(mask, spline, new_point, u);
+ }
+ }
+ else {
+
+ /* calculating auto handles works much nicer */
+#if 0
+ /* next points are aligning in the direction of previous/next point */
+ MaskSplinePoint *point;
+ float v1[2], v2[2], vec[2];
+ float dir = 1.0f;
+
+ if (new_point == spline->points) {
+ point = new_point + 1;
+ dir = -1.0f;
+ }
+ else
+ point = new_point - 1;
+
+ if (spline->tot_point < 3) {
+ v1[0] = point->bezt.vec[1][0] * width;
+ v1[1] = point->bezt.vec[1][1] * height;
+
+ v2[0] = new_point->bezt.vec[1][0] * width;
+ v2[1] = new_point->bezt.vec[1][1] * height;
+ }
+ else {
+ if (new_point == spline->points) {
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list