Search in sources :

Example 1 with Candidate

use of org.geotoolkit.display2d.style.labeling.candidate.Candidate in project geotoolkit by Geomatys.

the class LinearLabelCandidateRenderer method generateCandidat.

@Override
public Candidate[] generateCandidat(final LinearLabelDescriptor descriptor) {
    try {
        final Shape[] shapes = descriptor.getGeometry().getDisplayShape();
        final Candidate[] candidates = new Candidate[shapes.length];
        for (int i = 0; i < shapes.length; i++) {
            candidates[i] = new LinearCandidate(descriptor, shapes[i]);
        }
        return candidates;
    } catch (TransformException ex) {
        Logger.getLogger("org.geotoolkit.display2d.style.labeling.decimate").log(Level.WARNING, null, ex);
    }
    return null;
}
Also used : Candidate(org.geotoolkit.display2d.style.labeling.candidate.Candidate) LinearCandidate(org.geotoolkit.display2d.style.labeling.candidate.LinearCandidate) LinearCandidate(org.geotoolkit.display2d.style.labeling.candidate.LinearCandidate) Shape(java.awt.Shape) TransformException(org.opengis.referencing.operation.TransformException)

Example 2 with Candidate

use of org.geotoolkit.display2d.style.labeling.candidate.Candidate in project geotoolkit by Geomatys.

the class SimulatedAnnealing method simulate.

public static Set<Candidate> simulate(final List<Candidate> cdts, double temperature, final double coolDown) {
    final Map<Candidate, Point> candidates = new HashMap<Candidate, Point>();
    for (Candidate cdt : cdts) {
        candidates.put(cdt, new Point((int) Math.floor(Math.random() * temperature - temperature / 2), (int) Math.floor(Math.random() * temperature - temperature / 2)));
    }
    // calculate the cost without any changes
    for (Candidate c : candidates.keySet()) {
        Point p = candidates.get(c);
        c.setCost(solutionCost(c, p, candidates));
    }
    // double bestSolutionCost = solutionCost(candidates);
    int sameResult = 0;
    int count = 0;
    // when we reach 10 times the same result, that means we haven't find anything better
    while (sameResult < 10) {
        System.out.println(count++ + " " + sameResult);
        boolean change = false;
        for (Candidate c : candidates.keySet()) {
            if (!(c instanceof PointCandidate))
                continue;
            Point p = candidates.get(c);
            // TODO find the best local solution using label intersecting this label
            boolean better = findBestLocalCombinaison((PointCandidate) c, p, candidates, temperature);
            if (better) {
                System.out.println("found better");
                change = true;
            }
        }
        sameResult = (change) ? 0 : sameResult + 1;
        // This approach of a global solution cost to much CPU,
        // we must find a way to make a local area best solution
        // // See if this improved the global solution
        // double solutionCost = solutionCost(candidates);
        // if (solutionCost < bestSolutionCost) {
        // bestSolutionCost = solutionCost;
        // 
        // //solution is better, change the candidate displacements
        // for(Candidate c : candidates.keySet()){
        // Point p = candidates.get(c);
        // if(c instanceof PointCandidate){
        // PointCandidate pc = (PointCandidate) c;
        // pc.x += pc.correctionX;
        // pc.y += pc.correctionY;
        // pc.correctionX = 0;
        // pc.correctionY = 0;
        // }
        // }
        // 
        // sameResult = 0;
        // } else {
        // sameResult++;
        // }
        // reduce temperature
        temperature = coolDown * temperature;
    }
    for (Candidate c : candidates.keySet()) {
        Point p = candidates.get(c);
        if (c instanceof PointCandidate) {
            PointCandidate pc = (PointCandidate) c;
            pc.correctionX = p.x;
            pc.correctionY = p.y;
        }
    }
    return candidates.keySet();
}
Also used : Candidate(org.geotoolkit.display2d.style.labeling.candidate.Candidate) PointCandidate(org.geotoolkit.display2d.style.labeling.candidate.PointCandidate) HashMap(java.util.HashMap) PointCandidate(org.geotoolkit.display2d.style.labeling.candidate.PointCandidate) Point(java.awt.Point) Point(java.awt.Point)

