Logo Search packages:      
Sourcecode: pixelmed version File versions  Download package

void com::pixelmed::display::SingleImagePanel::paintComponent ( Graphics  g  )  [inline, inherited]

Parameters:
g 

Definition at line 1534 of file SingleImagePanel.java.

References com::pixelmed::display::SingleImagePanel::applyVOILUT(), com::pixelmed::display::SingleImagePanel::applyWindowCenterAndWidthLinear(), com::pixelmed::display::SingleImagePanel::applyWindowCenterAndWidthLogistic(), com::pixelmed::display::SingleImagePanel::applyWindowCenterAndWidthWithPaletteColor(), com::pixelmed::display::SingleImagePanel::currentVOITransformInUse, com::pixelmed::display::TextAnnotation::getAnchorPoint(), com::pixelmed::display::TextAnnotation::getAnchorPointXAsInt(), com::pixelmed::display::TextAnnotation::getAnchorPointYAsInt(), com::pixelmed::display::SourceImage::getBackgroundValue(), com::pixelmed::display::SourceImage::getBufferedImage(), com::pixelmed::dicom::VOITransform::getCenter(), com::pixelmed::dicom::DisplayShutter::getCircularShutterBRHC(), com::pixelmed::dicom::DisplayShutter::getCircularShutterTLHC(), com::pixelmed::display::OrientationAnnotations::getColumnOrientation(), com::pixelmed::dicom::Overlay::getColumnOrigin(), com::pixelmed::dicom::Overlay::getNumberOfOverlays(), com::pixelmed::dicom::VOITransform::getNumberOfTransforms(), com::pixelmed::dicom::Overlay::getOverlayAsBinaryBufferedImage(), com::pixelmed::dicom::DisplayShutter::getRectangularShutterBRHC(), com::pixelmed::dicom::DisplayShutter::getRectangularShutterTLHC(), com::pixelmed::dicom::ModalityTransform::getRescaleIntercept(), com::pixelmed::dicom::ModalityTransform::getRescaleSlope(), com::pixelmed::display::OrientationAnnotations::getRowOrientation(), com::pixelmed::dicom::Overlay::getRowOrigin(), com::pixelmed::display::DisplayedAreaSelection::getSelectionHeight(), com::pixelmed::display::DisplayedAreaSelection::getSelectionWidth(), com::pixelmed::display::TextAnnotation::getString(), com::pixelmed::dicom::DisplayShutter::getVerticesOfPolygonalShutterAsPoint2D(), com::pixelmed::dicom::VOITransform::getWidth(), com::pixelmed::display::DisplayedAreaSelection::getXOffset(), com::pixelmed::display::DisplayedAreaSelection::getYOffset(), com::pixelmed::dicom::DisplayShutter::isCircularShutter(), com::pixelmed::dicom::DisplayShutter::isPolygonalShutter(), com::pixelmed::dicom::DisplayShutter::isRectangularShutter(), com::pixelmed::display::DemographicAndTechniqueAnnotations::iterator(), com::pixelmed::display::DisplayedAreaSelection::shapeSelectionToMatchAvailableWindow(), com::pixelmed::display::SingleImagePanel::useIntercept, com::pixelmed::display::SingleImagePanel::useSlope, com::pixelmed::display::SingleImagePanel::useVOILUTNotFunction, com::pixelmed::display::SingleImagePanel::voiLUTBitsPerEntry, com::pixelmed::display::SingleImagePanel::voiLUTData, com::pixelmed::display::SingleImagePanel::voiLUTEntryMax, com::pixelmed::display::SingleImagePanel::voiLUTEntryMin, com::pixelmed::display::SingleImagePanel::voiLUTFirstValueMapped, com::pixelmed::display::SingleImagePanel::voiLUTIdentityWindowCenter, com::pixelmed::display::SingleImagePanel::voiLUTIdentityWindowWidth, com::pixelmed::display::SingleImagePanel::voiLUTNumberOfEntries, com::pixelmed::display::SingleImagePanel::voiLUTTopOfEntryRange, com::pixelmed::display::SingleImagePanel::windowCenter, and com::pixelmed::display::SingleImagePanel::windowWidth.

                                             {
//System.err.println("SingleImagePanel.paintComponent(): start");
//try { throw new Exception(); } catch (Exception e) { e.printStackTrace(System.err); }
//long startTime = System.currentTimeMillis();
            Cursor was = getCursor();
            setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
            
            int useSrcImageIndex = currentSrcImageSortOrder == null ? currentSrcImageIndex : currentSrcImageSortOrder[currentSrcImageIndex];
//System.err.println("SingleImagePanel.paintComponent() useSrcImageIndex: "+useSrcImageIndex);
            BufferedImage useSrcImage = sImg.getBufferedImage(useSrcImageIndex);
//System.err.println("SingleImagePanel.paintComponent() useSrcImage is BufferedImage as follows:"); BufferedImageUtilities.describeImage(useSrcImage,System.err);

            Rectangle windowSize = this.getBounds();
//System.err.println("SingleImagePanel.paintComponent():windowSize = "+windowSize);

            // the following is not sensitive to selection area change ... in future may need to make this explicit on resize event ... :(
            if (cachedWindowSize != null && (windowSize.width != cachedWindowSize.width && windowSize.height != cachedWindowSize.height)) {           // do not care about position
//System.err.println("SingleImagePanel.paintComponent(): window size changed, so flushing cache and resetting selection to original");
                  dirtySource();
                  useDisplayedAreaSelection=null;
            }
            cachedWindowSize = windowSize;

            if (useDisplayedAreaSelection == null) {
                  if (originalDisplayedAreaSelection == null) {
                        originalDisplayedAreaSelection = new DisplayedAreaSelection(useSrcImage.getWidth(),useSrcImage.getHeight());            // default is entire image
                  }
//System.err.println("SingleImagePanel.setDisplayedAreaSelection(): originalDisplayedAreaSelection = "+originalDisplayedAreaSelection);
                  useDisplayedAreaSelection = originalDisplayedAreaSelection.shapeSelectionToMatchAvailableWindow(windowSize);
//System.err.println("SingleImagePanel.paintComponent(): useDisplayedAreaSelection (after shapping to match available window size) = "+useDisplayedAreaSelection);
            }

            double useScaleFactor = ((double)windowSize.width)/useDisplayedAreaSelection.getSelectionWidth();
//System.err.println("SingleImagePanel.paintComponent(): useScaleFactor = "+useScaleFactor);

            imageToWindowCoordinateTransform = AffineTransform.getTranslateInstance(-useDisplayedAreaSelection.getXOffset()*useScaleFactor,-useDisplayedAreaSelection.getYOffset()*useScaleFactor);
            imageToWindowCoordinateTransform.concatenate(AffineTransform.getScaleInstance(useScaleFactor,useScaleFactor));
            if (preTransformImageRelativeCoordinates != null) {
                  imageToWindowCoordinateTransform.concatenate(preTransformImageRelativeCoordinates);
            }
//System.err.println("SingleImagePanel.paintComponent(): imageToWindowCoordinateTransform = "+imageToWindowCoordinateTransform);
            try {
                  windowToImageCoordinateTransform = imageToWindowCoordinateTransform.createInverse();
            }
            catch (NoninvertibleTransformException e) {
                  e.printStackTrace(System.err);
                  windowToImageCoordinateTransform=null;
            }
//System.err.println("SingleImagePanel.paintComponent(): windowToImageCoordinateTransform = "+windowToImageCoordinateTransform);
            
            if (cachedPreWindowedImage == null) {
//System.err.println("SingleImagePanel.paintComponent(): cachedPreWindowedImage is null");
                  if (cachedResizedSelectedRegionImage == null) {
//System.err.println("SingleImagePanel.paintComponent(): resizing prior to windowing");
                        if (cachedResizedImage == null) {
                              if (resampler == null) {
                                    resampler = new BufferedImageUtilities();
                              }
//long resampleTime = System.currentTimeMillis();
                              int backgroundValuePriorToWindowing = sImg.getBackgroundValue();

                              int srcWidth = useSrcImage.getWidth();
                              int srcHeight = useSrcImage.getHeight();
                              cachedResizedImage=resampler.resample(useSrcImage,
                                    srcWidth,
                                    srcHeight,
                                    0,
                                    0,
                                    (int)Math.round(srcWidth*useScaleFactor),
                                    (int)Math.round(srcHeight*useScaleFactor),
                                    signed,
                                    backgroundValuePriorToWindowing);
//System.err.println("SingleImagePanel.paintComponent(): resizing with resampler - done in "+(System.currentTimeMillis()-resampleTime)+" ms");
//System.err.println("SingleImagePanel.paintComponent(): resampled BufferedImage is as follows:"); BufferedImageUtilities.describeImage(cachedResizedImage,System.err);
                        }
//long getSubimageTime = System.currentTimeMillis();
                        int scaledSelectionX = (int)Math.round(useDisplayedAreaSelection.getXOffset()*useScaleFactor);
                        int scaledSelectionY = (int)Math.round(useDisplayedAreaSelection.getYOffset()*useScaleFactor);
                        int scaledSelectionWidth = (int)Math.round(useDisplayedAreaSelection.getSelectionWidth()*useScaleFactor);
                        int scaledSelectionHeight = (int)Math.round(useDisplayedAreaSelection.getSelectionHeight()*useScaleFactor);
//System.err.println("SingleImagePanel.paintComponent(): before clipping to image area - scaledSelectionX = "+scaledSelectionX);
//System.err.println("SingleImagePanel.paintComponent(): before clipping to image area - scaledSelectionY = "+scaledSelectionY);
//System.err.println("SingleImagePanel.paintComponent(): before clipping to image area - scaledSelectionWidth = "+scaledSelectionWidth);
//System.err.println("SingleImagePanel.paintComponent(): before clipping to image area - scaledSelectionHeight = "+scaledSelectionHeight);

                        if (scaledSelectionX < 0) {
                              offsetDrawingOfResizedSelectedRegionImageX = - scaledSelectionX;
                              //scaledSelectionWidth -= offsetDrawingOfResizedSelectedRegionImageX;
                              scaledSelectionX = 0;
                        }
                        else {
                              offsetDrawingOfResizedSelectedRegionImageX = 0;
                        }
                              
                        if (scaledSelectionY < 0) {
                              offsetDrawingOfResizedSelectedRegionImageY = - scaledSelectionY;
                              //scaledSelectionHeight -= offsetDrawingOfResizedSelectedRegionImageY;
                              scaledSelectionY = 0;
                        }
                        else {
                              offsetDrawingOfResizedSelectedRegionImageY = 0;
                        }

                        int cachedResizedImageWidth = cachedResizedImage.getWidth();
//System.err.println("SingleImagePanel.paintComponent(): cachedResizedImageWidth = "+cachedResizedImageWidth);
                        if (scaledSelectionX + scaledSelectionWidth > cachedResizedImageWidth) {
                              scaledSelectionWidth = cachedResizedImageWidth - scaledSelectionX;
                        }
                        else if (scaledSelectionX + scaledSelectionWidth < cachedResizedImageWidth) { // use all available image to the right, i.e., if panning beyond original selection
                              scaledSelectionWidth = cachedResizedImageWidth - scaledSelectionX;
                        }
                        if (scaledSelectionWidth < 0) {
                              scaledSelectionWidth = 0;
                        }

                        int cachedResizedImageHeight = cachedResizedImage.getHeight();
//System.err.println("SingleImagePanel.paintComponent(): cachedResizedImageHeight = "+cachedResizedImageHeight);
                        if (scaledSelectionY + scaledSelectionHeight > cachedResizedImageHeight) {
                              scaledSelectionHeight = cachedResizedImageHeight - scaledSelectionY;
                        }
                        else if (scaledSelectionY + scaledSelectionHeight < cachedResizedImageHeight) {     // use all available image to the bottom, i.e., if panning beyond original selection
                              scaledSelectionHeight = cachedResizedImageHeight - scaledSelectionY;
                        }
                        if (scaledSelectionHeight < 0) {
                              scaledSelectionHeight = 0;
                        }

//System.err.println("SingleImagePanel.paintComponent(): after clipping to image area - scaledSelectionX = "+scaledSelectionX);
//System.err.println("SingleImagePanel.paintComponent(): after clipping to image area - scaledSelectionY = "+scaledSelectionY);
//System.err.println("SingleImagePanel.paintComponent(): after clipping to image area - scaledSelectionWidth = "+scaledSelectionWidth);
//System.err.println("SingleImagePanel.paintComponent(): after clipping to image area - scaledSelectionHeight = "+scaledSelectionHeight);
//System.err.println("SingleImagePanel.paintComponent(): offsetDrawingOfResizedSelectedRegionImageX = "+offsetDrawingOfResizedSelectedRegionImageX);
//System.err.println("SingleImagePanel.paintComponent(): offsetDrawingOfResizedSelectedRegionImageY = "+offsetDrawingOfResizedSelectedRegionImageY);

                        cachedResizedSelectedRegionImage = 
                              scaledSelectionHeight > 0 && scaledSelectionWidth > 0
                              ? cachedResizedImage.getSubimage(scaledSelectionX,scaledSelectionY,scaledSelectionWidth,scaledSelectionHeight)
                              : null;
//System.err.println("SingleImagePanel.paintComponent(): selecting subimage from resized image - done in "+(System.currentTimeMillis()-getSubimageTime)+" ms");
                  }
                  useSrcImage=cachedResizedSelectedRegionImage;
                  
                  if (useSrcImage == null) {          // e.g., nothing left to draw since panned offscreen
                        cachedPreWindowedImage = null;
                  }
                  else  if (useSrcImage.getColorModel().getNumComponents() == 1) {
                  
                        // First, find pre-selected VOI for this frame, if any
                        
//System.err.println("currentVOITransformInUse "+currentVOITransformInUse);
                        if (currentVOITransformInUse != -1
                         && !useVOILUTNotFunction
                         && voiTransform != null
                         && voiTransform.getNumberOfTransforms(useSrcImageIndex) > currentVOITransformInUse) {
                              windowWidth=voiTransform.getWidth(useSrcImageIndex,currentVOITransformInUse);
                              windowCenter=voiTransform.getCenter(useSrcImageIndex,currentVOITransformInUse);
//System.err.println("For new frame "+useSrcImageIndex+" using preselected center "+windowCenter+" and width "+windowWidth);
                        }
                        else {
                              //currentVOITransformInUse=-1;
                              // Just leave it alone (but don't disable use of selection for other frames)
//System.err.println("For new frame "+useSrcImageIndex+" using user selected center "+windowCenter+" and width "+windowWidth);
                        }
                        
                        // Second, find rescale attributes for this frame
                        
                        if (modalityTransform != null) {
                                  useSlope = modalityTransform.getRescaleSlope    (useSrcImageIndex);
                              useIntercept = modalityTransform.getRescaleIntercept(useSrcImageIndex);
//System.err.println("For new frame "+useSrcImageIndex+" using preselected rescale slope "+useSlope+" and intercept "+useIntercept);
                        }
                        else {
                              useSlope=1.0;
                              useIntercept=0.0;
//System.err.println("For new frame "+useSrcImageIndex+" using default rescale slope "+useSlope+" and intercept "+useIntercept);
                        }
                        
                        // Finally, actually build the destination image
//System.err.println("SingleImagePanel.paintComponent() useVOILUTNotFunction = "+useVOILUTNotFunction);
//System.err.println("SingleImagePanel.paintComponent() numberOfEntries = "+numberOfEntries);
//System.err.println("SingleImagePanel.paintComponent() redTable = "+redTable);
//System.err.println("SingleImagePanel.paintComponent() useVOIFunction = "+useVOIFunction);
//long applyVOITime = System.currentTimeMillis();
                        if (useVOILUTNotFunction) {
                              cachedPreWindowedImage = applyVOILUT(useSrcImage,windowCenter,windowWidth,voiLUTIdentityWindowCenter,voiLUTIdentityWindowWidth,signed,inverted,useSlope,useIntercept,hasPad,pad,padRangeLimit,
                                    voiLUTNumberOfEntries,voiLUTFirstValueMapped,voiLUTBitsPerEntry,voiLUTData,voiLUTEntryMin,voiLUTEntryMax,voiLUTTopOfEntryRange);
                        }
                        else if (numberOfEntries != 0 && redTable != null) {
                              cachedPreWindowedImage = applyWindowCenterAndWidthWithPaletteColor(useSrcImage,windowCenter,windowWidth,signed,inverted,useSlope,useIntercept,hasPad,pad,padRangeLimit,
                                    largestGray,bitsPerEntry,numberOfEntries,redTable,greenTable,blueTable);
                        }
                        else if (useVOIFunction == 1) {
                              cachedPreWindowedImage = applyWindowCenterAndWidthLogistic(useSrcImage,windowCenter,windowWidth,signed,inverted,useSlope,useIntercept,hasPad,pad,padRangeLimit);
                        }
                        else {
                              cachedPreWindowedImage = applyWindowCenterAndWidthLinear(useSrcImage,windowCenter,windowWidth,signed,inverted,useSlope,useIntercept,hasPad,pad,padRangeLimit);
                        }
//System.err.println("SingleImagePanel.paintComponent(): VOI/window applied in "+(System.currentTimeMillis()-applyVOITime)+" ms");
                  }
                  else {
//System.err.println("SingleImagePanel.paintComponent() using useSrcImage as cachedPreWindowedImage="+useSrcImage);
                        cachedPreWindowedImage=useSrcImage;
                  }
//System.err.println("SingleImagePanel.paintComponent() mrj.version="+System.getProperty("mrj.version"));
                  if (cachedPreWindowedImage != null && useConvertToMostFavorableImageType) {
//long conversionTime = System.currentTimeMillis();
                        cachedPreWindowedImage=BufferedImageUtilities.convertToMostFavorableImageType(cachedPreWindowedImage);
//System.err.println("SingleImagePanel.paintComponent(): converted to most favorable done in "+(System.currentTimeMillis()-conversionTime)+" ms");
                  }
            }
            else {
//System.err.println("SingleImagePanel.paintComponent(): using cachedPreWindowedImage");
            }
                        
//long drawImageTime = System.currentTimeMillis();
            Graphics2D g2d=(Graphics2D)g;
            if (cachedPreWindowedImage != null) {
//System.err.println("SingleImagePanel.paintComponent(): same size draw");
                  Shape holdClip = null;
                  if (displayShutter != null) {
                        holdClip = g2d.getClip();
                        if (displayShutter.isCircularShutter()) {
                              Point2D tlhc = imageToWindowCoordinateTransform.transform(displayShutter.getCircularShutterTLHC(),null);
                              double tlhcX = tlhc.getX();
                              double tlhcY = tlhc.getY();
                              Point2D brhc = imageToWindowCoordinateTransform.transform(displayShutter.getCircularShutterBRHC(),null);
                              double brhcX = brhc.getX();
                              double brhcY = brhc.getY();
                              g2d.clip(new Ellipse2D.Double(tlhcX,tlhcY,brhcX-tlhcX,brhcY-tlhcY));
                        }
                        if (displayShutter.isRectangularShutter()) {
                              Point2D tlhc = imageToWindowCoordinateTransform.transform(displayShutter.getRectangularShutterTLHC(),null);
                              double tlhcX = tlhc.getX();
                              double tlhcY = tlhc.getY();
                              Point2D brhc = imageToWindowCoordinateTransform.transform(displayShutter.getRectangularShutterBRHC(),null);
                              double brhcX = brhc.getX();
                              double brhcY = brhc.getY();
                              g2d.clip(new Rectangle2D.Double(tlhcX,tlhcY,brhcX-tlhcX,brhcY-tlhcY));
                        }
                        if (displayShutter.isPolygonalShutter()) {
                              Point2D[] points = displayShutter.getVerticesOfPolygonalShutterAsPoint2D();
                              Polygon polygon = new Polygon();
                              for (int i=0; i<points.length; ++i) {
                                    Point2D point = imageToWindowCoordinateTransform.transform(points[i],null);
                                    polygon.addPoint((int)(point.getX()),(int)(point.getY()));
                              }
                              g2d.clip(polygon);
                        }
                  }
                  g2d.drawImage(cachedPreWindowedImage,offsetDrawingOfResizedSelectedRegionImageX,offsetDrawingOfResizedSelectedRegionImageY,this);
                  if (holdClip != null) {
                        g2d.setClip(holdClip);
                  }
            }
//System.err.println("SingleImagePanel.paintComponent(): draw cachedPreWindowedImage into dst image done in "+(System.currentTimeMillis()-drawImageTime)+" ms");

//long drawAnnotationsTime = System.currentTimeMillis();
            Color interactiveColor = Color.red;
            Color persistentColor = Color.green;
            Color selectedColor = Color.red;
            Color localizerColor = Color.green;
            Color volumeLocalizationColor = Color.blue;
            Color preDefinedColor = Color.yellow;
            int lineWidth = 2;
            Font preDefinedFont = new Font("SansSerif",Font.BOLD,14);
            Font persistentFont = new Font("SansSerif",Font.BOLD,10);
            
            // draw any graphics that are displayed area relative ...
                        
            if (demographicAndTechniqueAnnotations != null) {
                  g2d.setColor(demographicAndTechniqueColor);
                  g2d.setFont(demographicAndTechniqueFont);

                  Iterator i = demographicAndTechniqueAnnotations.iterator(useSrcImageIndex);
                  while (i.hasNext()) {
                        TextAnnotationPositioned.drawPositionedString((TextAnnotationPositioned)i.next(),g2d,this,5,5);
                  }

            }
            
            {
                  g2d.setColor(orientationColor);
                  g2d.setFont(orientationFont);
                  // draw orientation
                  if (orientationAnnotations != null) {
                        String rowOrientation = orientationAnnotations.getRowOrientation(useSrcImageIndex);
                        if (rowOrientation != null && rowOrientation.length() > 0) {
                              TextAnnotationPositioned.drawVerticallyCenteredString(rowOrientation,showOrientationsLeftSide,g2d,this,5);
                        }
                        String columnOrientation = orientationAnnotations.getColumnOrientation(useSrcImageIndex);
                        if (columnOrientation != null && columnOrientation.length() > 0) {
                              TextAnnotationPositioned.drawHorizontallyCenteredString(columnOrientation,false/*isTop*/,g2d,this,5);
                        }
                  }
                  
                  if (showZoomFactor) {
                        double scaleFactor = Math.abs(imageToWindowCoordinateTransform.getScaleX());        // -ve if flipped; should check same in both axes ? :(
                        String sZoomFactor = "1:" + FloatFormatter.toString(scaleFactor);
//System.err.println("SingleImagePanel.paintComponent(): sZoomFactor = "+sZoomFactor);
                        TextAnnotationPositioned.drawVerticallyCenteredString(sZoomFactor,showZoomFactorLeftSide,g2d,this,2,5);
                        String sDisplayPixelSize = "[" + FloatFormatter.toString(pixelSpacingInSourceImage/scaleFactor) + "mm]";
                        TextAnnotationPositioned.drawVerticallyCenteredString(sDisplayPixelSize,showZoomFactorLeftSide,g2d,this,3,5);
                  }
            }

            if (sideAndViewAnnotationString != null) {
                  g2d.setColor(sideAndViewAnnotationColor);
                  g2d.setFont(sideAndViewAnnotationFont);
                  TextAnnotationPositioned.drawPositionedString(
                        new TextAnnotationPositioned(sideAndViewAnnotationString,showSideAndViewAnnotationLeftSide,true/*fromTop*/,0/*row*/),
                              g2d,this,sideAndViewAnnotationVerticalOffset,5
                  );
            }

            // draw any text that are image relative, but using display relative font size
            // by transforming point BEFORE changing graphics context to image relative
            
            if (persistentDrawingText != null) {
                  g2d.setColor(persistentColor);
                  g2d.setFont(persistentFont);
                  Iterator i = persistentDrawingText.iterator();
                  while (i.hasNext()) {
                        TextAnnotation text = (TextAnnotation)i.next();
                        Point imageRelativeAnchorPoint = text.getAnchorPoint();
                        Point2D windowRelativeAnchorPoint = imageToWindowCoordinateTransform.transform(imageRelativeAnchorPoint,null);
                        String string = text.getString();
                        int margin = 5;
                        int stringWidth  = (int)(g2d.getFontMetrics().getStringBounds(string,g2d).getWidth());
                        DrawingUtilities.drawShadowedString(string,
                              showOrientationsLeftSide ? margin : getBounds().width - margin - stringWidth,
                              (int)windowRelativeAnchorPoint.getY(),                // always left or right since sometimes doesn't fit (clipped on right) if drawn at anchor point:(
                              g2d);
                  }
            }

            // draw any graphics that are image relative, by applying a scaled AffineTransform to the graphics context ...

//System.err.println("SingleImagePanel.paintComponent(): draw any graphics");
            
            g2d.transform(imageToWindowCoordinateTransform);
            
            if (showOverlays && overlay != null && overlay.getNumberOfOverlays(useSrcImageIndex) > 0) {
//System.err.println("SingleImagePanel.paintComponent(): Drawing overlays for frame "+useSrcImageIndex);
                  for (int o=0; o<16; ++o) {
                        BufferedImage overlayImage = overlay.getOverlayAsBinaryBufferedImage(useSrcImageIndex,o);
                        if (overlayImage != null) {
//System.err.println("SingleImagePanel.paintComponent(): Drawing overlay number "+o);
                              int rowOrigin = overlay.getRowOrigin(useSrcImageIndex,o);
                              int columnOrigin = overlay.getColumnOrigin(useSrcImageIndex,o);
                              {
                                    byte[] red = { (byte)0, (byte)0 };
                                    byte[] green = { (byte)0, (byte)0 };
                                    byte[] blue = { (byte)0, (byte)0 };
                                    IndexColorModel colorModel = new IndexColorModel(
                                          1 /* bits */,
                                          2 /* size */,
                                          red,green,blue,
                                          0 /* the first index (black value) is to be transparent */);
                                    BufferedImage shadowImage = new BufferedImage(colorModel,overlayImage.getRaster(),false,null);
                                    g2d.drawImage(shadowImage,null,columnOrigin+1,rowOrigin+1);
                              }
                              g2d.drawImage(overlayImage,null,columnOrigin,rowOrigin);
                        }
                  }
            }
            
            if (interactiveDrawingShapes != null) {
//System.err.println("SingleImagePanel.paintComponent(): Draw interactive shapes:");
//LocalizerPosterFactory.dumpShapes(interactiveDrawingShapes);
                  g2d.setColor(interactiveColor);
                  Iterator i = interactiveDrawingShapes.iterator();
                  while (i.hasNext()) {
                        DrawingUtilities.drawShadowedShape((Shape)i.next(),g2d);
                  }
            }

            if (persistentDrawingShapes != null) {
//System.err.println("SingleImagePanel.paintComponent(): Draw persistent shapes:");
//LocalizerPosterFactory.dumpShapes(persistentDrawingShapes);
                  g2d.setColor(persistentColor);
                  Iterator i = persistentDrawingShapes.iterator();
                  while (i.hasNext()) {
                        DrawingUtilities.drawShadowedShape((Shape)i.next(),g2d);
                  }
            }

            if (selectedDrawingShapes != null) {
//System.err.println("SingleImagePanel.paintComponent(): Draw selected shapes:");
//LocalizerPosterFactory.dumpShapes(persistentDrawingShapes);
                  g2d.setColor(selectedColor);
                  Iterator i = selectedDrawingShapes.iterator();
                  while (i.hasNext()) {
                        DrawingUtilities.drawShadowedShape((Shape)i.next(),g2d);
                  }
            }

            if (volumeLocalizationShapes != null) {
//System.err.println("SingleImagePanel.paintComponent(): draw volume localization shapes");
//LocalizerPosterFactory.dumpShapes(volumeLocalizationShapes);
                  g2d.setColor(volumeLocalizationColor);
                  Iterator i = volumeLocalizationShapes.iterator();
                  while (i.hasNext()) {
                        DrawingUtilities.drawShadowedShape((Shape)i.next(),g2d);
                  }
            }
            
            if (localizerShapes != null) {                  // do this after volumeLocalizationShapes, in case need to draw on top
//System.err.println("SingleImagePanel.paintComponent(): draw localizer shapes");
//LocalizerPosterFactory.dumpShapes(localizerShapes);
                  g2d.setColor(localizerColor);
                  Iterator i = localizerShapes.iterator();
                  while (i.hasNext()) {
                        DrawingUtilities.drawShadowedShape((Shape)i.next(),g2d);
                  }
            }
            
            if (preDefinedShapes != null) {
                  g2d.setColor(preDefinedColor);
                  g2d.setStroke(new BasicStroke(lineWidth));
                  Iterator i = preDefinedShapes.iterator();
                  while (i.hasNext()) {
                        DrawingUtilities.drawShadowedShape((Shape)i.next(),g2d);
                  }
            }

            if (preDefinedText != null) {
                  g2d.setColor(preDefinedColor);
                  g2d.setFont(preDefinedFont);
                  Iterator i = preDefinedText.iterator();
                  while (i.hasNext()) {
                        TextAnnotation text = (TextAnnotation)i.next();
                        DrawingUtilities.drawShadowedString(text.getString(),text.getAnchorPointXAsInt(),text.getAnchorPointYAsInt(),g2d);
                  }
            }
//System.err.println("SingleImagePanel.paintComponent(): draw annotations done in "+(System.currentTimeMillis()-drawAnnotationsTime)+" ms");
            
            setCursor(was);
//System.err.println("paintComponent() elapsed: "+(System.currentTimeMillis()-startTime)+" ms");
//System.err.println("SingleImagePanel.paintComponent(): end");
      }


Generated by  Doxygen 1.6.0   Back to index