Changeset 1433


Ignore:
Timestamp:
May 19, 2005, 4:18:07 PM (19 years ago)
Author:
duncan
Message:

changes from vanessa and duncan

File:
1 edited

Legend:

Unmodified
Added
Removed
  • inundation/ga/storm_surge/alpha_shape/alpha_shape.py

    r1432 r1433  
    33
    44From website by Kaspar Fischer:
    5 As mentionned in Edelsbrunner's and Mucke's paper, one can
     5As mentionned in Edelsbrunner's and Muecke's paper, one can
    66intuitively think of an alpha-shape as the following:
    77
     
    4242    points = point_dict['pointlist']
    4343   
    44     #alpha = Alpha_Shape(points)
    45     #alpha.write_boundary(boundary_file)
    4644    AS = Alpha_Shape(points, alpha)
    4745    AS.write_boundary(boundary_file)
     
    6159        """
    6260        self._set_points(points)
    63         #self._alpha_shape_algorithm(alpha=alpha)
    6461        self._alpha_shape_algorithm(alpha)
    6562
     
    7572        if len(points)==3:
    7673            #check not in a straight line
     74            # FIXME check points 1,2,3 if straingt, check if points 2,3,4, ect
    7775            x01 = points[0][0] - points[1][0]
    7876            y01 = points[0][1] - points[1][1]
     
    218216            #alpha_tri = self.get_alpha_triangles(self.optimum_alpha)
    219217            #print "alpha shape triangles ", alpha_tri
    220 
    221             reg_edge = self.get_regular_edges(self.optimum_alpha)
    222             #print "alpha boundary edges", reg_edge
    223218        else:
    224             reg_edge = self.get_regular_edges(alpha)
     219            self.alpha = alpha
     220        reg_edge = self.get_regular_edges(self.alpha)
    225221   
    226222        self.boundary = [self.edge[k] for k in reg_edge]
     
    264260        # first need to check for near-zero values of denom
    265261        delta = 0.00000001
    266         random.seed()
     262        # FIXME checking two real numbers
    267263        zeroind = [k for k in range(len(denom)) if denom[k]==0 ]
    268         # if some denom values are close to zero, we perturb the associated vertices and recalculate
     264        # if some denom values are zero, we perturb the associated vertices and recalculate
    269265        while zeroind!=[]:
     266            random.seed()
    270267            print "Warning: degenerate triangles found in alpha_shape.py, results may be inaccurate."
    271268            for d in zeroind:
     
    283280            dist31 = x31*x31 + y31*y31
    284281            denom = x21*y31 - x31*y21
     282            # FIXME checking two real numbers
    285283            zeroind = [k for k in range(len(denom)) if denom[k]==0 ]
    286284
    287  
    288         # from Numeric import divide_safe
    289285        try:
    290286            dx = divide_safe(y31*dist21 - y21*dist31,denom)
    291287            dy = divide_safe(x21*dist31 - x31*dist21,denom)
    292288        except ZeroDivisionError:
    293             print "There are serious problems with the delaunay triangles"
    294             raise  #DSG maybe don't catch this error? Is recovery possible?
    295             # VR - we've already tried to deal with these errors above...
    296             #      but should probably write some better code!
     289            raise  AlphaError
    297290           
    298291        self.triradius = 0.5*sqrt(dx*dx + dy*dy)
    299292        #print "triangle radii", self.triradius
    300        
    301 
    302 
    303293
    304294    def _edge_intervals(self):
     
    311301       
    312302        # It should be possible to rewrite this routine in an array-friendly
    313         # form like _tri_circumradius()  if we need to speed things up.
     303        # form like _tri_circumradius()  if we need to speed things up.
     304        # Hard to do though.
    314305
    315306        edges = []
     
    324315                        self.points[tri[(i+2)%3],1] for i in [0,1,2]])
    325316            elen = sqrt(dx*dx+dy*dy)
    326             #angle = array([(-dx[(i+1)%3]*dx[(i+2)%3]-dy[(i+1)%3]*dy[(i+2)%3])/(elen[(i+1)%3]*elen[(i+2)%3]) for i in [0,1,2]])
    327             #angle = arccos(angle)
    328317            # really only need sign - not angle value:
    329318            anglesign = array([(-dx[(i+1)%3]*dx[(i+2)%3]-
     
    350339                else:
    351340                    continue
    352                 #if angle[i]>pi/2:
    353341                if anglesign[i] < 0:
    354342                    edgeinterval[-1][0] = edgeinterval[-1][1]
     
    383371                    vertexinterval[i][1]=INF
    384372            except ValueError:
    385                 # print "Vertex %i is isolated?"%i
    386                 # print "coords: ",self.points[i]
    387                 # print "Vertex nbrs: ", vertexnbrs[i]
    388                 # print "nbr radii: ",radii
    389                 # vertexinterval[i] = [0,INF]
    390 
    391                 #DSG is it ok to catch this error and continue?
    392                 pass
     373                raise AlphaError
    393374
    394375        self.vertexnbr = vertexnbrs
     
    623604                bdry.append((tri[(i+1)%3], tri[(i+2)%3]))
    624605
    625         self.boundarytriangle = bdrytri
    626 
    627606        newbdry = []
    628607        for ed in bdry:
     
    668647            for i in [0,1,2]:
    669648                bdry.append((tri[(i+1)%3], tri[(i+2)%3]))
    670 
    671         self.boundarytriangle = bdrytri
    672649
    673650        newbdry = []
Note: See TracChangeset for help on using the changeset viewer.