Node based architecture

King animator333 at gmail.com
Mon Jul 12 14:08:50 EDT 2010


Hi,

I am planning to build a generic node based framework using python. I
would start with a simple image editing application. I hope that
experienced users understands what am I trying to say here. In simple
words:

LoaderNode : Load Image from disk
OperatorNode : Performs a specific task on data and spit output(data)
OutputNode : Get the data from OperatorNode(output) and writes image
to disk.
Graph : A collection Nodes that are inter connected.

The question is how to process graph?

Here is a simple representation:

class Integer(object):
    """ A simple integer node. """
    def __init__(self, value=0):
        self.value = value

    def output(self):
        return self.value

class OperatorAdd(object):
    """ A simple operator node """
    def __init__(self, integerInst1=None, integerInst2=None):
        self.a = integerInst1.output()
        self.b = integerInst2.output()

    def compute(self):
        return Integer(self.a + self.b)

    def output(self):
        return self.compute()

"Integer" is data node and "OperatorAdd" is a compute node. Imagine I
have created two integer nodes and their output is going to
"OperatorNode". One way to solve is to represent every node using a
string and then you can write these series of string which actually is
a python code that you can execute and get the result.

Example:
compute = """
i1 = Integer(2)
i2 = Integer(3)
i3 = OperatorAdd(i1, i2).output()
"""

Now you can execute "compute" variable using exec(compute) or
something like that.

This would do the job but I would like to know the opinion of more
experienced users. One advantage of above mentioned string method is
that it can be saved to disk and later you can load/compute it again.

Cheers

Prashant



More information about the Python-list mailing list