Example usage for java.awt Polygon Polygon

List of usage examples for java.awt Polygon Polygon

Introduction

In this page you can find the example usage for java.awt Polygon Polygon.

Prototype

public Polygon(int[] xpoints, int[] ypoints, int npoints) 

Source Link

Document

Constructs and initializes a Polygon from the specified parameters.

Usage

From source file:com.naryx.tagfusion.cfm.tag.awt.cfCHART.java

private Shape getMarker(String markerStyle, int markerSize) {
    double size = markerSize;
    double delta = markerSize / 2.0;
    double delta3rd = markerSize / 3.0;
    double delta4th = markerSize / 4.0;
    double delta5th = markerSize / 5.0;
    double delta6th = markerSize / 6.0;
    int[] xpoints = null;
    int[] ypoints = null;

    if (markerStyle.equals("triangle")) {
        xpoints = intArray(0.0, delta, -delta);
        ypoints = intArray(-delta, delta, delta);
        return new Polygon(xpoints, ypoints, 3);
    } else if (markerStyle.equals("triangledown")) {
        xpoints = intArray(-delta, +delta, 0.0);
        ypoints = intArray(-delta, -delta, delta);
        return new Polygon(xpoints, ypoints, 3);
    } else if (markerStyle.equals("triangleright")) {
        xpoints = intArray(-delta, delta, -delta);
        ypoints = intArray(-delta, 0.0, delta);
        return new Polygon(xpoints, ypoints, 3);
    } else if (markerStyle.equals("triangleleft")) {
        xpoints = intArray(-delta, delta, delta);
        ypoints = intArray(0.0, -delta, +delta);
        return new Polygon(xpoints, ypoints, 3);
    } else if (markerStyle.equals("diamond")) {
        xpoints = intArray(0.0, delta, 0.0, -delta);
        ypoints = intArray(-delta, 0.0, delta, 0.0);
        return new Polygon(xpoints, ypoints, 4);
    } else if (markerStyle.equals("circle")) {
        return new java.awt.geom.Ellipse2D.Double(-delta, -delta, size, size);
    } else if (markerStyle.equals("letterx")) {
        xpoints = intArray(0.0, delta3rd, delta, delta6th, delta, delta3rd, 0.0, -delta3rd, -delta, -delta6th,
                -delta, -delta3rd);/*from w ww  .  j a va 2  s .c om*/
        ypoints = intArray(-delta6th, -delta, -delta3rd, 0.0, delta3rd, delta, delta6th, delta, delta3rd, 0.0,
                -delta3rd, -delta);
        return new Polygon(xpoints, ypoints, 12);
    } else if (markerStyle.equals("mcross")) {
        xpoints = intArray(0.0, -delta5th, delta5th, 0.0, delta, delta, 0.0, delta5th, -delta5th, 0.0, -delta,
                -delta);
        ypoints = intArray(0.0, -delta, -delta, 0.0, -delta5th, delta5th, 0.0, delta, delta, 0.0, delta5th,
                -delta5th);
        return new Polygon(xpoints, ypoints, 12);
    } else if (markerStyle.equals("snow")) {
        xpoints = intArray(0.0, delta4th, delta, 0.0, delta, delta4th, 0.0, -delta4th, -delta, 0.0, -delta,
                -delta4th);
        ypoints = intArray(0.0, -delta, -delta4th, 0.0, delta4th, delta, 0.0, delta, delta4th, 0.0, -delta4th,
                -delta);
        return new Polygon(xpoints, ypoints, 12);
    } else if (markerStyle.equals("rcross")) {
        xpoints = intArray(-delta4th, delta4th, delta4th, delta, delta, delta4th, delta4th, -delta4th,
                -delta4th, -delta, -delta, -delta4th);
        ypoints = intArray(-delta, -delta, -delta4th, -delta4th, delta4th, delta4th, delta, delta, delta4th,
                delta4th, -delta4th, -delta4th);
        return new Polygon(xpoints, ypoints, 12);
    } else if (markerStyle.equals("horizontalrectangle")) {
        return new java.awt.geom.Rectangle2D.Double(-delta, -delta / 2, size, size / 2);
    } else if (markerStyle.equals("verticalrectangle")) {
        return new java.awt.geom.Rectangle2D.Double(-delta / 2, -delta, size / 2, size);
    }

    // The default is a rectangle
    return new java.awt.geom.Rectangle2D.Double(-delta, -delta, size, size);
}

From source file:stainingestimation.StainingEstimation.java

