001/**
002 * 
003 */
004package plugins.kernel.roi.roi3d;
005
006import icy.type.rectangle.Rectangle3D;
007
008import java.awt.geom.Ellipse2D;
009import java.awt.geom.Rectangle2D;
010
011import plugins.kernel.roi.roi2d.ROI2DEllipse;
012
013/**
014 * Class defining a 3D Ellipse ROI as a stack of individual 2D Ellipse ROI.
015 * 
016 * @author Stephane
017 */
018public class ROI3DStackEllipse extends ROI3DStackShape
019{
020    public ROI3DStackEllipse()
021    {
022        super(ROI2DEllipse.class);
023    }
024
025    public ROI3DStackEllipse(Rectangle3D rect)
026    {
027        this();
028
029        if (rect.isInfiniteZ())
030            throw new IllegalArgumentException("Cannot set infinite Z dimension on the 3D Stack Ellipse ROI.");
031
032        final Rectangle2D rect2d = rect.toRectangle2D();
033
034        beginUpdate();
035        try
036        {
037            for (int z = (int) Math.floor(rect.getMinZ()); z <= (int) rect.getMaxZ(); z++)
038                setSlice(z, new ROI2DEllipse(rect2d));
039        }
040        finally
041        {
042            endUpdate();
043        }
044    }
045
046    public ROI3DStackEllipse(Rectangle2D rect, int zMin, int zMax)
047    {
048        this();
049
050        if (zMax < zMin)
051            throw new IllegalArgumentException("ROI3DStackEllipse: cannot create the ROI (zMax < zMin).");
052
053        beginUpdate();
054        try
055        {
056            for (int z = zMin; z <= zMax; z++)
057                setSlice(z, new ROI2DEllipse(rect));
058        }
059        finally
060        {
061            endUpdate();
062        }
063    }
064
065    public ROI3DStackEllipse(Ellipse2D ellipse, int zMin, int zMax)
066    {
067        this(ellipse.getBounds2D(), zMin, zMax);
068    }
069
070    @Override
071    public String getDefaultName()
072    {
073        return "Ellipse2D stack";
074    }
075}