diff --git a/data/curvatures.py b/data/curvatures.py index 1f289fe..ff72902 100644 --- a/data/curvatures.py +++ b/data/curvatures.py @@ -96,28 +96,34 @@ class Data: class Cache: def __init__(self, folder, neighbourhood, frames, include_neighbours=True): self.cache = dict() + self.folder = folder + self.neighbourhood = neighbourhood + self.frames = frames + self.include_neighbours = include_neighbours - for frame in tqdm.tqdm(frames): + + def read(self, main_id): + frames = [frame for frame in self.frames if frame.split()[0] == main_id] + for frame in frames: id = frame.split()[0] - frame_nr = int(frame.split()[1]) garment = frame.split()[2] if id in self.cache.keys(): continue self.cache[id] = Data() - mask = read_garment_mask(folder, id, garment) #np.load(os.path.join(folder, 'mesh_mask', f'{id}.npy')).astype(bool) + mask = read_garment_mask(self.folder, id, garment) - if include_neighbours: - k_neighbors = np.argsort(dist[mask, :][:, mask], axis=-1)[:, :neighbourhood] #cloud.get_neighbors(k=neighbourhood) + if self.include_neighbours: + k_neighbors = np.argsort(dist[mask, :][:, mask], axis=-1)[:, :self.neighbourhood] self.cache[id].k_neighbors = k_neighbors G = tm.graph.vertex_adjacency_graph(m) for i in range(v.shape[0]): for k in range(25): assert nx.has_path(G, i, k_neighbors[i, k]), f'No path between {i} and {k_neighbors[i, k]}' - _, faces = _maskFaces(np.zeros((14475,3)), F, mask) #np.load(os.path.join(folder, 'faces', f'{id}.npy')) - v = read_posed_garment_frame(folder, id, garment, frame_nr)[mask,:] + _, faces = _maskFaces(np.zeros((14475,3)), F, mask) + v = read_posed_garment_frame(folder, id, garment, 0)[mask,:] m = tm.Trimesh(v, faces, process=False, validate=False) outliers = np.array([len(v) for v in m.vertex_neighbors]) == 0 outliers = np.nonzero(outliers)[0] @@ -130,6 +136,10 @@ class Cache: self.cache[id].faces = faces def __getitem__(self, id): + if id not in self.cache.keys(): + del self.cache + self.cache = dict() + self.read(id) return self.cache[id] @@ -383,13 +393,13 @@ if __name__ == '__main__': start = time.perf_counter() # generate_curvatures(folder, neighbourhood, frames) - # curvatures = read_raw_curvatures(folder, frames, neighbourhood) + curvatures = read_raw_curvatures(folder, frames, neighbourhood) # bins = get_bins(curvatures, nr_of_labels) # np.save(f'custom_data/{type}_bins{skirt_modifier}_{neighbourhood}.npy', bins) # print(bins) - # bins = np.load(f'custom_data/{type}_bins{skirt_modifier}_{neighbourhood}.npy') - # generate_curvature_labels(folder, bins, curvatures, frames, neighbourhood) - visualize_curvature_labels(folder, frames) + bins = np.load(f'custom_data/{type}_bins{skirt_modifier}_{neighbourhood}.npy') + generate_curvature_labels(folder, bins, curvatures, frames, neighbourhood) + # visualize_curvature_labels(folder, frames) print(time.perf_counter() - start)