def intersect_surface_plane_uv(surface, plane, samples_u=50, samples_v=50, init_samples=10, ortho_samples=10, tolerance=1e-3, maxiter=50): # Unsorted! u_min, u_max = surface.get_u_min(), surface.get_u_max() v_min, v_max = surface.get_v_min(), surface.get_v_max() u_range = np.linspace(u_min, u_max, num=samples_u) v_range = np.linspace(v_min, v_max, num=samples_v) points = [] for u in u_range: curve = SvIsoUvCurve(surface, 'U', u) ps = intersect_curve_plane(curve, plane, init_samples=init_samples, ortho_samples=ortho_samples, tolerance=tolerance, maxiter=maxiter) points.extend(ps) for v in v_range: curve = SvIsoUvCurve(surface, 'V', v) ps = intersect_curve_plane(curve, plane, init_samples=init_samples, ortho_samples=ortho_samples, tolerance=tolerance, maxiter=maxiter) points.extend(ps) return [tuple(p) for p in points]
def process(self): if not any(socket.is_linked for socket in self.outputs): return surface_s = self.inputs['Surface'].sv_get() value_s = self.inputs['Value'].sv_get() if isinstance(surface_s[0], SvSurface): surface_s = [surface_s] value_s = ensure_nesting_level(value_s, 2) u_curves_out = [] v_curves_out = [] for surfaces, values in zip_long_repeat(surface_s, value_s): new_u_curves = [] new_v_curves = [] for surface, value in zip_long_repeat(surfaces, values): u_curve = SvIsoUvCurve.take(surface, 'V', value) v_curve = SvIsoUvCurve.take(surface, 'U', value) new_u_curves.append(u_curve) new_v_curves.append(v_curve) if self.join: u_curves_out.extend(new_u_curves) v_curves_out.extend(new_v_curves) else: u_curves_out.append(new_u_curves) v_curves_out.append(new_v_curves) self.outputs['UCurve'].sv_set(u_curves_out) self.outputs['VCurve'].sv_set(v_curves_out)
def process(self): if not any(socket.is_linked for socket in self.outputs): return surface_s = self.inputs['Surface'].sv_get() if isinstance(surface_s[0], SvSurface): surface_s = [surface_s] curves_out = [] for surfaces in surface_s: for surface in surfaces: u_min, u_max = surface.get_u_min(), surface.get_u_max() v_min, v_max = surface.get_v_min(), surface.get_v_max() if self.cyclic_mode == 'NO': curve1 = SvIsoUvCurve(surface, 'V', v_min, flip=False) curve2 = SvIsoUvCurve(surface, 'U', u_max, flip=False) curve3 = SvIsoUvCurve(surface, 'V', v_max, flip=True) curve4 = SvIsoUvCurve(surface, 'U', u_min, flip=True) new_curves = [ SvConcatCurve([curve1, curve2, curve3, curve4]) ] elif self.cyclic_mode == 'U': curve1 = SvIsoUvCurve(surface, 'V', v_max, flip=False) curve2 = SvIsoUvCurve(surface, 'V', v_min, flip=False) new_curves = [curve1, curve2] elif self.cyclic_mode == 'V': curve1 = SvIsoUvCurve(surface, 'U', u_max, flip=False) curve2 = SvIsoUvCurve(surface, 'U', u_min, flip=False) new_curves = [curve1, curve2] else: raise Exception("Unsupported mode") curves_out.append(new_curves) self.outputs['Boundary'].sv_set(curves_out)
def ortho_project_surface(src_point, surface, init_samples=10, maxiter=30, tolerance=1e-4): """ Find the orthogonal projection of src_point to surface. dependencies: scipy """ u_min, u_max = surface.get_u_min(), surface.get_u_max() v_min, v_max = surface.get_v_min(), surface.get_v_max() u0 = (u_min + u_max) / 2.0 v0 = (v_min + v_max) / 2.0 fixed_axis = 'U' fixed_axis_value = u0 prev_fixed_axis_value = v0 prev_point = surface.evaluate(u0, v0) i = 0 while True: if i > maxiter: raise Exception("No convergence") curve = SvIsoUvCurve(surface, fixed_axis, fixed_axis_value) projection = ortho_project_curve(src_point, curve, init_samples=init_samples) point = projection.nearest dv = point - prev_point fixed_axis_value = projection.nearest_u if np.linalg.norm(dv) < tolerance: break if fixed_axis == 'U': fixed_axis = 'V' else: fixed_axis = 'U' prev_fixed_axis_value = fixed_axis_value prev_point = point i += 1 if fixed_axis == 'U': u, v = prev_fixed_axis_value, fixed_axis_value else: u, v = fixed_axis_value, prev_fixed_axis_value return u, v, point