Example usage for java.awt.geom Path2D contains

List of usage examples for java.awt.geom Path2D contains

Introduction

In this page you can find the example usage for java.awt.geom Path2D contains.

Prototype

public static boolean contains(PathIterator pi, Rectangle2D r) 

Source Link

Document

Tests if the specified Rectangle2D is entirely inside the closed boundary of the specified PathIterator .

Usage

From source file:vteaexploration.plottools.panels.XYExplorationPanel.java

@Override
public int getGatedSelected(ImagePlus ip) {
    ArrayList<MicroObject> ImageGatedObjects = new ArrayList<MicroObject>();
    ArrayList<MicroObject> volumes = (ArrayList) plotvalues.get(1);
    try {/*from   w  w w  . j a v  a 2  s  .co  m*/
        ListIterator<MicroObject> itr = volumes.listIterator();
        while (itr.hasNext()) {
            MicroObject m = itr.next();
            int[] c = new int[2];
            c = m.getBoundsCenter();
            if (ip.getRoi().contains(c[0], c[1])) {
                ImageGatedObjects.add(m);
            }
        }
    } catch (NullPointerException e) {
        return 0;
    }

    Gate gate;
    ListIterator<Gate> gate_itr = gates.listIterator();
    ArrayList<MicroObject> result = new ArrayList<MicroObject>();

    while (gate_itr.hasNext()) {
        gate = gate_itr.next();
        if (gate.getSelected()) {
            Path2D path = gate.createPath2DInChartSpace();

            MicroObjectModel volume;
            double xValue = 0;
            double yValue = 0;

            ListIterator<MicroObject> it = ImageGatedObjects.listIterator();
            try {
                while (it.hasNext()) {
                    volume = it.next();
                    if (volume != null) {
                        xValue = ((Number) processPosition(currentX, (MicroObject) volume)).doubleValue();
                        yValue = ((Number) processPosition(currentY, (MicroObject) volume)).doubleValue();
                        if (path.contains(xValue, yValue)) {
                            result.add((MicroObject) volume);
                        }
                    }
                }
            } catch (NullPointerException e) {
                return 0;
            }
        }
    }
    return result.size();
}

From source file:vteaexploration.plottools.panels.XYExplorationPanel.java

@Override
public int getSelectedObjects() {
    Gate gate;//from   w ww .j  a  va  2  s . c om
    ListIterator<Gate> gate_itr = gates.listIterator();

    //.get
    int selected = 0;
    int gated = 0;
    int total = 0;

    ArrayList<MicroObject> result = new ArrayList<MicroObject>();

    while (gate_itr.hasNext()) {
        gate = gate_itr.next();
        if (gate.getSelected()) {
            Path2D path = gate.createPath2DInChartSpace();

            ArrayList<MicroObject> volumes = (ArrayList) this.plotvalues.get(1);
            MicroObjectModel volume;

            double xValue = 0;
            double yValue = 0;

            ListIterator<MicroObject> it = volumes.listIterator();
            try {
                while (it.hasNext()) {
                    volume = it.next();
                    if (volume != null) {
                        xValue = ((Number) processPosition(currentX, (MicroObject) volume)).doubleValue();
                        yValue = ((Number) processPosition(currentY, (MicroObject) volume)).doubleValue();
                        if (path.contains(xValue, yValue)) {
                            result.add((MicroObject) volume);
                        }
                    }
                }
            } catch (NullPointerException e) {
                return 0;
            }
        }
    }

    //System.out.println("RESULT: total gates " + gates.size() + ": " + this.getTitle() + ", Gated: " + selected + ", Total: " + total + ", for: " + 100 * (new Double(selected).doubleValue() / (new Double(total)).doubleValue()) + "%");
    return result.size();
}

From source file:vteaexploration.plottools.panels.XYExplorationPanel.java

