[2276] | 1 | #!/usr/bin/env python |
---|
| 2 | # |
---|
| 3 | import tempfile |
---|
| 4 | import unittest |
---|
| 5 | from mesh_interface import * |
---|
| 6 | from load_mesh.loadASCII import * |
---|
| 7 | from utilities.polygon import inside_polygon |
---|
[2402] | 8 | from coordinate_transforms.geo_reference import Geo_reference,DEFAULT_ZONE |
---|
[2276] | 9 | |
---|
| 10 | class TestCase(unittest.TestCase): |
---|
| 11 | def setUp(self): |
---|
| 12 | pass |
---|
| 13 | |
---|
| 14 | def tearDown(self): |
---|
| 15 | pass |
---|
| 16 | |
---|
| 17 | def test_create_mesh_from_regions(self): |
---|
| 18 | x=-500 |
---|
| 19 | y=-1000 |
---|
| 20 | mesh_geo = geo_reference=Geo_reference(56,x,y) |
---|
| 21 | |
---|
| 22 | # These are the absolute values |
---|
| 23 | polygon_absolute = [[0,0],[100,0],[100,100],[0,100]] |
---|
| 24 | |
---|
| 25 | x_p = -10 |
---|
| 26 | y_p = -40 |
---|
| 27 | geo_ref_poly = Geo_reference(56, x_p, y_p) |
---|
| 28 | polygon = geo_ref_poly.change_points_geo_ref(polygon_absolute) |
---|
| 29 | |
---|
[2282] | 30 | boundary_tags = {'walls':[0,1],'bom':[2]} |
---|
[2276] | 31 | |
---|
| 32 | inner1_polygon_absolute = [[10,10],[20,10],[20,20],[10,20]] |
---|
| 33 | inner1_polygon = geo_ref_poly. \ |
---|
| 34 | change_points_geo_ref(inner1_polygon_absolute) |
---|
| 35 | |
---|
| 36 | inner2_polygon_absolute = [[30,30],[40,30],[40,40],[30,40]] |
---|
| 37 | inner2_polygon = geo_ref_poly. \ |
---|
| 38 | change_points_geo_ref(inner2_polygon_absolute) |
---|
| 39 | |
---|
| 40 | interior_regions = [(inner1_polygon, 5),(inner2_polygon, 0.2)] |
---|
| 41 | m = create_mesh_from_regions(polygon, |
---|
| 42 | boundary_tags, |
---|
| 43 | 10000000, |
---|
| 44 | interior_regions=interior_regions, |
---|
[2295] | 45 | poly_geo_reference=geo_ref_poly, |
---|
| 46 | mesh_geo_reference=mesh_geo) |
---|
[2276] | 47 | |
---|
[2282] | 48 | # Test the mesh instance |
---|
| 49 | self.failUnless(len(m.regions)==3, |
---|
| 50 | 'FAILED!') |
---|
| 51 | segs = m.getUserSegments() |
---|
| 52 | self.failUnless(len(segs)==12, |
---|
| 53 | 'FAILED!') |
---|
| 54 | self.failUnless(len(m.userVertices)==12, |
---|
| 55 | 'FAILED!') |
---|
| 56 | self.failUnless(segs[0].tag=='walls', |
---|
| 57 | 'FAILED!') |
---|
| 58 | self.failUnless(segs[1].tag=='walls', |
---|
| 59 | 'FAILED!') |
---|
| 60 | |
---|
| 61 | self.failUnless(segs[2].tag=='bom', |
---|
| 62 | 'FAILED!') |
---|
| 63 | self.failUnless(segs[3].tag=='', |
---|
| 64 | 'FAILED!') |
---|
| 65 | |
---|
[2295] | 66 | # Assuming the order of the region points is known. |
---|
| 67 | # (This isn't true, if you consider create_mesh_from_regions |
---|
| 68 | # a black box) |
---|
| 69 | poly_point = m.getRegions()[0] |
---|
| 70 | |
---|
| 71 | #print "poly_point", poly_point |
---|
| 72 | #print "polygon_absolute",polygon_absolute |
---|
| 73 | |
---|
| 74 | # poly_point values are relative to the mesh geo-ref |
---|
| 75 | # make them absolute |
---|
| 76 | self.failUnless(inside_polygon([poly_point.x+x,poly_point.y+y], |
---|
| 77 | polygon_absolute, closed = False), |
---|
| 78 | 'FAILED!') |
---|
| 79 | |
---|
| 80 | # Assuming the order of the region points is known. |
---|
| 81 | # (This isn't true, if you consider create_mesh_from_regions |
---|
| 82 | # a black box) |
---|
| 83 | poly_point = m.getRegions()[1] |
---|
| 84 | |
---|
| 85 | #print "poly_point", poly_point |
---|
| 86 | #print "polygon_absolute",polygon_absolute |
---|
| 87 | |
---|
| 88 | # poly_point values are relative to the mesh geo-ref |
---|
| 89 | # make them absolute |
---|
| 90 | self.failUnless(inside_polygon([poly_point.x+x,poly_point.y+y], |
---|
| 91 | inner1_polygon_absolute, |
---|
| 92 | closed = False), |
---|
| 93 | 'FAILED!') |
---|
| 94 | |
---|
| 95 | # Assuming the order of the region points is known. |
---|
| 96 | # (This isn't true, if you consider create_mesh_from_regions |
---|
| 97 | # a black box) |
---|
| 98 | poly_point = m.getRegions()[2] |
---|
| 99 | |
---|
| 100 | #print "poly_point", poly_point |
---|
| 101 | #print "polygon_absolute",polygon_absolute |
---|
| 102 | |
---|
| 103 | # poly_point values are relative to the mesh geo-ref |
---|
| 104 | # make them absolute |
---|
| 105 | self.failUnless(inside_polygon([poly_point.x+x,poly_point.y+y], |
---|
| 106 | inner2_polygon_absolute, |
---|
| 107 | closed = False), |
---|
| 108 | 'FAILED!') |
---|
[2402] | 109 | |
---|
| 110 | |
---|
| 111 | |
---|
| 112 | def test_create_mesh_from_regions2(self): |
---|
| 113 | |
---|
| 114 | # These are the absolute values |
---|
| 115 | min_x = 10 |
---|
| 116 | min_y = 88 |
---|
| 117 | polygon_absolute = [[min_x,min_y],[1000,100],[1000,1000],[100,1000]] |
---|
| 118 | |
---|
| 119 | x_p = -10 |
---|
| 120 | y_p = -40 |
---|
| 121 | zone = 808 |
---|
| 122 | geo_ref_poly = Geo_reference(zone, x_p, y_p) |
---|
| 123 | polygon = geo_ref_poly.change_points_geo_ref(polygon_absolute) |
---|
| 124 | |
---|
| 125 | boundary_tags = {'walls':[0,1],'bom':[2]} |
---|
| 126 | |
---|
| 127 | inner1_polygon_absolute = [[10,10],[20,10],[20,20],[10,20]] |
---|
| 128 | inner1_polygon = geo_ref_poly. \ |
---|
| 129 | change_points_geo_ref(inner1_polygon_absolute) |
---|
| 130 | |
---|
| 131 | inner2_polygon_absolute = [[30,30],[40,30],[40,40],[30,40]] |
---|
| 132 | inner2_polygon = geo_ref_poly. \ |
---|
| 133 | change_points_geo_ref(inner2_polygon_absolute) |
---|
| 134 | |
---|
| 135 | interior_regions = [(inner1_polygon, 5),(inner2_polygon, 0.2)] |
---|
| 136 | m = create_mesh_from_regions(polygon, |
---|
| 137 | boundary_tags, |
---|
| 138 | 10000000, |
---|
| 139 | interior_regions=interior_regions, |
---|
| 140 | poly_geo_reference=geo_ref_poly) |
---|
| 141 | |
---|
| 142 | |
---|
| 143 | # Test the mesh instance |
---|
| 144 | self.failUnless(len(m.regions)==3, |
---|
| 145 | 'FAILED!') |
---|
| 146 | segs = m.getUserSegments() |
---|
| 147 | self.failUnless(len(segs)==12, |
---|
| 148 | 'FAILED!') |
---|
| 149 | self.failUnless(len(m.userVertices)==12, |
---|
| 150 | 'FAILED!') |
---|
| 151 | self.failUnless(segs[0].tag=='walls', |
---|
| 152 | 'FAILED!') |
---|
| 153 | self.failUnless(segs[1].tag=='walls', |
---|
| 154 | 'FAILED!') |
---|
| 155 | |
---|
| 156 | self.failUnless(segs[2].tag=='bom', |
---|
| 157 | 'FAILED!') |
---|
| 158 | self.failUnless(segs[3].tag=='', |
---|
| 159 | 'FAILED!') |
---|
| 160 | |
---|
| 161 | self.failUnless(m.geo_reference.get_zone()==zone, |
---|
| 162 | 'FAILED!') |
---|
| 163 | self.failUnless(m.geo_reference.get_xllcorner()==min_x, |
---|
| 164 | 'FAILED!') |
---|
| 165 | self.failUnless(m.geo_reference.get_yllcorner()==min_y, |
---|
| 166 | 'FAILED!') |
---|
| 167 | |
---|
| 168 | |
---|
| 169 | def test_create_mesh_from_regions3(self): |
---|
| 170 | |
---|
| 171 | # These are the absolute values |
---|
| 172 | min_x = 10 |
---|
| 173 | min_y = 88 |
---|
| 174 | polygon = [[min_x,min_y],[1000,100],[1000,1000],[100,1000]] |
---|
| 175 | |
---|
| 176 | |
---|
| 177 | x_p = -10 |
---|
| 178 | y_p = -40 |
---|
| 179 | geo_ref_poly = Geo_reference(56, x_p, y_p) |
---|
| 180 | |
---|
| 181 | boundary_tags = {'walls':[0,1],'bom':[2]} |
---|
| 182 | |
---|
| 183 | inner1_polygon_absolute = [[10,10],[20,10],[20,20],[10,20]] |
---|
| 184 | inner1_polygon = geo_ref_poly. \ |
---|
| 185 | change_points_geo_ref(inner1_polygon_absolute) |
---|
| 186 | |
---|
| 187 | inner2_polygon_absolute = [[30,30],[40,30],[40,40],[30,40]] |
---|
| 188 | inner2_polygon = geo_ref_poly. \ |
---|
| 189 | change_points_geo_ref(inner2_polygon_absolute) |
---|
| 190 | |
---|
| 191 | interior_regions = [(inner1_polygon, 5),(inner2_polygon, 0.2)] |
---|
| 192 | m = create_mesh_from_regions(polygon, |
---|
| 193 | boundary_tags, |
---|
| 194 | 10000000, |
---|
| 195 | interior_regions=interior_regions) |
---|
| 196 | |
---|
| 197 | |
---|
| 198 | # Test the mesh instance |
---|
| 199 | self.failUnless(len(m.regions)==3, |
---|
| 200 | 'FAILED!') |
---|
| 201 | segs = m.getUserSegments() |
---|
| 202 | self.failUnless(len(segs)==12, |
---|
| 203 | 'FAILED!') |
---|
| 204 | self.failUnless(len(m.userVertices)==12, |
---|
| 205 | 'FAILED!') |
---|
| 206 | self.failUnless(segs[0].tag=='walls', |
---|
| 207 | 'FAILED!') |
---|
| 208 | self.failUnless(segs[1].tag=='walls', |
---|
| 209 | 'FAILED!') |
---|
| 210 | |
---|
| 211 | self.failUnless(segs[2].tag=='bom', |
---|
| 212 | 'FAILED!') |
---|
| 213 | self.failUnless(segs[3].tag=='', |
---|
| 214 | 'FAILED!') |
---|
| 215 | |
---|
| 216 | self.failUnless(m.geo_reference.get_zone()==DEFAULT_ZONE, |
---|
| 217 | 'FAILED!') |
---|
| 218 | self.failUnless(m.geo_reference.get_xllcorner()==min_x, |
---|
| 219 | 'FAILED!') |
---|
| 220 | self.failUnless(m.geo_reference.get_yllcorner()==min_y, |
---|
| 221 | 'FAILED!') |
---|
| 222 | |
---|
[2276] | 223 | #------------------------------------------------------------- |
---|
| 224 | if __name__ == "__main__": |
---|
| 225 | suite = unittest.makeSuite(TestCase,'test') |
---|
| 226 | #suite = unittest.makeSuite(meshTestCase,'test_asciiFile') |
---|
| 227 | runner = unittest.TextTestRunner() #verbosity=2) |
---|
| 228 | runner.run(suite) |
---|
| 229 | |
---|