cz.cuni.jagrlib.testing
Class UniformGrid

java.lang.Object
  extended by cz.cuni.jagrlib.DefaultProperty
      extended by cz.cuni.jagrlib.Piece
          extended by cz.cuni.jagrlib.DefaultGeometrySearch
              extended by cz.cuni.jagrlib.testing.UniformGrid
All Implemented Interfaces:
Breakable, GeometrySearch, Property, Template

public class UniformGrid
extends DefaultGeometrySearch

Uniform grid for fast searching.

Since:
0.24
See Also:
UniformGrid.java

Nested Class Summary
protected  class UniformGrid.CenterIterator
          Custom iterator for center pass.
protected static class UniformGrid.GridHeapItem
          Support class for grid-pass.
protected  class UniformGrid.RayIteratorOld
          Custom iterator for ray-segment-pass (old version).
protected  class UniformGrid.RaySegmentIterator2D
          Custom iterator for ray-segment-pass (new version - 2DDDA).
protected  class UniformGrid.RayTriangleIterator3D
          Custom iterator for ray-triangle-pass (3DDDA).
 
Field Summary
protected  int[] accel
          Accelerator array.
protected  boolean alt
          Use alternative implementation?
static java.lang.String ALTERNATIVE
           
protected static java.lang.String CATEGORY
          Object category.
protected static int CELL_GRANUL
          Cell granularity (the rest of each cell is filled by NULL).
protected  int[] cells
          Actual number of cells.
protected  double[] cellSize
          Actual cell size.
protected  int ctx
          Actual context.
protected  int[][] data
          Array of individual cells.
protected  int[] deferred
          Deferred inserted items.
protected  int dim
          Actual dimensionality of the grid.
static java.lang.String DIM
           
protected  int entity
          Actual entity type (VERTEX, EDGE or FACE are supported).
protected  Brep geometry
          Accelarator - reference to Brep instance.
protected static double GRID_EPSILON
          Tolerance for cell-boundary tests.
protected  long heapCounter
          Statistics: heap operations (insert, remove first).
protected  double[] leftBound
          Actual left boundary.
static java.lang.String MAX_GRID_SIZE
           
protected  int maxGrid
          Maximal grid size (in one dimension).
protected  long pointBoxCounter
          Statistics: point to box distance.
protected  long pointPointCounter
          Statistics: point to point distance.
static RegPiece reg
          Static registration instance for this class.
protected  double[] rightBound
          Actual right boundary (relative to the leftBound).
protected static java.lang.String TEMPLATE_NAME
          Object template identifier.
 
Fields inherited from class cz.cuni.jagrlib.Piece
channels, info, pl, plugs, TEMPLATE_TYPE, userBreak
 
Fields inherited from interface cz.cuni.jagrlib.iface.Property
LOGGING, STATISTICS, TEXT_DESCRIPTION
 
Fields inherited from interface cz.cuni.jagrlib.Template
ALL_PLUGS, C_1D, C_2D, C_3D, C_ALPHA, C_BINARY, C_BREP, C_CAMERA, C_CIRCLE, C_CLIP, C_COMPRESSION, C_CURVE, C_DATA, C_DRAW, C_EDITOR, C_ELLIPSE, C_FILL, C_FILTER, C_FLOAT, C_FUNCTION, C_IMAGE, C_INTEGER, C_IO, C_LIGHT, C_LINE, C_METRIC, C_POLYGON, C_PROJECTION, C_RADIOSITY, C_RASTER, C_RENDER, C_SAMPLE, C_SCENE, C_SET, C_SOLID, C_TEXT, C_TRANSFORM, C_VECTOR, C_VIEWER, C_WORKER, CAT_EMPTY, EMPTY, IFACE, JAGRLIB, JAGRLIB2, MANIPULATOR_COMBO, MANIPULATOR_CUSTOM, MANIPULATOR_DEFAULT, MANIPULATOR_MULTILINE, PL_ALPHAMASK, PL_BITMASK, PL_CAUSTIC, PL_CODEC, PL_COLORMAP, PL_COMPARE, PL_DATA, PL_DIRECT, PL_EDITOR, PL_FILTER, PL_FUNCTION, PL_IMAGE, PL_IMPORT, PL_INPUT, PL_INTERSECTION, PL_LIGHTSOURCE, PL_ORDER, PL_OUTPUT, PL_PALETTE, PL_PHOTON, PL_PROPERTY, PL_QUANTIZER, PL_RASTER, PL_RENDER, PL_SHADOW, PL_STREAM, PL_TRANSFORM, PL_TRIGGER, PL_VOLUME, PL_WINDOW, TYPE_BOOLEAN, TYPE_DOUBLE, TYPE_FLOAT, TYPE_INTEGER, TYPE_LONG, TYPE_OBJECT, TYPE_STRING
 
Constructor Summary
UniformGrid()
           
 
Method Summary
 boolean buildDirectory(int entity, int ctx)
          Builds the whole data structure (directory) from scratch.
 BrepIterator centerPass(double[] center, double radius, BrepIterator pre)
          Initializes a new center pass.
