use of de.fhg.igd.geom.Point3D in project hale by halestudio.
the class AreaCalc method triangulate.
/**
* Triangulates the polygon.
*
* @param pos List of {@link GeoPosition}
*
* @return List of {@link Triangle}
*/
private List<Triangle> triangulate(List<GeoPosition> pos) {
// contains all triangles
List<Triangle> triangles = new ArrayList<Triangle>(pos.size() - 1);
// standard epsg code
int epsg = pos.get(0).getEpsgCode();
// check if it's already a triangle
if (pos.size() == 3) {
triangles.add(new Triangle(pos.get(0), pos.get(1), pos.get(2)));
return triangles;
}
// contains all points from the surface
List<Point3D> face = new ArrayList<>();
// convert Point2D to Vertex
for (int i = 0; i < pos.size(); i++) {
GeoPosition p = pos.get(i);
face.add(new Point3D(p.getX(), p.getY(), 0.0));
}
// create FaceSet and triangulate
FaceTriangulation fst = new FaceTriangulation();
List<List<Point3D>> faces = fst.triangulateFace(face);
// convert
for (List<Point3D> f : faces) {
// create GeoPositions
GeoPosition p1, p2, p3;
p1 = new GeoPosition(f.get(0).getX(), f.get(0).getY(), epsg);
p2 = new GeoPosition(f.get(1).getX(), f.get(1).getY(), epsg);
p3 = new GeoPosition(f.get(2).getX(), f.get(2).getY(), epsg);
// add triangle
triangles.add(new Triangle(p1, p2, p3));
}
return triangles;
}
use of de.fhg.igd.geom.Point3D in project hale by halestudio.
the class StyledInstanceMarker method paintPoint.
/**
* @see InstanceMarker#paintPoint(Point, Graphics2D, CRSDefinition,
* InstanceWaypoint, PixelConverter, int, CoordinateReferenceSystem,
* boolean)
*/
@Override
protected Area paintPoint(Point geometry, Graphics2D g, CRSDefinition crsDefinition, InstanceWaypoint context, PixelConverter converter, int zoom, CoordinateReferenceSystem mapCRS, boolean calculateArea) {
initStyle(context);
Area area = null;
try {
if (pointSymbolizer == null || (SLD.mark(pointSymbolizer) == null && pointSymbolizer.getGraphic().graphicalSymbols().isEmpty())) {
// generic
return super.paintFallback(g, context, converter, zoom, null, calculateArea);
}
// get CRS converter
CRSConverter conv = CRSConverter.getConverter(crsDefinition.getCRS(), mapCRS);
// manually convert to map CRS
Point3D mapPoint = conv.convert(geometry.getX(), geometry.getY(), 0);
GeoPosition pos = new GeoPosition(mapPoint.getX(), mapPoint.getY(), converter.getMapEpsg());
// determine pixel coordinates
Point2D point = converter.geoToPixel(pos, zoom);
Coordinate coordinate = new Coordinate(point.getX(), point.getY());
Point newPoint = geometry.getFactory().createPoint(coordinate);
// create a LiteShape and instantiate the Painter and the
// StyleFactory
LiteShape2 lites = new LiteShape2(newPoint, null, null, false);
StyledShapePainter ssp = new StyledShapePainter();
SLDStyleFactory styleFactory = new SLDStyleFactory();
Range<Double> range = new Range<Double>(Double.class, 0.5, 1.5);
PointSymbolizer pointS;
// is the Waypoint selected?
if (context.isSelected()) {
// switch to the SelectionSymbolizer
pointS = getSelectionSymbolizer(pointSymbolizer);
} else
// use the specific PointSymbolizer
pointS = pointSymbolizer;
// Create the Style2D object for painting with the use of a
// DummyFeature wich extends SimpleFeatures
// because Geotools can only work with that
DummyFeature dummy = new DummyFeature();
Style2D style2d = styleFactory.createStyle(dummy, pointS, range);
// create the area object of the painted image for further use
area = getArea(point, style2d, lites);
// actually paint
ssp.paint(g, lites, style2d, 1);
// graphic)
if (context.isSelected() && style2d instanceof GraphicStyle2D) {
GraphicStyle2D gs2d = (GraphicStyle2D) style2d;
// get minX and minY for the drawn rectangle arround the image
int minX = (int) point.getX() - gs2d.getImage().getWidth() / 2;
int minY = (int) point.getY() - gs2d.getImage().getHeight() / 2;
// apply the specification of the selection rectangle
applyFill(g, context);
applyStroke(g, context);
// draw the selection rectangle
g.drawRect(minX - 1, minY - 1, gs2d.getImage().getWidth() + 1, gs2d.getImage().getHeight() + 1);
}
} catch (Exception e) {
e.printStackTrace();
return null;
}
return area;
}
use of de.fhg.igd.geom.Point3D in project hale by halestudio.
the class FaceTriangulation method earCutting.
/**
* Cuts an ear from a face. The ear will be removed from the given list of
* points and the indices of the real vertices will also be truncated.
*
* @param points all vertices of the face
* @param indices an array containing indices for the real vertices
* @return the indices of the ear
*/
private int[] earCutting(List<Point3D> points, int[] indices) {
if (points.size() == 3) {
points.clear();
return indices;
}
// one triangle always remains)
for (int i = 0; i < points.size() - 1; ++i) {
Point3D v1, v2, v3;
int i1, i2, i3;
if (i == 0) {
v1 = points.get(points.size() - 1);
i1 = indices[points.size() - 1];
v2 = points.get(0);
i2 = indices[0];
v3 = points.get(1);
i3 = indices[1];
} else {
v1 = points.get(i - 1);
i1 = indices[i - 1];
v2 = points.get(i);
i2 = indices[i];
v3 = points.get(i + 1);
i3 = indices[i + 1];
}
// is the vertex convex?
if (_convexCache[i] == CONVEX_NOTCHECKED) {
if (isConvex(v1, v2, v3)) {
_convexCache[i] = CONVEX_TRUE;
} else {
_convexCache[i] = CONVEX_FALSE;
}
}
// if the vertex is concave it cannot be an ear
if (_convexCache[i] == CONVEX_FALSE) {
continue;
}
boolean ear = isEar(v1, v2, v3, points);
if (ear) {
// cut ear:
// create new Face
int[] result = new int[] { i1, i2, i3 };
// remove ear vertex from old Face
if (i == 0) {
System.arraycopy(indices, 1, indices, 0, indices.length - 1);
} else {
System.arraycopy(indices, 0, indices, 0, i);
System.arraycopy(indices, i + 1, indices, i, indices.length - i - 1);
}
points.remove(i);
return result;
}
}
// contains at least one ear
return null;
}
use of de.fhg.igd.geom.Point3D in project hale by halestudio.
the class FaceTriangulation method reversePoints.
/**
* Reverses a list of points
*
* @param a the list
* @param indices the index array that connects the points with the vertices
* in the corresponding face
*/
private static void reversePoints(List<Point3D> a, int[] indices) {
for (int i = 0; i < a.size() / 2; ++i) {
int j = a.size() - 1 - i;
Point3D p1 = a.get(i);
Point3D p2 = a.get(j);
a.set(i, p2);
a.set(j, p1);
int i1 = indices[i];
int i2 = indices[j];
indices[i] = i2;
indices[j] = i1;
}
}
use of de.fhg.igd.geom.Point3D in project hale by halestudio.
the class FaceTriangulation method projectAndCompactFace.
/**
* Projects a Face onto a 2D plane using a given normal. Also compacts the
* face (removes consecutive duplicate points).
*
* @param f the Face
* @param k the normal
* @param points a valid list that will receive the new projected points
* @return the index array that connects the new projected points with the
* vertex array in the given Face
* @throws IllegalArgumentException if the list of points is null
*/
private static int[] projectAndCompactFace(List<Point3D> f, List<Point3D> points, Point3D k) {
if (points == null) {
throw new IllegalArgumentException("points must not be null");
}
// handle degenerated faces
if (f.size() == 0) {
return new int[0];
} else if (f.size() == 1) {
points.add(f.get(0));
return new int[] { 0 };
} else if (f.size() == 2) {
points.add(f.get(0));
points.add(f.get(1));
return new int[] { 0, 1 };
}
// calculate projected coordinate system
Point3D i = new Point3D();
Point3D j = new Point3D();
if ((Math.abs(k.getX()) > 0.1) || (Math.abs(k.getY()) > 0.1)) {
i.setX(-k.getY());
i.setY(k.getX());
i.setZ(k.getZ());
} else {
i.setX(k.getZ());
i.setZ(-k.getX());
i.setY(k.getY());
}
normalize(i);
j.setX(i.getY() * k.getZ() - i.getZ() * k.getY());
j.setY(i.getZ() * k.getX() - i.getX() * k.getZ());
j.setZ(i.getX() * k.getY() - i.getY() * k.getX());
normalize(j);
// project face onto a plane:
// transform points and create index array
int len = f.size();
if (f.get(0).equals(f.get(len - 1))) {
// create a triangle from a face with 4 points, if the
// first one and the last one are equal
--len;
}
List<Integer> indexList = new ArrayList<Integer>();
for (int v = 0; v < len; ++v) {
if (f.get((len + v - 1) % len).equals(f.get(v))) {
// skip consecutive duplicate points
continue;
}
double vx = f.get(v).getX();
double vy = f.get(v).getY();
double vz = f.get(v).getZ();
double x = vx * i.getX() + vy * i.getY() + vz * i.getZ();
double y = vx * j.getX() + vy * j.getY() + vz * j.getZ();
double z = vx * k.getX() + vy * k.getY() + vz * k.getZ();
points.add(new Point3D(x, y, z));
// add the original index, so we can refer to it later
indexList.add(v);
}
// copy indexes
int[] indices = new int[indexList.size()];
int p = 0;
for (Integer index : indexList) {
indices[p++] = index;
}
return indices;
}
Aggregations