[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [31501] branches/particles-2010/source/ blender: Implemented a filter node, which can be used to filter data sets by arbitrary criteria.

Lukas Toenne lukas.toenne at googlemail.com
Sat Aug 21 14:52:10 CEST 2010


Revision: 31501
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=31501
Author:   lukastoenne
Date:     2010-08-21 14:52:10 +0200 (Sat, 21 Aug 2010)

Log Message:
-----------
Implemented a filter node, which can be used to filter data sets by arbitrary criteria. The result of a node is the filtered if any of its inputs is filtered, i.e. the resulting data set is the intersection of the incoming data.

Modified Paths:
--------------
    branches/particles-2010/source/blender/blenkernel/BKE_node.h
    branches/particles-2010/source/blender/blenkernel/intern/node.c
    branches/particles-2010/source/blender/makesrna/intern/rna_nodetree_types.h
    branches/particles-2010/source/blender/nodes/SIM_node.h
    branches/particles-2010/source/blender/nodes/intern/SIM_nodes/SIM_set_particle_data.c
    branches/particles-2010/source/blender/nodes/intern/SIM_util.c
    branches/particles-2010/source/blender/nodes/intern/SIM_util.h
    branches/particles-2010/source/blender/nodes/intern/node_tree_simulation.c

Added Paths:
-----------
    branches/particles-2010/source/blender/nodes/intern/SIM_nodes/SIM_filter.c

Modified: branches/particles-2010/source/blender/blenkernel/BKE_node.h
===================================================================
--- branches/particles-2010/source/blender/blenkernel/BKE_node.h	2010-08-21 11:44:23 UTC (rev 31500)
+++ branches/particles-2010/source/blender/blenkernel/BKE_node.h	2010-08-21 12:52:10 UTC (rev 31501)
@@ -504,6 +504,7 @@
 #define SIM_NODE_PASS				603
 #define SIM_NODE_IF					604
 #define SIM_NODE_FOR				605
+#define SIM_NODE_FILTER				606
 
 /* scalar math */
 #define SIM_NODE_SCALAR_ADD			650

Modified: branches/particles-2010/source/blender/blenkernel/intern/node.c
===================================================================
--- branches/particles-2010/source/blender/blenkernel/intern/node.c	2010-08-21 11:44:23 UTC (rev 31500)
+++ branches/particles-2010/source/blender/blenkernel/intern/node.c	2010-08-21 12:52:10 UTC (rev 31501)
@@ -2932,6 +2932,7 @@
 	nodeRegisterType(ntypelist, &sim_node_pass);
 	nodeRegisterType(ntypelist, &sim_node_if);
 	nodeRegisterType(ntypelist, &sim_node_for);
+	nodeRegisterType(ntypelist, &sim_node_filter);
 
 	nodeRegisterType(ntypelist, &sim_node_scalar_add);
 	nodeRegisterType(ntypelist, &sim_node_scalar_subtract);

Modified: branches/particles-2010/source/blender/makesrna/intern/rna_nodetree_types.h
===================================================================
--- branches/particles-2010/source/blender/makesrna/intern/rna_nodetree_types.h	2010-08-21 11:44:23 UTC (rev 31500)
+++ branches/particles-2010/source/blender/makesrna/intern/rna_nodetree_types.h	2010-08-21 12:52:10 UTC (rev 31501)
@@ -138,6 +138,7 @@
 DefNode( SimulationNode, SIM_NODE_PASS,           0,                      "PASS",           Pass,             "Pass",              ""              )
 DefNode( SimulationNode, SIM_NODE_IF,             0,                      "IF",             If,               "If",                ""              )
 DefNode( SimulationNode, SIM_NODE_FOR,            0,                      "FOR",            For,              "For",               ""              )
+DefNode( SimulationNode, SIM_NODE_FILTER,         0,                      "FILTER",         Filter,           "Filter",            ""              )
 DefNode( SimulationNode, SIM_NODE_SCALAR_ADD,     0,                      "SCALAR_ADD",     ScalarAdd,        "Add",               ""              )
 DefNode( SimulationNode, SIM_NODE_SCALAR_SUBTRACT, 0,                     "SCALAR_SUBTRACT", ScalarSubtract,  "Subtract",          ""              )
 DefNode( SimulationNode, SIM_NODE_SCALAR_MULTIPLY, 0,                     "SCALAR_MULTIPLY", ScalarMultiply,  "Multiply",          ""              )

Modified: branches/particles-2010/source/blender/nodes/SIM_node.h
===================================================================
--- branches/particles-2010/source/blender/nodes/SIM_node.h	2010-08-21 11:44:23 UTC (rev 31500)
+++ branches/particles-2010/source/blender/nodes/SIM_node.h	2010-08-21 12:52:10 UTC (rev 31501)
@@ -42,6 +42,7 @@
 extern bNodeType sim_node_pass;
 extern bNodeType sim_node_if;
 extern bNodeType sim_node_for;
+extern bNodeType sim_node_filter;
 
 extern bNodeType sim_node_scalar_add;
 extern bNodeType sim_node_scalar_subtract;

Added: branches/particles-2010/source/blender/nodes/intern/SIM_nodes/SIM_filter.c
===================================================================
--- branches/particles-2010/source/blender/nodes/intern/SIM_nodes/SIM_filter.c	                        (rev 0)
+++ branches/particles-2010/source/blender/nodes/intern/SIM_nodes/SIM_filter.c	2010-08-21 12:52:10 UTC (rev 31501)
@@ -0,0 +1,110 @@
+/**
+* ***** 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) 2006 Blender Foundation.
+* All rights reserved.
+* 
+* The Original Code is: all of this file.
+* 
+* Contributor(s): none yet.
+* 
+* ***** END GPL LICENSE BLOCK *****
+
+*/
+
+#include "../SIM_util.h"
+
+/* **************** Select a branch based on a condition ******************** */
+/* This node implements an execution sequence.
+ * It is the central entry point for any simulation.
+ */
+
+static bNodeSocketType inputs[]= { 
+	{ SOCK_BOOL, 1, "Filter", 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f },
+	{ SOCK_ANY, 1, "In", 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f },
+	{ -1, 0, "" }
+};
+
+static bNodeSocketType outputs[]= { 
+	{ SOCK_ANY, 0, "Out", 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f },
+	{ -1, 0, "" }
+};
+
+static int exec(SimNodeThreadContext *ctx, SimNodeJob *job)
+{
+	SimNodeDataStream istream[2];
+	SimNodeDataStream ostream[1];
+	
+	switch (job->node->outputs[0].datatype) {
+	case SOCK_OP:
+		break;
+	case SOCK_INT:
+		SIM_JOBEXEC_BEGIN(ctx, job, istream, ostream);
+		if (sim_istream_read_bool(istream, 0))
+			sim_ostream_filter(ostream, 0);
+		else
+			sim_ostream_write_int(ostream, 0, sim_istream_read_int(istream, 1));
+		SIM_JOBEXEC_END(ctx, job)
+		break;
+	case SOCK_BOOL:
+		SIM_JOBEXEC_BEGIN(ctx, job, istream, ostream);
+		if (sim_istream_read_bool(istream, 0))
+			sim_ostream_filter(ostream, 0);
+		else
+			sim_ostream_write_bool(ostream, 0, sim_istream_read_bool(istream, 1));
+		SIM_JOBEXEC_END(ctx, job)
+		break;
+	case SOCK_VECTOR:
+		SIM_JOBEXEC_BEGIN(ctx, job, istream, ostream);
+		if (sim_istream_read_bool(istream, 0))
+			sim_ostream_filter(ostream, 0);
+		else
+			sim_ostream_write_vector(ostream, 0, sim_istream_read_vector(istream, 1));
+		SIM_JOBEXEC_END(ctx, job)
+		break;
+	case SOCK_RGBA:
+		SIM_JOBEXEC_BEGIN(ctx, job, istream, ostream);
+		if (sim_istream_read_bool(istream, 0))
+			sim_ostream_filter(ostream, 0);
+		else
+			sim_ostream_write_rgba(ostream, 0, sim_istream_read_rgba(istream, 1));
+		SIM_JOBEXEC_END(ctx, job)
+		break;
+	}
+	return NODE_EXEC_FINISHED;
+}
+
+bNodeType sim_node_filter= {
+	/* *next,*prev     */	NULL, NULL,
+	/* type code       */	SIM_NODE_FILTER,
+	/* name            */	"Filter",
+	/* width+range     */	140, 100, 320,
+	/* class+opts      */	NODE_CLASS_SIMULATION, 0,
+	/* input sock      */	inputs,
+	/* output sock     */	outputs,
+	/* storage         */	"",
+	/* execfunc        */	NULL,
+	/* butfunc         */	NULL,
+	/* initfunc        */	NULL,
+	/* freestoragefunc */	NULL,
+	/* copysotragefunc */	NULL,
+	/* id              */	NULL,
+	/* pynode, pydict  */	NULL, NULL,
+	/* gpufunc         */	NULL,
+	/* sim_exec        */	exec,
+	/* sim_opexec      */	NULL
+};

Modified: branches/particles-2010/source/blender/nodes/intern/SIM_nodes/SIM_set_particle_data.c
===================================================================
--- branches/particles-2010/source/blender/nodes/intern/SIM_nodes/SIM_set_particle_data.c	2010-08-21 11:44:23 UTC (rev 31500)
+++ branches/particles-2010/source/blender/nodes/intern/SIM_nodes/SIM_set_particle_data.c	2010-08-21 12:52:10 UTC (rev 31501)
@@ -80,6 +80,8 @@
 		if (propinit)
 			*(char*)pset_parprop(pit.pa, propinit) = sim_istream_read_bool(istream, 4);
 		pit_next(&pit);
+		SIM_JOBEXEC_OUTPUT_FILTERED
+		pit_next(&pit);
 		SIM_JOBEXEC_OUTPUT_END(ctx, job)
 	}
 	return NODE_EXEC_FINISHED;

