Beispiel #1
0
 def get_geometry(self):
     if self.mode == 'CURVE':
         curves = self.inputs['Curves'].sv_get()
         if isinstance(curves[0], (list, tuple)):
             curves = sum(curves, [])
         container = multi.CurveContainer()
         for i, curve in enumerate(curves):
             if not isinstance(curve, SvNurbsCurve):
                 if hasattr(curve, 'to_nurbs'):
                     curve = curve.to_nurbs(
                         implementation=SvNurbsCurve.GEOMDL)
                 else:
                     raise TypeError(
                         "Provided object #%s is not a NURBS curve, but %s!"
                         % (i, type(curve)))
             container.append(SvGeomdlCurve.from_any_nurbs(curve).curve)
         return container
     else:  # SURFACE
         surfaces = self.inputs['Surfaces'].sv_get()
         if isinstance(surfaces[0], (list, tuple)):
             surfaces = sum(surfaces, [])
         container = multi.SurfaceContainer()
         for i, surface in enumerate(surfaces):
             if not isinstance(surface, SvNurbsSurface):
                 if hasattr(surface, 'to_nurbs'):
                     surface = surface.to_nurbs(
                         implementation=SvNurbsCurve.GEOMDL)
                 else:
                     raise TypeError(
                         "Provided object #%s is not a NURBS surface, but %s!"
                         % (i, type(surface)))
             container.append(
                 SvGeomdlSurface.from_any_nurbs(surface).surface)
         return container
def test_deriv_surf_fig(bspline_surface):
    fname = "test-derivative_surface.png"

    data = operations.derivative_surface(bspline_surface)
    multi_shape = multi.SurfaceContainer(data)
    multi_shape.vis = VisMPL.VisSurface()
    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)
def test_export_stl_ascii_multi(nurbs_surface_decompose):
    fname = FILE_NAME + ".stl"

    data = operations.decompose_surface(nurbs_surface_decompose)
    nurbs_multi = multi.SurfaceContainer(data)

    nurbs_multi.sample_size = SAMPLE_SIZE
    exchange.export_stl(nurbs_multi, fname, binary=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)
Beispiel #4
0
def test_surf_multi_fig_save(bspline_surface):
    conf = VisMPL.VisConfig()
    vis = VisMPL.VisSurfWireframe(config=conf)

    fname = "test-multi_surface.png"

    data = operations.decompose_surface(bspline_surface)
    multi_shape = multi.SurfaceContainer(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)
Beispiel #5
0
def test_surf_multi_fig_nowindow(bspline_surface):
    conf = VisMPL.VisConfig()
    vis = VisMPL.VisSurfScatter(config=conf)

    fname = conf.figure_image_filename

    data = operations.decompose_surface(bspline_surface)
    multi_shape = multi.SurfaceContainer(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)
Beispiel #6
0
 def get_geometry(self):
     if self.mode == 'CURVE':
         curves = self.inputs['Curves'].sv_get()
         if isinstance(curves[0], (list, tuple)):
             curves = sum(curves, [])
         container = multi.CurveContainer()
         for i, curve in enumerate(curves):
             if not isinstance(curve, SvExGeomdlCurve):
                 raise TypeError("Provided object #%s is not a NURBS curve, but %s!" % (i, type(curve)))
             container.append(curve.curve)
         return container
     else: # SURFACE
         surfaces = self.inputs['Surfaces'].sv_get()
         if isinstance(surfaces[0], (list, tuple)):
             surfaces = sum(surfaces, [])
         container = multi.SurfaceContainer()
         for i, surface in enumerate(surfaces):
             if not isinstance(surface, SvExGeomdlSurface):
                 raise TypeError("Provided object #%s is not a NURBS surface, but %s!" % (i, type(surface)))
             container.append(surface.surface)
         return container
