From c1cd94df9d6420a7a4f3d076366b40329e81df08 Mon Sep 17 00:00:00 2001 From: Rafael Brune Date: Tue, 16 Jan 2018 20:02:02 +0100 Subject: [PATCH] Fix and enable cutting out of sub-grid pieces. (#1) Fix and enable cutting out of sub-grid pieces. --- README.rst | 2 ++ lidartile/cli.py | 6 ++++++ lidartile/grid.py | 12 ++++++------ 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/README.rst b/README.rst index 172c5e6..de71bf8 100755 --- a/README.rst +++ b/README.rst @@ -31,6 +31,8 @@ Options are: * ``-l``: Scale. Use numbers less than 1 to scale down, e.g. 0.5 is half scale. +* ``-ix,iy,iw,ih``: Sub-grid, use to cut out a certain piece from the input map. ``x,y`` define lower-left corner and ``w,h`` the width and height of the cut-out. + Commandline Examples -------------------- diff --git a/lidartile/cli.py b/lidartile/cli.py index 5e37a2f..0ecd70b 100755 --- a/lidartile/cli.py +++ b/lidartile/cli.py @@ -18,11 +18,17 @@ def main(): parser.add_argument("-m", "--smoothing", type=float, default=0) parser.add_argument("-l", "--scale", type=float, default=0.3) parser.add_argument("-o", "--output", default="output.stl") + parser.add_argument("-ix", "--slicex", type=int, default=0) + parser.add_argument("-iy", "--slicey", type=int, default=0) + parser.add_argument("-iw", "--slicewidth", type=int, default=0) + parser.add_argument("-ih", "--sliceheight", type=int, default=0) parser.add_argument("files", nargs="+") args = parser.parse_args() ingestor = AscIngestor(args.files, divisor=args.divisor, zboost=args.zboost) ingestor.load() + if args.slicewidth and args.sliceheight: + ingestor.grid = ingestor.grid.slice(args.slicex, args.slicey, args.slicewidth, args.sliceheight) grid = ingestor.grid if args.clip: print "Clipping..." diff --git a/lidartile/grid.py b/lidartile/grid.py index 66eda61..b6b144e 100755 --- a/lidartile/grid.py +++ b/lidartile/grid.py @@ -50,16 +50,16 @@ def smooth(self, factor=1): limit = s * (1 / factor) self[x, y] = clip(height, m - limit, m + limit) - def slice(self, x, y, w, h): + def slice(self, ox, oy, w, h): """ Returns a sub-grid """ - assert x + w <= self.width - assert y + h <= self.height + assert ox + w <= self.width + assert oy + h <= self.height result = self.__class__(w, h) - for y in range(y, y + h): - idx = x + (y * w) - ouridx = x + (y * self.width) + for y in range(h): + idx = y * w + ouridx = ox + ((oy+y) * self.width) result.data[idx:idx+w] = self.data[ouridx:ouridx+w] return result