Exemplo n.º 1
0
  /*
   * (non-Javadoc)
   * @see org.gvsig.raster.driver.datasetproperties.IHistogramable#getHistogram()
   */
  public Histogram getHistogram() throws InterruptedException {
    RasterTask task = RasterTaskQueue.get(Thread.currentThread().toString());
    progressHistogram = 0;
    Histogram hist = null;
    double[][] limits = getAllBandsLimits();

    hist = new Histogram(getBandCount(), limits[0], limits[1], getDataType());

    for (int iBand = 0; iBand < getBandCount(); iBand++) {
      for (int row = 0; row < getHeight(); row++) {
        switch (getDataType()) {
          case IBuffer.TYPE_BYTE:
            for (int col = 0; col < getWidth(); col++)
              hist.incrementPxValue(iBand, (double) (getElemByte(row, col, iBand)));
            break;
          case IBuffer.TYPE_SHORT:
            for (int col = 0; col < getWidth(); col++)
              hist.incrementPxValue(iBand, (double) (getElemShort(row, col, iBand)));
            break;
          case IBuffer.TYPE_INT:
            for (int col = 0; col < getWidth(); col++)
              hist.incrementPxValue(iBand, (double) (getElemInt(row, col, iBand)));
            break;
          case IBuffer.TYPE_FLOAT:
            for (int col = 0; col < getWidth(); col++)
              hist.incrementPxValue(iBand, (double) getElemFloat(row, col, iBand));
            break;
          case IBuffer.TYPE_DOUBLE:
            for (int col = 0; col < getWidth(); col++)
              hist.incrementPxValue(iBand, getElemDouble(row, col, iBand));
            break;
        }

        if (task.getEvent() != null) task.manageEvent(task.getEvent());

        progressHistogram = ((iBand * getHeight() + row) * 100) / (getHeight() * getBandCount());
      }
    }
    progressHistogram = 100;
    return hist;
  }
Exemplo n.º 2
0
  /*
   * (non-Javadoc)
   * @see org.gvsig.raster.dataset.IBuffer#getLimits()
   */
  public double[] getLimits() throws InterruptedException {
    RasterTask task = RasterTaskQueue.get(Thread.currentThread().toString());
    double max = Double.NEGATIVE_INFINITY;
    double secondMax = max;
    double min = Double.MAX_VALUE;
    double secondMin = min;
    double value = 0;

    switch (getDataType()) {
      case IBuffer.TYPE_BYTE:
        for (int i = 0; i < getBandCount(); i++)
          for (int r = 0; r < getHeight(); r++) {
            for (int c = 0; c < getWidth(); c++) {
              value = (double) ((getElemByte(r, c, i)));
              if (value > max) {
                if (max != value) secondMax = max;
                max = value;
              }
              if (value < min) {
                if (min != value) secondMin = min;
                min = value;
              }
            }
            if (task.getEvent() != null) task.manageEvent(task.getEvent());
          }
        break;
      case IBuffer.TYPE_SHORT:
        for (int i = 0; i < getBandCount(); i++)
          for (int r = 0; r < getHeight(); r++) {
            for (int c = 0; c < getWidth(); c++) {
              value = (double) getElemShort(r, c, i);
              if (value > max) {
                if (max != value) secondMax = max;
                max = value;
              }
              if (value < min) {
                if (min != value) secondMin = min;
                min = value;
              }
            }
            if (task.getEvent() != null) task.manageEvent(task.getEvent());
          }
        break;
      case IBuffer.TYPE_INT:
        for (int i = 0; i < getBandCount(); i++)
          for (int r = 0; r < getHeight(); r++) {
            for (int c = 0; c < getWidth(); c++) {
              value = (double) getElemInt(r, c, i);
              if (value > max) {
                if (max != value) secondMax = max;
                max = value;
              }
              if (value < min) {
                if (min != value) secondMin = min;
                min = value;
              }
            }
            if (task.getEvent() != null) task.manageEvent(task.getEvent());
          }
        break;
      case IBuffer.TYPE_FLOAT:
        for (int i = 0; i < getBandCount(); i++)
          for (int r = 0; r < getHeight(); r++) {
            for (int c = 0; c < getWidth(); c++) {
              value = (double) getElemFloat(r, c, i);
              if (value > max) {
                if (max != value) secondMax = max;
                max = value;
              }
              if (value < min) {
                if (min != value) secondMin = min;
                min = value;
              }
            }
            if (task.getEvent() != null) task.manageEvent(task.getEvent());
          }
        break;
      case IBuffer.TYPE_DOUBLE:
        for (int i = 0; i < getBandCount(); i++)
          for (int r = 0; r < getHeight(); r++) {
            for (int c = 0; c < getWidth(); c++) {
              value = getElemDouble(r, c, i);
              if (value > max) {
                if (max != value) secondMax = max;
                max = value;
              }
              if (value < min) {
                if (min != value) secondMin = min;
                min = value;
              }
            }
            if (task.getEvent() != null) task.manageEvent(task.getEvent());
          }
        break;
    }
    // Si no existe un secondMax lo igualo al maximo existente
    if (secondMax == Double.NEGATIVE_INFINITY) secondMax = max;
    // Si no existe un secondMin lo igualo al minimo existente
    if (secondMin == Double.MAX_VALUE) secondMin = min;

    double[] values = new double[4];
    values[0] = min;
    values[1] = max;
    values[2] = secondMin;
    values[3] = secondMax;
    return values;
  }
