コード例 #1
0
ファイル: IOParameterPage.java プロジェクト: TonioF/beam
 private static ParamGroup createDefaultParamGroup(final InputProductValidator validator) {
   final ParamGroup paramGroup = new ParamGroup();
   final DefaultRequestElementFactory factory = DefaultRequestElementFactory.getInstance();
   final Parameter inputProductParameter = factory.createDefaultInputProductParameter();
   inputProductParameter.addParamChangeListener(
       new ParamChangeListener() {
         public void parameterValueChanged(final ParamChangeEvent event) {
           validateInputProduct(event.getParameter(), validator);
         }
       });
   paramGroup.addParameter(inputProductParameter);
   final Parameter outputProductParameter = factory.createDefaultOutputProductParameter();
   final Object defaultValue = outputProductParameter.getProperties().getDefaultValue();
   if (defaultValue instanceof File) {
     outputProductParameter
         .getProperties()
         .setDefaultValue(new File((File) defaultValue, _defaultOutputProductFileName));
   }
   paramGroup.addParameter(outputProductParameter);
   paramGroup.addParameter(factory.createOutputFormatParameter());
   paramGroup.addParameter(factory.createDefaultLogPatternParameter(_defaultLogPrefix));
   try {
     paramGroup.addParameter(factory.createLogToOutputParameter(_defaultLogToOutput));
   } catch (ParamValidateException e) {
     Debug.trace("Unable to validate parameter '" + LOG_TO_OUTPUT_PARAM_NAME + "'"); /*I18N*/
     Debug.trace(e);
   }
   return paramGroup;
 }
コード例 #2
0
  /**
   * Activates the given <code>PageComponent</code>. Does nothing if it is already the active one.
   *
   * <p>Does nothing if this <code>ApplicationPage</code> doesn't contain the given <code>
   * PageComponent</code>.
   *
   * @param pageComponent the <code>PageComponent</code>
   */
  public void setActiveComponent(PageComponent pageComponent) {
    if (!pageComponentMap.containsValue(pageComponent)) {
      return;
    }

    Debug.trace("setActiveComponent: pageComponent = " + pageComponent);
    if (settingActiveComponent) {
      return;
    }

    // if pageComponent is already active, don't do anything
    if (this.activeComponent == pageComponent) {
      setActiveSelectionContext();
      return;
    }

    settingActiveComponent = true;

    if (this.activeComponent != null) {
      fireFocusLost(this.activeComponent);
    }
    giveFocusTo(pageComponent);
    this.activeComponent = pageComponent;
    fireFocusGained(this.activeComponent);

    setActiveSelectionContext();

    settingActiveComponent = false;
  }
コード例 #3
0
ファイル: Hdf5ProductWriter.java プロジェクト: maduhu/beam
 private void createScalarAttribute(
     int locationID, String name, int jh5DataType, int typeSize, Object value) throws IOException {
   Debug.trace(
       "Hdf5ProductWriter.createScalarAttribute("
           + "locationID="
           + locationID
           + ", name="
           + name
           + ", jh5DataType="
           + jh5DataType
           + ", typeSize="
           + typeSize
           + ", value="
           + value
           + ")");
   int attrTypeID = -1;
   int attrSpaceID = -1;
   int attributeID = -1;
   try {
     attrTypeID = H5.H5Tcopy(jh5DataType);
     if (typeSize > 0) {
       H5.H5Tset_size(attrTypeID, typeSize);
     }
     attrSpaceID = H5.H5Screate(HDF5Constants.H5S_SCALAR);
     attributeID =
         H5.H5Acreate(locationID, name, attrTypeID, attrSpaceID, HDF5Constants.H5P_DEFAULT);
     H5.H5Awrite(attributeID, attrTypeID, value);
   } catch (HDF5Exception e) {
     throw new ProductIOException(createErrorMessage(e));
   } finally {
     closeH5A(attributeID);
     closeH5S(attrSpaceID);
     closeH5T(attrTypeID);
   }
 }
