"""@package Primitive
This module provides an abstraction of the relationGraph using networkX

"""

import networkx as nx
import packages.primitive as primitive

class RelationGraph(object):
    def __init__(self,primArray, assignArray):
        self.G=nx.Graph()
        
        # First create the nodes
        for p in primArray:
            self.G.add_node(p.uid, w=0)
        
        # Then their relations
        for idx1, p1 in enumerate(primArray):
            for idx2, p2 in enumerate(primArray):
                if (idx2 > idx1):           
                    self.G.add_edge(p1.uid, p2.uid)
        
        # And finaly the node weights (number of samples)
        # assignArray[][0] = point id
        # assignArray[][1] = primitive uid
        for a in assignArray:
            if a[1] in self.G.node:
                self.G.node[a[1]]['w'] += 1
                    
        #print "Number of primitives:  ",self.G.number_of_nodes()
        #print "Number of connections: ",self.G.number_of_edges()
        
    def draw(self):
        nx.draw_spectral(self.G)
        #nx.draw_networkx_labels(self.G,pos=nx.spectral_layout(self.G))

@@ -257,16 +257,51 @@
 Graph()%0A
+        self.indexedPrimArray = %7B%7D%0A
         
@@ -402,16 +402,61 @@
 d, w=0)%0A
+            self.indexedPrimArray%5Bp.uid%5D = p%0A
         
@@ -1096,24 +1096,256 @@
 ()%0A        %0A
+    # Call the functor over the primitives connected by and edge%0A    def processConnectedNodes(self, functor):%0A        for e in self.G.edges():%0A            functor( self.indexedPrimArray%5Be%5B0%5D%5D, self.indexedPrimArray%5Be%5B1%5D%5D)%0A        %0A
     def draw

Add add function taking a functor as input to process connected primitives