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;
}
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();
}
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;
}
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;
}
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();
}
Aggregations