コード例 #4
0
 protected void fireClosed(PageComponent component) {
   Debug.trace("AbstractApplicationPage.fireClosed [" + component + "]");
   component.componentClosed();
   for (PageComponentListener listener : pageComponentListeners) {
     listener.componentClosed(component);
   }
 }
コード例 #5
0
  /**
   * Provides an implementation of the <code>readProductNodes</code> interface method. Clients
   * implementing this method can be sure that the input object and eventually the subset
   * information has already been set.
   *
   * <p>
   *
   * <p>This method is called as a last step in the <code>readProductNodes(input, subsetInfo)</code>
   * method.
   *
   * @throws java.io.IOException if an I/O error occurs
   */
  @Override
  protected Product readProductNodesImpl() throws IOException {

    Product product;
    try {
      final File fileFromInput = ReaderUtils.getFileFromInput(getInput());
      dataDir = createDirectory(fileFromInput);
      dataDir.readProductDirectory();
      product = dataDir.createProduct();
      addCalibrationLUT(product, fileFromInput.getParentFile());
      product.getGcpGroup();
      product.setFileLocation(fileFromInput);
      product.setProductReader(this);
      product.setModified(false);

      final MetadataElement absRoot = AbstractMetadata.getAbstractedMetadata(product);
      isAscending = absRoot.getAttributeString(AbstractMetadata.PASS).equals("ASCENDING");
      isAntennaPointingRight =
          absRoot.getAttributeString(AbstractMetadata.antenna_pointing).equals("right");
    } catch (Exception e) {
      Debug.trace(e.toString());
      final IOException ioException = new IOException(e.getMessage());
      ioException.initCause(e);
      throw ioException;
    }

    return product;
  }
コード例 #6
0
 protected void fireFocusLost(PageComponent component) {
   Debug.trace("AbstractApplicationPage.fireFocusLost [" + component + "]");
   component.componentFocusLost();
   for (PageComponentListener listener : pageComponentListeners) {
     listener.componentFocusLost(component);
   }
 }
コード例 #7
0
    private BufferedImage createThumbNailImage(Dimension imgSize, ProgressMonitor pm) {
      Assert.notNull(pm, "pm");

      String thumbNailBandName = getThumbnailBandName();
      Band thumbNailBand = product.getBand(thumbNailBandName);

      Debug.trace(
          "ProductSubsetDialog: Reading thumbnail data for band '" + thumbNailBandName + "'...");
      pm.beginTask("Creating thumbnail image", 5);
      BufferedImage image = null;
      try {
        MultiLevelSource multiLevelSource =
            BandImageMultiLevelSource.create(thumbNailBand, SubProgressMonitor.create(pm, 1));
        final ImageLayer imageLayer = new ImageLayer(multiLevelSource);
        final int imageWidth = imgSize.width;
        final int imageHeight = imgSize.height;
        final int imageType = BufferedImage.TYPE_3BYTE_BGR;
        image = new BufferedImage(imageWidth, imageHeight, imageType);
        Viewport snapshotVp = new DefaultViewport(isModelYAxisDown(imageLayer));
        final BufferedImageRendering imageRendering = new BufferedImageRendering(image, snapshotVp);

        final Graphics2D graphics = imageRendering.getGraphics();
        graphics.setColor(getBackground());
        graphics.fillRect(0, 0, imageWidth, imageHeight);

        snapshotVp.zoom(imageLayer.getModelBounds());
        snapshotVp.moveViewDelta(snapshotVp.getViewBounds().x, snapshotVp.getViewBounds().y);
        imageLayer.render(imageRendering);

        pm.worked(4);
      } finally {
        pm.done();
      }
      return image;
    }