protected  void computeAccelerators()
          Computes array-indexing accelerators.
protected  void computeBounds()
          Computes coordinate bounds of the whole data set.
protected  void computeBoundsDeferred()
          Computes coordinate bounds of the current set plus deferred insertions.
 java.lang.Object get(java.lang.String key)
          Gets the given property.
 int getStatistics(long[] counters)
          Returns (and resets) counters (for statistics, profiling).
protected  void insert(int index, int id)
          Inserts a new item into the given cell.
protected  void insertEdge(int id, double[] coords, int[] vert, int[][] icoords, int[] ind)
          Inserts a new edge 'id'.
protected  int[] insertFace(int id, double[] coords, int[] vert, int[][] icoords, int[] ind)
          Inserts a new face 'id'.
protected  void insertVertex(int id, double[] coords)
          Inserts a new vertex 'id'.
protected  boolean nextCoord(int[] ind, int[] mi, int[] ma)
          Computes nex integer-coordinate vector, returns true if succeeded.
 boolean optimizeDirectory()
          Optimizes the data structure (directory).
 BrepIterator rayPass(double[] start, double[] direction, BrepIterator pre)
          Initializes a new ray-casting pass.
 boolean resetDirectory(int entity, int ctx)
          (Re-)initializes the data structure (directory).
protected  void scaleGrid()
          Determines grid scale and sets the cells[] array.
 void set(java.lang.String key, java.lang.Object value)
          Sets the given property.
static int setTemplate(Template t, int ord)
          General-purpose registration routine.
 
Methods inherited from class cz.cuni.jagrlib.DefaultGeometrySearch
finishedSegment, getProgress, insertObject, intervalQuery, intervalQuery, localize, localize, removeObject, sweepPass
 
Methods inherited from class cz.cuni.jagrlib.Piece
className, connect, findPlug, findPlug, getInfo, getInterface, getInterface, getPlug, getReg, init, isCompatible, isCompatible, isConnected, logError, logWarning, myInterface, newInputPlug, newOptOutputPlug, newOutputPlug, newPlug, noTemplates, propBegin, propBounds, propDefault, propEnd, propEnum, propManipulator, propManipulator, setProgressListener, setRegStrings, setTemplateDynamic, stop
 
Methods inherited from class cz.cuni.jagrlib.DefaultProperty
booleanProperty, booleanProperty, colorDoubleProperty, colorProperty, commit, doubleProperty, doubleProperty, doubleProperty, enumProperty, floatProperty, floatProperty, floatProperty, intProperty, intProperty, intProperty, longProperty, longProperty, longProperty, set, stringProperty
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface cz.cuni.jagrlib.iface.Property
commit
 

Field Detail

GRID_EPSILON

protected static final double GRID_EPSILON
Tolerance for cell-boundary tests.

See Also:
Constant Field Values

maxGrid

protected int maxGrid
Maximal grid size (in one dimension).


dim

protected int dim
Actual dimensionality of the grid.


alt

protected boolean alt
Use alternative implementation?


leftBound

protected double[] leftBound
Actual left boundary.


rightBound

protected double[] rightBound
Actual right boundary (relative to the leftBound).


cellSize

protected double[] cellSize
Actual cell size.


cells

protected int[] cells
Actual number of cells.


accel

protected int[] accel
Accelerator array. accel[0] .. total array size, accel[1] .. horizontal size (y++), accel[2] .. depth layer size (z++), ..


data

protected int[][] data
Array of individual cells.


geometry

protected Brep geometry
Accelarator - reference to Brep instance.


entity

protected int entity
Actual entity type (VERTEX, EDGE or FACE are supported).


ctx

protected int ctx
Actual context.


CELL_GRANUL

protected static final int CELL_GRANUL
Cell granularity (the rest of each cell is filled by NULL).

See Also:
Constant Field Values

deferred

protected int[] deferred
Deferred inserted items.


pointBoxCounter

protected long pointBoxCounter
Statistics: point to box distance.


pointPointCounter

protected long pointPointCounter
Statistics: point to point distance.


heapCounter

protected long heapCounter
Statistics: heap operations (insert, remove first).


MAX_GRID_SIZE

public static final java.lang.String MAX_GRID_SIZE
See Also:
Constant Field Values

DIM

public static final java.lang.String DIM
See Also:
Constant Field Values

ALTERNATIVE

public static final java.lang.String ALTERNATIVE
See Also:
Constant Field Values

TEMPLATE_NAME

protected static final java.lang.String TEMPLATE_NAME
Object template identifier.

See Also:
Constant Field Values

CATEGORY

protected static final java.lang.String CATEGORY
Object category.

See Also:
Constant Field Values

reg

public static final RegPiece reg
Static registration instance for this class. Automatically initialized in class-loading time.

Constructor Detail

UniformGrid

public UniformGrid()
Method Detail

computeBounds

