00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
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
00068
00069
00070
00071
00072
00073
00074
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
00107 return 0;
00108 }
00109
00110
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
00125 return 0;
00126 }
00127
00128
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
00142 color = colorMap.getColor(colMin - 1);
00143 } else {
00144
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
00179 color = colorMap.getColor(colMax - 1);
00180 } else {
00181
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
00197 double colorIndex = ((getSize()) * (value - boundMin) / (boundMax - boundMin)) + OFFSET;
00198 applyTexCoord(gl, colorIndex);
00199 }
00200
00201 }