Skip to content

Commit

Permalink
Rename BoundedVoronoi, support Point type for Shapefiles
Browse files Browse the repository at this point in the history
  • Loading branch information
gwlucastrig committed Sep 12, 2018
1 parent 1d29c1d commit 465718c
Show file tree
Hide file tree
Showing 9 changed files with 146 additions and 34 deletions.
Binary file modified dist/Tinfour-1.0.jar
Binary file not shown.
Binary file modified dist/TinfourViewer-1.0.jar
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
*/
public class BoundedVoronoiBuildOptions {

protected boolean enableAdjustments = false;
protected boolean enableAdjustments;

// The default adjustment value of 30 was chosen through trial and error.
// A round number was chosen to reflect the fact that it is an arbitrary
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,6 @@
import tinfour.common.Vertex;
import tinfour.edge.EdgePool;
import tinfour.edge.QuadEdge;
import tinfour.semivirtual.SemiVirtualIncrementalTin;
import tinfour.standard.IncrementalTin;
import tinfour.utils.TinInstantiationUtility;
import tinfour.utils.VertexColorizerKempe6;

Expand All @@ -71,7 +69,7 @@
* <strong>This class is under development and is subject to minor
* changes in its API and behavior.</strong>
*/
public class BoundedVoronoi {
public class BoundedVoronoiDiagram {

/**
* The overall domain of the structure
Expand All @@ -95,7 +93,7 @@ public class BoundedVoronoi {

private double maxRadius = -1;

private BoundedVoronoi() {
private BoundedVoronoiDiagram() {
// a private constructor to deter applications from
// invoking the default constructor
sampleBounds = null;
Expand All @@ -111,7 +109,7 @@ private BoundedVoronoi() {
* null to use defaults.
*
*/
public BoundedVoronoi(List<Vertex> vertexList, BoundedVoronoiBuildOptions options) {
public BoundedVoronoiDiagram(List<Vertex> vertexList, BoundedVoronoiBuildOptions options) {
if (vertexList == null) {
throw new IllegalArgumentException(
"Null input not allowed for constructor");
Expand Down Expand Up @@ -176,7 +174,7 @@ public BoundedVoronoi(List<Vertex> vertexList, BoundedVoronoiBuildOptions option
* @param delaunayTriangulation a valid instance of a Delaunay Triangulation
* implementation.
*/
public BoundedVoronoi(IIncrementalTin delaunayTriangulation) {
public BoundedVoronoiDiagram(IIncrementalTin delaunayTriangulation) {
if (delaunayTriangulation == null) {
throw new IllegalArgumentException(
"Null input is not allowed for TIN");
Expand Down Expand Up @@ -316,8 +314,8 @@ private IQuadEdge liangBarsky(Vertex v0, Vertex v1) {
} else {
x = x0 + t0 * xDelta;
y = y0 + t0 * yDelta;
z = computeZ(iBorder0, x, y);
p0 = new Vertex(x, y, z, v0.getIndex());
z = computePerimeterParameter(iBorder0, x, y);
p0 = new PerimeterVertex(x, y, z, v0.getIndex());
p0.setSynthetic(true);
}

Expand All @@ -326,16 +324,16 @@ private IQuadEdge liangBarsky(Vertex v0, Vertex v1) {
} else {
x = x0 + t1 * xDelta;
y = y0 + t1 * yDelta;
z = computeZ(iBorder1, x, y);
p1 = new Vertex(x, y, z, v1.getIndex());
z = computePerimeterParameter(iBorder1, x, y);
p1 = new PerimeterVertex(x, y, z, v1.getIndex());
p1.setSynthetic(true);
}

return edgePool.allocateEdge(p0, p1);
}

@SuppressWarnings("PMD.CollapsibleIfStatements")
private double computeZ(double x, double y) {
private double computePerimeterParameter(double x, double y) {
if (y == ymin) {
// bottom border range 0 to 1
if (xmin <= x && x <= xmax) {
Expand All @@ -360,7 +358,7 @@ private double computeZ(double x, double y) {
return Double.NaN;
}

private double computeZ(int iBoarder, double x, double y) {
private double computePerimeterParameter(int iBoarder, double x, double y) {
switch (iBoarder) {
case 0:
return (x - xmin) / (xmax - xmin);
Expand Down Expand Up @@ -451,14 +449,14 @@ private void buildPerimeterRay(IQuadEdge e, Vertex[] center, IQuadEdge[] part) {
y = t * uY + cY;
if (t >= 0 && y0 <= y && y <= y1) {
z = 4 - (y - y0) / (y1 - y0); // the left side, descending, z in [3,4]
Vertex v = new Vertex(x0, y, z, -vCenter.getIndex());
Vertex v = new PerimeterVertex(x0, y, z, -vCenter.getIndex());
nBuild = insertRayVertex(nBuild, vBuild, tBuild, t, v);
}
t = (x1 - cX) / uX;
y = t * uY + cY;
if (t >= 0 && y0 <= y && y <= y1) {
z = 1 + (y - y0) / (y1 - y0); // right side, ascending, z in [1,2]
Vertex v = new Vertex(x1, y, z, -vCenter.getIndex());
Vertex v = new PerimeterVertex(x1, y, z, -vCenter.getIndex());
nBuild = insertRayVertex(nBuild, vBuild, tBuild, t, v);
}
}
Expand All @@ -468,15 +466,15 @@ private void buildPerimeterRay(IQuadEdge e, Vertex[] center, IQuadEdge[] part) {
x = t * uX + cX;
if (t >= 0 && x0 <= x && x <= x1) {
z = (x - x0) / (x1 - x0); // bottom side, ascending, z in [0,1]
Vertex v = new Vertex(x, y0, z, -vCenter.getIndex());
Vertex v = new PerimeterVertex(x, y0, z, -vCenter.getIndex());
nBuild = insertRayVertex(nBuild, vBuild, tBuild, t, v);
}

t = (y1 - cY) / uY;
x = t * uX + cX;
if (t >= 0 && x0 <= x && x <= x1) {
z = 3 - (x - x0) / (x1 - x0); // top side, descending, z in [2,3]
Vertex v = new Vertex(x, y1, z, -vCenter.getIndex());
Vertex v = new PerimeterVertex(x, y1, z, -vCenter.getIndex());
nBuild = insertRayVertex(nBuild, vBuild, tBuild, t, v);
}
}
Expand Down Expand Up @@ -574,8 +572,16 @@ private void buildCenter(Circumcircle cCircle, IQuadEdge e, Vertex[] centers) {
}
double x = cCircle.getX();
double y = cCircle.getY();
double z = computeZ(x, y);
Vertex v = new Vertex(x, y, z, mindex(e, f, r));
// there is a low, but non-zero, probability that the center
// will lie on one of the perimeter edges.
double z = computePerimeterParameter(x, y);
Vertex v;
if (Double.isNaN(z)) {
v = new Vertex(x, y, z, mindex(e, f, r));
} else {
v = new PerimeterVertex(x, y, z, mindex(e, f, r));
}

centers[e.getIndex()] = v;
centers[f.getIndex()] = v;
centers[r.getIndex()] = v;
Expand All @@ -594,15 +600,18 @@ private void buildStructure(
IIncrementalTin tin,
BoundedVoronoiBuildOptions pOptions) {

if (pOptions.enableAdjustments) {
if (tin instanceof IncrementalTin) {
((IncrementalTin) tin).collaspsePerimeterTriangles(
pOptions.adjustmentThreshold);
} else if (tin instanceof SemiVirtualIncrementalTin) {
((SemiVirtualIncrementalTin) tin).collaspsePerimeterTriangles(
pOptions.adjustmentThreshold);
}
}

// The TIN classes' adjustment logic has a flaw, so it is supressed here
// pending a fix or permanent removal
//if (pOptions.enableAdjustments) {
// if (tin instanceof IncrementalTin) {
// ((IncrementalTin) tin).collaspsePerimeterTriangles(
// pOptions.adjustmentThreshold);
// } else if (tin instanceof SemiVirtualIncrementalTin) {
// ((SemiVirtualIncrementalTin) tin).collaspsePerimeterTriangles(
// pOptions.adjustmentThreshold);
// }
//}

// The visited array tracks which of the TIN edges were
// visited for various processes. It is used more than once.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
@SuppressWarnings("PMD.AvoidInstantiatingObjectsInLoops")
public class BoundedVoronoiDrawingUtility {

private final BoundedVoronoi diagram;
private final BoundedVoronoiDiagram diagram;
private final AffineTransform af;
private final Rectangle2D bounds;

Expand Down Expand Up @@ -100,7 +100,7 @@ public class BoundedVoronoiDrawingUtility {
* defaults are to be used.
*/
public BoundedVoronoiDrawingUtility(
BoundedVoronoi diagram,
BoundedVoronoiDiagram diagram,
int width,
int height,
int pad,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,14 @@
public class BoundedVoronoiIntegrityCheck {

String message;
BoundedVoronoi lmv;
BoundedVoronoiDiagram lmv;

/**
* Constructs an instance of the integrity checker tied to the
* specified instance.
* @param BoundedVoronoi a valid, correctly populated instance
*/
public BoundedVoronoiIntegrityCheck(BoundedVoronoi BoundedVoronoi) {
public BoundedVoronoiIntegrityCheck(BoundedVoronoiDiagram BoundedVoronoi) {
lmv = BoundedVoronoi;
message = null;
}
Expand Down
76 changes: 76 additions & 0 deletions src/main/java/tinfour/voronoi/PerimeterVertex.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/* --------------------------------------------------------------------
* Copyright 2018 Gary W. Lucas.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0A
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ---------------------------------------------------------------------
*/

/*
* -----------------------------------------------------------------------
*
* Revision History:
* Date Name Description
* ------ --------- -------------------------------------------------
* 09/2018 G. Lucas Initial implementation
*
* Notes:
*
* -----------------------------------------------------------------------
*/
package tinfour.voronoi;

import tinfour.common.Vertex;

/**
* Extends the Vertex class to add perimeter parameter.
*/
class PerimeterVertex extends Vertex {
/**
* The perimeter parameter
*/
final double p;

/**
* Construct a vertex at the specified horizontal Cartesian coordinates with
* a z value indicating the parameterized position along the rectangular
* bounds of the Voronoi Diagram. The parameter is a value in the
* range 0 &le; z &lt 4.
* @param x the x Cartesian coordinate of the vertex
* @param y the y Cartesian coordinate of the vertex
* @param z the parameterized position, in range 0 to 4.
* @param index an arbitrary index value
*/
public PerimeterVertex(double x, double y, double z, int index){
super(x, y, z, index);
this.p = z;
}

/**
* Gets the perimeter parameter value for vertex.
* @return a valid double-precision value
*/
@Override
public double getZ(){
return p;
}

@Override
public String toString() {
if (this.isSynthetic()) {
return String.format("Pv %11.9f", p);
} else {
// the rare case of a circumcenter lying on the perimeter
return String.format("Pcc %11.9f, center %d", p, getIndex());
}
}
}
16 changes: 15 additions & 1 deletion src/main/java/tinfour/voronoi/ThiessenPolygon.java
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public double getArea() {
}

/**
* Gets the central vertex of the polygon.
* Gets the defining vertex of the polygon.
*
* @return the vertex
*/
Expand Down Expand Up @@ -142,6 +142,20 @@ public boolean isPointInPolygon(double x, double y) {
public boolean isOpen(){
return open;
}

/**
* Gets the index element of the defining vertex for this polygon.
* The vertex index is under the control of the calling application
* and is not modified by the Voronoi classes. Note that the
* index of a vertex is not necessarily unique but left to the
* requirements of the application that constructs it.
* @return an integer value
*/
public int getIndex(){
return vertex.getIndex();
}


@Override
public String toString() {
return String.format("ThiessenPolygon vertex=%s", vertex.getLabel());
Expand Down
15 changes: 14 additions & 1 deletion src/test/java/tinfour/test/shapefile/ShapefileReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ public ShapefileReader(File file) throws IOException {
}

minX = raf.readDouble();
maxX = raf.readDouble();
minY = raf.readDouble();
maxX = raf.readDouble();
maxY = raf.readDouble();
minZ = raf.readDouble();
maxZ = raf.readDouble();
Expand Down Expand Up @@ -196,6 +196,19 @@ record = new ShapefileRecord();
+ ", expected " + shapefileType.getTypeCode());
}
switch (shapefileType) {
case Point:
// simple case, but we populate other record items for consistency
record.setSizes(1,1);
record.nParts = 1;
record.nPoints = 1;
record.partStart[1] = 1;
record.x0 = raf.readDouble();
record.y0 = raf.readDouble();
record.x1 = record.x0;
record.y1 = record.y0;
record.xyz[0] = record.x0;
record.xyz[1] = record.y0;
break;
case PolyLineZ:
case PolygonZ: {
record.x0 = raf.readDouble();
Expand Down

0 comments on commit 465718c

Please sign in to comment.