def display_curve(curve, ctrlpts=True):
    # Generate the visualisation configuration
    vis_config = VisMPL.VisConfig(legend=True, ctrlpts=ctrlpts)
    vis_comp = VisMPL.VisCurve2D(vis_config)
    # Draw the control point polygon and the evaluated curve
    curve.vis = vis_comp
    curve.render()
Exemplo n.º 2
0
    def surface_visualizer(self, surface):

        #%matplotlib

        # Create a visualization configuration instance with no legend, no axes and set the resolution to 120 dpi
        vis_config = VisMPL.VisConfig(ctrlpts=False, axes_equal=False)
        # Create a visualization method instance using the configuration above
        vis_obj = VisMPL.VisSurface(vis_config)
        # Set the visualization method of the curve object
        surface.vis = vis_obj
        surface.render(colormap=cm.cool, plot=False)
def test_curve3d_multi_fig_nowindow(bspline_curve3d):
    conf = VisMPL.VisConfig()
    vis = VisMPL.VisCurve3D(config=conf)

    multi = operations.decompose_curve(bspline_curve3d)
    multi.vis = vis
    multi.render(plot=False)

    assert os.path.isfile(conf.figure_image_filename)
    assert os.path.getsize(conf.figure_image_filename) > 0

    # Clean up temporary file if exists
    if os.path.isfile(conf.figure_image_filename):
        os.remove(conf.figure_image_filename)
def test_curve3d_fig_save(bspline_curve3d):
    conf = VisMPL.VisConfig()
    vis = VisMPL.VisCurve3D(config=conf)

    fname = "test-curve.png"

    bspline_curve3d.vis = vis
    bspline_curve3d.render(filename=fname, plot=False)

    assert os.path.isfile(fname)
    assert os.path.getsize(fname) > 0

    # Clean up temporary file if exists
    if os.path.isfile(fname):
        os.remove(fname)
def test_surf_fig_nowindow(bspline_surface):
    conf = VisMPL.VisConfig()
    vis = VisMPL.VisSurface(config=conf)

    fname = conf.figure_image_filename

    bspline_surface.vis = vis
    bspline_surface.render(plot=False)

    assert os.path.isfile(fname)
    assert os.path.getsize(fname) > 0

    # Clean up temporary file if exists
    if os.path.isfile(conf.figure_image_filename):
        os.remove(conf.figure_image_filename)
def test_surf_fig_save(bspline_surface):
    conf = VisMPL.VisConfig()
    vis = VisMPL.VisSurface(config=conf)

    fname = "test-surface.png"

    bspline_surface.vis = vis
    bspline_surface.render(filename=fname, plot=False)

    assert os.path.isfile(fname)
    assert os.path.getsize(fname) > 0

    # Clean up temporary file if exists
    if os.path.isfile(fname):
        os.remove(fname)
def test_surf_multi_fig_save(bspline_surface):
    conf = VisMPL.VisConfig()
    vis = VisMPL.VisSurfWireframe(config=conf)

    fname = "test-multi_surface.png"

    multi = operations.decompose_surface(bspline_surface)
    multi.vis = vis
    multi.render(filename=fname, plot=False)

    assert os.path.isfile(fname)
    assert os.path.getsize(fname) > 0

    # Clean up temporary file if exists
    if os.path.isfile(fname):
        os.remove(fname)
Exemplo n.º 8
0
def test_curve2d_multi_fig_save(bspline_curve2d):
    conf = VisMPL.VisConfig()
    vis = VisMPL.VisCurve2D(config=conf)

    fname = "test-multi_curve.png"

    multi = bspline_curve2d.decompose()
    multi.vis = vis
    multi.render(filename=fname, plot=False)

    assert os.path.isfile(fname)
    assert os.path.getsize(fname) > 0

    # Clean up temporary file if exists
    if os.path.isfile(fname):
        os.remove(fname)
def test_surf_multi_fig_nowindow(bspline_surface):
    conf = VisMPL.VisConfig()
    vis = VisMPL.VisSurfScatter(config=conf)

    fname = conf.figure_image_filename

    multi = operations.decompose_surface(bspline_surface)
    multi.vis = vis
    multi.render(plot=False)

    assert os.path.isfile(fname)
    assert os.path.getsize(fname) > 0

    # Clean up temporary file if exists
    if os.path.isfile(conf.figure_image_filename):
        os.remove(conf.figure_image_filename)
