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 transform(self, v: np.ndarray, f: np.ndarray) -> Tuple[np.ndarray, np.ndarray]: xs = v[:, 0] ys = v[:, 1] zs = v[:, 2] min_x = min(xs) max_x = max(xs) min_y = min(ys) max_y = max(ys) min_z = min(zs) max_z = max(zs) x_len = (max_x - min_x) * 0.5 y_len = (max_y - min_y) * 0.5 z_len = (max_z - min_z) * 0.5 x_mid = x_len + min_x y_mid = y_len + min_y z_mid = z_len + min_z largest_len = max(x_len, y_len, z_len) center = np.array([x_mid, y_mid, z_mid]) # 0 fix, 1 move, -1 flow s = [] deform_centers = [] for i in range(int(self.config[PIVOTS])): deform_centers.append(v[int(np.floor(self.config[PIVOT_LABEL[i]] * len(v)))]) for ve in v: dist = min([np.linalg.norm(ve - dc) for dc in deform_centers]) if dist < 0.05 * largest_len: s.append(1) elif dist < 0.5 * largest_len: s.append(-1) else: s.append(0) s = np.array(s) b = np.array([[t[0] for t in [(i, s[i]) for i in range(0, v.shape[0])] if t[1] >= 0]]).T b = b.astype(f.dtype) u_bc = np.zeros((b.shape[0], v.shape[1])) v_bc = np.zeros((b.shape[0], v.shape[1])) for bi in range(b.shape[0]): v_bc[bi] = v[b[bi]] if s[b[bi]] == 0: # Don't move handle 0 u_bc[bi] = v[b[bi]] elif s[b[bi]] == 1: old = v[b[bi]] displacement = old - center displacement *= self.config[DIS] u_bc[bi] = center + displacement d_bc = u_bc - v_bc d = igl.harmonic_weights(v, f, b, d_bc, 2) u = v + d return u, deepcopy(f)
def MinimalSurface(V, Nz, Iz, Al, Ar): Nz *= 1.05 V_borders = border_approximate(Nz, Iz, Al, Ar) V = np.row_stack([Nz, Iz, Al, Ar, V_borders, V]) b, bc = contrl_vertices(sV3, V) b, bc = contrl_vertices(sV5, bc) nilr_idx = contrl_vertices(sV5, np.row_stack([Nz, Iz, Al, Ar]), unique=False) V = igl.harmonic_weights(sV5, sF5, b, bc, 3) return V, sF5, bc, nilr_idx
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)