Example #1
0
 /** Creates the images composing the grid. */
 private void createGridImagesAsTextures() {
   if (parent.getColorModel().equals(ImViewer.GREY_SCALE_MODEL)) {
     if (!hasGridImagesAsTexture()) {
       clearTextureMap(gridImagesAsTextures);
       gridImagesAsTextures = parent.getGridImagesAsTexture();
     }
   } else {
     clearTextureMap(gridImagesAsTextures);
     gridImagesAsTextures = parent.getGridImagesAsTexture();
   }
 }
Example #2
0
 /** Creates the images composing the grid. */
 private void createGridImages() {
   // if (combinedImage == null) return;
   if (originalGridImages == null) originalGridImages = new ArrayList<BufferedImage>();
   clearList(gridImages);
   if (ImViewer.GREY_SCALE_MODEL.equals(parent.getColorModel())) {
     createGridImagesForGreyScale();
     return;
   }
   List l = parent.getActiveChannels();
   int maxC = parent.getMaxC();
   switch (l.size()) {
     case 0:
       for (int i = 0; i < maxC; i++) gridImages.add(null);
       break;
     case 1:
     case 2:
     case 3:
       if (isImageMappedRGB(l) && !parent.isCompressed()) {
         combinedImage = null;
         combinedImage = Factory.magnifyImage(gridRatio, renderedImage);
         int w = combinedImage.getWidth();
         int h = combinedImage.getHeight();
         DataBuffer buf = combinedImage.getRaster().getDataBuffer();
         List<ChannelData> list = parent.getSortedChannelData();
         Iterator<ChannelData> i = list.iterator();
         int index;
         while (i.hasNext()) {
           index = i.next().getIndex();
           if (parent.isChannelActive(index)) {
             if (parent.isChannelRed(index)) {
               gridImages.add(
                   Factory.createBandImage(
                       buf, w, h, Factory.RED_MASK, Factory.BLANK_MASK, Factory.BLANK_MASK));
             } else if (parent.isChannelGreen(index)) {
               gridImages.add(
                   Factory.createBandImage(
                       buf, w, h, Factory.BLANK_MASK, Factory.GREEN_MASK, Factory.BLANK_MASK));
             } else if (parent.isChannelBlue(index)) {
               gridImages.add(
                   Factory.createBandImage(
                       buf, w, h, Factory.BLANK_MASK, Factory.BLANK_MASK, Factory.BLUE_MASK));
             }
           } else {
             gridImages.add(null);
           }
         }
       } else {
         retrieveGridImages();
       }
       break;
     default:
       retrieveGridImages();
   }
 }
Example #3
0
 /**
  * Sets the ratio of the grid image.
  *
  * @param gridRatio The value to set.
  */
 void setGridRatio(double gridRatio) {
   // if (ratio == 1) return; //We don't want to be too small.
   double max = ZoomGridAction.MAX_ZOOM_FACTOR;
   if (gridRatio > max) return;
   this.gridRatio = gridRatio;
   if (ImViewerAgent.hasOpenGLSupport()) return;
   if (CollectionUtils.isEmpty(originalGridImages)) {
     try {
       createGridImages();
     } catch (Exception e) {
       handleGridImageCreationException(e);
     }
     return;
   }
   int n = originalGridImages.size();
   clearList(gridImages);
   int maxC = parent.getMaxC();
   switch (n) {
     case 0:
       for (int i = 0; i < maxC; i++) gridImages.add(null);
       break;
     case 1:
     case 2:
     case 3:
       // TODO: Review that code.
       if (isImageMappedRGB(parent.getActiveChannels())) {
         try {
           createGridImages();
         } catch (Exception e) {
           handleGridImageCreationException(e);
         }
       } else {
         combinedImage = null;
         combinedImage = Factory.magnifyImage(gridRatio, renderedImage);
         Iterator<BufferedImage> i = originalGridImages.iterator();
         while (i.hasNext()) {
           gridImages.add(Factory.magnifyImage(gridRatio, i.next()));
         }
       }
       break;
     default:
       combinedImage = null;
       combinedImage = Factory.magnifyImage(gridRatio, renderedImage);
       Iterator<BufferedImage> i = originalGridImages.iterator();
       while (i.hasNext()) {
         gridImages.add(Factory.magnifyImage(gridRatio, i.next()));
       }
   }
 }
Example #4
0
 /**
  * Returns the number of row for the grid.
  *
  * @return See above.
  */
 int getGridRow() {
   int n = parent.getMaxC();
   if (n == 1) return 1;
   if (n == 2 || n == 3) return 2;
   int row = n / 2;
   if (n % 2 != 0) row += 1;
   return row;
 }
Example #5
0
  /** Creates the images composing the grid when the color model is <code>GreyScale</code>. */
  private void createGridImagesForGreyScale() {
    int maxC = parent.getMaxC();
    List l = parent.getActiveChannelsInGrid();
    int n = l.size();
    clearList(gridImages);
    if (combinedImage != null) combinedImage.flush();
    switch (n) {
      case 0:
        for (int i = 0; i < maxC; i++) gridImages.add(null);
        combinedImage = null;
        break;
      case 1:
      case 2:
      case 3:
        if (isImageMappedRGB(l)) {
          BufferedImage image = parent.getCombinedGridImage();
          if (image == null) {
            for (int i = 0; i < maxC; i++) gridImages.add(null);
            break;
          }
          combinedImage = Factory.magnifyImage(gridRatio, image);

          int w = combinedImage.getWidth();
          int h = combinedImage.getHeight();

          DataBuffer buf = combinedImage.getRaster().getDataBuffer();
          List<ChannelData> list = parent.getSortedChannelData();
          Iterator<ChannelData> i = list.iterator();
          int index;
          while (i.hasNext()) {
            index = i.next().getIndex();
            if (l.contains(index)) {
              if (parent.isChannelRed(index)) {
                gridImages.add(
                    Factory.createBandImage(
                        buf, w, h, Factory.RED_MASK, Factory.RED_MASK, Factory.RED_MASK));
              } else if (parent.isChannelGreen(index)) {
                gridImages.add(
                    Factory.createBandImage(
                        buf, w, h, Factory.GREEN_MASK, Factory.GREEN_MASK, Factory.GREEN_MASK));
              } else if (parent.isChannelBlue(index)) {
                gridImages.add(
                    Factory.createBandImage(
                        buf, w, h, Factory.BLUE_MASK, Factory.BLUE_MASK, Factory.BLUE_MASK));
              }
            } else {
              gridImages.add(null);
            }
          }
        } else {
          retrieveGridImagesForGreyScale(l);
        }
        break;

      default:
        retrieveGridImagesForGreyScale(l);
    }
  }
Example #6
0
 /**
  * Retrieves the images composing the grid when the color model is <code>RBG</code> and when the
  * channels are not mapped to red, green or blue i.e. a channel mapped to yellow.
  */
 private void retrieveGridImages() {
   List<BufferedImage> images = parent.getGridImages();
   if (images != null) {
     Iterator<BufferedImage> i = images.iterator();
     boolean b = originalGridImages.size() == 0;
     BufferedImage img;
     while (i.hasNext()) {
       img = i.next();
       gridImages.add(Factory.magnifyImage(img, gridRatio, 0));
       if (b) originalGridImages.add(img);
     }
     combinedImage = Factory.magnifyImage(renderedImage, gridRatio, 0);
   }
 }
Example #7
0
 /**
  * Returns the list of grid images for openGL.
  *
  * @return See above.
  */
 List<GridImage> getGridImages() {
   List<GridImage> list = new ArrayList<GridImage>();
   List<ChannelData> l = parent.getSortedChannelData();
   Iterator<ChannelData> i = l.iterator();
   int index;
   GridImage image;
   // boolean[] rgb;
   ChannelData data;
   String label;
   boolean b = isRenderedImageRGB();
   if (!isModelRGB()) b = false;
   while (i.hasNext()) {
     data = i.next();
     index = data.getIndex();
     label = data.getChannelLabeling();
     // rgb = new boolean[3];
     if (parent.isChannelActive(index)) {
       /*
       if (b) {
       	rgb[0] = !parent.isChannelRed(index);
       	rgb[1] = !parent.isChannelGreen(index);
       	rgb[2] = !parent.isChannelBlue(index);
       	image = new GridImage(index, true, label, rgb);
       } else {
       	image = new GridImage(index, true, label);
       	image.setTextureData(gridImagesAsTextures.get(index));
       }
       */
       image = new GridImage(index, true, label);
       image.setTextureData(gridImagesAsTextures.get(index));
     } else {
       image = new GridImage(index, false, label);
     }
     list.add(image);
   }
   return list;
 }
