def _load_from_store(self, name, data): if len(data) > 0: out = ploads(gzip.decompress(data)) for n in out: spacing = self.root_spacing / math.pow(2, len(n)) aabb = self.root_aabb for i in n: aabb = split_aabb(aabb, int(i)) node = Node(n, aabb, spacing) node.load_from_bytes(out[n]) self.node_bytes[n] = out[n] self.nodes[n] = node else: spacing = self.root_spacing / math.pow(2, len(name)) aabb = self.root_aabb for i in name: aabb = split_aabb(aabb, int(i)) node = Node(name, aabb, spacing) self.nodes[name] = node return self.nodes[name]
def get_node(self, name): """Returns the node mathing the given name""" if name not in self.nodes: spacing = self.root_spacing / math.pow(2, len(name)) aabb = self.root_aabb for i in name: aabb = split_aabb(aabb, int(i)) node = Node(name, aabb, spacing) self.nodes[name] = node else: node = self.nodes[name] return node
def write_tileset(in_folder, out_folder, octree_metadata, offset, scale, projection, rotation_matrix, include_rgb): # compute tile transform matrix if rotation_matrix is None: transform = np.identity(4) else: transform = inverse_matrix(rotation_matrix) transform = np.dot(transform, scale_matrix(1.0 / scale[0])) transform = np.dot(translation_matrix(offset), transform) # build fake points if True: root_node = Node('', octree_metadata.aabb, octree_metadata.spacing * 2) root_node.children = [] inv_aabb_size = (1.0 / (octree_metadata.aabb[1] - octree_metadata.aabb[0])).astype(np.float32) for child in ['0', '1', '2', '3', '4', '5', '6', '7']: ondisk_tile = name_to_filename(out_folder, child.encode('ascii'), '.pnts') if os.path.exists(ondisk_tile): tile_content = TileContentReader.read_file(ondisk_tile) fth = tile_content.body.feature_table.header xyz = tile_content.body.feature_table.body.positions_arr.view(np.float32).reshape((fth.points_length, 3)) if include_rgb: rgb = tile_content.body.feature_table.body.colors_arr.reshape((fth.points_length, 3)) else: rgb = np.zeros(xyz.shape, dtype=np.uint8) root_node.grid.insert( octree_metadata.aabb[0].astype(np.float32), inv_aabb_size, xyz.copy(), rgb) pnts_writer.node_to_pnts(''.encode('ascii'), root_node, out_folder, include_rgb) executor = concurrent.futures.ProcessPoolExecutor() root_tileset = Node.to_tileset(executor, ''.encode('ascii'), octree_metadata.aabb, octree_metadata.spacing, out_folder, scale) executor.shutdown() root_tileset['transform'] = transform.T.reshape(16).tolist() root_tileset['refine'] = 'REPLACE' for child in root_tileset['children']: child['refine'] = 'ADD' tileset = { 'asset': { 'version': '1.0', }, 'geometricError': np.linalg.norm( octree_metadata.aabb[1] - octree_metadata.aabb[0]) / scale[0], 'root': root_tileset, } with open('{}/tileset.json'.format(out_folder), 'w') as f: f.write(json.dumps(tileset))
def node(): bbox = np.array([[0, 0, 0], [2, 2, 2]]) return Node('noeud', bbox, compute_spacing(bbox))