public void makeOverlayImage(ArrayList gates, int x, int y, int xAxis, int yAxis) {
    //convert gate to chart x,y path

    Gate gate;//from   w  w w  .  ja va2 s .  c o  m
    ListIterator<Gate> gate_itr = gates.listIterator();

    //.get

    int total = 0;
    int gated = 0;
    int selected = 0;
    int gatedSelected = 0;

    int gatecount = gates.size();

    while (gate_itr.hasNext()) {
        gate = gate_itr.next();
        if (gate.getSelected()) {
            Path2D path = gate.createPath2DInChartSpace();

            ArrayList<MicroObject> result = new ArrayList<MicroObject>();

            ArrayList<MicroObject> volumes = (ArrayList) this.plotvalues.get(1);
            MicroObjectModel volume;

            double xValue = 0;
            double yValue = 0;

            ListIterator<MicroObject> it = volumes.listIterator();
            try {
                while (it.hasNext()) {
                    volume = it.next();
                    if (volume != null) {
                        xValue = ((Number) processPosition(xAxis, (MicroObject) volume)).doubleValue();
                        yValue = ((Number) processPosition(yAxis, (MicroObject) volume)).doubleValue();
                        if (path.contains(xValue, yValue)) {
                            result.add((MicroObject) volume);
                        }
                    }
                }
            } catch (NullPointerException e) {
            }
            ;

            Overlay overlay = new Overlay();

            int count = 0;
            BufferedImage placeholder = new BufferedImage(impoverlay.getWidth(), impoverlay.getHeight(),
                    BufferedImage.TYPE_INT_ARGB);

            ImageStack gateOverlay = new ImageStack(impoverlay.getWidth(), impoverlay.getHeight());

            selected = getSelectedObjects();

            total = volumes.size();

            gated = getGatedObjects(impoverlay);

            gatedSelected = getGatedSelected(impoverlay);

            for (int i = 0; i <= impoverlay.getNSlices(); i++) {
                BufferedImage selections = new BufferedImage(impoverlay.getWidth(), impoverlay.getHeight(),
                        BufferedImage.TYPE_INT_ARGB);

                Graphics2D g2 = selections.createGraphics();

                ImageRoi ir = new ImageRoi(0, 0, placeholder);
                ListIterator<MicroObject> vitr = result.listIterator();

                while (vitr.hasNext()) {
                    try {
                        MicroObject vol = (MicroObject) vitr.next();

                        int[] x_pixels = vol.getXPixelsInRegion(i);
                        int[] y_pixels = vol.getYPixelsInRegion(i);

                        for (int c = 0; c < x_pixels.length; c++) {

                            g2.setColor(gate.getColor());
                            g2.drawRect(x_pixels[c], y_pixels[c], 1, 1);
                        }
                        ir = new ImageRoi(0, 0, selections);
                        count++;

                    } catch (NullPointerException e) {
                    }
                }

                ir.setPosition(i);
                ir.setOpacity(0.4);
                overlay.add(ir);

                gateOverlay.addSlice(ir.getProcessor());

                java.awt.Font f = new Font("Arial", Font.BOLD, 12);
                BigDecimal percentage = new BigDecimal(selected);
                BigDecimal totalBD = new BigDecimal(total);
                percentage = percentage.divide(totalBD, 4, BigDecimal.ROUND_UP);

                BigDecimal percentageGated = new BigDecimal(gated);
                BigDecimal totalGatedBD = new BigDecimal(total);
                percentageGated = percentageGated.divide(totalGatedBD, 4, BigDecimal.ROUND_UP);

                BigDecimal percentageGatedSelected = new BigDecimal(gatedSelected);
                BigDecimal totalGatedSelectedBD = new BigDecimal(total);
                percentageGatedSelected = percentageGatedSelected.divide(totalGatedSelectedBD, 4,
                        BigDecimal.ROUND_UP);

                // System.out.println("PROFILING: gate fraction: " + percentage.toString());
                if (impoverlay.getWidth() > 256) {

                    TextRoi textTotal = new TextRoi(5, 10,
                            selected + "/" + total + " gated (" + 100 * percentage.doubleValue() + "%)");

                    if (gated > 0) {
                        textTotal = new TextRoi(5, 10, selected + "/" + total + " total ("
                                + 100 * percentage.doubleValue() + "%)" + "; " + gated + "/" + total + " roi ("
                                + 100 * percentageGated.doubleValue() + "%)" + "; " + gatedSelected + "/"
                                + total + " overlap (" + 100 * percentageGatedSelected.doubleValue() + "%)", f);
                    }
                    //TextRoi textImageGated = new TextRoi(5, 18, selected + "/" + total + " gated objects (" + 100 * percentage.doubleValue() + "%)", f);
                    textTotal.setPosition(i);
                    //textImageGated.setPosition(i);
                    overlay.add(textTotal);
                } else {
                    f = new Font("Arial", Font.PLAIN, 10);
                    TextRoi line1 = new TextRoi(5, 5,
                            selected + "/" + total + " gated" + "(" + 100 * percentage.doubleValue() + "%)", f);
                    overlay.add(line1);
                    if (gated > 0) {
                        f = new Font("Arial", Font.PLAIN, 10);
                        TextRoi line2 = new TextRoi(5, 18,
                                gated + "/" + total + " roi (" + 100 * percentageGated.doubleValue() + "%)", f);
                        overlay.add(line2);
                        TextRoi line3 = new TextRoi(5, 31, gatedSelected + "/" + total + " overlap ("
                                + 100 * percentageGatedSelected.doubleValue() + "%)", f);
                        overlay.add(line3);
                    }
                    line1.setPosition(i);

                }
            }
            impoverlay.setOverlay(overlay);

            //ImagePlus gateMaskImage = new ImagePlus("gates", gateOverlay);

            //gateMaskImage.show();

            gate.setGateOverlayStack(gateOverlay);

        }

        impoverlay.draw();
        impoverlay.setTitle(this.getTitle());

        if (impoverlay.getDisplayMode() != IJ.COMPOSITE) {
            impoverlay.setDisplayMode(IJ.COMPOSITE);
        }

        if (impoverlay.getSlice() == 1) {
            impoverlay.setZ(Math.round(impoverlay.getNSlices() / 2));
        } else {
            impoverlay.setSlice(impoverlay.getSlice());
        }
        impoverlay.show();
    }
}