Search in sources :

Example 6 with Polygon

use of de.lmu.ifi.dbs.elki.data.spatial.Polygon in project elki by elki-project.

the class SweepHullDelaunay2D method getHull.

/**
 * Get the convex hull only.
 *
 * Note: if you also want the Delaunay Triangulation, you should get that
 * first!
 *
 * @return Convex hull
 */
public Polygon getHull() {
    if (hull == null) {
        run(true);
    }
    DoubleMinMax minmaxX = new DoubleMinMax();
    DoubleMinMax minmaxY = new DoubleMinMax();
    List<double[]> hullp = new ArrayList<>(hull.size());
    for (IntIntPair pair : hull) {
        double[] v = points.get(pair.first);
        hullp.add(v);
        minmaxX.put(v[0]);
        minmaxY.put(v[1]);
    }
    return new Polygon(hullp, minmaxX.getMin(), minmaxX.getMax(), minmaxY.getMin(), minmaxY.getMax());
}
Also used : DoubleMinMax(de.lmu.ifi.dbs.elki.math.DoubleMinMax) ArrayList(java.util.ArrayList) Polygon(de.lmu.ifi.dbs.elki.data.spatial.Polygon) IntIntPair(de.lmu.ifi.dbs.elki.utilities.pairs.IntIntPair)

Example 7 with Polygon

use of de.lmu.ifi.dbs.elki.data.spatial.Polygon in project elki by elki-project.

the class SimplePolygonParser method parseLine.

/**
 * Parse a single line.
 *
 * @return {@code true} if the line was read successful.
 */
private boolean parseLine() {
    cureid = null;
    curpoly = null;
    curlbl = null;
    polys.clear();
    coords.clear();
    labels.clear();
    Matcher m = COORD.matcher(reader.getBuffer());
    for (; /* initialized by nextLineExceptComments */
    tokenizer.valid(); tokenizer.advance()) {
        m.region(tokenizer.getStart(), tokenizer.getEnd());
        if (m.find()) {
            try {
                double c1 = ParseUtil.parseDouble(m.group(1));
                double c2 = ParseUtil.parseDouble(m.group(2));
                if (m.group(3) != null) {
                    double c3 = ParseUtil.parseDouble(m.group(3));
                    coords.add(new double[] { c1, c2, c3 });
                } else {
                    coords.add(new double[] { c1, c2 });
                }
                continue;
            } catch (NumberFormatException e) {
                LOG.warning("Looked like a coordinate pair but didn't parse: " + tokenizer.getSubstring());
            }
        }
        // Match polygon separator:
        // FIXME: Avoid unnecessary subSequence call.
        final int len = tokenizer.getEnd() - tokenizer.getStart();
        if (// 
        POLYGON_SEPARATOR.length() == len && reader.getBuffer().subSequence(tokenizer.getStart(), tokenizer.getEnd()).equals(POLYGON_SEPARATOR)) {
            if (!coords.isEmpty()) {
                polys.add(new Polygon(new ArrayList<>(coords)));
            }
            continue;
        }
        String cur = tokenizer.getSubstring();
        // First label will become the External ID
        if (cureid == null) {
            cureid = new ExternalID(cur);
        } else {
            labels.add(cur);
        }
    }
    // Complete polygon
    if (!coords.isEmpty()) {
        polys.add(new Polygon(coords));
    }
    curpoly = new PolygonsObject(polys);
    curlbl = (haslabels || !labels.isEmpty()) ? LabelList.make(labels) : null;
    return true;
}
Also used : Matcher(java.util.regex.Matcher) ExternalID(de.lmu.ifi.dbs.elki.data.ExternalID) ArrayList(java.util.ArrayList) Polygon(de.lmu.ifi.dbs.elki.data.spatial.Polygon) PolygonsObject(de.lmu.ifi.dbs.elki.data.spatial.PolygonsObject)

Aggregations

Polygon (de.lmu.ifi.dbs.elki.data.spatial.Polygon)7 ArrayList (java.util.ArrayList)4 PolygonsObject (de.lmu.ifi.dbs.elki.data.spatial.PolygonsObject)3 Cluster (de.lmu.ifi.dbs.elki.data.Cluster)2 Model (de.lmu.ifi.dbs.elki.data.model.Model)2 ArrayModifiableDBIDs (de.lmu.ifi.dbs.elki.database.ids.ArrayModifiableDBIDs)2 DBIDIter (de.lmu.ifi.dbs.elki.database.ids.DBIDIter)2 DoubleObjPair (de.lmu.ifi.dbs.elki.utilities.pairs.DoubleObjPair)2 Color (java.awt.Color)2 ExternalID (de.lmu.ifi.dbs.elki.data.ExternalID)1 NumberVector (de.lmu.ifi.dbs.elki.data.NumberVector)1 DBIDs (de.lmu.ifi.dbs.elki.database.ids.DBIDs)1 DoubleRelation (de.lmu.ifi.dbs.elki.database.relation.DoubleRelation)1 Relation (de.lmu.ifi.dbs.elki.database.relation.Relation)1 DoubleMinMax (de.lmu.ifi.dbs.elki.math.DoubleMinMax)1 GrahamScanConvexHull2D (de.lmu.ifi.dbs.elki.math.geometry.GrahamScanConvexHull2D)1 ArrayListIter (de.lmu.ifi.dbs.elki.utilities.datastructures.iterator.ArrayListIter)1 IntIntPair (de.lmu.ifi.dbs.elki.utilities.pairs.IntIntPair)1 HashMap (java.util.HashMap)1 Iterator (java.util.Iterator)1