Skip to content

feat(Octree): adaptive octree in geometry - #1415

Open
BotellaA wants to merge 10 commits into
nextfrom
feat/octree
Open

BotellaA wants to merge 10 commits into
nextfrom
feat/octree

Conversation

@BotellaA

Copy link
Copy Markdown
Member

Adaptive octree used by the octree metric of Geode-Common (feat/octree, PR #691) and the Simplex mesher (feat/octree, PR #494).

Octree<dimension> (geometry)

  • Adaptive 2D/3D octree on a root grid covering a domain box. Cells are indexed in creation order, and refining a leaf appends its 2^dimension children (indices never change, no coarsening).
  • Integer anchors on the finest lattice (21 bits per axis in 3D, 31 in 2D), so max_depth() follows from the root grid size.
  • Queries: leaf_containing, cell_bounding_box, cell_center, cell_lengths, leaves, parent/children, traverse( filter, action ) with pruning.
  • face_neighbor_leaves and balance( BALANCE_TYPE ) (2:1 balance, deterministic FIFO order).
  • cell_attribute_manager(): attributes on all cells, inherited by the children on refinement. Serializable.

Conversion to meshes (mesh helpers)

  • convert_octree_into_hybrid_solid (3D) and convert_octree_into_polygonal_surface (2D): one hexahedron/quadrangle per leaf, leaf attributes transferred. Non-conforming at level jumps; meant for visualization and export.

Tests

test-octree (refinement, queries, traversal, neighbours, balance, serialization) and test-convert-octree.

🤖 Generated with Claude Code

BotellaA and others added 3 commits November 16, 2026 11:27
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Comment thread include/geode/geometry/octree.hpp Resolved
Comment thread include/geode/geometry/octree.hpp Resolved
Comment thread include/geode/geometry/octree.hpp Resolved
BotellaA and others added 2 commits November 19, 2026 10:04
The template definition of Octree::traverse moves from the detail folder
(advanced header, outside geode::detail) to octree.hpp. FACE_SIDE and
BALANCE_TYPE document how face_neighbor_leaves() and balance() use them.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@BotellaA
BotellaA marked this pull request as ready for review November 19, 2026 09:10
@BotellaA
BotellaA requested a review from panquez November 19, 2026 09:10
GCC rejects a member of Octree::Impl (external linkage) whose type is
declared in an anonymous namespace (-Werror=subobject-linkage).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@panquez panquez left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM but there is too much uses of uint32_t and uint64_t which is not mainly used in OpenGeode

Comment thread include/geode/geometry/octree.hpp Outdated
* 2^(dimension-1) finer leaves of a one-level-finer neighbor.
*/
using FaceNeighbors =
absl::InlinedVector< index_t, 1u << ( dimension - 1 ) >;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

put this in a variable like NB_CHILDREN

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added NB_FACE_CHILDREN (2^(dimension-1), the children of a cell touching one of its faces), used for FaceNeighbors and in the docs (1d125c6).

Comment thread include/geode/geometry/octree.hpp Outdated
/*!
* Minimal corner of the cell in the finest lattice.
*/
[[nodiscard]] const std::array< uint32_t, dimension >& cell_anchor(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use index_t instead of uint32 ?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in 1d125c6: anchors and lattice values are index_t (they fit in 31 bits), in the API, the implementation and the tests.

/*!
* All the leaf cells, sorted by cell index.
*/
[[nodiscard]] std::vector< index_t > leaves() const;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could be intersecting to have of the leaves from a non leaves level cell?

@BotellaA BotellaA Nov 20, 2026 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added leaves( cell ) (df4ed85): the leaves of the subtree of a cell (the cell itself if it is a leaf), in depth-first order, children in index order. Also bound in Python.

Comment thread src/geode/geometry/octree.cpp Outdated
}
const auto smallest_side =
*std::min_element( sides.begin(), sides.end() );
uint64_t nb_roots{ 1 };

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why using uint64?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not needed there: the guard now checks nb < NO_ID / nb_roots before the product, with index_t (1d125c6, test_elongated covers each guard). The conversion corner keys are index_t too. uint64_t remains only for the locational code used as hash key (sentinel bit + 21 bits x 3 axes = 64 bits), which needs it, and for the random generator of the test.

BotellaA and others added 4 commits November 20, 2026 15:51
…n count

Anchors and lattice values fit in 31 bits: index_t replaces uint32_t,
and the corner keys of the conversions no longer need uint64_t. The
root count guard checks before the product instead of using uint64_t.
NB_FACE_CHILDREN names 2^(dimension-1).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Octree2D/Octree3D (queries, refine, traverse with Python callables,
face_neighbor_leaves, balance, cell attributes) with index checks, and
convert_octree_into_polygonal_surface / convert_octree_into_hybrid_solid.
The geometry module imports opengeode_py_basic for AttributeManager.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants