Intersection of cylinder with box/plane

I just saw @tpietzsch’s latest awesome addition to BigDataViewer: (Real)Box Selection Dialogs in BigDataViewer

The intersection of box and viewer plane and rasterization via @awalter17’s awesome imglib2-roi is very interesting for me as I have a similar problem: Instead of intersecting two boxes (considering the plane a box), I need an intersection of a box with a cylinder or a box with a circle. It is important that cylinder/circle and box are not axis aligned. Is there any such functionality in imglib2-roi to do that efficiently? That would be amazing!

1 Like

@hanslovsky it should be possible. imglib2-roi has a Sphere implementation, but no cylinder (you could define a cylinder using DefaultRealMaskRealInterval). Both of these masks could then be converted to a RealRandomAccessibleRealInterval and then rastered via Views similar to what @tpietzsch has done.

Additionally, any real-space mask in imglib2-roi can be transformed with a RealTransform so they don’t need to be axis aligned.

1 Like

Yes, would be possible with imglib-roi once there is an implementation for Cylinder.
You would use the appropriate GeomMasks methods to create box and cylinder masks, which are basically Predicate<Localizable>, can be combined using and, or, etc methods, and translated using transform.

“efficiently” might be a problem here… The way it works is that you ask: is a coordinate inside the region. Which just does a (shortcutting) logical AND (is it inside the cyinder && is it inside the box).
You will not get a simplified parametric description (what would that be anyway) and you will not necessarily get a tight bounding box. It’s also not super-slow. Depends on your use-case.

Thank you @awalter17 and @tpietzsch

My use case is painting a 2D circle (planar in the current viewer window) into data that is not axis aligned with the viewer, i.e. no axis of the data is orthogonal to the viewer window. Because voxels have a spatial extent the centers of the voxels that I want to paint into may be outside the viewer plane. What I currently do is flood fill where voxels are filled if any of the center or the corners of the bounding box of the voxel are within the circle (or cylinder, I add some depth to the brush). Initially I thought that would cover everything but there are cases where the brush and the voxel would intersect, but I would not paint into that, e.g. the circle is fully contained in the voxel but not touching the voxel’s center.

I don’t think anything in imglib2-roi at the moment will solve that.

1 Like