Module: graphicsDataUtilities

Utility functions for visualization, which provides functions for special graphics manipulation, colors, mesh manipulation, etc.; note that specific function for GraphicsData creation now moved into the graphics submodule; includes functionality like mesh manipulation and some helper functions

  • Author: Johannes Gerstmayr

  • Date: 2020-07-26 (created) Modified: 2024-05-10 (moved primitive functions to graphics)

  • Notes:
    Some useful colors are defined, using RGBA (Red, Green, Blue and Alpha = opacity) channels in the range [0,1], e.g., red = [1,0,0,1].
    Available colors are: color4red, color4green, color4blue, color4cyan, color4magenta, color4yellow, color4orange, color4pink, color4lawngreen, color4violet, color4springgreen, color4dodgerblue, color4grey, color4darkgrey, color4lightgrey, color4lightred, color4lightgreen, color4steelblue, color4brown, color4black, color4darkgrey2, color4lightgrey2, color4white
    Additionally, a list of 16 colors ‘color4list’ is available, which is intended to be used, e.g., for creating n bodies with different colors

Function: SwitchTripletOrder

SwitchTripletOrder(vector)

  • function description:
    helper function to switch order of three items in a list; mostly used for reverting normals in triangles
  • input:
    3D vector as list or as np.array
  • output:
    interchanged 2nd and 3rd component of list

Function: ComputeTriangleNormal

ComputeTriangleNormal(p0, p1, p2)

  • function description:
    compute normalized normal for 3 triangle points
  • input:
    3D vector as list or as np.array
  • output:
    normal as np.array

Function: ComputeTriangleArea

ComputeTriangleArea(p0, p1, p2)

  • function description:
    compute area of triangle given by 3 points
  • input:
    3D vector as list or as np.array
  • output:
    area as float

Function: RefineMesh

RefineMesh(points, triangles)

  • function description:
    refine triangle mesh; every triangle is subdivided into 4 triangles
  • input:
    points: list of np.array with 3 floats per point
    triangles: list of np.array with 3 int per triangle (0-based indices to triangles)
  • output:
    returns [points2, triangles2] containing the refined mesh; if the original mesh is consistent, no points are duplicated; if the mesh is not consistent, some mesh points are duplicated!
  • notes:
    becomes slow for meshes with more than 5000 points

Relevant Examples (Ex) and TestModels (TM) with weblink to github:


Function: ShrinkMeshNormalToSurface

ShrinkMeshNormalToSurface(points, triangles, distance)

  • function description:
    shrink mesh using triangle normals; every point is at least moved a distance ‘distance’ normal from boundary
  • input:
    points: list of np.array with 3 floats per point
    triangles: list of np.array with 3 int per triangle (0-based indices to triangles)
    distance: float value of minimum distance
  • output:
    returns [points2, triangles2] containing the refined mesh; currently the points of the subdivided triangles are duplicated!
  • notes:
    ONLY works for consistent meshes (no duplicated points!)

Relevant Examples (Ex) and TestModels (TM) with weblink to github:


Function: ComputeTriangularMesh

ComputeTriangularMesh(vertices, segments)

  • function description:
    helper function to compute triangular mesh from list of vertices (=points) and segments;
    computes triangular meshes for non-convex case. In order to make it efficient, it first computes
    neighbors and then defines triangles at segments to be inside/outside. Finally neighboring
    relations are used to define all triangles inside/outside
    finally only returns triangles that are inside the segments
  • input:
    vertices: list of pairs of coordinates of vertices in mesh [x,y]
    segments: list of segments, which are pairs of node numbers [i,j], defining the boundary of the mesh;
    the ordering of the nodes is such that left triangle = inside, right triangle = outside, compare example with segment [V1,V2]:
    inside
    V1 V2
    O———-O
    outside
  • output:
    triangulation structure of Delaunay(…), see scipy.spatial.Delaunaystructure, containing all simplices (=triangles)
  • notes:
    Delauney will not work if points are duplicated; you must first create point lists without duplicated points!
  • example:
points = np.array([[0, 0], [0, 2], [2, 2], [2, 1], [1, 1], [0, 1], [1, 0]])
segments = [len(points)-1,0]
for i in range(len(points)-1):
    segments += [i,i+1]
tri = ComputeTriangularMesh(points, segments)
print(tri.simplices)

Function: SegmentsFromPoints

SegmentsFromPoints(points, pointIndexOffset = 0, invert = False, closeCurve = True)

  • function description:
    convert point list into segments (indices to points); point indices start with pointIndexOffset
  • input:
    invert: True: circle defines outter boundary; False: circle cuts out geometry inside a geometry
    pointIndexOffset: point indices start with pointIndexOffset
  • output:
    return segments, containing list of lists of point indices for segments

Function: CirclePointsAndSegments

CirclePointsAndSegments(center = [0,0], radius = 0.1, invert = False, pointIndexOffset = 0, nTiles = 16)

  • function description:
    create points and segments, used in SolidExtrusion(…) for circle with given parameters
  • input:
    center: 2D center point (list/numpy array) for circle center
    radius: radius of circle
    invert: True: circle defines outter boundary; False: circle cuts out geometry inside a geometry
    pointIndexOffset: point indices start with pointIndexOffset
    nTiles: number of tiles/segments for circle creation (higher is finer)
  • output:
    return [points, segments], both containing lists of lists
  • notes:
    geometries may not intersect!

Function: GraphicsDataRectangle

GraphicsDataRectangle(xMin, yMin, xMax, yMax, color = [0.,0.,0.,1.])

  • function description:
    generate graphics data for 2D rectangle
  • input:
    minimal and maximal cartesian coordinates in (x/y) plane; color provided as list of 4 RGBA values
  • output:
    graphicsData dictionary, to be used in visualization of EXUDYN objects
  • notes:
    DEPRECATED

Relevant Examples (Ex) and TestModels (TM) with weblink to github:


Function: GraphicsDataOrthoCubeLines

GraphicsDataOrthoCubeLines(xMin, yMin, zMin, xMax, yMax, zMax, color = [0.,0.,0.,1.])

  • function description:
    generate graphics data for orthogonal block drawn with lines
  • input:
    minimal and maximal cartesian coordinates for orthogonal cube; color provided as list of 4 RGBA values
  • output:
    graphicsData dictionary, to be used in visualization of EXUDYN objects
  • notes:
    DEPRECATED

Relevant Examples (Ex) and TestModels (TM) with weblink to github: