def __load_node(self, fh, current_node, current_tri): # assign the current data current_node.set_data(current_tri) # get the next triangle in the file next_tri = indexed_tri_3D(self.point_cloud_instance) # try to load if not next_tri.load(fh): return next_tri # label[1] contains the maximum level of the triangle # check the current triangle label against the previous triangle label if next_tri.get_label()[1] == current_tri.get_label()[1]: # occur at same level so do not create any children return next_tri if next_tri.get_label()[1] > current_tri.get_label()[1]: # do not occur at same level so add children and start the recursion for i in range(0,4): # add child and assign the next triangle to it current_node = current_node.add_child(indexed_tri_3D(self.point_cloud_instance)) next_tri = self.__load_node(fh, current_node, next_tri) # need to go back up to the parent node so as to create the siblings correctly # otherwise we would be reproducing with our own siblings if not isinstance(current_node.get_parent(), NoneType): current_node = current_node.get_parent() # control will never reach here but will return next_tri anyway to avoid warnings return next_tri
def load(self, fh): # read the grid in from the binary file format self.meta_data = read_meta_data(fh) # create and read the point cloud self.point_cloud_instance = point_cloud() self.point_cloud_instance.load(fh) # read the number of base triangles in n_tris = read_int(fh); assert(n_tris < 1e7) # less than a million triangles - this is # just a check that we are reading the # correct file # load the triangles current_tri = indexed_tri_3D(self.point_cloud_instance) current_tri.load(fh) for i in range(0, n_tris): self.triangles.append(quad_tree()) current_node = self.triangles[i].get_root() current_tri = self.__load_node(fh, current_node, current_tri)