Exemplo n.º 10
0
def test_curve3d_multi_fig_save(bspline_curve3d):
    conf = VisMPL.VisConfig()
    vis = VisMPL.VisCurve3D(config=conf)

    fname = "test-multi_curve.png"

    data = operations.decompose_curve(bspline_curve3d)
    multi_shape = multi.CurveContainer(data)
    multi_shape.vis = vis
    multi_shape.render(filename=fname, plot=False)

    assert os.path.isfile(fname)
    assert os.path.getsize(fname) > 0

    # Clean up temporary file if exists
    if os.path.isfile(fname):
        os.remove(fname)
Exemplo n.º 11
0
def test_curve2d_multi_fig_nowindow(bspline_curve2d):
    conf = VisMPL.VisConfig()
    vis = VisMPL.VisCurve2D(config=conf)

    fname = conf.figure_image_filename

    data = operations.decompose_curve(bspline_curve2d)
    multi_shape = multi.CurveContainer(data)
    multi_shape.vis = vis
    multi_shape.render(plot=False)

    assert os.path.isfile(fname)
    assert os.path.getsize(fname) > 0

    # Clean up temporary file if exists
    if os.path.isfile(conf.figure_image_filename):
        os.remove(conf.figure_image_filename)
def test_surf_ctrlpts_offset(bspline_surface):
    conf = VisMPL.VisConfig()
    vis = VisMPL.VisSurface(config=conf)

    # Set control points grid offset
    vis.ctrlpts_offset = 3.5

    fname = "test-surface.png"

    bspline_surface.vis = vis
    bspline_surface.render(filename=fname, plot=False)

    assert os.path.isfile(fname)
    assert os.path.getsize(fname) > 0

    # Clean up temporary file if exists
    if os.path.isfile(fname):
        os.remove(fname)
Exemplo n.º 13
0
def build_vis(obj, **kwargs):
    """ Prepares visualization module for the input spline geometry.

    :param obj: input spline geometry object
    :return: spline geometry object updated with a visualization module
    """
    vis_config = VisMPL.VisConfig(**kwargs)
    if isinstance(obj, (NURBS.Curve, multi.CurveContainer)):
        if obj.dimension == 2:
            obj.vis = VisMPL.VisCurve2D(vis_config)
        elif obj.dimension == 3:
            obj.vis = VisMPL.VisCurve3D(vis_config)
        else:
            raise RuntimeError("Can only plot 2- or 3-dimensional curves")

    if isinstance(obj, (NURBS.Surface, multi.SurfaceContainer)):
        obj.vis = VisMPL.VisSurface(vis_config)

    if isinstance(obj, (NURBS.Volume, multi.VolumeContainer)):
        obj.vis = VisMPL.VisVolume(vis_config)

    return obj
Exemplo n.º 14
0
def display_landscape(landscape, delta=0.04):
    # Auto-generate knot vector
    landscape.knotvector_u = utilities.generate_knot_vector(
        landscape.degree_u, landscape.ctrlpts_size_u)
    landscape.knotvector_v = utilities.generate_knot_vector(
        landscape.degree_v, landscape.ctrlpts_size_v)

    # Set evaluation delta
    landscape.delta = delta

    # Evaluate curve
    landscape.evaluate()

    # Draw the control point polygon and the evaluated curve
    # Prepare the VisConfig
    vis_config = VisMPL.VisConfig(ctrlpts=False)

    vis_comp = VisMPL.VisSurfTriangle(vis_config)
    landscape.vis = vis_comp
    print(
        "Displaying the landscape. This consists of a large mountainous area with several peaks, a small hill, a river which runs between the hill and the mountains, and a lake which the river feeds into."
    )
    landscape.render(
        colormap=cm.get_cmap(name='terrain'))  # Apply a colormap to the render
Exemplo n.º 15
0
        [-4.4061, -0.056926, 6.3034]]

n = int(len(cp_o) / 2)

control_points = [[0, 0, 0]] * n

for i in range(len(y)):
    ang = np.linspace(0, 2 * np.pi, n)
    for th in ang:
        control_points.append([y[i] * np.cos(th), y[i] * np.sin(th), z[i]])

for c in cp_o:
    control_points.append(c)

t = int(len(control_points) / n)

surf.set_ctrlpts(control_points, t, n)

surf.knotvector_u = utilities.generate_knot_vector(surf.degree_u, t)
surf.knotvector_v = utilities.generate_knot_vector(surf.degree_v, n)

surf.evaluate()

# Visualization config
vis_config = vis.VisConfig(figure_size=[30, 15])
# Visualization component
vis_comp = vis.VisSurface(vis_config)
# Set visualization component of the surface
surf.vis = vis_comp
# Render the surface
surf.render()
Exemplo n.º 16
0
# Fix file path
os.chdir(os.path.dirname(os.path.realpath(__file__)))

# Create a BSpline (NUBS) curve instance
curve = BSpline.Curve()

# Set degree
curve.degree = 2

