def between_levels(self):
        self.logger.start()
        self.update_target()
        if self.source_mesh is None:
            last_mesh_path = f'{self.opt.cp_folder}/{self.opt.mesh_name}_level{self.level - 1 + self.refinement:02d}.obj'
            if self.level > 0 and os.path.isfile(last_mesh_path):
                self.source_mesh = mesh_utils.to(mesh_utils.load_mesh(last_mesh_path), self.device)
                self.source_mesh = self.source_mesh[0] * (2 ** self.level), self.source_mesh[1]
                self.target_mesh = self.target_mesh[0] * (2 ** self.level), self.target_mesh[1]
            else:
                mesh_path = f'{const.RAW_MESHES}/{self.opt.mesh_name}_template.obj'
                if not os.path.isfile(mesh_path) or not self.opt.pre_template:
                    # mesh_path = f'{const.RAW_MESHES}/icosahedron.obj'
                    self.source_mesh = mesh_utils.load_real_mesh(self.opt.template_name, self.opt.template_start, False)
                else:
                    self.source_mesh = mesh_utils.load_mesh(mesh_path)
                self.source_mesh = mesh_utils.to(mesh_utils.to_unit_cube(self.source_mesh)[0], self.device)
                scale = 1 / mesh_utils.edge_lengths(self.source_mesh).mean().item()
                self.target_mesh = self.target_mesh[0] * scale, self.target_mesh[1]
                self.source_mesh = self.source_mesh[0] * scale, self.source_mesh[1]
                self.target_transform = self.target_transform[0], self.target_transform[1] * scale

                if self.opt.template_start > 0 or os.path.isfile(mesh_path):
                    mesh_utils.export_mesh(self.source_mesh, f'{self.opt.cp_folder}/{self.opt.mesh_name}_template.obj')
        if self.level != 0 and not self.refinement:
            self.source_mesh = mesh_utils.Upsampler(self.source_mesh)(self.source_mesh)
        self.ds_source = mesh_utils.VerticesDS(self.source_mesh).to(self.device)

        self.save_scales()
    def update_target(self):
        if (len(self.opt.switches) == 0 or self.opt.switches[-1] < self.level) and self.target_mesh is None:
            self.target_mesh = mesh_utils.load_mesh(f'{const.RAW_MESHES}/{self.opt.mesh_name}')
            self.target_mesh, self.target_transform = mesh_utils.to_unit_cube(self.target_mesh)

        elif self.level == 0:
            self.target_mesh = mesh_utils.load_mesh(f'{const.RAW_MESHES}/{self.opt.mesh_name}_0')
            self.target_mesh, self.target_transform = mesh_utils.to_unit_cube(self.target_mesh)

        elif self.level in self.opt.switches:
            self.target_mesh = mesh_utils.load_mesh(f'{const.RAW_MESHES}/{self.opt.mesh_name}_{self.level}')
            self.target_mesh = (self.target_mesh[0] - self.target_transform[0][None, :]) * self.target_transform[1], self.target_mesh[1]
            self.opt.gamma_edge_global = self.opt.gamma_edge_local = 0
        self.target_mesh = mesh_utils.to(self.target_mesh, self.device)
 def __init__(self, path_or_mesh: Union[str, T_Mesh], opt: Options, level: int, local_axes: Union[N, TS] = None):
     self.level = level
     self.opt = opt
     if type(path_or_mesh) is str:
         self.raw_mesh = mesh_utils.load_mesh(path_or_mesh)
     else:
         self.raw_mesh: T_Mesh = path_or_mesh
     self.update_ds(self.raw_mesh, level)
     self.valid_axes = local_axes is not None
     if local_axes is None:
         self.local_axes = self.extract_local_axes()
     else:
         self.local_axes = local_axes
Esempio n. 4
0
def render_mesh(mesh: Union[T_Mesh, str], ambient_color: T, light_dir: T):
    if type(mesh) is str:
        mesh = mesh_utils.load_mesh(mesh)
    _ = fix_vertices(mesh)
    colors = compute_colors(mesh, ambient_color, light_dir)
    mesh = mesh[0].numpy(), mesh[1].numpy()
    plot = init_plot(mesh)
    add_surfaces(mesh, plot, colors)
    li = max(plot[1][1], plot[1][3], plot[1][5])
    plot[0].auto_scale_xyz([0, li], [0, li], [0, li])
    pl.tight_layout()
    fig_data = fig2data(plot)
    pl.close(plot[2])
    return fig_data
Esempio n. 5
0
 def first_load(mesh_path: str, data_path: str) -> mesh_utils.MeshWrap:
     vs, faces = mesh_utils.load_mesh(mesh_path)
     hold = vs[:, 1].copy()
     # swapping y and z
     vs[:, 1] = vs[:, 2]
     vs[:, 2] = hold
     mesh = (vs, faces)
     mesh = mesh_utils.to_unit(mesh)
     face_areas, face_normals = mesh_utils.compute_face_areas(mesh)
     face_centers = mesh_utils.compute_faces_centers(mesh)
     data = {
         'vs': mesh[0],
         'faces': mesh[1],
         'face_areas': face_areas,
         'face_normals': face_normals,
         'total_area': face_areas.sum(),
         'face_ne': mesh_utils.compute_face_ne(mesh),
         'face_centers': face_centers
     }
     np.savez_compressed(data_path, **data)
     return mesh_utils.MeshWrap(data)