@@ -7,16 +7,13 @@
Loading
7 7
8 8
__displayname__ = 'Point Set'
9 9
10 -
import vtk
11 -
from vtk.util import numpy_support as nps
12 -
import pyvista
13 -
14 10
import numpy as np
11 +
import pyvista
15 12
16 13
from omfvista.utilities import add_data, add_textures
17 14
18 15
19 -
def point_set_to_vtk(pse):
16 +
def point_set_to_vtk(pse, origin=(0.0, 0.0, 0.0)):
20 17
    """Convert the point set to a :class:`pyvista.PolyData` data object.
21 18
22 19
    Args:
@@ -25,34 +22,16 @@
Loading
25 22
    Return:
26 23
        :class:`pyvista.PolyData`
27 24
    """
28 -
29 -
    points = pse.geometry.vertices
30 -
    npoints = pse.geometry.num_nodes
31 -
32 -
    # Make VTK cells array
33 -
    cells = np.hstack((np.ones((npoints, 1)),
34 -
                       np.arange(npoints).reshape(-1, 1)))
35 -
    cells = np.ascontiguousarray(cells, dtype=np.int64)
36 -
    cells = np.reshape(cells, (2*npoints))
37 -
    vtkcells = vtk.vtkCellArray()
38 -
    vtkcells.SetCells(npoints, nps.numpy_to_vtk(cells, deep=True, array_type=vtk.VTK_ID_TYPE))
39 -
40 -
    # Convert points to vtk object
41 -
    pts = vtk.vtkPoints()
42 -
    pts.SetNumberOfPoints(pse.geometry.num_nodes)
43 -
    pts.SetData(nps.numpy_to_vtk(points))
44 -
45 -
    # Create polydata
46 -
    output = vtk.vtkPolyData()
47 -
    output.SetPoints(pts)
48 -
    output.SetVerts(vtkcells)
25 +
    points = np.array(pse.geometry.vertices)
26 +
    output = pyvista.PolyData(points)
49 27
50 28
    # Now add point data:
51 29
    add_data(output, pse.data)
52 30
53 31
    add_textures(output, pse.textures, pse.name)
54 32
55 -
    return pyvista.wrap(output)
33 +
    output.points += np.array(origin)
34 +
    return output
56 35
57 36
58 37
point_set_to_vtk.__displayname__ = 'Point Set to VTK'

@@ -7,15 +7,13 @@
Loading
7 7
8 8
__displayname__ = 'Line Set'
9 9
10 -
import vtk
11 -
from vtk.util import numpy_support as nps
12 -
import pyvista
13 -
14 10
import numpy as np
11 +
import pyvista
15 12
16 13
from omfvista.utilities import add_data
17 14
18 -
def line_set_to_vtk(lse):
15 +
16 +
def line_set_to_vtk(lse, origin=(0.0, 0.0, 0.0)):
19 17
    """Convert the line set to a :class:`pyvista.PolyData` data object.
20 18
21 19
    Args:
@@ -24,46 +22,23 @@
Loading
24 22
    Return:
25 23
        :class:`pyvista.PolyData`
26 24
    """
25 +
    ids = np.array(lse.geometry.segments).reshape(-1, 2).astype(np.int_)
26 +
    lines = np.c_[np.full(len(ids), 2, dtype=np.int_), ids]
27 +
28 +
    output = pyvista.PolyData()
29 +
    output.points = np.array(lse.geometry.vertices)
30 +
    output.lines = lines
27 31
28 -
    output = vtk.vtkPolyData()
29 -
    cells = vtk.vtkCellArray()
30 -
    pts = vtk.vtkPoints()
31 -
32 -
    # Make a data array for grouping the line segments
33 -
    indexArr = vtk.vtkIntArray()
34 -
    indexArr.SetNumberOfValues(lse.geometry.num_cells)
35 -
    indexArr.SetName('Line Index')
36 -
37 -
    # Generate VTK Points from the vertices
38 -
    pts.SetNumberOfPoints(lse.geometry.num_nodes)
39 -
    pts.SetData(nps.numpy_to_vtk(lse.geometry.vertices))
40 -
41 -
    last = lse.geometry.segments[0][0]
42 -
    segi = 0
43 -
    for i in range(len(lse.geometry.segments)):
44 -
        # Create a VTK Line cell for each segment
45 -
        seg = lse.geometry.segments[i]
46 -
        aLine = vtk.vtkLine()
47 -
        aLine.GetPointIds().SetId(0, seg[0])
48 -
        aLine.GetPointIds().SetId(1, seg[1])
49 -
        cells.InsertNextCell(aLine)
50 -
        # Group segments by connectivity:
51 -
        if seg[0] != last:
52 -
            segi += 1
53 -
        last = seg[1]
