Package gaiasky.util.tree
Class OctreeNode
java.lang.Object
gaiasky.util.tree.OctreeNode
- All Implemented Interfaces:
ILineRenderable
,IRenderable
-
Field Summary
Modifier and TypeFieldDescriptionfinal Vector3d
The centre of this octant.Children nodes.final int
Contains the depth level.double
The distance to the camera in units of the center of this octant.The object used to load new octants.final Vector3d
Contains the top-right-back position of the octant.static int
Max depth of the structure this node belongs to.final Vector3d
Contains the bottom-left-front position of the octant.static int
static int
int
Number of direct children nodes of this node.int
Total number of nodes contained in the subtree that has this node at its root.int
Number of objects directly contained in this node.int
Number of objects contained in this node and its descendants.List of objects in this node.boolean
Is this octant observed in this frame?float
The opacity of this node.long
The unique page identifier.The parent, if any.final Vector3d
Octant size in x, y and z.double
If observed, the view angle in radians of this octant. -
Constructor Summary
ConstructorDescriptionOctreeNode
(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 node.OctreeNode
(long pageId, double x, double y, double z, double hsx, double hsy, double hsz, int depth) Constructs an octree node.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. -
Method Summary
Modifier and TypeMethodDescriptionboolean
add
(IOctreeObject e) boolean
addAll
(List<IOctreeObject> l) void
addChildrenToList
(ArrayList<OctreeNode> list) Adds all the children of this node and its descendants to the given list.void
addParticlesTo
(com.badlogic.gdx.utils.Array<IOctreeObject> particles) Adds all the particles of this node and its descendants to the given list.long
protected void
boolean
contains
(double x, double y, double z) boolean
boolean
containsObject
(IOctreeObject object) int
void
dispose()
Disposes this octree node (and all children nodes recursively)findOctant
(long id) getBestOctant
(Vector3d position) Returns the deepest octant that contains the position.Gets the component types of this entitydouble
Gets the last distance to the camera calculated for this entityint
float
int
Gets the depth of this subtree, that is, the number of levels of the longest parent-child path starting at this node.float
Returns the opacity of this renderableprotected int
Gets the index of this node in the parent's list.getRoot()
Gets the root of the tree this octant is in by successively checking the parent until it is null.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
(IOctreeObject e, int level) boolean
int
Counts the number of direct children of this node.int
Counts the number of nodes recursively.void
remove()
Removes this octant from the octree.void
removeChild
(OctreeNode child) Removes the child from this octant's descendants.void
render
(LineRenderSystem sr, ICamera camera, float alpha) void
resolveChildren
(Map<Long, Pair<OctreeNode, long[]>> map) Resolves and adds the children of this node using the map.void
void
setOctantLoader
(IOctantLoader loader) Sets the octree loader to this node.void
setOctantLoader
(IOctantLoader loader, boolean recursive) Sets the octant loader to this node.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 node.toString()
toString
(boolean rec) void
toTree
(TreeSet<IOctreeObject> tree) void
update
(Vector3b parentTransform, ICamera cam, List<IOctreeObject> roulette, float opacity, boolean updateNumLabels) Computes the observed value and the transform of each observed node.void
Updates the number of objects, own objects and children.void
updateCountsWithNumber
(int n) Called when this octant has just been loaded or unloaded.
-
Field Details
-
nOctantsObserved
public static int nOctantsObserved -
nObjectsObserved
public static int nObjectsObserved -
maxDepth
public static int maxDepthMax depth of the structure this node belongs to. -
min
Contains the bottom-left-front position of the octant. -
max
Contains the top-right-back position of the octant. -
centre
The centre of this octant. -
size
Octant size in x, y and z. -
depth
public final int depthContains the depth level. -
pageId
public long pageIdThe unique page identifier. -
numObjectsRec
public int numObjectsRecNumber of objects contained in this node and its descendants. -
numObjects
public int numObjectsNumber of objects directly contained in this node. -
numChildrenRec
public int numChildrenRecTotal number of nodes contained in the subtree that has this node at its root. -
numChildren
public int numChildrenNumber of direct children nodes of this node. -
parent
The parent, if any. -
children
Children nodes. -
objects
List of objects in this node. -
loader
The object used to load new octants. -
viewAngle
public double viewAngleIf observed, the view angle in radians of this octant. -
distToCamera
public double distToCameraThe distance to the camera in units of the center of this octant. -
observed
public boolean observedIs this octant observed in this frame? -
opacity
public float opacityThe opacity of this node.
-
-
Constructor Details
-
OctreeNode
public OctreeNode(long pageId, double x, double y, double z, double hsx, double hsy, double hsz, int depth) Constructs an octree node. -
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. -
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 id.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().
-
-
Method Details
-
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
-
computePageId
public long computePageId() -
computePageIdRec
-
getParentIndex
protected int getParentIndex()Gets the index of this node in the parent's list. -
containsObject
-
resolveChildren
Resolves and adds the children of this node using the map. It runs recursively once the children have been added.- Parameters:
map
- The children 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
-
addAll
-
setObjects
-
insert
-
toTree
-
addChildrenToList
Adds all the children of this node and its descendants to the given list.- Parameters:
list
- The tree of nodes.
-
addParticlesTo
Adds all the particles of this node and its descendants to the given list.- Parameters:
particles
- The list of particles.
-
toString
-
toString
-
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
Removes the child from this octant's descendants.- Parameters:
child
- The child node to remove.
-
numChildren
public int numChildren()Counts the number of direct children of this node.- Returns:
- The number of direct children.
-
numNodesRec
public int numNodesRec()Counts the number of nodes recursively.- Returns:
- The number of nodes.
-
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
-
contains
public boolean contains(double x, double y, double z) -
contains
-
getBestOctant
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(Vector3b parentTransform, ICamera cam, List<IOctreeObject> roulette, float opacity, boolean updateNumLabels) 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.updateNumLabels
- Whether to perform the performance optimization to update the number of labels in each star group according to the current view angle.
-
isObserved
public boolean isObserved() -
getStatus
-
setStatus
-
setStatus
Sets the status to this node and its descendants recursively to the given depth level.- Parameters:
status
- The new status.depth
- The depth.
-
updateCountsWithNumber
public void updateCountsWithNumber(int n) Called when this octant has just been loaded or unloaded. Updates the numbers of this and its ascendants without having to reprocess the whole tree, which is slow for larger trees.- Parameters:
n
- The number of stars loaded or unloaded.
-
updateCounts
public void updateCounts()Updates the number of objects, own objects and children. This operation runs recursively in depth. -
countObjects
public int countObjects() -
findOctant
-
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
- Specified by:
render
in interfaceILineRenderable
-
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
-
setOctantLoader
Sets the octant loader to this node. Optionally, the loader can be set recursively to all children octree nodes of this node.- Parameters:
loader
- The loader to set.recursive
- Whether to set the loader recursively to the children nodes.
-
setOctantLoader
Sets the octree loader to this node. It does not set the loader of children recursively.- Parameters:
loader
- The loader to set.
-