001/**
002 * 
003 */
004package plugins.kernel.roi.descriptor.property;
005
006import icy.plugin.abstract_.Plugin;
007import icy.plugin.interface_.PluginROIDescriptor;
008import icy.roi.ROI;
009import icy.roi.ROIDescriptor;
010import icy.sequence.Sequence;
011import icy.type.point.Point5D;
012
013import java.util.ArrayList;
014import java.util.HashMap;
015import java.util.List;
016import java.util.Map;
017
018/**
019 * This {@link PluginROIDescriptor} implements the position ROI descriptors:<br/>
020 * <li>Position X (in pixel)</li><br/>
021 * <li>Position Y (in pixel)</li><br/>
022 * <li>Position C (in pixel)</li><br/>
023 * <li>Position Z (in pixel)</li><br/>
024 * <li>Position T (in pixel)</li>
025 * 
026 * @author Stephane
027 */
028public class ROIPositionDescriptorsPlugin extends Plugin implements PluginROIDescriptor
029{
030    public static final String ID_POSITION_X = ROIPositionXDescriptor.ID;
031    public static final String ID_POSITION_Y = ROIPositionYDescriptor.ID;
032    public static final String ID_POSITION_Z = ROIPositionZDescriptor.ID;
033    public static final String ID_POSITION_T = ROIPositionTDescriptor.ID;
034    public static final String ID_POSITION_C = ROIPositionCDescriptor.ID;
035
036    public static final ROIPositionXDescriptor positionXDescriptor = new ROIPositionXDescriptor();
037    public static final ROIPositionYDescriptor positionYDescriptor = new ROIPositionYDescriptor();
038    public static final ROIPositionZDescriptor positionZDescriptor = new ROIPositionZDescriptor();
039    public static final ROIPositionTDescriptor positionTDescriptor = new ROIPositionTDescriptor();
040    public static final ROIPositionCDescriptor positionCDescriptor = new ROIPositionCDescriptor();
041
042    @Override
043    public List<ROIDescriptor> getDescriptors()
044    {
045        final List<ROIDescriptor> result = new ArrayList<ROIDescriptor>();
046
047        result.add(positionXDescriptor);
048        result.add(positionYDescriptor);
049        result.add(positionZDescriptor);
050        result.add(positionTDescriptor);
051        result.add(positionCDescriptor);
052
053        return result;
054    }
055
056    @Override
057    public Map<ROIDescriptor, Object> compute(ROI roi, Sequence sequence) throws UnsupportedOperationException
058    {
059        final Map<ROIDescriptor, Object> result = new HashMap<ROIDescriptor, Object>();
060
061        try
062        {
063            // compute position descriptors
064            final Point5D position = roi.getPosition5D();
065
066            result.put(positionXDescriptor, Double.valueOf(ROIPositionXDescriptor.getPositionX(position)));
067            result.put(positionYDescriptor, Double.valueOf(ROIPositionYDescriptor.getPositionY(position)));
068            result.put(positionZDescriptor, Double.valueOf(ROIPositionZDescriptor.getPositionZ(position)));
069            result.put(positionTDescriptor, Double.valueOf(ROIPositionTDescriptor.getPositionT(position)));
070            result.put(positionCDescriptor, Double.valueOf(ROIPositionCDescriptor.getPositionC(position)));
071        }
072        catch (Exception e)
073        {
074            final String mess = getClass().getSimpleName() + ": cannot compute descriptors for '" + roi.getName() + "'";
075            throw new UnsupportedOperationException(mess, e);
076        }
077
078        return result;
079    }
080}