001/**
002 * 
003 */
004package plugins.kernel.roi.descriptor.measure;
005
006import icy.roi.ROI;
007import icy.roi.ROIDescriptor;
008import icy.sequence.Sequence;
009
010/**
011 * Contour ROI descriptor class (see {@link ROIDescriptor})
012 * 
013 * @author Stephane
014 */
015public class ROIContourDescriptor extends ROIDescriptor
016{
017    public static final String ID = "Contour";
018
019    public ROIContourDescriptor()
020    {
021        super(ID, "Contour", Double.class);
022    }
023
024    @Override
025    public String getUnit(Sequence sequence)
026    {
027        return "px";
028    }
029
030    @Override
031    public String getDescription()
032    {
033        return "Number of points for the contour";
034    }
035
036    @Override
037    public Object compute(ROI roi, Sequence sequence) throws UnsupportedOperationException
038    {
039        return Double.valueOf(computeContour(roi));
040    }
041
042    /**
043     * Returns the number of contour point for the specified ROI.
044     * 
045     * @param roi
046     *        the ROI on which we want to compute the number of contour point
047     * @return the number of contour point
048     */
049    public static double computeContour(ROI roi)
050    {
051        return roi.getNumberOfContourPoints();
052    }
053
054//    /**
055//     * Returns the contour size from a given number of contour points in the best unit (see
056//     * {@link Sequence#getBestPixelSizeUnit(int, int)}) for the specified sequence and dimension.<br>
057//     * <ul>
058//     * Ex:
059//     * <li>getContourSize(sequence, roi, 2) return the perimeter value</li>
060//     * <li>getContourSize(sequence, roi, 3) return the surface area value</li>
061//     * </ul>
062//     * It may returns <code>Double.Nan</code> if the operation is not supported for that ROI.
063//     * 
064//     * @param contourPoints
065//     *        the number of contour points (override the ROI value)
066//     * @param roi
067//     *        the ROI we want to compute the contour size
068//     * @param sequence
069//     *        the input sequence used to retrieve operation unit by using pixel size information.
070//     * @param dim
071//     *        the dimension for the contour size operation (2 = perimeter, 3 = surface area, ...)
072//     * @return the number of contour point
073//     * @see Sequence#getBestPixelSizeUnit(int, int)
074//     * @throws UnsupportedOperationException
075//     *         if the contour calculation for the specified dimension is not supported by the ROI
076//     */
077//    public static double computeContour(double contourPoints, ROI roi, Sequence sequence, int dim)
078//            throws UnsupportedOperationException
079//    {
080//        final double mul = ROIBasicMeasureDescriptorsPlugin.getMultiplierFactor(sequence, roi, dim);
081//
082//        // 0 means the operation is not supported for this ROI
083//        if (mul == 0d)
084//            throw new UnsupportedOperationException("Can't process '" + ID + "' calculation for dimension " + dim
085//                    + " on the ROI: " + roi.getName());
086//
087//        return sequence.calculateSizeBestUnit(contourPoints * mul, dim, dim - 1);
088//    }
089}