54 -
        indexArr.SetValue(i, segi)
55 -
56 -
    # Generate the output
57 -
    output.SetPoints(pts)
58 -
    output.SetLines(cells)
59 -
    output.GetCellData().AddArray(indexArr)
32 +
    indices = output.connectivity().cell_arrays['RegionId']
33 +
    output['Line Index'] = indices
60 34
61 35
    # Now add data to lines:
62 36
    add_data(output, lse.data)
63 37
64 38
    # TODO: if subtype is borehole make a tube
65 39
66 -
    return pyvista.wrap(output)
40 +
    output.points += np.array(origin)
41 +
    return output
67 42
68 43
69 44
line_set_to_vtk.__displayname__ = 'Line Set to VTK'

@@ -7,8 +7,6 @@
Loading
7 7
8 8
9 9
import numpy as np
10 -
import vtk
11 -
from vtk.util import numpy_support as nps
12 10
import pyvista
13 11
from PIL import Image
14 12
@@ -42,14 +40,7 @@
Loading
42 40
def add_data(output, data):
43 41
    """Adds data arrays to an output VTK data object"""
44 42
    for d in data:
45 -
        arr = d.array.array
46 -
        c = nps.numpy_to_vtk(num_array=arr)
47 -
        c.SetName(d.name)
48 -
        loc = d.location
49 -
        if loc == 'vertices':
50 -
            output.GetPointData().AddArray(c)
51 -
        else:
52 -
            output.GetCellData().AddArray(c)
43 +
        output[d.name] = np.array(d.array.array)
53 44
    return output
54 45
55 46
@@ -60,14 +51,8 @@
Loading
60 51
61 52
    for i, tex in enumerate(textures):
62 53
        # Now map the coordinates for the texture
63 -
        m = vtk.vtkTextureMapToPlane()
64 -
        m.SetInputDataObject(output)
65 -
        m.SetOrigin(tex.origin)
66 -
        m.SetPoint1(tex.origin + tex.axis_u)
67 -
        m.SetPoint2(tex.origin + tex.axis_v)
68 -
        m.Update()
54 +
        tmp = output.texture_map_to_plane(origin=tex.origin, point_u=tex.origin + tex.axis_u, point_v=tex.origin + tex.axis_v)
69 55
        # Grab the texture coordinates
70 -
        tmp = m.GetOutputDataObject(0)
71 56
        tcoord = tmp.GetPointData().GetTCoords()
72 57
        name = tex.name
73 58
        if name is None or name == '':

@@ -8,21 +8,18 @@
Loading
8 8
9 9
__displayname__ = 'Volume'
10 10
11 -
import vtk
12 -
from vtk.util import numpy_support as nps
11 +
import numpy as np
13 12
import pyvista
14 13
15 14
from omfvista.utilities import check_orientation, check_orthogonal
16 15
17 -
import numpy as np
18 -
19 16
20 17
def get_volume_shape(vol):
21 18
    """Returns the shape of a gridded volume"""
22 19
    return ( len(vol.tensor_u), len(vol.tensor_v), len(vol.tensor_w))
23 20
24 21
25 -
def volume_grid_geom_to_vtk(volgridgeom):
22 +
def volume_grid_geom_to_vtk(volgridgeom, origin=(0.0, 0.0, 0.0)):
26 23
    """Convert the 3D gridded volume to a :class:`pyvista.StructuredGrid`
27 24
    (or a :class:`pyvista.RectilinearGrid` when apprropriate) object contatining
28 25
    the 2D surface.
@@ -45,17 +42,9 @@
Loading
45 42
46 43
    # If axis orientations are standard then use a vtkRectilinearGrid
47 44
    if check_orientation(volgridgeom.axis_u, volgridgeom.axis_v, volgridgeom.axis_w):
48 -
        output = vtk.vtkRectilinearGrid()
49 -
        output.SetDimensions(len(x), len(y), len(z)) # note this subtracts 1
50 -
        output.SetXCoordinates(nps.numpy_to_vtk(num_array=x))
51 -
        output.SetYCoordinates(nps.numpy_to_vtk(num_array=y))
52 -
        output.SetZCoordinates(nps.numpy_to_vtk(num_array=z))
53 -
        return pyvista.wrap(output)
45 +
        return pyvista.RectilinearGrid(x + origin[0], y + origin[1], z + origin[2])
54 46
55 47
    # Otherwise use a vtkStructuredGrid
56 -
    output = vtk.vtkStructuredGrid()
57 -
    output.SetDimensions(len(x), len(y), len(z)) # note this subtracts 1
58 -
59 48
    # Build out all nodes in the mesh
60 49
    xx, yy, zz = np.meshgrid(x, y, z, indexing='ij')
61 50
    points = np.c_[xx.ravel('F'), yy.ravel('F'), zz.ravel('F')]
@@ -64,17 +53,14 @@
Loading
64 53
    rotation_mtx = np.array([volgridgeom.axis_u, volgridgeom.axis_v, volgridgeom.axis_w])
65 54
    points = points.dot(rotation_mtx)
66 55
67 -
    # Convert points to vtk object
68 -
    pts = vtk.vtkPoints()
69 -
    pts.SetNumberOfPoints(len(points))
70 -
    pts.SetData(nps.numpy_to_vtk(points))
71 -
    # Now build the output
72 -
    output.SetPoints(pts)
73 -
74 -
    return pyvista.wrap(output)
56 +
    output = pyvista.StructuredGrid()
57 +
    output.points = points
58 +
    output.dimensions = len(x), len(y), len(z)
59 +
    output.points += np.array(origin)
60 +
    return output
75 61
76 62
77 -
def volume_to_vtk(volelement):
63 +
def volume_to_vtk(volelement, origin=(0.0, 0.0, 0.0)):
78 64
    """Convert the volume element to a VTK data object.
