def testregion_with_maxarea(self):

        points = []
        seglist = []
        holelist = []
        regionlist = [(3, 1, 1.0)]

        points = [(0.0, 0.0), (6.0, 0.0), (6.0, 6.0), (0.0, 6.0)]
        pointattlist = [[], [], [], []]
        seglist = [(0, 1), (1, 2), (3, 2), (3, 0), (0, 2)]
        segattlist = [0, 0, 0, 0, 0]

        mode = "Qzpna36a"
        data = generate_mesh(points, seglist, holelist, regionlist,
                             pointattlist, segattlist, mode, points)

        self.assertTrue(
            len(data['generatedtrianglelist']) == 2,
            'testregion_with_maxarea 1: # of tris is wrong!')
        # Another test case
        regionlist = [(3, 1, 1.0), (1, 3, 1.0, 8.0)]
        mode = "Qzp21na36a"
        data = generate_mesh(points, seglist, holelist, regionlist,
                             pointattlist, segattlist, mode, points)
        # print "len(data['generatedtrianglelist']",len(data['generatedtrianglelist'])
        # for Duncan On unix this returns a 7 triangle result.
        # for Duncan on Windows returns a 6 triangle result.
        # for Ole on nautilus this returns 6
        # for Duncan on nautilus this returns 7
        # It seems to be the results from triangle that is
        # causing the different results, and we are treating
        # triangle as a back box.

        self.assertTrue(
            len(data['generatedtrianglelist']) >= 6,
            'testregion_with_maxarea 2: # of tris is wrong!')
        # Another test case
        regionlist = [(3, 1, 1.0, 8.0), (1, 3, 1.0, 8.0)]
        mode = "Qzpna36a"
        data = generate_mesh(points, seglist, holelist, regionlist,
                             pointattlist, segattlist, mode, points)
        # print "len(data['generatedtrianglelist']",len(data['generatedtrianglelist'])
        # On unix this returns a 10 triangle result.
        # Windows returns a 8 triangle result.
        self.assertTrue(
            len(data['generatedtrianglelist']) >= 8,
            'testregion_with_maxarea 3: # of tris is wrong!')

        # Another test case
        regionlist = [(3, 1, 1.0), (1, 3, 1.0, 8.0)]
        mode = "Qzpna8a"
        data = generate_mesh(points, seglist, holelist, regionlist,
                             pointattlist, segattlist, mode, points)
        # print "len(data['generatedtrianglelist']",len(data['generatedtrianglelist'])
        # On unix this returns a 10 triangle result.
        # Windows returns a 8 triangle result.

        self.assertTrue(
            len(data['generatedtrianglelist']) >= 8,
            'testregion_with_maxarea 4: # of tris is wrong!')
    def testregion_with_maxarea(self):

        points = []
        seglist = []
        holelist = []
        regionlist = [(3,1,1.0)]

        points = [(0.0,0.0),(6.0,0.0),(6.0,6.0),(0.0,6.0)]
        pointattlist = [[],[],[],[]]
        seglist = [(0,1),(1,2),(3,2),(3,0),(0,2)]
        segattlist = [0,0,0,0,0]
        
        mode = "Qzpna36a"
        data = generate_mesh(points,seglist,holelist,regionlist,
                              pointattlist,segattlist,  mode, points)

        self.assertTrue(len(data['generatedtrianglelist']) == 2,
                        'testregion_with_maxarea 1: # of tris is wrong!')
        ## Another test case
        regionlist = [(3,1,1.0),(1,3,1.0,8.0)]
        mode = "Qzp21na36a"
        data = generate_mesh(points,seglist,holelist,regionlist,
                              pointattlist,segattlist,  mode, points)
        #print "len(data['generatedtrianglelist']",len(data['generatedtrianglelist'])
        # for Duncan On unix this returns a 7 triangle result.
        # for Duncan on Windows returns a 6 triangle result.
        # for Ole on nautilus this returns 6
        # for Duncan on nautilus this returns 7
        # It seems to be the results from triangle that is
        # causing the different results, and we are treating
        # triangle as a back box.

        self.assertTrue(len(data['generatedtrianglelist']) >= 6,
                        'testregion_with_maxarea 2: # of tris is wrong!')
        ## Another test case
        regionlist = [(3,1,1.0,8.0),(1,3,1.0,8.0)]
        mode = "Qzpna36a"
        data = generate_mesh(points,seglist,holelist,regionlist,
                              pointattlist,segattlist,  mode, points)
        #print "len(data['generatedtrianglelist']",len(data['generatedtrianglelist'])
        # On unix this returns a 10 triangle result.
        # Windows returns a 8 triangle result.
        self.assertTrue(len(data['generatedtrianglelist']) >= 8,
                        'testregion_with_maxarea 3: # of tris is wrong!')

        ## Another test case
        regionlist = [(3,1,1.0),(1,3,1.0,8.0)]
        mode = "Qzpna8a"
        data = generate_mesh(points,seglist,holelist,regionlist,
                              pointattlist,segattlist,  mode, points)
        #print "len(data['generatedtrianglelist']",len(data['generatedtrianglelist'])
        # On unix this returns a 10 triangle result.
        # Windows returns a 8 triangle result.

        self.assertTrue(len(data['generatedtrianglelist']) >= 8,
                        'testregion_with_maxarea 4: # of tris is wrong!')
