def run(self): if not self.copyData(): return if self.geo.getNumFaces() == 0 or self.geo.getNumVertexes() == 0: return mesh = self.geo.getTriangulateMesh() v = mesh.points() f = mesh.face_vertex_indices() # Find the open boundary bnd = igl.boundary_loop(f) # Map the boundary to a circle, preserving edge proportions bnd_uv = igl.map_vertices_to_circle(v, bnd) # Harmonic parametrization for the internal vertices uv = igl.harmonic_weights(v, f, bnd, bnd_uv, 1) arap = igl.ARAP(v, f, 2, np.zeros((0))) uv = arap.solve(np.zeros((0, 0)), uv) self.geo.setVertexAttribData(self.get_property("Attribute Name"), uv, attribType='vector3', defaultValue=[0, 0, 0]) if self.get_property("Show Mode") == "2d": self.geo.mesh.setVertexAttribData("pos", uv)
def test_arap2(self): num_b = 100 thetas = np.linspace(0, 2 * np.pi, num_b)[:, np.newaxis] r = thetas / (2 * np.pi) boundary = np.concatenate( [r * np.cos(thetas), np.sin(thetas), np.zeros([num_b, 1])], axis=1) edges = np.array([(i, (i + 1) % boundary.shape[0]) for i in range(boundary.shape[0])]) v, f = igl.triangulate(boundary[:, :2], edges, np.zeros([0, 0])) v = np.concatenate([v, np.zeros([v.shape[0], 1])], axis=1) b = igl.boundary_loop(f.astype(np.int32)) thetas = np.linspace(0, 2 * np.pi, len(b))[:, np.newaxis] circle_b = np.concatenate( [np.cos(thetas), np.sin(thetas), np.zeros([len(b), 1])], axis=1) v0 = igl.harmonic_weights(v, f.astype(np.int32), b, np.asfortranarray(circle_b), 1) print(circle_b.shape, b.shape, v.shape, v.shape) arap = igl.ARAP(v, f, 2, b) v2 = arap.solve(circle_b[:, :2], v0[:, :2]) self.assertEqual(v2.shape[0], v0.shape[0])
def test_slim(self): v, f, _ = igl.read_off("data/camelhead.off") b = igl.boundary_loop(f) thetas = np.linspace(0, 2 * np.pi, len(b))[:, np.newaxis] bc = np.concatenate([np.cos(thetas), np.sin(thetas), np.zeros_like(thetas)], axis=1) uv_initial_guess = igl.harmonic_weights(v, f, b, bc, 1) slim = igl.SLIM(v, f, uv_initial_guess[:, :2], b, bc[:, :2], igl.SLIM_ENERGY_TYPE_ARAP, 0.0) slim.solve(1) v2 = slim.vertices() self.assertEqual(v2.shape[0], v.shape[0]) self.assertTrue(v2.flags.c_contiguous)
def test_arap1(self): v, f, _ = igl.read_off("data/camelhead.off") b = igl.boundary_loop(f) thetas = np.linspace(0, 2 * np.pi, len(b))[:, np.newaxis] bc = np.concatenate([np.cos(thetas), np.sin(thetas), np.zeros_like(thetas)], axis=1) uv_initial_guess = igl.harmonic_weights(v, f, b, bc, 1) arap1 = igl.ARAP(v, f, 2, b) vp1 = arap1.solve(bc[:, :2], uv_initial_guess[:, :2]) self.assertEqual(vp1.shape[0], v.shape[0]) self.assertTrue(vp1.flags.c_contiguous) arap2 = igl.ARAP(v, f, 3, b) vp2 = arap2.solve(bc, uv_initial_guess) self.assertEqual(vp2.shape[0], v.shape[0]) self.assertTrue(vp2.flags.c_contiguous)
def run(self): if not self.copyData(): return if self.geo.getNumFaces() == 0 or self.geo.getNumVertexes() == 0: return mesh = self.geo.getTriangulateMesh() v = mesh.points() f = mesh.face_vertex_indices() bnd = igl.boundary_loop(f) bnd_uv = igl.map_vertices_to_circle(v, bnd) uv = igl.harmonic_weights(v, f, bnd, bnd_uv, 1) uv = np.hstack([uv, np.zeros((uv.shape[0], 1))]) self.geo.setVertexAttribData(self.get_property("Attribute Name"), uv, attribType='vector3', defaultValue=[0, 0, 0]) if self.get_property("Show Mode") == "2d": self.geo.mesh.setVertexAttribData("pos", uv)
def tutte(V, F): #Get Boundary and Edge L = igl.boundary_loop(F) sizeL = len(L) #Iterate over boundary bc = [] for i in range(sizeL): bc.append([ math.cos(math.pi * 2 / sizeL * i), math.sin(math.pi * 2 / sizeL * i) ]) bc = np.array(bc, dtype=np.double) print("L: : ", L.shape) #Iterate over edge, build some kind of sparse matrix,, E = igl.edges(F) I = [] J = [] Val = [] diag = np.zeros(len(V)) for i, e in enumerate(E): tp = 1.0 / 3 * np.linalg.norm((V[e[0]] - V[e[1]])) I.append(e[0]) J.append(e[1]) Val.append(tp) I.append(e[1]) J.append(e[0]) Val.append(tp) diag[e[0]] -= tp diag[e[1]] -= tp #Add diag value to sparse matrix for i, v in enumerate(V): I.append(i) J.append(i) Val.append(diag[i]) #A : Sparse matrix A = coo_matrix((Val, (I, J)), shape=(len(V), len(V))).tocsr() B_flat = np.zeros((len(V), 2), dtype=np.double) b = L.reshape(len(L), 1) #L -> Boundary Aeq = csr_matrix((0, 0), dtype=np.double) Beq = np.zeros(shape=(0, 1)) # print("A : ", A.shape) # print("B_flat : ", B_flat.shape) # print("b : ", b.shape) # print("bc : ", bc.shape) # print("Aeq: ", Aeq.shape) # print("Beq : ", Beq.shape) # print(A.shape) U = igl.min_quad_with_fixed(A, B_flat, b, bc, Aeq, Beq, False) return U[1], bc
elif key == ord('2'): # Plot the mesh in 2D using the UV coordinates as vertex coordinates viewer.data.set_mesh(V_uv, F) viewer.core.align_camera_center(V_uv, F) viewer.data.compute_normals() return False # Load a mesh in OFF format igl.readOFF("../../tutorial/shared/camelhead.off", V, F) # Fix two points on the boundary bnd = igl.eigen.MatrixXi() b = igl.eigen.MatrixXi(2, 1) igl.boundary_loop(F, bnd) b[0] = bnd[0] b[1] = bnd[int(bnd.size() / 2)] bc = igl.eigen.MatrixXd([[0, 0], [1, 0]]) # LSCM parametrization igl.lscm(V, F, b, bc, V_uv) # Scale the uv V_uv *= 5 # Plot the mesh viewer = igl.viewer.Viewer() viewer.data.set_mesh(V, F) viewer.data.set_uv(V_uv) viewer.callback_key_down = key_down
# Plot the 3D mesh viewer.data.set_mesh(V,F) viewer.core.align_camera_center(V,F) elif key == ord('2'): # Plot the mesh in 2D using the UV coordinates as vertex coordinates viewer.data.set_mesh(V_uv,F) viewer.core.align_camera_center(V_uv,F) viewer.data.compute_normals() return False # Load a mesh in OFF format igl.readOFF("../../tutorial/shared/camelhead.off", V, F) # Find the open boundary bnd = igl.eigen.MatrixXi() igl.boundary_loop(F,bnd) # Map the boundary to a circle, preserving edge proportions bnd_uv = igl.eigen.MatrixXd() igl.map_vertices_to_circle(V,bnd,bnd_uv) # Harmonic parametrization for the internal vertices igl.harmonic(V,F,bnd,bnd_uv,1,V_uv) # Scale UV to make the texture more clear V_uv *= 5; # Plot the mesh viewer = igl.viewer.Viewer() viewer.data.set_mesh(V, F) viewer.data.set_uv(V_uv)
def test_boundary_loop(self): l = igl.boundary_loop(self.f) self.assertEqual(len(l.shape), 1) self.assertEqual(l.dtype, self.f.dtype) self.assertTrue(l.flags.c_contiguous)
def test_boundary_loop(self): l = igl.boundary_loop(self.f) self.assertEqual(len(l.shape), 1) self.assertEqual(l.dtype, self.f.dtype)