protected void computeBounds()
Computes coordinate bounds of the whole data set. leftBound/rightBound are filled with min/max values.


computeBoundsDeferred

protected void computeBoundsDeferred()
Computes coordinate bounds of the current set plus deferred insertions. leftBound/rightBound are filled with min/max values.


computeAccelerators

protected final void computeAccelerators()
Computes array-indexing accelerators.


scaleGrid

protected final void scaleGrid()
Determines grid scale and sets the cells[] array.


insert

protected final void insert(int index,
                            int id)
Inserts a new item into the given cell.


nextCoord

protected final boolean nextCoord(int[] ind,
                                  int[] mi,
                                  int[] ma)
Computes nex integer-coordinate vector, returns true if succeeded.


insertVertex

protected final void insertVertex(int id,
                                  double[] coords)
Inserts a new vertex 'id'.


insertEdge

protected final void insertEdge(int id,
                                double[] coords,
                                int[] vert,
                                int[][] icoords,
                                int[] ind)
Inserts a new edge 'id'.


insertFace

protected final int[] insertFace(int id,
                                 double[] coords,
                                 int[] vert,
                                 int[][] icoords,
                                 int[] ind)
Inserts a new face 'id'.


buildDirectory

public boolean buildDirectory(int entity,
                              int ctx)
Builds the whole data structure (directory) from scratch.

Specified by:
buildDirectory in interface GeometrySearch
Overrides:
buildDirectory in class DefaultGeometrySearch
Parameters:
entity - Type of stored entities (VERTEX, EDGE or FACE from interface Brep).
ctx - Handle to the used Brep-context.
Returns:
true if this service is implemented.
See Also:
resetDirectory(int, int), optimizeDirectory(), Brep.VERTEX, Brep.EDGE, Brep.SOLID

resetDirectory

public boolean resetDirectory(int entity,
                              int ctx)
(Re-)initializes the data structure (directory).

Specified by:
resetDirectory in interface GeometrySearch
Overrides:
resetDirectory in class DefaultGeometrySearch
Parameters:
entity - Type of stored entities (VERTEX, EDGE or FACE from interface Brep).
ctx - Handle to the used Brep-context.
Returns:
true if this service is implemented.
See Also:
buildDirectory(int, int), optimizeDirectory(), Brep.VERTEX, Brep.EDGE, Brep.SOLID

optimizeDirectory

public boolean optimizeDirectory()
Optimizes the data structure (directory). Can be used for finishing of the update phase or for explicit data structure optimization. Non-mandatory. (but application has to call it at the end of update phase).

Specified by:
optimizeDirectory in interface GeometrySearch
Overrides:
optimizeDirectory in class DefaultGeometrySearch
Returns:
true if this service is implemented.
See Also:
buildDirectory(int, int), resetDirectory(int, int)

centerPass

public BrepIterator centerPass(double[] center,
                               double radius,
                               BrepIterator pre)
Initializes a new center pass. Objects are enumerated in order defined by increasing distance from the given center point.

Specified by:
centerPass in interface GeometrySearch
Overrides:
centerPass in class DefaultGeometrySearch
Parameters:
center - Center of a pass.
radius - Maximum radius to be searched.
pre - Pre-allocated BrepIterator object (can be null).
Returns:
The initialized iterator data.
See Also:
DefaultGeometrySearch.getProgress(cz.cuni.jagrlib.iface.BrepIterator, int[])

rayPass

public BrepIterator rayPass(double[] start,
                            double[] direction,
                            BrepIterator pre)
Initializes a new ray-casting pass.

Specified by:
rayPass in interface GeometrySearch
Overrides:
rayPass in class DefaultGeometrySearch
Parameters:
start - Starting point of the ray.
direction - Direction vector of the ray.
pre - Pre-allocated BrepIterator object (can be null).
Returns:
The initialized iterator data.
See Also:
DefaultGeometrySearch.getProgress(cz.cuni.jagrlib.iface.BrepIterator, int[])

getStatistics

public int getStatistics(long[] counters)
Returns (and resets) counters (for statistics, profiling).

counters[0] .. number of point-to-point distance calculations.

counters[1] .. number of point-to-box distance calculations.

counters[2] .. number of log(N) heap operations.

Specified by:
getStatistics in interface GeometrySearch
Overrides:
getStatistics in class DefaultGeometrySearch
Parameters:
counters - Array to hold result. If null functions returns required length.
Returns:
Required array length.

set

public void set(java.lang.String key,
                java.lang.Object value)
Sets the given property.

Specified by:
set in interface Property
Overrides:
set in class DefaultProperty
Parameters:
key - Key string.
value - The new value.
See Also:
Property.commit()

get

public java.lang.Object get(java.lang.String key)
Gets the given property.

Specified by:
get in interface Property
Overrides:
get in class DefaultProperty
Parameters:
key - Key string.
Returns:
The actual value or null.

setTemplate

public static int setTemplate(Template t,
                              int ord)
General-purpose registration routine. Sets all plugs, strings, etc. to the given Template.