79 65
80 66
    Args:
@@ -82,20 +68,14 @@
Loading
82 68
            convert
83 69
84 70
    """
85 -
    output = volume_grid_geom_to_vtk(volelement.geometry)
71 +
    output = volume_grid_geom_to_vtk(volelement.geometry, origin=origin)
86 72
    shp = get_volume_shape(volelement.geometry)
87 73
    # Add data to output
88 74
    for data in volelement.data:
89 75
        arr = data.array.array
90 76
        arr = np.reshape(arr, shp).flatten(order='F')
91 -
        c = nps.numpy_to_vtk(num_array=arr, deep=True)
92 -
        c.SetName(data.name)
93 -
        loc = data.location
94 -
        if loc == 'vertices':
95 -
            output.GetPointData().AddArray(c)
96 -
        else:
97 -
            output.GetCellData().AddArray(c)
98 -
    return pyvista.wrap(output)
77 +
        output[data.name] = arr
78 +
    return output
99 79
100 80
101 81
# Now set up the display names for the docs

@@ -9,51 +9,31 @@
Loading
9 9
10 10
__displayname__ = 'Surface'
11 11
12 -
import vtk
13 -
from vtk.util import numpy_support as nps
14 -
import pyvista
15 -
import omf
16 -
17 -
18 12
import numpy as np
13 +
import omf
14 +
import pyvista
19 15
20 16
from omfvista.utilities import check_orientation, check_orthogonal
21 17
from omfvista.utilities import add_data, add_textures
22 18
23 -
def surface_geom_to_vtk(surfgeom):
24 -
    """Convert the triangulated surface to a :class:`pyvista.UnstructuredGrid`
19 +
20 +
def surface_geom_to_vtk(surfgeom, origin=(0.0, 0.0, 0.0)):
21 +
    """Convert the triangulated surface to a :class:`pyvista.PolyData`
25 22
    object
26 23
27 24
    Args:
28 25
        surfgeom (:class:`omf.surface.SurfaceGeometry`): the surface geomotry to
29 26
            convert
30 27
    """
31 -
32 -
    output = vtk.vtkUnstructuredGrid()
33 -
    pts = vtk.vtkPoints()
34 -
    cells = vtk.vtkCellArray()
35 -
36 -
    # Generate the points
37 -
    pts.SetNumberOfPoints(surfgeom.num_nodes)
38 -
    pts.SetData(nps.numpy_to_vtk(surfgeom.vertices))
39 -
40 -
    # Generate the triangle cells
41 -
    cellConn = surfgeom.triangles.array
42 -
    cellsMat = np.concatenate(
43 -
        (np.ones((cellConn.shape[0], 1), dtype=np.int64)*cellConn.shape[1], cellConn),
44 -
        axis=1).ravel()
45 -
    cells = vtk.vtkCellArray()
46 -
    cells.SetNumberOfCells(cellConn.shape[0])
47 -
    cells.SetCells(cellConn.shape[0],
48 -
            nps.numpy_to_vtk(cellsMat, deep=True, array_type=vtk.VTK_ID_TYPE))
49 -
50 -
    # Add to output
51 -
    output.SetPoints(pts)
52 -
    output.SetCells(vtk.VTK_TRIANGLE, cells)
53 -
    return pyvista.wrap(output)
28 +
    pts = np.array(surfgeom.vertices)
29 +
    tris = np.array(surfgeom.triangles.array)
30 +
    faces = np.c_[np.full(len(tris), 3), tris]
31 +
    output = pyvista.PolyData(pts, faces)
32 +
    output.points += np.array(origin)
33 +
    return output
