Changeset 3541


Ignore:
Timestamp:
Aug 29, 2006, 5:12:03 PM (18 years ago)
Author:
duncan
Message:

simplifying public interface of mesh.

Files:
5 edited

Legend:

Unmodified
Added
Removed
  • anuga_core/source/anuga/pmesh/mesh.py

    r3514 r3541  
    2929import load_mesh.loadASCII
    3030import anuga.alpha_shape.alpha_shape
    31 from anuga.geospatial_data.geospatial_data import Geospatial_data, ensure_geospatial
     31from anuga.geospatial_data.geospatial_data import Geospatial_data, ensure_geospatial, ensure_absolute
    3232
    3333try: 
     
    743743            segments.append( [lo, hi] )
    744744        region_dict['segments'] = segments
    745 
    746 
    747         #Create tags
    748         #E.g. ['wall', 'wall', 'ocean', 'wall']
    749         # from a dic
    750         #{'wall':[0,1,3],'ocean':[2]}
    751         segment_tags = ['']*N
    752         if tags is not None:
    753             for key in tags:
    754                 indices = tags[key]
    755                 for i in indices:
    756                     segment_tags[i] = key
    757         region_dict['segment_tags'] = segment_tags
     745        region_dict['segment_tags'] = self._tag_dict2list(tags, N)
     746       
    758747   
    759748        self.addVertsSegs(region_dict) #this is passing absolute values
     
    774763        return inner
    775764
     765    def _tag_dict2list(self, tags, number_of_segs):
     766        """
     767        Convert a tag dictionary from this sort of format;
     768        #{'wall':[0,3],'ocean':[2]}
     769
     770        To a list format
     771        # ['wall', '', 'ocean', 'wall']
     772
     773        Note: '' is a default value of nothing
     774        """
     775        # FIXME (DSG-DSG): Using '' as a default isn't good.
     776        #Try None.
     777        # Due to this default this method is too connected to
     778        # _add_area_from_polygon
     779       
     780        segment_tags = ['']*number_of_segs
     781        if tags is not None:
     782            for key in tags:
     783                indices = tags[key]
     784                for i in indices:
     785                    segment_tags[i] = key
     786        return segment_tags
     787       
    776788    def add_circle(self, center, radius, segment_count=100,
    777789                   center_geo_reference=None, tag = None,
     
    788800           
    789801        """
    790         pass
    791802        # convert center and radius to a polygon
    792         ### pi = math.pi
    793         ### num_of_cuts = 100
    794803        cuts = []
    795804        factor = 2* math.pi/segment_count
     
    845854        #not a list of lists.
    846855        # add a method to the points class to fix this up.
     856     
     857    def add_segment(self, v1, v2, tag):
     858        """
     859        Don't do this function.
     860        what will the v's be objects?  How is the user suppost to get them?
     861
     862        Indexes?  If add vertstosegs or add_region_from_polygon is called
     863        more than once then the actual index is not obvious.  Making this
     864        function confusing.
     865        """
     866        pass
     867
     868
     869    def add_points_and_segments(self, points,
     870                                  segments, segment_tags = None):
     871        """
     872        Add an outline of the mesh.
     873        Vertices is a list of points/ a standard representation of points.
     874        Segments is a list of tuples of integers.  Each tuple defines the
     875           start and end of the segment by it's vertex index, in relation to
     876           the list of vertices.
     877        segment_tags is an optional dictionary which is used to add tags to
     878           the segments.  The key is the tag name, value is the list of segment
     879           indexes the tag will apply to.
     880           eg. {'wall':[0,3],'ocean':[2]}
     881           
     882        """
     883        #make sure the points are absolute
     884        points = ensure_absolute(points)
     885       
     886        #create points, segs and tags
     887        region_dict = {}
     888        region_dict['points'] = points
     889        region_dict['segments'] = segments
     890        region_dict['segment_tags'] = self._tag_dict2list(segment_tags,
     891                                                          len(segments))
     892        self.addVertsSegs(region_dict)
    847893       
    848894    def addVertsSegs(self, outlineDict):
     
    864910        #print "outlineDict['segments']",outlineDict['segments']
    865911       
    866         localUserVertices = []
    867         #index = 0
     912        i_offset = len(self.userVertices)
     913        #print "self.userVertices",self.userVertices
     914        #print "index_offset",index_offset
    868915        for point in outlineDict['points']:
    869916            v=Vertex(point[0]-self.geo_reference.xllcorner,
    870917                     point[1]-self.geo_reference.yllcorner)
    871             #v.index = index
    872             #index +=1
    873918            self.userVertices.append(v)
    874             localUserVertices.append(v)
    875919           
    876         #index = 0
    877920        for seg,seg_tag in map(None,outlineDict['segments'],
    878921                       outlineDict['segment_tags']):
    879             segObject = Segment( localUserVertices[int(seg[0])],
    880                            localUserVertices[int(seg[1])] )
     922            segObject = Segment(self.userVertices[int(seg[0])+i_offset],
     923                           self.userVertices[int(seg[1])+i_offset] )
    881924            if not seg_tag == '':
    882925                segObject.set_tag(seg_tag)
    883             #segObject.index = index
    884             #index +=1
    885926            self.userSegments.append(segObject)
    886             #DSG!!!
     927           
    887928       
    888929    def get_triangle_count(self):
  • anuga_core/source/anuga/pmesh/mesh_interface.py

    r3514 r3541  
    6969    #(DSG) Yes!
    7070
    71     # First check that interior polygons are fully contained in bounding polygon
     71    # First check that interior polygons are fully contained in bounding
     72    # polygon
    7273    #Note, Both poly's have the same geo_ref, therefore don't take into account
    7374    # geo_ref
  • anuga_core/source/anuga/pmesh/test_mesh.py

    r3514 r3541  
    13541354        m.addVertsSegs(dict)
    13551355
     1356    def test_addVertsSegs_done_twice(self):
     1357        m = Mesh()
     1358        dict = {}
     1359        dict['points'] = [[0.0, 0.0], [5.0, 0.0], [5.0, 5.0]]
     1360        dict['segments'] = [[0, 1], [1, 2], [2,0]]
     1361        dict['segment_tags'] = ['0','1','2']
     1362        m.addVertsSegs(dict)
     1363       
     1364        dict = {}
     1365        dict['points'] = [[2.0, 1.0], [4.0, 1.0], [4.0, 3.0]]
     1366        dict['segments'] = [[0, 1], [1, 2], [2,0]]
     1367        dict['segment_tags'] = ['3','4','5']
     1368        m.addVertsSegs(dict)
     1369
     1370       
     1371        self.failUnless(m.userSegments[5].vertices[0].y == 3,
     1372                        'Wrong vertex connected.')
     1373        self.failUnless(m.userSegments[5].vertices[1].y == 1,
     1374                        'Wrong vertex connected.')
     1375           
     1376    def test_add_points_and_segments(self):
     1377        m = Mesh()
     1378        Segment.set_default_tag("food")
     1379        dict = {}
     1380        points =  [[0.0, 0.0], [1.0, 0.0], [1.0, 1.0]]
     1381        segments = [[0, 1], [1, 2]]
     1382        segment_tags = {'do-op':[1]}
     1383        m.add_points_and_segments(points,
     1384                                    segments, segment_tags)
     1385        # have to reset this , since it's a class attribute
     1386        Segment.set_default_tag("")
     1387
     1388       
     1389        self.failUnless(len(m.userSegments) ==2,
     1390                        'Wrong segment list length.')
     1391        self.failUnless(len(m.userVertices) == 3,
     1392                        'Wrong vertex list length.')
     1393        self.failUnless(m.userSegments[0].tag =='food',
     1394                        'Wrong segment tag length.')
     1395        self.failUnless(m.userSegments[1].tag =='do-op',
     1396                        'Wrong segment tag.')
     1397       
    13561398    def test_exportASCIImeshfile(self):
    13571399   
     
    22342276if __name__ == "__main__":
    22352277    suite = unittest.makeSuite(meshTestCase,'test')
    2236     #suite = unittest.makeSuite(meshTestCase,'test_generate_mesh')
     2278    #suite = unittest.makeSuite(meshTestCase,'test_add_points_and_segments')
    22372279    runner = unittest.TextTestRunner() #verbosity=2)
    22382280    runner.run(suite)
  • development/dam_2006/create_mesh.py

    r3535 r3541  
    2929
    3030    #Boundary
    31     # FIXME (DSG-DSG): Update this to use new interface.
    32     dict = {}
    33     dict['points'] = [point_sw,   #se
    34                       point_nw,
    35                       point_dam_top,
    36                       point_ne,
    37                       point_se,
    38                       point_dam_bottom
    39                       ]
    40     #if False:
     31    points = [point_sw,   #se
     32              point_nw,
     33              point_dam_top,
     34              point_ne,
     35              point_se,
     36              point_dam_bottom
     37              ]
    4138   
    42     dict['segments'] = [[0,1], [1,2], [2,3],
     39    segments = [[0,1], [1,2], [2,3],
    4340                        [3,4 ],[4,5], [5,0],  #The outer border
    4441                        [2,5]]         #dam Separator
    4542   
    46     dict['segment_tags'] = ['wall',
    47                             'wall',
    48                             'wall',
    49                             'edge',
    50                             'wall',
    51                             'wall',         
    52                             '']           #Interior
    53 
     43    segment_tags = {'wall':[0,1,2,4,5],'edge':[3]} # '':[6]
    5444       
    55     m.addVertsSegs(dict)
     45    m.add_points_and_segments(points, segments, segment_tags)
    5646   
    5747    dam = m.add_region(-0.0000001,(ytop - ybottom)/2)
  • documentation/user_manual/anuga_user_manual.tex

    r3533 r3541  
    12111211\end{methoddesc}
    12121212
     1213
     1214\begin{methoddesc}  {add\_points_and_segments}{self, points, segments,
     1215    segment\_tags=None}
     1216Module: \module{pmesh.mesh},  Class: \class{Mesh}
     1217
     1218This method is used to build the mesh outline. It adds some points and
     1219segments connecting some points.  A tag for each point can optionally
     1220be added.
     1221
     1222\end{methoddesc}
    12131223
    12141224\begin{methoddesc} {add\_region}{x,y, geo_reference=None}
Note: See TracChangeset for help on using the changeset viewer.