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

code format changes

File:
1 edited

Legend:

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

    r1433 r1435  
    1515we now straighten all ``round'' faces to triangles and line segments,
    1616we have an intuitive description of what is called the alpha-shape.
     17
     18Author: Vanessa Robins, ANU
    1719"""
    1820
     
    2830OUTPUT_FILE_TITLE = "# The alpha shape boundary defined by point index pairs of edges"
    2931INF = pow(10,9)
     32EPSILON = 1.0e-12
    3033
    3134def alpha_shape_via_files(point_file, boundary_file, alpha= None):
     
    5053    def __init__(self, points, alpha = None):
    5154        """
    52         An Alpha_Shape requires input of a set of points.  Other class routines
     55        An Alpha_Shape requires input of a set of points. Other class routines
    5356        return the alpha shape boundary.
    5457       
     
    109112        """
    110113        Use the flags to set constraints on the boundary:
    111         raw_boundary    Return raw boundary i.e. the regular edges of the  alpha shape
     114        raw_boundary    Return raw boundary i.e. the regular edges of the
     115                        alpha shape.
    112116        remove_holes    filter to remove small holes
    113117                        (small is defined by  boundary_points_fraction )
     
    188192        mode = "Qzcn"
    189193        #print "computing delaunay triangulation ... \n"
    190         tridata = triang.genMesh(points,seglist,holelist,regionlist,pointattlist,segattlist,trilist,mode)
     194        tridata = triang.genMesh(points,seglist,holelist,regionlist,
     195                                 pointattlist,segattlist,trilist,mode)
    191196        #print tridata
    192         #print "point attribute list: ", tridata['generatedpointattributelist'],"\n"
     197        #print "point attlist: ", tridata['generatedpointattributelist'],"\n"
    193198        #print "hull segments: ", tridata['generatedsegmentlist'], "\n"
    194199        self.deltri = tridata['generatedtrianglelist']
    195200        self.deltrinbr = tridata['generatedtriangleneighborlist']
    196         self.hulledges = tridata['generatedsegmentlist']                              
     201        self.hulledges = tridata['generatedsegmentlist']
    197202
    198203        #print "Number of delaunay triangles: ", len(self.deltri), "\n"
     
    211216            # Ken Clarkson's hull program uses smallest alpha so that
    212217            # every vertex is non-singular so...
    213             self.optimum_alpha = max([ iv[0] for iv in self.vertexinterval if iv!=[] ])
     218            self.optimum_alpha = max([iv[0] for iv in self.vertexinterval \
     219                                      if iv!=[] ])
    214220            # print "optimum alpha ", self.optimum_alpha
    215             self.alpha = self.optimum_alpha
    216             #alpha_tri = self.get_alpha_triangles(self.optimum_alpha)
    217             #print "alpha shape triangles ", alpha_tri
    218         else:
    219             self.alpha = alpha
     221            alpha = self.optimum_alpha
     222        self.alpha = alpha
    220223        reg_edge = self.get_regular_edges(self.alpha)
    221    
    222224        self.boundary = [self.edge[k] for k in reg_edge]
    223225        #print "alpha boundary edges ", self.boundary
    224         self._init_boundary_triangles()
    225            
     226        self._init_boundary_triangles()           
    226227        return
    227228
     
    260261        # first need to check for near-zero values of denom
    261262        delta = 0.00000001
    262         # FIXME checking two real numbers
    263         zeroind = [k for k in range(len(denom)) if denom[k]==0 ]
    264         # if some denom values are zero, we perturb the associated vertices and recalculate
     263        zeroind = [k for k in range(len(denom)) if \
     264                   (denom[k]< EPSILON and  denom[k] > -EPSILON)]
     265        # if some denom values are close to zero,
     266        # we perturb the associated vertices and recalculate
    265267        while zeroind!=[]:
    266268            random.seed()
     
    280282            dist31 = x31*x31 + y31*y31
    281283            denom = x21*y31 - x31*y21
    282             # FIXME checking two real numbers
    283             zeroind = [k for k in range(len(denom)) if denom[k]==0 ]
    284 
     284            zeroind = [k for k in range(len(denom)) if \
     285                       (denom[k]< EPSILON and  denom[k] > -EPSILON)]
    285286        try:
    286287            dx = divide_safe(y31*dist21 - y21*dist31,denom)
     
    461462                return i
    462463            k = findroot(vptr[i])
    463             vptr[i] = k    # this produces "path compression" in the union-find tree.
     464            vptr[i] = k    # this produces "path compression" in the
     465                           # union-find tree.
    464466            return k
    465467
     
    511513                            vptr[vr] = rvl
    512514                #print "vptr: ", vptr, "\n"
    513 
    514515        # end edge loop
    515516
     
    528529
    529530        # littleind has root indices for small components
    530         littleind = [k for k in range(len(vptr)) if (vptr[k]<0 and vptr[k]>-cutoff)]
     531        littleind = [k for k in range(len(vptr)) if \
     532                     (vptr[k]<0 and vptr[k]>-cutoff)]
    531533        if littleind:
    532534            # littlecomp has all vptr indices in the small components
    533             littlecomp = [k for k in range(len(vptr)) if findroot(k) in littleind]
     535            littlecomp = [k for k in range(len(vptr)) if \
     536                          findroot(k) in littleind]
    534537            # vdiscard has the vertex indices corresponding to vptr indices 
    535538            vdiscard = [verts[k] for k in littlecomp]
    536             newbdry = [e for e in bdry if not((e[0] in vdiscard) and (e[1] in vdiscard))]
     539            newbdry = [e for e in bdry if \
     540                       not((e[0] in vdiscard) and (e[1] in vdiscard))]
    537541
    538542            newverts = self._vertices_from_edges(newbdry)
     
    546550                    newbt.append(bt)
    547551
    548             self.boundarytriangle = newbt
    549            
     552            self.boundarytriangle = newbt           
    550553        else:
    551554            newbdry = bdry
     
    556559    def _smooth_indents(self):
    557560        """
    558         Given edges in bdry, test for acute-angle triangular indents and remove them.
     561        Given edges in bdry, test for acute-angle triangular indents
     562        and remove them.
    559563        """
    560564       
     
    576580            for j in [0,1,2]:
    577581                eda = (self.deltri[ind][(j+1)%3], self.deltri[ind][(j+2)%3])
    578                 edb = (self.deltri[ind][(j+2)%3], self.deltri[ind][(j+1)%3])               
     582                edb = (self.deltri[ind][(j+2)%3], self.deltri[ind][(j+1)%3])
    579583                if eda in bdry or edb in bdry:
    580584                    bect +=1
     
    588592            tri = self.deltri[tind[0]]
    589593           
    590             dx = array([self.points[tri[(i+1)%3],0] - self.points[tri[(i+2)%3],0] for i in [0,1,2]])
    591             dy = array([self.points[tri[(i+1)%3],1] - self.points[tri[(i+2)%3],1] for i in [0,1,2]])
    592             anglesign = array([(-dx[(i+1)%3]*dx[(i+2)%3]-dy[(i+1)%3]*dy[(i+2)%3]) for i in [0,1,2]])
    593             # record any triangle that has an acute angle spanned by two edges along the boundary..
     594            dx = array([self.points[tri[(i+1)%3],0] - \
     595                        self.points[tri[(i+2)%3],0] for i in [0,1,2]])
     596            dy = array([self.points[tri[(i+1)%3],1] - \
     597                        self.points[tri[(i+2)%3],1] for i in [0,1,2]])
     598            anglesign = array([(-dx[(i+1)%3]*dx[(i+2)%3]-\
     599                                dy[(i+1)%3]*dy[(i+2)%3]) for i in [0,1,2]])
     600            # record any triangle that has an acute angle spanned by
     601            #two edges along the boundary..
    594602            if anglesign[tind[1]] > 0:
    595603                acutetri.append(tind[0])
     
    597605        #print "acute boundary triangles ", acutetri
    598606
    599         # adjust the bdry edges and triangles by adding in the acutetri triangles
     607        # adjust the bdry edges and triangles by adding
     608        #in the acutetri triangles
    600609        for pind in acutetri:
    601610            bdrytri.remove(pind)
     
    627636        v = v1+v2
    628637        v.sort()
    629         probv = [v[k] for k in range(len(v)) if (v[k]!=v[k-1] and v.count(v[k])>2) ]
     638        probv = [v[k] for k in range(len(v)) \
     639                 if (v[k]!=v[k-1] and v.count(v[k])>2) ]
    630640        #print "problem vertices: ", probv 
    631641
Note: See TracChangeset for help on using the changeset viewer.