001/**
002 * 
003 */
004package icy.type.dimension;
005
006import java.awt.Dimension;
007
008/**
009 * The <code>Dimension5D</code> class is to encapsulate a 4D dimension (X,Y,Z,T).
010 * 
011 * @author Stephane
012 */
013public abstract class Dimension5D implements Cloneable
014{
015    /**
016     * Returns the size of the X dimension in double precision.
017     * 
018     * @return the size of the X dimension.
019     */
020    public abstract double getSizeX();
021
022    /**
023     * Returns the size of the Y dimension in double precision.
024     * 
025     * @return the size of the Y dimension.
026     */
027    public abstract double getSizeY();
028
029    /**
030     * Returns the size of the Z dimension in double precision.
031     * 
032     * @return the size of the Z dimension.
033     */
034    public abstract double getSizeZ();
035
036    /**
037     * Returns the size of the T dimension in double precision.
038     * 
039     * @return the size of the T dimension.
040     */
041    public abstract double getSizeT();
042
043    /**
044     * Returns the size of the C dimension in double precision.
045     * 
046     * @return the size of the C dimension.
047     */
048    public abstract double getSizeC();
049
050    /**
051     * Sets the size of the X dimension of this <code>Dimension5D</code> in <code>double</code>
052     * precision.
053     */
054    public abstract void setSizeX(double value);
055
056    /**
057     * Sets the size of the Y dimension of this <code>Dimension5D</code> in <code>double</code>
058     * precision.
059     */
060    public abstract void setSizeY(double value);
061
062    /**
063     * Sets the size of the Z dimension of this <code>Dimension5D</code> in <code>double</code>
064     * precision.
065     */
066    public abstract void setSizeZ(double value);
067
068    /**
069     * Sets the size of the T dimension of this <code>Dimension5D</code> in <code>double</code>
070     * precision.
071     */
072    public abstract void setSizeT(double value);
073
074    /**
075     * Sets the size of the C dimension of this <code>Dimension5D</code> in <code>double</code>
076     * precision.
077     */
078    public abstract void setSizeC(double value);
079
080    /**
081     * Sets the size of this <code>Dimension5D</code> object.
082     * 
083     * @param sizeX
084     *        the new size for the X dimension
085     * @param sizeY
086     *        the new size for the Y dimension
087     * @param sizeZ
088     *        the new size for the Z dimension
089     * @param sizeT
090     *        the new size for the T dimension
091     * @param sizeC
092     *        the new size for the C dimension
093     */
094    public abstract void setSize(double sizeX, double sizeY, double sizeZ, double sizeT, double sizeC);
095
096    /**
097     * Sets the size of this <code>Dimension5D</code> object to match the specified size.
098     * 
099     * @param d
100     *        the new size for the <code>Dimension5D</code> object
101     */
102    public void setSize(Dimension5D d)
103    {
104        setSize(d.getSizeX(), d.getSizeY(), d.getSizeZ(), d.getSizeT(), d.getSizeC());
105    }
106
107    /**
108     * Returns <code>true</code> if the X dimension should be considered as infinite.
109     */
110    public abstract boolean isInfiniteX();
111
112    /**
113     * Returns <code>true</code> if the Y dimension should be considered as infinite.
114     */
115    public abstract boolean isInfiniteY();
116
117    /**
118     * Returns <code>true</code> if the Z dimension should be considered as infinite.
119     */
120    public abstract boolean isInfiniteZ();
121
122    /**
123     * Returns <code>true</code> if the T dimension should be considered as infinite.
124     */
125    public abstract boolean isInfiniteT();
126
127    /**
128     * Returns <code>true</code> if the C dimension should be considered as infinite.
129     */
130    public abstract boolean isInfiniteC();
131
132    /**
133     * Convert to 2D dimension.
134     */
135    public abstract java.awt.geom.Dimension2D toDimension2D();
136
137    /**
138     * Convert to 3D dimension.
139     */
140    public abstract Dimension3D toDimension3D();
141
142    /**
143     * Convert to 4D dimension.
144     */
145    public abstract Dimension4D toDimension4D();
146
147    /**
148     * Returns an integer {@link Dimension5D} that encloses the double <code>Dimension5D</code>.<br>
149     * The returned <code>Dimension5D.Integer</code> might also fail to completely enclose the
150     * original double <code>Dimension5D</code> if it overflows the limited range of the integer
151     * data type.
152     * 
153     * @return an integer <code>Dimension5D</code> that completely encloses
154     *         the actual double <code>Dimension5D</code>.
155     */
156
157    public Dimension5D.Integer toInteger()
158    {
159        return new Dimension5D.Integer((int) Math.ceil(getSizeX()), (int) Math.ceil(getSizeY()),
160                (int) Math.ceil(getSizeZ()), (int) Math.ceil(getSizeT()), (int) Math.ceil(getSizeC()));
161    }
162
163    @Override
164    public boolean equals(Object obj)
165    {
166        if (obj instanceof Dimension5D)
167        {
168            final Dimension5D dim = (Dimension5D) obj;
169            return (getSizeX() == dim.getSizeX()) && (getSizeY() == dim.getSizeY()) && (getSizeZ() == dim.getSizeZ())
170                    && (getSizeT() == dim.getSizeT()) && (getSizeC() == dim.getSizeC());
171        }
172
173        return super.equals(obj);
174    }
175
176    /**
177     * Creates a new object of the same class as this object.
178     * 
179     * @return a clone of this instance.
180     * @exception OutOfMemoryError
181     *            if there is not enough memory.
182     * @see java.lang.Cloneable
183     */
184    @Override
185    public Object clone()
186    {
187        try
188        {
189            return super.clone();
190        }
191        catch (CloneNotSupportedException e)
192        {
193            // this shouldn't happen, since we are Cloneable
194            throw new InternalError();
195        }
196    }
197
198    @Override
199    public String toString()
200    {
201        return getClass().getName() + "[" + getSizeX() + "," + getSizeY() + "," + getSizeZ() + "," + getSizeT() + ","
202                + getSizeC() + "]";
203    }
204
205    public static class Double extends Dimension5D
206    {
207        public double sizeX;
208        public double sizeY;
209        public double sizeZ;
210        public double sizeT;
211        public double sizeC;
212
213        public Double(double sizeX, double sizeY, double sizeZ, double sizeT, double sizeC)
214        {
215            super();
216
217            this.sizeX = sizeX;
218            this.sizeY = sizeY;
219            this.sizeZ = sizeZ;
220            this.sizeT = sizeT;
221            this.sizeC = sizeC;
222        }
223
224        public Double(double[] sizeXYZTC)
225        {
226            final int len = sizeXYZTC.length;
227
228            if (len > 0)
229                this.sizeX = sizeXYZTC[0];
230            if (len > 1)
231                this.sizeY = sizeXYZTC[1];
232            if (len > 2)
233                this.sizeZ = sizeXYZTC[2];
234            if (len > 3)
235                this.sizeT = sizeXYZTC[3];
236            if (len > 3)
237                this.sizeC = sizeXYZTC[4];
238        }
239
240        public Double()
241        {
242            this(0d, 0d, 0d, 0d, 0d);
243        }
244
245        @Override
246        public double getSizeX()
247        {
248            return sizeX;
249        }
250
251        @Override
252        public double getSizeY()
253        {
254            return sizeY;
255        }
256
257        @Override
258        public double getSizeZ()
259        {
260            return sizeZ;
261        }
262
263        @Override
264        public double getSizeT()
265        {
266            return sizeT;
267        }
268
269        @Override
270        public double getSizeC()
271        {
272            return sizeC;
273        }
274
275        @Override
276        public void setSizeX(double value)
277        {
278            sizeX = value;
279        }
280
281        @Override
282        public void setSizeY(double value)
283        {
284            sizeY = value;
285        }
286
287        @Override
288        public void setSizeZ(double value)
289        {
290            sizeZ = value;
291        }
292
293        @Override
294        public void setSizeT(double value)
295        {
296            sizeT = value;
297        }
298
299        @Override
300        public void setSizeC(double value)
301        {
302            sizeC = value;
303        }
304
305        @Override
306        public boolean isInfiniteX()
307        {
308            return (getSizeX() == java.lang.Double.POSITIVE_INFINITY);
309        }
310
311        @Override
312        public boolean isInfiniteY()
313        {
314            return (getSizeY() == java.lang.Double.POSITIVE_INFINITY);
315        }
316
317        @Override
318        public boolean isInfiniteZ()
319        {
320            return (getSizeZ() == java.lang.Double.POSITIVE_INFINITY);
321        }
322
323        @Override
324        public boolean isInfiniteT()
325        {
326            return (getSizeT() == java.lang.Double.POSITIVE_INFINITY);
327        }
328
329        @Override
330        public boolean isInfiniteC()
331        {
332            return (getSizeC() == java.lang.Double.POSITIVE_INFINITY);
333        }
334
335        @Override
336        public void setSize(double sizeX, double sizeY, double sizeZ, double sizeT, double sizeC)
337        {
338            this.sizeX = sizeX;
339            this.sizeY = sizeY;
340            this.sizeZ = sizeZ;
341            this.sizeT = sizeT;
342            this.sizeC = sizeC;
343        }
344
345        @Override
346        public java.awt.geom.Dimension2D toDimension2D()
347        {
348            return new Dimension2D.Double(sizeX, sizeY);
349        }
350
351        @Override
352        public Dimension3D toDimension3D()
353        {
354            return new Dimension3D.Double(sizeX, sizeY, sizeZ);
355        }
356
357        @Override
358        public Dimension4D toDimension4D()
359        {
360            return new Dimension4D.Double(sizeX, sizeY, sizeZ, sizeT);
361        }
362    }
363
364    public static class Float extends Dimension5D
365    {
366        public float sizeX;
367        public float sizeY;
368        public float sizeZ;
369        public float sizeT;
370        public float sizeC;
371
372        public Float(float sizeX, float sizeY, float sizeZ, float sizeT, float sizeC)
373        {
374            super();
375
376            this.sizeX = sizeX;
377            this.sizeY = sizeY;
378            this.sizeZ = sizeZ;
379            this.sizeT = sizeT;
380            this.sizeC = sizeC;
381        }
382
383        public Float(float[] sizeXYZTC)
384        {
385            final int len = sizeXYZTC.length;
386
387            if (len > 0)
388                this.sizeX = sizeXYZTC[0];
389            if (len > 1)
390                this.sizeY = sizeXYZTC[1];
391            if (len > 2)
392                this.sizeZ = sizeXYZTC[2];
393            if (len > 3)
394                this.sizeT = sizeXYZTC[3];
395            if (len > 3)
396                this.sizeC = sizeXYZTC[4];
397        }
398
399        public Float()
400        {
401            this(0f, 0f, 0f, 0f, 0f);
402        }
403
404        @Override
405        public double getSizeX()
406        {
407            return sizeX;
408        }
409
410        @Override
411        public double getSizeY()
412        {
413            return sizeY;
414        }
415
416        @Override
417        public double getSizeZ()
418        {
419            return sizeZ;
420        }
421
422        @Override
423        public double getSizeT()
424        {
425            return sizeT;
426        }
427
428        @Override
429        public double getSizeC()
430        {
431            return sizeC;
432        }
433
434        @Override
435        public void setSizeX(double value)
436        {
437            sizeX = (float) value;
438        }
439
440        @Override
441        public void setSizeY(double value)
442        {
443            sizeY = (float) value;
444        }
445
446        @Override
447        public void setSizeZ(double value)
448        {
449            sizeZ = (float) value;
450        }
451
452        @Override
453        public void setSizeT(double value)
454        {
455            sizeT = (float) value;
456        }
457
458        @Override
459        public void setSizeC(double value)
460        {
461            sizeC = (float) value;
462        }
463
464        @Override
465        public boolean isInfiniteX()
466        {
467            return (getSizeX() == java.lang.Float.POSITIVE_INFINITY);
468        }
469
470        @Override
471        public boolean isInfiniteY()
472        {
473            return (getSizeY() == java.lang.Float.POSITIVE_INFINITY);
474        }
475
476        @Override
477        public boolean isInfiniteZ()
478        {
479            return (getSizeZ() == java.lang.Float.POSITIVE_INFINITY);
480        }
481
482        @Override
483        public boolean isInfiniteT()
484        {
485            return (getSizeT() == java.lang.Float.POSITIVE_INFINITY);
486        }
487
488        @Override
489        public boolean isInfiniteC()
490        {
491            return (getSizeC() == java.lang.Float.POSITIVE_INFINITY);
492        }
493
494        @Override
495        public void setSize(double sizeX, double sizeY, double sizeZ, double sizeT, double sizeC)
496        {
497            this.sizeX = (float) sizeX;
498            this.sizeY = (float) sizeY;
499            this.sizeZ = (float) sizeZ;
500            this.sizeT = (float) sizeT;
501            this.sizeC = (float) sizeC;
502        }
503
504        @Override
505        public java.awt.geom.Dimension2D toDimension2D()
506        {
507            return new Dimension2D.Float(sizeX, sizeY);
508        }
509
510        @Override
511        public Dimension3D toDimension3D()
512        {
513            return new Dimension3D.Float(sizeX, sizeY, sizeZ);
514        }
515
516        @Override
517        public Dimension4D toDimension4D()
518        {
519            return new Dimension4D.Float(sizeX, sizeY, sizeZ, sizeT);
520        }
521
522    }
523
524    public static class Integer extends Dimension5D
525    {
526        public int sizeX;
527        public int sizeY;
528        public int sizeZ;
529        public int sizeT;
530        public int sizeC;
531
532        public Integer(int sizeX, int sizeY, int sizeZ, int sizeT, int sizeC)
533        {
534            super();
535
536            this.sizeX = sizeX;
537            this.sizeY = sizeY;
538            this.sizeZ = sizeZ;
539            this.sizeT = sizeT;
540            this.sizeC = sizeC;
541        }
542
543        public Integer(int[] sizeXYZTC)
544        {
545            final int len = sizeXYZTC.length;
546
547            if (len > 0)
548                this.sizeX = sizeXYZTC[0];
549            if (len > 1)
550                this.sizeY = sizeXYZTC[1];
551            if (len > 2)
552                this.sizeZ = sizeXYZTC[2];
553            if (len > 3)
554                this.sizeT = sizeXYZTC[3];
555            if (len > 4)
556                this.sizeC = sizeXYZTC[4];
557        }
558
559        public Integer()
560        {
561            this(0, 0, 0, 0, 0);
562        }
563
564        @Override
565        public double getSizeX()
566        {
567            return sizeX;
568        }
569
570        @Override
571        public double getSizeY()
572        {
573            return sizeY;
574        }
575
576        @Override
577        public double getSizeZ()
578        {
579            return sizeZ;
580        }
581
582        @Override
583        public double getSizeT()
584        {
585            return sizeT;
586        }
587
588        @Override
589        public double getSizeC()
590        {
591            return sizeC;
592        }
593
594        @Override
595        public void setSizeX(double value)
596        {
597            sizeX = (int) Math.ceil(value);
598        }
599
600        @Override
601        public void setSizeY(double value)
602        {
603            sizeY = (int) Math.ceil(value);
604        }
605
606        @Override
607        public void setSizeZ(double value)
608        {
609            sizeZ = (int) Math.ceil(value);
610        }
611
612        @Override
613        public void setSizeT(double value)
614        {
615            sizeT = (int) Math.ceil(value);
616        }
617
618        @Override
619        public void setSizeC(double value)
620        {
621            sizeC = (int) Math.ceil(value);
622        }
623
624        @Override
625        public boolean isInfiniteX()
626        {
627            return (getSizeX() == java.lang.Integer.MAX_VALUE);
628        }
629
630        @Override
631        public boolean isInfiniteY()
632        {
633            return (getSizeY() == java.lang.Integer.MAX_VALUE);
634        }
635
636        @Override
637        public boolean isInfiniteZ()
638        {
639            return (getSizeZ() == java.lang.Integer.MAX_VALUE);
640        }
641
642        @Override
643        public boolean isInfiniteT()
644        {
645            return (getSizeT() == java.lang.Integer.MAX_VALUE);
646        }
647
648        @Override
649        public boolean isInfiniteC()
650        {
651            return (getSizeC() == java.lang.Integer.MAX_VALUE);
652        }
653
654        @Override
655        public void setSize(double sizeX, double sizeY, double sizeZ, double sizeT, double sizeC)
656        {
657            this.sizeX = (int) Math.ceil(sizeX);
658            this.sizeY = (int) Math.ceil(sizeY);
659            this.sizeZ = (int) Math.ceil(sizeZ);
660            this.sizeT = (int) Math.ceil(sizeT);
661            this.sizeC = (int) Math.ceil(sizeC);
662        }
663
664        @Override
665        public java.awt.geom.Dimension2D toDimension2D()
666        {
667            return new Dimension(sizeX, sizeY);
668        }
669
670        @Override
671        public Dimension3D toDimension3D()
672        {
673            return new Dimension3D.Integer(sizeX, sizeY, sizeZ);
674        }
675
676        @Override
677        public Dimension4D toDimension4D()
678        {
679            return new Dimension4D.Integer(sizeX, sizeY, sizeZ, sizeT);
680        }
681
682        @Override
683        public Integer toInteger()
684        {
685            return (Integer) clone();
686        }
687    }
688}