private void updateCellValues(int startXCell, int startYCell, int lastXCell, int lastYCell, Triangle startTriangle) { // Go over each grid cell and locate a triangle in it to be the cell's // starting search triangle. Since we only pass between adjacent cells // we can search from the last triangle found and not from the start. // Add triangles for each column cells for (int i = startXCell; i <= lastXCell; i++) { // Find a triangle at the begining of the current column startTriangle = indexDelaunay.find(middleOfCell(i, startYCell), startTriangle); grid[i][startYCell] = startTriangle; Triangle prevRowTriangle = startTriangle; // Add triangles for the next row cells for (int j = startYCell + 1; j <= lastYCell; j++) { grid[i][j] = indexDelaunay.find(middleOfCell(i, j), prevRowTriangle); prevRowTriangle = grid[i][j]; } } }
/** * Finds a valid (existing) trinagle adjacent to a given invalid cell * * @param minInvalidCell * minimum bounding box invalid cell * @return a valid triangle adjacent to the invalid cell */ private Triangle findValidTriangle(PointInt minInvalidCell) { // If the invalid cell is the minimal one in the grid we are forced to // search the // triangulation for a trinagle at that location if (minInvalidCell.x == 0 && minInvalidCell.y == 0) return indexDelaunay.find(middleOfCell(minInvalidCell.getX(), minInvalidCell.getY()), null); else // Otherwise we can take an adjacent cell triangle that is still // valid return grid[Math.min(0, minInvalidCell.getX())][Math.min(0, minInvalidCell.getY())]; }
/** * Initialize the grid index * * @param delaunay * delaunay triangulation to index * @param xCellCount * number of grid cells in a row * @param yCellCount * number of grid cells in a column * @param region * geographic region to index */ private void init(DelaunayTriangulation delaunay, int xCellCount, int yCellCount, BoundingBox region) { indexDelaunay = delaunay; indexRegion = region; xSize = region.getWidth() / yCellCount; ySize = region.getHeight() / xCellCount; // The grid will hold a trinagle for each cell, so a point (x,y) will // lie // in the cell representing the grid partition of region to a // xCellCount on yCellCount grid grid = new Triangle[xCellCount][yCellCount]; Triangle colStartTriangle = indexDelaunay.find(middleOfCell(0, 0)); updateCellValues(0, 0, xCellCount - 1, yCellCount - 1, colStartTriangle); }