コード例 #8
0
ファイル: Hdf5ProductWriter.java プロジェクト: maduhu/beam
 private void closeH5S(int spaceID) {
   if (spaceID != -1) {
     try {
       H5.H5Sclose(spaceID);
     } catch (HDF5LibraryException e) {
       Debug.trace(e);
       /*...*/
     }
   }
 }
コード例 #9
0
ファイル: Hdf5ProductWriter.java プロジェクト: maduhu/beam
 private void closeH5A(int attributeID) {
   if (attributeID != -1) {
     try {
       H5.H5Aclose(attributeID);
     } catch (HDF5LibraryException e) {
       Debug.trace(e);
       /*...*/
     }
   }
 }
コード例 #10
0
ファイル: Hdf5ProductWriter.java プロジェクト: maduhu/beam
 private void closeH5G(int groupID) {
   if (groupID != -1) {
     try {
       H5.H5Gclose(groupID);
     } catch (HDF5LibraryException e) {
       Debug.trace(e);
       /*...*/
     }
   }
 }
コード例 #11
0
ファイル: Hdf5ProductWriter.java プロジェクト: maduhu/beam
 private void closeH5D(int datasetID) {
   if (datasetID != -1) {
     try {
       H5.H5Dclose(datasetID);
     } catch (HDF5LibraryException e) {
       Debug.trace(e);
       /*...*/
     }
   }
 }
コード例 #12
0
ファイル: Hdf5ProductWriter.java プロジェクト: maduhu/beam
 private void closeH5T(int typeID) {
   if (typeID != -1) {
     try {
       H5.H5Tclose(typeID);
     } catch (HDF5LibraryException e) {
       Debug.trace(e);
       /*...*/
     }
   }
 }
コード例 #13
0
ファイル: Hdf5ProductWriter.java プロジェクト: maduhu/beam
  private void writeTiePointGrid(TiePointGrid grid, String path) throws IOException {
    final int w = grid.getRasterWidth();
    final int h = grid.getRasterHeight();
    long[] dims = new long[] {h, w};
    int dataTypeID = -1;
    int dataSpaceID = -1;
    int datasetID = -1;
    try {
      dataTypeID = createH5TypeID(grid.getDataType());
      dataSpaceID = H5.H5Screate_simple(2, dims, null);
      datasetID =
          H5.H5Dcreate(
              _fileID,
              path + "/" + grid.getName(),
              dataTypeID,
              dataSpaceID,
              HDF5Constants.H5P_DEFAULT);

      // Very important attributes
      createScalarAttribute(datasetID, "scene_raster_width", grid.getSceneRasterWidth());
      createScalarAttribute(datasetID, "scene_raster_height", grid.getSceneRasterHeight());
      createScalarAttribute(datasetID, "offset_x", grid.getOffsetX());
      createScalarAttribute(datasetID, "offset_y", grid.getOffsetY());
      createScalarAttribute(datasetID, "sub_sampling_x", grid.getSubSamplingX());
      createScalarAttribute(datasetID, "sub_sampling_y", grid.getSubSamplingY());

      // Less important attributes
      try {
        createScalarAttribute(datasetID, "raster_width", grid.getRasterWidth());
        createScalarAttribute(datasetID, "raster_height", grid.getRasterHeight());
        createScalarAttribute(datasetID, "unit", grid.getUnit());
        createScalarAttribute(datasetID, "description", grid.getDescription());
        createScalarAttribute(datasetID, "CLASS", "IMAGE");
        createScalarAttribute(datasetID, "IMAGE_VERSION", 1.0F);
      } catch (IOException e) {
        /* ignore IOException because these attributes are not very essential... */
        Debug.trace("failed to create attribute: " + e.getMessage());
      }

      H5.H5Dwrite(
          datasetID,
          dataTypeID,
          HDF5Constants.H5S_ALL,
          HDF5Constants.H5S_ALL,
          HDF5Constants.H5P_DEFAULT,
          grid.getData().getElems());

    } catch (HDF5Exception e) {
      throw new ProductIOException(createErrorMessage(e));
    } finally {
      closeH5D(datasetID);
      closeH5S(dataSpaceID);
      closeH5T(dataTypeID);
    }
  }