Example #8
0
  /**
   * Creates a single image.
   *
   * @param image The image to create.
   * @param constraint The constraint indicating to add the scale bar.
   * @param name The name of the image.
   * @throws EncoderException
   * @throws IOException
   */
  private void writeSingleImage(BufferedImage image, boolean constraint, String name)
      throws EncoderException, IOException {
    int width = image.getWidth();
    int h = image.getHeight();
    String v = getUnitBarValue();
    int s = (int) model.getUnitBarSize();

    BufferedImage newImage = new BufferedImage(width, h, BufferedImage.TYPE_INT_RGB);
    Graphics2D g2 = (Graphics2D) newImage.getGraphics();
    ImagePaintingFactory.setGraphicRenderingSettings(g2);
    // Paint the original image.
    g2.drawImage(image, null, 0, 0);

    if (constraint) ImagePaintingFactory.paintScaleBar(g2, width - s - 10, h - 10, s, v);
    writeImage(newImage, name);
  }
Example #9
0
 /**
  * Retrieves the images composing the grid when the color model is <code>GreyScale</code> and when
  * the channels are not mapped to red, green or blue i.e. a channel mapped to yellow.
  *
  * @param channels Collection of active channels in the grid.
  */
 private void retrieveGridImagesForGreyScale(List channels) {
   List<BufferedImage> images = parent.getGridImages();
   if (images != null) {
     int last = images.size() - 1;
     combinedImage = Factory.magnifyImage(gridRatio, images.get(last));
     images.remove(last);
     Iterator<BufferedImage> i = images.iterator();
     boolean b = originalGridImages.size() == 0 && !isImageMappedRGB(channels);
     BufferedImage img;
     while (i.hasNext()) {
       img = i.next();
       gridImages.add(Factory.magnifyImage(gridRatio, img));
       if (b) originalGridImages.add(img);
     }
   }
 }
Example #10
0
 /**
  * Returns the size of the grid.
  *
  * @return See above.
  */
 Dimension getGridSize() {
   int w = (int) (getMaxX() * gridRatio);
   int h = (int) (getMaxY() * gridRatio);
   int n = parent.getMaxC();
   int row = 0;
   int col = 0;
   if (n == 1) {
     row = 1;
     col = 2;
   } else if (n == 2 || n == 3) {
     row = 2;
     col = 2;
   } else {
     col = 3;
     row = n / 2;
     if (n % 2 != 0) row += 1;
   }
   return new Dimension(col * w + (col - 1) * GAP, row * h + (row - 1) * GAP);
 }
Example #11
0
 /**
  * Returns a collection of images composing the grid.
  *
  * @return See above.
  */
 List<SplitImage> getSplitImages() {
   if (splitImages == null) splitImages = new ArrayList<SplitImage>();
   else splitImages.clear();
   String n;
   splitImages = new ArrayList<SplitImage>();
   List<ChannelData> list = parent.getSortedChannelData();
   Iterator<ChannelData> i = list.iterator();
   ChannelData channel;
   int j = 0;
   int size = gridImages.size();
   while (i.hasNext()) {
     channel = i.next();
     n = PREFIX + channel.getChannelLabeling();
     if (j >= size) splitImages.add(new SplitImage(null, n));
     else splitImages.add(new SplitImage(gridImages.get(j), n));
     j++;
   }
   splitImages.add(new SplitImage(combinedImage, COMBINED));
   return splitImages;
 }
Example #12
0
 /**
  * Sets the selected XY-plane. A new plane is then rendered.
  *
  * @param z The selected z-section.
  * @param t The selected timepoint.
  */
 void setSelectedXYPlane(int z, int t) {
   parent.setSelectedXYPlane(z, t);
 }
Example #13
0
 /**
  * Returns <code>true</code> if the textual information is painted on top of the grid image,
  * <code>false</code> otherwise.
  *
  * @return See above.
  */
 boolean isTextVisible() {
   return parent.isTextVisible();
 }
Example #14
0
 /**
  * Returns the index of the selected pane.
  *
  * @return See above.
  */
 int getSelectedIndex() {
   return parent.getSelectedIndex();
 }
Example #15
0
 /**
  * Returns the size of the tiled image along the Y-axis i.e. the size of a tile along the Y-axis
  * multiplied by the number of rows.
  *
  * @return See above.
  */
 int getTiledImageSizeY() {
   return parent.getTiledImageSizeY();
 }
Example #16
0
 /**
  * Loads the tiles.
  *
  * @param r The selected rectangle.
  */
 void loadTiles(Rectangle r) {
   parent.loadTiles(r);
 }
Example #17
0
 /**
  * Returns the size of the unit bar.
  *
  * @return See above.
  */
 double getUnitBarSize() {
   return model.getUnitBarSize();
 }
Example #18
0
 /**
  * Returns <code>true</code> if the unit bar is painted on top of the displayed image, <code>false
  * </code> otherwise.
  *
  * @return See above.
  */
 boolean isUnitBar() {
   return model.isUnitBar();
 }
Example #19
0
 /**
  * Returns the name of the image.
  *
  * @return See above.
  */
 String getPartialImageName() {
   return UIUtilities.removeFileExtension(model.getImageName());
 }
Example #20
0
 /**
  * Sets the value of the flag controlling if the unit bar is painted or not.
  *
  * @param unitBar Pass <code>true</code> to paint the unit bar, <code>false</code> otherwise.
  */
 void setUnitBar(boolean unitBar) {
   double v = EditorUtil.transformSize(parent.getPixelsSizeX()).getValue();
   if (v == 0 || v == 1) unitBar = false;
   this.unitBar = unitBar;
 }
Example #21
0
 /**
  * Returns the number of timepoints.
  *
  * @return See above.
  */
 int getMaxT() {
   return parent.getRealT();
 }
Example #22
0
 /**
  * Returns <code>true</code> if the active channels are mapped to <code>Red</code>, <code>Green
  * </code> or <code>Blue</code>, <code>false</code> only and exclusively, if the number of active
  * channels is 0 or greater than 3.
  *
  * @param channels The collection of channels to handle.
  * @return See above.
  */
 private boolean isImageMappedRGB(List channels) {
   return parent.isMappedImageRGB(channels);
 }
Example #23
0
 /**
  * Displays the preview dialog with images depending on the saving type.
  *
  * @param savingType The type of saving.
  */
 private void createImages(int savingType) {
   boolean b = uiDelegate.includeROI();
   switch (savingType) {
     default:
     case ImgSaverUI.IMAGE:
       imageType = ImgSaverUI.IMAGE;
       mainImage = model.getDisplayedImage(b);
       imageComponents = null;
       break;
     case ImgSaverUI.GRID_IMAGE:
       imageType = ImgSaverUI.GRID_IMAGE;
       mainImage = model.getGridImage();
       imageComponents = null;
       break;
     case ImgSaverUI.PROJECTED_IMAGE:
       imageType = ImgSaverUI.PROJECTED_IMAGE;
       mainImage = model.getDisplayedProjectedImage();
       imageComponents = null;
       break;
     case ImgSaverUI.IMAGE_AND_COMPONENTS:
       imageType = ImgSaverUI.IMAGE_AND_COMPONENTS;
       mainImage = model.getDisplayedImage(b);
       imageComponents = model.getImageComponents(ImViewer.RGB_MODEL, b);
       break;
     case ImgSaverUI.IMAGE_AND_COMPONENTS_GREY:
       imageType = ImgSaverUI.IMAGE_AND_COMPONENTS;
       mainImage = model.getDisplayedImage(b);
       imageComponents = model.getImageComponents(ImViewer.GREY_SCALE_MODEL, b);
       break;
     case ImgSaverUI.LENS_IMAGE:
       imageType = ImgSaverUI.LENS_IMAGE;
       mainImage = model.getZoomedLensImage();
       imageComponents = null;
       break;
     case ImgSaverUI.LENS_IMAGE_AND_COMPONENTS:
       imageType = ImgSaverUI.LENS_IMAGE_AND_COMPONENTS;
       mainImage = model.getZoomedLensImage();
       imageComponents = model.getLensImageComponents(ImViewer.RGB_MODEL);
       break;
     case ImgSaverUI.LENS_IMAGE_AND_COMPONENTS_GREY:
       imageType = ImgSaverUI.LENS_IMAGE_AND_COMPONENTS;
       mainImage = model.getZoomedLensImage();
       imageComponents = model.getLensImageComponents(ImViewer.GREY_SCALE_MODEL);
   }
 }
Example #24
0
 /**
  * Returns the real timepoint.
  *
  * @return See above.
  */
 int getRealSelectedT() {
   return parent.getRealSelectedT();
 }
