Revision 11065

View differences:

trunk/extensions/extRasterTools-SE/src/org/gvsig/rastertools/histogram/HistogramPanelListener.java
260 260
		incrementableTask = new IncrementableTask(histogramProcess);
261 261
		histogramProcess.setIncrementableTask(incrementableTask);
262 262
		incrementableTask.showWindow();
263
		iaux.resetPercent();
263 264
		histogramProcess.start();
264 265
		incrementableTask.start();
265 266
	}
trunk/extensions/extRasterTools-SE/src/org/gvsig/rastertools/histogram/HistogramProcess.java
55 55
		} catch (HistogramException e) {
56 56
			e.printStackTrace();
57 57
		}
58
		while (!incrementableTask.getStarted());
59 58
		while (incrementableTask.isAlive());
60 59
		incrementableTask.Hide();
61 60
		incrementableTask = null;
trunk/libraries/libUIComponent/src/org/gvsig/gui/beans/incrementabletask/IncrementableTask.java
41 41
	private volatile Thread blinker = null;
42 42
	private boolean threadSuspended = false;
43 43
	private boolean ended = false;
44
	private boolean started = false;
45 44
	
46 45
	private ArrayList actionCommandListeners = new ArrayList();
47 46
	private boolean bDoCallListeners = true;
......
67 66
	 * Este thread va leyendo el porcentaje hasta que se completa el histograma.
68 67
	 */
69 68
	public synchronized void run() {
70
		getProgressPanel().setPercent(0);
71 69
		while (!ended && (iIncrementable.getPercent() < 100)) {
72 70
			try {
73 71
				getProgressPanel().setLabel(iIncrementable.getLabel());
74 72
				getProgressPanel().setPercent(iIncrementable.getPercent());
75 73
				getProgressPanel().setTitle(iIncrementable.getTitle());
76 74
				getProgressPanel().setLog(iIncrementable.getLog());
77
				started = true;
78 75
				Thread.sleep(100);
79 76
				synchronized(this) {
80 77
					while (threadSuspended && !ended)
......
85 82
		}
86 83
	}
87 84
	
88
	public boolean getStarted() {
89
		return started;
90
	}
91

  
92 85
	public void Hide() {
93 86
		getProgressPanel().setVisible(false);
94 87
		getProgressPanel().hide();
trunk/libraries/libRaster/src/org/gvsig/raster/dataset/RasterDataset.java
814 814
			histogram = new DatasetHistogram(this);
815 815
		return histogram;
816 816
	}
817
		
817
	
818
	public void resetPercent() {
819
		if (histogram != null)
820
			histogram.resetPercent();
821
	}
818 822
	public int getPercent() {
819
		if(histogram != null)
823
		if (histogram != null)
820 824
			return histogram.getPercent();
821 825
		return 0;
822 826
	}
trunk/libraries/libRaster/src/org/gvsig/raster/dataset/properties/DatasetListHistogram.java
102 102
		}
103 103
		return null;
104 104
	}
105
	
105

  
106
	public void resetPercent() {
107
		for (int i = 0; i < multiDataset.getDatasetCount(); i++) {
108
			multiDataset.getDataset(i).resetPercent();
109
		}
110
	}
111

  
106 112
	public int getPercent() {
107 113
		int percent = 0;
108 114
		for (int i = 0; i < multiDataset.getDatasetCount(); i++) {
trunk/libraries/libRaster/src/org/gvsig/raster/dataset/properties/DatasetHistogram.java
175 175
		} 
176 176
		return histogram;
177 177
	}
178
	
178

  
179
	public void resetPercent() {
180
		percent=0;
181
	}
182

  
179 183
	public int getPercent() {
180 184
		return percent;
181 185
	}
trunk/libraries/libRaster/src/org/gvsig/raster/dataset/RasterMultiDataset.java
45 45
 * @author Nacho Brodin (nachobrodin@gmail.com)
46 46
 *
47 47
 */
48
public class RasterMultiDataset implements IHistogramable{
48
public class RasterMultiDataset implements IHistogramable {
49 49
	//File list
50 50
	private ArrayList 					files = new ArrayList();
51 51
	private String						name = null;
......
864 864
			return histogram.getPercent();
865 865
		return 0;
866 866
	}
867
	
868
}
867

  
868
	/*
869
	 * (non-Javadoc)
870
	 * @see org.gvsig.raster.util.IHistogramable#resetPercent()
871
	 */
872
	public void resetPercent() {
873
		if (histogram != null)
874
			histogram.resetPercent();
875
	}
876
}
trunk/libraries/libRaster/src/org/gvsig/raster/dataaccess/cache/PageBuffer.java
35 35
 * @author Nacho Brodin (nachobrodin@gmail.com)