Example 3 with Candidate

use of org.geotoolkit.display2d.style.labeling.candidate.Candidate in project geotoolkit by Geomatys.

the class SimulatedAnnealing method solutionCost.

private static int solutionCost(final Map<? extends Candidate, Point> candidates) {
    int d = 0;
    for (Candidate c : candidates.keySet()) {
        Point p = candidates.get(c);
        d += solutionCost(c, p, candidates);
    }
    return d;
}
Also used : Candidate(org.geotoolkit.display2d.style.labeling.candidate.Candidate) PointCandidate(org.geotoolkit.display2d.style.labeling.candidate.PointCandidate) Point(java.awt.Point) Point(java.awt.Point)

Example 4 with Candidate

use of org.geotoolkit.display2d.style.labeling.candidate.Candidate in project geotoolkit by Geomatys.

the class SimulatedAnnealing method solutionLocalCost.

private static int solutionLocalCost(final Map<? extends Candidate, Point> localCandidates, final Map<? extends Candidate, Point> candidates) {
    int d = 0;
    for (Candidate c : localCandidates.keySet()) {
        Point p = localCandidates.get(c);
        d += solutionCost(c, p, candidates);
    }
    return d;
}
Also used : Candidate(org.geotoolkit.display2d.style.labeling.candidate.Candidate) PointCandidate(org.geotoolkit.display2d.style.labeling.candidate.PointCandidate) Point(java.awt.Point) Point(java.awt.Point)

Example 5 with Candidate

use of org.geotoolkit.display2d.style.labeling.candidate.Candidate in project geotoolkit by Geomatys.

the class DecimationLabelRenderer method portrayLabels.

/**
 * {@inheritDoc }
 */
@Override
public boolean portrayLabels() {
    final Graphics2D g2 = context.getGraphics();
    // enable antialiasing for labels
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    // paint the remaining candidates
    for (Candidate candidate : candidates) {
        if (candidate instanceof PointCandidate) {
            pointRenderer.render(candidate);
        } else if (candidate instanceof LinearCandidate) {
            LinearRenderer.render(candidate);
        }
    }
    layers.clear();
    return !candidates.isEmpty();
}
Also used : Candidate(org.geotoolkit.display2d.style.labeling.candidate.Candidate) PointCandidate(org.geotoolkit.display2d.style.labeling.candidate.PointCandidate) LinearCandidate(org.geotoolkit.display2d.style.labeling.candidate.LinearCandidate) LinearCandidate(org.geotoolkit.display2d.style.labeling.candidate.LinearCandidate) PointCandidate(org.geotoolkit.display2d.style.labeling.candidate.PointCandidate) Graphics2D(java.awt.Graphics2D)

Aggregations

Candidate (org.geotoolkit.display2d.style.labeling.candidate.Candidate)8 PointCandidate (org.geotoolkit.display2d.style.labeling.candidate.PointCandidate)7 Point (java.awt.Point)4 LinearCandidate (org.geotoolkit.display2d.style.labeling.candidate.LinearCandidate)3 Graphics2D (java.awt.Graphics2D)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 TransformException (org.opengis.referencing.operation.TransformException)2 FontMetrics (java.awt.FontMetrics)1 Shape (java.awt.Shape)1 LabelDescriptor (org.geotoolkit.display2d.style.labeling.LabelDescriptor)1 LabelLayer (org.geotoolkit.display2d.style.labeling.LabelLayer)1 LinearLabelDescriptor (org.geotoolkit.display2d.style.labeling.LinearLabelDescriptor)1 PointLabelDescriptor (org.geotoolkit.display2d.style.labeling.PointLabelDescriptor)1 Coordinate (org.locationtech.jts.geom.Coordinate)1 Geometry (org.locationtech.jts.geom.Geometry)1 Point (org.locationtech.jts.geom.Point)1