54 34
55 35
56 -
def surface_grid_geom_to_vtk(surfgridgeom):
36 +
def surface_grid_geom_to_vtk(surfgridgeom, origin=(0.0, 0.0, 0.0)):
57 37
    """Convert the 2D grid to a :class:`pyvista.StructuredGrid` object.
58 38
59 39
    Args:
@@ -63,8 +43,6 @@
Loading
63 43
    """
64 44
    surfgridgeom._validate_mesh()
65 45
66 -
    output = vtk.vtkStructuredGrid()
67 -
68 46
    axis_u = np.array(surfgridgeom.axis_u)
69 47
    axis_v = np.array(surfgridgeom.axis_v)
70 48
    axis_w = np.cross(axis_u, axis_v)
@@ -81,8 +59,6 @@
Loading
81 59
82 60
    z = np.array([oz])
83 61
84 -
    output.SetDimensions(len(x), len(y), len(z))
85 -
86 62
    # Build out all nodes in the mesh
87 63
    xx, yy, zz = np.meshgrid(x, y, z, indexing='ij')
88 64
    xx, yy, zz, = xx.ravel('F'), yy.ravel('F'), zz.ravel('F')
@@ -92,16 +68,16 @@
Loading
92 68
    # Rotate the points based on the axis orientations
93 69
    points = points.dot(rotation_mtx)
94 70
95 -
    # Convert points to vtk object
96 -
    pts = vtk.vtkPoints()
97 -
    pts.SetNumberOfPoints(len(points))
98 -
    pts.SetData(nps.numpy_to_vtk(points))
99 71
    # Now build the output
100 -
    output.SetPoints(pts)
72 +
    output = pyvista.StructuredGrid()
73 +
    output.points = points
74 +
    output.dimensions = len(x), len(y), len(z)
75 +
76 +
    output.points += np.array(origin)
77 +
    return output
101 78
102 -
    return pyvista.wrap(output)
103 79
104 -
def surface_to_vtk(surfel):
80 +
def surface_to_vtk(surfel, origin=(0.0, 0.0, 0.0)):
105 81
    """Convert the surface to a its appropriate VTK data object type.
106 82
107 83
    Args:
@@ -116,7 +92,7 @@
Loading
116 92
    elif isinstance(geom, omf.surface.SurfaceGridGeometry):
117 93
        builder = surface_grid_geom_to_vtk
118 94
119 -
    output = builder(geom)
95 +
    output = builder(geom, origin=origin)
120 96
121 97
    # Now add point data:
122 98
    add_data(output, surfel.data)

@@ -50,12 +50,14 @@
Loading
50 50
51 51
__displayname__ = 'Wrapper'
52 52
53 +
import numpy as np
53 54
import omf
54 -
import omfvista
55 55
import pyvista
56 56
57 +
import omfvista
58 +
57 59
58 -
def wrap(data):
60 +
def wrap(data, origin=(0.0, 0.0, 0.0)):
59 61
    """Wraps the OMF data object/project as a VTK data object. This is the
60 62
    primary function that an end user will harness.
61 63
@@ -100,7 +102,10 @@
Loading
100 102
    # get the class name
101 103
    key = data.__class__.__name__
102 104
    try:
103 -
        return wrappers[key](data)
105 +
        if key != 'Project':
106 +
            return wrappers[key](data, origin=origin)
107 +
        else:
108 +
            return wrappers[key](data)
104 109
    except KeyError:
105 110
        raise RuntimeError('Data of type ({}) is not supported currently.'.format(key))
106 111
@@ -111,8 +116,9 @@
Loading
111 116
    """
112 117
    # Iterate over the elements and add converted VTK objects a MultiBlock
113 118
    data = pyvista.MultiBlock()
119 +
    origin = np.array(project.origin)
114 120
    for i, e in enumerate(project.elements):
115 -
        d = omfvista.wrap(e)
121 +
        d = omfvista.wrap(e, origin=origin)
116 122
        data[i, e.name] = d
117 123
    return data
118 124
Files Coverage
omfvista 94.91%
Project Totals (7 files) 94.91%
210.1
TRAVIS_PYTHON_VERSION=3.6
TRAVIS_OS_NAME=linux
210.2
TRAVIS_PYTHON_VERSION=3.7
TRAVIS_OS_NAME=linux
210.3
TRAVIS_PYTHON_VERSION=3.8
TRAVIS_OS_NAME=linux
1
ignore:
2
  - "tests/*.py"
3
comment: false
Sunburst
The inner-most circle is the entire project, moving away from the center are folders then, finally, a single file. The size and color of each slice is representing the number of statements and the coverage, respectively.
Icicle
The top section represents the entire project. Proceeding with folders and finally individual files. The size and color of each slice is representing the number of statements and the coverage, respectively.
Grid
Each block represents a single file in the project. The size and color of each block is represented by the number of statements and the coverage, respectively.
Loading