Beispiel #7
0
def generate_nurbs_from_file(file_name, delta, shape_idx, file_type=''):
    """Generates NURBS objects from supported file formats"""
    # Fix input types
    delta = float(delta)
    shape_idx = int(shape_idx)

    # Try to find file type from its extension
    if not file_type:
        fname, fext = os.path.splitext(file_name)
        file_type = fext[1:]

    ftype = file_type.lower()
    if ftype in CLI_FILE_IMPORT_TYPES:
        # Build NURBS object
        nurbs_objs = CLI_FILE_IMPORT_TYPES[ftype](file_name,
                                                  delta=delta,
                                                  jinja2=True)

        # Return the shape
        if len(nurbs_objs) == 1:
            return nurbs_objs[0]

        if isinstance(nurbs_objs[0], NURBS.Curve):
            result = multi.CurveContainer(nurbs_objs)
        elif isinstance(nurbs_objs[0], NURBS.Surface):
            result = multi.SurfaceContainer(nurbs_objs)
        else:
            result = multi.VolumeContainer(nurbs_objs)

        # Set the delta for multi shape objects
        if 0.0 < delta < 1.0:
            result.delta = delta

        if shape_idx >= 0:
            return result[shape_idx]
        return result
    else:
        raise RuntimeError("The input file type '" + str(file_type) +
                           "' is not supported")
Beispiel #8
0
 def vis_multiple_spline_surf(self, surfs):
     mcrv = multi.SurfaceContainer([surf, surf1])
     mcrv.vis = VisMPL.VisSurface()
     mcrv.render()
# Set degrees
surf.degree_u = 1
surf.degree_v = 2

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

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

# Decompose the surface
surf_list = operations.decompose_surface(surf)
surfaces = multi.SurfaceContainer(surf_list)

# Translate one of the surface patch
operations.translate(surfaces[1], (-0.25, 0.25, 0), inplace=True)

# Set number of samples for all split surfaces
surfaces.sample_size = 50

# Plot the control point grid and the evaluated surface
vis_comp = VisMPL.VisSurfWireframe()
surfaces.vis = vis_comp
surfaces.render()

# Good to have something here to put a breakpoint
pass
Beispiel #10
0
    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 volume
    pvolume = construct.construct_volume('w', surf01, surf02, surf03, degree=1)

    # Voxelize the volume
    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 the isosurface
    surfvol = construct.extract_isosurface(pvolume)
    msurf = multi.SurfaceContainer(surfvol)

    # Visualize the isosurface
    msurf.vis = vis.VisSurface(vis.VisConfig(ctrlpts=False))
    msurf.delta = 0.05
    msurf.render(evalcolor=[
        "skyblue", "cadetblue", "crimson", "crimson", "crimson", "crimson"
    ])

# Good to have something here to put a breakpoint
pass
Beispiel #11
0
    Developed by Onur Rauf Bingol (c) 2018
"""

import os
from geomdl import exchange
from geomdl import multi
from geomdl.visualization import VisPlotly as vis


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

# Read a directory containing mesh files
data = exchange.import_smesh('data')

# Generate a surface container for visualization
multi_mesh = multi.SurfaceContainer(data)
multi_mesh.sample_size = 5

# Draw the control point grid and the evaluated surface
vis_config = vis.VisConfig(ctrlpts=False, legend=False)
vis_comp = vis.VisSurface(vis_config)
multi_mesh.vis = vis_comp
multi_mesh.render()

# Save surfaces as a .obj file
exchange.export_obj(multi_mesh, "multisurface01.obj")

# Good to have something here to put a breakpoint
pass
# -*- coding: utf-8 -*-
"""
    Examples for the NURBS-Python Package
    Released under MIT License
    Developed by Onur Rauf Bingol (c) 2019

    Exporting multiple NURBS surfaces in VTK Polydata format