Modified: branches/particles-2010/source/blender/nodes/intern/SIM_util.c
===================================================================
--- branches/particles-2010/source/blender/nodes/intern/SIM_util.c	2010-08-21 11:44:23 UTC (rev 31500)
+++ branches/particles-2010/source/blender/nodes/intern/SIM_util.c	2010-08-21 12:52:10 UTC (rev 31501)
@@ -450,6 +450,21 @@
 	*stream->filter = 1;
 }
 
+void sim_ostream_filter_all(SimNodeDataStream *stream)
+{
+	int i, total=stream->total;
+	for (i=0; i < total; ++i, ++stream) {
+		if (stream->filter == NULL) {
+			int k;
+			stream->batch->filter = MEM_callocN(stream->batch->totdata * sizeof(char), "SimNodeBatch filter");
+			/* if no filter existed before, all values up to current are unfiltered */
+			for (k=0, stream->filter=stream->batch->filter; k < stream->current; ++k, ++stream->filter)
+				*stream->filter = 0;
+		}
+		*stream->filter = 1;
+	}
+}
+
 void sim_ostream_write_float(SimNodeDataStream *stream, int sock, float value)
 {
 	stream += sock;

Modified: branches/particles-2010/source/blender/nodes/intern/SIM_util.h
===================================================================
--- branches/particles-2010/source/blender/nodes/intern/SIM_util.h	2010-08-21 11:44:23 UTC (rev 31500)
+++ branches/particles-2010/source/blender/nodes/intern/SIM_util.h	2010-08-21 12:52:10 UTC (rev 31501)
@@ -175,6 +175,7 @@
 int sim_ostream_next(struct SimNodeDataStream *stream);
 int sim_ostream_isvalid(struct SimNodeDataStream *stream);
 void sim_ostream_filter(struct SimNodeDataStream *stream, int sock);
+void sim_ostream_filter_all(struct SimNodeDataStream *stream);
 void sim_ostream_write_float(struct SimNodeDataStream *stream, int sock, float value);
 void sim_ostream_write_int(struct SimNodeDataStream *stream, int sock, int value);
 void sim_ostream_write_bool(struct SimNodeDataStream *stream, int sock, char value);
@@ -182,7 +183,7 @@
 void sim_ostream_write_rgba(struct SimNodeDataStream *stream, int sock, float *value);
 
 
-#if 0
+#if 1
 #define SIM_JOBEXEC_DEBUGPRINT \
 	if (i == 0) printf("-> Node %s: %d", job->node->node->name, job->current); \
 	else if (i < 3) printf(", %d", job->current); \
@@ -203,9 +204,11 @@
 	ovalid = sim_ostream_init(ostream, ctx, job, job->current); \
 	for (i=0; ivalid && ovalid && i < job->input_totdata; ++i, ++job->current) { \
 		SIM_JOBEXEC_DEBUGPRINT \
-		{
+		if (!sim_istream_isfiltered(istream)) {
 #define SIM_JOBEXEC_END(ctx, job) \
 		} \
+		else \
+			sim_ostream_filter_all(ostream); \
 		ivalid = sim_istream_next(istream); \
 		ovalid = sim_ostream_next(ostream); \
 	} \
@@ -239,7 +242,10 @@
 	valid = (sim_istream_init(istream, ctx, job)); \

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list