def makeMesh(self): if self.Xs.shape[2] == 0: return X = self.Xs[:, :, 0] Y = self.Ys[:, :, 0] Z = self.Zs[:, :, 0] mesh = PolyMesh() #Come up with vertex indices in the mask Mask = np.array(self.Mask, dtype=np.int32) nV = np.sum(Mask) Mask[self.Mask > 0] = np.arange(nV) + 1 Mask = Mask - 1 VPos = np.zeros((nV, 3)) VPos[:, 0] = X[self.Mask > 0] VPos[:, 1] = Y[self.Mask > 0] VPos[:, 2] = -Z[self.Mask > 0] #Add lower right triangle v1 = Mask[0:-1, 0:-1].flatten() v2 = Mask[1:, 0:-1].flatten() v3 = Mask[1:, 1:].flatten() N = v1.size ITris1 = np.concatenate((np.reshape(v1, [N, 1]), np.reshape( v2, [N, 1]), np.reshape(v3, [N, 1])), 1) #Add upper right triangle v1 = Mask[0:-1, 0:-1].flatten() v2 = Mask[1:, 1:].flatten() v3 = Mask[0:-1, 1:].flatten() N = v1.size ITris2 = np.concatenate((np.reshape(v1, [N, 1]), np.reshape( v2, [N, 1]), np.reshape(v3, [N, 1])), 1) ITris = np.concatenate((ITris1, ITris2), 0) #Only retain triangles which have all three points ITris = ITris[np.sum(ITris == -1, 1) == 0, :] mesh.VPos = VPos mesh.ITris = ITris mesh.VColors = 0.5 * np.ones(mesh.VPos.shape) mesh.updateNormalBuffer() mesh.VPosVBO = vbo.VBO(np.array(mesh.VPos, dtype=np.float32)) mesh.VNormalsVBO = vbo.VBO(np.array(mesh.VNormals, dtype=np.float32)) mesh.VColorsVBO = vbo.VBO(np.array(mesh.VColors, dtype=np.float32)) mesh.IndexVBO = vbo.VBO(mesh.ITris, target=GL_ELEMENT_ARRAY_BUFFER) mesh.needsDisplayUpdate = False self.mesh = mesh
def makeMesh(self): if self.Xs.shape[2] == 0: return X = self.Xs[:, :, 0] Y = self.Ys[:, :, 0] Z = self.Zs[:, :, 0] mesh = PolyMesh() #Come up with vertex indices in the mask Mask = np.array(self.Mask, dtype=np.int32) nV = np.sum(Mask) Mask[self.Mask > 0] = np.arange(nV) + 1 Mask = Mask - 1 VPos = np.zeros((nV, 3)) VPos[:, 0] = X[self.Mask > 0] VPos[:, 1] = Y[self.Mask > 0] VPos[:, 2] = -Z[self.Mask > 0] #Add lower right triangle v1 = Mask[0:-1, 0:-1].flatten() v2 = Mask[1:, 0:-1].flatten() v3 = Mask[1:, 1:].flatten() N = v1.size ITris1 = np.concatenate((np.reshape(v1, [N, 1]), np.reshape(v2, [N, 1]), np.reshape(v3, [N, 1])), 1) #Add upper right triangle v1 = Mask[0:-1, 0:-1].flatten() v2 = Mask[1:, 1:].flatten() v3 = Mask[0:-1, 1:].flatten() N = v1.size ITris2 = np.concatenate((np.reshape(v1, [N, 1]), np.reshape(v2, [N, 1]), np.reshape(v3, [N, 1])), 1) ITris = np.concatenate((ITris1, ITris2), 0) #Only retain triangles which have all three points ITris = ITris[np.sum(ITris == -1, 1) == 0, :] mesh.VPos = VPos mesh.ITris = ITris mesh.VColors = 0.5*np.ones(mesh.VPos.shape) mesh.updateNormalBuffer() mesh.VPosVBO = vbo.VBO(np.array(mesh.VPos, dtype=np.float32)) mesh.VNormalsVBO = vbo.VBO(np.array(mesh.VNormals, dtype=np.float32)) mesh.VColorsVBO = vbo.VBO(np.array(mesh.VColors, dtype=np.float32)) mesh.IndexVBO = vbo.VBO(mesh.ITris, target=GL_ELEMENT_ARRAY_BUFFER) mesh.needsDisplayUpdate = False self.mesh = mesh
return angles if __name__ == '__main__': if len(sys.argv) < 4: print "Usage: python makeRotationImages.py <mesh name> <directory name> <NFrames>" sys.exit(0) [filename, dirName, NFrames] = [sys.argv[1], sys.argv[2], int(sys.argv[3])] np.random.seed(100) #For repeatable results randomly sampling if not os.path.exists(dirName): os.mkdir(dirName) m = PolyMesh() m.loadFile(filename) m.VPos = m.VPos * np.random.randn(m.VPos.shape[0], m.VPos.shape[1]) #Output rotation video #angles = 2*np.pi*np.random.rand(NFrames, 2) #angles = np.zeros((NFrames, 2)) #angles[:, 0] = np.linspace(0, 2*np.pi, NFrames+1)[0:NFrames] #angles = getUniformSphereAngles(3) [I, J] = np.meshgrid(np.linspace(0, 2 * np.pi, 30), np.linspace(0, 2 * np.pi, 30)) angles = np.zeros((I.size, 2)) angles[:, 0] = I.flatten() angles[:, 1] = J.flatten()
return angles if __name__ == "__main__": if len(sys.argv) < 4: print "Usage: python makeRotationImages.py <mesh name> <directory name> <NFrames>" sys.exit(0) [filename, dirName, NFrames] = [sys.argv[1], sys.argv[2], int(sys.argv[3])] np.random.seed(100) # For repeatable results randomly sampling if not os.path.exists(dirName): os.mkdir(dirName) m = PolyMesh() m.loadFile(filename) m.VPos = m.VPos * np.random.randn(m.VPos.shape[0], m.VPos.shape[1]) # Output rotation video # angles = 2*np.pi*np.random.rand(NFrames, 2) # angles = np.zeros((NFrames, 2)) # angles[:, 0] = np.linspace(0, 2*np.pi, NFrames+1)[0:NFrames] # angles = getUniformSphereAngles(3) [I, J] = np.meshgrid(np.linspace(0, 2 * np.pi, 30), np.linspace(0, 2 * np.pi, 30)) angles = np.zeros((I.size, 2)) angles[:, 0] = I.flatten() angles[:, 1] = J.flatten() doShapeGLPlot(m, angles, dirName)
y[anchorsIdx] += anchorWeights*anchors y = igl.eigen.MatrixXd(y) ret = solver.solve(y) return np.array(ret) if __name__ == '__main__2': anchorWeights = 10000 m = PolyMesh() m.loadOffFile("cow.off") m.performDisplayUpdate() X = sio.loadmat("anchors.mat") anchors = X['anchors'] anchorsIdx = X['anchorsIdx'].flatten().tolist() deltaCoords = X['deltaCoords'] L = makeLaplacianMatrixCotWeights(m.VPos, m.ITris, anchorsIdx, anchorWeights) m.VPos = solveLaplacianMatrix(L, deltaCoords, anchors, anchorWeights) m.saveOffFile("LapCow.off") if __name__ == '__main__3': anchorWeights = 100 m = getSphereMesh(1, 2) print "BBox Before: ", m.getBBox() m.performDisplayUpdate() anchorsIdx = np.random.randint(0, len(m.vertices), 30).tolist() L = makeLaplacianMatrixCotWeights(m.VPos, m.ITris, anchorsIdx, anchorWeights) sio.savemat("L.mat", {"L":L}) deltaCoords = L.dot(m.VPos)[0:len(m.vertices), :] anchors = m.VPos[anchorsIdx, :] anchors = anchors*5 m.VPos = solveLaplacianMatrix(L, deltaCoords, anchors, anchorWeights) print "BBox After:", m.getBBox()