36 36
 *
37 37
 */
38
public class PageBuffer implements IBuffer{
38
public class PageBuffer implements IBuffer {
39 39

  
40 40
	private PageBandBuffer[] pageBandBuffer = null;
41 41
	private int	percent = 0;
......
454 454

  
455 455
	/*
456 456
	 * (non-Javadoc)
457
	 * @see org.gvsig.raster.driver.datasetproperties.IHistogramable#getPercent()
457
	 * @see org.gvsig.raster.util.IHistogramable#resetPercent()
458 458
	 */
459
	public void resetPercent() {
460
		percent = 0;
461
	}
462

  
463
	/*
464
	 * (non-Javadoc)
465
	 * @see org.gvsig.raster.util.IHistogramable#getPercent()
466
	 */
459 467
	public int getPercent() {
460 468
		return percent;
461 469
	}
trunk/libraries/libRaster/src/org/gvsig/raster/dataaccess/buffer/RasterMemoryBuffer.java
1268 1268
									break;
1269 1269
    	}
1270 1270
    }
1271

  
1272

  
1273
}
1271
}
trunk/libraries/libRaster/src/org/gvsig/raster/dataaccess/buffer/RasterBuffer.java
47 47
	public double 			noDataValue = -99999;
48 48
	protected int			percent = 0;
49 49
	
50
    protected int 			width;
51
    protected int 			height;
52
    protected int 			nBands;
53
    protected int 			dataType;
54
    
55
    /**
56
     * Variable est?tica que si est? a false desactiva el uso de cach?. Puede ser usada por un cliente
57
     * para cargar siempre los datos en memoria. independientemente de su tama?o. 
58
     */
59
    public static boolean	cacheOn = true;
60
    /**
61
     * Fuerza la carga de los datos en cach? independientemente de su tama?o. Su
62
     * uso suele ser util solo para depuraci?n. Su valor por defecto y recomendado
63
     * es siempre false.
64
     */
65
    public static boolean 	forceToLoadInCache = false;
66
    /**
67
     * Fuerza la carga de los datos en cach? de solo lectura independientemente de su tama?o. Su
68
     * uso suele ser util solo para depuraci?n. Su valor por defecto y recomendado
69
     * es siempre false.
70
     */
71
    public static boolean 	forceToLoadInReadOnlyCache = false;
72
    /**
73
     * Valor con el que se rellena una banda no valida del buffer. Una banda no valida es la que 
74
     * no tiene datos asignados y tampoco puede ser null. Todas las bandas no validas de un buffer
75
     * apuntan por referencia a la misma banda.
76
     */
77
    protected double		notValidValue = 0D;
50
  protected int 			width;
51
  protected int 			height;
52
  protected int 			nBands;
53
  protected int 			dataType;
54
  
55
  /**
56
   * Variable est?tica que si est? a false desactiva el uso de cach?. Puede ser usada por un cliente
57
   * para cargar siempre los datos en memoria. independientemente de su tama?o. 
58
   */
59
  public static boolean	cacheOn = true;
60
  /**
61
   * Fuerza la carga de los datos en cach? independientemente de su tama?o. Su
62
   * uso suele ser util solo para depuraci?n. Su valor por defecto y recomendado
63
   * es siempre false.
64
   */
65
  public static boolean 	forceToLoadInCache = false;
66
  /**
67
   * Fuerza la carga de los datos en cach? de solo lectura independientemente de su tama?o. Su
68
   * uso suele ser util solo para depuraci?n. Su valor por defecto y recomendado
69
   * es siempre false.
70
   */
71
  public static boolean 	forceToLoadInReadOnlyCache = false;
72
  /**
73
   * Valor con el que se rellena una banda no valida del buffer. Una banda no valida es la que 
74
   * no tiene datos asignados y tampoco puede ser null. Todas las bandas no validas de un buffer
75
   * apuntan por referencia a la misma banda.
76
   */
77
  protected double		notValidValue = 0D;
78 78

  
79
    /**
80
     * Genera instancias del buffer de datos adecuado al tama?o del raster. Si no hay muchos datos
81
     * (menos de cacheMemorySize) crear? un buffer en memoria. Si hay m?s de esta cantidad
82
     * entonces crearemos un buffer cacheado (RasterCache). A partir de la cantidad se?alada
83
     * por multicacheMemorySize haremos un buffer cacheado donde cada p?gina no ocupa todo
84
     * el ancho del raster ya que este ser? muy grande. La gesti?n de una cache donde cada
85
     * pagina ha de partir una l?nea lleva una complejidad a?adida.
86
     *  
87
     * @param dataType Tipo de dato
88
     * @param width Ancho
89
     * @param height Alto
90
     * @param bandNr Banda
91
     * @param malloc
92
     * @return
93
     * @throws RasterDriverException 
94
     * @throws NotSupportedExtensionException 
95
     * @throws FileNotFoundException 
96
     */
