#!/usr/bin/env python # import tempfile import unittest from mesh_interface import * from load_mesh.loadASCII import * from utilities.polygon import inside_polygon from coordinate_transforms.geo_reference import Geo_reference,DEFAULT_ZONE class TestCase(unittest.TestCase): def setUp(self): pass def tearDown(self): pass def test_create_mesh_from_regions(self): x=-500 y=-1000 mesh_geo = geo_reference=Geo_reference(56,x,y) # These are the absolute values polygon_absolute = [[0,0],[100,0],[100,100],[0,100]] x_p = -10 y_p = -40 geo_ref_poly = Geo_reference(56, x_p, y_p) polygon = geo_ref_poly.change_points_geo_ref(polygon_absolute) boundary_tags = {'walls':[0,1],'bom':[2]} inner1_polygon_absolute = [[10,10],[20,10],[20,20],[10,20]] inner1_polygon = geo_ref_poly. \ change_points_geo_ref(inner1_polygon_absolute) inner2_polygon_absolute = [[30,30],[40,30],[40,40],[30,40]] inner2_polygon = geo_ref_poly. \ change_points_geo_ref(inner2_polygon_absolute) interior_regions = [(inner1_polygon, 5),(inner2_polygon, 0.2)] m = create_mesh_from_regions(polygon, boundary_tags, 10000000, interior_regions=interior_regions, poly_geo_reference=geo_ref_poly, mesh_geo_reference=mesh_geo) # Test the mesh instance self.failUnless(len(m.regions)==3, 'FAILED!') segs = m.getUserSegments() self.failUnless(len(segs)==12, 'FAILED!') self.failUnless(len(m.userVertices)==12, 'FAILED!') self.failUnless(segs[0].tag=='walls', 'FAILED!') self.failUnless(segs[1].tag=='walls', 'FAILED!') self.failUnless(segs[2].tag=='bom', 'FAILED!') self.failUnless(segs[3].tag=='', 'FAILED!') # Assuming the order of the region points is known. # (This isn't true, if you consider create_mesh_from_regions # a black box) poly_point = m.getRegions()[0] #print "poly_point", poly_point #print "polygon_absolute",polygon_absolute # poly_point values are relative to the mesh geo-ref # make them absolute self.failUnless(inside_polygon([poly_point.x+x,poly_point.y+y], polygon_absolute, closed = False), 'FAILED!') # Assuming the order of the region points is known. # (This isn't true, if you consider create_mesh_from_regions # a black box) poly_point = m.getRegions()[1] #print "poly_point", poly_point #print "polygon_absolute",polygon_absolute # poly_point values are relative to the mesh geo-ref # make them absolute self.failUnless(inside_polygon([poly_point.x+x,poly_point.y+y], inner1_polygon_absolute, closed = False), 'FAILED!') # Assuming the order of the region points is known. # (This isn't true, if you consider create_mesh_from_regions # a black box) poly_point = m.getRegions()[2] #print "poly_point", poly_point #print "polygon_absolute",polygon_absolute # poly_point values are relative to the mesh geo-ref # make them absolute self.failUnless(inside_polygon([poly_point.x+x,poly_point.y+y], inner2_polygon_absolute, closed = False), 'FAILED!') def test_create_mesh_from_regions2(self): # These are the absolute values min_x = 10 min_y = 88 polygon_absolute = [[min_x,min_y],[1000,100],[1000,1000],[100,1000]] x_p = -10 y_p = -40 zone = 808 geo_ref_poly = Geo_reference(zone, x_p, y_p) polygon = geo_ref_poly.change_points_geo_ref(polygon_absolute) boundary_tags = {'walls':[0,1],'bom':[2]} inner1_polygon_absolute = [[10,10],[20,10],[20,20],[10,20]] inner1_polygon = geo_ref_poly. \ change_points_geo_ref(inner1_polygon_absolute) inner2_polygon_absolute = [[30,30],[40,30],[40,40],[30,40]] inner2_polygon = geo_ref_poly. \ change_points_geo_ref(inner2_polygon_absolute) interior_regions = [(inner1_polygon, 5),(inner2_polygon, 0.2)] m = create_mesh_from_regions(polygon, boundary_tags, 10000000, interior_regions=interior_regions, poly_geo_reference=geo_ref_poly) # Test the mesh instance self.failUnless(len(m.regions)==3, 'FAILED!') segs = m.getUserSegments() self.failUnless(len(segs)==12, 'FAILED!') self.failUnless(len(m.userVertices)==12, 'FAILED!') self.failUnless(segs[0].tag=='walls', 'FAILED!') self.failUnless(segs[1].tag=='walls', 'FAILED!') self.failUnless(segs[2].tag=='bom', 'FAILED!') self.failUnless(segs[3].tag=='', 'FAILED!') self.failUnless(m.geo_reference.get_zone()==zone, 'FAILED!') self.failUnless(m.geo_reference.get_xllcorner()==min_x, 'FAILED!') self.failUnless(m.geo_reference.get_yllcorner()==min_y, 'FAILED!') def test_create_mesh_from_regions3(self): # These are the absolute values min_x = 10 min_y = 88 polygon = [[min_x,min_y],[1000,100],[1000,1000],[100,1000]] x_p = -10 y_p = -40 geo_ref_poly = Geo_reference(56, x_p, y_p) boundary_tags = {'walls':[0,1],'bom':[2]} inner1_polygon_absolute = [[10,10],[20,10],[20,20],[10,20]] inner1_polygon = geo_ref_poly. \ change_points_geo_ref(inner1_polygon_absolute) inner2_polygon_absolute = [[30,30],[40,30],[40,40],[30,40]] inner2_polygon = geo_ref_poly. \ change_points_geo_ref(inner2_polygon_absolute) interior_regions = [(inner1_polygon, 5),(inner2_polygon, 0.2)] m = create_mesh_from_regions(polygon, boundary_tags, 10000000, interior_regions=interior_regions) # Test the mesh instance self.failUnless(len(m.regions)==3, 'FAILED!') segs = m.getUserSegments() self.failUnless(len(segs)==12, 'FAILED!') self.failUnless(len(m.userVertices)==12, 'FAILED!') self.failUnless(segs[0].tag=='walls', 'FAILED!') self.failUnless(segs[1].tag=='walls', 'FAILED!') self.failUnless(segs[2].tag=='bom', 'FAILED!') self.failUnless(segs[3].tag=='', 'FAILED!') self.failUnless(m.geo_reference.get_zone()==DEFAULT_ZONE, 'FAILED!') self.failUnless(m.geo_reference.get_xllcorner()==min_x, 'FAILED!') self.failUnless(m.geo_reference.get_yllcorner()==min_y, 'FAILED!') #------------------------------------------------------------- if __name__ == "__main__": suite = unittest.makeSuite(TestCase,'test') #suite = unittest.makeSuite(meshTestCase,'test_asciiFile') runner = unittest.TextTestRunner() #verbosity=2) runner.run(suite)