java.lang.Object
de.grogra.vecmath.geom.Octree
Abstract base class for octrees.
- Author:
- Michael Tauer, Ole Kniemeyer
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
ACell
represents a cell of anOctree
.static class
An instance ofState
represents the state which is needed for octree algorithms, namely for the methodscomputeIntersections(de.grogra.vecmath.geom.Line, int, de.grogra.vecmath.geom.IntersectionList, de.grogra.vecmath.geom.Intersection, de.grogra.vecmath.geom.Intersection, de.grogra.vecmath.geom.Octree.State)
andOctree.Cell.getVolume(int, de.grogra.vecmath.geom.Octree.State)
. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final int
The maximum depth which can be handled by this octree implementation.static final int
The grid size (number of cells in a single direction) which corresponds to the maximum depth,1 << MAX_DEPTH
. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionboolean
computeIntersections
(Line line, int which, IntersectionList list, Intersection excludeStart, Intersection excludeEnd, Octree.State state) Computes intersections between the boundary surfaces of the volumes of this union and the specifiedline
.abstract Octree.State
This factory methods creates a new instance ofOctree.State
which is suitable as state for this octree.protected void
int
Returns the number of octree cells of this octree.int
getDepth()
Returns the depth of this octree.protected abstract ArrayList
Returns a list of infinite volumes which shall be treated as part of the octree, though they cannot be included in the hierarchy of octree cells.getMax()
Returns the maximum coordinates of the octree box.getMin()
Returns the minimum coordinates of the octree box.getRoot()
Returns the root cell of the octree.protected void
initialize
(int maxDepth, int minObjects, Tuple3d min, Tuple3d max, Octree.Cell root) Initializes the octree.static int
suggestDepth
(int numberOfVolumes) Suggests a maximal octree depth for the givennumberOfVolumes
.
-
Field Details
-
MAX_DEPTH
public static final int MAX_DEPTHThe maximum depth which can be handled by this octree implementation. No subdivision corresponds to a depth of 0, a single subdivision in eight cells to a depth of 1 etc.- See Also:
-
MAX_GRID_SIZE
public static final int MAX_GRID_SIZEThe grid size (number of cells in a single direction) which corresponds to the maximum depth,1 << MAX_DEPTH
.- See Also:
-
-
Constructor Details
-
Octree
public Octree()
-
-
Method Details
-
initialize
Initializes the octree. Theroot
cell has to contain all finite volumes, it will be subdivided by this method.- Parameters:
maxDepth
- maximum allowed depth of octreeminObjects
- minimum volumes per cell. Only cells having more thenminObjects
volumes are checked for subdivisionmin
- minimum coordinates of octree boxmax
- maximum coordinates of octree boxroot
- root cell of the octree
-
finishCells
protected void finishCells() -
getMin
Returns the minimum coordinates of the octree box. All finite objects are contained in this box. The returned value must not be modified.- Returns:
- minimum coordinates of octree box
-
getMax
Returns the maximum coordinates of the octree box. All finite objects are contained in this box. The returned value must not be modified.- Returns:
- maximum coordinates of octree box
-
getDepth
public int getDepth()Returns the depth of this octree. A depth of 0 indicates that only the root cell is present etc.- Returns:
- depth of octree
-
getCellCount
public int getCellCount()Returns the number of octree cells of this octree.- Returns:
- number of cells
-
getRoot
Returns the root cell of the octree. The cell hierarchy contains all finite volumes.- Returns:
- root cell of octree
-
createState
This factory methods creates a new instance ofOctree.State
which is suitable as state for this octree. State information is needed in the methodscomputeIntersections(de.grogra.vecmath.geom.Line, int, de.grogra.vecmath.geom.IntersectionList, de.grogra.vecmath.geom.Intersection, de.grogra.vecmath.geom.Intersection, de.grogra.vecmath.geom.Octree.State)
andOctree.Cell.getVolume(int, de.grogra.vecmath.geom.Octree.State)
.- Returns:
- new instance of suitable
State
subclass
-
getInfiniteVolumes
Returns a list of infinite volumes which shall be treated as part of the octree, though they cannot be included in the hierarchy of octree cells.- Returns:
- list of infinite volumes, or
null
-
computeIntersections
public boolean computeIntersections(Line line, int which, IntersectionList list, Intersection excludeStart, Intersection excludeEnd, Octree.State state) Computes intersections between the boundary surfaces of the volumes of this union and the specifiedline
. For the parameters, seeVolume.computeIntersections(de.grogra.vecmath.geom.Line, int, de.grogra.vecmath.geom.IntersectionList, de.grogra.vecmath.geom.Intersection, de.grogra.vecmath.geom.Intersection)
. The additional parameterstate
has to be preallocated by invocation ofcreateState()
and may be used for multiple invocations of this method. This is preferable to the ordinarycomputeIntersections
-method of the interfaceVolume
for performance reasons.- Parameters:
line
- a linewhich
- one ofIntersection.ALL
,Intersection.CLOSEST
,Intersection.ANY
, this determines which intersections have to be added tolist
list
- the intersections are added to this listexcludeStart
- intersection at start point which shall be excluded, ornull
excludeEnd
- intersection at end point which shall be excluded, ornull
state
- instance ofState
as returned bycreateState()
- Returns:
true
iff the beginning of the line lies within the volume
-
suggestDepth
public static int suggestDepth(int numberOfVolumes) Suggests a maximal octree depth for the givennumberOfVolumes
. The computed value minimizes the heuristic cost functionc(d) = N / 4d + r 2d where N isnumberOfVolumes
and r the relative cost of passing an octree cell compared to intersecting a volume. The first part of this function estimates the number of ray/volume intersections for a single ray, the second part estimates the number of passed octree cells.Based on experimental data, r = 0.1 has been chosen.
- Parameters:
numberOfVolumes
- number of volumes in the scene- Returns:
- suggested value for maximal octree depth
-