Example #1
0
  /**
   * Creates ImageColorMap from a file
   *
   * @param imageSource source of the image. Can be url, BufferedImage or ImageWrapper
   * @param sizex - width of the image
   * @param sizey - height of the image
   * @param sizez - depth of the image
   */
  public ImageColorMap(Object imageSource, double sizex, double sizey, double sizez) {

    super.addParams(m_aparams);

    mp_imageSource.setValue(imageSource);
    mp_size.setValue(new Vector3d(sizex, sizey, sizez));
  }
Example #2
0
  /** @noRefGuide */
  private int prepareImage() {

    long t0 = time();

    printf("ImageColorMap.prepareImage()\n");

    Object imageSource = mp_imageSource.getValue();
    if (imageSource == null) throw new RuntimeException("imageSource is null");

    if (imageSource instanceof String) {

      try {
        m_imageData = new ImageColor(ImageIO.read(new File((String) imageSource)));
      } catch (IOException e) {
        printf("Can't find file: %s\n", imageSource);
        // empty 1x1 image
        m_imageData = new ImageColor(1, 1);
        throw new RuntimeException(e);
      }

    } else if (imageSource instanceof Text2D) {

      m_imageData = new ImageColor(((Text2D) imageSource).getImage());
    } else if (imageSource instanceof FormattedText2D) {

      m_imageData = new ImageColor(((FormattedText2D) imageSource).getImage());

    } else if (imageSource instanceof BufferedImage) {

      m_imageData = new ImageColor((BufferedImage) imageSource);

    } else if (imageSource instanceof ImageWrapper) {

      m_imageData = new ImageColor(((ImageWrapper) imageSource).getImage());
    }

    if (m_imageData == null) {
      // Cast to String for now, not sure how to really handle this
      String file = imageSource.toString();
      printf("Converted to string: " + file);
      try {
        m_imageData = new ImageColor(ImageIO.read(new File(file)));
      } catch (IOException e) {
        // empty 1x1 image
        m_imageData = new ImageColor(1, 1);
        throw new RuntimeException(e);
      }
    }
    if (m_imageData == null) {
      m_imageData = new ImageColor(1, 1);
      throw new IllegalArgumentException(
          "Unhandled imageSource: " + imageSource + " class: " + imageSource.getClass());
    }

    return ResultCodes.RESULT_OK;
  }
Example #3
0
 /**
  * Get the source image
  *
  * @return
  */
 public Object getImage() {
   return mp_imageSource.getValue();
 }
Example #4
0
 /**
  * Set the source image
  *
  * @param val
  */
 public void setImage(Object val) {
   mp_imageSource.setValue(val);
 }