示例#1
0
def test_compatibility_generate_ctrlptsw2d_file2(nurbs_surface):
    fname_in = FILE_NAME + "_in.txt"
    fname_out = FILE_NAME + "_out.txt"
    fname_final = FILE_NAME + "_final.txt"

    exchange.export_txt(nurbs_surface, fname_in, two_dimensional=True)

    compatibility.generate_ctrlpts2d_weights_file(fname_in, fname_out)
    compatibility.generate_ctrlptsw2d_file(fname_out, fname_final)
    ctrlpts, size_u, size_v = exchange.import_txt(fname_final, two_dimensional=True)
    ctrlptsw = compatibility.generate_ctrlptsw(ctrlpts)

    res_array = []
    for res in ctrlptsw:
        res_array.append(res)

    assert nurbs_surface.ctrlptsw == res_array
    assert nurbs_surface.ctrlpts_size_u == size_u
    assert nurbs_surface.ctrlpts_size_v == size_v

    # Clean up temporary file if exists
    if os.path.isfile(fname_in):
        os.remove(fname_in)
        os.remove(fname_out)
        os.remove(fname_final)
示例#2
0
def test_export_import_txt_surface1(bspline_surface):
    fname = FILE_NAME + ".txt"

    bspline_surface.sample_size = SAMPLE_SIZE
    exchange.export_txt(bspline_surface, fname, two_dimensional=False)

    # Import text file
    result = exchange.import_txt(fname, two_dimensional=False)

    res_array = []
    for res in result:
        res_array.append(res)

    assert res_array == bspline_surface.ctrlpts

    # Clean up temporary file if exists
    if os.path.isfile(fname):
        os.remove(fname)
示例#3
0
def test_export_import_txt_curve(bspline_curve3d):
    fname = FILE_NAME + ".txt"

    bspline_curve3d.sample_size = SAMPLE_SIZE
    exchange.export_txt(bspline_curve3d, fname)

    # Import text file
    result = exchange.import_txt(fname)

    res_array = []
    for res in result:
        res_array.append(res)

    assert res_array == bspline_curve3d.ctrlpts

    # Clean up temporary file if exists
    if os.path.isfile(fname):
        os.remove(fname)
from geomdl import exchange
from geomdl.visualization import VisMPL as vis

# Fix file path
os.chdir(os.path.dirname(os.path.realpath(__file__)))

# Create a BSpline surface instance
surf1 = BSpline.Surface()

# Set degrees
surf1.degree_u = 3
surf1.degree_v = 3

# Set control points
surf1.set_ctrlpts(
    *exchange.import_txt("ex_surface01.cpt", two_dimensional=True))

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

# Set evaluation delta
surf1.delta = 0.025

# Rotate surf1 and generate a copy in surf2
surf2 = operations.rotate(surf1, 45, axis=2)

# Visualize surfaces
msurf1 = multi.SurfaceContainer(surf1, surf2)
msurf1.vis = vis.VisSurface()
msurf1.render()
示例#5
0
import os
from geomdl import BSpline
from geomdl import utilities
from geomdl import exchange
# from geomdl.visualization import VisMPL
from geomdl.visualization import VisPlotly

# Fix file path
os.chdir(os.path.dirname(os.path.realpath(__file__)))

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

# Set up the NURBS curve
curve.ctrlpts = exchange.import_txt("ex_curve03.cpt")
curve.degree = 3

# Auto-generate knot vector
curve.knotvector = utilities.generate_knot_vector(curve.degree,
                                                  len(curve.ctrlpts))

# Set evaluation delta
curve.delta = 0.01

# Evaulate curve
curve.evaluate()

# Draw the control point polygon and the evaluated curve
vis_comp = VisPlotly.VisCurve2D()
curve.vis = vis_comp
# Fix file path
os.chdir(os.path.dirname(os.path.realpath(__file__)))

#
# Curve Evaluation
#

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

# Set degree
curve.degree = 3

# Set control points
curve.ctrlpts = exchange.import_txt("../curve3d/ex_curve3d02.cpt")

# Auto-generate knot vector
curve.knotvector = utilities.generate_knot_vector(curve.degree,
                                                  len(curve.ctrlpts))

# Set evaluation delta
curve.delta = 0.001

# Evaulate curve
curve.evaluate()

#
# Multiple vector evaluation after v3.0.7
#
示例#7
0
from geomdl import exchange
from geomdl.visualization import VisMPL as vis

# Fix file path
os.chdir(os.path.dirname(os.path.realpath(__file__)))

# Create a NURBS surface instance
surf = NURBS.Surface()

# Set degrees
surf.degree_u = 1
surf.degree_v = 2

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

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

# Set evaluation delta
surf.delta = 0.05

# Evaluate surface
surf.evaluate()

# Plot the control point grid and the evaluated surface
vis_comp = vis.VisSurface()
surf.vis = vis_comp
surf.render()