TrixiParticles.jl icon indicating copy to clipboard operation
TrixiParticles.jl copied to clipboard

Add `OrientedBoundingBox` for spatial region analysis and particle selection

Open LasNikas opened this issue 3 months ago • 1 comments

This PR adds an OrientedBoundingBox that enables analysis of arbitrarily oriented rectangular regions within computational domains. For example: use is_in_oriented_box(coords, box) to define measurement windows for calculating flow rates through specific cross-sections.

Or for particle selection: using intersect(ic::InitialCondition, box::OrientedBoundingBox...) - particularly useful for creating clamped particles for the TLSPH system.

2D

using TrixiParticles
using Plots

data_dir = pkgdir(TrixiParticles, "examples", "preprocessing", "data")
geometry = load_geometry(joinpath(data_dir, "potato.asc"))

box_1 = OrientedBoundingBox(geometry)
box_2 = OrientedBoundingBox(geometry, local_axis_scale=(1.5, 2))
box_3 = OrientedBoundingBox(geometry, local_axis_scale=(3, 0.5))

plot(geometry, label="geometry", color=:black)
plot!(box_1, label="box: no scaling")
plot!(box_2, label="box: local_axis_scale=(1.5, 2)")
plot!(box_3, label="box: local_axis_scale=(3, 0.5)")
image
# Create a point cloud from a spherical shape (quarter circle sector)
shape = SphereShape(0.1, 1.5, (0.2, 0.4), 1.0, n_layers=4,
                    sphere_type=RoundSphere(; start_angle=0, end_angle=π/4))
box = OrientedBoundingBox(shape.coordinates)
image

3D

(hard to visualize but it's working)

file = pkgdir(TrixiParticles, "test", "preprocessing", "data")
geometry = load_geometry(joinpath(file, "inflow.stl"))
box_3d = OrientedBoundingBox(geometry)

trixi2vtk(stack(box_3d.spanning_vectors) .+ box_3d.box_origin)
image

LasNikas avatar Sep 29 '25 15:09 LasNikas

Codecov Report

:x: Patch coverage is 81.91489% with 17 lines in your changes missing coverage. Please review. :white_check_mark: Project coverage is 64.06%. Comparing base (c1db9a3) to head (b19c703).

Files with missing lines Patch % Lines
src/visualization/recipes_plots.jl 0.00% 14 Missing :warning:
src/preprocessing/geometries/geometries.jl 96.25% 3 Missing :warning:
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #929      +/-   ##
==========================================
+ Coverage   63.87%   64.06%   +0.19%     
==========================================
  Files         117      117              
  Lines        7842     7931      +89     
==========================================
+ Hits         5009     5081      +72     
- Misses       2833     2850      +17     
Flag Coverage Δ
unit 64.06% <81.91%> (+0.19%) :arrow_up:

Flags with carried forward coverage won't be shown. Click here to find out more.

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

:rocket: New features to boost your workflow:
  • :snowflake: Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

codecov[bot] avatar Sep 29 '25 16:09 codecov[bot]