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