# Set control points for a periodic curve
curve.ctrlpts = [[1, 0], [-1, 0], [-1.5, 1.5], [1.5, -1.5], [1, 0], [-1, 0]]

# Knot vector
curve.knotvector = [0, 1, 2, 3, 4, 5, 6, 7, 8]

# Set evaluation delta
curve.sample_size = 100

# Evaluate curve
curve.evaluate()

# Draw the control point polygon and the evaluated curve
vis_config = VisMPL.VisConfig(ctrlpts=False, legend=False)
vis_comp = VisMPL.VisCurve2D(vis_config)
curve.vis = vis_comp
curve.render()

# Good to have something here to put a breakpoint
pass
Exemplo n.º 17
0
from geomdl.shapes import curve2d

# Try to load the visualization module
try:
    render = True
    from geomdl.visualization import VisMPL
except ImportError:
    render = False

# Generate a NURBS full circle from 7 control points
circle = curve2d.full_circle2(radius=5.0)
circle.delta = 0.01

# Render the circle and the control points polygon
if render:
    vis_config = VisMPL.VisConfig(ctrlpts=True, figure_size=[9, 8])
    vis_comp = VisMPL.VisCurve2D(config=vis_config)
    circle.vis = vis_comp
    circle.render()

# Decompose the circle into Bezier curve segments
bezier_segments = circle.decompose()

# Prepare Bezier segments for plotting
bezier_segments.delta = 0.01

# Render the Bezier curve segments and their control points polygons
if render:
    vis_config = VisMPL.VisConfig(ctrlpts=True, figure_size=[9, 8])
    vis_comp = VisMPL.VisCurve2D(config=vis_config)
    bezier_segments.vis = vis_comp
# Set control points
surf.set_ctrlpts(*exchange.import_txt("../ex_surface01.cpt", two_dimensional=True))

# Set knot vectors
surf.knotvector_u = [0.0, 0.0, 0.0, 0.0, 1.0, 2.0, 3.0, 3.0, 3.0, 3.0]
surf.knotvector_v = [0.0, 0.0, 0.0, 0.0, 1.0, 2.0, 3.0, 3.0, 3.0, 3.0]

# Set sample size
surf.sample_size = 30

# Set surface tessellation component
surf.tessellator = tessellate.TrimTessellate()

# Set visualization component
visconf = vis.VisConfig(ctrlpts=False, legend=False, trims=False)
surf.vis = vis.VisSurface(config=visconf)

# Generate circular trim curves with different sense
tcrv1 = analytic.Circle(origin=(0.25, 0.25), radius=0.20)
tcrv1.opt = ['sense', 1]
tcrv2 = analytic.Circle(origin=(0.75, 0.75), radius=0.20)
tcrv2.opt = ['sense', 1]
trim_curves = [tcrv1, tcrv2]

# Set trim curves (as a list)
surf.trims = trim_curves

# Visualize surface
surf.render(colormap=cm.copper)
Exemplo n.º 19
0
import numpy as np
import matplotlib.pyplot as plt
from geomdl import fitting
from geomdl import exchange
from geomdl.visualization import VisMPL as vis
'''
todo: fit 3d curves to central axes of the toroid experiments
'''

con_toroid = exchange.import_csv("con_toroid_caxis.csv",delimiter = ',')
print(len(con_toroid))
toroid = exchange.import_csv("toroid_caxis.csv",delimiter = ',')
print(toroid)

curve = fitting.approximate_curve(toroid,degree = 2,ctrlpts_size = 10)
curve1 = fitting.approximate_curve(con_toroid,degree = 2,ctrlpts_size = 10-)
# Plot the interpolated curve
curve.delta = 0.005
curve.vis = vis.VisCurve3D(vis.VisConfig(ctrlpts=False))
curve.render()

