Example #1
0
    def plotBsplineSurface(self,
                           pts,
                           corsequences,
                           lsagsequences=[],
                           rsagsequences=[],
                           degree=3,
                           visualization_type=-1,
                           side=2):
        # side = 0 (Left) | side = 1 (Right)

        if side == 0:
            lsurface = self.createBsplineSurface(pts=pts,
                                                 corsequences=corsequences,
                                                 sagsequences=lsagsequences)

            # Set visualization component
            if visualization_type == 0:
                lsurface.delta = 0.01
                vis_comp = VisMPL.VisSurfScatter()
            elif visualization_type == 1:
                vis_comp = VisMPL.VisSurface()
            elif visualization_type == 2:
                vis_comp = VisMPL.VisSurfWireframe()
            else:
                vis_comp = VisMPL.VisSurfTriangle()
            lsurface.vis = vis_comp

            # Render the surface
            lsurface.render()

        else:
            rsurface = self.createBsplineSurface(pts=pts,
                                                 corsequences=corsequences,
                                                 sagsequences=rsagsequences)

            # Set visualization component
            if visualization_type == 0:
                rsurface.delta = 0.01
                vis_comp = VisMPL.VisSurfScatter()
            elif visualization_type == 1:
                vis_comp = VisMPL.VisSurface()
            elif visualization_type == 2:
                vis_comp = VisMPL.VisSurfWireframe()
            else:
                vis_comp = VisMPL.VisSurfTriangle()
            rsurface.vis = vis_comp

            # Render the surface
            rsurface.render()
Example #2
0
    def plotNURBSSurfaces(self,
                          left_pts,
                          right_pts,
                          corsequences,
                          lsagsequences,
                          rsagsequences,
                          degree=3,
                          visualization_type=-1):
        left_surface = self.createNURBSSurface(pts=left_pts,
                                               corsequences=corsequences,
                                               sagsequences=lsagsequences)
        right_surface = self.createNURBSSurface(pts=right_pts,
                                                corsequences=corsequences,
                                                sagsequences=rsagsequences)

        # Create a MultiSurface
        surfaces = Multi.MultiSurface()
        surfaces.add(left_surface)
        surfaces.add(right_surface)

        # Set visualization component
        if visualization_type == 0:
            surfaces.delta = 0.01
            vis_comp = VisMPL.VisSurfScatter()
        elif visualization_type == 1:
            vis_comp = VisMPL.VisSurface()
        elif visualization_type == 2:
            vis_comp = VisMPL.VisSurfWireframe()
        else:
            vis_comp = VisMPL.VisSurfTriangle()
        surfaces.vis = vis_comp

        # Render the surface
        surfaces.render()
Example #3
0
def test_surf_multi_fig_save(bspline_surface):
    conf = VisMPL.VisConfig()
    vis = VisMPL.VisSurfTriangle(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)
Example #4
0
def test_surf_multi_fig_nowindow(bspline_surface):
    conf = VisMPL.VisConfig()
    vis = VisMPL.VisSurfTriangle(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)
Example #5
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
Example #6
0
t_ctrlptsw = compat.combine_ctrlpts_weights(p_ctrlpts, p_weights)
n_ctrlptsw = compat.flip_ctrlpts_u(t_ctrlptsw, p_size_u, p_size_v)

# Since we have no information on knot vectors, let's auto-generate them
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)

#
# Import surface to NURBS-Python
#

surf = NURBS.Surface()
surf.degree_u = p_degree_u
surf.degree_v = p_degree_v
surf.ctrlpts_size_u = p_size_u
surf.ctrlpts_size_v = p_size_v
surf.ctrlptsw = n_ctrlptsw
surf.knotvector_u = n_knotvector_u
surf.knotvector_v = n_knotvector_v

# Set evaluation delta
surf.delta = 0.05

# Set visualization component
vis_comp = VisMPL.VisSurfTriangle()
surf.vis = vis_comp

# Render the surface
surf.render()
Example #7
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]

# Set evaluation delta
surf.delta = 0.025

# Evaluate surface points
surf.evaluate()

# Import and use Matplotlib's colormaps
from matplotlib import cm

# Plot the control point grid and the evaluated surface
vis_comp = vis.VisSurfTriangle()
surf.vis = vis_comp
surf.render(colormap=cm.cool)

# Good to have something here to put a breakpoint
pass
Example #8
0

# duck3.nurbs

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

# Create a NURBS surface
duck3 = NURBS.Surface()
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]

# Plotting
ducky = Multi.MultiSurface()
ducky.add_list([duck1, duck2, duck3])
vis_config = VisMPL.VisConfig(ctrlpts=False, legend=False)

