Esempio n. 1
0
 def test(self):
     """tests model
     returns: number correct and total number
     """
     with torch.no_grad():
         out = self.forward()
         dist1, dist2, _, _ = self.criterion(self.labels, out)
         test_loss = 0.5 * (dist1.mean() + dist2.mean())
         
         labels = torch.Tensor.cpu(self.labels).numpy()
         out = torch.Tensor.cpu(out).numpy()
         
         for i in range(out.shape[0]) :
             normals = pcu.estimate_normals(out[i], k=16)
             #print(n.shape, n)
             fs, vs = poisson_reconstruction(out[i], normals, depth=5, full_depth=3)
             print(vs.shape, fs.shape)
             filename, file_extension = os.path.splitext(self.filename[i])
             file = '%s/%s_%s%s' % (self.export_folder[i], filename, 'out', file_extension)
             print(file)
             self.output_export(vs, fs, file)
         
         #print(labels.shape, out.shape)
         #for i in range(len(labels)) :
         #    mean_error, R, indices = icp(labels[i], out[i], tolerance=0.0001)
         #    print(out[i].shape, out[i])
         #    print(indices.shape, np.unique(indices).shape, indices, np.unique(indices))
         #print(out[indices[:len(indices)-self.pad_iter]].shape, self.init_faces)
         #self.output_export(vertices, faces)
         print(test_loss, len(self.labels))
     return test_loss, len(self.labels), out, self.labels
    def compute_reward(self, points, normals, depth):
        faces, vertices = poisson_reconstruction(points, normals, depth=depth)
        reward = self.env.model.surface_similarity(vertices, faces)

        if self._illustrate:
            illustrate_mesh(vertices, faces).display()
        return reward
Esempio n. 3
0
    def update(self):

        points, normals = get_points_normals_from(self.input_)
        faces, vertices = poisson_reconstruction(points, normals,
                                                    depth=self.depth)

        self.output_ = get_polydata_from(vertices, faces)
Esempio n. 4
0
    def update(self):

        points, normals = get_points_normals_from(self.input_)
        faces, vertices = poisson_reconstruction(points,
                                                 normals,
                                                 depth=self.depth)

        self.output_ = get_polydata_from(vertices, faces)
Esempio n. 5
0
def create_surface_actor(points, n=None, orientationPoint=None, negate=False):
    """Generate point normals using PCA (principal component analysis).
    Basically this estimates a local tangent plane around each sample point p
    by considering a small neighborhood of points around p, and fitting a plane
    to the neighborhood (via PCA).

    :param int n: neighborhood size to calculate the normal
    :param list orientationPoint: adjust the +/- sign of the normals so that
        the normals all point towards a specified point. If None, perform a traversal
        of the point cloud and flip neighboring normals so that they are mutually consistent.

    :param bool negate: flip all normals
    """

    if n is not None:
        sampleSize = n

    else:
        sampleSize = points.GetNumberOfPoints() * .00005
        if sampleSize < 10:
            sampleSize = 10

    polydata = vtk.vtkPolyData()
    polydata.SetPoints(points)

    print('Estimating normals using PCANormalEstimation')
    normals = vtk.vtkPCANormalEstimation()
    normals.SetInputData(polydata)
    normals.SetSampleSize(sampleSize)
    if orientationPoint is not None:
        normals.SetNormalOrientationToPoint()
        normals.SetOrientationPoint(orientationPoint)
    else:
        normals.SetNormalOrientationToGraphTraversal()
    if negate:
        normals.FlipNormalsOn()
    normals.Update()

    points_array = vtk_to_numpy(points.GetData())
    normals_array = vtk_to_numpy(
        normals.GetOutput().GetPointData().GetNormals())

    faces, vertices = poisson_reconstruction(points_array,
                                             normals_array,
                                             depth=10)

    return create_mesh_actor(vertices, faces)
Esempio n. 6
0
def screenPoisson(xyz_file, ply_file = None):
    '''
    xyz_file:str, 文件的路径
    ply_file:str, 文件的路径
    '''

    # Helper Function to read the xyz-normals point cloud file
    points, normals = points_normals_from(xyz_file)

    faces, vertices = poisson_reconstruction(points, normals, depth=10)

    # 创建渲染的角色:点云,重建后的网格
    points_actor = create_points_actor(points)
    mesh_actor = create_mesh_actor(vertices, faces)

    render(points_actor, mesh_actor)

    # 将表面重建的网格保存为PLY文件
    if ply_file != None:
        ply_from_array(vertices, faces, output_file = ply_file)
Esempio n. 7
0
    def compute_approx_surface(self, exactness_level=10):
        '''
            Compute an approximating surface using Poisson recronstruction
                exactness_level:  controls the smoothness
                        larger exactness_level will fit the points more --> less smooth
        '''
        self.compute_pnormals()

        LOGGER.info('Computing Poisson surface for {} points'.format(self.npoints))
        mtimer = Timer()
        sfaces, sverts = poisson_reconstruction(self.points.tolist(),
                                                self.pnormals.tolist(),
                                                depth=exactness_level)
        mtimer.end(False)
        LOGGER.info('Poisson surface computed! took {} created {} faces and {} vertices.'
                    .format(mtimer, len(sfaces), len(sverts)))

        # represent the poisson surface as a triangulation
        self.surf_poisson = TriMesh(sverts, faces=sfaces, label='surf_poisson')

        #self.surf_poisson.write_vtp('_temp3.vtp', {})#params)
        #self.surf_poisson.remesh()
        #self.surf_poisson.write_vtp('_temp3_remeshed.vtp', {})#params)
        self.surf_poisson.display()
Esempio n. 8
0
def poission_rect(points,normals,depth=7,full_depth=5,scale=1.1,samples_per_node=1,cg_depth=0.0):
    facets,verticle=pypoisson.poisson_reconstruction(points,normals,depth,full_depth,scale,samples_per_node,cg_depth)
    return np.array(facets),np.array(verticle)
Esempio n. 9
0
#!/usr/bin/env python3
"""
@author:Harold
@file: poisson.py
@time: 27/09/2019
"""

from pypoisson import poisson_reconstruction
from ply_from_array import points_normals_from, ply_from_array

filename = "ism_train_cat_normal.txt"
output_file = "ism_train_cat_normal_recon.ply"

points, normals = points_normals_from(filename)

faces, vertices = poisson_reconstruction(points, normals, depth=10)

ply_from_array(vertices, faces, output_file=output_file)
Esempio n. 10
0
 def _get_mesh(self, observation):
     faces, vertices = poisson_reconstruction(
         observation.points,
         observation.normals,
         depth=self._reconstruction_depth)
     return vertices, faces
Esempio n. 11
0
def get_mesh(observation, depth=10):
    faces, vertices = poisson_reconstruction(observation.points,
                                             observation.normals,
                                             depth=depth)
    return vertices, faces
Esempio n. 12
0
from pypoisson import poisson_reconstruction
from ply_from_array import points_normals_from, ply_from_array

filename = "horse_with_normals.xyz"
output_file = "horse_reconstruction.ply"

#Helper Function to read the xyz-normals point cloud file
points, normals = points_normals_from(filename)

faces, vertices = poisson_reconstruction(points, normals, depth=10)

#Helper function to save mesh to PLY Format
ply_from_array(vertices, faces, output_file=output_file)