linux-macos-windows

GridVisualizeTools.jl

Lean package providing a number of tools used in GridVisualize.jl and PlutoVista.jl. Possibly also useful for other packages.

Color and colormaps

GridVisualizeTools.region_cmapFunction
region_cmap(n)

Create customized distinguishable colormap for interior regions. For this we use a kind of pastel colors.

region_cmap(10)[1]

# output

RGB{Float64}(0.85, 0.6, 0.6)
source
region_cmap(5)
GridVisualizeTools.bregion_cmapFunction
bregion_cmap(n)

Create customized distinguishable colormap for boundary regions. These use fully saturated colors.

bregion_cmap(10)[1]

# output

RGB{Float64}(1.0, 0.0, 0.0)
source
bregion_cmap(5)
GridVisualizeTools.rgbtupleFunction
rgbtuple(c)

Create color tuple from color description (e.g. string)

julia> rgbtuple(:red)
(1.0, 0.0, 0.0)

julia> rgbtuple("red")
(1.0, 0.0, 0.0)
source
rgbtuple(c)

Create color tuple from RGB color.

julia> rgbtuple(RGB(0.0,1,0))
(0.0, 1.0, 0.0)
source
rgbtuple(:red)
# output

(1.0,1.0,1.0)
ColorTypes.RGBType
RGB(c)

Create RGB color from color name string.

julia> Colors.RGB("red") RGB{Float64}(1.0,0.0,0.0) ```

source
RGB(c)

Create RGB color from color name symbol.

julia> Colors.RGB(:red)
RGB{Float64}(1.0, 0.0, 0.0)
source
RGB(c)

Create RGB color from tuple

julia> Colors.RGB((1.0,0,0))
RGB{Float64}(1.0, 0.0, 0.0)
source
RGB(:red)
RGB("green")

Visibility handling of grid cells

GridVisualizeTools.extract_visible_cells3DFunction
extract_visible_cells3D(
    coord,
    cellnodes,
    cellregions,
    nregions,
    xyzcut;
    primepoints,
    Tp,
    Tf
)

Extract visible tetrahedra - those intersecting with the planes x=xyzcut[1] or y=xyzcut[2] or z=xyzcut[3].

Return corresponding points and facets for each region for drawing as mesh (Makie,MeshCat) or trisurf (pyplot)

source
GridVisualizeTools.extract_visible_bfaces3DFunction
extract_visible_bfaces3D(
    coord,
    bfacenodes,
    bfaceregions,
    nbregions,
    xyzcut;
    primepoints,
    Tp,
    Tf
)

Extract visible boundary faces - those not cut off by the planes x=xyzcut[1] or y=xyzcut[2] or z=xyzcut[3].

Return corresponding points and facets for each region for drawing as mesh (Makie,MeshCat) or trisurf (pyplot)

source

Marching triangles and tetrahdra

GridVisualizeTools.marching_tetrahedraFunction
marching_tetrahedra(
    coord,
    cellnodes,
    func,
    planes,
    flevels;
    tol,
    primepoints,
    primevalues,
    Tv,
    Tp,
    Tf
)

Extract isosurfaces and plane interpolation for function on 3D tetrahedral mesh.

The basic observation is that locally on a tetrahedron, cuts with planes and isosurfaces of P1 functions look the same. This method calculates data for several plane cuts and several isosurfaces at once.

Input parameters:

  • coord: 3 x n_points matrix of point coordinates
  • cellnodes: 4 x n_cells matrix of point numbers per tetrahedron
  • func: n_points vector of piecewise linear function values
  • planes: vector of plane equations ax+by+cz+d=0,each stored as vector [a,b,c,d]
  • flevels: vector of function isolevels

Keyword arguments:

  • tol: tolerance for tet x plane intersection
  • primepoints: 3 x n_prime matrix of "corner points" of domain to be plotted. These are not in the mesh but are used to calculate the axis size e.g. by Makie
  • primevalues: n_prime vector of function values in corner points. These can be used to calculate function limits e.g. by Makie
  • Tv: type of function values returned
  • Tp: type of points returned
  • Tf: type of facets returned

Return values: (points, tris, values)

  • points: vector of points (Tp)
  • tris: vector of triangles (Tf)
  • values: vector of function values (Tv)

These can be readily turned into a mesh with function values on it.

Caveat: points with similar coordinates are not identified, e.g. an intersection of a plane and an edge will generate as many edge intersection points as there are tetrahedra adjacent to that edge. As a consequence, normal calculations for visualization always will end up with facet normals, not point normals, and the visual impression of a rendered isosurface will show its piecewise linear genealogy.

source

Equidistant markers on polylines

GridVisualizeTools.markerpointsFunction
markerpoints(points, nmarkers, transform)

Assume that points are nodes of a polyline. Place nmarkers equidistant markers at the polyline, under the assumption that the points are transformed via the transformation matrix M for visualization.

source

Planes & isolevels

GridVisualizeTools.makeplanesFunction
makeplanes(xyzmin, xyzmax, x, y, z)

For vectors of x, y and z coordinates, create equations for planes parallel to the coordinate axes.

source
using GridVisualizeTools
makeplanes([0.,0,0], [1.,1,1], [0.5], [],[])
# output
1-element Vector{Vector{Float64}}:
 [1.0, 0.0, 0.0, -0.5]
using GridVisualizeTools
makeplanes([0.,0,0], [1.,1,1], [0.5], [0.5],[])
# output
2-element Vector{Vector{Float64}}:
 [1.0, 0.0, 0.0, -0.5]
 [0.0, 1.0, 0.0, -0.5]
GridVisualizeTools.makeisolevelsFunction
makeisolevels(func, levels, limits, colorbarticks)

Update levels, limits, colorbartics based on vector given in func.

  • if limits[1]>limits[2], replace it by extrema(func).
  • if levels is a number, replace it with a linear range in limits of length levels+2
  • if colorbarticks is nothing replace it with levels and add the limits to the result otherwise, if it is a number, replace it with a linear range of corresponding length
source
using GridVisualizeTools
makeisolevels(collect(0:0.1:10), 1, (-1,1),3)
# output
([-1.0, 0.0, 1.0], (-1, 1), [-1.0, 0.0, 1.0])
using GridVisualizeTools
makeisolevels(collect(0:0.1:10), 1, (1,-1),3)
# output
([0.0, 5.0, 10.0], (0.0, 10.0), [0.0, 5.0, 10.0])
using GridVisualizeTools
makeisolevels(collect(0:0.1:10), 1, (1,-1),nothing)
# output
([0.0, 5.0, 10.0], (0.0, 10.0), [0.0, 5.0, 10.0])

Private API

GridVisualizeTools.tet_x_plane!Function
tet_x_plane!(
    ixcoord,
    ixvalues,
    pointlist,
    node_indices,
    planeq_values,
    function_values;
    tol
)

Calculate intersections between tetrahedron with given piecewise linear function data and plane

Adapted from gltools.

A non-empty intersection is either a triangle or a planar quadrilateral, defined by either 3 or 4 intersection points between tetrahedron edges and the plane.

Input:

  • pointlist: 3xN array of grid point coordinates
  • nodeindices: 4 element array of node indices (pointing into pointlist and functionvalues)
  • planeq_values: 4 element array of plane equation evaluated at the node coordinates
  • function_values: N element array of function values

Mutates:

  • ixcoord: 3x4 array of plane - tetedge intersection coordinates
  • ixvalues: 4 element array of function values at plane - tetdedge intersections

Returns:

  • nxs,ixcoord,ixvalues

This method can be used both for the evaluation of plane sections and for the evaluation of function isosurfaces.

source