Package gaiasky.util.tree
Class OctreeNode
- java.lang.Object
-
- gaiasky.util.tree.OctreeNode
-
- All Implemented Interfaces:
ILineRenderable
,IRenderable
public class OctreeNode extends java.lang.Object implements ILineRenderable
Octree node implementation which contains a list ofIPosition
objects and possibly 8 subnodes.
-
-
Field Summary
Fields Modifier and Type Field Description Vector3d
blf
Contains the bottom-left-front position of the octantBoundingBoxd
box
The bounding boxVector3d
centre
The centre of this octantOctreeNode[]
children
Children nodesint
childrenCount
Number of children nodes of this nodeint
depth
Contains the depth leveldouble
distToCamera
The distance to the camera in units of the center of this octantstatic boolean
LOAD_ACTIVE
Is dynamic loading active?static int
maxDepth
Max depth of the structure this node belongs toint
nObjects
Number of objects contained in this node and its descendantsstatic int
nObjectsObserved
static int
nOctantsObserved
java.util.List<AbstractPositionEntity>
objects
List of objectsboolean
observed
Is this octant observed in this frame?float
opacity
The opacity of this nodeint
ownObjects
Number of objects contained in this nodelong
pageId
The unique page identifierOctreeNode
parent
The parent, if anyVector3d
size
Octant size in x, y and zVector3d
trb
Contains the top-right-back position of the octantdouble
viewAngle
If observed, the view angle in radians of this octant
-
Constructor Summary
Constructors Constructor Description OctreeNode(double x, double y, double z, double hsx, double hsy, double hsz, int depth)
Constructs an octree nodeOctreeNode(double x, double y, double z, double hsx, double hsy, double hsz, int childrenCount, int nObjects, int ownObjects, int depth)
Constructs an octree node.OctreeNode(double x, double y, double z, double hsx, double hsy, double hsz, int depth, OctreeNode parent, int i)
Constructs an octree nodeOctreeNode(long pageId, double x, double y, double z, double hsx, double hsy, double hsz, int depth)
Constructs an octree nodeOctreeNode(long pageid, double x, double y, double z, double hsx, double hsy, double hsz, int childrenCount, int nObjects, int ownObjects, int depth)
Constructs an octree node.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
add(AbstractPositionEntity e)
boolean
addAll(java.util.List<AbstractPositionEntity> l)
void
addChildrenToList(java.util.ArrayList<OctreeNode> tree)
Adds all the children of this node and its descendants to the given list.void
addParticlesTo(com.badlogic.gdx.utils.Array<AbstractPositionEntity> particles)
Adds all the particles of this node and its descendants to the given list.long
computePageId()
protected void
computePageIdRec(int[] hashv)
boolean
containsObject(AbstractPositionEntity object)
int
countObjects()
void
dispose()
Disposes this octree node (and all children nodes recursively)OctreeNode
findOctant(long id)
OctreeNode
getBestOctant(Vector3d position)
Returns the deepest octant that contains the positionComponentTypes
getComponentType()
Gets the component types of this entitydouble
getDistToCamera()
Gets the last distance to the camera calculated for this entityint
getGlPrimitive()
float
getLineWidth()
int
getMaxDepth()
Gets the depth of this subtree, that is, the number of levels of the longest parent-child path starting at this node.float
getOpacity()
Returns the opacity of this renderableprotected int
getParentIndex()
Gets the index of this node in the parent's listOctreeNode
getRoot()
Gets the root of the tree this octant is in by successively checking the parent until it is null.LoadStatus
getStatus()
static long
hash(double value)
Returns an integer hash code representing the given double value.static long
hash(double x, double y, double z)
boolean
insert(AbstractPositionEntity e, int level)
boolean
isObserved()
int
numNodes()
Counts the number of nodes recursivelyvoid
remove()
Removes this octant from the octreevoid
removeChild(OctreeNode child)
Removes the child from this octant's descendantsvoid
render(LineRenderSystem sr, ICamera camera, float alpha)
void
resolveChildren(java.util.Map<java.lang.Long,Pair<OctreeNode,long[]>> map)
Resolves and adds the children of this node using the map.void
setObjects(java.util.List<AbstractPositionEntity> l)
void
setStatus(LoadStatus status)
void
setStatus(LoadStatus status, int depth)
Sets the status to this node and its descendants recursively to the given depth level.int[][]
stats()
Gets some per-level stats on the octree nodejava.lang.String
toString()
java.lang.String
toString(boolean rec)
void
toTree(java.util.TreeSet<AbstractPositionEntity> tree)
void
update(Vector3d parentTransform, ICamera cam, java.util.List<SceneGraphNode> roulette, float opacity)
Computes the observed value and the transform of each observed node.void
updateNumbers()
Updates the number of objects, own objects and children.
-
-
-
Field Detail
-
nOctantsObserved
public static int nOctantsObserved
-
nObjectsObserved
public static int nObjectsObserved
-
maxDepth
public static int maxDepth
Max depth of the structure this node belongs to
-
LOAD_ACTIVE
public static boolean LOAD_ACTIVE
Is dynamic loading active?
-
pageId
public long pageId
The unique page identifier
-
blf
public final Vector3d blf
Contains the bottom-left-front position of the octant
-
trb
public final Vector3d trb
Contains the top-right-back position of the octant
-
centre
public final Vector3d centre
The centre of this octant
-
box
public final BoundingBoxd box
The bounding box
-
size
public final Vector3d size
Octant size in x, y and z
-
depth
public final int depth
Contains the depth level
-
nObjects
public int nObjects
Number of objects contained in this node and its descendants
-
ownObjects
public int ownObjects
Number of objects contained in this node
-
childrenCount
public int childrenCount
Number of children nodes of this node
-
parent
public OctreeNode parent
The parent, if any
-
children
public OctreeNode[] children
Children nodes
-
objects
public java.util.List<AbstractPositionEntity> objects
List of objects
-
viewAngle
public double viewAngle
If observed, the view angle in radians of this octant
-
distToCamera
public double distToCamera
The distance to the camera in units of the center of this octant
-
observed
public boolean observed
Is this octant observed in this frame?
-
opacity
public float opacity
The opacity of this node
-
-
Constructor Detail
-
OctreeNode
public OctreeNode(double x, double y, double z, double hsx, double hsy, double hsz, int depth)
Constructs an octree node- Parameters:
x
-y
-z
-hsx
-hsy
-hsz
-depth
-
-
OctreeNode
public OctreeNode(long pageId, double x, double y, double z, double hsx, double hsy, double hsz, int depth)
Constructs an octree node- Parameters:
pageId
-x
-y
-z
-hsx
-hsy
-hsz
-depth
-
-
OctreeNode
public OctreeNode(double x, double y, double z, double hsx, double hsy, double hsz, int depth, OctreeNode parent, int i)
Constructs an octree node- Parameters:
x
-y
-z
-hsx
-hsy
-hsz
-depth
-parent
- The parent of this octanti
- The index in the parent's children
-
OctreeNode
public OctreeNode(double x, double y, double z, double hsx, double hsy, double hsz, int childrenCount, int nObjects, int ownObjects, int depth)
Constructs an octree node.- Parameters:
x
- The x coordinate of the center.y
- The y coordinate of the center.z
- The z coordinate of the center.hsx
- The half-size in x.hsy
- The half-size in y.hsz
- The half-size in z.childrenCount
- Number of children nodes. Same as non null positions in children vector.nObjects
- Number of objects contained in this node and its descendants.ownObjects
- Number of objects contained in this node. Same as objects.size().
-
OctreeNode
public OctreeNode(long pageid, double x, double y, double z, double hsx, double hsy, double hsz, int childrenCount, int nObjects, int ownObjects, int depth)
Constructs an octree node.- Parameters:
pageid
- The octant idx
- The x coordinate of the center.y
- The y coordinate of the center.z
- The z coordinate of the center.hsx
- The half-size in x.hsy
- The half-size in y.hsz
- The half-size in z.childrenCount
- Number of children nodes. Same as non null positions in children vector.nObjects
- Number of objects contained in this node and its descendants.ownObjects
- Number of objects contained in this node. Same as objects.size().
-
-
Method Detail
-
computePageId
public long computePageId()
-
computePageIdRec
protected void computePageIdRec(int[] hashv)
-
getParentIndex
protected int getParentIndex()
Gets the index of this node in the parent's list
-
containsObject
public boolean containsObject(AbstractPositionEntity object)
-
resolveChildren
public void resolveChildren(java.util.Map<java.lang.Long,Pair<OctreeNode,long[]>> map)
Resolves and adds the children of this node using the map. It runs recursively once the children have been added.- Parameters:
map
-
-
getOpacity
public float getOpacity()
Description copied from interface:IRenderable
Returns the opacity of this renderable- Specified by:
getOpacity
in interfaceIRenderable
- Returns:
- The opacity
-
add
public boolean add(AbstractPositionEntity e)
-
addAll
public boolean addAll(java.util.List<AbstractPositionEntity> l)
-
setObjects
public void setObjects(java.util.List<AbstractPositionEntity> l)
-
insert
public boolean insert(AbstractPositionEntity e, int level)
-
toTree
public void toTree(java.util.TreeSet<AbstractPositionEntity> tree)
-
addChildrenToList
public void addChildrenToList(java.util.ArrayList<OctreeNode> tree)
Adds all the children of this node and its descendants to the given list.- Parameters:
tree
-
-
addParticlesTo
public void addParticlesTo(com.badlogic.gdx.utils.Array<AbstractPositionEntity> particles)
Adds all the particles of this node and its descendants to the given list.- Parameters:
particles
-
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
toString
public java.lang.String toString(boolean rec)
-
stats
public int[][] stats()
Gets some per-level stats on the octree node- Returns:
- A [DEPTH,2] matrix with number of octants [i,0] and objects [i,1] per level
-
remove
public void remove()
Removes this octant from the octree
-
removeChild
public void removeChild(OctreeNode child)
Removes the child from this octant's descendants- Parameters:
child
-
-
numNodes
public int numNodes()
Counts the number of nodes recursively- Returns:
- The number of nodes
-
getComponentType
public ComponentTypes getComponentType()
Description copied from interface:IRenderable
Gets the component types of this entity- Specified by:
getComponentType
in interfaceIRenderable
- Returns:
- The component types
-
getDistToCamera
public double getDistToCamera()
Description copied from interface:IRenderable
Gets the last distance to the camera calculated for this entity- Specified by:
getDistToCamera
in interfaceIRenderable
- Returns:
- The distance
-
getBestOctant
public OctreeNode getBestOctant(Vector3d position)
Returns the deepest octant that contains the position- Parameters:
position
- The position- Returns:
- The best octant
-
getMaxDepth
public int getMaxDepth()
Gets the depth of this subtree, that is, the number of levels of the longest parent-child path starting at this node. If run on the root node, this gives the maximum octree depth.- Returns:
- The maximum depth of this node.
-
update
public void update(Vector3d parentTransform, ICamera cam, java.util.List<SceneGraphNode> roulette, float opacity)
Computes the observed value and the transform of each observed node.- Parameters:
parentTransform
- The parent transform.cam
- The current camera.roulette
- List where the nodes to be processed are to be added.opacity
- The opacity to set.
-
isObserved
public boolean isObserved()
-
getStatus
public LoadStatus getStatus()
-
setStatus
public void setStatus(LoadStatus status)
-
setStatus
public void setStatus(LoadStatus status, int depth)
Sets the status to this node and its descendants recursively to the given depth level.- Parameters:
status
- The new status.depth
- The depth.
-
updateNumbers
public void updateNumbers()
Updates the number of objects, own objects and children. This operation runs recursively in depth.
-
countObjects
public int countObjects()
-
findOctant
public OctreeNode findOctant(long id)
-
getRoot
public OctreeNode getRoot()
Gets the root of the tree this octant is in by successively checking the parent until it is null.- Returns:
- The root of the tree
-
render
public void render(LineRenderSystem sr, ICamera camera, float alpha)
- Specified by:
render
in interfaceILineRenderable
-
hash
public static long hash(double x, double y, double z)
-
hash
public static long hash(double value)
Returns an integer hash code representing the given double value.- Parameters:
value
- the value to be hashed- Returns:
- the hash code
-
dispose
public void dispose()
Disposes this octree node (and all children nodes recursively)
-
getLineWidth
public float getLineWidth()
- Specified by:
getLineWidth
in interfaceILineRenderable
-
getGlPrimitive
public int getGlPrimitive()
- Specified by:
getGlPrimitive
in interfaceILineRenderable
-
-