use of java.awt.geom.GeneralPath in project beast-mcmc by beast-dev.
the class KMLRenderer method render.
public void render(BufferedImage image) {
Graphics2D g2d = image.createGraphics();
g2d.setColor(background);
g2d.fillRect(0, 0, image.getWidth(), image.getHeight());
viewTransform = new ViewTransform(bounds, image.getWidth(), image.getHeight());
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
g2d.setColor(shapeColor);
AffineTransform transform = viewTransform.getTransform();
for (Shape s : shapes) {
GeneralPath path = new GeneralPath(s);
path.transform(transform);
g2d.fill(path);
}
}
use of java.awt.geom.GeneralPath in project beast-mcmc by beast-dev.
the class VisualizeKMLJointProb method paintComponent.
public void paintComponent(Graphics g) {
System.out.println("entering paintComponent()");
computeScales();
Graphics2D g2d = (Graphics2D) g;
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
g2d.setStroke(new BasicStroke(1.5f));
int sx1 = probs.x(start.getX());
int sy1 = probs.y(start.getY());
int sx2 = probs.x(B.getX());
int sy2 = probs.y(B.getY());
int t = 49;
AffineTransform transform = getFullTransform();
double maxProb = 0.0;
double[][] p = new double[probs.latticeWidth][probs.latticeHeight];
for (int i = 0; i < probs.latticeWidth; i++) {
for (int j = 0; j < probs.latticeHeight; j++) {
p[i][j] = probs.p(sx1, sy1, i, j, t) * probs.p(sx2, sy2, i, j, t);
if (p[i][j] > maxProb)
maxProb = p[i][j];
}
}
System.out.println("Painting lattice probs");
for (int i = 0; i < probs.latticeWidth; i++) {
for (int j = 0; j < probs.latticeHeight; j++) {
p[i][j] /= maxProb;
Rectangle2D rect = new Rectangle2D.Double(i * probs.dx + probs.minx, j * probs.dy + probs.miny, probs.dx, probs.dy);
g.setColor(cf.getColor((float) p[i][j]));
g2d.fill(transform.createTransformedShape(rect));
g.setColor(Color.black);
g2d.draw(transform.createTransformedShape(rect));
}
}
System.out.println("Painting shapes");
for (Shape s : shapes) {
System.out.print(".");
System.out.flush();
GeneralPath path = new GeneralPath(s);
path.transform(transform);
g2d.setPaint(Color.BLACK);
g2d.fill(path);
}
g2d.setColor(Color.yellow);
SpaceTime.paintDot(new SpaceTime(0, start), 4, transform, g2d);
SpaceTime.paintDot(new SpaceTime(0, B), 4, transform, g2d);
}
use of java.awt.geom.GeneralPath in project android_frameworks_base by crdroidandroid.
the class Path_Delegate method transform.
/**
* Transform the points in this path by matrix, and write the answer
* into dst. If dst is null, then the the original path is modified.
*
* @param matrix The matrix to apply to the path
* @param dst The transformed path is written here. If dst is null,
* then the the original path is modified
*/
public void transform(Matrix_Delegate matrix, Path_Delegate dst) {
if (matrix.hasPerspective()) {
assert false;
Bridge.getLog().fidelityWarning(LayoutLog.TAG_MATRIX_AFFINE, "android.graphics.Path#transform() only " + "supports affine transformations.", null, null);
}
GeneralPath newPath = new GeneralPath();
PathIterator iterator = mPath.getPathIterator(matrix.getAffineTransform());
newPath.append(iterator, false);
if (dst != null) {
dst.mPath = newPath;
} else {
mPath = newPath;
}
}
use of java.awt.geom.GeneralPath in project processdash by dtuma.
the class RadarPlot method drawRadar.
protected void drawRadar(Graphics2D g2, Rectangle2D plotArea, PlotRenderingInfo info, int pieIndex, PieDataset data) {
// adjust the plot area by the interior spacing value
double gapHorizontal = plotArea.getWidth() * this.interiorGap;
double gapVertical = plotArea.getHeight() * this.interiorGap;
double radarX = plotArea.getX() + gapHorizontal / 2;
double radarY = plotArea.getY() + gapVertical / 2;
double radarW = plotArea.getWidth() - gapHorizontal;
double radarH = plotArea.getHeight() - gapVertical;
// NOTE that non-circular radar charts are not currently supported.
if (true) {
//circular) {
double min = Math.min(radarW, radarH) / 2;
radarX = (radarX + radarX + radarW) / 2 - min;
radarY = (radarY + radarY + radarH) / 2 - min;
radarW = 2 * min;
radarH = 2 * min;
}
double radius = radarW / 2;
double centerX = radarX + radarW / 2;
double centerY = radarY + radarH / 2;
Rectangle2D radarArea = new Rectangle2D.Double(radarX, radarY, radarW, radarH);
// plot the data (unless the dataset is null)...
if ((data != null) && (data.getKeys().size() > 0)) {
// get a list of categories...
List keys = data.getKeys();
int numAxes = keys.size();
// draw each of the axes on the radar chart, and register
// the shape of the radar line.
double multiplier = 1.0;
GeneralPath lineShape = new GeneralPath(GeneralPath.WIND_NON_ZERO, numAxes + 1);
GeneralPath gridShape = new GeneralPath(GeneralPath.WIND_NON_ZERO, numAxes + 1);
int axisNumber = -1;
Iterator iterator = keys.iterator();
while (iterator.hasNext()) {
Comparable currentKey = (Comparable) iterator.next();
axisNumber++;
Number dataValue = data.getValue(currentKey);
double value = (dataValue != null ? dataValue.doubleValue() : 0);
if (value > 1 || Double.isNaN(value) || Double.isInfinite(value))
value = 1.0;
if (value < 0)
value = 0.0;
multiplier *= value;
double angle = 2 * Math.PI * axisNumber / numAxes;
double deltaX = Math.sin(angle) * radius;
double deltaY = -Math.cos(angle) * radius;
// draw the spoke
g2.setPaint(axisPaint);
g2.setStroke(axisStroke);
Line2D line = new Line2D.Double(centerX, centerY, centerX + deltaX, centerY + deltaY);
g2.draw(line);
// register the grid line and the shape line
if (axisNumber == 0) {
gridShape.moveTo((float) deltaX, (float) deltaY);
lineShape.moveTo((float) (deltaX * value), (float) (deltaY * value));
} else {
gridShape.lineTo((float) deltaX, (float) deltaY);
lineShape.lineTo((float) (deltaX * value), (float) (deltaY * value));
}
if (showAxisLabels) {
// draw the label
double labelX = centerX + deltaX * (1 + axisLabelGap);
double labelY = centerY + deltaY * (1 + axisLabelGap);
String label = currentKey.toString();
drawLabel(g2, radarArea, label, axisNumber, labelX, labelY);
}
}
gridShape.closePath();
lineShape.closePath();
// draw five gray concentric gridlines
g2.translate(centerX, centerY);
g2.setPaint(gridLinePaint);
g2.setStroke(gridLineStroke);
for (int i = 5; i > 0; i--) {
Shape scaledGrid = gridShape.createTransformedShape(AffineTransform.getScaleInstance(i / 5.0, i / 5.0));
g2.draw(scaledGrid);
}
// get the color for the plot shape.
Paint dataPaint = plotLinePaint;
if (dataPaint == ADAPTIVE_COLORING) {
//multiplier = Math.exp(Math.log(multiplier) * 2 / numAxes);
dataPaint = getMultiplierColor((float) multiplier);
}
// compute a slightly transparent version of the plot color for
// the fill.
Paint dataFill = null;
if (dataPaint instanceof Color && getForegroundAlpha() != 1.0)
dataFill = new Color(((Color) dataPaint).getRed() / 255f, ((Color) dataPaint).getGreen() / 255f, ((Color) dataPaint).getBlue() / 255f, getForegroundAlpha());
else
dataFill = dataPaint;
// draw the plot shape. First fill with a parially
// transparent color, then stroke with the opaque color.
g2.setPaint(dataFill);
g2.fill(lineShape);
g2.setPaint(dataPaint);
g2.setStroke(plotLineStroke);
g2.draw(lineShape);
// cleanup the graphics context.
g2.translate(-centerX, -centerY);
}
}
Aggregations