1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806
|
/*
*
* Copyright (C) 1999, Institute for MicroTherapy
*
* This software and supporting documentation were developed by
*
* University of Witten/Herdecke
* Department of Radiology and MicroTherapy
* Institute for MicroTherapy
* Medical computer science
*
* Universitaetsstrasse 142
* 44799 Bochum, Germany
*
* http://www.microtherapy.de/go/cs
* mailto:computer.science@microtherapy.de
*
* THIS SOFTWARE IS MADE AVAILABLE, AS IS, AND THE INSTITUTE MAKES NO
* WARRANTY REGARDING THE SOFTWARE, ITS PERFORMANCE, ITS MERCHANTABILITY
* OR FITNESS FOR ANY PARTICULAR USE, FREEDOM FROM ANY COMPUTER DISEASES
* OR ITS CONFORMITY TO ANY SPECIFICATION. THE ENTIRE RISK AS TO QUALITY
* AND PERFORMANCE OF THE SOFTWARE IS WITH THE USER.
*
* Author : $Author: kleber $
* Last update : $Date: 2003/09/08 10:15:38 $
* Revision : $Revision: 1.2 $
* State: $State: Exp $
*/
package viewer.presentation;
import J2Ci.*;
import java.awt.*;
import java.util.*;
import java.awt.geom.*;
/**
* This class handles the graphic annoations.
* This class implementing only the GUI-based methods,
* the data are stored in the c++ interface jDVPSGraphicObject. Every
* PresentationStateGraphicObject must have one jDVPSGraphicObject which stores
* the data of a graphic annotation.
*<BR>
* Each jDVPSGraphicObject has an index in the jDVPresentationState,
* this index must be the same as the index in this class ( defined
* in the super class PresentationStateLayerObject).
*
* @author Klaus Kleber
* @since 30.04.1999
* @see PresentationStateAnnotatonObject
* @see PresentationStateLayerObject
* @see J2Ci.jDVPSGraphicObject
*/
public class PresentationStateGraphicObject extends PresentationStateAnnotationObject {
/**
* Contains the geometric representation of a
* PresentationStateGraphicObject as a Shape, which can be drawn in any
* Graphics2D object. If the PresentationStateGraphicObject is display relative, the Shape
* can be drawn without transformations. If the PresentationStateGraphicObject is
* image relative the shape must be transform.
*
* @since 30.04.1999
*/
Shape thisShape = null;
/**
* Contains the data of a graphic annotation in a c++ interface.
*
* @since 30.04.1999
*/
jDVPSGraphicObject graphicObject;
DisplayArea da;
/**
* Constructs a new object.
*
* @since 30.04.1999
*/
private PresentationStateGraphicObject() {
super();
}
/**
* Constructs a new PresentationStateGraphicObject and sets the specified attributs
* in the jDVPSGraphicObject.
*
* @param graphicObject Contains the data of a graphic annotation in a c++ interface.
* @param index Contains the index of the PresentationStateGraphicObject.
* @param type Contains the new graphic type of the jDVPSGraphicObject.
* @param pointList Contains the new points of the jDVPSGraphicObject.
* @param annotationUnits Contains the new annotation units.
* @param isFilled True if the jDVPSGraphicObject shuold be set to filled.
* @param screenSize Contains the size for displaying.
* @param aff Contains the applying transformations.
* @since 30.04.1999
*/
public PresentationStateGraphicObject( jDVPSGraphicObject graphicObject,
int index,
int type,
float[] pointList,
int annotationUnits,
boolean isFilled,
Dimension screenSize,
AffineTransform aff) {
this();
this.index = index;
this.graphicObject = graphicObject;
this.screenSize= screenSize;
this.aff = aff;
graphicObject.setFilled(isFilled);
graphicObject.setGraphicType(type);
if (annotationUnits == 1) {
Point2D.Float point = new Point2D.Float();
for (int i = 0; i < pointList.length/2;i++) {
aff.transform( new Point2D.Float(pointList[2*i]-1,pointList[2*i+1]-1),point);
pointList[2*i] = point.x/screenSize.width;
pointList[2*i+1] = point.y/screenSize.height;
}
}
graphicObject.setData(pointList.length/2, pointList, annotationUnits);
buildShape();
}
/**
* Constructs a PresentationStateGraphicObject form the specified jDVPSGraphicObject
* with the specified index
*
* @param graphicObject Contains the data of a graphic annotation in a c++ interface.
* @param index Contains the index of the PresentationStateGraphicObject.
* @since 30.04.1999
*/
public PresentationStateGraphicObject(jDVPSGraphicObject graphicObject, DisplayArea da,int index) {
this();
this.da = da;
this.index = index;
this.graphicObject = graphicObject;
//Builds the shape, if pixel relative
if (getAnnotationUnits() ==0) buildShape();
}
/**
* Checks if the PresentationStateGraphicObject is closed. An PresentationStateGraphicObject is cloed if the fist and the last
* point are equal and the PresentationStateGraphicObject has more than 2 points.
*
* @return True if the annotation is closed.
* @since 30.04.1999
*/
public boolean isClosed() {
if (getGraphicType() == jDVPSGraphicType.DVPST_ellipse) return true;
if (getGraphicType() == jDVPSGraphicType.DVPST_circle) return true;
//if (getGraphicType() == jDVPSGraphicType.DVPST_interpolated) return false;
if (getNumberOfPoints() < 3) return false;
else return getPoint(0).equals(getPoint(getNumberOfPoints()-1));
}
/**
* Moves the PresentationStateGraphicObject analog to the specified points.
* The first point is the start point and the secound point is the point where the
* first point is moved to. The PresentationStateGraphicObject will be moved
* analog to the result vector.
*
* @param moveAnn Start moving point.
* @param point Stop moving point.
* @since 30.04.1999
*/
public void moveTo(Point2D.Float moveAnn,Point2D.Float point ) {
float[] newPixels = new float[getNumberOfPoints()*2];
Point2D.Float translatedPoint1 = new Point2D.Float();
Point2D.Float translatedPoint2 = new Point2D.Float();
Point2D.Float translatedPoint = new Point2D.Float();
//image relative
if (getAnnotationUnits() == 0) {
translatedPoint1 = getInverseTransformedPoint(moveAnn,aff);
translatedPoint2 = getInverseTransformedPoint(point,aff);
translatedPoint.x = translatedPoint2.x-translatedPoint1.x;
translatedPoint.y = translatedPoint2.y-translatedPoint1.y;
for (int i = 0; i < getNumberOfPoints(); i++) {
newPixels[2*i] = getPoint(i).x+translatedPoint.x;
newPixels[2*i+1] = getPoint(i).y +translatedPoint.y;
}
graphicObject.setData(newPixels.length/2, newPixels,0);
}
//Display relative
else {
Point2D.Float diff = new Point2D.Float();
diff.x = point.x-moveAnn.x;
diff.y = point.y-moveAnn.y;
for (int i = 0; i < getNumberOfPoints(); i++) {
newPixels[2*i] = getPoint(i).x+diff.x/screenSize.width;
newPixels[2*i+1] =getPoint(i).y+ diff.y/screenSize.height;
}
graphicObject.setData(getNumberOfPoints(), newPixels, 1);
}
buildShape();
}
/**
* Rebuilds the display relative annotations if the size for displaying the image
* has changed.
*
* @param The new screensize of the annotation.
* @since 30.04.1999
*/
public void setScreenSize(Dimension screenSize) {
this.screenSize = screenSize;
if (getAnnotationUnits() ==jDVPSannotationUnit.DVPSA_display) if (screenSize!= null)buildShape();
}
/*
* Builds the shape form the jDVPSGraphicObject
*
* @since 30.04.1999
*/
public void buildShape() {
//Contructs Polyline
if (getGraphicType() == jDVPSGraphicType.DVPST_polyline) thisShape = buildPolyline();
//Contructs Interpolated??
else if (getGraphicType() == jDVPSGraphicType.DVPST_interpolated)thisShape = buildInterpolated();
//Contructs Circle
else if (getGraphicType() == jDVPSGraphicType.DVPST_circle)thisShape = buildCircle();
else if (getGraphicType() == jDVPSGraphicType.DVPST_ellipse)thisShape = buildEllipse();
else if (getGraphicType() == jDVPSGraphicType.DVPST_point)thisShape = buildPoint();
}
/**
* Draws the shape of the graphics annotation with the specified
* transformation in the specified Graphics2d object
*
* @param g2 The context in which this object will be drawn.
* @param aff Contains the applying transformation.
* @since 30.04.1999
*/
public void draw(Graphics2D g2,AffineTransform aff, boolean scale) {
System.out.println(getInfo());
this.aff = aff;
if ((g2!=null) && (thisShape!= null)) {
//System.out.println("**********draw Image Rel*************************");
if (getAnnotationUnits() ==0) {
g2.setTransform(aff);
g2.draw((thisShape));
if ((isfilled()&& isClosed())||getGraphicType() == jDVPSGraphicType.DVPST_point) g2.fill(thisShape);
if (!isActive()) drawBounding(g2,aff);
}
else {
//System.out.println("**********draw Display rel*************************");
g2.setTransform(new AffineTransform());
// g2.setStroke(graphicStroke);
g2.draw(thisShape);
if ((isfilled()&& isClosed())||getGraphicType() == jDVPSGraphicType.DVPST_point) g2.fill(thisShape);
}
}
}
public void convertDisplayedAreas(float offsetX, float offsetY,float transX, float transY) {
System.out.println("transY: "+transY);
System.out.println("transX: "+transX);
System.out.println("offsetY: "+offsetY);
System.out.println("offsetX: "+offsetX);
if (getAnnotationUnits() ==jDVPSannotationUnit.DVPSA_display) {
int number = getNumberOfPoints();
float[] points = new float[number*2];
Point2D.Float p = new Point2D.Float();
for (int i = 0; i< number; i++) {
p = getPoint(i);
System.out.println("p: "+p);
points[2*i] = offsetX + p.x*transX;
points[2*i+1] = offsetY + p.y*transY;
}
graphicObject.setData(number, points, jDVPSannotationUnit.DVPSA_display);
buildShape();
}
}
/**
* Marked the PresentationStateGraphicObject with Rectangles in the specified
* Graphics2D context.
*
* @param g2 The context in which this object will be merked.
* @param aff Contains the applying transformation.
* @since 30.04.1999
*/
public void drawBounding(Graphics2D g2,AffineTransform aff) {
Rectangle2D boundingRect;
if (getAnnotationUnits()==0) {
boundingRect = aff.createTransformedShape(thisShape.getBounds2D()).getBounds2D();
}
else {
boundingRect = thisShape.getBounds2D();
}
g2.setTransform(new AffineTransform());
g2.draw(new Rectangle2D.Double(boundingRect.getX()- 6,boundingRect.getY()-6,5,5));
g2.draw(new Rectangle2D.Double(boundingRect.getX()+boundingRect.getWidth()+1,boundingRect.getY()-6,5,5));
g2.draw(new Rectangle2D.Double(boundingRect.getX()-6,boundingRect.getY()+boundingRect.getHeight()+1,5,5));
g2.draw(new Rectangle2D.Double(boundingRect.getX()+boundingRect.getWidth()+1,boundingRect.getY()+boundingRect.getHeight()+1,5,5));
}
/**
* Checks if the graphic annotation is filled.
*
* @return True if graphic is filled.
* @since 30.04.1999
* @see J2Ci.jDVPSGraphicObject#isFilled
*/
public boolean isfilled() {
return graphicObject.isFilled();
}
/**
* Gets the graphic annotation units.
*
* @return graphic annotation units.
* @since 30.04.1999
* @see J2Ci.jDVPSGraphicObject#getAnnotationUnits
*/
public int getAnnotationUnits() {
return graphicObject.getAnnotationUnits();
}
/**
* Gets the graphic type of the graphic object.
*
* @return graphic type of the graphic object.
* @since 30.04.1999
* @see J2Ci.jDVPSGraphicObject#getGraphicType
*/
int getGraphicType() {
return graphicObject.getGraphicType();
}
/**
* Gets the point at the specified index.
*
* @param index Specifies the index.
* @return The point at the specified index.
* @since 30.04.1999
* @see J2Ci.jDVPSGraphicObject#getPoint
*/
Point2D.Float getPoint(int index) {
jDoubleByRef x = new jDoubleByRef();
jDoubleByRef y = new jDoubleByRef();
graphicObject.getPoint(index,x,y);
return new Point2D.Float((float)x.value, (float) y.value);
}
/**
* Gets the point at the specified index.
*
* @param index Specifies the index.
* @return The point at the specified index.
* @since 30.04.1999
* @see J2Ci.jDVPSGraphicObject#getPoint
*/
Point2D.Double getPointDouble(int index) {
jDoubleByRef x = new jDoubleByRef();
jDoubleByRef y = new jDoubleByRef();
graphicObject.getPoint(index,x,y);
return new Point2D.Double(x.value, y.value);
}
/**
* Gets the number of points in the annotation.
*
* @return The number of points in the annotation.
* @since 30.04.1999
* @see J2Ci.jDVPSGraphicObject#getNumberOfPoints
*/
int getNumberOfPoints() {
return graphicObject.getNumberOfPoints();
}
/**
* Caluclates an new shape form a polyline graphic annotation.
*
* @return The shape of the annotation.
* @since 30.04.1999
*/
Shape buildPolyline() {
//Shape object
GeneralPath generalPath= new GeneralPath();
//Image realtive annotation
if ( getAnnotationUnits() == 0) {
generalPath.moveTo((getPoint(0).x-1), (getPoint(0).y-1));
for (int i = 1; i< getNumberOfPoints(); i++) generalPath.lineTo(getPoint(i).x-1, getPoint(i).y-1);
}
//Display realtive annotation
else {
generalPath.moveTo(((getPoint(0).x)*(screenSize.width)),(getPoint(0).y*screenSize.height));
for (int i = 1; i< getNumberOfPoints(); i++) generalPath.lineTo(getPoint(i).x*screenSize.width, getPoint(i).y*screenSize.height);
}
return generalPath;
}
/**
* Caluclates an new shape form a interpolated graphic annotation.
*
* @return The shape of the annotation.
* @since 30.04.1999
*/
Shape buildInterpolated() {
GeneralPath generalPath= null;
//Image realtive annotation
if ( getAnnotationUnits() == 0) {
int size = getNumberOfPoints();
Point2D.Double[] pts = new Point2D.Double[size];
Point2D.Double p;
for (int i = 0; i< size; i++) {
p = getPointDouble(i);
pts[i] = new Point2D.Double(p.x-1,p.y-1);
}
generalPath = viewer.paint.GeometryTool.getCubicSpline(pts, 1d);
}
//Display realtive annotation
else {
int size = getNumberOfPoints();
Point2D.Double[] pts = new Point2D.Double[size];
Point2D.Double p;
for (int i = 0; i< size; i++) {
p = getPointDouble(i);
pts[i] = new Point2D.Double(p.x*screenSize.width,p.y*screenSize.height);
}
generalPath = viewer.paint.GeometryTool.getCubicSpline(pts, 1d);
}
return generalPath;
}
/**
* Caluclates an new shape form a ellipse graphic annotation.
*
* @return The shape of the annotation.
* @since 30.04.1999
*/
Shape buildEllipse() {
System.out.println("zzzzz");
//Shape object
Ellipse2D.Float ellipse;
//TLHC of the circle
float majMinX;
float majMinY;
float minMinX;
float minMinY;
//Calculates letfx
if (getPoint(0).x< getPoint(1).x) {
majMinX = getPoint(0).x ;
}
else {
majMinX = getPoint(1).x ;
}
//calculates lefty
if (getPoint(0).y< getPoint(1).y) {
majMinY = getPoint(0).y;
}
else {
majMinY = getPoint(1).y;
}
//Calculates letfx
if (getPoint(2).x< getPoint(3).x) {
minMinX = getPoint(2).x ;
}
else {
minMinX = getPoint(3).x ;
}
//calculates lefty
if (getPoint(2).y< getPoint(3).y) {
minMinY = getPoint(2).y;
}
else {
minMinY = getPoint(3).y;
}
float leftx;
float lefty;
float height;
float width;
if (minMinY<majMinY) {
height = Math.abs(getPoint(0).x-getPoint(1).x);
width= Math.abs(getPoint(2).y-getPoint(3).y);
leftx=majMinX;
lefty=minMinY;
/*
System.err.println("getPoint(0)" +getPoint(0));
System.err.println("getPoint(1)" +getPoint(1));
System.err.println("getPoint(2)" +getPoint(2));
System.err.println("getPoint(3)" +getPoint(3));
System.err.println("11 height "+ height+"; width: " +width+", leftx" +leftx+", leftx: " +lefty);
*/
} else {
width = Math.abs(getPoint(0).y-getPoint(1).y);
height= Math.abs(getPoint(2).x-getPoint(3).x);
leftx=minMinX;
lefty=majMinY;
/*
System.err.println("getPoint(0)" +getPoint(0));
System.err.println("getPoint(1)" +getPoint(1));
System.err.println("getPoint(2)" +getPoint(2));
System.err.println("getPoint(3)" +getPoint(3));
System.err.println("11 height "+ height+"; width: " +width+", leftx" +leftx+", leftx: " +lefty);
*/
}
if ( getAnnotationUnits() == 0) {
ellipse = new Ellipse2D.Float(leftx-1,lefty-1,height-1,width-1);
}
else {
ellipse = new Ellipse2D.Float( leftx*screenSize.width,
lefty*screenSize.height,
height*screenSize.width,
width*screenSize.height);
System.out.println("Ellipse:" +leftx+ ", " +screenSize.toString());
}
return ellipse;
}
/**
* Caluclates an new shape form a circle graphic annotation.
*
* @return The shape of the annotation.
* @since 30.04.1999
*/
Shape buildCircle() {
Ellipse2D.Float circle;
float leftx;
float lefty;
float radius;
Point2D.Float pointCenter;
Point2D.Float pointAtCirc;
if ( getAnnotationUnits() == 0) {
//System.out.println(" Image relative Annotation");
pointCenter = new Point2D.Float(getPoint(0).x-1f,getPoint(0).y-1f);
pointAtCirc = new Point2D.Float(getPoint(1).x-1f,getPoint(1).y-1f);
}
else {
//System.out.println(" Display relative Annotation");
pointCenter = new Point2D.Float(getPoint(0).x*screenSize.width,getPoint(0).y*screenSize.height);
pointAtCirc = new Point2D.Float(getPoint(1).x*screenSize.width,getPoint(1).y*screenSize.height);
}
//Calculates radius
radius = (float)Math.sqrt( (pointCenter.x-pointAtCirc.x)*
(pointCenter.x-pointAtCirc.x) +
(pointCenter.y-pointAtCirc.y)*
(pointCenter.y-pointAtCirc.y));
leftx = pointCenter.x-radius;
lefty = pointCenter.y-radius;
circle = new Ellipse2D.Float(leftx, lefty, 2*radius-1,2*radius-1);
//System.out.println("Circle: Annotation " + leftx + ", " +lefty + ", " + radius);
return circle;
}
/**
* Caluclates an new shape form a circle graphic annotation.
*
* @return The shape of the annotation.
* @since 30.04.1999
*/
Shape buildPoint() {
System.out.println("-----------------------------buildPoint");
Ellipse2D.Float circle;
float leftx;
float lefty;
float radius;
Point2D.Float pointCenter;
Point2D.Float pointAtCirc;
if ( getAnnotationUnits() == 0) {
//System.out.println(" Image relative Annotation");
pointCenter = new Point2D.Float(getPoint(0).x-1f,getPoint(0).y-1f);
}
else {
//System.out.println(" Display relative Annotation");
pointCenter = new Point2D.Float(getPoint(0).x*screenSize.width,getPoint(0).y*screenSize.height);
}
//Calculates radius
radius = 5;
leftx = pointCenter.x-radius;
lefty = pointCenter.y-radius;
circle = new Ellipse2D.Float(leftx, lefty, 2*radius-1,2*radius-1);
//System.out.println("Circle: Annotation " + leftx + ", " +lefty + ", " + radius);
return circle;
}
/**
* Returns a String representing this object.The string contains the graphic
* type of the annotation and the annatation unit.
*
* @return A String representing this object.
* @since 30.04.1999
*/
public String getListText() {
String returnString = new String();
if (getAnnotationUnits()== 0)returnString = returnString.concat("image rel. graphic:");
else returnString = returnString.concat("display rel. graphic: ");
if (getGraphicType()== 1)returnString = returnString.concat("polyline");
if (getGraphicType()== 2)returnString = returnString.concat("interpol.");
if (getGraphicType()== 3)returnString = returnString.concat("circle");
if (getGraphicType()== 4)returnString = returnString.concat("ellipse");
if (getGraphicType()== 0)returnString = returnString.concat("point");
return returnString;
}
/**
* Returns a String representing this object.
*
* @return A String representing this object
* @since 30.04.1999
*/
public String getInfo() {
String returnString;
//fill attributes
returnString = new String( " PresenationStateGraphicsObject" + "\n"+"\n"+
" isfilled: "+ isfilled() + "\n" +
" getAnnotationUnits: "+ getAnnotationUnits() + "\n" +
" getGraphicType: "+ getGraphicType() + "\n" );
//fill points
for (int i = 0; i < getNumberOfPoints(); i++) {
returnString = returnString.concat(" Point " + i + ": X = " + getPoint(i).getX() + ", Y = " + getPoint(i).getY()+"\n");
}
return returnString;
}
/**
* Deletes the object.
*
* @since 30.04.1999
*/
public void deleteAll() {
graphicObject = null;
thisShape = null;
}
/**
* Filles/unfilles the annotation.
*
* @param filled True if the annatation shuold be filled.
* @since 30.04.1999
* @see J2Ci.jDVPSGraphicObject#setFilled
*/
public void setFilled(boolean filled) {
graphicObject.setFilled(filled);
}
/**
* Check if this object contains the specified point.
*
* @return true if this object contains the specified point.
* @since 30.04.1999
*/
public boolean contains(Point2D.Float point) {
if (getNumberOfPoints() <= 2) {
Rectangle2D boundsRect;
boundsRect = thisShape.getBounds2D();
if (getAnnotationUnits() == 0)
return (new Rectangle2D.Double(boundsRect.getX()-1f,boundsRect.getY()-1f,boundsRect.getWidth()+2d, boundsRect.getHeight()+2d )).contains(getInverseTransformedPoint(point,aff));
else
return (new Rectangle2D.Double(boundsRect.getX()-1f,boundsRect.getY()-1f,boundsRect.getWidth()+2d, boundsRect.getHeight()+2d )).contains(point);
}
if (getAnnotationUnits() == 0) return thisShape.contains(getInverseTransformedPoint(point,aff));
else return thisShape.contains(point);
}
/**
* If the annotation units is display relative this function
* converts the annotation to image relative and vice versa.
*
* @since 30.04.1999
*/
public void convert() {
float[] newPixels = new float[getNumberOfPoints()*2];
Point2D.Float translatedPoint = new Point2D.Float();
//Convert image relative to display relative
if (getAnnotationUnits() == 0) {
for (int i = 0; i < getNumberOfPoints(); i++) {
aff.transform(new Point2D.Float(getPoint(i).x-1 ,getPoint(i).y-1),translatedPoint);
newPixels[2*i] = translatedPoint.x/screenSize.width;
newPixels[2*i+1] = translatedPoint.y/screenSize.height;
}
for (int i = 0; i< newPixels.length; i++) System.out.println("klausnewPoint: " +i + ", : " + newPixels[i]);
graphicObject.setData(getNumberOfPoints(), newPixels, 1);
}
//Convert display relative to image relative.
else {
for (int i = 0; i < getNumberOfPoints(); i++) {
try {
aff.inverseTransform(new Point2D.Float(getPoint(i).x*screenSize.width,getPoint(i).y*screenSize.height),translatedPoint);
}
catch(NoninvertibleTransformException e)
{}
newPixels[2*i] = translatedPoint.x+1;
newPixels[2*i+1] = translatedPoint.y+1;
}
graphicObject.setData(newPixels.length/2, newPixels,0);
}
buildShape();
}
}
/*
* CVS Log
* $Log: PresentationStateGraphicObject.java,v $
* Revision 1.2 2003/09/08 10:15:38 kleber
* Bugfix: The first two points of Ellipse are definesd as the major axis
*
* Revision 1.1.1.1 2001/06/06 10:32:30 kleber
* Init commit for DICOMscope 3.5
* Create new CVS
*
*/
|