# Plot the interpolated curve
curve1.delta = 0.005
curve1.vis = vis.VisCurve3D(vis.VisConfig(ctrlpts=False))
curve1.render()
Exemplo n.º 20
0
    def _execute(self):

        print('Process of field surface evaluation started')
        start = time.time()
        if not os.path.exists(self.path + 'surface_evaluation/'):
            os.makedirs(self.path + 'surface_evaluation/')

        odP = outlier_detector_Parameters()
        tfP = terrain_filter_Parameters()
        tgP = terrain_grid_Parameters()
        sfP = surface_fit_Parameters()

        out_flag = self.outlier_detector(points=self.dws_point_cloud,
                                         metric=odP.METRIC,
                                         method=odP.METHOD,
                                         radius=odP.RADIUS,
                                         deviance=odP.DEVIANCE,
                                         K=odP.K)

        store_point_cloud(self.path + 'surface_evaluation/' + "clean_roi.las",
                          self.dws_point_cloud[out_flag, :], self.header)
        save_img(self.dws_point_cloud[out_flag, :], 'clean_roi_0_0',
                 self.path + 'surface_evaluation/', 0, 0)
        save_img(self.dws_point_cloud[out_flag, :], 'clean_roi_0_90',
                 self.path + 'surface_evaluation/', 0, 90)

        print('outliers removed .....')
        terrain_points = self.terrain_filter(
            points=self.dws_point_cloud[out_flag, :],
            method=tfP.METHOD,
            window_size=tfP.WINDOW_SIZE,
            window_stride=tfP.WINDOW_STRIDE,
            quantile=tfP.WINDOW_QUANTILE,
            k=tfP.K)
        print('terrain points founded .....')
        terrain_grid_points = self.terrain_grid(
            points=terrain_points,
            metric=tgP.METRIC,
            K=tgP.K,
            grid_resolution=tgP.GRID_RESOLUTION)
        print('terrain grid was formed .....')

        surface = self.surface_fit(terrain_grid=terrain_grid_points,
                                   grid_resolution=tgP.GRID_RESOLUTION,
                                   u_degree=sfP.U_DEGREE,
                                   v_degree=sfP.V_DEGREE,
                                   delta=sfP.DELTA)
        # Create a visualization configuration instance with no legend, no axes and set the resolution to 120 dpi
        vis_config = VisMPL.VisConfig(ctrlpts=False, axes_equal=False)
        # Create a visualization method instance using the configuration above
        vis_obj = VisMPL.VisSurface(vis_config)
        # Set the visualization method of the curve object
        surface.vis = vis_obj
        surface.render(filename=self.path + 'surface_evaluation/' +
                       "terrain.png",
                       colormap=cm.cool,
                       plot=False)
        print('surface was modeled .....')

        # Get the evaluated points
        surface_points = np.array(surface.evalpts)
        print('de-terrain points process')

        deTerreained_points = np.zeros_like(self.dws_point_cloud[out_flag, :])

        for i, point in enumerate(tqdm(self.dws_point_cloud[out_flag, :])):

            clean_point = point.copy()
            point_dist = np.array(
                ((surface_points[:, 0] - point[0])**2 +
                 (surface_points[:, 1] - point[1])**2)**(0.5))

            clean_point[2] = clean_point[2] - surface_points[
                np.argmin(point_dist), 2]
            deTerreained_points[i] = clean_point

        deTerreained_points[:, 2] = deTerreained_points[:, 2] + np.abs(
            deTerreained_points[:, 2].min())
        store_point_cloud(
            self.path + 'surface_evaluation/' + "de-terrained_roi.las",
            deTerreained_points, self.header)

        save_img(deTerreained_points, 'de-terrained_roi_0_0',
                 self.path + 'surface_evaluation/', 0, 0)
        save_img(deTerreained_points, 'de-terrained_roi_0_90',
                 self.path + 'surface_evaluation/', 0, 90)
        print('point cloud was de-terrained ......')
        end = time.time()

        print('Time:{}'.format(end - start))
# Fix file path
os.chdir(os.path.dirname(os.path.realpath(__file__)))

# Create a NURBS curve instance (full circle)
curve = NURBS.Curve()

# Set evaluation delta
curve.delta = 0.01

# Set up curve
curve.read_ctrlpts_from_txt("ex_curve04.cptw")
curve.degree = 2
# Use a specialized knot vector
curve.knotvector = [0, 0, 0, 0.25, 0.25, 0.5, 0.5, 0.75, 0.75, 1, 1, 1]

# Convert to a 3D curve
curve3d = curve.add_dimension()

# Translate curve to z = 5
curve3d.translate((0, 0, 5))

# Draw the control point polygon and the evaluated curve
if render_curve:
    vis_config = VisMPL.VisConfig(ctrlpts=True)
    vis_comp = VisMPL.VisCurve3D(vis_config)
    curve3d.vis = vis_comp
    curve3d.render()

# Good to have something here to put a breakpoint
pass
Exemplo n.º 22
0
#                 (disp_X[1,7], -disp_Z[1,7]),]
# curve1.knotvector = (0.0, 0.0, 0.0, 0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 5.0, 5.0, 5.0)
# curve2.ctrlpts =[(disp_X[2,0], -disp_Z[2,0]),
#                 (disp_X[2,1], -disp_Z[2,1]),
#                 (disp_X[2,2], -disp_Z[2,2]),
#                 (disp_X[2,3], -disp_Z[2,3]),
#                 (disp_X[2,4], -disp_Z[2,4]),
#                 (disp_X[2,5], -disp_Z[2,5]),
#                 (disp_X[2,6], -disp_Z[2,6]),
#                 (disp_X[2,7], -disp_Z[2,7]),]
# curve2.knotvector = (0.0, 0.0, 0.0, 0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 5.0, 5.0, 5.0)

