|
| 1 | +from parse3ddmp import DMP3d |
| 2 | +import os |
| 3 | + |
| 4 | +dump3dexe = '"C:\\Program Files (x86)\\Survex\\dump3d.exe"' |
| 5 | +dump3dexe = 'dump3d' |
| 6 | +fname = "Ireby/Ireby2/Ireby2.3d" |
| 7 | +outputfile = "Ireby/Ireby2/Ireby2.json" |
| 8 | + |
| 9 | +dstream = os.popen("%s -d %s" % (dump3dexe, fname)) |
| 10 | +lines = dstream.readlines() |
| 11 | +dmp3d = DMP3d(lines) |
| 12 | + |
| 13 | +from parse3ddmp import P3 |
| 14 | +import json |
| 15 | + |
| 16 | +leglines = [line for line in dmp3d.lines if line[0] != line[1] and "SURFACE" not in line[4]] |
| 17 | +xsects = [xsect for xsect in dmp3d.xsects if len(xsect) >= 2] |
| 18 | + |
| 19 | +assert not dmp3d.cs, "We need to convert from absolute coords in this case" |
| 20 | + |
| 21 | +# points as triples |
| 22 | +stationpoints = set() |
| 23 | +stationpoints.update(line[0] for line in leglines) |
| 24 | +stationpoints.update(line[1] for line in leglines) |
| 25 | +stationpoints = list(stationpoints) |
| 26 | +stationpoints.sort(key=lambda X: (X[2], X[0], X[1])) |
| 27 | + |
| 28 | +# centralize the sketch |
| 29 | +def rangerat(ps, i, maxfac): |
| 30 | + return (1-maxfac)*min(p[i] for p in ps) + maxfac*max(p[i] for p in ps) |
| 31 | +svxp0 = P3(rangerat(stationpoints, 0, 0.5), rangerat(stationpoints, 1, 0.5), rangerat(stationpoints, 2, 1.0)) |
| 32 | + |
| 33 | +stationpointsdict = dict((p, i) for i, p in enumerate(stationpoints)) |
| 34 | +stationpointscoords = sum((tuple(stationpoint - svxp0) for stationpoint in stationpoints), ()) |
| 35 | +stationpointsnames = [ dmp3d.nodepmap[stationpoint][0][0] for stationpoint in stationpoints ] |
| 36 | +legsconnections = sum(((stationpointsdict[legline[0]], stationpointsdict[legline[1]]) for legline in leglines), ()) |
| 37 | +legsconnections = sum(((stationpointsdict[legline[0]], stationpointsdict[legline[1]]) for legline in leglines), ()) |
| 38 | +legsstyles = [ legline[3] for legline in leglines ] |
| 39 | + |
| 40 | +xsectgps = [ ] |
| 41 | +for xsectseq in xsects: |
| 42 | + xsectpoints = [dmp3d.nmapnodes[xs[0]] for xs in xsectseq] |
| 43 | + xsectindexes = [ stationpointsdict[xsectpoint] for xsectpoint in xsectpoints ] |
| 44 | + xsectrightvecs = [ ] |
| 45 | + for i in range(len(xsectpoints)): |
| 46 | + pback = xsectpoints[max(0, i-1)] |
| 47 | + p = xsectpoints[i] |
| 48 | + pfore = xsectpoints[min(len(xsectpoints)-1, i+1)] |
| 49 | + vback = P3.ZNorm(P3(p.x - pback.x, p.y - pback.y, 0.0)) |
| 50 | + vfore = P3.ZNorm(P3(pfore.x - p.x, pfore.y - p.y, 0.0)) |
| 51 | + xsectplanevec = P3.ZNorm(vback + vfore) |
| 52 | + xsectrightvecs.append(xsectplanevec[1]) |
| 53 | + xsectrightvecs.append(-xsectplanevec[0]) |
| 54 | + xsectrightvecs |
| 55 | + xsectlruds = sum((xs[1] for xs in xsectseq), ()) |
| 56 | + xsectlruds |
| 57 | + xsectgps.append({ "xsectindexes":xsectindexes, "xsectrightvecs":xsectrightvecs, "xsectlruds":xsectlruds }) |
| 58 | +xsectgps |
| 59 | + |
| 60 | +jrec = { "stationpointscoords": stationpointscoords, |
| 61 | + "stationpointsnames": stationpointsnames, |
| 62 | + "legsconnections": legsconnections, |
| 63 | + "legsstyles": legsstyles, |
| 64 | + "xsectgps": xsectgps |
| 65 | + } |
| 66 | + |
| 67 | +open(outputfile, "w").write(json.dumps(jrec)) |
0 commit comments