# Use Matplotlib's colormaps to color the duck
from matplotlib import cm

ducky.vis = VisMPL.VisSurfTriangle(vis_config)
ducky.sample_size = 50
ducky.render(colormap=[cm.Wistia, cm.copper, cm.copper])

pass
Example #9
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
Example #10
0
    def plotBsplineSurfaces(self,
                            left_pts,
                            right_pts,
                            corsequences,
                            lsagsequences,
                            rsagsequences,
                            degree=3,
                            visualization_type=-1):
        """ Create B-spline surface

        Parameters
        ----------
        left_pts: list
            List of tuples with 3D points that represents the left diaphragmatic surface

        right_pts: list
            List of tuples with 3D points that represents the right diaphragmatic surface

        corsequences: list
            List of int with the coronal sequences available

        lsagsequences: list
            List of int with the sagittal sequences available from the left lung

        rsagsequences: list
            List of int with the sagittal sequences available from the right lung

        degree: int
            B-spline surface's Degree (Default = 2)

        visualization_type: int
            -1: (Default) Wireframe plot for the control points and triangulated plot for the surface points
            0: Wireframe plot for the control points and scatter plot for the surface points
            1: Triangular mesh plot for the surface and wireframe plot for the control points grid
            2: Scatter plot for the control points and wireframe for the surface points
        """
        left_surface = self.createBsplineSurface(pts=left_pts,
                                                 corsequences=corsequences,
                                                 sagsequences=lsagsequences)
        right_surface = self.createBsplineSurface(pts=right_pts,
                                                  corsequences=corsequences,
                                                  sagsequences=rsagsequences)

        # Create a MultiSurface
        surfaces = Multi.MultiSurface()
        surfaces.add(left_surface)
        surfaces.add(right_surface)

        # Set visualization component
        if visualization_type == 0:
            surfaces.delta = 0.01
            vis_comp = VisMPL.VisSurfScatter()
        elif visualization_type == 1:
            vis_comp = VisMPL.VisSurface()
        elif visualization_type == 2:
            vis_comp = VisMPL.VisSurfWireframe()
        else:
            vis_comp = VisMPL.VisSurfTriangle()
        surfaces.vis = vis_comp

        # Render the surface
        surfaces.render()
Example #11
0
            [5.0, -15.0, 0.0, 1.0], [-5.0, -15.0, 0.0, 1.0],
            [-15.0, -15.0, 0.0, 1.0], [-25.0, -15.0, 0.0, 1.0]],
           [[25.0, -5.0, 5.0, 1.0], [15.0, -5.0, 5.0, 1.0],
            [5.0, -5.0, 5.0, 1.0], [-5.0, -5.0, 5.0, 1.0],
            [-15.0, -5.0, 5.0, 1.0], [-25.0, -5.0, 5.0, 1.0]],
           [[25.0, 5.0, 5.0, 1.0], [15.0, 5.0, 5.0, 1.0], [5.0, 5.0, 5.0, 1.0],
            [-5.0, 5.0, 5.0, 1.0], [-15.0, 5.0, 5.0, 1.0],
            [-25.0, 5.0, 5.0, 1.0]],
           [[25.0, 15.0, 0.0, 1.0], [15.0, 15.0, 0.0, 1.0],
            [5.0, 15.0, 5.0, 1.0], [-5.0, 15.0, 5.0, 1.0],
            [-15.0, 15.0, 0.0, 1.0], [-25.0, 15.0, 0.0, 1.0]],
           [[25.0, 25.0, 0.0, 1.0], [15.0, 25.0, 0.0, 1.0],
            [5.0, 25.0, 5.0, 1.0], [-5.0, 25.0, 5.0, 1.0],
            [-15.0, 25.0, 0.0, 1.0], [-25.0, 25.0, 0.0, 1.0]]]

# Generate surface
surf = NURBS.Surface()
surf.degree_u = 3
surf.degree_v = 3
surf.ctrlpts2d = ctrlpts
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]
surf.sample_size = 30

# Visualize surface
surf.vis = VisMPL.VisSurfTriangle()
surf.render(colormap=cm.summer)

# Good to have something here to put a breakpoint
pass
Example #12
0
# Create a BSpline surface instance
surf = BSpline.Surface()

# 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 split surface
surf.sample_size = 50

# Generate the visualization component and its configuration
vis_config = myvis.VisConfig(ctrlpts=False, legend=False)
vis_comp = myvis.VisSurfTriangle(vis_config)

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

# Plot the split surface
surf.render()

# Good to have something here to put a breakpoint
pass