public class IlvIndexedSet extends Object implements Serializable
IlvIndexedSet
is a class dedicated to managing a large number of
graphic objects in a list or a quadtree.Constructor and Description |
---|
IlvIndexedSet()
Creates a new indexed set.
|
IlvIndexedSet(int maxInNode,
int maxInList)
Creates a new indexed set.
|
Modifier and Type | Method and Description |
---|---|
void |
addObject(IlvGraphic obj)
Adds an object.
|
void |
afterUpdate(IlvGraphic obj,
IlvRect bbox)
Updates the location of the object in the quadtree.
|
void |
beforeUpdate(IlvGraphic obj,
IlvRect bbox)
Prepares the update of the
IlvIndexedSet . |
void |
collectObjects(IlvPoint p,
IlvPoint tp,
IlvTransformer t,
IlvGraphicVector result)
Collects all visible objects at a specified location.
|
void |
collectSelectableObjects(IlvPoint p,
IlvPoint tp,
IlvTransformer t,
IlvGraphicVector result)
Collects all visible and selectable objects at a specified location.
|
IlvRect |
computeBBox(IlvTransformer t)
Returns the bounding rectangle of the set when
drawn with the specified transformer.
|
void |
deleteAll()
Removes all the objects.
|
int |
getCardinal()
Returns the number of objects.
|
IlvGraphicEnumeration |
getElements()
Returns an enumeration of all the objects.
|
int |
getIndex(IlvGraphic obj)
Returns the index of the specified object in the
IlvIndexedSet . |
IlvGraphicEnumeration |
getManagers()
Returns an enumeration of all the instances of
IlvManager
that have been added in this IlvIndexedSet . |
int |
getManagersCount()
Returns the number of
IlvManager objects that have been
added in this IlvIndexedSet . |
IlvGraphic |
getObject(IlvPoint p,
IlvPoint tp,
IlvTransformer t)
Looks for a visible object at a specified location.
|
IlvGraphic |
getObject(int index)
Returns the object at the input index.
|
IlvGraphic |
getSelectableObject(IlvPoint p,
IlvPoint tp,
IlvTransformer t)
Looks for a visible and selectable object at a specified location.
|
long |
getSubsequentRemoveThreshold()
Returns the threshold for optimized remove operations.
|
boolean |
isQuadtreeEnabled()
Returns
true if the quadtree is enabled. |
boolean |
isZOrdering()
Returns whether Z-ordering is enabled.
|
void |
map(IlvApplyObject f,
Object arg)
Applies a function to all the objects in the set.
|
void |
mapInside(IlvRect rect,
IlvRect trect,
IlvApplyObject f,
Object arg,
IlvTransformer t)
Applies a function to all objects located in a specified rectangle.
|
void |
mapInside(IlvRect rect,
IlvRect trect,
IlvApplyObject f,
Object arg,
IlvTransformer t,
boolean traverse)
Applies a function to all objects located in a specified rectangle.
|
void |
mapIntersects(IlvRect rect,
IlvRect trect,
IlvApplyObject f,
Object arg,
IlvTransformer t)
Applies a function to all objects with a bounding box that intersects a
specified rectangle.
|
void |
mapIntersects(IlvRect rect,
IlvRect trect,
IlvApplyObject f,
Object arg,
IlvTransformer t,
boolean traverse)
Applies a function to all objects with a bounding box that intersects a
specified rectangle.
|
void |
removeObject(IlvGraphic obj)
Removes an object.
|
void |
setIndex(IlvGraphic obj,
int index)
Changes the index of the specified object in the
IlvIndexedSet . |
static void |
SetInitialNumberOfNonZoomablesCapacity(int length)
Sets the initial capacity of the internal vector of the indexed set
that stores the nonzoomable objects.
|
static void |
SetInitialNumberOfObjectsCapacity(int length)
Sets the initial capacity of the internal vector of the indexed set
that stores all (zoomable and nonzoomable) objects.
|
void |
setQuadtreeEnabled(boolean enable)
Enables or disables the quadtree.
|
void |
setSubsequentRemoveThreshold(long threshold)
Sets the threshold when to use optimized remove operations.
|
void |
setZOrdering(boolean enable)
Sets whether Z-ordering is enabled.
|
public IlvIndexedSet()
public IlvIndexedSet(int maxInNode, int maxInList)
maxInNode
- The maximum number of objects for a node of the quadtree.maxInList
- The maximum number of objects before using the quadtree.public void setQuadtreeEnabled(boolean enable)
Compared to a list, the quadtree is a spatial data structure that speeds
up the search of graphic objects at a given location
(for instance getObject
, mapInside
,
mapIntersects
) but requires a (usually negligible) slowdown
of operations that modify the location of any objects (see
afterUpdate
).
enable
- If true
, the quadtree gets enabled; otherwise
it gets disabled.isQuadtreeEnabled()
,
getObject(ilog.views.IlvPoint, ilog.views.IlvPoint, ilog.views.IlvTransformer)
,
mapInside(ilog.views.IlvRect, ilog.views.IlvRect, ilog.views.IlvApplyObject, java.lang.Object, ilog.views.IlvTransformer)
,
mapIntersects(ilog.views.IlvRect, ilog.views.IlvRect, ilog.views.IlvApplyObject, java.lang.Object, ilog.views.IlvTransformer)
,
afterUpdate(ilog.views.IlvGraphic, ilog.views.IlvRect)
,
IlvQuadtree
public boolean isQuadtreeEnabled()
true
if the quadtree is enabled.setQuadtreeEnabled(boolean)
,
IlvQuadtree
public void setZOrdering(boolean enable)
If Z-ordering is disabled, the quadtree is free to choose any drawing order.
This is in general the fastest option, since the quadtree is able to optimize
the drawing performance by fine-tuned drawing orders. However, in this case,
you cannot influence the drawing order through the method setIndex(ilog.views.IlvGraphic, int)
.
If Z-ordering is enabled, the drawing order is given by the indices of the
objects (see getIndex(ilog.views.IlvGraphic)
) and can be influenced through the
method setIndex(ilog.views.IlvGraphic, int)
. This works when the quadtree is enabled as well as
when the quadtree is disabled.
The drawing order with disabled quadtree is anyway not chosen by the
quadtree.
In terms of performance, using the quadtree without Z-ordering is the fastest option, using the quadtree with Z-ordering is slightly slower, and using no quadtree at all is the slowest option. The speed depends on various factors:
getObject(IlvPoint, IlvPoint, IlvTransformer)
are several magnitudes faster, even if Z-ordering is enabled. isZOrdering()
,
setQuadtreeEnabled(boolean)
,
setIndex(ilog.views.IlvGraphic, int)
public boolean isZOrdering()
setZOrdering(boolean)
public static void SetInitialNumberOfObjectsCapacity(int length)
addObject(ilog.views.IlvGraphic)
operation.
You can change this value before allocating any indexed set.
Once an indexed set is allocated and already filled, changing this
value has no effect on that indexed set.public static void SetInitialNumberOfNonZoomablesCapacity(int length)
addObject(ilog.views.IlvGraphic)
operation.
You can change this value before allocating any indexed set.
Once an indexed set is allocated and already filled with nonzoomable
objects, changing this value has no effect on that indexed set.public void setSubsequentRemoveThreshold(long threshold)
You can set the threshold to Long.MAX_VALUE
to
disable the optimized mechanism, so that errors of the remove operation
are detected immediately. This is in general better if you want to
debug operations related to IlvIndexedSet
.
The default value is 3.
removeObject(ilog.views.IlvGraphic)
,
getSubsequentRemoveThreshold()
public long getSubsequentRemoveThreshold()
setSubsequentRemoveThreshold(long)
public void addObject(IlvGraphic obj)
obj
- The graphic object to be added.public void removeObject(IlvGraphic obj)
obj
- The graphic object to be removed.public int getCardinal()
public void deleteAll()
public IlvGraphic getObject(IlvPoint p, IlvPoint tp, IlvTransformer t)
p
- The point at which the search will be started.tp
- The point p
transformed.t
- The transformer through which the set is drawn.p
if there is one.
Otherwise it returns null
.setQuadtreeEnabled(boolean)
public IlvGraphic getSelectableObject(IlvPoint p, IlvPoint tp, IlvTransformer t)
p
- The point at which the search will be started.tp
- The point p
transformed.t
- The transformer through which the set is drawn.p
if there is one.
Otherwise it returns null
.setQuadtreeEnabled(boolean)
public void collectObjects(IlvPoint p, IlvPoint tp, IlvTransformer t, IlvGraphicVector result)
p
- The point at which the search will be started.tp
- The point p
transformed.t
- The transformer through which the set is drawn.result
- The resulting objects.setQuadtreeEnabled(boolean)
public void collectSelectableObjects(IlvPoint p, IlvPoint tp, IlvTransformer t, IlvGraphicVector result)
p
- The point at which the search will be started.tp
- The point p
transformed.t
- The transformer through which the set is drawn.result
- The resulting objects.setQuadtreeEnabled(boolean)
public void beforeUpdate(IlvGraphic obj, IlvRect bbox)
IlvIndexedSet
. This method is
called before a change of the bounding box of a graphic object.
You should not call this method directly.
obj
- The graphic object.bbox
- The old bounding box of the graphic object in manager
coordinates.
It can be null
, in which case it will be computed.afterUpdate(ilog.views.IlvGraphic, ilog.views.IlvRect)
public void afterUpdate(IlvGraphic obj, IlvRect bbox)
You should not call this method directly.
obj
- The graphic object.bbox
- The new bounding box of the graphic object in manager
coordinates.
It can be null
, in which case it will be computed.beforeUpdate(ilog.views.IlvGraphic, ilog.views.IlvRect)
,
setQuadtreeEnabled(boolean)
public IlvGraphicEnumeration getElements()
Note that it is not allowed to remove or add graphic objects while
browsing the enumeration returned by this method.
Wrap the returned enumeration into IlvBufferedGraphicEnumeration
if it is necessary to add or remove objects while using the enumeration.
public void setIndex(IlvGraphic obj, int index)
IlvIndexedSet
.
If the specified graphic object is not in this IlvIndexedSet
,
the method does nothing and does not issue any exception.
Elements between the current index of the object and the desired index are
shifted by one position, that is, their index changes.
Note that changing the index of an object in the IlvIndexedSet
will only change the drawing order of the object if the Z-ordering option
is enabled or if the quadtree is turned off.
If the quadtree is enabled and the Z-ordering option is turned off, the
quadtree is free to choose any faster drawing order regardless the indices
of the objects of this indexed set.setQuadtreeEnabled(boolean)
,
setZOrdering(boolean)
,
getIndex(ilog.views.IlvGraphic)
public int getIndex(IlvGraphic obj)
IlvIndexedSet
.
If the specified graphic object is not in this IlvIndexedSet
,
the method returns -1
.
Note that the index of an object in the IlvIndexedSet
defines the drawing order of the object only if the Z-ordering option
is enabled or if the quadtree is turned off.
If the quadtree is enabled and the Z-ordering option is turned off, there
is no way to influence the drawing order within the indexed set.
If the quadtree is enabled and the Z-ordering option is turned off, the
quadtree is free to choose any faster drawing order regardless the indices
of the objects of this indexed set.setQuadtreeEnabled(boolean)
,
setZOrdering(boolean)
,
setIndex(ilog.views.IlvGraphic, int)
public IlvGraphic getObject(int index)
IlvIndexedSet
.
Note that the index of an object in the IlvIndexedSet
defines the drawing order of the object only if the Z-ordering option
is enabled or if the quadtree is turned off.
If the quadtree is enabled and the Z-ordering option is turned off, the
quadtree is free to choose any faster drawing order regardless the indices
of the objects of this indexed set.setQuadtreeEnabled(boolean)
,
setZOrdering(boolean)
,
getCardinal()
,
setIndex(ilog.views.IlvGraphic, int)
public IlvGraphicEnumeration getManagers()
IlvManager
that have been added in this IlvIndexedSet
.
Note that it is not allowed to remove or add managers while
browsing the enumeration returned by this method.
Wrap the returned enumeration into IlvBufferedGraphicEnumeration
if it is necessary to add or remove managers while using the enumeration.public int getManagersCount()
IlvManager
objects that have been
added in this IlvIndexedSet
.public void map(IlvApplyObject f, Object arg)
f
- The function to be applied.arg
- The argument of the function.public void mapInside(IlvRect rect, IlvRect trect, IlvApplyObject f, Object arg, IlvTransformer t)
f
to all graphic
objects inside the rectangle rect
.rect
- The rectangle.trect
- The transformed rectangle.f
- The method to be applied.arg
- The argument passed to the method.t
- The transformer used to display the set.setQuadtreeEnabled(boolean)
public void mapInside(IlvRect rect, IlvRect trect, IlvApplyObject f, Object arg, IlvTransformer t, boolean traverse)
f
to all graphic
objects inside the rectangle rect
.
This method will traverse recursively
the IlvManager
objects added in this set to apply the function
to all objects that are inside the specified rectangle if the
parameter traverse
is set to true
.rect
- The rectangle.trect
- The transformed rectangle.f
- The method to be applied.arg
- The argument passed to the method.t
- The transformer used to display the set.traverse
- When true
, the method will traverse
recursively the IlvManager
objects added in this set to apply
the function to all objects that are inside the specified rectangle.setQuadtreeEnabled(boolean)
public void mapIntersects(IlvRect rect, IlvRect trect, IlvApplyObject f, Object arg, IlvTransformer t)
rect
- The rectangle.trect
- The transformed rectangle.f
- The method to be applied.arg
- The argument passed to the method.t
- The transformer used to display the set.setQuadtreeEnabled(boolean)
public void mapIntersects(IlvRect rect, IlvRect trect, IlvApplyObject f, Object arg, IlvTransformer t, boolean traverse)
IlvManager
objects added in this set to apply the function
to all objects that intersect the rectangle if the parameter
traverse
is set to true
.rect
- The rectangle.trect
- The transformed rectangle.f
- The method to be applied.arg
- The argument passed to the method.t
- The transformer used to display the set.traverse
- If true
, then the method will traverse
recursively the IlvManager
objects added in this set to apply
the function to all objects that intersect the rectangle.setQuadtreeEnabled(boolean)
public IlvRect computeBBox(IlvTransformer t)
t
- The transformer.© Copyright Rogue Wave Software, Inc. 1997, 2018. All Rights Reserved.