예제 #1
0
 def to_face_graph(self, val=1):
     """ Returns a Graph representation of the mesh faces by index.
         
         :param val: number of coincident points for neighborness.
         :type val: int
         :returns: A Graph of face indexes.
         :rtype: Graph
         
         ::
         
             quadmesh.to_face_graph(2)
     """ 
     from decodes.extensions.graph import Graph
     graph = Graph()
     graph.naked_nodes = []
     for f1 in range(len(self.faces)):
         for f2 in range(len(self.faces)):
             if f1 != f2:
                 count = 0
                 for index in self.faces[f2]:
                     if index in self.faces[f1]:
                         count+=1
                 if count >= val:
                     graph.add_edge(f1,f2)
         if len(graph.edges[f1]) < len(self.faces[f1]):
             if f1 not in graph.naked_nodes:
                 graph.naked_nodes.append(f1)
                                       
     return graph
예제 #2
0
    def rebuild_edges(self):
        # create a new empty graph and copy over existing nodes
        ngraph = Graph()
        # for every point in the old graph:
        for p1 in self.nodes:
            # for each of the other points nearest to this one:
            for p2 in self.nearest_to(p1):
                ngraph.add_edge(p1, p2, bidirectional=False)

        # update the nodes and edges of this proximity graph
        self.nodes = ngraph.nodes
        self.edges = ngraph.edges
예제 #3
0
    def to_pt_graph(self):
        """ Returns a Graph representation of the mesh points by index.

            :returns: A Graph of point indexes.
            :rtype: Graph
            
            ::
            
                quadmesh.to_pt_graph()
        """
        graph = Graph()
        for index in range(len(self.pts)):
            for face in self.faces:
                for px in face:
                    if index in face and index!=px: graph.add_edge(index, px)
        return graph
예제 #4
0
    def __init__(self, bds, r):

        self.r = r
        self.r_sqr = r * r
        self.cell_size = r / m.sqrt(2)
        self.dom_x, self.dom_y = bds.ival_x, bds.ival_y
        self.len_row = int(m.ceil(self.dom_x.b / self.cell_size))
        self.len_col = int(m.ceil(self.dom_y.b / self.cell_size))
        self.cells = {}
        self.graph = Graph()

        for xi in range(self.len_row):
            for yi in range(self.len_col):
                self.cells[(xi, yi)] = []

        for cell in self.cells:
            if cell[0] < self.len_row and cell[1] < self.len_col:
                self.graph.add_edge(cell, (cell[0], cell[1] + 1))
                self.graph.add_edge(cell, (cell[0] + 1, cell[1] + 1))
                self.graph.add_edge(cell, (cell[0] + 1, cell[1]))
            if 0 < cell[0]:
                self.graph.add_edge(cell, (cell[0] - 1, cell[1] + 1))