97
    public static RasterBuffer getBuffer(int dataType, int width, int height, int bandNr, boolean malloc, String filePath) 
98
    	/*throws FileNotFoundException, NotSupportedExtensionException, RasterDriverException*/{
99
    	//Opci?n de cachear siempre activada (Solo DEBUG)
100
    	if(forceToLoadInCache)
101
    		return new RasterCache(dataType, width, height, bandNr);
102
    	if(forceToLoadInReadOnlyCache && filePath != null){
103
			try {
104
				return new RasterReadOnlyHugeBuffer(dataType, width, height, bandNr, filePath);
105
			} catch (FileNotFoundException e) {
106
				//TODO: EXCEPTION: Modificar el lanzamiento de excepciones del RasterBuffer
107
				e.printStackTrace();
108
			} catch (NotSupportedExtensionException e) {
109
				e.printStackTrace();
110
			} catch (RasterDriverException e) {
111
				e.printStackTrace();
112
			}
113
    	}
114
    		
115
    	if(cacheOn){
116
	    	long size = (RasterUtilities.getBytesFromRasterBufType(dataType) * width * height * bandNr) / 1024;
117
	    	long ms1 = cacheMemorySize * 1024;
118
	    	long ms2 = multicacheMemorySize * 1024;
119
	    	if(size <= ms1)
120
	    		return new RasterMemoryBuffer(dataType, width, height, bandNr, malloc);
121
	    	else{
122
	    		//if(filePath == null)
123
	    			return new RasterCache(dataType, width, height, bandNr);
124
		    	/*else 
125
		    		return new RasterReadOnlyHugeBuffer(dataType, width, height, bandNr, filePath);*/
126
	    	}	
127
    	}else
79
  /**
80
   * Genera instancias del buffer de datos adecuado al tama?o del raster. Si no hay muchos datos
81
   * (menos de cacheMemorySize) crear? un buffer en memoria. Si hay m?s de esta cantidad
82
   * entonces crearemos un buffer cacheado (RasterCache). A partir de la cantidad se?alada
83
   * por multicacheMemorySize haremos un buffer cacheado donde cada p?gina no ocupa todo
84
   * el ancho del raster ya que este ser? muy grande. La gesti?n de una cache donde cada
85
   * pagina ha de partir una l?nea lleva una complejidad a?adida.
86
   *  
87
   * @param dataType Tipo de dato
88
   * @param width Ancho
89
   * @param height Alto
90
   * @param bandNr Banda
91
   * @param malloc
92
   * @return
93
   * @throws RasterDriverException 
94
   * @throws NotSupportedExtensionException 
95
   * @throws FileNotFoundException 
96
   */
97
  public static RasterBuffer getBuffer(int dataType, int width, int height, int bandNr, boolean malloc, String filePath) 
98
  	/*throws FileNotFoundException, NotSupportedExtensionException, RasterDriverException*/{
99
  	//Opci?n de cachear siempre activada (Solo DEBUG)
100
  	if(forceToLoadInCache)
101
  		return new RasterCache(dataType, width, height, bandNr);
102
  	if(forceToLoadInReadOnlyCache && filePath != null){
103
		try {
104
			return new RasterReadOnlyHugeBuffer(dataType, width, height, bandNr, filePath);
105
		} catch (FileNotFoundException e) {
106
			//TODO: EXCEPTION: Modificar el lanzamiento de excepciones del RasterBuffer
107
			e.printStackTrace();
108
		} catch (NotSupportedExtensionException e) {
109
			e.printStackTrace();
110
		} catch (RasterDriverException e) {
111
			e.printStackTrace();
112
		}
113
  	}
114
  		
115
  	if(cacheOn){
116
    	long size = (RasterUtilities.getBytesFromRasterBufType(dataType) * width * height * bandNr) / 1024;
117
    	long ms1 = cacheMemorySize * 1024;
118
    	long ms2 = multicacheMemorySize * 1024;
119
    	if(size <= ms1)
128 120
    		return new RasterMemoryBuffer(dataType, width, height, bandNr, malloc);
129
    }
130
    
131
    /**
132
     * Reserva de memoria para el rasterbuf
133
     * @param dataType Tipo de dato
134
     * @param width Ancho
135
     * @param height Alto
136
     * @param bandNr Numero de bandas
137
     * @param orig
138
     */
139
    public abstract void malloc(int dataType, int width, int height, int bandNr);
140
   
141
    /*
142
     *  (non-Javadoc)
143
     * @see org.gvsig.fmap.driver.IBuffer#getWidth()
144
     */
145
    public int getWidth() {
146
        return width;
147
    }
121
    	else{
122
    		//if(filePath == null)
123
    			return new RasterCache(dataType, width, height, bandNr);
124
	    	/*else 
125
	    		return new RasterReadOnlyHugeBuffer(dataType, width, height, bandNr, filePath);*/
126
    	}	
127
  	}else
128
  		return new RasterMemoryBuffer(dataType, width, height, bandNr, malloc);
129
  }
