Skip to main content

Design fields to fabrication-ready geometry

Project description

XelToFab

PyPI Python 3.13+ License: MIT

A design field post-processing pipeline that transforms continuous scalar fields from optimization solvers and neural networks into clean, fabrication-ready triangle meshes (3D) and contour representations (2D). The pipeline handles thresholding, smoothing, mesh extraction, quality improvement, visualization, and multi-format export.

Installation

# From PyPI (stable)
pip install xeltofab

# With optional format support
pip install "xeltofab[vtk,hdf5]"

# From source (development)
git clone https://github.com/xarthurx/XelToFab.git
cd XelToFab
uv sync

Quick Start

# Process a 3D density field into an STL mesh
xtf process density.npy -o output.stl

# Process with custom parameters and save a comparison plot
xtf process density.npy -o output.stl --threshold 0.4 --sigma 1.5 --viz

# Visualize a 2D density field
xtf viz density_2d.npy -o comparison.png

Pipeline

Scalar Field → Preprocess → Extract → Smooth → Mesh/Contours
     (.npy)      threshold     marching    Taubin     (.stl/.obj)
                 + morphology  cubes/sq.   filter
  1. Preprocess — Gaussian smoothing, Heaviside thresholding, morphological cleanup, small component removal
  2. Extract — Marching cubes (3D) or marching squares (2D) via scikit-image
  3. Smooth — Taubin smoothing via trimesh (3D meshes only)

Python API

import numpy as np
from xeltofab.state import PipelineState, PipelineParams
from xeltofab.pipeline import process
from xeltofab.io import save_mesh

# Create a scalar field (e.g., a sphere)
z, y, x = np.mgrid[-1:1:50j, -1:1:50j, -1:1:50j]
field = (x**2 + y**2 + z**2 < 0.5**2).astype(float)

# Run the pipeline
params = PipelineParams(threshold=0.5, smooth_sigma=1.0)
state = PipelineState(field=field, params=params)
result = process(state)

# Export
save_mesh(result, "sphere.stl")

Using Example Data

Pre-computed topology optimization results are included in data/examples/ (sourced from IDEALLab EngiBench):

from xeltofab.io import load_field
from xeltofab.pipeline import process

state = load_field("data/examples/beams_2d_50x100_sample0.npy")
result = process(state)

Supported Input Formats

Format Extensions Install
NumPy .npy, .npz Built-in
MATLAB .mat Built-in (via scipy)
CSV/Text .csv, .txt Built-in
VTK .vtk, .vtr, .vti pip install "xeltofab[vtk]"
HDF5/XDMF .h5, .hdf5, .xdmf pip install "xeltofab[hdf5]"
All formats pip install "xeltofab[all-formats]"

List available formats: xtf formats

Development

uv sync                          # Install deps
uv run pytest tests/ -v          # Run tests
uv run ruff check src/ tests/    # Lint
uv run ruff format src/ tests/   # Format
uv run marimo edit notebooks/demo.py  # Interactive demo

Project Structure

src/xeltofab/
├── state.py        Pipeline state + parameter models
├── preprocess.py   Field preprocessing
├── extract.py      Mesh/contour extraction
├── smooth.py       Taubin smoothing
├── pipeline.py     Orchestrator
├── io.py           File I/O (multi-format load, mesh export)
├── loaders/        Format-specific loaders (numpy, matlab, csv, vtk, hdf5)
├── field_plots.py  Matplotlib visualization
└── cli.py          CLI (xtf)

See docs/ARCHITECTURE.md for detailed architecture documentation.

Documentation

Full documentation is available at xel-to-fab.vercel.app.

Requirements

  • Python 3.13+
  • uv for development

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

xeltofab-0.3.3.tar.gz (32.3 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

xeltofab-0.3.3-py3-none-any.whl (42.8 kB view details)

Uploaded Python 3

File details

Details for the file xeltofab-0.3.3.tar.gz.

File metadata

  • Download URL: xeltofab-0.3.3.tar.gz
  • Upload date:
  • Size: 32.3 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for xeltofab-0.3.3.tar.gz
Algorithm Hash digest
SHA256 1ceab7846cc3d7232660390c113661e8d0b5f6190ca6a4157faf29d0f542280e
MD5 59e7a0362d06df9e26fed26278f0a1cd
BLAKE2b-256 e43dc0cc4b1b74b8516223e2d6078eb18e8c4bcfd5ed0e7b6980b3a8306e2dde

See more details on using hashes here.

Provenance

The following attestation bundles were made for xeltofab-0.3.3.tar.gz:

Publisher: publish-pypi.yml on xarthurx/XelToFab

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file xeltofab-0.3.3-py3-none-any.whl.

File metadata

  • Download URL: xeltofab-0.3.3-py3-none-any.whl
  • Upload date:
  • Size: 42.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for xeltofab-0.3.3-py3-none-any.whl
Algorithm Hash digest
SHA256 374f0d507a2bbef74c1ca6c6a7dbec0ef607a2737ef6542d70e876fd6e03934a
MD5 bfe18a52029b2d21086bb05ef7fc5b5b
BLAKE2b-256 97364d5f7a66d87af7eb84421d61dcb5674a169669ad945c2fd6362f86641323

See more details on using hashes here.

Provenance

The following attestation bundles were made for xeltofab-0.3.3-py3-none-any.whl:

Publisher: publish-pypi.yml on xarthurx/XelToFab

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page