private void check2PointsMinimum() { if (getNumPoints() == 2) { throw new IllegalStateException("gradation curve must at least have 2 points"); } }
public Point[] getPoints() { Point[] points = new Point[getNumPoints()]; for (int i = 0; i < getNumPoints(); i++) { points[i] = getPointAt(i); } return points; }
public void setNumPoints(int numPoints) { while (getNumPoints() < numPoints) { addPoint(new Point(getMaxDisplaySample() + 1.0, Color.BLACK)); } while (getNumPoints() > numPoints) { removePointAt(getNumPoints() - 1); } }
private static void alignNumPoints(ColorPaletteDef sourceCPD, ColorPaletteDef targetCPD) { int deltaNumPoints = targetCPD.getNumPoints() - sourceCPD.getNumPoints(); if (deltaNumPoints < 0) { for (; deltaNumPoints != 0; deltaNumPoints++) { targetCPD.insertPointAfter(0, new ColorPaletteDef.Point()); } } else if (deltaNumPoints > 0) { for (; deltaNumPoints != 0; deltaNumPoints--) { targetCPD.removePointAt(1); } } }
@Override public int getSliderCount() { return getImageInfo().getColorPaletteDef().getNumPoints(); }
private int getNumGradationCurvePoints() { return getImageInfo().getColorPaletteDef().getNumPoints(); }
@Override public int getRowCount() { if (getImageInfo() == null) { return 0; } return getImageInfo().getColorPaletteDef().getNumPoints(); }
public int getRowCount() { if (getImageInfo() == null) { return 0; } return getImageInfo().getColorPaletteDef().getNumPoints(); }
/** * Sets the colours of the colour palette of this image info. * * @param colors the new colours */ public void setColors(Color[] colors) { ColorPaletteDef cpd = getColorPaletteDef(); int numPoints = cpd.getNumPoints(); for (int i = 0; i < numPoints; i++) { ColorPaletteDef.Point point = cpd.getPointAt(i); point.setColor(colors[i % colors.length]); } }
private Color computeColor(final double sample) { for (int i = 0; i < getNumPoints() - 1; i++) { final Point p1 = getPointAt(i); final Point p2 = getPointAt(i + 1); final double sample1 = p1.getSample(); final double sample2 = p2.getSample(); final Color color1 = p1.getColor(); final Color color2 = p2.getColor(); if (sample >= sample1 && sample <= sample2) { if (discrete) { return color1; } else { return computeColor(sample, sample1, sample2, color1, color2); } } } return Color.BLACK; }
private static PlanarImage createByteIndexedImage(RasterDataNode raster, RenderedImage sourceImage, ImageInfo imageInfo) { ColorPaletteDef colorPaletteDef = imageInfo.getColorPaletteDef(); final double minSample = colorPaletteDef.getMinDisplaySample(); final double maxSample = colorPaletteDef.getMaxDisplaySample(); if (isClassificationBand(raster)) { final IntMap sampleColorIndexMap = new IntMap((int) minSample - 1, 4098); final ColorPaletteDef.Point[] points = colorPaletteDef.getPoints(); for (int colorIndex = 0; colorIndex < points.length; colorIndex++) { sampleColorIndexMap.putValue((int) getSample(points[colorIndex]), colorIndex); } final int undefinedIndex = colorPaletteDef.getNumPoints(); return createIndexedImage(sourceImage, sampleColorIndexMap, undefinedIndex); } else { return createByteIndexedImage(raster, sourceImage, minSample, maxSample, 1.0); } }
final ColorPaletteDef cpd = imageInfo.getColorPaletteDef(); Debug.assertNotNull(cpd); Debug.assertTrue(cpd.getNumPoints() >= 2); final Color[] colorPalette = new Color[numColors]; int pointIndex = 0; final int maxPointIndex = cpd.getNumPoints() - 2; BorderSamplesAndColors boSaCo = getBorderSamplesAndColors(imageInfo, pointIndex, null); for (int i = 0; i < numColors - 1; i++) {
public static Color computeColor(ImageInfo imageInfo, Double rasterValue) { final ColorPaletteDef cpd = imageInfo.getColorPaletteDef(); if (rasterValue <= cpd.getMinDisplaySample()) { return cpd.getFirstPoint().getColor(); } else if (rasterValue >= cpd.getMaxDisplaySample()) { return cpd.getLastPoint().getColor(); } else { BorderSamplesAndColors boSaCo = new BorderSamplesAndColors(); final boolean logScaled = imageInfo.isLogScaled(); if (logScaled) { rasterValue = Stx.LOG10_SCALING.scale(rasterValue); } for (int i = 0; i < cpd.getNumPoints() - 1; i++) { boSaCo = getBorderSamplesAndColors(imageInfo, i, boSaCo); if (rasterValue >= boSaCo.sample1 && rasterValue <= boSaCo.sample2) { return computeColor(rasterValue, boSaCo); } } } return Color.black; }
private static void transferPoints(ColorPaletteDef sourceCPD, double minSample, double maxSample, boolean autoDistribute, ColorPaletteDef targetCPD) { if (autoDistribute || sourceCPD.isAutoDistribute()) { alignNumPoints(sourceCPD, targetCPD); double minDisplaySample = sourceCPD.getMinDisplaySample(); double maxDisplaySample = sourceCPD.getMaxDisplaySample(); double delta1 = (maxSample > minSample) ? maxSample - minSample : 1.0; double delta2 = (maxDisplaySample > minDisplaySample) ? maxDisplaySample - minDisplaySample : 1.0; double b = delta1 / delta2; double a = minSample - minDisplaySample * b; for (int i = 0; i < sourceCPD.getNumPoints(); i++) { targetCPD.getPointAt(i).setSample(a + b * sourceCPD.getPointAt(i).getSample()); targetCPD.getPointAt(i).setColor(sourceCPD.getPointAt(i).getColor()); targetCPD.getPointAt(i).setLabel(sourceCPD.getPointAt(i).getLabel()); } } else { targetCPD.setPoints(sourceCPD.getPoints().clone()); } }
ColorPaletteDef cpd = new ColorPaletteDef(-1.0, 1.0); assertEquals(256, cpd.getNumColors()); assertEquals(3, cpd.getNumPoints()); assertEquals(-1.0, cpd.getPointAt(0).getSample(), 1e-10); assertEquals(+0.0, cpd.getPointAt(1).getSample(), 1e-10); assertEquals(3, cpd.getNumPoints()); assertEquals(-1.0, cpd.getPointAt(0).getSample(), 1e-10); assertEquals(+0.5, cpd.getPointAt(1).getSample(), 1e-10); new Point(600, Color.WHITE) }); assertEquals(4, cpd.getNumPoints()); assertEquals(256, cpd.getNumColors()); new Point(600, Color.WHITE) }, 512); assertEquals(4, cpd.getNumPoints()); assertEquals(512, cpd.getNumColors());