use of de.fhg.igd.geom.Point3D in project hale by halestudio.
the class FaceTriangulation method isEar.
/**
* Checks if vertex p2 is an ear
*
* @param p1 the point prior to p2
* @param p2 the point to check
* @param p3 the point next to p2
* @param points the array of all vertices
* @return true if p2 is an ear, false otherwise
*/
private boolean isEar(Point3D p1, Point3D p2, Point3D p3, List<Point3D> points) {
for (int i = 0; i < points.size() - 1; ++i) {
Point3D a1, a2, a3;
if (i == 0) {
a1 = points.get(points.size() - 1);
a2 = points.get(0);
a3 = points.get(1);
} else {
a1 = points.get(i - 1);
a2 = points.get(i);
a3 = points.get(i + 1);
}
// don't check triangle points
if (a2 == p1 || a2 == p2 || a2 == p3) {
continue;
}
if (_convexCache[i] == CONVEX_NOTCHECKED) {
_convexCache[i] = (isConvex(a1, a2, a3) ? CONVEX_TRUE : CONVEX_FALSE);
}
if (_convexCache[i] == CONVEX_FALSE) {
// if this point is concave and
// the triangle p1,p2,p3 contains it
// the p1,p2,p3 is no ear!
boolean c1 = isConvex(p1, p2, a2);
boolean c2 = isConvex(p2, p3, a2);
boolean c3 = isConvex(p3, p1, a2);
if ((c1 == c2) && (c2 == c3)) {
return false;
}
}
}
return true;
}
use of de.fhg.igd.geom.Point3D in project hale by halestudio.
the class AbstractInstancePainter method createWaypoint.
/**
* Create a way-point for an instance
*
* @param instance the instance
* @param instanceService the instance service
* @return the created way-point or <code>null</code> if
*/
protected InstanceWaypoint createWaypoint(Instance instance, InstanceService instanceService) {
// retrieve instance reference
// ,
InstanceReference ref = instanceService.getReference(instance);
// getDataSet());
BoundingBox bb = null;
List<GeometryProperty<?>> geometries = new ArrayList<GeometryProperty<?>>(DefaultGeometryUtil.getDefaultGeometries(instance));
ListIterator<GeometryProperty<?>> it = geometries.listIterator();
while (it.hasNext()) {
GeometryProperty<?> prop = it.next();
// check if geometry is valid for display in map
CoordinateReferenceSystem crs = (prop.getCRSDefinition() == null) ? (null) : (prop.getCRSDefinition().getCRS());
if (crs == null) {
// no CRS, can't display in map
// remove from list
it.remove();
} else {
Geometry geometry = prop.getGeometry();
// determine geometry bounding box
BoundingBox geometryBB = BoundingBox.compute(geometry);
if (geometryBB == null) {
// no valid bounding box for geometry
it.remove();
} else {
try {
// get converter to way-point CRS
CRSConverter conv = CRSConverter.getConverter(crs, getWaypointCRS());
// convert BB to way-point SRS
geometryBB = conv.convert(geometryBB);
// add to instance bounding box
if (bb == null) {
bb = new BoundingBox(geometryBB);
} else {
bb.add(geometryBB);
}
} catch (Exception e) {
log.error("Error converting instance bounding box to waypoint bounding box", e);
// ignore geometry
it.remove();
}
}
}
}
if (bb == null || geometries.isEmpty()) {
// don't create way-point w/o geometries
return null;
}
// use bounding box center as GEO position
Point3D center = bb.getCenter();
GeoPosition pos = new GeoPosition(center.getX(), center.getY(), GenericWaypoint.COMMON_EPSG);
// buffer bounding box if x or y dimension empty
if (bb.getMinX() == bb.getMaxX()) {
bb.setMinX(bb.getMinX() - BUFFER_VALUE);
bb.setMaxX(bb.getMaxX() + BUFFER_VALUE);
}
if (bb.getMinY() == bb.getMaxY()) {
bb.setMinY(bb.getMinY() - BUFFER_VALUE);
bb.setMaxY(bb.getMaxY() + BUFFER_VALUE);
}
// set dummy z range (otherwise the RTree can't deal correctly with it)
bb.setMinZ(-BUFFER_VALUE);
bb.setMaxZ(BUFFER_VALUE);
String name = findInstanceName(instance);
// create the way-point
// XXX in abstract method?
InstanceWaypoint wp = new InstanceWaypoint(pos, bb, ref, geometries, instance.getDefinition(), name);
// each way-point must have its own marker, as the marker stores the
// marker areas
wp.setMarker(createMarker(wp));
return wp;
}
use of de.fhg.igd.geom.Point3D in project hale by halestudio.
the class InstanceMarker method paintLine.
/**
* Paint a line string geometry.
*
* @param geometry the line string
* @param g the graphics object to paint on
* @param crsDefinition the CRS definition associated to the geometry
* @param context the context
* @param converter the pixel converter
* @param zoom the zoom level
* @param mapCRS the map coordinate reference system
* @param calculateArea if the area representing the marker should be
* calculated, if <code>false</code> is given here the return
* value is ignored and should be <code>null</code>
* @return the polygon area or <code>null</code> if painting failed
*/
protected Area paintLine(LineString geometry, Graphics2D g, CRSDefinition crsDefinition, InstanceWaypoint context, PixelConverter converter, int zoom, CoordinateReferenceSystem mapCRS, boolean calculateArea) {
Coordinate[] coordinates = geometry.getCoordinates();
if (coordinates.length <= 0) {
return null;
}
if (coordinates.length == 1) {
// fall back to point drawing
Point point = getGeometryFactory().createPoint(coordinates[0]);
return paintPoint(point, g, crsDefinition, context, converter, zoom, mapCRS, calculateArea);
}
try {
// get CRS converter
CRSConverter conv = CRSConverter.getConverter(crsDefinition.getCRS(), mapCRS);
List<Point2D> mapPoints = new ArrayList<Point2D>(coordinates.length);
for (Coordinate coord : coordinates) {
// manually convert to map CRS
Point3D mapPoint = conv.convert(coord.x, coord.y, 0);
GeoPosition pos = new GeoPosition(mapPoint.getX(), mapPoint.getY(), converter.getMapEpsg());
Point2D point = converter.geoToPixel(pos, zoom);
mapPoints.add(point);
}
if (applyStroke(g, context)) {
for (int i = 0; i < mapPoints.size() - 1; i++) {
// draw each connecting line
Point2D p1 = mapPoints.get(i);
Point2D p2 = mapPoints.get(i + 1);
g.drawLine((int) p1.getX(), (int) p1.getY(), (int) p2.getX(), (int) p2.getY());
}
} else {
log.warn("Stroke disabled in style, LineString is not rendered");
}
if (!calculateArea) {
return null;
}
// use a buffer around the line as area
// XXX
java.awt.Polygon[] buffer = createBufferPolygon(mapPoints, 3);
// ok?
if (buffer.length == 0) {
return null;
} else if (buffer.length == 1) {
return new PolygonArea(buffer[0]);
} else {
Collection<Area> areas = new ArrayList<Area>();
for (java.awt.Polygon bufferPoly : buffer) {
areas.add(new PolygonArea(bufferPoly));
}
return new MultiArea(areas);
}
} catch (Exception e) {
log.error("Error painting instance polygon geometry", e);
return null;
}
}
use of de.fhg.igd.geom.Point3D in project hale by halestudio.
the class InstanceMarker method paintPoint.
/**
* Paint a point geometry.
*
* @param geometry the point
* @param g the graphics object to paint on
* @param crsDefinition the CRS definition associated to the geometry
* @param context the context
* @param converter the pixel converter
* @param zoom the zoom level
* @param mapCRS the map coordinate reference system
* @param calculateArea if the area representing the marker should be
* calculated, if <code>false</code> is given here the return
* value is ignored and should be <code>null</code>
* @return the point marker area or <code>null</code> if painting failed
*/
protected Area paintPoint(Point geometry, Graphics2D g, CRSDefinition crsDefinition, InstanceWaypoint context, PixelConverter converter, int zoom, CoordinateReferenceSystem mapCRS, boolean calculateArea) {
try {
/*
* Conversion to map pixel coordinates: Though most of the time the
* result will be the origin (0,0), e.g. for way-points representing
* a single point, the coordinates may also be different, e.g. for
* MultiPoint way-points.
*/
// 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);
int x = (int) point.getX();
int y = (int) point.getY();
// fall-back: circle
if (applyFill(g, context)) {
g.fillOval(x - defaultPointSize / 2, y - defaultPointSize / 2, defaultPointSize, defaultPointSize);
}
if (applyStroke(g, context)) {
// TODO respect stroke width?
g.drawOval(x - defaultPointSize / 2 - 1, y - defaultPointSize / 2 - 1, defaultPointSize + 1, defaultPointSize + 1);
}
if (calculateArea) {
return new PolygonArea(new java.awt.Polygon(new int[] { x - defaultPointSize / 2 - 1, x + defaultPointSize / 2 + 1, x + defaultPointSize / 2 + 1, x - defaultPointSize / 2 - 1 }, new int[] { y - defaultPointSize / 2 - 1, y - defaultPointSize / 2 - 1, y + defaultPointSize / 2 + 1, y + defaultPointSize / 2 + 1 }, 4));
} else {
return null;
}
} catch (Exception e) {
log.error("Error painting instance point geometry", e);
return null;
}
}
use of de.fhg.igd.geom.Point3D in project hale by halestudio.
the class InstanceMarker method createPolygon.
private java.awt.Polygon createPolygon(Coordinate[] coordinates, CRSConverter geoConverter, PixelConverter pixelConverter, int zoom) throws TransformException, IllegalGeoPositionException {
java.awt.Polygon result = new java.awt.Polygon();
for (Coordinate coord : coordinates) {
// manually convert to map CRS
Point3D mapPoint = geoConverter.convert(coord.x, coord.y, 0);
GeoPosition pos = new GeoPosition(mapPoint.getX(), mapPoint.getY(), pixelConverter.getMapEpsg());
Point2D point = pixelConverter.geoToPixel(pos, zoom);
result.addPoint((int) point.getX(), (int) point.getY());
}
return result;
}
Aggregations