Package org.web3d.util.spatial
Class GridTrianglePartition
java.lang.Object
org.web3d.util.spatial.GridTrianglePartition
- All Implemented Interfaces:
SpatialPartition
A spatial structure using a grid pattern and triangle objects.
- Version:
- $Id: $
- Author:
- Alan Hudson
-
Field Summary
FieldsModifier and TypeFieldDescriptionint
How many cells have been filled by insertsint
-
Constructor Summary
ConstructorsConstructorDescriptionGridTrianglePartition
(double voxelSize, int numVoxelsPerSide, int numTris) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionprotected void
calcBoundsForTriangle
(Triangle tri, float[] min, float[] max) Calculate a bounding box for a triangle.void
clear()
Clear the structure of all data.protected void
Fill in the grid given a box of grid coordinates.protected void
fillCellsExact
(int[] min, int[] max, Triangle tri) Fill in the grid given a box of grid coordinates.void
findBoundsForTriangle
(Triangle tri, int[] minCoords, int[] maxCoords) Check the general interface contract in superclass method Geometry.doVoxelization.int
findGridCoordsFromWorldCoords
(float coord) Find voxel grid coordinates for a given world coordinatevoid
findGridCoordsFromWorldCoords
(float[] coords, int[] pos) Find voxel grid coordinates for a given world coordinatevoid
findVoxelInWorldCoords
(int x, int y, int z, float[] pos) Find voxel world coordinates for a given voxel coordinate.int[]
getObjects
(int[] min, int[] max) Gets the objects in the specified region.int[]
getObjects
(Region region) Gets the objects in the specified region.float[]
getTriangle
(int id) Get the triangle mapping for an id.Return the grid counts in strin form.void
Insert an array of Triangles.void
Insert an object into the structure.boolean
intersectsTriangle
(Vec3DDouble a, Vec3DDouble b, Vec3DDouble c, float[] pos) Does triangle overlap a voxel.void
-
Field Details
-
cellsFilled
public int cellsFilledHow many cells have been filled by inserts -
numInserts
public int numInserts
-
-
Constructor Details
-
GridTrianglePartition
public GridTrianglePartition(double voxelSize, int numVoxelsPerSide, int numTris) Constructor.- Parameters:
voxelSize
- The size of each voxel in meters.numVoxelsPerSide
- The number of voxels in each axis. Must be even.numTris
-
-
-
Method Details
-
clear
public void clear()Clear the structure of all data.- Specified by:
clear
in interfaceSpatialPartition
-
getObjects
Gets the objects in the specified region. Any object which is contained or overlaps the region will be returned. Objects exactly on a voxel boundary shall be returned in all touching regions.- Specified by:
getObjects
in interfaceSpatialPartition
- Parameters:
region
- The region of interest.- Returns:
- objs The list of triangles
-
getObjects
public int[] getObjects(int[] min, int[] max) Gets the objects in the specified region. Any object which is contained or overlaps the region will be returned. Objects exactly on a voxel boundary shall be returned in all touching regions.- Parameters:
min
- The min grid cell locationmax
- The max grid cell location- Returns:
- The objects or null if none
-
getTriangle
public float[] getTriangle(int id) Get the triangle mapping for an id.- Parameters:
id
-- Returns:
-
insert
Insert an object into the structure.- Parameters:
tri
- The triangleuseBounds
- Should the bounds be used instead of the exact object.
-
insert
Insert an array of Triangles.- Parameters:
tris
- The trianglesuseBounds
- Should the bounds be used instead of the exact object.
-
calcBoundsForTriangle
Calculate a bounding box for a triangle.- Parameters:
tri
-min
- The array to fill in the min boundsmax
- The array to fill in the max bounds
-
findGridCoordsFromWorldCoords
public void findGridCoordsFromWorldCoords(float[] coords, int[] pos) Find voxel grid coordinates for a given world coordinate- Parameters:
coords
- The world coordinatespos
- The position in the grid, preallocate to 3. // * @return The grid coords, x,y,z
-
findGridCoordsFromWorldCoords
public int findGridCoordsFromWorldCoords(float coord) Find voxel grid coordinates for a given world coordinate- Parameters:
coord
- The world coordinates // * param pos The position in the grid, preallocate to 3.- Returns:
- The grid coords, x,y,z
-
findVoxelInWorldCoords
public void findVoxelInWorldCoords(int x, int y, int z, float[] pos) Find voxel world coordinates for a given voxel coordinate.- Parameters:
x
- The x coordy
- The y coordz
- The z coordpos
- The returned position, preallocate to 3
-
fillCells
Fill in the grid given a box of grid coordinates.- Parameters:
min
- The min bounds in cell coordsmax
- The max bounds in cell coordstri
-
-
fillCellsExact
Fill in the grid given a box of grid coordinates.- Parameters:
min
- The min bounds in cell coordsmax
- The max bounds in cell coordstri
-
-
gridCountsToString
-
printStats
public void printStats() -
findBoundsForTriangle
Check the general interface contract in superclass method Geometry.doVoxelization. Current method follows the voxelization algorithm strategy proposed in [DACH2000], but actual implementation only accounts for binary voxels. It is spected that with few changes, this algorithm manages the scalar (multivalued) voxel case for antialiased voxelization. -
intersectsTriangle
Does triangle overlap a voxel. From paper: Fast 3D Triangle-Box Overlap Testing TODO: this paper mentions having errors with long thin polygons- Parameters:
a
- first triangle coordinateb
- second triangle coordinatec
- third triangle coordinatepos
- The voxel center position
-