All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.github.mianalysis.mia.process.voxel.BresenhamLine Maven / Gradle / Ivy

Go to download

ModularImageAnalysis (MIA) is an ImageJ plugin which provides a modular framework for assembling image and object analysis workflows. Detected objects can be transformed, filtered, measured and related. Analysis workflows are batch-enabled by default, allowing easy processing of high-content datasets.

There is a newer version: 1.6.8
Show newest version
package io.github.mianalysis.mia.process.voxel;

/**
 * Implements Bresenham's line algorithm to draw a straight line between two points.
 */
public class BresenhamLine {
    public static int[][] getLine(int x0, int x1, int y0, int y1) {
        int w = Math.abs(x1-x0);
        int h = Math.abs(y1-y0);

        int sx = x1 h) {
            double derr = Math.abs((double) h/(double) w);
            double error = derr - 0.5;

            xy = new int[w][2];
            int currY = y0;

            for (int i = 0; i < w; i++) {
                xy[i][0] = x0 + i*sx;
                xy[i][1] = currY;
                error = error + derr;

                if (error >= 0.5) {
                    currY = currY + sy;
                    error = error - 1;

                }
            }

        } else {
            double derr = Math.abs((double) w/(double) h);
            double error = derr - 0.5;

            xy = new int[h][2];
            int currX = x0;

            for (int i = 0; i < h; i++) {
                xy[i][0] = currX;
                xy[i][1] = y0 + i*sy;
                error = error + derr;

                if (error >= 0.5) {
                    currX = currX + sx;
                    error = error - 1;

                }
            }

        }

        return xy;

    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy