Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
180 changes: 180 additions & 0 deletions docs/plans/2026-06-10-implement-ll-brepnet.md

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,9 @@ dependencies:
- -e ./ll_stepnet
- -e ./cadling
- -e ./geotoken
- -e ./ll_brepnet

# ll_brepnet training/eval (pytorch-lightning is pure-Python; pulls
# torchmetrics + tensorboard for logging and metrics)
- pytorch-lightning>=2.0.0
- tensorboard>=2.12.0
46 changes: 46 additions & 0 deletions ll_brepnet/ATTRIBUTION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Attribution & provenance

`ll_brepnet` is an **independent, MIT-licensed** implementation. It is *inspired
by* prior research on neural networks for boundary-representation (B-Rep) CAD
models, but it **does not include, copy, or adapt source code** from those
projects.

## Inspiration (ideas, not code)

- **BRepNet: A Topological Message Passing System for Solid Models** —
Lambourne, Willis, Jayaraman, Sanghi, Meltzer, Shayani. CVPR 2021.
[arXiv:2104.00706](https://arxiv.org/abs/2104.00706).
The Autodesk reference implementation (`AutodeskAILab/BRepNet`) is licensed
**CC BY-NC-SA 4.0** (NonCommercial + ShareAlike). To keep this package MIT and
free of NonCommercial restrictions, `ll_brepnet` deliberately does **not**
reproduce that code or its distinctive expression — in particular it does
**not** implement BRepNet's configurable *kernel*-based topological
convolution (the `kernels/*.json` winged-edge walk machinery). It uses only
the published *ideas* (coedge adjacency, message passing over the B-Rep,
fusing UV-grid geometry) as a guide.

- **UV-Net: Learning from Boundary Representations** — Jayaraman et al. The
UV-grid sampling + 1D/2D CNN surface/curve encoder idea informs our geometry
encoders, which are written from scratch as standard convolutional stacks.

## What this package is actually built on

The implementation is composed from the **LatticeLabs toolkit's own MIT-licensed
B-Rep machinery**, principally from `cadling`:

- coedge incidence extraction — `cadling.lib.topology.coedge_extractor`
- B-Rep face-graph + face/edge features — `cadling.lib.topology.brep_face_graph`
- UV-grid sampling — `cadling.lib.geometry.uv_grid_extractor`
- UV-Net-style encoders and the simple coedge message-passing encoder —
`cadling.models.segmentation.architectures.{uv_net,brep_net}`

Geometry I/O uses the public APIs of `pythonocc-core` and `occwl` (separate,
independently-licensed libraries consumed as dependencies — not vendored).

## Consequence

Because no CC BY-NC-SA code is copied, `ll_brepnet` is distributed under the
**MIT License** (see `LICENSE`), consistent with the rest of the toolkit, and
carries no NonCommercial or ShareAlike obligations. The trade-off is that it is
**not a faithful reproduction** of the BRepNet paper's architecture and is not
expected to match its published accuracy numbers.
21 changes: 21 additions & 0 deletions ll_brepnet/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2026 Lattice Labs

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
54 changes: 54 additions & 0 deletions ll_brepnet/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# ll_brepnet

A B-Rep **face-graph neural network** for CAD solid-model segmentation, in the
UV-Net / BRepNet lineage. `ll_brepnet` operates directly on the boundary
representation of a solid — faces and edges connected through oriented *coedges*
(carrying next / previous / mate / parent-face / parent-edge adjacency) — and
fuses that topology with UV-grid surface and curve geometry to predict a
semantic segment label for every face.

It is an **independent, MIT-licensed** package built on the LatticeLabs
toolkit's own B-Rep machinery (`cadling`). It is *inspired by* BRepNet
([arXiv:2104.00706](https://arxiv.org/abs/2104.00706)) and UV-Net but contains
no code from those projects — see [`ATTRIBUTION.md`](ATTRIBUTION.md).

> **Status — under active implementation.** This package is being built out
> milestone-by-milestone per
> [`docs/plans/2026-06-10-implement-ll-brepnet.md`](../docs/plans/2026-06-10-implement-ll-brepnet.md).
> The package installs and imports today (M0 complete). Extraction, dataset,
> model, training and evaluation land in subsequent milestones; this README and
> the documentation site are updated as each milestone is verified, and will
> never claim a capability that is not yet backed by working, tested code.

## Package layout

| Subpackage | Purpose |
|---|---|
| `ll_brepnet.pipelines` | STEP/JSON → coedge graph + geometry → `.npz`; dataset-manifest building |
| `ll_brepnet.dataloaders` | `BRepDataset` / `BRepDataModule`, multi-solid collation, face-count sampler |
| `ll_brepnet.models` | UV-Net geometry encoders + the `LLBRepNet` LightningModule + per-face seg head |
| `ll_brepnet.eval` | folder/checkpoint inference → per-face logits |

## Installation

`ll_brepnet` needs PyTorch, `pythonocc-core` and `occwl`, which on macOS must
come from conda (see the repo `CLAUDE.md` for the OpenMP rationale). The simplest
path is to reuse the existing `cadling` conda environment, which already
provides them, and add `pytorch-lightning`:

```bash
conda activate cadling
pip install pytorch-lightning
pip install -e ./ll_brepnet
```

Or create a standalone environment:

```bash
conda env create -f ll_brepnet/environment.yaml
conda activate ll-brepnet
```

## License

MIT — see [`LICENSE`](LICENSE) and [`ATTRIBUTION.md`](ATTRIBUTION.md).
25 changes: 25 additions & 0 deletions ll_brepnet/environment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Conda environment for ll_brepnet.
#
# IMPORTANT (macOS / Apple Silicon): pytorch MUST come from conda-forge, never
# from PyPI, to avoid the fatal OpenMP/libomp conflict documented in the repo
# CLAUDE.md ("OMP: Error #15"). pythonocc-core is conda-only. occwl and
# pytorch-lightning are pure-Python and installed via pip on top of conda.
#
# In practice ll_brepnet shares the existing `cadling` conda env, which already
# provides pytorch 2.7.1, pythonocc-core 7.8.1.1 and occwl 3.0.0; this file
# reproduces that stack standalone and adds pytorch-lightning.
name: ll-brepnet
channels:
- conda-forge
dependencies:
- python=3.12
- pytorch>=2.0.0
- pythonocc-core>=7.8.0
- numpy>=1.24.0
- scikit-learn>=1.0.0
- tqdm>=4.64.0
- pip
- pip:
- occwl>=3.0.0
- pytorch-lightning>=2.0.0
- -e .
64 changes: 64 additions & 0 deletions ll_brepnet/ll_brepnet/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
"""LL-BRepNet: a B-Rep face-graph neural network for CAD solid-model segmentation.

``ll_brepnet`` operates directly on the boundary representation (B-Rep) of a CAD
solid: faces and edges are connected through *coedges* (oriented half-edges that
carry next/previous/mate/parent-face/parent-edge adjacency). A coedge
message-passing encoder fuses topological adjacency with UV-grid surface/curve
geometry to predict a semantic segment label for every face.

The package is organised into four subpackages:

- :mod:`ll_brepnet.pipelines` -- STEP/JSON -> coedge graph + geometry -> ``.npz``
extraction and dataset-manifest building.
- :mod:`ll_brepnet.dataloaders` -- ``BRepDataset`` / ``BRepDataModule`` plus the
multi-solid collation and face-count batch sampler.
- :mod:`ll_brepnet.models` -- the UV-Net geometry encoders and the
``LLBRepNet`` LightningModule with its per-face segmentation head.
- :mod:`ll_brepnet.eval` -- folder/checkpoint inference producing per-face logits.

This is an independent MIT implementation built on the LatticeLabs toolkit's own
B-Rep machinery. It is *inspired by* BRepNet (Lambourne et al., CVPR 2021,
arXiv:2104.00706) and UV-Net, but contains no code from those projects; see
``ATTRIBUTION.md``.
"""

from __future__ import annotations

__version__ = "0.1.0"

import importlib

# Public API. Resolved lazily (PEP 562) so ``import ll_brepnet`` stays cheap and
# does not eagerly pull in torch / pythonocc / cadling: the heavy module is only
# imported the first time the attribute is accessed.
_LAZY_EXPORTS = {
"LLBRepNet": "ll_brepnet.models.ll_brepnet",
"UVNetSurfaceEncoder": "ll_brepnet.models.uvnet_encoders",
"UVNetCurveEncoder": "ll_brepnet.models.uvnet_encoders",
"BRepDataset": "ll_brepnet.dataloaders.brep_dataset",
"BRepDataModule": "ll_brepnet.dataloaders.brep_dataset",
"BRepBatch": "ll_brepnet.dataloaders.brep_dataset",
"brep_collate_fn": "ll_brepnet.dataloaders.brep_dataset",
"MaxNumFacesSampler": "ll_brepnet.dataloaders.max_num_faces_loader",
"BRepDataExtractor": "ll_brepnet.pipelines.extract_brepnet_data_from_step",
"extract_brepnet_data_from_step": "ll_brepnet.pipelines.extract_brepnet_data_from_step",
"extract_step_files": "ll_brepnet.pipelines.extract_brepnet_data_from_step",
"extract_brepnet_data_from_json": "ll_brepnet.pipelines.extract_brepnet_data_from_json",
"build_dataset_file": "ll_brepnet.pipelines.build_dataset_file",
"prepare_fusion360": "ll_brepnet.pipelines.quickstart",
"evaluate_folder": "ll_brepnet.eval.evaluate",
"do_training": "ll_brepnet.train",
}

__all__ = ["__version__", *sorted(_LAZY_EXPORTS)]


def __getattr__(name: str):
module_path = _LAZY_EXPORTS.get(name)
if module_path is None:
raise AttributeError(f"module 'll_brepnet' has no attribute {name!r}")
return getattr(importlib.import_module(module_path), name)


def __dir__():
return sorted([*globals().keys(), *_LAZY_EXPORTS])
4 changes: 4 additions & 0 deletions ll_brepnet/ll_brepnet/dataloaders/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
"""Dataset and batching: ``BRepDataset`` / ``BRepDataModule``, the multi-solid
collation with index-offset arithmetic, and the face-count batch sampler."""

from __future__ import annotations
Loading
Loading