コード例 #14
0
  /**
   * Creates a parameter editor instance for the given parameter.
   *
   * @param parameter the parameter
   * @return the parameter editor, never null
   */
  public static ParamEditor createParamEditor(Parameter parameter) {
    Guardian.assertNotNull("parameter", parameter);
    ParamProperties paramProps = parameter.getProperties();
    Debug.assertNotNull(paramProps);

    ParamEditor editor = null;

    // Step 1: Try to create an editor from the 'editorClass' property
    //
    Class editorClass = paramProps.getEditorClass();
    if (editorClass != null) {
      Constructor editorConstructor = null;
      try {
        editorConstructor = editorClass.getConstructor(Parameter.class);
      } catch (NoSuchMethodException e) {
        Debug.trace(e);
      } catch (SecurityException e) {
        Debug.trace(e);
      }
      if (editorConstructor != null) {
        try {
          editor = (ParamEditor) editorConstructor.newInstance(parameter);
        } catch (InstantiationException e) {
          Debug.trace(e);
        } catch (IllegalAccessException e) {
          Debug.trace(e);
        } catch (IllegalArgumentException e) {
          Debug.trace(e);
        } catch (InvocationTargetException e) {
          Debug.trace(e);
        }
      }
    }
    if (editor != null) {
      return editor;
    }

    // Step 2: Create a default editor based on the parameter's type info
    //
    if (parameter.isTypeOf(Boolean.class)) {
      editor = new BooleanEditor(parameter);
    } else if (parameter.isTypeOf(Color.class)) {
      editor = new ColorEditor(parameter);
    } else if (parameter.isTypeOf(File.class)) {
      editor = new FileEditor(parameter);
    } else if (paramProps.getValueSet() != null && paramProps.getValueSet().length > 0) {
      if (parameter.isTypeOf(String[].class)) {
        editor = new ListEditor(parameter);
      } else {
        editor = new ComboBoxEditor(parameter);
      }
    }

    // The last choice works always: a text field!
    if (editor == null) {
      editor = new TextFieldEditor(parameter);
    }

    return editor;
  }
コード例 #15
0
  private static RasterDataNode[] getReferencedNodes(final RasterDataNode node) {
    final Product product = node.getProduct();
    if (product != null) {
      final List<String> expressions = new ArrayList<String>(10);
      if (node.getValidPixelExpression() != null) {
        expressions.add(node.getValidPixelExpression());
      }
      final ProductNodeGroup<Mask> overlayMaskGroup = node.getOverlayMaskGroup();
      if (overlayMaskGroup.getNodeCount() > 0) {
        final Mask[] overlayMasks =
            overlayMaskGroup.toArray(new Mask[overlayMaskGroup.getNodeCount()]);
        for (final Mask overlayMask : overlayMasks) {
          final String expression;
          if (overlayMask.getImageType() == Mask.BandMathsType.INSTANCE) {
            expression = Mask.BandMathsType.getExpression(overlayMask);
          } else if (overlayMask.getImageType() == Mask.RangeType.INSTANCE) {
            expression = Mask.RangeType.getExpression(overlayMask);
          } else {
            expression = null;
          }
          if (expression != null) {
            expressions.add(expression);
          }
        }
      }
      if (node instanceof VirtualBand) {
        final VirtualBand virtualBand = (VirtualBand) node;
        expressions.add(virtualBand.getExpression());
      }

      final ArrayList<Term> termList = new ArrayList<Term>(10);
      for (final String expression : expressions) {
        try {
          final Term term = product.parseExpression(expression);
          if (term != null) {
            termList.add(term);
          }
        } catch (ParseException e) {
          // @todo se handle parse exception
          Debug.trace(e);
        }
      }

      final Term[] terms = termList.toArray(new Term[termList.size()]);
      final RasterDataSymbol[] refRasterDataSymbols = BandArithmetic.getRefRasterDataSymbols(terms);
      return BandArithmetic.getRefRasters(refRasterDataSymbols);
    }
    return new RasterDataNode[0];
  }
コード例 #16
0
ファイル: IOParameterPage.java プロジェクト: TonioF/beam
 private static void validateInputProduct(
     final Parameter parameter, final InputProductValidator validator) {
   final File file = (File) parameter.getValue();
   if (file == null || "".equals(file.getPath().trim())) {
     return;
   }
   String msg = null;
   if (file.exists()) {
     Product product = null;
     try {
       product = ProductIO.readProduct(file);
       if (product != null) {
         if (validator != null) {
           final boolean valid = validator.validate(product);
           if (!valid) {
             msg = validator.getErrorMessage();
             if (msg == null) {
               msg = "Unknown error.";
             }
           }
         }
       } else {
         msg = "Unknown product file format.";
       }
     } catch (IOException e) {
       msg = e.getMessage();
     } finally {
       if (product != null) {
         product.dispose();
       }
     }
   } else {
     msg = "File '" + file.getPath() + "' does not exists.";
   }
   if (msg != null) {
     JOptionPane.showMessageDialog(
         parameter.getEditor().getEditorComponent(),
         "Invalid input product file:\n" + msg,
         "Invalid Input Product",
         JOptionPane.ERROR_MESSAGE);
     Debug.trace(msg);
   }
 }
コード例 #17
0
ファイル: Hdf5ProductWriter.java プロジェクト: maduhu/beam
  /**
   * Writes the in-memory representation of a data product. This method was called by <code>
   * writeProductNodes(product,
   * output)</code> of the AbstractProductWriter.
   *
   * @throws IllegalArgumentException if <code>output</code> type is not one of the supported output
   *     sources.
   * @throws IOException if an I/O error occurs
   */
  @Override
  protected void writeProductNodesImpl() throws IOException {

    if (!_hdf5LibInit) {
      try {
        H5.H5open();
        _hdf5LibInit = true;
      } catch (HDF5LibraryException e) {
        throw new ProductIOException(createErrorMessage(e));
      }
    }

    if (getOutput() instanceof String) {
      _outputFile = new File((String) getOutput());
    } else if (getOutput() instanceof File) {
      _outputFile = (File) getOutput();
    }
    Debug.assertNotNull(_outputFile); // super.writeProductNodes should have checked this already

    _outputFile =
        FileUtils.ensureExtension(_outputFile, Hdf5ProductWriterPlugIn.HDF5_FILE_EXTENSION);

    try {
      Debug.trace("creating HDF5 file " + _outputFile.getPath());
      _fileID =
          H5.H5Fcreate(
              _outputFile.getPath(),
              HDF5Constants.H5F_ACC_TRUNC,
              HDF5Constants.H5P_DEFAULT,
              HDF5Constants.H5P_DEFAULT);
    } catch (HDF5LibraryException e) {
      throw new ProductIOException(createErrorMessage(e));
    }

    writeTiePointGrids();
    writeGeoCoding();
    writeFlagCodings();
    writeMetadata();
  }
コード例 #18
0
ファイル: Hdf5ProductWriter.java プロジェクト: maduhu/beam
 /**
  * Writes all data in memory to disk. After a flush operation, the writer can be closed safely
  *
  * @throws IOException on failure
  */
 public void flush() throws IOException {
   if (_fileID == -1) {
     return;
   }
   if (_bandIDs != null) {
     Iterator it = _bandIDs.values().iterator();
     while (it.hasNext()) {
       int datasetID = (Integer) it.next();
       if (datasetID != -1) {
         try {
           H5.H5Fflush(datasetID, HDF5Constants.H5F_SCOPE_LOCAL);
         } catch (HDF5LibraryException e) {
           Debug.trace(e);
           /*...*/
         }
       }
     }
   }
   try {
     H5.H5Fflush(_fileID, HDF5Constants.H5F_SCOPE_LOCAL);
   } catch (HDF5LibraryException e) {
     throw new ProductIOException(createErrorMessage(e));
   }
 }