Ejemplo n.º 3
0
    def testrectangleIIc(self):
        points = []
        seglist = []
        holelist = []
        regionlist = []

        points = [(0.0,0.0),(0.0,10.0),(3.0,0.0),(3.0,10.0)]
        pointattlist = None
        regionlist.append( (1.2,1.2,5.0) )
        seglist = [(0,1),(1,3),(3,2),(2,0)]
        segattlist = None
        
        mode = "Qzp"
        
        data = generate_mesh(points,seglist,holelist,regionlist,
                              pointattlist,segattlist, mode, points)
        correct = num.array([(1, 0, 2), (2, 3, 1)])
        self.assertTrue(num.alltrue(data['generatedtrianglelist'].flat == \
                                    correct.flat),
                        'trianglelist is wrong!')
        correct = num.array([(0, 1), (1, 3), (3, 2), (2, 0)])
        self.assertTrue(num.alltrue(data['generatedsegmentlist'].flat == \
                                    correct.flat),
                        'segmentlist is wrong!')

        correct = num.array([(0.0, 0.0), (0.0, 10.0),
                             (3.0, 0.0), (3.0, 10.0)])
        self.assertTrue(num.allclose(data['generatedpointlist'].flat, \
                                     correct.flat),
                        'Failed')
Ejemplo n.º 4
0
    def testsegmarker(self):

        holelist = []
        regionlist = []

        points = [(0.0,0.0),(0.0,10.0),(3.0,0.0),(3.0,10.0)]
        pointattlist = [[],[],[],[]]
        regionlist.append( (1.2,1.2,5.0) )
        seglist = [(0,1),(1,3),(3,2),(2,0)]
        segattlist = [1.0,2.0,3.0,4.0]
        
        mode = "Qzp"
        data = generate_mesh(points,seglist,holelist,regionlist,
                              pointattlist,segattlist, mode, points)

        correct = num.array([(1, 0, 2), (2, 3, 1)])
        self.assertTrue(num.alltrue(data['generatedtrianglelist'].flat == \
                                    correct.flat),
                        'trianglelist is wrong!')
        correct = num.array([(0, 1), (1, 3), (3, 2), (2, 0)])
        self.assertTrue(num.alltrue(data['generatedsegmentlist'].flat == \
                                    correct.flat),
                        'segmentlist is wrong!')

        correct = num.array([(0.0, 0.0), (0.0, 10.0),
                             (3.0, 0.0), (3.0, 10.0)])
        self.assertTrue(num.allclose(data['generatedpointlist'].flat, \
                                     correct.flat),
                        'Failed')
        
        self.assertTrue(num.alltrue(data['generatedsegmentmarkerlist'] == \
                                    num.array([1,2,3,4])),
                        'Failed!')
    def test_numeric_arrays(self):
        points = []
        seglist = []
        holelist = []
        regionlist = []
        points = [(0.0, 0.0), (0.0, 10.0), (3.0, 0.0), (3.0, 10.0)]
        pointattlist = []
        # 5.0 is the region tag, 99.0 is the max area
        tri_tag = 123456.0
        regionlist.append([0.2, 0.2, tri_tag, 99.0])
        seglist = [(0, 1), (1, 3), (3, 2), (2, 0)]
        segattlist = [21, 22, 23, 24]
        # The 'A' has to be there to get the region marker stuff working
        mode = "QzpnA"
        #mode = "jQpznAa2000.1a"

        #print('mode', mode)
        data = generate_mesh(points, seglist, holelist, regionlist,
                             pointattlist, segattlist, mode, points)
        #print("data", data)

        correct = num.array([(1, 0, 2), (2, 3, 1)])
        self.assertTrue(
            num.alltrue(data['generatedtrianglelist'].flat == correct.flat),
            'trianglelist is wrong!')
        correct = num.array([(0, 1), (1, 3), (3, 2), (2, 0)])
        self.assertTrue(
            num.alltrue(data['generatedsegmentlist'].flat == correct.flat),
            'segmentlist is wrong!')

        correct = num.array([(0.0, 0.0), (0.0, 10.0), (3.0, 0.0), (3.0, 10.0)])
        self.assertTrue(
            num.allclose(data['generatedpointlist'].flat, correct.flat),
            'Failed')

        correct = num.array([[tri_tag], [tri_tag]])
        self.assertTrue(
            num.allclose(data['generatedtriangleattributelist'].flat,
                         correct.flat), 'Failed')
        correct = num.array([(0, 1), (1, 3), (3, 2), (2, 0)])
        self.assertTrue(
            num.alltrue(data['generatedsegmentlist'].flat == correct.flat),
            'Failed!')

        correct = num.array(segattlist, num.int)
        self.assertTrue(
            num.allclose(data['generatedsegmentmarkerlist'].flat,
                         correct.flat), 'Failed')

        # I copied these answers from the output, so bad test..
        correct = num.array([(-1, 1, -1), (-1, 0, -1)])
        self.assertTrue(
            num.alltrue(
                data['generatedtriangleneighborlist'].flat == correct.flat),
            'Failed!')
    def test_numeric_arrays(self):
        points = []
        seglist = []
        holelist = []
        regionlist = []
        points = [(0.0,0.0),(0.0,10.0),(3.0,0.0),(3.0,10.0)]
        pointattlist = []
        # 5.0 is the region tag, 99.0 is the max area
        tri_tag = 123456.0
        regionlist.append( [0.2,0.2, tri_tag,99.0] )
        seglist = [(0,1),(1,3),(3,2),(2,0)]
        segattlist = [21,22,23,24]
         #The 'A' has to be there to get the region marker stuff working
        mode = "QzpnA"
        #mode = "jQpznAa2000.1a"
        data = generate_mesh(points,seglist,holelist,regionlist,
                              pointattlist,segattlist, mode, points)
        #print "data", data

     
        correct = num.array([(1, 0, 2), (2, 3, 1)])
        self.assertTrue(num.alltrue(data['generatedtrianglelist'].flat == \
                                    correct.flat),
                        'trianglelist is wrong!')
        correct = num.array([(0, 1), (1, 3), (3, 2), (2, 0)])
        self.assertTrue(num.alltrue(data['generatedsegmentlist'].flat == \
                                    correct.flat),
                        'segmentlist is wrong!')

        correct = num.array([(0.0, 0.0), (0.0, 10.0),
                             (3.0, 0.0), (3.0, 10.0)])
        self.assertTrue(num.allclose(data['generatedpointlist'].flat, \
                                     correct.flat),
                        'Failed')
        
        correct = num.array([[tri_tag], [tri_tag]])
        self.assertTrue(num.allclose(data['generatedtriangleattributelist'].flat, \
                                     correct.flat),
                        'Failed')
        correct = num.array([(0, 1), (1, 3), (3, 2), (2, 0)])
        self.assertTrue(num.alltrue(data['generatedsegmentlist'].flat == \
                                    correct.flat),
                        'Failed!')
        
        correct = num.array(segattlist, num.int)
        self.assertTrue(num.allclose(data['generatedsegmentmarkerlist'].flat, 
                                     correct.flat),
                        'Failed')
        
        # I copied these answers from the output, so bad test..
        correct = num.array([(-1, 1, -1), (-1, 0, -1)])
        self.assertTrue(num.alltrue(data['generatedtriangleneighborlist'].flat == \
                                    correct.flat),
                        'Failed!')
