Esempio n. 1
0
 def generate_mesh(self):
     """
     Generate a mesh from self.data and saves it.
     :return:
     """
     self.make_network_input()
     mesh = self.network.module.generate_mesh(self.data.network_input)
     path = '/'.join([self.opt.training_media_path, str(self.flags.media_count)]) + ".obj"
     image_path = '/'.join([self.data.image_path, '00.png'])
     mesh_processor.save(mesh, path, self.colormap)
     self.flags.media_count += 1
     return {"output_path": path,
             "image_path": image_path}
Esempio n. 2
0
    def demo(self, demo_path, input_path_points=None):
        """
        This function takes an image or pointcloud path as input and save the mesh infered by Atlasnet
        Extension supported are ply npy obg and png
        :return: path to the generated mesh
        """
        ext = demo_path.split('.')[-1]
        self.data = self.datasets.dataset_train.load(demo_path)
        self.data = EasyDict(self.data)

        if input_path_points is None:
            input_path_points = demo_path

        #prepare normalization
        get_normalization = self.datasets.dataset_train.load(input_path_points)
        get_normalization = EasyDict(get_normalization)

        self.make_network_input()
        mesh = self.network.module.generate_mesh(self.data.network_input)
        if get_normalization.operation is not None:
            # Undo any normalization that was used to preprocess the input.
            vertices = torch.from_numpy(mesh.vertices).clone().unsqueeze(0)
            get_normalization.operation.invert()
            unnormalized_vertices = get_normalization.operation.apply(vertices)
            mesh = pymesh.form_mesh(
                vertices=unnormalized_vertices.squeeze().numpy(),
                faces=mesh.faces)

        if self.opt.demo:
            path = demo_path.split('.')
            path[-2] += "AtlasnetReconstruction"
            path[-1] = "ply"
            path = ".".join(path)
        else:
            path = '/'.join(
                [self.opt.training_media_path,
                 str(self.flags.media_count)]) + ".ply"
            self.flags.media_count += 1

        print(f"Atlasnet generated mesh at {path}!")
        mesh_processor.save(mesh, path, self.colormap)
        return path