# multi_curve_x = Multi.MultiCurve(curve0, curve1, curve2)

multi_curve.delta = 0.05
vis_config = VisMPL.VisConfig(legend=False)
multi_curve.vis = VisMPL.VisCurve2D(vis_config)
multi_curve.render()

print("Prozes time:  %s seconds ---" % (time.time() - start_time))
print("Exit!")

# print('Kontrollpunkte und Gewichte:')

# for i in range(curve_geometry.NbPoles):
#     pole = curve_geometry.Pole(i)
#     weight = curve_geometry.Weight(i)

#     print('  ', i, pole, weight)

# print()
Exemplo n.º 23
0
# Get the control points from the generated grid
surf04.ctrlpts2d = sg04.grid

# Set knot vectors
surf04.knotvector_u = utilities.generate_knot_vector(surf04.degree_u,
                                                     surf04.ctrlpts_size_u)
surf04.knotvector_v = utilities.generate_knot_vector(surf04.degree_v,
                                                     surf04.ctrlpts_size_v)

# Construct the parametric volume with a uniform knot vector
pvolume = construct.construct_volume('w',
                                     surf01,
                                     surf02,
                                     surf03,
                                     surf04,
                                     degree=2)

# Visualize volume
pvolume.vis = vis.VisVolume(vis.VisConfig(ctrlpts=True, evalpts=False))
pvolume.render()

# Knot vector refinement
operations.refine_knotvector(pvolume, [1, 1, 1])

# Visualize volume after knot insertions
pvolume.render()

# Good to have something here to put a breakpoint
pass
# -*- coding: utf-8 -*-
"""
    Question 2a: Decompose the heart-shaped object in question 1 into Bezier curves and show all control
    points for each Bezier curve.
"""

import os
from geomdl import BSpline
from geomdl import utilities
from geomdl import operations
from geomdl.visualization import VisMPL
from question_1 import generate_heart

# Set up the visualisation settings
vis_config = VisMPL.VisConfig(
    legend=False,
    ctrlpts=True)  # Set ctrlpts=True to plot control points with the curves
vis_comp = VisMPL.VisCurve2D(vis_config)

#
# Create the decomposed heart
#

# Generate the heart
heart = generate_heart()

# Decompose the B-Spline into Bezier curves
heart_bezier = operations.decompose_curve(heart)

