001/* 002 * Copyright 2010-2015 Institut Pasteur. 003 * 004 * This file is part of Icy. 005 * 006 * Icy is free software: you can redistribute it and/or modify 007 * it under the terms of the GNU General Public License as published by 008 * the Free Software Foundation, either version 3 of the License, or 009 * (at your option) any later version. 010 * 011 * Icy is distributed in the hope that it will be useful, 012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 014 * GNU General Public License for more details. 015 * 016 * You should have received a copy of the GNU General Public License 017 * along with Icy. If not, see <http://www.gnu.org/licenses/>. 018 */ 019package icy.type.point; 020 021import java.awt.Point; 022import java.awt.geom.Point2D; 023 024/** 025 * Point5D interface.<br> 026 * Incomplete implementation (work in progress...) 027 * 028 * @author Stephane 029 */ 030public abstract class Point5D implements Cloneable 031{ 032 /** 033 * Returns the X coordinate of this <code>Point5D</code> in <code>double</code> precision. 034 * 035 * @return the X coordinate of this <code>Point5D</code>. 036 */ 037 public abstract double getX(); 038 039 /** 040 * Returns the Y coordinate of this <code>Point5D</code> in <code>double</code> precision. 041 * 042 * @return the Y coordinate of this <code>Point5D</code>. 043 */ 044 public abstract double getY(); 045 046 /** 047 * Returns the Z coordinate of this <code>Point5D</code> in <code>double</code> precision. 048 * 049 * @return the Z coordinate of this <code>Point5D</code>. 050 */ 051 public abstract double getZ(); 052 053 /** 054 * Returns the T coordinate of this <code>Point5D</code> in <code>double</code> precision. 055 * 056 * @return the T coordinate of this <code>Point5D</code>. 057 */ 058 public abstract double getT(); 059 060 /** 061 * Returns the C coordinate of this <code>Point5D</code> in <code>double</code> precision. 062 * 063 * @return the C coordinate of this <code>Point5D</code>. 064 */ 065 public abstract double getC(); 066 067 /** 068 * Sets the X coordinate of this <code>Point5D</code> in <code>double</code> precision. 069 */ 070 public abstract void setX(double x); 071 072 /** 073 * Sets the Y coordinate of this <code>Point5D</code> in <code>double</code> precision. 074 */ 075 public abstract void setY(double y); 076 077 /** 078 * Sets the Z coordinate of this <code>Point5D</code> in <code>double</code> precision. 079 */ 080 public abstract void setZ(double z); 081 082 /** 083 * Sets the T coordinate of this <code>Point5D</code> in <code>double</code> precision. 084 */ 085 public abstract void setT(double t); 086 087 /** 088 * Sets the C coordinate of this <code>Point5D</code> in <code>double</code> precision. 089 */ 090 public abstract void setC(double c); 091 092 /** 093 * Sets the location of this <code>Point5D</code> to the 094 * specified <code>double</code> coordinates. 095 * 096 * @param x 097 * the new X coordinate of this {@code Point5D} 098 * @param y 099 * the new Y coordinate of this {@code Point5D} 100 * @param z 101 * the new Z coordinate of this {@code Point5D} 102 * @param t 103 * the new T coordinate of this {@code Point5D} 104 * @param c 105 * the new C coordinate of this {@code Point5D} 106 */ 107 public void setLocation(double x, double y, double z, double t, double c) 108 { 109 setX(x); 110 setY(y); 111 setZ(z); 112 setT(t); 113 setC(c); 114 } 115 116 /** 117 * Sets the location of this <code>Point5D</code> to the same 118 * coordinates as the specified <code>Point5D</code> object. 119 * 120 * @param p 121 * the specified <code>Point5D</code> to which to set 122 * this <code>Point5D</code> 123 */ 124 public void setLocation(Point5D p) 125 { 126 setLocation(p.getX(), p.getY(), p.getZ(), p.getT(), p.getC()); 127 } 128 129 /** 130 * Convert to 2D point 131 */ 132 public abstract Point2D toPoint2D(); 133 134 /** 135 * Convert to 3D point 136 */ 137 public abstract Point3D toPoint3D(); 138 139 /** 140 * Convert to 4D point 141 */ 142 public abstract Point4D toPoint4D(); 143 144 @Override 145 public boolean equals(Object obj) 146 { 147 if (obj instanceof Point5D) 148 { 149 final Point5D pt = (Point5D) obj; 150 return (getX() == pt.getX()) && (getY() == pt.getY()) && (getZ() == pt.getZ()) && (getT() == pt.getT()) 151 && (getC() == pt.getC()); 152 } 153 154 return super.equals(obj); 155 } 156 157 /** 158 * Creates a new object of the same class as this object. 159 * 160 * @return a clone of this instance. 161 * @exception OutOfMemoryError 162 * if there is not enough memory. 163 * @see java.lang.Cloneable 164 */ 165 @Override 166 public Object clone() 167 { 168 try 169 { 170 return super.clone(); 171 } 172 catch (CloneNotSupportedException e) 173 { 174 // this shouldn't happen, since we are Cloneable 175 throw new InternalError(); 176 } 177 } 178 179 @Override 180 public String toString() 181 { 182 return getClass().getName() + "[" + getX() + "," + getY() + "," + getZ() + ", " + getT() + "," + getC() + "]"; 183 } 184 185 public static class Double extends Point5D 186 { 187 /** 188 * Create an array of Point5D.Double from the input double array.<br> 189 * <br> 190 * The format of the input array should be as follow:<br> 191 * <code>input.lenght</code> = number of point * 5.<br> 192 * <code>input[(pt * 5) + 0]</code> = X coordinate for point <i>pt</i><br> 193 * <code>input[(pt * 5) + 1]</code> = Y coordinate for point <i>pt</i><br> 194 * <code>input[(pt * 5) + 2]</code> = Z coordinate for point <i>pt</i><br> 195 * <code>input[(pt * 5) + 3]</code> = T coordinate for point <i>pt</i><br> 196 * <code>input[(pt * 5) + 4]</code> = C coordinate for point <i>pt</i><br> 197 */ 198 public static Point5D.Double[] toPoint5D(double[] input) 199 { 200 final Point5D.Double[] result = new Point5D.Double[input.length / 5]; 201 202 int pt = 0; 203 for (int i = 0; i < input.length; i += 5) 204 result[pt++] = new Point5D.Double(input[i + 0], input[i + 1], input[i + 2], input[i + 3], input[i + 4]); 205 206 return result; 207 } 208 209 /** 210 * Create an array of double from the input Point5D.Double array.<br> 211 * <br> 212 * The format of the output array is as follow:<br> 213 * <code>result.lenght</code> = number of point * 5.<br> 214 * <code>result[(pt * 5) + 0]</code> = X coordinate for point <i>pt</i><br> 215 * <code>result[(pt * 5) + 1]</code> = Y coordinate for point <i>pt</i><br> 216 * <code>result[(pt * 5) + 2]</code> = Z coordinate for point <i>pt</i><br> 217 * <code>result[(pt * 5) + 3]</code> = T coordinate for point <i>pt</i><br> 218 * <code>result[(pt * 5) + 4]</code> = C coordinate for point <i>pt</i><br> 219 */ 220 public static double[] toDoubleArray(Point5D.Double[] input) 221 { 222 final double[] result = new double[input.length * 5]; 223 224 int off = 0; 225 for (Point5D.Double pt : input) 226 { 227 result[off++] = pt.x; 228 result[off++] = pt.y; 229 result[off++] = pt.z; 230 result[off++] = pt.t; 231 result[off++] = pt.c; 232 } 233 234 return result; 235 } 236 237 public double x; 238 public double y; 239 public double z; 240 public double t; 241 public double c; 242 243 public Double(double x, double y, double z, double t, double c) 244 { 245 super(); 246 247 this.x = x; 248 this.y = y; 249 this.z = z; 250 this.t = t; 251 this.c = c; 252 } 253 254 public Double(double[] xyztc) 255 { 256 final int len = xyztc.length; 257 258 if (len > 0) 259 this.x = xyztc[0]; 260 if (len > 1) 261 this.y = xyztc[1]; 262 if (len > 2) 263 this.z = xyztc[2]; 264 if (len > 3) 265 this.t = xyztc[3]; 266 if (len > 4) 267 this.c = xyztc[4]; 268 } 269 270 public Double() 271 { 272 this(0d, 0d, 0d, 0d, 0d); 273 } 274 275 @Override 276 public double getX() 277 { 278 return x; 279 } 280 281 @Override 282 public void setX(double x) 283 { 284 this.x = x; 285 } 286 287 @Override 288 public double getY() 289 { 290 return y; 291 } 292 293 @Override 294 public void setY(double y) 295 { 296 this.y = y; 297 } 298 299 @Override 300 public double getZ() 301 { 302 return z; 303 } 304 305 @Override 306 public void setZ(double z) 307 { 308 this.z = z; 309 } 310 311 @Override 312 public double getT() 313 { 314 return t; 315 } 316 317 @Override 318 public void setT(double t) 319 { 320 this.t = t; 321 } 322 323 @Override 324 public double getC() 325 { 326 return c; 327 } 328 329 @Override 330 public void setC(double c) 331 { 332 this.c = c; 333 } 334 335 @Override 336 public void setLocation(double x, double y, double z, double t, double c) 337 { 338 this.x = x; 339 this.y = y; 340 this.z = z; 341 this.t = t; 342 this.c = c; 343 } 344 345 @Override 346 public Point2D toPoint2D() 347 { 348 return new Point2D.Double(x, y); 349 } 350 351 @Override 352 public Point3D toPoint3D() 353 { 354 return new Point3D.Double(x, y, z); 355 } 356 357 @Override 358 public Point4D toPoint4D() 359 { 360 return new Point4D.Double(x, y, z, t); 361 } 362 } 363 364 public static class Float extends Point5D 365 { 366 /** 367 * Create an array of Point5D.Float from the input float array.<br> 368 * <br> 369 * The format of the input array should be as follow:<br> 370 * <code>input.lenght</code> = number of point * 5.<br> 371 * <code>input[(pt * 5) + 0]</code> = X coordinate for point <i>pt</i><br> 372 * <code>input[(pt * 5) + 1]</code> = Y coordinate for point <i>pt</i><br> 373 * <code>input[(pt * 5) + 2]</code> = Z coordinate for point <i>pt</i><br> 374 * <code>input[(pt * 5) + 3]</code> = T coordinate for point <i>pt</i><br> 375 * <code>input[(pt * 5) + 4]</code> = C coordinate for point <i>pt</i><br> 376 */ 377 public static Point5D.Float[] toPoint5D(float[] input) 378 { 379 final Point5D.Float[] result = new Point5D.Float[input.length / 5]; 380 381 int pt = 0; 382 for (int i = 0; i < input.length; i += 5) 383 result[pt++] = new Point5D.Float(input[i + 0], input[i + 1], input[i + 2], input[i + 3], input[i + 4]); 384 385 return result; 386 } 387 388 /** 389 * Create an array of float from the input Point5D.Float array.<br> 390 * <br> 391 * The format of the output array is as follow:<br> 392 * <code>result.lenght</code> = number of point * 5.<br> 393 * <code>result[(pt * 5) + 0]</code> = X coordinate for point <i>pt</i><br> 394 * <code>result[(pt * 5) + 1]</code> = Y coordinate for point <i>pt</i><br> 395 * <code>result[(pt * 5) + 2]</code> = Z coordinate for point <i>pt</i><br> 396 * <code>result[(pt * 5) + 3]</code> = T coordinate for point <i>pt</i><br> 397 * <code>result[(pt * 5) + 4]</code> = C coordinate for point <i>pt</i><br> 398 */ 399 public static float[] toFloatArray(Point5D.Float[] input) 400 { 401 final float[] result = new float[input.length * 5]; 402 403 int off = 0; 404 for (Point5D.Float pt : input) 405 { 406 result[off++] = pt.x; 407 result[off++] = pt.y; 408 result[off++] = pt.z; 409 result[off++] = pt.t; 410 result[off++] = pt.c; 411 } 412 413 return result; 414 } 415 416 public float x; 417 public float y; 418 public float z; 419 public float t; 420 public float c; 421 422 public Float(float x, float y, float z, float t, float c) 423 { 424 super(); 425 426 this.x = x; 427 this.y = y; 428 this.c = c; 429 this.z = z; 430 this.t = t; 431 } 432 433 public Float(float[] xyztc) 434 { 435 final int len = xyztc.length; 436 437 if (len > 0) 438 this.x = xyztc[0]; 439 if (len > 1) 440 this.y = xyztc[1]; 441 if (len > 2) 442 this.z = xyztc[2]; 443 if (len > 3) 444 this.t = xyztc[3]; 445 if (len > 4) 446 this.c = xyztc[4]; 447 } 448 449 public Float() 450 { 451 this(0f, 0f, 0f, 0f, 0f); 452 } 453 454 @Override 455 public double getX() 456 { 457 return x; 458 } 459 460 @Override 461 public void setX(double x) 462 { 463 this.x = (float) x; 464 } 465 466 @Override 467 public double getY() 468 { 469 return y; 470 } 471 472 @Override 473 public void setY(double y) 474 { 475 this.y = (float) y; 476 } 477 478 @Override 479 public double getZ() 480 { 481 return z; 482 } 483 484 @Override 485 public void setZ(double z) 486 { 487 this.z = (float) z; 488 } 489 490 @Override 491 public double getT() 492 { 493 return t; 494 } 495 496 @Override 497 public void setT(double t) 498 { 499 this.t = (float) t; 500 } 501 502 @Override 503 public double getC() 504 { 505 return c; 506 } 507 508 @Override 509 public void setC(double c) 510 { 511 this.c = (float) c; 512 } 513 514 @Override 515 public void setLocation(double x, double y, double z, double t, double c) 516 { 517 this.x = (float) x; 518 this.y = (float) y; 519 this.z = (float) z; 520 this.t = (float) t; 521 this.c = (float) c; 522 } 523 524 @Override 525 public Point2D toPoint2D() 526 { 527 return new Point2D.Float(x, y); 528 } 529 530 @Override 531 public Point3D toPoint3D() 532 { 533 return new Point3D.Float(x, y, z); 534 } 535 536 @Override 537 public Point4D toPoint4D() 538 { 539 return new Point4D.Float(x, y, z, t); 540 } 541 } 542 543 public static class Integer extends Point5D 544 { 545 /** 546 * Create an array of Point5D.Integer from the input integer array.<br> 547 * <br> 548 * The format of the input array should be as follow:<br> 549 * <code>input.lenght</code> = number of point * 5.<br> 550 * <code>input[(pt * 5) + 0]</code> = X coordinate for point <i>pt</i><br> 551 * <code>input[(pt * 5) + 1]</code> = Y coordinate for point <i>pt</i><br> 552 * <code>input[(pt * 5) + 2]</code> = Z coordinate for point <i>pt</i><br> 553 * <code>input[(pt * 5) + 3]</code> = T coordinate for point <i>pt</i><br> 554 * <code>input[(pt * 5) + 4]</code> = C coordinate for point <i>pt</i><br> 555 */ 556 public static Point5D.Integer[] toPoint5D(int[] input) 557 { 558 final Point5D.Integer[] result = new Point5D.Integer[input.length / 5]; 559 560 int pt = 0; 561 for (int i = 0; i < input.length; i += 5) 562 result[pt++] = new Point5D.Integer(input[i + 0], input[i + 1], input[i + 2], input[i + 3], input[i + 4]); 563 564 return result; 565 } 566 567 /** 568 * Create an array of integer from the input Point5D.Integer array.<br> 569 * <br> 570 * The format of the output array is as follow:<br> 571 * <code>result.lenght</code> = number of point * 5.<br> 572 * <code>result[(pt * 5) + 0]</code> = X coordinate for point <i>pt</i><br> 573 * <code>result[(pt * 5) + 1]</code> = Y coordinate for point <i>pt</i><br> 574 * <code>result[(pt * 5) + 2]</code> = Z coordinate for point <i>pt</i><br> 575 * <code>result[(pt * 5) + 3]</code> = T coordinate for point <i>pt</i><br> 576 * <code>result[(pt * 5) + 4]</code> = C coordinate for point <i>pt</i><br> 577 */ 578 public static int[] toIntegerArray(Point5D.Integer[] input) 579 { 580 final int[] result = new int[input.length * 5]; 581 582 int off = 0; 583 for (Point5D.Integer pt : input) 584 { 585 result[off++] = pt.x; 586 result[off++] = pt.y; 587 result[off++] = pt.z; 588 result[off++] = pt.t; 589 result[off++] = pt.c; 590 } 591 592 return result; 593 } 594 595 public int x; 596 public int y; 597 public int z; 598 public int t; 599 public int c; 600 601 public Integer(int x, int y, int z, int t, int c) 602 { 603 super(); 604 605 this.x = x; 606 this.y = y; 607 this.z = z; 608 this.t = t; 609 this.c = c; 610 } 611 612 public Integer(int[] xyztc) 613 { 614 final int len = xyztc.length; 615 616 if (len > 0) 617 this.x = xyztc[0]; 618 if (len > 1) 619 this.y = xyztc[1]; 620 if (len > 2) 621 this.z = xyztc[2]; 622 if (len > 3) 623 this.t = xyztc[3]; 624 if (len > 4) 625 this.c = xyztc[4]; 626 } 627 628 public Integer() 629 { 630 this(0, 0, 0, 0, 0); 631 } 632 633 @Override 634 public double getX() 635 { 636 return x; 637 } 638 639 @Override 640 public void setX(double x) 641 { 642 this.x = (int) x; 643 } 644 645 @Override 646 public double getY() 647 { 648 return y; 649 } 650 651 @Override 652 public void setY(double y) 653 { 654 this.y = (int) y; 655 } 656 657 @Override 658 public double getZ() 659 { 660 return z; 661 } 662 663 @Override 664 public void setZ(double z) 665 { 666 this.z = (int) z; 667 } 668 669 @Override 670 public double getT() 671 { 672 return t; 673 } 674 675 @Override 676 public void setT(double t) 677 { 678 this.t = (int) t; 679 } 680 681 @Override 682 public double getC() 683 { 684 return c; 685 } 686 687 @Override 688 public void setC(double c) 689 { 690 this.c = (int) c; 691 } 692 693 @Override 694 public void setLocation(double x, double y, double z, double t, double c) 695 { 696 this.x = (int) x; 697 this.y = (int) y; 698 this.z = (int) z; 699 this.t = (int) t; 700 this.c = (int) c; 701 } 702 703 @Override 704 public Point2D toPoint2D() 705 { 706 return new Point(x, y); 707 } 708 709 @Override 710 public Point3D toPoint3D() 711 { 712 return new Point3D.Integer(x, y, z); 713 } 714 715 @Override 716 public Point4D toPoint4D() 717 { 718 return new Point4D.Integer(x, y, z, t); 719 } 720 } 721}