FecColorMap.java

Go to the documentation of this file.
00001 /*
00002  * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
00003  * Copyright (C) 2008 - INRIA - Jean-Baptiste Silvy
00004  * desc : Special colormap used by fec objects 
00005  * 
00006  * This file must be used under the terms of the CeCILL.
00007  * This source file is licensed as described in the file COPYING, which
00008  * you should have received as part of this distribution.  The terms
00009  * are also available at    
00010  * http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
00011  *
00012  */
00013 
00014 
00015 package org.scilab.modules.renderer.fecDrawing;
00016 
00017 import javax.media.opengl.GL;
00018 
00019 import org.scilab.modules.renderer.utils.ColorMap;
00020 import org.scilab.modules.renderer.utils.TexturedColorMap;
00021 
00022 
00027 public class FecColorMap extends TexturedColorMap {
00028 
00029         private static final double OFFSET = 0.5;
00030         
00031         private double boundMin;
00032         private double boundMax;
00033         
00037         private ColorMap colorMap;
00038         
00043         public FecColorMap(ColorMap colMap) {
00044                 super();
00045                 colorMap = colMap;
00046                 boundMin = 0.0;
00047                 boundMax = 0.0;
00048         }
00049         
00064         public void setFecWeirdValues(double zMin, double zMax, int colMin, int colMax, int colOutLow, int colOutUp) {
00065                 int useCMapSize = colMax - colMin + 1;
00066                 
00067                 // schema of the color map we will create
00068                 // between zMin and zMax we will use the part of the colormap
00069                 // which is between colMin and colMax so its length is colMax - colMin
00070                 // to find lower size and upper size, we just use proportionality
00071                 //
00072                 //    <-- lowerSize --> <-- colMax - colMin --> <-- upperSize -->
00073                 //    |----------------|-----------------------|-----------------|
00074                 // minBoud            zmin                    zMax             maxBound
00075                 //
00076                 int upperSize = computeUpperSizeLength(useCMapSize, zMin, zMax, boundMin);
00077                 int lowerSize = computeLowerSizeLength(useCMapSize, zMin, zMax, boundMax);
00078                 
00079                 setSize(useCMapSize + upperSize + lowerSize);
00080                 
00081                 fillLowerPart(lowerSize, colOutLow, colMin);
00082                 fillMiddlePart(lowerSize, colMin, colMax);
00083                 fillUpperPart(lowerSize + useCMapSize, upperSize, colOutUp, colMax);
00084         }
00085         
00091         public void setRealBounds(double min, double max) {
00092                 boundMin = min;
00093                 boundMax = max;
00094         }
00095         
00104         protected int computeLowerSizeLength(int centerSize, double zMin, double zMax, double boundMin) {
00105                 if (boundMin >= zMin) {
00106                         // no lower part needed
00107                         return 0;
00108                 }
00109                 
00110                 // ceil to be sure to enter the colormap
00111                 return (int) Math.ceil(centerSize * (zMin - boundMin) / (zMax - zMin));
00112         }
00113         
00122         protected int computeUpperSizeLength(int centerSize, double zMin, double zMax, double boundMax) {
00123                 if (boundMax <= zMax) {
00124                         // no lower part needed
00125                         return 0;
00126                 }
00127                 
00128                 // ceil to be sure to enter the colormap
00129                 return (int) Math.ceil(centerSize * (boundMax - zMax) / (zMax - zMin));
00130         }
00131         
00138         protected void fillLowerPart(int lowerSize, int colOutLow, int colMin) {
00139                 double[] color = null;
00140                 if (colOutLow <= 0) {
00141                         // use colMin as color
00142                         color = colorMap.getColor(colMin - 1);
00143                 } else {
00144                         // use colOutLow as color
00145                         color = colorMap.getColor(colOutLow - 1);
00146                 }
00147                 for (int i = 0; i < lowerSize; i++) {
00148                         setColor(i, color);
00149                 }
00150                 
00151         }
00152         
00159         protected void fillMiddlePart(int colMapStart, int colMin, int colMax) {
00160                 int endIndex = colMapStart + colMax - colMin + 1;
00161                 for (int i = colMapStart; i < endIndex; i++) {
00162                         double[] color = colorMap.getColor(i + colMin - 1 - colMapStart);
00163                         setColor(i, color);
00164                 }
00165                 
00166         }
00167         
00175         protected void fillUpperPart(int colMapStart, int upperSize, int colOutUp, int colMax) {
00176                 double[] color = null;
00177                 if (colOutUp <= 0) {
00178                         // use colMax as color
00179                         color = colorMap.getColor(colMax - 1);
00180                 } else {
00181                         // use colOutLow as color
00182                         color = colorMap.getColor(colOutUp - 1);
00183                 }
00184                 for (int i = colMapStart; i < colMapStart + upperSize; i++) {
00185                         setColor(i, color);
00186                 }
00187                 
00188         }
00189         
00195         public void useValue(GL gl, double value) {
00196                 // experimental value
00197                 double colorIndex = ((getSize()) * (value - boundMin) / (boundMax - boundMin)) + OFFSET;
00198                 applyTexCoord(gl, colorIndex);
00199         }
00200         
00201 }

Generated on Tue Sep 9 17:48:30 2008 for Scilab [trunk] by  doxygen 1.5.5