Пример #1
0
    def simple_cow(self, fbo):
        from pyvista import examples

        # download mesh
        mesh = examples.download_cow()
        decimated = mesh.decimate_boundary(target_reduction=0.75)

        fbo.set_subplots((1, 2))
        fbo.subplot(0, 0)
        fbo.add_text("Original mesh", font_size=24, color='black')
        fbo.add_mesh(mesh, show_edges=True, color='brown')
        fbo.subplot(0, 1)
        fbo.add_text("Decimated version", font_size=24, color='black')
        fbo.add_mesh(decimated, show_edges=True, color=True)

        fbo.link_views()  # link all the views
        # Set a camera position to all linked views
        fbo.camera_position = [(15, 5, 0), (0, 0, 0), (0, 1, 0)]
        fbo.set_background('red')
        fbo.update()

        style = MouseInteractorHighLightActor(ren_win=fbo.ren_win,
                                              ren=fbo.renderers)
        # style.SetDefaultRenderer(fbo.renderer)
        fbo._style_class = style
        fbo.update_style()

        image_data = fbo.image
        print(image_data)
Пример #2
0
def test_box_grid():
    grid = np.zeros((30, 30, 30))
    grid[13:18, 5:25, 13:18] = 1

    elements, vertices, vert_manager = grid_to_tets(grid, 0.1)

    mesh = examples.download_cow()
    distances = mesh_select(vertices, mesh)
    print("distances: ", distances)

    print(elements, vertices)
    constraints = [[0, [1, 1, 1]], [1, [1, 1, 1]], [2, [1, 1, 1]],
                   [3, [1, 1, 1]]]

    loads = [[32, -10000., 0.0, 0]]
    # [20, 1000., 0.0, 0],
    #[34, 1000., 0.0, 0],
    # [31, 10000., 0.0, 0]]
    poisson = 0.3
    youngs = 2000

    displacements = solve_full(elements, vertices, poisson, youngs,
                               constraints, loads)
    magnitudes = get_displacement_magnitudes(displacements)
    print("magnitudes", magnitudes)

    plotter = pv.Plotter()
    #add_tets_to_display(vertices, elements, plotter, magnitudes)

    surface = generate_unstructured_grid(elements, vertices)
    voxels = pv.voxelize(surface, density=surface.length / 200)
    plotter.add_mesh(voxels)
    plotter.show()
Пример #3
0
    def cow(self, fbo):
        from pyvista import examples

        # download mesh
        mesh = examples.download_cow()
        decimated = mesh.decimate_boundary(target_reduction=0.75)

        fbo.set_subplots((1, 2))
        fbo.subplot(0, 0)
        fbo.add_text("Original mesh", font_size=24, color='black')
        fbo.add_mesh(mesh, show_edges=True, color='brown')
        fbo.subplot(0, 1)
        fbo.add_text("Decimated version", font_size=24, color='black')
        fbo.add_mesh(decimated, show_edges=True, color=True)

        fbo.link_views()  # link all the views
        # Set a camera position to all linked views
        fbo.camera_position = [(15, 5, 0), (0, 0, 0), (0, 1, 0)]
        fbo.set_background('red')
        fbo.update()

        style = MouseInteractorHighLightActor(ren_win=fbo.ren_win,
                                              ren=fbo.renderers)
        # style.SetDefaultRenderer(fbo.renderer)
        fbo._style_class = style
        fbo.update_style()

        fbo.open_gif("linked.gif")

        # Update camera and write a frame for each updated position
        nframe = 15
        for i in range(nframe):
            fbo.camera_position = [
                (15 * np.cos(i * np.pi / 45.0), 5.0,
                 15 * np.sin(i * np.pi / 45.0)),
                (0, 0, 0),
                (0, 1, 0),
            ]
            # fbo.update()
            fbo.write_frame()
Пример #4
0
 def test_download_cow():
     data = examples.download_cow()
     assert data.n_points
Пример #5
0
~~~~~~~~~~~~

Positional lights in PyVista have customizable beam shapes, see the
:ref:`ref_light_beam_shape_example` example. Spotlights are special in
the sense that they are unidirectional lights with a finite position,
so they can be visualized using a cone.

