Class BoundingBox

java.lang.Object
sc.fiji.snt.util.BoundingBox
All Implemented Interfaces:
Cloneable

public class BoundingBox extends Object implements Cloneable
A BoundingBox contains information (including spatial calibration) of a tracing canvas bounding box, i.e., the minimum bounding cuboid containing all nodes (SNTPoints) of a reconstructed structure.
Author:
Tiago Ferreira
  • Field Details

    • xSpacing

      public double xSpacing
      The 'voxel width' of the bounding box
    • ySpacing

      public double ySpacing
      The 'voxel height' of the bounding box
    • zSpacing

      public double zSpacing
      The 'voxel depth' of the bounding box
    • info

      public String info
      Used to store information about this bounding box. Default is null
    • spacingUnit

      protected String spacingUnit
    • origin

      protected PointInImage origin
      The bounding box origin (SE, lower corner)
    • originOpposite

      protected PointInImage originOpposite
      The origin opposite (NW, upper corner)
  • Constructor Details

    • BoundingBox

      public BoundingBox()
      Constructs an 'empty' BoundingBox using default values, with the box origin defined as a point with Double.NaN coordinates and Double.NaN dimensions
    • BoundingBox

      public BoundingBox(Collection<? extends SNTPoint> points)
      Computes a bounding box from a point cloud.
      Parameters:
      points - the point cloud
  • Method Details

    • reset

      protected void reset()
    • setSpacing

      public void setSpacing(double xSpacing, double ySpacing, double zSpacing, String spacingUnit)
      Sets the voxel spacing.
      Parameters:
      xSpacing - the 'voxel width' of the bounding box
      ySpacing - the 'voxel height' of the bounding box
      zSpacing - the 'voxel depth' of the bounding box
      spacingUnit - the length unit
    • compute

      public void compute(Iterator<? extends SNTPoint> iterator)
      Computes a new positioning so that this box encloses the specified point cloud.
      Parameters:
      iterator - the iterator of the points Collection
    • append

      public void append(Iterator<? extends SNTPoint> iterator)
      Computes the bounding box of the specified point cloud and appends it to this bounding box, resizing it as needed.
      Parameters:
      iterator - the iterator of the points Collection
    • getCentroid

      public SNTPoint getCentroid()
    • inferSpacing

      public void inferSpacing(Collection<SWCPoint> points)
      Infers the voxel spacing of this box from the inter-node distances of a Collection of SWCPoints.
      Parameters:
      points - the point collection
    • isScaled

      public boolean isScaled()
      Checks whether this BoundingBox is spatially calibrated, i.e., if voxel spacing has been specified
      Returns:
      true, if voxel spacing has been specified
    • setUnit

      public void setUnit(String unit)
      Sets the default length unit for voxel spacing (typically um, for SWC reconstructions)
      Parameters:
      unit - the new unit
    • sanitizedUnit

      public static String sanitizedUnit(String unit)
    • getUnit

      public String getUnit()
      Gets the length unit of voxel spacing
      Returns:
      the unit
    • getCalibration

      public ij.measure.Calibration getCalibration()
      Creates a Calibration object using information from this BoundingBox
      Returns:
      the Calibration object
    • getDimensions

      public double[] getDimensions()
      Gets this BoundingBox dimensions in real world units.
      Returns:
      the BoundingBox dimensions {width, height, depth}.
    • getDimensions

      public double[] getDimensions(boolean scaled)
      Gets this BoundingBox dimensions.
      Parameters:
      scaled - If true, dimensions are retrieved in real world units, otherwise in ("pixel") units
      Returns:
      the BoundingBox dimensions {width, height, depth}.
    • getDiagonal

      public double getDiagonal()
      Gets the box diagonal
      Returns:
      the diagonal of BoundingBox
    • contains

      public boolean contains(BoundingBox boundingBox)
      Checks whether the specified BoundingBox is enclosed by this one .
      Parameters:
      boundingBox - the bounding box to be tested
      Returns:
      true, if successful
    • contains2D

      public boolean contains2D(SNTPoint point)
    • contains

      public boolean contains(SNTPoint point)
    • combine

      public void combine(BoundingBox other)
      Combines this bounding box with another one. It is assumed both boxes share the same voxel spacing/Calibration.
      Parameters:
      other - the bounding box to be combined.
    • intersection

      public BoundingBox intersection(BoundingBox other)
      Retrieves the intersection cuboid between this bounding with another bounding box. It is assumed both boxes share the same voxel spacing/Calibration.
      Parameters:
      other - the second bounding box.
      Returns:
      The intersection cuboid.
    • origin

      public PointInImage origin()
      Retrieves the origin of this box.
      Returns:
      the origin
    • originOpposite

      public PointInImage originOpposite()
      Retrieves the origin opposite of this box.
      Returns:
      the origin
    • unscaledOrigin

      public PointInImage unscaledOrigin()
      Retrieves the origin of this box in unscaled ("pixel" units)
      Returns:
      the unscaled origin
    • unscaledOriginOpposite

      public PointInImage unscaledOriginOpposite()
      Retrieves the origin opposite of this box in unscaled ("pixel" units)
      Returns:
      the unscaled origin opposite
    • width

      public double width()
    • height

      public double height()
    • depth

      public double depth()
    • setDimensions

      public void setDimensions(long uncalibratedWidth, long uncalibratedHeight, long uncalibratedDepth) throws IllegalArgumentException
      Sets the dimensions of this bounding box using uncalibrated (pixel) lengths.
      Parameters:
      uncalibratedWidth - the uncalibrated width
      uncalibratedHeight - the uncalibrated height
      uncalibratedDepth - the uncalibrated depth
      Throws:
      IllegalArgumentException - If origin has not been set or compute(Iterator) has not been called
    • setOrigin

      public void setOrigin(PointInImage origin)
      Sets the origin for this box, i.e., its (xMin, yMin, zMin) vertex.
      Parameters:
      origin - the new origin
    • setOriginOpposite

      public void setOriginOpposite(PointInImage originOpposite)
      Sets the origin opposite for this box, i.e., its (xMax, yMax, zMax) vertex.
      Parameters:
      originOpposite - the new origin opposite.
    • hasDimensions

      public boolean hasDimensions()
    • toBoundingBox3d

      public org.jzy3d.maths.BoundingBox3d toBoundingBox3d()
    • scale

      public BoundingBox scale(double[] scale)
    • shift

      public BoundingBox shift(double[] offset)
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • clone

      public BoundingBox clone()
      Creates a copy of this BoundingBox.
      Overrides:
      clone in class Object
      Returns:
      a new BoundingBox that is a copy of this bounding box
    • toString

      public String toString()
      Overrides:
      toString in class Object