use of gdsc.smlm.model.MoleculeModel in project GDSC-SMLM by aherbert.
the class DiffusionRateTest method run.
/*
* (non-Javadoc)
*
* @see ij.plugin.PlugIn#run(java.lang.String)
*/
public void run(String arg) {
SMLMUsageTracker.recordPlugin(this.getClass(), arg);
if (IJ.controlKeyDown()) {
simpleTest();
return;
}
extraOptions = Utils.isExtraOptions();
if (!showDialog())
return;
lastSimulatedDataset[0] = lastSimulatedDataset[1] = "";
lastSimulatedPrecision = 0;
final int totalSteps = (int) Math.ceil(settings.seconds * settings.stepsPerSecond);
conversionFactor = 1000000.0 / (settings.pixelPitch * settings.pixelPitch);
// Diffusion rate is um^2/sec. Convert to pixels per simulation frame.
final double diffusionRateInPixelsPerSecond = settings.diffusionRate * conversionFactor;
final double diffusionRateInPixelsPerStep = diffusionRateInPixelsPerSecond / settings.stepsPerSecond;
final double precisionInPixels = myPrecision / settings.pixelPitch;
final boolean addError = myPrecision != 0;
Utils.log(TITLE + " : D = %s um^2/sec, Precision = %s nm", Utils.rounded(settings.diffusionRate, 4), Utils.rounded(myPrecision, 4));
Utils.log("Mean-displacement per dimension = %s nm/sec", Utils.rounded(1e3 * ImageModel.getRandomMoveDistance(settings.diffusionRate), 4));
if (extraOptions)
Utils.log("Step size = %s, precision = %s", Utils.rounded(ImageModel.getRandomMoveDistance(diffusionRateInPixelsPerStep)), Utils.rounded(precisionInPixels));
// Convert diffusion co-efficient into the standard deviation for the random walk
final double diffusionSigma = (settings.getDiffusionType() == DiffusionType.LINEAR_WALK) ? // Q. What should this be? At the moment just do 1D diffusion on a random vector
ImageModel.getRandomMoveDistance(diffusionRateInPixelsPerStep) : ImageModel.getRandomMoveDistance(diffusionRateInPixelsPerStep);
Utils.log("Simulation step-size = %s nm", Utils.rounded(settings.pixelPitch * diffusionSigma, 4));
// Move the molecules and get the diffusion rate
IJ.showStatus("Simulating ...");
final long start = System.nanoTime();
final long seed = System.currentTimeMillis() + System.identityHashCode(this);
RandomGenerator[] random = new RandomGenerator[3];
RandomGenerator[] random2 = new RandomGenerator[3];
for (int i = 0; i < 3; i++) {
random[i] = new Well19937c(seed + i * 12436);
random2[i] = new Well19937c(seed + i * 678678 + 3);
}
Statistics[] stats2D = new Statistics[totalSteps];
Statistics[] stats3D = new Statistics[totalSteps];
StoredDataStatistics jumpDistances2D = new StoredDataStatistics(totalSteps);
StoredDataStatistics jumpDistances3D = new StoredDataStatistics(totalSteps);
for (int j = 0; j < totalSteps; j++) {
stats2D[j] = new Statistics();
stats3D[j] = new Statistics();
}
SphericalDistribution dist = new SphericalDistribution(settings.confinementRadius / settings.pixelPitch);
Statistics asymptote = new Statistics();
// Save results to memory
MemoryPeakResults results = new MemoryPeakResults(totalSteps);
Calibration cal = new Calibration(settings.pixelPitch, 1, 1000.0 / settings.stepsPerSecond);
results.setCalibration(cal);
results.setName(TITLE);
int peak = 0;
// Store raw coordinates
ArrayList<Point> points = new ArrayList<Point>(totalSteps);
StoredData totalJumpDistances1D = new StoredData(settings.particles);
StoredData totalJumpDistances2D = new StoredData(settings.particles);
StoredData totalJumpDistances3D = new StoredData(settings.particles);
for (int i = 0; i < settings.particles; i++) {
if (i % 16 == 0) {
IJ.showProgress(i, settings.particles);
if (Utils.isInterrupted())
return;
}
// Increment the frame so that tracing analysis can distinguish traces
peak++;
double[] origin = new double[3];
final int id = i + 1;
MoleculeModel m = new MoleculeModel(id, origin.clone());
if (addError)
origin = addError(origin, precisionInPixels, random);
if (useConfinement) {
// Note: When using confinement the average displacement should asymptote
// at the average distance of a point from the centre of a ball. This is 3r/4.
// See: http://answers.yahoo.com/question/index?qid=20090131162630AAMTUfM
// The equivalent in 2D is 2r/3. However although we are plotting 2D distance
// this is a projection of the 3D position onto the plane and so the particles
// will not be evenly spread (there will be clustering at centre caused by the
// poles)
final double[] axis = (settings.getDiffusionType() == DiffusionType.LINEAR_WALK) ? nextVector() : null;
for (int j = 0; j < totalSteps; j++) {
double[] xyz = m.getCoordinates();
double[] originalXyz = xyz.clone();
for (int n = confinementAttempts; n-- > 0; ) {
if (settings.getDiffusionType() == DiffusionType.GRID_WALK)
m.walk(diffusionSigma, random);
else if (settings.getDiffusionType() == DiffusionType.LINEAR_WALK)
m.slide(diffusionSigma, axis, random[0]);
else
m.move(diffusionSigma, random);
if (!dist.isWithin(m.getCoordinates())) {
// Reset position
for (int k = 0; k < 3; k++) xyz[k] = originalXyz[k];
} else {
// The move was allowed
break;
}
}
points.add(new Point(id, xyz));
if (addError)
xyz = addError(xyz, precisionInPixels, random2);
peak = record(xyz, id, peak, stats2D[j], stats3D[j], jumpDistances2D, jumpDistances3D, origin, results);
}
asymptote.add(distance(m.getCoordinates()));
} else {
if (settings.getDiffusionType() == DiffusionType.GRID_WALK) {
for (int j = 0; j < totalSteps; j++) {
m.walk(diffusionSigma, random);
double[] xyz = m.getCoordinates();
points.add(new Point(id, xyz));
if (addError)
xyz = addError(xyz, precisionInPixels, random2);
peak = record(xyz, id, peak, stats2D[j], stats3D[j], jumpDistances2D, jumpDistances3D, origin, results);
}
} else if (settings.getDiffusionType() == DiffusionType.LINEAR_WALK) {
final double[] axis = nextVector();
for (int j = 0; j < totalSteps; j++) {
m.slide(diffusionSigma, axis, random[0]);
double[] xyz = m.getCoordinates();
points.add(new Point(id, xyz));
if (addError)
xyz = addError(xyz, precisionInPixels, random2);
peak = record(xyz, id, peak, stats2D[j], stats3D[j], jumpDistances2D, jumpDistances3D, origin, results);
}
} else {
for (int j = 0; j < totalSteps; j++) {
m.move(diffusionSigma, random);
double[] xyz = m.getCoordinates();
points.add(new Point(id, xyz));
if (addError)
xyz = addError(xyz, precisionInPixels, random2);
peak = record(xyz, id, peak, stats2D[j], stats3D[j], jumpDistances2D, jumpDistances3D, origin, results);
}
}
}
// Debug: record all the particles so they can be analysed
// System.out.printf("%f %f %f\n", m.getX(), m.getY(), m.getZ());
final double[] xyz = m.getCoordinates();
double d2 = 0;
totalJumpDistances1D.add(d2 = xyz[0] * xyz[0]);
totalJumpDistances2D.add(d2 += xyz[1] * xyz[1]);
totalJumpDistances3D.add(d2 += xyz[2] * xyz[2]);
}
final double time = (System.nanoTime() - start) / 1000000.0;
IJ.showProgress(1);
MemoryPeakResults.addResults(results);
lastSimulatedDataset[0] = results.getName();
lastSimulatedPrecision = myPrecision;
// Convert pixels^2/step to um^2/sec
final double msd2D = (jumpDistances2D.getMean() / conversionFactor) / (results.getCalibration().getExposureTime() / 1000);
final double msd3D = (jumpDistances3D.getMean() / conversionFactor) / (results.getCalibration().getExposureTime() / 1000);
Utils.log("Raw data D=%s um^2/s, Precision = %s nm, N=%d, step=%s s, mean2D=%s um^2, MSD 2D = %s um^2/s, mean3D=%s um^2, MSD 3D = %s um^2/s", Utils.rounded(settings.diffusionRate), Utils.rounded(myPrecision), jumpDistances2D.getN(), Utils.rounded(results.getCalibration().getExposureTime() / 1000), Utils.rounded(jumpDistances2D.getMean() / conversionFactor), Utils.rounded(msd2D), Utils.rounded(jumpDistances3D.getMean() / conversionFactor), Utils.rounded(msd3D));
aggregateIntoFrames(points, addError, precisionInPixels, random2);
IJ.showStatus("Analysing results ...");
if (showDiffusionExample) {
showExample(totalSteps, diffusionSigma, random);
}
// Plot a graph of mean squared distance
double[] xValues = new double[stats2D.length];
double[] yValues2D = new double[stats2D.length];
double[] yValues3D = new double[stats3D.length];
double[] upper2D = new double[stats2D.length];
double[] lower2D = new double[stats2D.length];
double[] upper3D = new double[stats3D.length];
double[] lower3D = new double[stats3D.length];
SimpleRegression r2D = new SimpleRegression(false);
SimpleRegression r3D = new SimpleRegression(false);
final int firstN = (useConfinement) ? fitN : totalSteps;
for (int j = 0; j < totalSteps; j++) {
// Convert steps to seconds
xValues[j] = (double) (j + 1) / settings.stepsPerSecond;
// Convert values in pixels^2 to um^2
final double mean2D = stats2D[j].getMean() / conversionFactor;
final double mean3D = stats3D[j].getMean() / conversionFactor;
final double sd2D = stats2D[j].getStandardDeviation() / conversionFactor;
final double sd3D = stats3D[j].getStandardDeviation() / conversionFactor;
yValues2D[j] = mean2D;
yValues3D[j] = mean3D;
upper2D[j] = mean2D + sd2D;
lower2D[j] = mean2D - sd2D;
upper3D[j] = mean3D + sd3D;
lower3D[j] = mean3D - sd3D;
if (j < firstN) {
r2D.addData(xValues[j], yValues2D[j]);
r3D.addData(xValues[j], yValues3D[j]);
}
}
// TODO - Fit using the equation for 2D confined diffusion:
// MSD = 4s^2 + R^2 (1 - 0.99e^(-1.84^2 Dt / R^2)
// s = localisation precision
// R = confinement radius
// D = 2D diffusion coefficient
// t = time
final PolynomialFunction fitted2D, fitted3D;
if (r2D.getN() > 0) {
// Do linear regression to get diffusion rate
final double[] best2D = new double[] { r2D.getIntercept(), r2D.getSlope() };
fitted2D = new PolynomialFunction(best2D);
final double[] best3D = new double[] { r3D.getIntercept(), r3D.getSlope() };
fitted3D = new PolynomialFunction(best3D);
// For 2D diffusion: d^2 = 4D
// where: d^2 = mean-square displacement
double D = best2D[1] / 4.0;
String msg = "2D Diffusion rate = " + Utils.rounded(D, 4) + " um^2 / sec (" + Utils.timeToString(time) + ")";
IJ.showStatus(msg);
Utils.log(msg);
D = best3D[1] / 6.0;
Utils.log("3D Diffusion rate = " + Utils.rounded(D, 4) + " um^2 / sec (" + Utils.timeToString(time) + ")");
} else {
fitted2D = fitted3D = null;
}
// Create plots
plotMSD(totalSteps, xValues, yValues2D, lower2D, upper2D, fitted2D, 2);
plotMSD(totalSteps, xValues, yValues3D, lower3D, upper3D, fitted3D, 3);
plotJumpDistances(TITLE, jumpDistances2D, 2, 1);
plotJumpDistances(TITLE, jumpDistances3D, 3, 1);
if (idCount > 0)
new WindowOrganiser().tileWindows(idList);
if (useConfinement)
Utils.log("3D asymptote distance = %s nm (expected %.2f)", Utils.rounded(asymptote.getMean() * settings.pixelPitch, 4), 3 * settings.confinementRadius / 4);
}
use of gdsc.smlm.model.MoleculeModel in project GDSC-SMLM by aherbert.
the class CreateData method convertRelativeToAbsolute.
/**
* Update the fluorophores relative coordinates to absolute
*
* @param molecules
*/
@SuppressWarnings("unused")
private void convertRelativeToAbsolute(List<CompoundMoleculeModel> molecules) {
for (CompoundMoleculeModel c : molecules) {
final double[] xyz = c.getCoordinates();
for (int n = c.getSize(); n-- > 0; ) {
MoleculeModel m = c.getMolecule(n);
double[] xyz2 = m.getCoordinates();
for (int i = 0; i < 3; i++) xyz2[i] += xyz[i];
}
}
}
use of gdsc.smlm.model.MoleculeModel in project GDSC-SMLM by aherbert.
the class CreateData method createCompoundMolecules.
@SuppressWarnings("unchecked")
private List<CompoundMoleculeModel> createCompoundMolecules() {
// Diffusion rate is um^2/sec. Convert to pixels per simulation frame.
final double diffusionFactor = (1000000.0 / (settings.pixelPitch * settings.pixelPitch)) / settings.stepsPerSecond;
List<CompoundMoleculeModel> compounds;
if (settings.compoundMolecules) {
// Try and load the compounds from the XML specification
try {
Object fromXML = createXStream().fromXML(settings.compoundText);
List<Compound> rawCompounds = (List<Compound>) fromXML;
// Convert from the XML serialised objects to the compound model
compounds = new ArrayList<CompoundMoleculeModel>(rawCompounds.size());
int id = 1;
for (Compound c : rawCompounds) {
MoleculeModel[] molecules = new MoleculeModel[c.atoms.length];
for (int i = 0; i < c.atoms.length; i++) {
Atom a = c.atoms[i];
molecules[i] = new MoleculeModel(a.mass, a.x, a.y, a.z);
}
CompoundMoleculeModel m = new CompoundMoleculeModel(id++, 0, 0, 0, Arrays.asList(molecules));
m.setFraction(c.fraction);
m.setDiffusionRate(c.D * diffusionFactor);
m.setDiffusionType(DiffusionType.fromString(c.diffusionType));
compounds.add(m);
}
// Convert coordinates from nm to pixels
final double scaleFactor = 1.0 / settings.pixelPitch;
for (CompoundMoleculeModel c : compounds) {
c.scale(scaleFactor);
}
} catch (Exception e) {
IJ.error(TITLE, "Unable to create compound molecules");
return null;
}
} else {
// Create a simple compound with one molecule at the origin
compounds = new ArrayList<CompoundMoleculeModel>(1);
CompoundMoleculeModel m = new CompoundMoleculeModel(1, 0, 0, 0, Arrays.asList(new MoleculeModel(0, 0, 0, 0)));
m.setDiffusionRate(settings.diffusionRate * diffusionFactor);
m.setDiffusionType(settings.getDiffusionType());
compounds.add(m);
}
return compounds;
}
use of gdsc.smlm.model.MoleculeModel in project GDSC-SMLM by aherbert.
the class BlinkEstimatorTest method estimateBlinking.
private TIntHashSet estimateBlinking(double nBlinks, double tOn, double tOff, int particles, double fixedFraction, boolean timeAtLowerBound, boolean doAssert) {
SpatialIllumination activationIllumination = new UniformIllumination(100);
int totalSteps = 100;
double eAct = totalSteps * 0.3 * activationIllumination.getAveragePhotons();
ImageModel imageModel = new ActivationEnergyImageModel(eAct, activationIllumination, tOn, 0, tOff, 0, nBlinks);
imageModel.setRandomGenerator(rand);
double[] max = new double[] { 256, 256, 32 };
double[] min = new double[3];
SpatialDistribution distribution = new UniformDistribution(min, max, rand.nextInt());
List<CompoundMoleculeModel> compounds = new ArrayList<CompoundMoleculeModel>(1);
CompoundMoleculeModel c = new CompoundMoleculeModel(1, 0, 0, 0, Arrays.asList(new MoleculeModel(0, 0, 0, 0)));
c.setDiffusionRate(diffusionRate);
c.setDiffusionType(DiffusionType.RANDOM_WALK);
compounds.add(c);
List<CompoundMoleculeModel> molecules = imageModel.createMolecules(compounds, particles, distribution, false);
// Activate fluorophores
List<? extends FluorophoreSequenceModel> fluorophores = imageModel.createFluorophores(molecules, totalSteps);
totalSteps = checkTotalSteps(totalSteps, fluorophores);
List<LocalisationModel> localisations = imageModel.createImage(molecules, fixedFraction, totalSteps, photons, 0.5, false);
// // Remove localisations to simulate missed counts.
// List<LocalisationModel> newLocalisations = new ArrayList<LocalisationModel>(localisations.size());
// boolean[] id = new boolean[fluorophores.size() + 1];
// Statistics photonStats = new Statistics();
// for (LocalisationModel l : localisations)
// {
// photonStats.add(l.getIntensity());
// // Remove by intensity threshold and optionally at random.
// if (l.getIntensity() < minPhotons || rand.nextDouble() < pDelete)
// continue;
// newLocalisations.add(l);
// id[l.getId()] = true;
// }
// localisations = newLocalisations;
// System.out.printf("Photons = %f\n", photonStats.getMean());
//
// List<FluorophoreSequenceModel> newFluorophores = new ArrayList<FluorophoreSequenceModel>(fluorophores.size());
// for (FluorophoreSequenceModel f : fluorophores)
// {
// if (id[f.getId()])
// newFluorophores.add(f);
// }
// fluorophores = newFluorophores;
MemoryPeakResults results = new MemoryPeakResults();
results.setCalibration(new Calibration(pixelPitch, 1, msPerFrame));
for (LocalisationModel l : localisations) {
// Remove by intensity threshold and optionally at random.
if (l.getIntensity() < minPhotons || rand.nextDouble() < pDelete)
continue;
float[] params = new float[7];
params[Gaussian2DFunction.X_POSITION] = (float) l.getX();
params[Gaussian2DFunction.Y_POSITION] = (float) l.getY();
params[Gaussian2DFunction.X_SD] = params[Gaussian2DFunction.Y_SD] = psfWidth;
params[Gaussian2DFunction.SIGNAL] = (float) (l.getIntensity());
results.addf(l.getTime(), 0, 0, 0, 0, 0, params, null);
}
// Add random localisations
for (int i = (int) (localisations.size() * pAdd); i-- > 0; ) {
float[] params = new float[7];
params[Gaussian2DFunction.X_POSITION] = (float) (rand.nextDouble() * max[0]);
params[Gaussian2DFunction.Y_POSITION] = (float) (rand.nextDouble() * max[1]);
params[Gaussian2DFunction.X_SD] = params[Gaussian2DFunction.Y_SD] = psfWidth;
// Intensity doesn't matter at the moment for tracing
params[Gaussian2DFunction.SIGNAL] = (float) (photons);
results.addf(1 + rand.nextInt(totalSteps), 0, 0, 0, 0, 0, params, null);
}
// Get actual simulated stats ...
Statistics statsNBlinks = new Statistics();
Statistics statsTOn = new Statistics();
Statistics statsTOff = new Statistics();
Statistics statsSampledNBlinks = new Statistics();
Statistics statsSampledTOn = new Statistics();
StoredDataStatistics statsSampledTOff = new StoredDataStatistics();
for (FluorophoreSequenceModel f : fluorophores) {
statsNBlinks.add(f.getNumberOfBlinks());
statsTOn.add(f.getOnTimes());
statsTOff.add(f.getOffTimes());
int[] on = f.getSampledOnTimes();
statsSampledNBlinks.add(on.length);
statsSampledTOn.add(on);
statsSampledTOff.add(f.getSampledOffTimes());
}
System.out.printf("N = %d (%d), N-blinks = %f, tOn = %f, tOff = %f, Fixed = %f\n", fluorophores.size(), localisations.size(), nBlinks, tOn, tOff, fixedFraction);
System.out.printf("Actual N-blinks = %f (%f), tOn = %f (%f), tOff = %f (%f), 95%% = %f, max = %f\n", statsNBlinks.getMean(), statsSampledNBlinks.getMean(), statsTOn.getMean(), statsSampledTOn.getMean(), statsTOff.getMean(), statsSampledTOff.getMean(), statsSampledTOff.getStatistics().getPercentile(95), statsSampledTOff.getStatistics().getMax());
System.out.printf("-=-=--=-\n");
BlinkEstimator be = new BlinkEstimator();
be.maxDarkTime = (int) (tOff * 10);
be.msPerFrame = msPerFrame;
be.relativeDistance = false;
double d = ImageModel.getRandomMoveDistance(diffusionRate);
be.searchDistance = (fixedFraction < 1) ? Math.sqrt(2 * d * d) * 3 : 0;
be.timeAtLowerBound = timeAtLowerBound;
be.showPlots = false;
//Assert.assertTrue("Max dark time must exceed the dark time of the data (otherwise no plateau)",
// be.maxDarkTime > statsSampledTOff.getStatistics().getMax());
int nMolecules = fluorophores.size();
if (usePopulationStatistics) {
nBlinks = statsNBlinks.getMean();
tOff = statsTOff.getMean();
} else {
nBlinks = statsSampledNBlinks.getMean();
tOff = statsSampledTOff.getMean();
}
// See if any fitting regime gets a correct answer
TIntHashSet ok = new TIntHashSet();
for (int nFittedPoints = MIN_FITTED_POINTS; nFittedPoints <= MAX_FITTED_POINTS; nFittedPoints++) {
be.nFittedPoints = nFittedPoints;
be.computeBlinkingRate(results, true);
double moleculesError = DoubleEquality.relativeError(nMolecules, be.getNMolecules());
double blinksError = DoubleEquality.relativeError(nBlinks, be.getNBlinks());
double offError = DoubleEquality.relativeError(tOff * msPerFrame, be.getTOff());
System.out.printf("Error %d: N = %f, blinks = %f, tOff = %f : %f\n", nFittedPoints, moleculesError, blinksError, offError, (moleculesError + blinksError + offError) / 3);
if (moleculesError < relativeError && blinksError < relativeError && offError < relativeError) {
ok.add(nFittedPoints);
System.out.printf("-=-=--=-\n");
System.out.printf("*** Correct at %d fitted points ***\n", nFittedPoints);
if (doAssert)
break;
}
//if (!be.isIncreaseNFittedPoints())
// break;
}
System.out.printf("-=-=--=-\n");
if (doAssert)
Assert.assertFalse(ok.isEmpty());
//Assert.assertEquals("Invalid t-off", tOff * msPerFrame, be.getTOff(), tOff * msPerFrame * relativeError);
return ok;
}
use of gdsc.smlm.model.MoleculeModel in project GDSC-SMLM by aherbert.
the class DiffusionRateTest method showExample.
private void showExample(int totalSteps, double diffusionSigma, RandomGenerator[] random) {
MoleculeModel m = new MoleculeModel(0, new double[3]);
float[] xValues = new float[totalSteps];
float[] x = new float[totalSteps];
float[] y = new float[totalSteps];
final double[] axis = (settings.getDiffusionType() == DiffusionType.LINEAR_WALK) ? nextVector() : null;
for (int j = 0; j < totalSteps; j++) {
if (settings.getDiffusionType() == DiffusionType.GRID_WALK)
m.walk(diffusionSigma, random);
else if (settings.getDiffusionType() == DiffusionType.LINEAR_WALK)
m.slide(diffusionSigma, axis, random[0]);
else
m.move(diffusionSigma, random);
x[j] = (float) (m.getX());
y[j] = (float) (m.getY());
xValues[j] = (float) ((j + 1) / settings.stepsPerSecond);
}
// Plot x and y coords on a timeline
String title = TITLE + " example coordinates";
Plot2 plot = new Plot2(title, "Time (seconds)", "Distance (um)");
float[] xUm = convertToUm(x);
float[] yUm = convertToUm(y);
float[] limits = Maths.limits(xUm);
limits = Maths.limits(limits, yUm);
plot.setLimits(0, totalSteps / settings.stepsPerSecond, limits[0], limits[1]);
plot.setColor(Color.red);
plot.addPoints(xValues, xUm, Plot2.LINE);
plot.setColor(Color.blue);
plot.addPoints(xValues, yUm, Plot2.LINE);
Utils.display(title, plot);
// Scale up and draw 2D position
for (int j = 0; j < totalSteps; j++) {
x[j] *= magnification;
y[j] *= magnification;
}
float[] limitsx = getLimits(x);
float[] limitsy = getLimits(y);
int width = (int) (limitsx[1] - limitsx[0]);
int height = (int) (limitsy[1] - limitsy[0]);
// Ensure we draw something, even it is a simple dot at the centre for no diffusion
if (width == 0) {
width = (int) (32 * magnification);
limitsx[0] = -width / 2;
}
if (height == 0) {
height = (int) (32 * magnification);
limitsy[0] = -height / 2;
}
ImageProcessor ip = new ByteProcessor(width, height);
// Adjust x and y using the minimum to centre
x[0] -= limitsx[0];
y[0] -= limitsy[0];
for (int j = 1; j < totalSteps; j++) {
// Adjust x and y using the minimum to centre
x[j] -= limitsx[0];
y[j] -= limitsy[0];
// Draw a line
ip.setColor(32 + (223 * j) / (totalSteps - 1));
ip.drawLine(round(x[j - 1]), round(y[j - 1]), round(x[j]), round(y[j]));
}
// Draw the final position
ip.putPixel((int) round(x[totalSteps - 1]), (int) round(y[totalSteps - 1]), 255);
ImagePlus imp = Utils.display(TITLE + " example", ip);
// Apply the fire lookup table
WindowManager.setTempCurrentImage(imp);
LutLoader lut = new LutLoader();
lut.run("fire");
WindowManager.setTempCurrentImage(null);
}
Aggregations