# Set evaluation delta
heart_bezier.delta = 0.001
Exemplo n.º 25
0
def main():
    points = np.loadtxt("N2_RV_P0.txt")

    zmin_loc_temp = np.where(points[:, 1] == 0)[0]
    zmin_loc = zmin_loc_temp

    # points = remove_3dpoint(points,zmin_loc)
    N = 5
    slice(N, points)

    slice0 = slice.slices[0]
    x0 = slice0[:, 0]
    y0 = slice0[:, 1]
    z0 = slice0[:, 2]
    slice1 = slice.slices[1]
    x1 = slice1[:, 0]
    y1 = slice1[:, 1]
    z1 = slice1[:, 2]
    slice2 = slice.slices[2]
    x2 = slice2[:, 0]
    y2 = slice2[:, 1]
    z2 = slice2[:, 2]
    slice3 = slice.slices[3]
    x3 = slice3[:, 0]
    y3 = slice3[:, 1]
    z3 = slice3[:, 2]
    slice4 = slice.slices[4]
    x4 = slice4[:, 0]
    y4 = slice4[:, 1]
    z4 = slice4[:, 2]
    print(np.shape(points))
    ranges = slice.bins

    diameter = x0.max() - x0.min()
    radius = diameter
    height = z0.max()

    diameter1 = x1.max() - x1.min()
    radius1 = diameter1
    height1 = z1.max()

    diameter2 = x2.max() - x2.min()
    radius2 = diameter2
    height2 = z2.max()

    diameter3 = x3.max() - x3.min()
    radius3 = diameter3
    height3 = z3.max()

    diameter4 = x4.max() - x4.min()
    radius4 = diameter4 / 2
    height4 = x4.max()

    # Generate a cylindrical surface using the shapes component
    cylinder = surface.cylinder(radius, height)
    # vis_config = VisMPL.VisConfig(ctrlpts=True)
    # vis_comp = VisMPL.VisSurface(config=vis_config)
    # cylinder.vis = vis_comp
    # cylinder.render()
    cyl_points = cylinder.evalpts
    print("*****************")
    # print(len(cyl_points))
    print("*****************")

    cylinder1 = surface.cylinder(radius1, height1)
    cyl_points1 = cylinder1.evalpts
    # vis_config = VisMPL.VisConfig(ctrlpts=True)
    # vis_comp = VisMPL.VisSurface(config=vis_config)
    # cylinder1.vis = vis_comp
    # cylinder1.render()

    cylinder2 = surface.cylinder(radius2, height2)
    cyl_points2 = cylinder2.evalpts
    # vis_config = VisMPL.VisConfig(ctrlpts=True)
    # vis_comp = VisMPL.VisSurface(config=vis_config)
    # cylinder2.vis = vis_comp
    # cylinder2.render()

    cylinder3 = surface.cylinder(radius3, height3)
    cyl_points3 = cylinder3.evalpts
    # vis_config = VisMPL.VisConfig(ctrlpts=True)
    # vis_comp = VisMPL.VisSurface(config=vis_config)
    # cylinder2.vis = vis_comp
    # cylinder2.render()

    cylinder4 = surface.cylinder(radius4, height4)
    cyl_points4 = cylinder4.evalpts
    # vis_config = VisMPL.VisConfig(ctrlpts=True)
    # vis_comp = VisMPL.VisSurface(config=vis_config)
    # cylinder4.vis = vis_comp
    # cylinder4.render()

    #try using points from the surface not the control points
    cylinder_cpts = np.array(cylinder.ctrlpts)
    cylinder_cpts1 = np.array(cylinder1.ctrlpts)
    cylinder_cpts2 = np.array(cylinder2.ctrlpts)
    cylinder_cpts3 = np.array(cylinder3.ctrlpts)
    cylinder_cpts4 = np.array(cylinder4.ctrlpts)

    a = np.array(cdist(np.array(cyl_points), slice0)).min(axis=0)
    b = np.array(cdist(np.array(cyl_points1), slice1)).min(axis=0)
    c = np.array(cdist(np.array(cyl_points2), slice2)).min(axis=0)
    d = np.array(cdist(np.array(cyl_points3), slice3)).min(axis=0)
    e = np.array(cdist(np.array(cyl_points4), slice4)).min(axis=0)

    test = np.zeros((len(cylinder_cpts), 3))
    test1 = np.zeros((len(cylinder_cpts1), 3))
    test2 = np.zeros((len(cylinder_cpts2), 3))
    test3 = np.zeros((len(cylinder_cpts3), 3))
    test4 = np.zeros((len(cylinder_cpts4), 3))

    for i in range(0, len(cylinder_cpts)):
        test[i] = (cylinder_cpts[i] / np.linalg.norm(cylinder_cpts[i])) * a[i]
        test1[i] = (cylinder_cpts1[i] /
                    np.linalg.norm(cylinder_cpts1[i])) * b[i]
        test2[i] = (cylinder_cpts2[i] /
                    np.linalg.norm(cylinder_cpts2[i])) * c[i]
        test3[i] = (cylinder_cpts3[i] /
                    np.linalg.norm(cylinder_cpts3[i])) * d[i]
        test4[i] = (cylinder_cpts4[i] /
                    np.linalg.norm(cylinder_cpts4[i])) * e[i]

    test_zeros_loc = np.where(test[:, 2] == 0)[0]
    test1_zeros_loc = np.where(test1[:, 2] == 0)[0]
    test2_zeros_loc = np.where(test2[:, 2] == 0)[0]
    test3_zeros_loc = np.where(test3[:, 2] == 0)[0]
    test4_zeros_loc = np.where(test4[:, 2] == 0)[0]

    test = remove_3dpoint(test, test_zeros_loc)
    test1 = remove_3dpoint(test1, test1_zeros_loc)
    test2 = remove_3dpoint(test2, test2_zeros_loc)
    test3 = remove_3dpoint(test3, test3_zeros_loc)
    test4 = remove_3dpoint(test4, test4_zeros_loc)

    test = np.array(
        [test[:, 0], test[:, 1],
         np.ones(len(test[:, 2])) * ranges[0]]).T
    test1 = np.array(
        [test1[:, 0], test1[:, 1],
         np.ones(len(test1[:, 2])) * ranges[1]]).T
    test2 = np.array(
        [test2[:, 0], test2[:, 1],
         np.ones(len(test2[:, 2])) * ranges[2]]).T
    test3 = np.array(
        [test3[:, 0], test3[:, 1],
         np.ones(len(test3[:, 2])) * ranges[3]]).T
    test4 = np.array(
        [test4[:, 0], test4[:, 1],
         np.ones(len(test4[:, 2])) * ranges[4]]).T

    # for i in range(0,len(test1)):
    # test1[i] = test1[i] + [0,0,height]
    # test2[i] = test2[i]+[0,0,height1]
    # test3[i] = test3[i]+[0,0,height2]

    test = remove_3dpoint(test, len(test) - 1)
    test1 = remove_3dpoint(test1, len(test1) - 1)
    test2 = remove_3dpoint(test2, len(test2) - 1)
    test3 = remove_3dpoint(test3, len(test3) - 1)
    test4 = remove_3dpoint(test4, len(test4) - 1)

    # test = np.insert(test,[0,len(test)],[[0,0,-5],[0,0,ranges[0]]],axis=0)
    # test1 = np.insert(test1,[0,len(test1)],[0,0,ranges[1]],axis=0)
    # test2 = np.insert(test2,[0,len(test2)],[0,0,ranges[2]],axis=0)
    test = np.insert(
        test,
        [len(test) - 2, len(test) - 1, len(test)], [test[0], test[1], test[2]],
        axis=0)
    test1 = np.insert(
        test1, [len(test1) - 2, len(test1) - 1,
                len(test1)], [test1[0], test1[1], test1[2]],
        axis=0)
    test2 = np.insert(
        test2, [len(test2) - 2, len(test2) - 1,
                len(test2)], [test2[0], test2[1], test2[2]],
        axis=0)
    test3 = np.insert(
        test3, [len(test3) - 2, len(test3) - 1,
                len(test3)], [test3[0], test3[1], test3[2]],
        axis=0)
    test = np.insert(
        test4, [len(test4) - 2, len(test4) - 1,
                len(test4)], [test4[0], test4[1], test4[2]],
        axis=0)

    # print(test)
    # print(test1)
    # print(test2)
    # print(test3)

    X = np.row_stack((test, test1, test2, test3, test4))
    print(X)
    # np.random.shuffle(X)

    np.savetxt("cpts_test.csv", X, delimiter=",")
    # np.savetxt("cpts_test1.csv", test1, delimiter=",")
    fig = plt.figure()
    ax = plt.axes(projection="3d")
    ax.scatter3D(test[:, 0],
                 test[:, 1],
                 np.ones(len(test[:, 2])) * ranges[0],
                 color='red')
    ax.scatter3D(test1[:, 0], test1[:, 1], test1[:, 2], color='blue')
    ax.scatter3D(test2[:, 0], test2[:, 1], test2[:, 2], color='green')
    ax.scatter3D(test3[:, 0], test3[:, 1], test3[:, 2], color='yellow')
    ax.scatter3D(test4[:, 0], test4[:, 1], test4[:, 2], color='purple')
    # ax.scatter3D(cylinder_cpts[:,0],cylinder_cpts[:,1],cylinder_cpts[:,2])
    # ax.scatter3D(cylinder_cpts1[:,0],cylinder_cpts1[:,1],cylinder_cpts1[:,2])

    # try fitting a NURBS Surface
    surf = NURBS.Surface()
    surf.delta = 0.03
    p_ctrlpts = exchange.import_csv("cpts_test.csv")
    print(len(p_ctrlpts))
    p_weights = np.ones((len(p_ctrlpts)))
    p_size_u = 9
    p_size_v = 5
    p_degree_u = 3
    p_degree_v = 3
    t_ctrlptsw = compat.combine_ctrlpts_weights(p_ctrlpts, p_weights)
    n_ctrlptsw = compat.flip_ctrlpts_u(t_ctrlptsw, p_size_u, p_size_v)
    n_knotvector_u = utils.generate_knot_vector(p_degree_u, p_size_u)
    n_knotvector_v = utils.generate_knot_vector(p_degree_v, p_size_v)

    surf.degree_u = p_degree_u
    surf.degree_v = p_degree_v
    surf.set_ctrlpts(n_ctrlptsw, p_size_u, p_size_v)
    surf.knotvector_u = n_knotvector_u
    surf.knotvector_v = n_knotvector_v
    vis_config = vis.VisConfig(ctrlpts=True, axes=True, legend=True)
    surf.vis = vis.VisSurface(vis_config)
    surf.evaluate()
    surf.render()
