001package plugins.kernel.roi.descriptor.measure;
002
003import icy.roi.ROI;
004import icy.roi.ROIDescriptor;
005import icy.sequence.Sequence;
006import icy.type.point.Point5D;
007
008/**
009 * MassCenter X coordinate ROI descriptor class (see {@link ROIDescriptor})
010 * 
011 * @author Stephane
012 */
013public class ROIMassCenterXDescriptor extends ROIDescriptor
014{
015    public static final String ID = "Mass center X";
016
017    public ROIMassCenterXDescriptor()
018    {
019        super(ID, "Center X", Double.class);
020    }
021
022    @Override
023    public String getDescription()
024    {
025        return "Mass center X";
026    }
027
028    @Override
029    public Object compute(ROI roi, Sequence sequence) throws UnsupportedOperationException
030    {
031        return Double.valueOf(getMassCenterX(ROIMassCenterDescriptorsPlugin.computeMassCenter(roi)));
032    }
033
034    /**
035     * Returns position X of specified Point5D object
036     */
037    public static double getMassCenterX(Point5D point)
038    {
039        if (point == null)
040            return Double.NaN;
041
042        return point.getX();
043    }
044}