Search in sources :

Example 11 with BoundingBox

use of de.fhg.igd.geom.BoundingBox in project hale by halestudio.

the class Node method pickSeeds.

/**
 * Finds the first entries of two splitted groups (Quadratic Split)
 *
 * @return the two entries
 */
private Localizable[] pickSeeds() {
    Localizable[] result = new Localizable[2];
    int ii = -1, jj = -1;
    double min = Double.NEGATIVE_INFINITY;
    for (int i = 0; i < _children.size() - 1; ++i) {
        for (int j = i + 1; j < _children.size(); ++j) {
            Localizable e1 = _children.get(i);
            Localizable e2 = _children.get(j);
            // compose a new bounding box
            BoundingBox bb = new BoundingBox(e1.getBoundingBox());
            bb.add(e2.getBoundingBox());
            // calculate waste
            double d = calcPseudoVolume(bb) - calcPseudoVolume(e1) - calcPseudoVolume(e2);
            if (d > min) {
                result[0] = e1;
                ii = i;
                result[1] = e2;
                jj = j;
                min = d;
            }
        }
    }
    // result must not be empty
    assert result[0] != null;
    assert result[1] != null;
    // remove entries from the list of Localizables
    // make sure that we remove the correct element jj if
    // ii has been removed before
    _children.remove(ii);
    _children.remove(ii < jj ? jj - 1 : jj);
    return result;
}
Also used : BoundingBox(de.fhg.igd.geom.BoundingBox) Localizable(de.fhg.igd.geom.Localizable)

Example 12 with BoundingBox

use of de.fhg.igd.geom.BoundingBox in project hale by halestudio.

the class Node method find.

/**
 * Returns a list of all Localizables that have any relation to the given
 * Localizable loc.
 *
 * @param loc the Localizable to match
 * @param ignoreZ true if the z coordinate should be ignored during
 *            candidate search
 * @return a list of Localizables (containing only leafs of this tree and no
 *         nodes)
 */
@SuppressWarnings("unchecked")
private List<T> find(final Localizable loc, boolean ignoreZ) {
    List<T> result = new ArrayList<T>();
    BoundingBox theirs = loc.getBoundingBox();
    for (Localizable l : _children) {
        BoundingBox ours = l.getBoundingBox();
        if (relate(ours, theirs, ignoreZ)) {
            if (l instanceof Node) {
                // descend
                result.addAll(((Node<T>) l).find(loc, ignoreZ));
            } else {
                // add leaf
                result.add((T) l);
            }
        }
    }
    return result;
}
Also used : BoundingBox(de.fhg.igd.geom.BoundingBox) ArrayList(java.util.ArrayList) Localizable(de.fhg.igd.geom.Localizable)

Example 13 with BoundingBox

use of de.fhg.igd.geom.BoundingBox in project hale by halestudio.

the class Node method findNeighborhood.

/**
 * This method will return the "Neighborhood" of a given Localizable.
 *
 * @param k the number of neighbor candidates to retrieve
 * @param loc the given Localizable
 * @param stepsize the size of each step in which the neighborhood is
 *            enlarged. If the original Localizable had no volume (because
 *            it's a point type), this value is first used as an absolute
 *            value and then as a successive relative increase
 * @return a list with all neighbors
 */
public ArrayList<T> findNeighborhood(int k, Localizable loc, double stepsize) {
    ArrayList<T> result = new ArrayList<T>();
    result.addAll(this.find(loc));
    BoundingBox bb = loc.getBoundingBox();
    while (result.size() < k && this.getBoundingBox().intersectsOrCovers(bb)) {
        bb.expand(stepsize);
        result.addAll(this.find(bb));
    }
    return result;
}
Also used : BoundingBox(de.fhg.igd.geom.BoundingBox) ArrayList(java.util.ArrayList)

Example 14 with BoundingBox

use of de.fhg.igd.geom.BoundingBox in project hale by halestudio.

the class RTree method insert.

/**
 * @see SpatialIndex#insert(Localizable)
 */
@Override
public void insert(T loc) {
    BoundingBox box = loc.getBoundingBox();
    if (!box.checkIntegrity()) {
        throw new IllegalArgumentException("You may not insert a " + "Localizable object with a invalid BoundingBox");
    }
    _root.insert(loc);
    ++_size;
}
Also used : BoundingBox(de.fhg.igd.geom.BoundingBox)

Example 15 with BoundingBox

use of de.fhg.igd.geom.BoundingBox 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;
}
Also used : GeometryProperty(eu.esdihumboldt.hale.common.schema.geometry.GeometryProperty) ArrayList(java.util.ArrayList) InvocationTargetException(java.lang.reflect.InvocationTargetException) Geometry(com.vividsolutions.jts.geom.Geometry) CRSConverter(eu.esdihumboldt.hale.ui.views.styledmap.util.CRSConverter) PseudoInstanceReference(eu.esdihumboldt.hale.common.instance.model.impl.PseudoInstanceReference) InstanceReference(eu.esdihumboldt.hale.common.instance.model.InstanceReference) Point3D(de.fhg.igd.geom.Point3D) BoundingBox(de.fhg.igd.geom.BoundingBox) GeoPosition(org.jdesktop.swingx.mapviewer.GeoPosition) CoordinateReferenceSystem(org.opengis.referencing.crs.CoordinateReferenceSystem)

Aggregations

BoundingBox (de.fhg.igd.geom.BoundingBox)20 GeoPosition (org.jdesktop.swingx.mapviewer.GeoPosition)11 ArrayList (java.util.ArrayList)8 Localizable (de.fhg.igd.geom.Localizable)6 IllegalGeoPositionException (org.jdesktop.swingx.mapviewer.IllegalGeoPositionException)6 Point2D (java.awt.geom.Point2D)5 Area (de.fhg.igd.mapviewer.marker.area.Area)4 Point (java.awt.Point)4 HashSet (java.util.HashSet)4 Geometry (com.vividsolutions.jts.geom.Geometry)3 Rectangle (java.awt.Rectangle)3 SelectableWaypoint (de.fhg.igd.mapviewer.waypoints.SelectableWaypoint)2 InstanceReference (eu.esdihumboldt.hale.common.instance.model.InstanceReference)2 AbstractInstancePainter (eu.esdihumboldt.hale.ui.views.styledmap.painter.AbstractInstancePainter)2 CRSConverter (eu.esdihumboldt.hale.ui.views.styledmap.util.CRSConverter)2 Graphics2D (java.awt.Graphics2D)2 BufferedImage (java.awt.image.BufferedImage)2 PixelConverter (org.jdesktop.swingx.mapviewer.PixelConverter)2 GeometryCollection (com.vividsolutions.jts.geom.GeometryCollection)1 LineString (com.vividsolutions.jts.geom.LineString)1