Skip to main content

2D triangle mesh remeshing toolkit (greedy + patch drivers, pocket fill, visualization).

Project description

SOFIA - Scalable Operators for Field-driven Iso/Ani Adaptation

A Modern 2D Triangular Mesh Modification Library

License: MIT Python 3.8+ Tests

FeaturesInstallationQuick StartDocumentationExamplesRoadmap


What is SOFIA?

SOFIA is a pure Python library for 2D triangular mesh modification and remeshing. It provides robust, high-quality local operations to edit, refine, and optimize meshes while maintaining mesh conformity and quality.

Perfect for:

  • Computational scientists working with 2D simulations
  • Computer graphics professionals needing mesh processing
  • Numerical analysis requiring adaptive mesh refinement
  • Researchers in mesh generation and optimization

Features

Core Operations

  • Edge Split - Midpoint and Delaunay-based splitting
  • Edge Collapse - Quality-preserving mesh coarsening
  • Edge Flip - Improve triangle quality through flipping
  • Vertex Insertion/Removal - Add or remove mesh vertices
  • Pocket Filling - Fill holes in meshes intelligently
  • Boundary Operations - Safe manipulation of mesh boundaries

Quality & Robustness

  • Quality Metrics - Min angle, area, shape measures
  • Conformity Checks - Ensure valid mesh topology
  • Amortized Validation - Fast incremental checking
  • Strict Mode - Optional rigorous validation
  • Area Preservation - Maintain geometric properties

Workflows

  • Greedy Remeshing - Iterative quality improvement
  • Patch-based Processing - Batch operations on mesh regions
  • Visualization - Built-in plotting with Matplotlib
  • Extensive Testing - 50+ unit tests for reliability

Installation

Using pip (Recommended)

pip install sofia-mesh

From Source

git clone https://github.com/youssef-mesri/sofia.git
cd sofia
pip install -e .

Requirements

  • Python 3.8 or higher
  • NumPy ≥ 1.20
  • SciPy ≥ 1.7
  • Matplotlib ≥ 3.3

Quick Start

Basic Example - Improve Mesh Quality

import numpy as np
from sofia import PatchBasedMeshEditor

# Create a simple mesh
points = np.array([
    [0.0, 0.0], [1.0, 0.0], [0.5, 0.8],
    [0.0, 1.0], [1.0, 1.0]
])
triangles = np.array([
    [0, 1, 2], [0, 2, 3], [1, 4, 2], [3, 2, 4]
])

# Initialize editor
editor = PatchBasedMeshEditor(points, triangles)

# Split an edge to refine the mesh
success = editor.split_edge(edge_id=0, method='midpoint')
print(f"Edge split: {success}")

# Get the updated mesh
new_points = editor.pts
new_triangles = editor.tris

# Check mesh quality
min_angle = editor.mesh_min_angle()
print(f"Minimum angle: {min_angle:.2f}°")

Remeshing Example

from sofia.core.remesh_driver import greedy_remesh

# Iteratively improve mesh quality
improved_editor = greedy_remesh(
    editor,
    target_min_angle=25.0,  # Target minimum angle in degrees
    max_iterations=100
)

print(f"Final quality: {improved_editor.mesh_min_angle():.2f}°")

Documentation


Examples

Check out the examples/ directory for more:

  • basic_remeshing.py - Simple mesh refinement
  • quality_improvement.py - Iterative quality optimization
  • boundary_operations.py - Boundary manipulation

Roadmap

Current (v1.0) - Python Implementation

  • Pure Python implementation
  • All core features working
  • Suitable for meshes up to ~10K triangles
  • Easy installation, no compilation needed

Next (v2.0) - High-Performance C++ Backend

  • 20-50x performance improvement 🚀
  • Transparent integration (same API)
  • Suitable for meshes up to 1M+ triangles
  • Optional: falls back to Python if C++ unavailable
  • Status: In development (private branch)

Future (v3.0+)

  • GPU acceleration
  • 3D tetrahedral mesh support
  • Parallel batch processing
  • Advanced anisotropic remeshing

Citation

If you use SOFIA in your research, please cite:

@software{sofia2025,
  author = {Mesri, Youssef},
    title = {SOFIA: Scalable Operators for Field-driven Iso/Ani Adaptation},
  year = {2025},
  url = {https://github.com/youssef-mesri/sofia},
  version = {1.0.0}
}

Contributing

Contributions are welcome! Please see CONTRIBUTING.md for guidelines.


License

SOFIA is released under the MIT License.


Acknowledgments

  • Inspired by classical mesh modification algorithms
  • Built with modern Python best practices
  • Developed for research in computational geometry

Contact

Author: Youssef Mesri


Made with love for the computational geometry community

Star us on GitHub if you find SOFIA useful!

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

sofia_mesh-0.1.0.tar.gz (218.2 kB view details)

Uploaded Source

Built Distribution

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

sofia_mesh-0.1.0-py3-none-any.whl (258.2 kB view details)

Uploaded Python 3

File details

Details for the file sofia_mesh-0.1.0.tar.gz.

File metadata

  • Download URL: sofia_mesh-0.1.0.tar.gz
  • Upload date:
  • Size: 218.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.8.10

File hashes

Hashes for sofia_mesh-0.1.0.tar.gz
Algorithm Hash digest
SHA256 cd062a08ad6fb5a1b0bf8e51e8103e3806b5d31d884114515e37d20981c90ea5
MD5 d435da0a9fd18fc4e2f062625918300b
BLAKE2b-256 87123d5bbc239bb87a387d22f08078d2781f0e45074f5e762272cb8604c0e065

See more details on using hashes here.

File details

Details for the file sofia_mesh-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: sofia_mesh-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 258.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.8.10

File hashes

Hashes for sofia_mesh-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f2163e9bf5a37639b3a4fc0d9c512dc9c670cb529ab00e11f00884e33252365d
MD5 db0e24cbdb91d0dcebc576d81566ff48
BLAKE2b-256 1a5acb51058d7ed7d55bd73c5cd940e5f074cc67e39d2a1463d377245dbdd446

See more details on using hashes here.

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