"""

from geomdl.shapes import surface
from geomdl import operations
from geomdl import multi
from geomdl import exchange_vtk

# Create a cylindrical surface
cylinder = surface.cylinder(radius=5.0, height=22.5)

# Decompose to generate multiple surfaces
cylinder_decomposed = operations.decompose_surface(cylinder)

# Add decomposed surfaces to a surface container
surf_container = multi.SurfaceContainer(cylinder_decomposed)

# Export evaluated points as a .vtk file
exchange_vtk.export_polydata(surf_container,
                             "cylindrical_surface_decomposed_evalpts.vtk",
                             tessellate=True)

# Good to have something here to put a breakpoint
pass
Beispiel #13
0
surf = BSpline.Surface()

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

# 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]

# Split the surface
surface_list1 = operations.split_surface_u(surf, param=0.25)
surfaces1 = multi.SurfaceContainer(surface_list1)

# Translate one of the split surfaces
operations.translate(surfaces1[0], (0, 0, 5), inplace=True)

# Split the other split surface
surface_list2 = operations.split_surface_v(surfaces1[1], param=0.75)
surfaces = multi.SurfaceContainer(surface_list2)
surfaces.add(surfaces1[0])

# Set number of samples for all split surfaces
surfaces.sample_size = 20

# Plot the control point grid and the evaluated surface
vis_comp = VisMPL.VisSurfTriangle()
surfaces.vis = vis_comp
# 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()

# Decompose surf1
surf1_decomposed = operations.decompose_surface(surf1)
msurf2 = multi.SurfaceContainer(surf1_decomposed)

# Rotate decomposed surface
msurf2_rotated = operations.rotate(msurf2, 90, axis=1)

# Visualize decomposed and decomposed-rotated surfaces
msurf3 = multi.SurfaceContainer(msurf2, msurf2_rotated)
msurf3.vis = vis.VisSurface()
msurf3.render()
    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"
    ])

# Good to have something here to put a breakpoint
pass
Beispiel #16
0
    1, 1, 1
]

# duck3.nurbs

# Process control points and weights
d3_ctrlpts = exchange.import_txt("duck3.ctrlpts", separator=" ")

# Create a NURBS surface
duck3 = NURBS.Surface()
duck3.name = "beak bottom"
duck3.order_u = 4
duck3.order_v = 4
duck3.ctrlpts_size_u = 6
duck3.ctrlpts_size_v = 6
duck3.ctrlpts = d3_ctrlpts
duck3.knotvector_u = [0, 0, 0, 0, 0.333333, 0.666667, 1, 1, 1, 1]
duck3.knotvector_v = [0, 0, 0, 0, 0.333333, 0.666667, 1, 1, 1, 1]

# Add all surfaces to a surface container
ducky = multi.SurfaceContainer(duck1, duck2, duck3)
ducky.sample_size = 50

# Visualization configuration
ducky.vis = VisVTK.VisSurface(ctrlpts=True,
                              legend=False,
                              figure_size=[940, 940])

# Render the ducky
ducky.render(evalcolor=["green", "yellow", "yellow"], cpcolor="wheat")
Beispiel #17
0
trim1.ctrlpts = ((1, 0), (0.95, 0.5), (1, 1), (0, 1), (0.05, 0.5), (0, 0), (1,
                                                                            0))
trim1.knotvector = knotvector.generate(trim1.degree, trim1.ctrlpts_size)
trim1.delta = 0.001
trim1.opt = ['reversed', 1]
# operations.scale(trim1, 0.5, inplace=True)

trim2 = deepcopy(trim1)
trim2.opt = ['reversed', 0]

# Add trim to surface 1
surf1.trims = [trim1]

# Add trim to surface 3
surf3.trims = [trim2]

# Visualize all surfaces
mult = multi.SurfaceContainer(surf1, surf2, surf3)
mult.sample_size = 30
mult.tessellator = tessellate.TrimTessellate()

# Show trim curves but don't show control points
vis_conf = vis.VisConfig(trims=True, ctrlpts=False)
mult.vis = vis.VisSurface(vis_conf)

# Render with colors
# mult.render(evalcolor=["steelblue", "red", "green"])

from geomdl import exchange
exchange.export_json(mult, "mult.json")