Skip to content

Data

In 3D data visualization, we distinguish two types of 3D data: 3D geometry and data associated with 3D geometry.

  • 3D geometry as data: In this category, we are mainly interested in visualizing the shape/location of the 3D geometry. For example, the shape of a deformed mesh or the location of points in a point cloud.
  • Data associated with 3D geometry: In this category, the data is a spatially varying field, and we would like to visualize its value at different locations. For example, the Gaussian curvature field on a curved surface, or the geodesic distance on a surface with respect to a source surface point.

Mesh elements

3D geometry are often represented as a mesh for visualization purposes. A mesh, such as the bunny model on the right1, consists of a set of vertices, edges, and facets. Data associated with 3D geometry are represented as an attribute of a mesh. Each attribute is defined for a specific element type (vertex, edge or facet).

In Hakowan, we leverage Lagrange's SurfaceMesh data structure to represent both 3D geometry and store data associated with 3D geometry as mesh attributes. In a sense, the elements of a mesh defines the "rows" of a 3D data frame, and the attributes of a mesh defines the "columns" of a 3D data frame. In addition, Hakowan can also extract geometry and data associated with geometry from a number of common 3D file formats such as OBJ, PLY, GLTF and MSH.

Hakowan accepts mesh files and Lagrange meshes directly:

l0 = hkw.layer("shape.obj")
l1 = hkw.layer(lagrange.io.load_mesh("shape.obj"))

Two-dimensional lagrange.SurfaceMesh inputs are embedded in the XY plane, with facets and attributes preserved. Two-component vector, position, normal, tangent, and bitangent attributes are embedded as (x, y, 0); UV attributes remain two-dimensional.

For a mesh defined by arrays, pass a mapping containing vertices and facets. Two-column vertices are embedded in the XY plane with Z set to zero; faces retain their connectivity. Optional vertex_attributes and facet_attributes mappings attach data to mesh elements:

For two-column vertices, two-component mapped attributes are also padded with a zero Z component.

mesh_layer = hkw.layer(
    {
        "vertices": [[0, 0], [1, 0], [1, 1], [0, 1]],
        "facets": [[0, 1, 2], [0, 2, 3]],
        "vertex_attributes": {"temperature": [10, 20, 30, 40]},
    }
).mark("surface")

Three-column vertices are also accepted. This representation supports planar 2D meshes without treating their vertices as a facet-free point cloud.

Numeric arrays with shape (n, 2) or (n, 3) become point clouds. Two-dimensional positions receive a zero Z coordinate:

points = np.array([[0, 0, 0], [1, 0, 0], [0, 1, 0]])
points_layer = hkw.layer(points).mark("point")

Tabular position inference recognizes exactly x, y, z, X, Y, and Z (all three axes), or the 2D pairs x, y and X, Y. When only two position columns are present, the generated Z coordinate is zero. Other column names are attributes, not inferred positions. The positions= argument can select 2 or 3 existing column names, but only for pandas and xarray inputs; arrays, files, meshes, PyVista/Trimesh objects, and other data types reject positions=. Other numeric columns become vertex attributes, boolean columns are retained as 0/1 attributes, and unsupported non-numeric columns are ignored. Position tables must contain at least one row.

table = pandas.DataFrame(
    {
        "east": [0, 1, 0],
        "north": [0, 0, 1],
        "height": [0, 0, 0],
        "temperature": [12.0, 18.0, 25.0],
    }
)
points_layer = hkw.layer(table, positions=("east", "north", "height")).mark("point")

PyVista polygonal datasets and Trimesh meshes preserve their surface topology, numeric point/vertex attributes, and numeric cell/face attributes:

surface_layer = hkw.layer(pyvista_mesh)
surface_layer = hkw.layer(trimesh_mesh)

These libraries are optional and are not imported by Hakowan. Install all four interoperability dependencies with pip install "hakowan[data]".

Inspecting data

Use hkw.inspect() before building a layer to obtain a JSON-safe summary of the geometry and its attributes. This is useful for scripts and agents that must choose fields without guessing their names or shapes.

The CLI equivalent is hkw inspect shape.ply. It prints one line per attribute, with per-channel extrema: scalars for one channel, tuples for multichannel data.

summary = hkw.inspect("shape.ply")

print(summary.vertex_count, summary.facet_count)
for attr in summary.attributes:
    print(attr.name, attr.element, attr.channels, attr.minimum, attr.maximum)

# Suitable for JSON serialization or model/tool input.
payload = summary.to_dict()

For indexed attributes, value_count is the number of unique stored values and element_count is the number of indices. Numeric summaries include finite and non-finite row counts, per-channel bounds, and quartiles.

Before rendering or compiling programmatically, use hkw.validate() to check whether the selected fields and backend are supported. For portable specifications and small validated edits, see the canonical specification guide.

Region of interest

When specifying the data, we can optionally specify a region of interest. The region of interest is an axis-aligned box that defines the region in the center of the rendering.

l0 = hkw.layer().data("shape.obj", roi_box=[[0, 0, 0], [1, 1, 1]])

See the Smoothed Particle Hydrodynamics example for a usage of region of interest.


  1. 3D model source: origamix rabbit ↩