001 //$HeadURL: https://sushibar/svn/deegree/base/trunk/resources/eclipse/svn_classfile_header_template.xml $ 002 /*---------------- FILE HEADER ------------------------------------------ 003 This file is part of deegree. 004 Copyright (C) 2001-2008 by: 005 Department of Geography, University of Bonn 006 http://www.giub.uni-bonn.de/deegree/ 007 lat/lon GmbH 008 http://www.lat-lon.de 009 010 This library is free software; you can redistribute it and/or 011 modify it under the terms of the GNU Lesser General Public 012 License as published by the Free Software Foundation; either 013 version 2.1 of the License, or (at your option) any later version. 014 This library is distributed in the hope that it will be useful, 015 but WITHOUT ANY WARRANTY; without even the implied warranty of 016 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 017 Lesser General Public License for more details. 018 You should have received a copy of the GNU Lesser General Public 019 License along with this library; if not, write to the Free Software 020 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 021 Contact: 022 023 Andreas Poth 024 lat/lon GmbH 025 Aennchenstr. 19 026 53177 Bonn 027 Germany 028 E-Mail: poth@lat-lon.de 029 030 Prof. Dr. Klaus Greve 031 Department of Geography 032 University of Bonn 033 Meckenheimer Allee 166 034 53115 Bonn 035 Germany 036 E-Mail: greve@giub.uni-bonn.de 037 ---------------------------------------------------------------------------*/ 038 039 package org.deegree.graphics.sld; 040 041 import java.util.List; 042 043 import org.deegree.graphics.sld.SLDFactory.Method; 044 import org.deegree.graphics.sld.SLDFactory.Mode; 045 046 /** 047 * <code>Interpolate</code> encapsulates data from the Symbology Encoding Schema 048 * (InterpolateType). 049 * 050 * @author <a href="mailto:schmitz@lat-lon.de">Andreas Schmitz</a> 051 * @author last edited by: $Author:$ 052 * 053 * @version $Revision:$, $Date:$ 054 */ 055 public class Interpolate { 056 057 private String fallbackValue; 058 059 private ParameterValueType lookupValue; 060 061 private Mode mode; 062 063 private Method method; 064 065 private List<InterpolationPoint> points; 066 067 /** 068 * @param fallbackValue 069 */ 070 public Interpolate( String fallbackValue ) { 071 this.fallbackValue = fallbackValue; 072 } 073 074 /** 075 * @param lookupValue 076 */ 077 public void setLookupValue( ParameterValueType lookupValue ) { 078 this.lookupValue = lookupValue; 079 } 080 081 /** 082 * @return the fallbackValue 083 */ 084 public String getFallbackValue() { 085 return fallbackValue; 086 } 087 088 /** 089 * @return the lookupValue 090 */ 091 public ParameterValueType getLookupValue() { 092 return lookupValue; 093 } 094 095 /** 096 * @return the method 097 */ 098 public Method getMethod() { 099 return method; 100 } 101 102 /** 103 * @return the mode 104 */ 105 public Mode getMode() { 106 return mode; 107 } 108 109 /** 110 * @param mode 111 */ 112 public void setMode( Mode mode ) { 113 this.mode = mode; 114 } 115 116 /** 117 * @param method 118 */ 119 public void setMethod( Method method ) { 120 this.method = method; 121 } 122 123 /** 124 * @param d 125 * @param opac 126 * the default opacity if none has been set 127 * @return the color value as int 128 */ 129 public int interpolate( float d, int opac ) { 130 int opacity = opac >> 24; 131 132 InterpolationPoint p = points.get( 0 ); 133 int r = p.redValue, g = p.greenValue, b = p.blueValue, o = p.opacitySet ? p.opacity : opacity; 134 double data = p.data; 135 if ( d < p.data ) { 136 return ( o << 24 ) + ( r << 16 ) + ( g << 8 ) + b; 137 } 138 139 for ( int i = 1; i < points.size(); ++i ) { 140 p = points.get( i ); 141 if ( p.data > d ) { 142 double f = ( p.data - d ) / ( p.data - data ); 143 return ( ( (int) ( f * ( p.opacitySet ? p.opacity : opacity - o ) + o ) ) << 24 ) 144 + ( ( (int) ( f * ( p.redValue - r ) + r ) ) << 16 ) 145 + ( ( (int) ( f * ( p.greenValue - g ) + g ) ) << 8 ) 146 + ( (int) ( ( f * ( p.blueValue - b ) + b ) ) ); 147 } 148 r = p.redValue; 149 g = p.greenValue; 150 b = p.blueValue; 151 o = p.opacitySet ? p.opacity : opacity; 152 data = p.data; 153 } 154 155 return ( o << 24 ) + ( r << 16 ) + ( g << 8 ) + b; 156 } 157 158 /** 159 * @param points 160 */ 161 public void setInterpolationPoints( List<InterpolationPoint> points ) { 162 this.points = points; 163 } 164 165 }