Ejemplo n.º 7
0
    def test_pointattlist(self):
        # segattlist = []
        points = []
        seglist = []
        holelist = []
        regionlist = []

        points = [(0.0,0.0),(0.0,4.0),(4.0,2.0),(2.0,0.0)]
        pointattlist = [0.,0.,10.,10.]
        regionlist.append( [0.2,0.2,2.1, 99.] )
        seglist = [(0,1),(1,2),(2,3),(3,0)]
        segattlist = [11,12,13,14]
        mode = "Qzp"
        data = generate_mesh(points,seglist,holelist,regionlist,
                              pointattlist,segattlist, mode, points)

        correct = num.array([[0.0],[0.0],[10],[10]])
        self.assertTrue(num.allclose(data['generatedpointattributelist'].flat, \
                                     correct.flat),
                        'Failed')
        
        pointattlist = [[0.],[0.],[10.],[10.]]
        mode = "Qzp"        
        data = generate_mesh(points,seglist,holelist,regionlist,
                              pointattlist,segattlist, mode, points)
        correct = num.array([[0.0],[0.0],[10],[10]])
        self.assertTrue(num.allclose(data['generatedpointattributelist'].flat, \
                                     correct.flat),
                        'Failed')
        
        pointattlist = [[0.,1],[0.,1],[10.,20],[10.,20]]
        mode = "Qzp"        
        data = generate_mesh(points,seglist,holelist,regionlist,
                              pointattlist,segattlist, mode, points)
        #print "data", data
        correct = num.array(pointattlist)
        self.assertTrue(num.allclose(data['generatedpointattributelist'].flat, \
                                     correct.flat),
                        'Failed')
Ejemplo n.º 8
0
    def _alpha_shape_algorithm(self, alpha=None):
        """
        Given a set of points (self.points) and an optional alpha value
        determines the alpha shape boundary (stored in self.boundary,
        accessed by get_boundary).
        
        Inputs:
          alpha: The alpha value can be optionally specified.  If it is
          not specified the optimum alpha value will be used.
        """

        self.alpha = alpha

        ## Build Delaunay triangulation
        from anuga.mesh_engine.mesh_engine import generate_mesh
        points = []
        seglist = []
        holelist = []
        regionlist = []
        pointattlist = []
        segattlist = []

        points = [(pt[0], pt[1]) for pt in self.points]
        pointattlist = [[] for i in range(len(points))]
        mode = "Qzcn"
        tridata = generate_mesh(points, seglist, holelist, regionlist,
                                pointattlist, segattlist, mode)
        self.deltri = tridata['generatedtrianglelist']
        self.deltrinbr = tridata['generatedtriangleneighborlist']
        self.hulledges = tridata['generatedsegmentlist']

        ## Build Alpha table
        ## the following routines determine alpha thresholds for the
        ## triangles, edges, and vertices of the delaunay triangulation
        self._tri_circumradius()
        self._edge_intervals()
        self._vertex_intervals()

        if alpha == None:
            # Find optimum alpha
            # Ken Clarkson's hull program uses smallest alpha so that
            # every vertex is non-singular so...
            self.optimum_alpha = max([iv[0] for iv in self.vertexinterval \
                                      if iv!=[] ])
            alpha = self.optimum_alpha
        self.alpha = alpha
        reg_edge = self.get_regular_edges(self.alpha)
        self.boundary = [self.edge[k] for k in reg_edge]
        self._init_boundary_triangles()

        return
Ejemplo n.º 9
0
    def _alpha_shape_algorithm(self, alpha=None):
        """
        Given a set of points (self.points) and an optional alpha value
        determines the alpha shape boundary (stored in self.boundary,
        accessed by get_boundary).
        
        Inputs:
          alpha: The alpha value can be optionally specified.  If it is
          not specified the optimum alpha value will be used.
        """

        self.alpha = alpha

        ## Build Delaunay triangulation
        from anuga.mesh_engine.mesh_engine import generate_mesh
        points = []
        seglist = []
        holelist = []
        regionlist = []
        pointattlist = []
        segattlist = []

        points = [(pt[0], pt[1]) for pt in self.points]
        pointattlist = [ [] for i in range(len(points)) ] 
        mode = "Qzcn"
        tridata = generate_mesh(points,seglist,holelist,regionlist,
                                 pointattlist,segattlist,mode)
        self.deltri = tridata['generatedtrianglelist']
        self.deltrinbr = tridata['generatedtriangleneighborlist']
        self.hulledges = tridata['generatedsegmentlist'] 

        ## Build Alpha table
        ## the following routines determine alpha thresholds for the
        ## triangles, edges, and vertices of the delaunay triangulation
        self._tri_circumradius()
        self._edge_intervals()
        self._vertex_intervals()

        if alpha==None:
            # Find optimum alpha
            # Ken Clarkson's hull program uses smallest alpha so that
            # every vertex is non-singular so... 
            self.optimum_alpha = max([iv[0] for iv in self.vertexinterval \
                                      if iv!=[] ])
            alpha = self.optimum_alpha
        self.alpha = alpha
        reg_edge = self.get_regular_edges(self.alpha)
        self.boundary = [self.edge[k] for k in reg_edge]
        self._init_boundary_triangles()
        
        return
