[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [47893] trunk/blender/source/blender: Keying Screen node from tomato branch

Sergey Sharybin sergey.vfx at gmail.com
Thu Jun 14 14:18:49 CEST 2012


Revision: 47893
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=47893
Author:   nazgul
Date:     2012-06-14 12:18:42 +0000 (Thu, 14 Jun 2012)
Log Message:
-----------
Keying Screen node from tomato branch

Merge Keying Screen node developed in tomato branch into trunk.

This node is aimed to make dealing with non-even greenscreens better
by generating gradiented image which could be used a input for keyer
nodes.

Based on building voronoi diagram using motion tracking markers as
sites position and average pattern color as color for that site.

Pretty straignforward node, some documentation is there
http://wiki.blender.org/index.php/User:Nazg-gul/Keying#Screen_color

Modified Paths:
--------------
    trunk/blender/source/blender/blenkernel/BKE_node.h
    trunk/blender/source/blender/blenkernel/intern/node.c
    trunk/blender/source/blender/blenlib/CMakeLists.txt
    trunk/blender/source/blender/compositor/CMakeLists.txt
    trunk/blender/source/blender/compositor/intern/COM_Converter.cpp
    trunk/blender/source/blender/editors/space_node/drawnode.c
    trunk/blender/source/blender/makesdna/DNA_node_types.h
    trunk/blender/source/blender/makesrna/intern/rna_nodetree.c
    trunk/blender/source/blender/makesrna/intern/rna_nodetree_types.h
    trunk/blender/source/blender/nodes/CMakeLists.txt
    trunk/blender/source/blender/nodes/NOD_composite.h

Added Paths:
-----------
    trunk/blender/source/blender/blenlib/BLI_voronoi.h
    trunk/blender/source/blender/blenlib/intern/voronoi.c
    trunk/blender/source/blender/compositor/nodes/COM_KeyingScreenNode.cpp
    trunk/blender/source/blender/compositor/nodes/COM_KeyingScreenNode.h
    trunk/blender/source/blender/compositor/operations/COM_KeyingScreenOperation.cpp
    trunk/blender/source/blender/compositor/operations/COM_KeyingScreenOperation.h
    trunk/blender/source/blender/nodes/composite/nodes/node_composite_keyingscreen.c

Modified: trunk/blender/source/blender/blenkernel/BKE_node.h
===================================================================
--- trunk/blender/source/blender/blenkernel/BKE_node.h	2012-06-14 12:05:38 UTC (rev 47892)
+++ trunk/blender/source/blender/blenkernel/BKE_node.h	2012-06-14 12:18:42 UTC (rev 47893)
@@ -658,6 +658,7 @@
 #define CMP_NODE_DOUBLEEDGEMASK    266
 #define CMP_NODE_OUTPUT_MULTI_FILE__DEPRECATED	267	/* DEPRECATED multi file node has been merged into regular CMP_NODE_OUTPUT_FILE */
 #define CMP_NODE_MASK		268
+#define CMP_NODE_KEYINGSCREEN		269
 
 #define CMP_NODE_GLARE		301
 #define CMP_NODE_TONEMAP	302

Modified: trunk/blender/source/blender/blenkernel/intern/node.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/node.c	2012-06-14 12:05:38 UTC (rev 47892)
+++ trunk/blender/source/blender/blenkernel/intern/node.c	2012-06-14 12:18:42 UTC (rev 47893)
@@ -1900,6 +1900,7 @@
 	register_node_type_cmp_color_spill(ttype);
 	register_node_type_cmp_luma_matte(ttype);
 	register_node_type_cmp_doubleedgemask(ttype);
+	register_node_type_cmp_keyingscreen(ttype);
 
 	register_node_type_cmp_translate(ttype);
 	register_node_type_cmp_rotate(ttype);

Added: trunk/blender/source/blender/blenlib/BLI_voronoi.h
===================================================================
--- trunk/blender/source/blender/blenlib/BLI_voronoi.h	                        (rev 0)
+++ trunk/blender/source/blender/blenlib/BLI_voronoi.h	2012-06-14 12:18:42 UTC (rev 47893)
@@ -0,0 +1,70 @@
+/*
+ * ***** 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): Sergey Sharybin
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+#ifndef __BLI_VORONOI_H__
+#define __BLI_VORONOI_H__
+
+struct ListBase;
+
+/** \file BLI_voronoi.h
+ *  \ingroup bli
+ */
+
+typedef struct VoronoiSite {
+	float co[2];
+	float color[3];
+} VoronoiSite;
+
+typedef struct VoronoiEdge {
+	struct VoronoiEdge *next, *prev;
+
+	float start[2], end[2];	/* start and end points */
+
+	/* this fields are used during diagram computation only */
+
+	float direction[2];		/* directional vector, from "start", points to "end", normal of |left, right| */
+
+	float left[2];			/* point on Voronoi place on the left side of edge */
+	float right[2];			/* point on Voronoi place on the right side of edge */
+
+	float f, g;				/* directional coeffitients satisfying equation y = f*x + g (edge lies on this line) */
+
+	/* some edges consist of two parts, so we add the pointer to another part to connect them at the end of an algorithm */
+	struct VoronoiEdge *neighbour;
+} VoronoiEdge;
+
+typedef struct VoronoiTriangulationPoint {
+	float co[2];
+	float color[3];
+	int power;
+} VoronoiTriangulationPoint;
+
+void BLI_voronoi_compute(const VoronoiSite *sites, int sites_total, int width, int height, struct ListBase *edges);
+
+void BLI_voronoi_triangulate(const VoronoiSite *sites, int sites_total, struct ListBase *edges, int width, int height,
+                             VoronoiTriangulationPoint **triangulated_points_r, int *triangulated_points_total_r,
+                             int (**triangles_r)[3], int *triangles_total_r);
+
+#endif /* __BLI_VORONOI_H__ */

Modified: trunk/blender/source/blender/blenlib/CMakeLists.txt
===================================================================
--- trunk/blender/source/blender/blenlib/CMakeLists.txt	2012-06-14 12:05:38 UTC (rev 47892)
+++ trunk/blender/source/blender/blenlib/CMakeLists.txt	2012-06-14 12:18:42 UTC (rev 47893)
@@ -89,6 +89,7 @@
 	intern/time.c
 	intern/uvproject.c
 	intern/voxel.c
+	intern/voronoi.c
 	intern/winstuff.c
 
 	BLI_args.h

Added: trunk/blender/source/blender/blenlib/intern/voronoi.c
===================================================================
--- trunk/blender/source/blender/blenlib/intern/voronoi.c	                        (rev 0)
+++ trunk/blender/source/blender/blenlib/intern/voronoi.c	2012-06-14 12:18:42 UTC (rev 47893)
@@ -0,0 +1,833 @@
+/*
+ * ***** 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): Sergey Sharybin
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/*
+ * Fortune's algorithm implemented using explanation and some code snippets from
+ * http://blog.ivank.net/fortunes-algorithm-and-implementation.html
+ */
+
+/** \file blender/blenkernel/intern/tracking.c
+ *  \ingroup bli
+ */
+
+#include "MEM_guardedalloc.h"
+
+#include "BLI_listbase.h"
+#include "BLI_math.h"
+#include "BLI_voronoi.h"
+#include "BLI_utildefines.h"
+
+#define VORONOI_EPS 1e-3
+
+enum {
+	voronoiEventType_Site = 0,
+	voronoiEventType_Circle = 1
+} voronoiEventType;
+
+typedef struct VoronoiEvent {
+	struct VoronoiEvent *next, *prev;
+
+	int type;		/* type of event (site or circle) */
+	float site[2];	/* site for which event was generated */
+
+	struct VoronoiParabola *parabola;	/* parabola for which event was generated */
+} VoronoiEvent;
+
+typedef struct VoronoiParabola {
+	struct VoronoiParabola *left, *right, *parent;
+	VoronoiEvent *event;
+	int is_leaf;
+	float site[2];
+	VoronoiEdge *edge;
+} VoronoiParabola;
+
+typedef struct VoronoiProcess {
+	ListBase queue, edges;
+	VoronoiParabola *root;
+	int width, height;
+	float current_y;
+} VoronoiProcess;
+
+/* event */
+
+static void voronoi_insertEvent(VoronoiProcess *process, VoronoiEvent *event)
+{
+	VoronoiEvent *current_event = process->queue.first;
+
+	while (current_event) {
+		if (current_event->site[1] < event->site[1]) {
+			break;
+		}
+		if (current_event->site[1] == event->site[1]) {
+			event->site[1] -= VORONOI_EPS;
+		}
+
+		current_event = current_event->next;
+	}
+
+	BLI_insertlinkbefore(&process->queue, current_event, event);
+}
+
+/* edge */
+static VoronoiEdge *voronoiEdge_new(float start[2], float left[2], float right[2])
+{
+	VoronoiEdge *edge = MEM_callocN(sizeof(VoronoiEdge), "voronoi edge");
+
+	copy_v2_v2(edge->start, start);
+	copy_v2_v2(edge->left, left);
+	copy_v2_v2(edge->right, right);
+
+	edge->neighbour = NULL;
+	edge->end[0] = 0;
+	edge->end[1] = 0;
+
+	edge->f = (right[0] - left[0]) / (left[1] - right[1]);
+	edge->g = start[1] - edge->f * start[0];
+
+	edge->direction[0] = right[1] - left[1];
+	edge->direction[1] = -(right[0] - left[0]);
+
+	return edge;
+}
+
+/* parabola */
+
+static VoronoiParabola *voronoiParabola_new(void)
+{
+	VoronoiParabola *parabola = MEM_callocN(sizeof(VoronoiParabola), "voronoi parabola");
+
+	parabola->is_leaf = FALSE;
+	parabola->event = NULL;
+	parabola->edge = NULL;
+	parabola->parent = 0;
+
+	return parabola;
+}
+
+static VoronoiParabola *voronoiParabola_newSite(float site[2])
+{
+	VoronoiParabola *parabola = MEM_callocN(sizeof(VoronoiParabola), "voronoi parabola site");
+
+	copy_v2_v2(parabola->site, site);
+	parabola->is_leaf = TRUE;
+	parabola->event = NULL;
+	parabola->edge = NULL;
+	parabola->parent = 0;
+
+	return parabola;
+}
+
+/* returns the closest leave which is on the left of current node */
+static VoronoiParabola *voronoiParabola_getLeftChild(VoronoiParabola *parabola)
+{
+	VoronoiParabola *current_parabola;
+
+	if (!parabola)
+		return NULL;
+
+	current_parabola = parabola->left;
+	while (!current_parabola->is_leaf) {
+		current_parabola = current_parabola->right;
+	}
+
+	return current_parabola;
+}
+
+/* returns the closest leave which is on the right of current node */
+static VoronoiParabola *voronoiParabola_getRightChild(VoronoiParabola *parabola)
+{
+	VoronoiParabola *current_parabola;
+
+	if (!parabola)
+		return NULL;
+
+	current_parabola = parabola->right;
+	while (!current_parabola->is_leaf) {
+		current_parabola = current_parabola->left;
+	}
+
+	return current_parabola;
+}
+
+/* returns the closest parent which is on the left */
+static VoronoiParabola *voronoiParabola_getLeftParent(VoronoiParabola *parabola)
+{
+	VoronoiParabola *current_par = parabola->parent;
+	VoronoiParabola *last_parabola = parabola;
+
+	while (current_par->left == last_parabola) {
+		if (!current_par->parent)
+			return NULL;
+
+		last_parabola = current_par;
+		current_par = current_par->parent;
+	}
+
+	return current_par;
+}
+
+/* returns the closest parent which is on the right */
+static VoronoiParabola *voronoiParabola_getRightParent(VoronoiParabola *parabola)
+{
+	VoronoiParabola *current_parabola = parabola->parent;
+	VoronoiParabola *last_parabola = parabola;
+
+	while (current_parabola->right == last_parabola) {
+		if (!current_parabola->parent)
+			return NULL;
+
+		last_parabola = current_parabola;
+		current_parabola = current_parabola->parent;
+	}
+
+	return current_parabola;
+}
+
+static void voronoiParabola_setLeft(VoronoiParabola *parabola, VoronoiParabola *left)
+{
+	parabola->left = left;
+	left->parent = parabola;
+}
+
+static void voronoiParabola_setRight(VoronoiParabola *parabola, VoronoiParabola *right)
+{
+	parabola->right = right;
+	right->parent = parabola;
+}
+
+static float voronoi_getY(VoronoiProcess *process, float p[2], float x)
+{

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list