001package plugins.kernel.roi.descriptor.property;
002
003import icy.plugin.abstract_.Plugin;
004import icy.plugin.interface_.PluginROIDescriptor;
005import icy.roi.ROI;
006import icy.roi.ROIDescriptor;
007import icy.sequence.Sequence;
008import icy.type.rectangle.Rectangle5D;
009
010import java.util.ArrayList;
011import java.util.HashMap;
012import java.util.List;
013import java.util.Map;
014
015/**
016 * This {@link PluginROIDescriptor} implements the size ROI descriptors:<br/>
017 * <li>Size X (in pixel)</li><br/>
018 * <li>Size Y (in pixel)</li><br/>
019 * <li>Size C (in pixel)</li><br/>
020 * <li>Size Z (in pixel)</li><br/>
021 * <li>Size T (in pixel)</li>
022 * 
023 * @author Stephane
024 */
025public class ROISizeDescriptorsPlugin extends Plugin implements PluginROIDescriptor
026{
027    public static final String ID_SIZE_X = ROISizeXDescriptor.ID;
028    public static final String ID_SIZE_Y = ROISizeYDescriptor.ID;
029    public static final String ID_SIZE_Z = ROISizeZDescriptor.ID;
030    public static final String ID_SIZE_T = ROISizeTDescriptor.ID;
031    public static final String ID_SIZE_C = ROISizeCDescriptor.ID;
032
033    public static final ROISizeXDescriptor sizeXDescriptor = new ROISizeXDescriptor();
034    public static final ROISizeYDescriptor sizeYDescriptor = new ROISizeYDescriptor();
035    public static final ROISizeZDescriptor sizeZDescriptor = new ROISizeZDescriptor();
036    public static final ROISizeTDescriptor sizeTDescriptor = new ROISizeTDescriptor();
037    public static final ROISizeCDescriptor sizeCDescriptor = new ROISizeCDescriptor();
038
039    @Override
040    public List<ROIDescriptor> getDescriptors()
041    {
042        final List<ROIDescriptor> result = new ArrayList<ROIDescriptor>();
043
044        result.add(sizeXDescriptor);
045        result.add(sizeYDescriptor);
046        result.add(sizeZDescriptor);
047        result.add(sizeTDescriptor);
048        result.add(sizeCDescriptor);
049
050        return result;
051    }
052
053    @Override
054    public Map<ROIDescriptor, Object> compute(ROI roi, Sequence sequence) throws UnsupportedOperationException
055    {
056        final Map<ROIDescriptor, Object> result = new HashMap<ROIDescriptor, Object>();
057
058        try
059        {
060            // compute size descriptors
061            final Rectangle5D size = roi.getBounds5D();
062
063            result.put(sizeXDescriptor, Double.valueOf(ROISizeXDescriptor.getSizeX(size)));
064            result.put(sizeYDescriptor, Double.valueOf(ROISizeYDescriptor.getSizeY(size)));
065            result.put(sizeZDescriptor, Double.valueOf(ROISizeZDescriptor.getSizeZ(size)));
066            result.put(sizeTDescriptor, Double.valueOf(ROISizeTDescriptor.getSizeT(size)));
067            result.put(sizeCDescriptor, Double.valueOf(ROISizeCDescriptor.getSizeC(size)));
068        }
069        catch (Exception e)
070        {
071            final String mess = getClass().getSimpleName() + ": cannot compute descriptors for '" + roi.getName() + "'";
072            throw new UnsupportedOperationException(mess, e);
073        }
074
075        return result;
076    }
077}