Package toxi.geom
Class PointOctree
java.lang.Object
toxi.geom.Vec3D
toxi.geom.AABB
toxi.geom.PointOctree
- All Implemented Interfaces:
Comparable<ReadonlyVec3D>
,ReadonlyVec3D
,Shape3D
Implements a spatial subdivision tree to work efficiently with large numbers
of 3D particles. This octree can only be used for particle type objects and
does NOT support 3D mesh geometry as other forms of Octrees do.
For further reference also see the OctreeDemo in the /examples folder.
-
Nested Class Summary
Nested classes/interfaces inherited from class toxi.geom.Vec3D
Vec3D.Axis
-
Field Summary
-
Constructor Summary
ConstructorDescriptionPointOctree
(Vec3D o, float size) Constructs a new PointOctree node within the AABB cube volume: {o.x, o.y, o.z} ... -
Method Summary
Modifier and TypeMethodDescriptionboolean
addAll
(Collection<Vec3D> points) Adds all points of the collection to the octree.boolean
Adds a new point/particle to the tree structure.void
applyVisitor
(OctreeVisitor visitor) Applies the givenOctreeVisitor
implementation to this node and all of its children.boolean
Checks if the point is within the given shape/volume.void
empty()
int
getDepth()
Finds the leaf node which spatially relates to the given pointfloat
Returns the minimum size of nodes (in world units).float
int
Selects all stored points within the given axis-aligned bounding box.Selects all stored points within the given sphere volumegetPointsWithinSphere
(Vec3D sphereOrigin, float clipRadius) Selects all stored points within the given sphere volumefloat
getSize()
boolean
Removes a point from the tree and (optionally) tries to release memory by reducing now empty sub-branches.void
removeAll
(Collection<Vec3D> points) void
setMinNodeSize
(float minNodeSize) void
setTreeAutoReduction
(boolean state) Enables/disables auto reduction of branches after points have been deleted from the tree.toString()
Methods inherited from class toxi.geom.AABB
copy, fromMinMax, getBoundingBox, getBoundingSphere, getExtent, getMax, getMin, getNormalForPoint, growToContainPoint, intersectsBox, intersectsRay, intersectsSphere, intersectsSphere, intersectsTriangle, set, set, set, setExtent, toMesh, toMesh, union, updateBounds
Methods inherited from class toxi.geom.Vec3D
abs, add, add, add, addSelf, addSelf, addSelf, angleBetween, angleBetween, clear, compareTo, constrain, constrain, cross, cross, crossInto, crossSelf, distanceTo, distanceToSquared, dot, dot, equals, equals, equalsWithTolerance, floor, frac, fromXYTheta, fromXZTheta, fromYZTheta, getAbs, getCartesian, getClosestAxis, getComponent, getComponent, getConstrained, getFloored, getFrac, getInverted, getLimited, getMapped, getNormalized, getNormalizedTo, getReciprocal, getReflected, getRotatedAroundAxis, getRotatedX, getRotatedY, getRotatedZ, getRoundedTo, getSignum, getSpherical, hashCode, headingXY, headingXZ, headingYZ, immutable, interpolateTo, interpolateTo, interpolateTo, interpolateTo, interpolateToSelf, interpolateToSelf, invert, isInAABB, isInAABB, isMajorAxis, isZeroVector, jitter, jitter, jitter, jitter, jitter, jitter, limit, magnitude, magSquared, max, maxSelf, min, minSelf, modSelf, modSelf, normalize, normalizeTo, randomVector, randomVector, reciprocal, reflect, rotateAroundAxis, rotateX, rotateY, rotateZ, roundTo, scale, scale, scale, scale, scaleSelf, scaleSelf, scaleSelf, scaleSelf, set, setComponent, setComponent, setX, setXY, setY, setZ, shuffle, signum, snapToAxis, sub, sub, sub, subSelf, subSelf, subSelf, to2DXY, to2DXZ, to2DYZ, to4D, to4D, toArray, toArray4, toCartesian, toSpherical, x, y, z
-
Constructor Details
-
PointOctree
Constructs a new PointOctree node within the AABB cube volume: {o.x, o.y, o.z} ... {o.x+size, o.y+size, o.z+size}- Parameters:
o
- tree originsize
- size of the tree volume along a single axis
-
-
Method Details
-
addAll
Adds all points of the collection to the octree. IMPORTANT: Points need be of type Vec3D or have subclassed it.- Parameters:
points
- point collection- Returns:
- true, if all points have been added successfully.
-
addPoint
Adds a new point/particle to the tree structure. All points are stored within leaf nodes only. The tree implementation is using lazy instantiation for all intermediate tree levels.- Parameters:
p
-- Returns:
- true, if point has been added successfully
-
applyVisitor
Applies the givenOctreeVisitor
implementation to this node and all of its children. -
containsPoint
Description copied from interface:Shape3D
Checks if the point is within the given shape/volume.- Specified by:
containsPoint
in interfaceShape3D
- Overrides:
containsPoint
in classAABB
- Returns:
- true, if inside
-
empty
public void empty() -
getChildren
- Returns:
- a copy of the child nodes array
-
getDepth
public int getDepth()- Returns:
- the depth
-
getLeafForPoint
Finds the leaf node which spatially relates to the given point- Parameters:
p
- point to check- Returns:
- leaf node or null if point is outside the tree dimensions
-
getMinNodeSize
public float getMinNodeSize()Returns the minimum size of nodes (in world units). This value acts as tree recursion limit since nodes smaller than this size are not subdivided further. Leaf node are always smaller or equal to this size.- Returns:
- the minimum size of tree nodes
-
getNodeSize
public float getNodeSize() -
getNumChildren
public int getNumChildren()- Returns:
- the number of child nodes (max. 8)
-
getOffset
- Returns:
- the offset
-
getParent
- Returns:
- the parent
-
getPoints
- Returns:
- the points
-
getPointsWithinBox
Selects all stored points within the given axis-aligned bounding box.- Parameters:
b
- AABB- Returns:
- all points with the box volume
-
getPointsWithinSphere
Selects all stored points within the given sphere volume- Parameters:
s
- sphere- Returns:
- selected points
-
getPointsWithinSphere
Selects all stored points within the given sphere volume- Parameters:
sphereOrigin
-clipRadius
-- Returns:
- selected points
-
getSize
public float getSize()- Returns:
- the size
-
remove
Removes a point from the tree and (optionally) tries to release memory by reducing now empty sub-branches.- Parameters:
p
- point to delete- Returns:
- true, if the point was found & removed
-
removeAll
-
setMinNodeSize
public void setMinNodeSize(float minNodeSize) - Parameters:
minNodeSize
-
-
setTreeAutoReduction
public void setTreeAutoReduction(boolean state) Enables/disables auto reduction of branches after points have been deleted from the tree. Turned off by default.- Parameters:
state
- true, to enable feature
-
toString
-