Exemplo n.º 1
0
 def containsPolyline(self, polyline):
     """
     Will return true if at least one point from the polyline is inside the block.
     """
     edge_polyline = self.getEdgePolygon()
     for p in polyline:
         if GeometryTools.pointInPolygon( p , edge_polyline ):
             return True
     return False
Exemplo n.º 2
0
 def countInside(self , polygon):
     """
     Will count the number of points in block which are inside polygon.
     """
     inside = 0
     for p in self:
         if GeometryTools.pointInPolygon( (p.x , p.y) , polygon ):
             inside += 1
     
     return inside 
Exemplo n.º 3
0
 def containsPolyline(self, polyline):
     """
     Will return true if at least one point from the polyline is inside the block.
     """
     edge_polyline = self.getEdgePolygon()
     for p in polyline:
         if GeometryTools.pointInPolygon(p, edge_polyline):
             return True
     else:
         edge_polyline.assertClosed()
         return GeometryTools.polylinesIntersect(edge_polyline, polyline)
Exemplo n.º 4
0
 def containsPolyline(self, polyline):
     """
     Will return true if at least one point from the polyline is inside the block.
     """
     edge_polyline = self.getEdgePolygon()
     for p in polyline:
         if GeometryTools.pointInPolygon( p , edge_polyline ):
             return True
     else:
         edge_polyline.assertClosed()
         return GeometryTools.polylinesIntersect( edge_polyline , polyline )
Exemplo n.º 5
0
    def splitFaultBlockClosedPolygon( grid , fault_blocks , polygon ):
        """
        Special case code when the region is limited only by one polygon.
        """
        new_fault_blocks = FaultBlockLayer( grid , fault_blocks.getK() )
        new_block = new_fault_blocks.addBlock()

        for block in fault_blocks:
            for p in block:
                if GeometryTools.pointInPolygon( (p.x , p.y) , polygon ):
                    new_block.addCell(p.i , p.j)
        
        return new_fault_blocks
Exemplo n.º 6
0
    def splitFaultBlocks(self , grid , fault_blocks ):
        boundingPolygon = Polyline(init_points = grid.getBoundingBox2D())
        boundingPolygon.assertClosed()
        if self.hasPolygon():
            if len(self.edges) == 1:
                return self.splitFaultBlockClosedPolygon( grid , fault_blocks , self.edges[0] )
            else:
                current_fault_block_layer = fault_blocks
                k = fault_blocks.getK()
                for edge in self.edges:
                    if isinstance(edge , Polyline):
                        # Start on a brand new fault block layer.
                        next_fault_block_layer = FaultBlockLayer( grid , k )
                        for block in current_fault_block_layer:
                            if block.containsPolyline(edge):
                                print "Block %d is split due to edge:%s" % (block.getBlockID() , edge.name())
                                sliced = GeometryTools.slicePolygon( boundingPolygon , edge )
                                inside_list = []
                                outside_list = []
                                for p in block:
                                    if GeometryTools.pointInPolygon( (p.x , p.y) , sliced ):
                                        inside_list.append( p )
                                    else:
                                        outside_list.append( p )

                                if len(inside_list) * len(outside_list) == 0:
                                    new_block = next_fault_block_layer.addBlock( )
                                    for p in inside_list:
                                        new_block.addCell(p.i , p.j)

                                    for p in outside_list:
                                        new_block.addCell(p.i , p.j)
                                else:
                                    layer = Layer( grid.getNX() , grid.getNY() )
                                    for p in inside_list:
                                        layer[p.i , p.j] = 1

                                    for p in outside_list:
                                        layer[p.i , p.j] = 2
                                            
                                    next_fault_block_layer.scanLayer( layer )
                            else:
                                next_fault_block_layer.insertBlockContent( block )

                        current_fault_block_layer = next_fault_block_layer
                return current_fault_block_layer
        else:
            return fault_blocks