130
  
131
  /**
132
   * Reserva de memoria para el rasterbuf
133
   * @param dataType Tipo de dato
134
   * @param width Ancho
135
   * @param height Alto
136
   * @param bandNr Numero de bandas
137
   * @param orig
138
   */
139
  public abstract void malloc(int dataType, int width, int height, int bandNr);
140
 
141
  /*
142
   *  (non-Javadoc)
143
   * @see org.gvsig.fmap.driver.IBuffer#getWidth()
144
   */
145
  public int getWidth() {
146
      return width;
147
  }
148 148

  
149
   /*
150
    *  (non-Javadoc)
151
    * @see org.gvsig.fmap.driver.IBuffer#getHeight()
152
    */
153
    public int getHeight() {
154
        return height;
155
    }
149
 /*
150
  *  (non-Javadoc)
151
  * @see org.gvsig.fmap.driver.IBuffer#getHeight()
152
  */
153
  public int getHeight() {
154
      return height;
155
  }
156 156

  
157
    /*
158
     *  (non-Javadoc)
159
     * @see org.gvsig.fmap.driver.IBuffer#getBandCount()
160
     */
161
    public int getBandCount() {
162
        return nBands;
163
    }
157
  /*
158
   *  (non-Javadoc)
159
   * @see org.gvsig.fmap.driver.IBuffer#getBandCount()
160
   */
161
  public int getBandCount() {
162
      return nBands;
163
  }
164 164

  
165
    /**
166
     * Obtiene el tipo de dato. Los tipos de dato posibles est?n definidos en IRaster.
167
     * @return tipo de datos
168
     */
165
  /**
166
   * Obtiene el tipo de dato. Los tipos de dato posibles est?n definidos en IRaster.
167
   * @return tipo de datos
168
   */
169 169
	public int getDataType() {
170 170
		return dataType;
171 171
	}
......
414 414
		}
415 415
		return hist;
416 416
	}
417
	
417

  
418
	/*
419
	 * (non-Javadoc)
420
	 * @see org.gvsig.raster.util.IHistogramable#resetPercent()
421
	 */
422
	public void resetPercent() {
423
		percent = 0;
424
	}
425

  
426
	/*
427
	 * (non-Javadoc)
428
	 * @see org.gvsig.raster.util.IHistogramable#getPercent()
429
	 */
418 430
	public int getPercent() {
419 431
		return percent;
420 432
	}
trunk/libraries/libRaster/src/org/gvsig/raster/util/IHistogramable.java
33 33
	public Histogram getHistogram()throws HistogramException;
34 34
	
35 35
	/**
36
	 * Inicializa el porcentaje a 0 de un histograma.
37
	 * @return int
38
	 */
39
	public void resetPercent();
40
	
41
	/**
36 42
	 * Obtiene el porcentaje procesado de un histograma.
37 43
	 * @return int
38 44
	 */
trunk/libraries/libRaster/src/org/gvsig/raster/util/Histogram.java
148 148
	public long[][] getLogaritmicHistogram() {
149 149
		if (histogram != null) {
150 150
			long[][] hist = new long[histogram.length][histogram[0].length];
151
			for (int iBand = 0; iBand < hist.length; iBand++) {
152
				long min = hist[iBand][0];
153
				for (int j = 1; j < hist[iBand].length; j++)
154
					if (min > hist[iBand][j]) min = hist[iBand][j];
155
				for (int j = 0; j < hist[iBand].length; j++)
151
			for (int iBand = 0; iBand < histogram.length; iBand++) {
152
				long min = histogram[iBand][0];
153
				for (int j = 1; j < histogram[iBand].length; j++)
154
					if (min > histogram[iBand][j]) min = histogram[iBand][j];
155
				for (int j = 0; j < histogram[iBand].length; j++)
156 156
					// Lo multiplico por 1000 para que no se pierdan datos al redondear
157 157
					hist[iBand][j] = (long) (java.lang.Math.log((double) (histogram[iBand][j] - min + 1))*1000);
158 158
			}

Also available in: Unified diff