|
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
|
2 |
*
|
|
3 |
* Copyright (C) 2007 IVER T.I. and Generalitat Valenciana.
|
|
4 |
*
|
|
5 |
* This program is free software; you can redistribute it and/or
|
|
6 |
* modify it under the terms of the GNU General Public License
|
|
7 |
* as published by the Free Software Foundation; either version 2
|
|
8 |
* of the License, or (at your option) any later version.
|
|
9 |
*
|
|
10 |
* This program is distributed in the hope that it will be useful,
|
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
13 |
* GNU General Public License for more details.
|
|
14 |
*
|
|
15 |
* You should have received a copy of the GNU General Public License
|
|
16 |
* along with this program; if not, write to the Free Software
|
|
17 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
|
18 |
*/
|
|
19 |
package org.gvsig.raster;
|
|
20 |
|
|
21 |
import java.awt.Dimension;
|
|
22 |
import java.awt.Graphics2D;
|
|
23 |
import java.awt.geom.AffineTransform;
|
|
24 |
import java.awt.geom.Rectangle2D;
|
|
25 |
import java.awt.image.BufferedImage;
|
|
26 |
|
|
27 |
import org.gvsig.fmap.raster.layers.FLyrRasterSE;
|
|
28 |
import org.gvsig.raster.buffer.WriterBufferServer;
|
|
29 |
import org.gvsig.raster.dataset.FileNotOpenException;
|
|
30 |
import org.gvsig.raster.dataset.io.RasterDriverException;
|
|
31 |
import org.gvsig.raster.grid.filter.FilterTypeException;
|
|
32 |
import org.gvsig.raster.grid.filter.RasterFilterListManager;
|
|
33 |
import org.gvsig.raster.grid.filter.enhancement.BrightnessContrastListManager;
|
|
34 |
import org.gvsig.raster.grid.filter.enhancement.EnhancementStretchListManager;
|
|
35 |
import org.gvsig.raster.grid.filter.enhancement.LinearStretchParams;
|
|
36 |
import org.gvsig.raster.hierarchy.IStatistics;
|
|
37 |
import org.gvsig.raster.util.process.ClippingProcess;
|
|
38 |
import org.gvsig.rastertools.clipping.ClippingBaseTest;
|
|
39 |
|
|
40 |
import com.hardcode.gdbms.driver.exceptions.ReadDriverException;
|
|
41 |
import com.iver.cit.gvsig.fmap.ViewPort;
|
|
42 |
import com.iver.utiles.swing.threads.Cancellable;
|
|
43 |
|
|
44 |
/**
|
|
45 |
* Test de pruebas del proceso de recorte
|
|
46 |
* https://gvsig.org/web/docdev/docs/desarrollo/plugins/raster-tools/funcionalidades/recorte-de-raster/caracteristicas?portal_status_message=Changes%20saved.
|
|
47 |
*
|
|
48 |
* 07/05/2008
|
|
49 |
* @author Nacho Brodin nachobrodin@gmail.com
|
|
50 |
*/
|
|
51 |
public class OpenAndCloseTest extends ClippingBaseTest {
|
|
52 |
//ulx, lrx, lry, uly
|
|
53 |
protected int[] coords = new int[]{0, 4000, 4000, 0};
|
|
54 |
|
|
55 |
/*
|
|
56 |
* (non-Javadoc)
|
|
57 |
* @see junit.framework.TestCase#setUp()
|
|
58 |
*/
|
|
59 |
//public void setUp() {
|
|
60 |
public static void main(String[] args) {
|
|
61 |
System.err.println("******************************************");
|
|
62 |
System.err.println("*** UniqueProcessTest running... ***");
|
|
63 |
System.err.println("******************************************");
|
|
64 |
OpenAndCloseTest t = new OpenAndCloseTest();
|
|
65 |
t.test();
|
|
66 |
}
|
|
67 |
|
|
68 |
//public void testStack() {
|
|
69 |
public void test() {
|
|
70 |
for (int i = 0; i < 1000; i++) {
|
|
71 |
FLyrRasterSE layer = openLayer("./test-images/prueba.jpg");
|
|
72 |
|
|
73 |
/*try {
|
|
74 |
clippingProcess(new int[]{0, 1, 2}, false, new int[]{0, 869, 869, 0});
|
|
75 |
} catch (Exception e) {
|
|
76 |
e.printStackTrace();
|
|
77 |
}*/
|
|
78 |
|
|
79 |
|
|
80 |
/*try {
|
|
81 |
clippingProcessReal(new int[]{0, 1, 2}, false, new double[]{0, 869, 869, 0});
|
|
82 |
} catch (Exception e) {
|
|
83 |
e.printStackTrace();
|
|
84 |
}*/
|
|
85 |
|
|
86 |
draw(layer);
|
|
87 |
|
|
88 |
layer.setRemoveRasterFlag(true);
|
|
89 |
layer.getDataSource().close();
|
|
90 |
layer.getRender().free();
|
|
91 |
|
|
92 |
Runtime r = Runtime.getRuntime();
|
|
93 |
|
|
94 |
System.err.println("Memoria Total: " + (r.totalMemory() / 1024) +"KB");
|
|
95 |
System.err.println("Memoria Usada: " + ((r.totalMemory() - r.freeMemory()) / 1024) +"KB");
|
|
96 |
System.err.println("Memoria Libre: " + (r.freeMemory() / 1024) +"KB");
|
|
97 |
System.err.println("Memoria MaxMemory: " + (r.maxMemory() / 1024) +"KB");
|
|
98 |
System.out.println("**************************************************");
|
|
99 |
}
|
|
100 |
}
|
|
101 |
|
|
102 |
private void draw(FLyrRasterSE layer) {
|
|
103 |
RasterFilterListManager filterManager = new RasterFilterListManager(layer.getRenderFilterList());
|
|
104 |
IStatistics stats = layer.getDataSource().getStatistics();
|
|
105 |
|
|
106 |
EnhancementStretchListManager elm = new EnhancementStretchListManager(filterManager);
|
|
107 |
BrightnessContrastListManager br = new BrightnessContrastListManager(filterManager);
|
|
108 |
|
|
109 |
try {
|
|
110 |
stats.calcFullStatistics();
|
|
111 |
elm.addEnhancedStretchFilter(LinearStretchParams.createStandardParam(layer.getRenderBands(), 0.0, stats, false),
|
|
112 |
stats,
|
|
113 |
layer.getRender().getRenderBands(),
|
|
114 |
false);
|
|
115 |
br.addBrightnessFilter(80);
|
|
116 |
br.addContrastFilter(56);
|
|
117 |
layer.setTransparency(25);
|
|
118 |
} catch (FileNotOpenException e) {
|
|
119 |
//No podemos aplicar el filtro
|
|
120 |
} catch (RasterDriverException e) {
|
|
121 |
//No podemos aplicar el filtro
|
|
122 |
} catch (FilterTypeException e) {
|
|
123 |
} catch (InterruptedException e) {
|
|
124 |
}
|
|
125 |
|
|
126 |
ViewPort vp = new ViewPort(null);
|
|
127 |
vp.setImageSize(new Dimension(1118, 662));
|
|
128 |
vp.setExtent(new Rectangle2D.Double(-346.88, 0, 1563.762, 870));
|
|
129 |
vp.setProjection(null);
|
|
130 |
BufferedImage bi = new BufferedImage(1118, 662, BufferedImage.TYPE_INT_ARGB);
|
|
131 |
Cancellable cancel = new Cancellable() {
|
|
132 |
public boolean isCanceled() {
|
|
133 |
return false;
|
|
134 |
}
|
|
135 |
|
|
136 |
public void setCanceled(boolean canceled) {}
|
|
137 |
};
|
|
138 |
try {
|
|
139 |
layer.draw(bi, (Graphics2D)bi.getGraphics(), vp, cancel, 5342.0);
|
|
140 |
} catch (ReadDriverException e) {
|
|
141 |
}
|
|
142 |
}
|
|
143 |
|
|
144 |
/**
|
|
145 |
* Proceso de recorte de la imagen en secuencial.
|
|
146 |
* @param drawBands
|
|
147 |
* @param onePerBand
|
|
148 |
* @param interp
|
|
149 |
*/
|
|
150 |
protected ClippingProcess clippingProcessPixel(int[] drawBands, boolean onePerBand, int[] coords) {
|
|
151 |
ClippingProcess clippingProcess = new ClippingProcess();
|
|
152 |
clippingProcess.addParam("viewname", null);
|
|
153 |
clippingProcess.addParam("pixelcoordinates", coords);
|
|
154 |
clippingProcess.addParam("filename", getFileTemp());
|
|
155 |
clippingProcess.addParam("datawriter", new WriterBufferServer());
|
|
156 |
clippingProcess.addParam("layer", lyr);
|
|
157 |
clippingProcess.addParam("drawablebands", drawBands);
|
|
158 |
clippingProcess.addParam("onelayerperband", new Boolean(onePerBand));
|
|
159 |
clippingProcess.addParam("affinetransform", new AffineTransform());
|
|
160 |
clippingProcess.addParam("resolution", new int[]{870, 870});
|
|
161 |
try {
|
|
162 |
clippingProcess.execute();
|
|
163 |
} catch (InterruptedException e) {
|
|
164 |
}
|
|
165 |
return clippingProcess;
|
|
166 |
}
|
|
167 |
|
|
168 |
/**
|
|
169 |
* Proceso de recorte de la imagen en secuencial.
|
|
170 |
* @param drawBands
|
|
171 |
* @param onePerBand
|
|
172 |
* @param interp
|
|
173 |
*/
|
|
174 |
protected ClippingProcess clippingProcessReal(int[] drawBands, boolean onePerBand, double[] coords) {
|
|
175 |
ClippingProcess clippingProcess = new ClippingProcess();
|
|
176 |
clippingProcess.addParam("viewname", null);
|
|
177 |
clippingProcess.addParam("realcoordinates", coords);
|
|
178 |
clippingProcess.addParam("filename", getFileTemp());
|
|
179 |
clippingProcess.addParam("datawriter", new WriterBufferServer());
|
|
180 |
clippingProcess.addParam("layer", lyr);
|
|
181 |
clippingProcess.addParam("drawablebands", drawBands);
|
|
182 |
clippingProcess.addParam("onelayerperband", new Boolean(onePerBand));
|
|
183 |
clippingProcess.addParam("affinetransform", new AffineTransform());
|
|
184 |
clippingProcess.addParam("resolution", new int[]{870, 870});
|
|
185 |
try {
|
|
186 |
clippingProcess.execute();
|
|
187 |
} catch (InterruptedException e) {
|
|
188 |
}
|
|
189 |
return clippingProcess;
|
|
190 |
}
|
|
191 |
|
|
192 |
}
|