# Fix file path
os.chdir(os.path.dirname(os.path.realpath(__file__)))

# Create a NURBS curve instance (full circle)
curve = NURBS.Curve()

# Set evaluation delta
curve.delta = 0.01

# Set up curve
curve.read_ctrlpts_from_txt("ex_curve04.cptw")
curve.degree = 2
# Use a specialized knot vector
curve.knotvector = [0, 0, 0, 0.25, 0.25, 0.5, 0.5, 0.75, 0.75, 1, 1, 1]

# Decompose the curve into Bezier curve segments
bezier = curve.decompose()

# Plot the curves using the curve container
bezier.delta = 0.01

if render_curve:
    vis_config = VisMPL.VisConfig(figure_size=[8, 8])
    vis_comp = VisMPL.VisCurve2D(vis_config)
    bezier.vis = vis_comp
    bezier.render()

# Good to have something here to put a breakpoint
pass
    # Set degrees
    surf03.degree_u = 1
    surf03.degree_v = 1

    # Get the control points from the generated grid
    surf03.ctrlpts2d = sg03.grid

    # Set knot vectors
    surf03.knotvector_u = utilities.generate_knot_vector(
        surf03.degree_u, surf03.ctrlpts_size_u)
    surf03.knotvector_v = utilities.generate_knot_vector(
        surf03.degree_v, surf03.ctrlpts_size_v)

    # Construct the parametric volume
    pvolume = construct.construct_volume(surf01, surf02, surf03, degree=1)
    pvolume.vis = vis.VisVoxel(vis.VisConfig(ctrlpts=False))
    pvolume.delta_u = pvolume.delta_v = 0.025
    pvolume.delta_w = 0.05
    pvolume.render(evalcolor="firebrick", use_mp=True, num_procs=16)

    # Extract surfaces from the parametric volume
    surfvol = construct.extract_surfaces(pvolume)

    # Construct the isosurface
    msurf = multi.SurfaceContainer(surfvol['uv'][0], surfvol['uv'][-1],
                                   surfvol['uw'][0], surfvol['uw'][-1],
                                   surfvol['vw'][0], surfvol['vw'][-1])
    msurf.vis = vis.VisSurface(vis.VisConfig(ctrlpts=False))
    msurf.delta = 0.05
    msurf.render(evalcolor=[
        "skyblue", "cadetblue", "crimson", "crimson", "crimson", "crimson"
Exemplo n.º 28
0
# Set degrees
surf.degree_u = 3
surf.degree_v = 3

# Get the control points from the generated grid
surf.ctrlpts2d = surfgrid.grid

# Set knot vectors
surf.knotvector_u = utilities.generate_knot_vector(surf.degree_u, surf.ctrlpts_size_u)
surf.knotvector_v = utilities.generate_knot_vector(surf.degree_v, surf.ctrlpts_size_v)

# Set sample size of the surface
surf.sample_size = 50

# Generate the visualization component and its configuration
vis_config = vis.VisConfig(ctrlpts=True, legend=False)
vis_comp = vis.VisSurface(vis_config)

# Set visualization component of the surface
surf.vis = vis_comp

# Plot the surface
surf.render()

# Export the surface as a .stl file
exchange.export_stl(surf, "bump_smoother_1pt-padding.stl")

# Good to have something here to put a breakpoint
pass
Exemplo n.º 29
0
    [0, 4, 0],
    [0, 8, -3],
    [2, 0, 6],
    [2, 4, 0],
    [2, 8, 0],
    [4, 0, 0],
    [4, 4, 0],
    [4, 8, 3],
    [6, 0, 0],
    [6, 4, -3],
    [6, 8, 0],
]
surf.set_ctrlpts(control_points, 4, 3)
surf.knotvector_u = [0, 0, 0, 0, 1, 1, 1, 1]
surf.knotvector_v = [0, 0, 0, 1, 1, 1]

# surf.delta = 0.05
surf.delta = 0.20  # 0.20 for testing, was originally 0.05 for smoothness

# 0.20, with 1.0 / 0.20 = 5.0,
# gives a matrix of [5x5] evalution points found by > surf.evalpts

# surf.vis = vis.VisSurface()
surf.vis = vis.VisSurface(vis.VisConfig(alpha=0.8))

surface_points = surf.evalpts
print(surface_points)
surf.render()

# surface 2, to come.
Exemplo n.º 30
0
# Create a NURBS surface instance
surf = NURBS.Surface()

# Set degress
surf.degree_u = 2
surf.degree_v = 2

# Set control points
surf.set_ctrlpts(*exchange.import_txt("ex_torus.cptw", two_dimensional=True))

# Set knot vectors
surf.knotvector_u = [0, 0, 0, 0.25, 0.25, 0.5, 0.5, 0.75, 0.75, 1, 1, 1]
surf.knotvector_v = [0, 0, 0, 0.25, 0.25, 0.5, 0.5, 0.75, 0.75, 1, 1, 1]

# Set sample size and evaluate surface
surf.sample_size = 25
surf.evaluate()

# Import colormaps
from matplotlib import cm

# Plot the surface
vis_config = VisMPL.VisConfig(ctrlpts=True, axes=True, legend=False)
vis_comp = VisMPL.VisSurfTriangle(vis_config)
surf.vis = vis_comp
surf.render(colormap=cm.coolwarm)

# Good to have something here to put a breakpoint
pass