| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- import numpy as np
- from utils.path import path
- from intersect import Mesh2D
- from utils.objparser import Mesh
- from scipy.misc import pilutil
- from PIL import ImageDraw
- OBJ_FILE = path(r'D:\loco-dev\maps\UMIC\umic.obj')
- LOCATION_FILE = path(r'D:\loco-dev\maps\UMIC\experiment\locations.txt')
- locations = []
- for l in LOCATION_FILE.lines():
- if l.startswith('#'):
- continue
- locid, x, y, z = l.split()
- locations.append((locid, float(x), float(y), float(z)))
- mesh = Mesh()
- mesh.parseObjFile(OBJ_FILE)
- mesh_xlim = (-1, 58)
- mesh_ylim = (-1, 18)
- pixel_per_meter = 16
- m2d = Mesh2D(mesh, mesh_xlim, mesh_ylim, pixel_per_meter)
- Z = [('eg', -2.0), ('og1', 1.0), ('og2', 4.5)]
- for name, z_cut in Z:
- print 'building %s...' % name
- f = path(r'N:\loco\dirk\lws\static\measure_%s.png' % name)
-
- to_be_combined = []
- for objname in m2d.objnames:
- print 'object: %s' % objname
- img = m2d.cut(objname, z_cut)
- to_be_combined.append(pilutil.fromimage(img))
- all_objects = np.add.reduce(np.array(to_be_combined))
- #~ combined_object_image
- print 'cache file to %s' % f.abspath()
-
-
- img = pilutil.toimage(all_objects)
-
- img = img.convert('RGB')
- draw = ImageDraw.Draw(img)
-
- for locid, x, y, z in locations:
- if abs(z - z_cut) < 2:
- _x, _y = m2d.meter2pixel(x, y)
- draw.text((_x, _y), locid, fill='#CC1111')
- draw.point((_x, _y), fill='#00FF00')
-
- img.save(f)
-
|