This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
def normals_from_xyz(xyz, smooth_sigma=None): | |
""" | |
Given a 3-plane float image containing x,y,z coordinates, | |
compute the surface normals at each pixel. | |
Returns a 3-plane floating point image with nx,ny,nz per pixel. | |
""" | |
if smooth_sigma is not None: | |
xyz = np.array(xyz) # make copy of input |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import rasterio | |
# load the geotiff (a DSM in this case) and read the data - only one index in this case | |
dsm = rasterio.open(dsm_fname) | |
dsm_data = dsm.read()[0] | |
# crop the data | |
dsm_crop = dsm_data[min_y:min_y+height, min_x:min_x+width] | |
# make a copy of the geotiff metadata |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Convert standard camera intrinsic and extrinsic parameters to a vtkCamera instance for rendering | |
* Assume square pixels and 0 skew (for now). | |
* | |
* focal_len : camera focal length (units pixels) | |
* nx,ny : image dimensions in pixels | |
* principal_pt: camera principal point, | |
* i.e. the intersection of the principal ray with the image plane (units pixels) | |
* camera_rot, camera_trans : rotation, translation matrix mapping world points to camera coordinates | |
* depth_min, depth_max : needed to set the clipping range |