/**
 * Performs the staining estimation of a given TMAspot. The image is patchized into small chunks (regular images are one patch, NDPIs might be cut into real patches. For NDPI, only the region of interests are processed).
 * Then the staining estimation is done in parallel for the patches, and the found nuclei are stored in a list of TMApoints. The size of the patches for NDPI is calculated by the number of available processors and max Memory.
 * @param se The StainingEstimation instance.
 * @param ts The TMAspot of the image./*from   w  w w.ja  v a 2  s  .  co m*/
 * @param radius The radius of the nuclei.
 * @param blur The blurring applied to the channels prior to local maxima finding.
 * @param tolerance The tolerance used for local maxima finding.
 * @param TMblur_hema The blurring for the dynamic threshold map for the channel 1 (if any).
 * @param TMblur_dab The blurring for the dynamic threshold map for the channel 2 (if any).
 * @param t_hema The fixed channel 1 threshold (between 0-255).
 * @param t_dab The fixed channel 2 threshold (between 0-255).
 * @param hide_legend If false, a legend of the color deconvolution algorithm will appear.
 * @param myStain String of the staining protocol (e.g. "H&E" or "H DAB").
 * @param substractChannels If true, channel 2 will be substracted from channel 1. 
 * @param asParallelThread If true, saving of the images will be done in a parallel thread. Saving the channel images takes long CPU time.
 * @param useThresholdMap If true, a dynamic threshold map is used for maximum acceptance instead of a fixed value.
 * @param respectAreas If true, including and excluding areas (ROI) on the images are respected and found nuclei are filtered accordingly.
 * @return A list of all found TMApoints on the given TMAspot. Points are already filtered by the including or excluding areas. Also, points to not overlap to each other (in the given radius).
 */
public static List<TMApoint> tma_stain(StainingEstimation se, TMAspot ts, int radius, double blur,
        int tolerance, int TMblur_hema, int TMblur_dab, int t_hema, int t_dab, boolean hide_legend,
        String myStain, boolean substractChannels, boolean useThresholdMap, boolean respectAreas,
        boolean asParallelThread) {
    tmarker tm = ts.getCenter();

    // RANDOM STREAM RESETTEN
    tm.resetRandomSeed();

    List<TMApoint> brown_spots_total = new ArrayList<>();

    try {
        String text = tm.getStatusMessageLabel().getText();

        if (!asParallelThread) {
            tm.setStatusMessageLabel(ts.getName() + ": Performing Staining Estimation ...");
            tm.setProgressbar(15);
        }

        List<Point> offsets = new ArrayList();
        List<Point> sizes = new ArrayList();

        int maxbytes = (int) (0.1 * se.manager.getMaxMemory() / se.manager.getNumberProcessors());
        int size = (int) Math.floor(Math.sqrt(maxbytes / 4.0));
        int w = ts.getWidth();
        int h = ts.getHeight();

        // collect the ROIS (we do only need to compute everything here, which is faster for large NDPI images)
        List<Polygon> rois_incl = new ArrayList();
        if (respectAreas && ts.isNDPI()) {
            rois_incl.addAll(ts.getIncludingAreas());
        }
        if (rois_incl.isEmpty())
            rois_incl.add(new Polygon(new int[] { 0, 0, w, w }, new int[] { 0, h, h, 0 }, 4)); // for tif, jpeg and other normal images, compute the whole image (not ROIS), since we can store the deconvolved channels on harddisk, making post-processing faster.

        // union overlaping ROIS
        List<Rectangle> rects = new ArrayList();
        rects.add(rois_incl.get(0).getBounds());
        for (int z = 1; z < rois_incl.size(); z++) {
            for (int k = 0; k < rects.size(); k++) {
                if (rects.get(k).intersects(rois_incl.get(z).getBounds())) {
                    rects.get(k).add(rois_incl.get(z).getBounds());
                } else {
                    rects.add(rois_incl.get(z).getBounds());
                }
            }
        }

        for (int z = 0; z < rects.size(); z++) {
            Rectangle rect = rects.get(z);
            int r_w = rect.width;
            int r_h = rect.height;

            // Patchize the large ROI
            for (int i = 0; i < 1.0 * r_w / size; i++) {
                for (int j = 0; j < 1.0 * r_h / size; j++) {
                    int size_x = Math.min(size, r_w - i * size);
                    int size_y = Math.min(size, r_h - j * size);
                    sizes.add(new Point(size_x, size_y));
                    offsets.add(new Point(rect.x + i * size, rect.y + j * size));
                }
            }
        }

        StainingEstimationCoreThread sect = new StainingEstimationCoreThread(
                (TMARKERPluginManager) se.getPluginManager(), se, ts, radius, blur, tolerance, TMblur_hema,
                TMblur_dab, t_hema, t_dab, hide_legend, myStain, substractChannels, useThresholdMap,
                respectAreas, brown_spots_total, offsets, sizes, size);
        sect.start();
        sect.join();

    } catch (InterruptedException ex) {
        Logger.getLogger(StainingEstimation.class.getName()).log(Level.SEVERE, null, ex);
    }
    return brown_spots_total;
}