Skip to content

Commit

Permalink
Fix and enable cutting out of sub-grid pieces. (#1)
Browse files Browse the repository at this point in the history
Fix and enable cutting out of sub-grid pieces.
  • Loading branch information
rbrune authored and andrewgodwin committed Jan 16, 2018
1 parent 9c2a7b6 commit c1cd94d
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
2 changes: 2 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
--------------------
Expand Down
6 changes: 6 additions & 0 deletions lidartile/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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..."
Expand Down
12 changes: 6 additions & 6 deletions lidartile/grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit c1cd94d

Please sign in to comment.