Пример #1
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()
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()
Пример #3
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_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_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_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)
Пример #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_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)
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)
Пример #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)
Пример #12
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)
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)
Пример #14
0
    def test_NURBS_BSPLINE_EQUAL(self):
        # Save results
        B_res = self.B_cur.evalpts
        N_res = self.N_cur.evalpts

        # Plot the control point polygon and the evaluated curve
        vis_comp = vis.VisCurve2D()
        self.N_cur.vis = vis_comp
        # self.N_cur.render()
        self.assertListAlmostEqual(B_res, N_res, 3)
Пример #15
0
    def test_gauss_newton2D(self):
        ''' Performs gauss newton search of optimum weights
        '''

        # Fit the NURBS weights and control points
        N_fit = F.gauss_newton2D(self.N_cur, self.points)

        # Plot (debug)
        fig = plt.figure(num=1)
        vis_fit = vis.VisCurve2D()
        N_fit.vis = vis_fit
        N_fit.render()
Пример #16
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
Пример #17
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()
Пример #18
0
    def draw_curve(self, curve):
        # Try to load the visualization module
        try:
            render_curve = True
            from geomdl.visualization import VisMPL
        except ImportError:
            render_curve = False

        # Draw the control point polygon and the evaluated curve
        if render_curve:
            vis_comp = VisMPL.VisCurve3D()
            curve.vis = vis_comp
            curve.render()
Пример #19
0
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)
Пример #20
0
def plot_BC(BC_ctrlpts, BC_knot, p):
    """Plot a boundary curve

	:param BC_ctrlpts: boundary control points
	:param BC_knot: boundary knot vector
	:param p: boundary degree
	"""
    cu = NURBS.Curve()
    cu.degree = p
    cu.ctrlpts = BC_ctrlpts.tolist()
    cu.knotvector = BC_knot
    cu.delta = 0.01
    # Plot the control point polygon and the evaluated curve
    cu.vis = VisMPL.VisCurve2D()
    cu.render()
Пример #21
0
def run(N, weight):
    N = N
    circle = create_curve(N)
    print(circle)
    weight = math.cos(math.pi / N) + weight
    cv = Multi.MultiCurve()
    k = 0
    while k < len(circle) - 1:
        cv.add(
            create_bezie_curve(circle[k], circle[k + 1], circle[k + 2],
                               weight))
        k = k + 2
    vis_compl = VisMPL.VisCurve2D()
    cv.vis = vis_compl
    cv.render()
Пример #22
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
Пример #23
0
    def draw_curves(self, curvespts):
        # Try to load the visualization module
        try:
            render_curve = True
            from geomdl.visualization import VisMPL
        except ImportError:
            render_curve = False

        # Plot the curves using the curve container
        curves = Multi.MultiCurve()
        curves.delta = 0.01

        for curve in curvespts:
            curves.add(curve)

        if render_curve:
            vis_comp = VisMPL.VisCurve3D()
            curves.vis = vis_comp
            curves.render()
Пример #24
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()
Пример #25
0
    for j in range(curve_geometry.NbPoles):
        data = model_part.GetNode(j + 1).X, model_part.GetNode(
            j + 1).Y, model_part.GetNode(j + 1).Z
        ctlpts_list.write(
            str(model_part.GetNode(j + 1).X) + ',' +
            str(model_part.GetNode(j + 1).Y) + ',' +
            str(model_part.GetNode(j + 1).Z) + '\n')

    ctlpts_list.close()
    plot_curve.ctrlpts = exchange.import_txt(
        "C:\_Masterarbeit\BeamValidation\python_base\Balken\ctlpts_list.txt")
    plot_curve.knotvector = utilities.generate_knot_vector(
        plot_curve.degree, len(plot_curve.ctrlpts))
    # Set evaluation delta
    # plot_curve.delta = 0.001
    # plot_curve.evaluate

    # add to mulit_curve
    multi_curve.add(plot_curve)

# Set evaluation delta
multi_curve.delta = 0.001
# multi_curve.evaluate
# plot the controlpoint polygon and the evaluated curve
vis_comp = VisMPL.VisCurve3D()
multi_curve.vis = vis_comp
multi_curve
multi_curve.render(cpcolor='black', evalcolor='red')
# multi_curve.render()
pass
Пример #26
0
curve.ctrlpts = [[1.0,1.0], [2.5,0.5], [5.0,1.0]]
curve.degree = 1

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

# Length computation
xi=[-0.57735, 0.57735]
wi=[1, 1]
g1= lambda t: curve.derivatives(0.25*t+0.25, 1)
dcurve1 = np.array([g1(xi[i])[1] for i in range(len(xi))])
length1 = 0.25*np.dot(wi, np.linalg.norm(dcurve1, axis=1))
print length1
l1 = np.linalg.norm(np.array(curve.ctrlpts[1]) - np.array(curve.ctrlpts[0]))
l2 = np.linalg.norm(np.array(curve.ctrlpts[2]) - np.array(curve.ctrlpts[1]))
print 'l1 = ', l1
print 'l2 = ', l2
print 'ana lengh=', l1+l2

sys.exit(0)
# Set evaluation delta
curve.delta = 0.01

# Evaluate curve
curve.evaluate()

# Draw the control point polygon and the evaluated curve
if render_curve:
    vis_comp = VisMPL.VisCurve2D()
    curve.vis = vis_comp
    curve.render()
# 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)
points = np.array([[math.cos(u)*math.cos(v), math.cos(v)*math.sin(u),math.sin(v)] 
                    for u in np.linspace(0,2*math.pi,num=30) 
                    for v in np.linspace(-math.pi/2,math.pi/2,num=30)])

# print(points)
# fig = plt.figure()
# ax = Axes3D(fig)
# ax.plot(points[:,0],points[:,1],points[:,2],'o',markersize=2)
# plt.show()

surf = approximate_surface(points.tolist(),30,30,3,3,ctrlpts_size_u=10,ctrlpts_size_v=10)

surf.delta = 0.05

surf.vis = VisMPL.VisSurfWireframe()
# surf.render()

div = 100
evalpts = np.array([surf.evaluate_list([(u,v) for v in np.linspace(0,1,div)]) for u in np.linspace(0,1,div)])
print(evalpts.shape)


fig = plt.figure()
ax = Axes3D(fig)

# all_points = np.reshape(evalpts,(div*div,3))
# ax.plot(all_points[:,0],all_points[:,1],all_points[:,2],'o',markersize=2)

# points33 = np.reshape(evalpts[10:13,10:13,:],(9,3))
# ax.plot(points33[:,0],points33[:,1],points33[:,2],'o',markersize=2)
Пример #29
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
Пример #30
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