示例#1
0
    def forward(self, x, mesh):
        if x.numel() == 0 or mesh.isempty():
            return [Meshes(verts=[], faces=[])]

        meshes = []
        vert_feats = None
        for i, stage in enumerate(self.stages):
            mesh, vert_feats = stage(x, mesh, vert_feats=vert_feats)
            meshes.append(mesh)
            if i < self.num_stages - 1:
                subdivide = SubdivideMeshes()
                mesh, vert_feats = subdivide(mesh, feats=vert_feats)
        return meshes
示例#2
0
文件: utils.py 项目: Diuven/meshgen
def initial_data(filename, method='poisson', divide_mesh=0, **kargs):
    """
    Reads point cloud from the given filename, and returns initialized mesh and point cloud
    Returns (mesh, pcd):
        mesh: pytorch3d mesh, initialized with poisson method from the original point cloud
        pcd: pytorch3d point cloud, read from the given filename
    """

    filename = str(filename)
    method = method.lower()
    possible_methods = ('alpha', 'convex', 'poisson', 'ball')

    o3d_pcd = io.load_o3d_pcd(data_path / filename)

    if method not in possible_methods:
        raise ValueError('method %s should be one of %s' %
                         (method, possible_methods))
    if method == 'alpha':
        reconstruct = mesh_ops.alpha_mesh
    elif method == 'convex':
        reconstruct = mesh_ops.convex_mesh
    elif method == 'poisson':
        reconstruct = mesh_ops.poisson_mesh
    elif method == 'ball':
        reconstruct = mesh_ops.ball_mesh
    else:
        raise RuntimeError()

    o3d_mesh = reconstruct(o3d_pcd, **kargs)

    pt3_mesh = io.o2p_mesh(o3d_mesh)
    pt3_pcd = io.o2p_pcd(o3d_pcd)

    for i in range(divide_mesh):
        divider = SubdivideMeshes()
        pt3_mesh = divider(pt3_mesh)

    return pt3_mesh, pt3_pcd
    def forward(self, img_feats, meshes, P=None, subdivide=False):
        """
        Args:
          img_feats (tensor): Tensor of shape (N, C, H, W) giving image features,
                              or a list of such tensors.
          meshes (Meshes): Meshes class of N meshes
          P (tensor): Tensor of shape (N, 4, 4) giving projection matrix to be applied
                      to vertex positions before vert-align. If None, don't project verts.
          subdivide (bool): Flag whether to subdivice the mesh after refinement

        Returns:
          output_meshes (list of Meshes): A list with S Meshes, where S is the
                                          number of refinement stages
        """
        output_meshes = []
        vert_feats = None
        for i, stage in enumerate(self.stages):
            meshes, vert_feats = stage(img_feats, meshes, vert_feats, P)
            output_meshes.append(meshes)
            if subdivide and i < self.num_stages - 1:
                subdivide = SubdivideMeshes()
                meshes, vert_feats = subdivide(meshes, feats=vert_feats)
        return output_meshes
示例#4
0
verts = verts.to(device)

# We scale normalize and center the target mesh to fit in a sphere of radius 1 centered at (0,0,0).
# (scale, center) will be used to bring the predicted mesh to its original center and scale
# Note that normalizing the target mesh, speeds up the optimization but is not necessary!
center = verts.mean(0)
verts = verts - center
scale = max(verts.abs().max(0)[0])
verts = verts / scale

# We construct a Meshes structure for the target mesh
trg_mesh = Meshes(verts=[verts], faces=[faces_idx])

# We initialize the source shape to be a sphere of radius 1
block1 = ico_sphere(2, device)
uppooling1 = SubdivideMeshes(block1)
block2 = uppooling1(block1)
uppooling2 = SubdivideMeshes(block2)
block3 = uppooling2(block2)

#TODO batch size, features

data1 = Data(x=block1.verts_packed().reshape(-1, 3),
             edge_index=block1.edges_packed().reshape(2, -1),
             face=block1.faces_packed().reshape(3, -1))
data1.pos = data1.x

data2 = Data(x=block2.verts_packed().reshape(-1, 3),
             edge_index=block2.edges_packed().reshape(2, -1),
             face=block2.faces_packed().reshape(3, -1))
data2.pos = data2.x