This is exactly the purpose of a ``vtk.vtkLightActor``, the
functionality of which can be enabled for spotlights:
"""
# sphinx_gallery_thumbnail_number = 1
import numpy as np
import pyvista as pv
from pyvista import examples

cow = examples.download_cow()
cow.rotate_x(90)
plotter = pv.Plotter(lighting='none', window_size=(1000, 1000))
plotter.add_mesh(cow, color='white')
floor = pv.Plane(center=(*cow.center[:2], cow.bounds[-2]),
                 i_size=30, j_size=25)
plotter.add_mesh(floor, color='green')

UFO = pv.Light(position=(0, 0, 10), focal_point=(0, 0, 0), color='white')
UFO.positional = True
UFO.cone_angle = 40
UFO.exponent = 10
UFO.intensity = 3
UFO.show_actor()
plotter.add_light(UFO)
Пример #6
0
"""
Cow
~~~

Tetrahedralize a cow mesh
"""
# sphinx_gallery_thumbnail_number = 3
import numpy as np
import pyvista as pv
from pyvista import examples
import tetgen
import pymeshfix

###############################################################################

cow_mesh = examples.download_cow().triangulate()

cpos = [(13., 7.6, -13.85),
 (0.44, -0.4, -0.37),
 (-0.28, 0.9, 0.3)]

cpos=[(15.87144235049248, 4.879216382405231, -12.14248864876951),
 (1.1623113035352375, -0.7609060338348953, 0.3192320579894903),
 (-0.19477922834083672, 0.9593375398915212, 0.20428542963665386)]

cow_mesh.plot(cpos=cpos)

###############################################################################

tet = tetgen.TetGen(cow_mesh)
tet.make_manifold()
Пример #7
0
# Extract the edges above a 12 degree feature angle
edges = mesh.extract_feature_edges(12)

# Render the edge lines on top of the original mesh
p = pv.Plotter()
p.add_mesh(mesh, color=True)
p.add_mesh(edges, color="red", line_width=5)
# Define a camera position that will zoom to her eye
p.camera_position = [(96.0, -197.0, 45.0), (7.0, -109.0, 22.0), (0, 0, 1)]
p.show()

###############################################################################
# We can do this analysis for any :class:`pyvista.PolyData` object. Let's try
# the cow mesh example:

mesh = examples.download_cow()

edges = mesh.extract_feature_edges(20)

p = pv.Plotter()
p.add_mesh(mesh, color=True)
p.add_mesh(edges, color="red", line_width=5)
p.camera_position = [(9.5, 3.0, 5.5), (2.5, 1, 0), (0, 1, 0)]
p.show()

###############################################################################
# We can leverage the :any:`pyvista.PolyData.n_open_edges` property and
# :func:`pyvista.PolyDataFilters.extract_feature_edges` filter to count and extract the
# open edges on a :class:`pyvista.PolyData` mesh.

# Download a sample surface mesh with visible open edges
Пример #8
0
"""
.. _mesh_quality_example:

Computing Mesh Quality
~~~~~~~~~~~~~~~~~~~~~~

Leverage powerful VTK algorithms for computing mesh quality.

Here we will use the :func:`pyvista.DataSetFilters.compute_cell_quality` filter
to compute the cell qualities. For a full list of the various quality metrics
available, please refer to the documentation for that filter.
"""
import pyvista as pv
from pyvista import examples
import numpy as np

mesh = examples.download_cow().triangulate().decimate(0.7)

cpos = [(10.10963531890468, 4.61130688407898, -4.503884867626516),
        (1.2896420468715433, -0.055387528972708225, 1.1228250502811408),
        (-0.2970769821136617, 0.9100381451936025, 0.2890948650371137)]

###############################################################################
# Compute the cell quality. Note that there are many different quality measures
qual = mesh.compute_cell_quality(quality_measure='scaled_jacobian')
qual

###############################################################################
qual.plot(cpos=cpos, scalars='CellQuality')
Пример #9
0
 def __init__(self):
     self._example_data = examples.download_cow()
     _ExampleLoader.__init__(self)
Пример #10
0
"""
Cow
~~~

Tetrahedralize a cow mesh
"""
# sphinx_gallery_thumbnail_number = 3
import numpy as np
import pyvista as pv
from pyvista import examples
import tetgen
import pymeshfix

###############################################################################

cow_mesh = examples.download_cow().tri_filter()

cpos = [(13., 7.6, -13.85),
 (0.44, -0.4, -0.37),
 (-0.28, 0.9, 0.3)]

cpos=[(15.87144235049248, 4.879216382405231, -12.14248864876951),
 (1.1623113035352375, -0.7609060338348953, 0.3192320579894903),
 (-0.19477922834083672, 0.9593375398915212, 0.20428542963665386)]

cow_mesh.plot(cpos=cpos)

###############################################################################

tet = tetgen.TetGen(cow_mesh)
tet.make_manifold()