Example #25
0
  /**
   * Saves the displayed images.
   *
   * @param init Pass <code>true</code> to initialize the images to save, <code>false</code>
   *     otherwise.
   */
  void saveImage(boolean init) {
    UserNotifier un = ImViewerAgent.getRegistry().getUserNotifier();
    if (init) createImages(uiDelegate.getSavingType());
    // Builds the image to display.
    boolean unitBar = model.isUnitBar();
    String v = getUnitBarValue();
    int s = (int) getUnitBarSize();
    boolean constrain;
    try {
      String name = uiDelegate.getSelectedFilePath();

      // make sure the parent directory paths all exist
      FileUtils.forceMkdir(new File(name).getParentFile());

      if (imageComponents == null) {
        constrain =
            unitBar && v != null && s < mainImage.getWidth() && imageType == ImgSaverUI.IMAGE;
        writeSingleImage(mainImage, constrain, name);
      } else {
        if (mainImage == null) return;
        Iterator i;
        int h, w;
        BufferedImage newImage;
        Graphics2D g2;
        if (uiDelegate.isSaveImagesInSeparatedFiles()) {
          constrain =
              unitBar && v != null && s < mainImage.getWidth() && imageType == ImgSaverUI.IMAGE;
          writeSingleImage(mainImage, constrain, name);
          i = imageComponents.iterator();
          int j = 0;
          while (i.hasNext()) {
            constrain = unitBar && v != null && imageType != ImgSaverUI.LENS_IMAGE_AND_COMPONENTS;
            writeSingleImage((BufferedImage) i.next(), constrain, name + "_" + j);
            j++;
          }
        } else {
          int width = mainImage.getWidth();
          h = mainImage.getHeight();
          int n = imageComponents.size();
          w = width * (n + 1) + ImgSaverPreviewer.SPACE * (n - 1);

          newImage = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
          g2 = (Graphics2D) newImage.getGraphics();
          g2.setColor(Color.WHITE);
          ImagePaintingFactory.setGraphicRenderingSettings(g2);
          // Paint the original image.
          i = imageComponents.iterator();
          int x = 0;
          while (i.hasNext()) {
            g2.drawImage((BufferedImage) i.next(), null, x, 0);
            if (unitBar && v != null && imageType != ImgSaverUI.LENS_IMAGE_AND_COMPONENTS)
              ImagePaintingFactory.paintScaleBar(g2, x + width - s - 10, h - 10, s, v);
            x += width;
            g2.fillRect(x, 0, ImgSaverPreviewer.SPACE, h);
            x += ImgSaverPreviewer.SPACE;
          }
          g2.drawImage(mainImage, null, x, 0);
          if (unitBar
              && v != null
              && !(imageType == ImgSaverUI.LENS_IMAGE_AND_COMPONENTS
                  || imageType == ImgSaverUI.LENS_IMAGE))
            ImagePaintingFactory.paintScaleBar(g2, x + width - s - 10, h - 10, s, v);
          writeImage(newImage, name);
        }
      }
    } catch (Exception e) {
      if (e instanceof IOException || e.getCause() instanceof IOException)
        un.notifyInfo(
            "Save Image failure",
            "Could not access file "
                + uiDelegate.getSelectedFilePath()
                + "\nMake sure you have the necessary permissions to perform this action.");
      else un.notifyError("Save Image failure", "An error occurred while saving the image.", e);
      return;
    }
    notifySave(getExtendedName(uiDelegate.getSelectedFilePath(), format));
    if (uiDelegate.isSetDefaultFolder())
      UIUtilities.setDefaultFolder(uiDelegate.getCurrentDirectory());
  }
Example #26
0
 /**
  * Returns the default z-section.
  *
  * @return See above.
  */
 int getDefaultZ() {
   return parent.getDefaultZ();
 }
Example #27
0
 /**
  * Returns the value (with two decimals) of the unit bar or <code>null</code> if the actual value
  * is <i>negative</i>.
  *
  * @return See above.
  */
 String getUnitBarValue() {
   return model.getUnitBarValue();
 }
Example #28
0
 /**
  * Returns the number of pixels along the Y-axis.
  *
  * @return See above.
  */
 int getMaxY() {
   return parent.getMaxY();
 }
Example #29
0
 /**
  * Returns the color of the unit bar.
  *
  * @return See above.
  */
 Color getUnitBarColor() {
   return model.getUnitBarColor();
 }
Example #30
0
 /**
  * Returns the size in microns of a pixel along the Y-axis.
  *
  * @return See above.
  */
 double getPixelsSizeZ() {
   return parent.getPixelsSizeZ();
 }