Parses the geometry of this ROI's shape by means of the shape's PathIterator; Depending on the task and rois argument it will: - create a single non-Shape Roi and add it to rois in case there is only one subpath, otherwise add this Roi unchanged to <c
(PathIterator pIter, int task, ArrayList rois)
| 791 | * (see @link #shapeToRois()} for details; |
| 792 | * @return Total length if task = GET_LENGTH.*/ |
| 793 | double parsePath(PathIterator pIter, int task, ArrayList rois) { |
| 794 | if (pIter==null || pIter.isDone()) |
| 795 | return 0.0; |
| 796 | double pw = 1.0, ph = 1.0; |
| 797 | if (imp!=null) { |
| 798 | Calibration cal = imp.getCalibration(); |
| 799 | pw = cal.pixelWidth; |
| 800 | ph = cal.pixelHeight; |
| 801 | } |
| 802 | float xbase = (float)getXBase(); |
| 803 | float ybase = (float)getYBase(); |
| 804 | |
| 805 | FloatArray xPoints = new FloatArray(); //vertex coordinates of current subpath |
| 806 | FloatArray yPoints = new FloatArray(); |
| 807 | FloatArray shapeArray = new FloatArray(); //values for creating a GeneralPath for the current subpath |
| 808 | boolean getLength = task == GET_LENGTH; |
| 809 | int nSubPaths = 0; // the number of subpaths |
| 810 | boolean horVertOnly = true; // subpath has only horizontal or vertical lines |
| 811 | boolean closed = false; |
| 812 | //boolean success = false; |
| 813 | float[] fcoords = new float[6]; // unscaled float coordinates of the path segment |
| 814 | double[] coords = new double[6]; // scaled (calibrated) coordinates of the path segment |
| 815 | double startCalX = 0.0; // start x of subpath (scaled) |
| 816 | double startCalY = 0.0; // start y of subpath (scaled) |
| 817 | double lastCalX = 0.0; // x of previous point in the subpath (scaled) |
| 818 | double lastCalY = 0.0; // y of previous point in the subpath (scaled) |
| 819 | double pathLength = 0.0; // calibrated pathLength/perimeter of current curve |
| 820 | double totalLength = 0.0; // sum of all calibrated path lengths/perimeters |
| 821 | double uncalLength = 0.0; // uncalibrated length of polygon, NaN in case of curves |
| 822 | boolean done = false; |
| 823 | while (true) { |
| 824 | int segType = done ? NO_SEGMENT_ANY_MORE : pIter.currentSegment(fcoords); //read segment (if there is one more) |
| 825 | int nCoords = 0; //will be number of coordinates supplied with the segment |
| 826 | if (!done) { |
| 827 | nCoords = nCoords(segType); |
| 828 | if (getLength) { //make scaled coodinates to calculate the length |
| 829 | pIter.currentSegment(coords); |
| 830 | scaleCoords(coords, nCoords, pw, ph); |
| 831 | } |
| 832 | pIter.next(); |
| 833 | done = pIter.isDone(); |
| 834 | } |
| 835 | |
| 836 | //IJ.log("segType="+segType+" nCoord="+nCoords+" done="+done+" nPoi="+nPoints+" len="+pathLength); |
| 837 | if (segType == NO_SEGMENT_ANY_MORE || (segType == PathIterator.SEG_MOVETO && xPoints.size()>0)) { |
| 838 | // subpath finished: analyze it & create roi if appropriate |
| 839 | closed = closed || (xPoints.size()>0 && xPoints.get(0) == xPoints.getLast() && yPoints.get(0) == yPoints.getLast()); |
| 840 | float[] xpf = xPoints.toArray(); |
| 841 | float[] ypf = yPoints.toArray(); |
| 842 | if (Double.isNaN(uncalLength) || !allInteger(xpf) || !allInteger(ypf)) |
| 843 | horVertOnly = false; //allow conversion to rectangle or traced roi only for integer coordinates |
| 844 | boolean forceTrace = getLength && (!done || nSubPaths>0); //when calculating the length for >1 subpath, assume traced rois if it can be such |
| 845 | int roiType = guessType(xPoints.size(), uncalLength, horVertOnly, forceTrace, closed); |
| 846 | Roi roi = null; |
| 847 | if (roiType == COMPOSITE && rois != null) { //for ShapeRois with curves, we have the length from the path already, make roi only if needed |
| 848 | Shape shape = makeShapeFromArray(shapeArray.toArray()); //the curved subpath (image pixel coordinates) |
| 849 | FloatPolygon fp = getFloatPolygon(shape, FLATNESS, /*separateSubpaths=*/ false, /*addPointForClose=*/ false, /*absoluteCoord=*/ false); |
| 850 | roi = new PolygonRoi(fp, FREEROI); |
no test coverage detected