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