Exemplo n.º 3
0
  /*
   * (non-Javadoc)
   * @see org.gvsig.raster.dataset.IBuffer#getLimits()
   */
  private double[][] getAllBandsLimits() throws InterruptedException {
    RasterTask task = RasterTaskQueue.get(Thread.currentThread().toString());
    double max[] = new double[getBandCount()];
    double min[] = new double[getBandCount()];
    double value = 0;

    for (int i = 0; i < getBandCount(); i++) {
      max[i] = Double.NEGATIVE_INFINITY;
      min[i] = Double.MAX_VALUE;
    }

    switch (getDataType()) {
      case IBuffer.TYPE_BYTE:
        for (int i = 0; i < getBandCount(); i++) {
          for (int r = 0; r < getHeight(); r++) {
            for (int c = 0; c < getWidth(); c++) {
              value = (double) ((getElemByte(r, c, i)));
              if (value > max[i]) max[i] = value;
              if (value < min[i]) min[i] = value;
            }
            if (task.getEvent() != null) task.manageEvent(task.getEvent());
          }
        }
        break;
      case IBuffer.TYPE_SHORT:
        for (int i = 0; i < getBandCount(); i++) {
          for (int r = 0; r < getHeight(); r++) {
            for (int c = 0; c < getWidth(); c++) {
              value = (double) getElemShort(r, c, i);
              if (value > max[i]) max[i] = value;
              if (value < min[i]) min[i] = value;
            }
            if (task.getEvent() != null) task.manageEvent(task.getEvent());
          }
        }
        break;
      case IBuffer.TYPE_INT:
        for (int i = 0; i < getBandCount(); i++) {
          for (int r = 0; r < getHeight(); r++) {
            for (int c = 0; c < getWidth(); c++) {
              value = (double) getElemInt(r, c, i);
              if (value > max[i]) max[i] = value;
              if (value < min[i]) min[i] = value;
            }
            if (task.getEvent() != null) task.manageEvent(task.getEvent());
          }
        }
        break;
      case IBuffer.TYPE_FLOAT:
        for (int i = 0; i < getBandCount(); i++) {
          for (int r = 0; r < getHeight(); r++) {
            for (int c = 0; c < getWidth(); c++) {
              value = (double) getElemFloat(r, c, i);
              if (value > max[i]) max[i] = value;
              if (value < min[i]) min[i] = value;
            }
            if (task.getEvent() != null) task.manageEvent(task.getEvent());
          }
        }
        break;
      case IBuffer.TYPE_DOUBLE:
        for (int i = 0; i < getBandCount(); i++) {
          for (int r = 0; r < getHeight(); r++) {
            for (int c = 0; c < getWidth(); c++) {
              value = getElemDouble(r, c, i);
              if (value > max[i]) max[i] = value;
              if (value < min[i]) min[i] = value;
            }
            if (task.getEvent() != null) task.manageEvent(task.getEvent());
          }
        }
        break;
    }
    double[][] values = new double[2][getBandCount()];

    for (int i = 0; i < getBandCount(); i++) {
      values[0][i] = min[i];
      values[1][i] = max[i];
    }
    return values;
  }
Exemplo n.º 4
0
 /**
  * Un evento de cancelado es enviado a la tarea cuando actionCanceled es activado. Para ello se
  * creará un objeto CancelEvent y se asignará a la tarea en ejecución. Esta lo procesará cuando
  * pueda e interrumpirá el proceso.
  */
 public void actionCanceled(IncrementableEvent e) {
   if (cancellable) rasterTask.setEvent(new CancelEvent(this));
 }