/* Last edited on 2013-01-03 00:03:11 by stolfilocal */ /* Creates a test chart of ellipses */ import java.lang.Math; import java.util.Arrays; import java.io.IOException; import minetto.utils.FloatImage; import minetto.utils.FloatImagePaint; public class MakeEllipseChart { public static void main(String[] args) throws IOException { String out_dir = args[0]; System.err.println("Creating a test chart with ellipses of various sizes"); int noctaves = 4; /* Octaves covered by chart. */ int nsteps = 3; /* Steps per octave. */ double rmin = 10; int ncols = 2; FloatImage img = make_chart(noctaves, nsteps, ncols, rmin); img.write_as_png(out_dir + "/chart_ellipses.png", 0.0f, 1.0f, 2.5, true); } public static FloatImage make_chart(int noctaves, int nsteps, int ncols, double rmin) { double rmax = rmin*Math.pow(2.0, noctaves); int nsy = nsteps*noctaves + 1; /* Number of Y radii to show. */ int nsx = 2; /* Number of X radii for each Y radius. */ return make_ellipse_chart(nsx, nsy, rmin, rmax); } /* ---------------------------------------------------------------------- Makes a chart with {nspots} rows of circles and ellipses with major radius varying from {rmin} to {rmax}. */ private static FloatImage make_ellipse_chart(int nsx, int nsy, double rmin, double rmax) { assert(nsx >= 2); assert(nsy >= 2); /* Background and foreground colors: */ float[] bg_rgb = new float[]{ 1.0000f, 0.9800f, 0.9700f }; float[] fg_rgb = new float[]{ 0.0000f, 0.0500f, 1.0000f }; /* Compute image size and alocate: */ int nc = 3; FloatImage out = null; int[] nx_slice = new int[nsy]; /* {nx_slice[ky]} is effective width of row {ky} of ellipses; */ for (int ky = 0; ky < nsy; ky++) { nx_slice[ky] = 0; } int nx = 0, ny = 0; for (int ypass = 0; ypass < 2; ypass++) { /* First pass we just compute {nx,ny,nx_slice[0..nsy-1]}. Second pass is for real: */ int ymin = 0; for (int ky = 0; ky < nsy; ky++) { double yrad = rmin*Math.pow(rmax/rmin, ((double)nsy - 1 - ky)/(nsy-1)); int ylim = ymin + 6*(int)Math.ceil(yrad/2); if (out == null) { /* Update image height. */ ny = ylim; } int xmin = (out == null ? 0 : (nx - nx_slice[ky])/2); for (int kx = 0; kx < nsx; kx++) { double xrad = yrad*Math.pow(0.50, ((double)kx)/(nsx-1)); int xlim = xmin + 6*(int)Math.ceil(xrad/2); if (out == null) { nx_slice[ky] = xlim; if (xlim > nx) { nx = xlim; } } if (out != null) { double xctr = ((double)xlim + xmin)/2; double yctr = ((double)ylim + ymin)/2; double thck = 0.2*yrad; FloatImagePaint.paint_ellipse(out, xctr, yctr, xrad, yrad, thck, fg_rgb); } xmin = xlim; } System.err.println(" slice width[" + ky + "] = " + nx_slice[ky]); ymin = ylim; } if (out == null) { System.err.println(" image size = " + nx + " x " + ny); out = new FloatImage(nc, nx, ny); out.set_all_pixels(bg_rgb); } } return out; } }