|
| 1 | +""" |
| 2 | + |
| 3 | + This example demonstrates the intersection of two NURBS spheres. |
| 4 | +""" |
| 5 | +import time |
| 6 | + |
| 7 | +from mmcore.construction import cylinder_surface_2pt |
| 8 | +from mmcore.geom._nurbs_eval import _tuple_to_nurbs, NURBSSurfaceTuple |
| 9 | +from mmcore.geom._nurbs_transform import transform_nurbs |
| 10 | +from mmcore.geom.bvh.lbvh import AABB |
| 11 | +from mmcore.geom.nurbs import NURBSSurface |
| 12 | +from mmcore.construction import nurbs_surface |
| 13 | +from mmcore.numeric.intersection.ssx import ssx |
| 14 | + |
| 15 | +# Creating intersection objects |
| 16 | +import numpy as np |
| 17 | + |
| 18 | +import numpy as np |
| 19 | +from mmcore.geom._nurbs_eval import NURBSSurfaceTuple |
| 20 | + |
| 21 | + |
| 22 | +s1 = NURBSSurfaceTuple( |
| 23 | + order_u=4, |
| 24 | + order_v=4, |
| 25 | + knot_u=np.array([ 0.00000000, 0.00000000, 0.00000000, 0.00000000, |
| 26 | + 584.56714755, 1169.13429511, 1169.13429511, 1169.13429511, |
| 27 | + 1169.13429511]), |
| 28 | + knot_v=np.array([ 0.00000000, 0.00000000, 0.00000000, 0.00000000, |
| 29 | + 675.00000000, 675.00000000, 675.00000000, 675.00000000]), |
| 30 | + control_points=np.array([[[2488.56941006, 1499.08843254, 0.00000000], |
| 31 | + [2394.60779838, 1603.70965174, 0.00000000], |
| 32 | + [2394.60779838, 1675.09483487, 0.00000000], |
| 33 | + [2488.56941006, 1779.71605406, 0.00000000]], |
| 34 | + |
| 35 | + [[2582.53102174, 1394.46721335, 0.00000000], |
| 36 | + [2550.34379877, 1515.98031620, 152.12435146], |
| 37 | + [2550.34379877, 1762.82417041, 152.12435146], |
| 38 | + [2582.53102174, 1884.33727326, 0.00000000]], |
| 39 | + |
| 40 | + [[2754.10779838, 1284.40224330, 0.00000000], |
| 41 | + [2754.10779838, 1466.26757810, 257.50000000], |
| 42 | + [2754.10779838, 1812.53690851, 257.50000000], |
| 43 | + [2754.10779838, 1994.40224330, 0.00000000]], |
| 44 | + |
| 45 | + [[2925.68457502, 1394.46721335, 0.00000000], |
| 46 | + [2957.87179798, 1515.98031620, 152.12435146], |
| 47 | + [2957.87179798, 1762.82417041, 152.12435146], |
| 48 | + [2925.68457502, 1884.33727326, 0.00000000]], |
| 49 | + |
| 50 | + [[3019.64618670, 1499.08843254, 0.00000000], |
| 51 | + [3113.60779838, 1603.70965174, 0.00000000], |
| 52 | + [3113.60779838, 1675.09483487, 0.00000000], |
| 53 | + [3019.64618670, 1779.71605406, 0.00000000]]]), |
| 54 | + weights=np.array([[1.00000000, 1.00000000, 1.00000000, 1.00000000], |
| 55 | + [1.00000000, 1.00000000, 1.00000000, 1.00000000], |
| 56 | + [1.00000000, 1.00000000, 1.00000000, 1.00000000], |
| 57 | + [1.00000000, 1.00000000, 1.00000000, 1.00000000], |
| 58 | + [1.00000000, 1.00000000, 1.00000000, 1.00000000]]) |
| 59 | +) |
| 60 | +import numpy as np |
| 61 | +from mmcore.geom._nurbs_eval import NURBSSurfaceTuple |
| 62 | + |
| 63 | + |
| 64 | +s2 = NURBSSurfaceTuple( |
| 65 | + order_u=2, |
| 66 | + order_v=2, |
| 67 | + knot_u=np.array([ 0.00000000, 0.00000000, 854.10934693, 854.10934693]), |
| 68 | + knot_v=np.array([ 0.00000000, 0.00000000, 1119.84031048, 1119.84031048]), |
| 69 | + control_points=np.array([[[2372.10906381, 1470.47565841, 170.90189109], |
| 70 | + [2614.15055984, 2054.83790061, 228.66096126]], |
| 71 | + |
| 72 | + [[2953.02855072, 1248.46099847, -17.28737813], |
| 73 | + [3195.07004676, 1832.82324067, 40.47169204]]]), |
| 74 | + weights=np.array([[1.00000000, 1.00000000], |
| 75 | + [1.00000000, 1.00000000]]) |
| 76 | +) |
| 77 | + |
| 78 | + |
| 79 | +s1,s2=s2,s1 |
| 80 | +import logging |
| 81 | +from examples.ssx.common_helpers import parse_args, save_pkl, draw_ssx, VIEWER_INSTALLED, CurveMaterial, ControlNetMaterial, PointMaterial |
| 82 | +args = parse_args() |
| 83 | +logging.basicConfig(level=getattr(logging, args.loglevel, logging.INFO)) |
| 84 | +from mmcore.numeric.intersection.ssx import nurbs_ssx |
| 85 | + |
| 86 | +s = time.time() |
| 87 | +result = nurbs_ssx(s1, s2, atol=0.001, angle_tol=0.052) |
| 88 | + |
| 89 | +print(f"intersection computed at: {time.time() - s} sec.") |
| 90 | +print(len(result[0]), "branch(s)") |
| 91 | +print(len(result[1]), "pts(s)") |
| 92 | + |
| 93 | +if args.save_pkl or args.pkl_path is not None: |
| 94 | + path = save_pkl(s1, s2, result, fp=args.pkl_path) |
| 95 | + print(path.absolute().as_posix()) |
| 96 | + |
| 97 | +RENDER = args.viewer |
| 98 | + |
| 99 | +if RENDER: |
| 100 | + inter_curves_mat = CurveMaterial( |
| 101 | + (0.0, 1.0, 0.5, 1.0), |
| 102 | + show_control_net=args.show_inter_cpts, |
| 103 | + control_net_material=ControlNetMaterial((0.0, 1.0, 0.5, 0.7), control_point_material=PointMaterial((0.0, 1.0, 0.5, 0.4), size=8)), |
| 104 | + ) |
| 105 | + |
| 106 | + viewer = draw_ssx(s1, s2, result, intersection_curves_material=inter_curves_mat) |
| 107 | + |
| 108 | + viewer.run() |
0 commit comments