/** * Transforms the figure. * * @param tx the transformation. */ public void transform(AffineTransform tx) { if (TRANSFORM.get(this) != null || tx.getType() != (tx.getType() & AffineTransform.TYPE_TRANSLATION)) { if (TRANSFORM.get(this) == null) { TRANSFORM.basicSet(this, (AffineTransform) tx.clone()); } else { AffineTransform t = TRANSFORM.getClone(this); t.preConcatenate(tx); TRANSFORM.basicSet(this, t); } } else { for (int i = 0; i < coordinates.length; i++) { tx.transform(coordinates[i], coordinates[i]); } if (FILL_GRADIENT.get(this) != null && !FILL_GRADIENT.get(this).isRelativeToFigureBounds()) { Gradient g = FILL_GRADIENT.getClone(this); g.transform(tx); FILL_GRADIENT.basicSet(this, g); } if (STROKE_GRADIENT.get(this) != null && !STROKE_GRADIENT.get(this).isRelativeToFigureBounds()) { Gradient g = STROKE_GRADIENT.getClone(this); g.transform(tx); STROKE_GRADIENT.basicSet(this, g); } } invalidate(); }
/** * Returns a noise value by interpolating between two values based on the floating point part of * the input. * * @param x Value to derive the noise from. * @param y Value to derive the noise from. * @param z Value to derive the noise from. * @return Noise value */ public double noise3(double x, double y, double z) { int ix = (int) Math.floor(x); int iy = (int) Math.floor(y); int iz = (int) Math.floor(z); double fy = y - iy; double fx = x - ix; double fz = z - iz; fx = Gradient.cosInterpolate(0, 1, fx); fy = Gradient.cosInterpolate(0, 1, fy); fz = Gradient.cosInterpolate(0, 1, fz); double v1 = rawNoise3(ix, iy, iz); double v2 = rawNoise3(ix + 1, iy, iz); double v3 = rawNoise3(ix, iy + 1, iz); double v4 = rawNoise3(ix + 1, iy + 1, iz); double v5 = rawNoise3(ix, iy, iz + 1); double v6 = rawNoise3(ix + 1, iy, iz + 1); double v7 = rawNoise3(ix, iy + 1, iz + 1); double v8 = rawNoise3(ix + 1, iy + 1, iz + 1); double i1 = Gradient.cosInterpolate(v1, v2, fx); double i2 = Gradient.cosInterpolate(v3, v4, fx); double i3 = Gradient.cosInterpolate(v5, v6, fx); double i4 = Gradient.cosInterpolate(v7, v8, fx); double j1 = Gradient.cosInterpolate(i1, i2, fy); double j2 = Gradient.cosInterpolate(i3, i4, fy); return Gradient.cosInterpolate(j1, j2, fz); }
public HeatMapFrame() throws Exception { super("Heat Map Frame"); double[][] data = HeatMap.generateRampTestData(); boolean useGraphicsYAxis = true; // you can use a pre-defined gradient: panel = new HeatMap(data, useGraphicsYAxis, Gradient.GRADIENT_BLUE_TO_RED); // or you can also make a custom gradient: Color[] gradientColors = new Color[] {Color.blue, Color.green, Color.yellow}; Color[] customGradient = Gradient.createMultiGradient(gradientColors, 500); panel.updateGradient(customGradient); // set miscelaneous settings panel.setDrawLegend(true); panel.setTitle("Height (m)"); panel.setDrawTitle(true); panel.setXAxisTitle("X-Distance (m)"); panel.setDrawXAxisTitle(true); panel.setYAxisTitle("Y-Distance (m)"); panel.setDrawYAxisTitle(true); panel.setCoordinateBounds(0, 6.28, 0, 6.28); panel.setDrawXTicks(true); panel.setDrawYTicks(true); panel.setColorForeground(Color.black); panel.setColorBackground(Color.white); this.getContentPane().add(panel); }
/** * Returns a noise value by interpolating between two values based on the floating point part of * the input. * * @param x Value to derive the noise from. * @param y Value to derive the noise from. * @return Noise value */ public double noise2(double x, double y) { int ix = (int) Math.floor(x); int iy = (int) Math.floor(y); double fy = y - iy; double fx = x - ix; double v1 = rawNoise2(ix, iy); double v2 = rawNoise2(ix + 1, iy); double v3 = rawNoise2(ix, iy + 1); double v4 = rawNoise2(ix + 1, iy + 1); double i1 = Gradient.t32Interpolate(v1, v2, fx); double i2 = Gradient.t32Interpolate(v3, v4, fx); return Gradient.cosInterpolate(i1, i2, fy); }
public FilmFilter(float angle) { gradient = new GradientFilter(); gradient.Gradient = Gradient.Fade(); gradient.OriginAngleDegree = angle; saturationFx = new SaturationModifyFilter(); saturationFx.SaturationFactor = -0.6f; }
/** * Returns a noise value by interpolating between two values based on the floating point part of * the input. * * @param x Value to derive the noise from. * @return Noise value */ public double noise1(double x) { int ix = (int) Math.floor(x); double fx = x - ix; double v1 = rawNoise1(ix); double v2 = rawNoise1(ix + 1); return Gradient.cosInterpolate(v1, v2, fx); }
public GenericLivingEntity() { super(); Color color = new Color(0, 0, 0, 0.75f); this.addChildren( _bar = (Container) new GenericContainer( // Used for the bar, this.children with an index 1+ are // targets new GenericGradient() .setTopColor(color) .setBottomColor(color) .setPriority(RenderPriority.Highest), new GenericContainer( _health = (Gradient) new GenericGradient(), _armor = (Gradient) new GenericGradient()) .setMargin(1) .setPriority(RenderPriority.High), new GenericContainer( _face = (GenericFace) new GenericFace() .setVisible(MMOCore.config_show_player_faces) .setMargin(3, 0, 3, 3), _label = (Label) new GenericLabel() .setResize(true) .setFixed(true) .setMargin(3, 3, 1, 3)) .setLayout(ContainerType.HORIZONTAL)) .setLayout(ContainerType.OVERLAY) .setMaxHeight(def_height) .setMargin(0, 0, 1, 0)) .setAlign(WidgetAnchor.TOP_LEFT) .setMinWidth(def_width) // .setMaxWidth(def_width * 2) .setMaxHeight(def_height + 1); color = new Color(1f, 0, 0, 0.75f); _health.setTopColor(color).setBottomColor(color); color = new Color(0.75f, 0.75f, 0.75f, 0.75f); _armor.setTopColor(color).setBottomColor(color); }
@Override public Container updateLayout() { _armor.setWidth(old_armor_width); // cache for bandwidth _health.setWidth(old_health_width); // cache for bandwidth super.updateLayout(); old_armor_width = _armor.getWidth(); // cache for bandwidth old_health_width = _health.getWidth(); // cache for bandwidth _armor.setWidth((_armor.getContainer().getWidth() * armor) / 100).setDirty(true); _health.setWidth((_health.getContainer().getWidth() * health) / 100).setDirty(true); return this; }
protected void build() throws SVGException { super.build(); StyleAttribute sty = new StyleAttribute(); if (getPres(sty.setName("x1"))) { x1 = sty.getFloatValueWithUnits(); } if (getPres(sty.setName("y1"))) { y1 = sty.getFloatValueWithUnits(); } if (getPres(sty.setName("x2"))) { x2 = sty.getFloatValueWithUnits(); } if (getPres(sty.setName("y2"))) { y2 = sty.getFloatValueWithUnits(); } }
public Gradient gradientAt(Point point) { double[] ax = point.toArray(); double[] gradient = new double[n]; double sqrtSum = 0.0; double cosSum = 0.0; for (int i = 0; i < n; i++) { sqrtSum += ax[i] * ax[i]; cosSum += Math.cos(2 * Math.PI * ax[i]); } sqrtSum = Math.sqrt(sqrtSum); cosSum /= n; for (int i = 0; i < n; i++) gradient[i] = (2 * ax[i] * Math.exp(-0.1 * sqrtSum)) / sqrtSum + 0.5 * Math.exp(cosSum) * Math.PI * Math.sin(2 * Math.PI * ax[i]); return Gradient.valueOf(gradient); }
private Gradient doGradient(boolean isLinear, Attributes atts) { Gradient gradient = new Gradient(); gradient.id = getStringAttr("id", atts); gradient.isLinear = isLinear; if (isLinear) { gradient.x1 = getFloatAttr("x1", atts, 0f); gradient.x2 = getFloatAttr("x2", atts, 0f); gradient.y1 = getFloatAttr("y1", atts, 0f); gradient.y2 = getFloatAttr("y2", atts, 0f); } else { gradient.x = getFloatAttr("cx", atts, 0f); gradient.y = getFloatAttr("cy", atts, 0f); gradient.radius = getFloatAttr("r", atts, 0f); } String transform = getStringAttr("gradientTransform", atts); if (transform != null) { gradient.matrix = parseTransform(transform); } String xlink = getStringAttr("href", atts); if (xlink != null) { if (xlink.startsWith("#")) { xlink = xlink.substring(1); } gradient.xlink = xlink; } return gradient; }
public Gradient createChild(Gradient g) { Gradient child = new Gradient(); child.id = g.id; child.xlink = id; child.isLinear = g.isLinear; child.x1 = g.x1; child.x2 = g.x2; child.y1 = g.y1; child.y2 = g.y2; child.x = g.x; child.y = g.y; child.radius = g.radius; child.positions = positions; child.colors = colors; child.matrix = matrix; if (g.matrix != null) { if (matrix == null) { child.matrix = g.matrix; } else { Matrix m = new Matrix(matrix); m.preConcat(g.matrix); child.matrix = m; } } return child; }
@Override public void endElement(String namespaceURI, String localName, String qName) throws SAXException { if (localName.equals("svg")) { picture.endRecording(); } else if (localName.equals("linearGradient")) { if (gradient.id != null) { if (gradient.xlink != null) { Gradient parent = gradientRefMap.get(gradient.xlink); if (parent != null) { gradient = parent.createChild(gradient); } } int[] colors = new int[gradient.colors.size()]; for (int i = 0; i < colors.length; i++) { colors[i] = gradient.colors.get(i); } float[] positions = new float[gradient.positions.size()]; for (int i = 0; i < positions.length; i++) { positions[i] = gradient.positions.get(i); } LinearGradient g = new LinearGradient( gradient.x1, gradient.y1, gradient.x2, gradient.y2, colors, positions, Shader.TileMode.CLAMP); if (gradient.matrix != null) { g.setLocalMatrix(gradient.matrix); } gradientMap.put(gradient.id, g); gradientRefMap.put(gradient.id, gradient); } } else if (localName.equals("radialGradient")) { if (gradient.id != null) { if (gradient.xlink != null) { Gradient parent = gradientRefMap.get(gradient.xlink); if (parent != null) { gradient = parent.createChild(gradient); } } int[] colors = new int[gradient.colors.size()]; for (int i = 0; i < colors.length; i++) { colors[i] = gradient.colors.get(i); } float[] positions = new float[gradient.positions.size()]; for (int i = 0; i < positions.length; i++) { positions[i] = gradient.positions.get(i); } if (gradient.xlink != null) { Gradient parent = gradientRefMap.get(gradient.xlink); if (parent != null) { gradient = parent.createChild(gradient); } } RadialGradient g = new RadialGradient( gradient.x, gradient.y, gradient.radius, colors, positions, Shader.TileMode.CLAMP); if (gradient.matrix != null) { g.setLocalMatrix(gradient.matrix); } gradientMap.put(gradient.id, g); gradientRefMap.put(gradient.id, gradient); } } else if (localName.equals("g")) { if (boundsMode) { boundsMode = false; } // Break out of hidden mode if (hidden) { hiddenLevel--; // Util.debug("Hidden down: " + hiddenLevel); if (hiddenLevel == 0) { hidden = false; } } // Clear gradient map gradientMap.clear(); popTransform(); } }
@Override public boolean process() { /* 0. Instantiate tensor holder, and initialize cursors. */ long[] tensorDims = new long[input.numDimensions() + 1]; for (int i = 0; i < input.numDimensions(); i++) { tensorDims[i] = input.dimension(i); } tensorDims[input.numDimensions()] = 3; try { D = input.factory().imgFactory(new FloatType()).create(tensorDims, new FloatType()); } catch (IncompatibleTypeException e) { errorMessage = BASE_ERROR_MESSAGE + "Failed to create tensor holder:\n" + e.getMessage(); return false; } /* 1. Create a smoothed version of the input. */ Img<FloatType> smoothed = Gauss.toFloat(new double[] {sigma, sigma}, input); /* 2. Compute the gradient of the smoothed input, but only algon X & Y */ boolean[] doDimension = new boolean[input.numDimensions()]; doDimension[0] = true; doDimension[1] = true; Gradient<FloatType> gradientCalculator = new Gradient<FloatType>(smoothed, doDimension); gradientCalculator.process(); final Img<FloatType> gradient = gradientCalculator.getResult(); /* 3. Compute the structure tensor. */ final Img<FloatType> J = D.factory().create(D, new FloatType()); final int newDim = input.numDimensions(); final Vector<Chunk> chunks = SimpleMultiThreading.divideIntoChunks(input.size(), numThreads); Thread[] threads = SimpleMultiThreading.newThreads(numThreads); for (int i = 0; i < threads.length; i++) { final Chunk chunk = chunks.get(i); threads[i] = new Thread("" + BASE_ERROR_MESSAGE + "thread " + i) { @Override public void run() { float ux, uy; Cursor<T> cursor = input.localizingCursor(); RandomAccess<FloatType> grad_ra = gradient.randomAccess(); RandomAccess<FloatType> J_ra = J.randomAccess(); cursor.jumpFwd(chunk.getStartPosition()); for (long k = 0; k < chunk.getLoopSize(); k++) { cursor.fwd(); for (int i = 0; i < input.numDimensions(); i++) { grad_ra.setPosition(cursor.getLongPosition(i), i); J_ra.setPosition(cursor.getLongPosition(i), i); } grad_ra.setPosition(0, newDim); ux = grad_ra.get().get(); grad_ra.fwd(newDim); uy = grad_ra.get().get(); J_ra.setPosition(0, newDim); J_ra.get().set(ux * ux); J_ra.fwd(newDim); J_ra.get().set(ux * uy); J_ra.fwd(newDim); J_ra.get().set(uy * uy); } } }; } SimpleMultiThreading.startAndJoin(threads); /* 3.5 Smoooth the structure tensor. */ Gauss.inFloat(new double[] {rho, rho, 0}, J); /* 4. Construct Diffusion tensor. */ for (int i = 0; i < threads.length; i++) { final Chunk chunk = chunks.get(i); threads[i] = new Thread("" + BASE_ERROR_MESSAGE + "thread " + i) { @Override public void run() { Cursor<T> cursor = input.localizingCursor(); RandomAccess<FloatType> J_ra = J.randomAccess(); RandomAccess<FloatType> D_ra = D.randomAccess(); float Jxx, Jxy, Jyy; double tmp, v1x, v1y, v2x, v2y, mag, mu1, mu2, lambda1, lambda2, di; double newLambda1, newLambda2, Dxx, Dxy, Dyy; double scale; cursor.jumpFwd(chunk.getStartPosition()); for (long k = 0; k < chunk.getLoopSize(); k++) { cursor.fwd(); for (int j = 0; j < input.numDimensions(); j++) { D_ra.setPosition(cursor.getLongPosition(j), j); J_ra.setPosition(cursor.getLongPosition(j), j); } // Compute eigenvalues J_ra.setPosition(0, newDim); Jxx = J_ra.get().get(); J_ra.fwd(newDim); Jxy = J_ra.get().get(); J_ra.fwd(newDim); Jyy = J_ra.get().get(); tmp = Math.sqrt((Jxx - Jyy) * (Jxx - Jyy) + 4 * Jxy * Jxy); v2x = 2 * Jxy; v2y = Jyy - Jxx + tmp; mag = Math.sqrt(v2x * v2x + v2y * v2y); v2x /= mag; v2y /= mag; v1x = -v2y; v1y = v2x; mu1 = 0.5 * (Jxx + Jyy + tmp); mu2 = 0.5 * (Jxx + Jyy - tmp); // Large one in abs values must be the 2nd if (Math.abs(mu2) > Math.abs(mu1)) { lambda1 = mu1; lambda2 = mu2; } else { lambda1 = mu2; lambda2 = mu1; } di = lambda2 - lambda1; scale = Util.pow(di * di, m); newLambda1 = alpha + (1 - alpha) * Math.exp(-C / scale); newLambda2 = alpha; Dxx = newLambda1 * v1x * v1x + newLambda2 * v2x * v2x; Dxy = newLambda1 * v1x * v1y + newLambda2 * v2x * v2x; Dyy = newLambda1 * v1y * v1y + newLambda2 * v2y * v2y; D_ra.setPosition(0, 2); D_ra.get().setReal(Dxx); D_ra.fwd(2); D_ra.get().setReal(Dxy); D_ra.fwd(2); D_ra.get().setReal(Dyy); } } }; } SimpleMultiThreading.startAndJoin(threads); return true; }
/** * Set the armor colour to use. * * @param color the solid colour for the health bar * @return this */ public GenericLivingEntity setArmorColor(Color color) { _armor.setTopColor(color).setBottomColor(color); return this; }
/** * Set the health colour to use. * * @param color the solid colour for the health bar * @return this */ public GenericLivingEntity setHealthColor(Color color) { _health.setTopColor(color).setBottomColor(color); return this; }