Ejemplo n.º 10
0
    def testbad_segattlist(self):
        holelist = []
        regionlist = []

        points = [(0.0,0.0),(0.0,10.0),(3.0,0.0),(3.0,10.0)]
        pointattlist = [[],[],[],[]]
        seglist = [(0,1),(1,3),(3,2),(2,0)]
        segattlist = [0,0]
        
        mode = "Qzpn"
        try:
            data = generate_mesh(points,seglist,holelist,regionlist,
                                  pointattlist,segattlist, mode, points)
            
        except ANUGAError:
            pass
        else:
            self.assertTrue(0 ==1,
                        'bad segment attribute list did not raise error!')
    def FIXME_bad_hole(self):

        holelist = [(9.0)]
        regionlist = []

        points = [(0.0, 0.0), (0.0, 10.0), (3.0, 0.0), (3.0, 10.0)]
        pointattlist = [[], [], [], []]
        seglist = [(0, 1), (1, 3), (3, 2), (2, 0)]
        segattlist = [0, 0, 0, 0]

        mode = "Qzpn"
        try:
            data = generate_mesh(points, seglist, holelist, regionlist,
                                 pointattlist, segattlist, mode, points)

        except TypeError:
            pass
        else:
            self.assertTrue(0 == 1, 'bad hole list did not raise error!')
    def FIXME_bad_hole(self):

        holelist = [(9.0)]
        regionlist = []

        points = [(0.0,0.0),(0.0,10.0),(3.0,0.0),(3.0,10.0)]
        pointattlist = [[],[],[],[]]
        seglist = [(0,1),(1,3),(3,2),(2,0)]
        segattlist = [0,0,0,0]
        
        mode = "Qzpn"
        try:
            data = generate_mesh(points,seglist,holelist,regionlist,
                                  pointattlist,segattlist,  mode, points)

        except TypeError:
            pass
        else:
            self.assertTrue(0 ==1,
                        'bad hole list did not raise error!')
    def test_bad_point_attsII(self):
        points = []
        seglist = []
        holelist = []
        regionlist = []

        points = [(0.0, 0.0), (0.0, 10.0), (3.0, 0.0), (3.0, 10.0)]
        pointattlist = [[1], [2], [3], [4, 8]]
        regionlist.append((1.2, 1.2, 5.0))
        seglist = [(0, 1), (1, 3), (3, 2), (2, 0)]
        segattlist = [0, 0, 0, 0]

        mode = "Qzp"

        try:
            data = generate_mesh(points, seglist, holelist, regionlist,
                                 pointattlist, segattlist, mode, points)
        except ANUGAError:
            pass
        else:
            self.assertTrue(0 == 1, 'bad list did not raise error!')
Ejemplo n.º 14
0
    def testrectangle_regionsII(self):
        points = []
        seglist = []
        holelist = []
        regionlist = []

        points = [(0.0,0.0),(0.0,10.0),(3.0,0.0),(3.0,10.0)]
        pointattlist = [[],[],[],[]]
        #it seems that
        #triangle only associates one region with a triangle
        regionlist.append( [1.3,1.3,88.33] )
        regionlist.append( [1.2,1.2,77,55] )
        seglist = [(0,1),(1,3),(3,2),(2,0)]
        segattlist = [0,0,0,0]
        
        mode = "QAzpq"
        data = generate_mesh(points,seglist,holelist,regionlist,
                              pointattlist,segattlist, mode, points)

        correct = num.array([[77.0], [77.0], [77.0], [77.0]])
        self.assertTrue(num.allclose(data['generatedtriangleattributelist'].flat, 
                                     correct.flat),
                        'Failed')
    def test_bad_point_attsII(self):
        points = []
        seglist = []
        holelist = []
        regionlist = []

        points = [(0.0,0.0),(0.0,10.0),(3.0,0.0),(3.0,10.0)]
        pointattlist = [[1],[2],[3],[4,8]]
        regionlist.append( (1.2,1.2,5.0) )
        seglist = [(0,1),(1,3),(3,2),(2,0)]
        segattlist = [0,0,0,0]
        
        mode = "Qzp"
        
        try:
            data = generate_mesh(points,seglist,holelist,
                                  regionlist,pointattlist,segattlist,
                                   mode, points)
        except ANUGAError:
            pass
        else:
            self.assertTrue(0 ==1,
                        'bad list did not raise error!')