ingo@1115: /* ingo@1115: * Copyright (c) 2010 by Intevation GmbH ingo@1115: * ingo@1115: * This program is free software under the LGPL (>=v2.1) ingo@1115: * Read the file LGPL.txt coming with the software for details ingo@1115: * or visit http://www.gnu.org/licenses/ if it does not exist. ingo@1115: */ ingo@1115: sascha@448: package de.intevation.gnv.raster; sascha@448: sascha@465: /** sascha@802: * Generates label attributes for iso lines. It takes the sascha@802: * neighboring palette ranges and calculates the mid point sascha@802: * between these two ranges. sascha@780: * @author Sascha L. Teichmann sascha@465: */ sascha@448: public class IsoAttributeGenerator sascha@465: implements IsoProducer.AttributeGenerator sascha@448: { sascha@802: /** sascha@802: * The palette where to look for the ranges. sascha@802: */ sascha@448: protected Palette palette; sascha@448: sascha@802: /** sascha@802: * Default constructor. sascha@802: */ sascha@448: public IsoAttributeGenerator() { sascha@448: } sascha@448: sascha@802: /** sascha@802: * Constructor to create an IsoAttributeGenerator with sascha@802: * a given lookup palette. sascha@802: * @param palette The palette. sascha@802: */ sascha@448: public IsoAttributeGenerator(Palette palette) { sascha@448: this.palette = palette; sascha@448: } sascha@448: sascha@448: public Object generateAttribute(int neighbor1, int neighbor2) { sascha@448: Palette.Entry e1 = palette.getEntryByIndex(neighbor1); sascha@448: Palette.Entry e2 = palette.getEntryByIndex(neighbor2); sascha@448: sascha@448: if (e1 == null || e2 == null) { sascha@448: return null; sascha@448: } sascha@448: sascha@448: double e1t = e1.getFrom(); sascha@448: double e2f = e2.getTo(); sascha@448: sascha@448: return Double.valueOf(e2f >= e1t sascha@448: ? 0.5d*(e1t+e2f) sascha@448: : 0.5d*(e2.getTo()+e1.getFrom())); sascha@448: } sascha@448: } sascha@798: // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :