def _read_3d(self): """Reads in a 3D SDF file and returns a Sdf object. Returns ------- :obj:`Sdf3D` A 3DSdf created from the data in the file. """ if not os.path.exists(self.filepath_): return None my_file = open(self.filepath_, 'r') nx, ny, nz = [int(i) for i in my_file.readline().split() ] #dimension of each axis should all be equal for LSH ox, oy, oz = [float(i) for i in my_file.readline().split()] #shape origin dims = np.array([nx, ny, nz]) origin = np.array([ox, oy, oz]) resolution = float(my_file.readline( )) # resolution of the grid cells in original mesh coords sdf_data = np.zeros(dims) # loop through file, getting each value count = 0 for k in range(nz): for j in range(ny): for i in range(nx): sdf_data[i][j][k] = float(my_file.readline()) count += 1 my_file.close() return sdf.Sdf3D(sdf_data, origin, resolution)
def _read_3d(self): ''' Reads a 3d SDF ''' my_file = open(self.file_name_, 'r') nx, ny, nz = [int(i) for i in my_file.readline().split() ] #dimension of each axis should all be equal for LSH ox, oy, oz = [float(i) for i in my_file.readline().split()] #shape origin dims = np.array([nx, ny, nz]) origin = np.array([ox, oy, oz]) resolution = float(my_file.readline( )) # resolution of the grid cells in original mesh coords sdf_data = np.zeros(dims) # loop through file, getting each value count = 0 for k in range(nz): for j in range(ny): for i in range(nx): sdf_data[i][j][k] = float(my_file.readline()) count += 1 my_file.close() return sdf.Sdf3D(sdf_data, origin, resolution)
def sample_sdfs(self, num_samples=1, full_cov=True): """ Samples sdfs from the GPIS Params: num_samples: (int) number of samples to generate full_cov: (bool) whether or not to use the diagonal or entire covariance matrix Returns: list of sdf objects """ sdf_samples = self.gp_.posterior_samples(self.grid_pts_, num_samples) sdfs = [] for i in range(num_samples): sdf_data = sdf_samples[:,i].reshape(self.dims_) sdfs.append(sdf.Sdf3D(sdf_data, pose = self.pose_)) return sdfs
def sdf_3d(data): """ Converts HDF5 data provided in dictionary |data| to an SDF object """ sdf_data = np.array(data[SDF_DATA_KEY]) origin = np.array(data.attrs[SDF_ORIGIN_KEY]) resolution = data.attrs[SDF_RES_KEY] # should never be used, really pose = tfx.identity_tf() scale = 1.0 if SDF_POSE_KEY in data.attrs.keys(): pose = data.attrs[SDF_POSE_KEY] if SDF_SCALE_KEY in data.attrs.keys(): scale = data.attrs[SDF_SCALE_KEY] tf = stf.SimilarityTransform3D(pose, scale) frame = None if SDF_FRAME_KEY in data.attrs.keys(): frame = data.attrs[SDF_FRAME_KEY] return sdf.Sdf3D(sdf_data, origin, resolution, tf, frame)