コード例 #19
0
ファイル: Hdf5ProductWriter.java プロジェクト: maduhu/beam
  private Integer createBandH5D(Band band) throws IOException {

    final int w = band.getRasterWidth();
    final int h = band.getRasterHeight();
    long[] dims = new long[] {h, w};
    int datasetID = -1;
    int fileTypeID = -1;
    int fileSpaceID = -1;

    try {
      fileTypeID = createH5TypeID(band.getDataType());
      fileSpaceID = H5.H5Screate_simple(2, dims, null);
      datasetID =
          H5.H5Dcreate(
              _fileID,
              "/bands/" + band.getName(),
              fileTypeID,
              fileSpaceID,
              HDF5Constants.H5P_DEFAULT);

      try {
        // @todo 1 nf/tb - MEMOPT: add min, max here
        createScalarAttribute(datasetID, "raster_width", band.getRasterWidth());
        createScalarAttribute(datasetID, "raster_height", band.getRasterHeight());
        createScalarAttribute(datasetID, "scaling_factor", band.getScalingFactor());
        createScalarAttribute(datasetID, "scaling_offset", band.getScalingOffset());
        createScalarAttribute(datasetID, "log10_scaled", band.isLog10Scaled() ? "true" : "false");
        createScalarAttribute(datasetID, "unit", band.getUnit());
        createScalarAttribute(datasetID, "description", band.getDescription());
        if (band.getSpectralBandIndex() >= 0) {
          createScalarAttribute(datasetID, "spectral_band_index", band.getSpectralBandIndex() + 1);
          createScalarAttribute(datasetID, "solar_flux", band.getSolarFlux());
          createScalarAttribute(datasetID, "bandwidth", band.getSpectralBandwidth());
          createScalarAttribute(datasetID, "wavelength", band.getSpectralWavelength());
        }
        if (band.getFlagCoding() != null) {
          createScalarAttribute(datasetID, "flag_coding", band.getFlagCoding().getName());
        }
        createScalarAttribute(datasetID, "CLASS", "IMAGE");
        createScalarAttribute(datasetID, "IMAGE_VERSION", 1.2F);

        if (band.isStxSet()) {
          final Stx stx = band.getStx();
          createScalarAttribute(datasetID, "min_sample", stx.getMinimum());
          createScalarAttribute(datasetID, "max_sample", stx.getMaximum());
        }
        if (band.getImageInfo() != null) {
          final ColorPaletteDef paletteDef = band.getImageInfo().getColorPaletteDef();
          float[] minmax =
              new float[] {
                (float) paletteDef.getMinDisplaySample(), (float) paletteDef.getMaxDisplaySample()
              };
          createArrayAttribute(datasetID, "IMAGE_MINMAXRANGE", minmax);
        }
      } catch (IOException e) {
        /* ignore IOException because these attributes are not very essential... */
        Debug.trace("failed to create attribute: " + e.getMessage());
      }

    } catch (HDF5Exception e) {
      closeH5D(datasetID);
      throw new ProductIOException(createErrorMessage(e));
    } finally {
      closeH5S(fileSpaceID);
      closeH5T(fileTypeID);
    }

    return datasetID;
  }
コード例 #20
0
 protected void fireHidden(PageComponent component) {
   Debug.trace("AbstractApplicationPage.fireHidden [" + component + "]");
   for (PageComponentListener listener : pageComponentListeners) {
     listener.componentHidden(component);
   }
 }
コード例 #21
0
  protected void addGeoCodingToProduct(final Product product) {

    if (!getSourceProduct().transferGeoCodingTo(product, getSubsetDef())) {
      Debug.trace("GeoCoding could not be transferred.");
    }
  }