gvsig-raster / org.gvsig.raster.app / trunk / org.gvsig.raster.app / org.gvsig.raster.app.tools / src / main / java / org / gvsig / raster / app / extension / raster / process / OverviewsProcess.java @ 235
History | View | Annotate | Download (4.41 KB)
1 |
/* gvSIG. Geographic Information System of the Valencian Government
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department
|
4 |
* of the Valencian Government (CIT)
|
5 |
*
|
6 |
* This program is free software; you can redistribute it and/or
|
7 |
* modify it under the terms of the GNU General Public License
|
8 |
* as published by the Free Software Foundation; either version 2
|
9 |
* of the License, or (at your option) any later version.
|
10 |
*
|
11 |
* This program is distributed in the hope that it will be useful,
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
* GNU General Public License for more details.
|
15 |
*
|
16 |
* You should have received a copy of the GNU General Public License
|
17 |
* along with this program; if not, write to the Free Software
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 |
* MA 02110-1301, USA.
|
20 |
*
|
21 |
*/
|
22 |
package org.gvsig.raster.app.extension.raster.process; |
23 |
|
24 |
import org.gvsig.addo.BuildingOverviewsException; |
25 |
import org.gvsig.addo.IOverviewIncrement; |
26 |
import org.gvsig.addo.Jaddo; |
27 |
import org.gvsig.addo.WritingException; |
28 |
import org.gvsig.andami.PluginServices; |
29 |
import org.gvsig.fmap.dal.coverage.store.MultiRasterStore; |
30 |
import org.gvsig.fmap.dal.coverage.store.RasterDataParameters; |
31 |
import org.gvsig.raster.fmap.config.Configuration; |
32 |
import org.gvsig.raster.fmap.layers.FLyrRaster; |
33 |
import org.gvsig.raster.util.RasterToolsUtil; |
34 |
|
35 |
|
36 |
/**
|
37 |
* Proceso para la generaci?n de overviews.
|
38 |
*
|
39 |
* 10/12/2007
|
40 |
* @author Nacho Brodin nachobrodin@gmail.com
|
41 |
*/
|
42 |
public class OverviewsProcess extends RasterProcess implements IOverviewIncrement { |
43 |
private FLyrRaster rasterSE = null; |
44 |
private int value = 0; |
45 |
private int resamplingAlg = Jaddo.AVERAGE; |
46 |
private int[] overviews = new int[] { 2, 4, 8, 16 }; |
47 |
|
48 |
/*
|
49 |
* (non-Javadoc)
|
50 |
* @see org.gvsig.rastertools.RasterProcess#init()
|
51 |
*/
|
52 |
public void init() { |
53 |
rasterSE = getLayerParam("layer");
|
54 |
|
55 |
int overviewsRate = 2; |
56 |
int nOverviews = 4; |
57 |
overviewsRate = Configuration.getValue("overviews_rate", new Integer(overviewsRate)).intValue(); |
58 |
nOverviews = Configuration.getValue("overviews_number", new Integer(nOverviews)).intValue(); |
59 |
resamplingAlg = Configuration.getValue("overviews_resampling_algorithm", new Integer(resamplingAlg)).intValue(); |
60 |
|
61 |
// Leemos de la configuraci?n los valores de algoritmo a usar,
|
62 |
// n?mero de overviews a generar y proporci?n de la primera overview
|
63 |
|
64 |
overviews = new int[nOverviews]; |
65 |
overviews[0] = overviewsRate;
|
66 |
for (int i = 1; i < nOverviews; i++) |
67 |
overviews[i] = overviewsRate * overviews[i - 1];
|
68 |
} |
69 |
|
70 |
/**
|
71 |
* M?todo donde se ejecutar? el Thread, aqu? se generaran las
|
72 |
* overviews
|
73 |
*/
|
74 |
public void process() { |
75 |
insertLineLog(PluginServices.getText(this, "overviews_generating")); |
76 |
|
77 |
Jaddo build = new Jaddo();
|
78 |
build.setIncrementListener(this);
|
79 |
try {
|
80 |
int nDat = rasterSE.getDataStore().getDataStoreCount();
|
81 |
|
82 |
if(rasterSE.getDataStore() instanceof MultiRasterStore) { |
83 |
for (int i = 0; i < nDat; i++) { |
84 |
insertLineLog(" Dataset: " + i);
|
85 |
RasterDataParameters params = (RasterDataParameters)((MultiRasterStore)rasterSE.getDataStore()).getDataStore(i).getParameters(); |
86 |
build.buildOverviews(resamplingAlg, params.getURI(), overviews); |
87 |
} |
88 |
} else {
|
89 |
RasterDataParameters params = (RasterDataParameters)rasterSE.getDataStore().getParameters(); |
90 |
build.buildOverviews(resamplingAlg, params.getURI(), overviews); |
91 |
} |
92 |
if (externalActions != null) |
93 |
externalActions.end(rasterSE); |
94 |
} catch (BuildingOverviewsException e) {
|
95 |
if (incrementableTask != null) |
96 |
incrementableTask.hideWindow(); |
97 |
RasterToolsUtil.messageBoxError("error_create_overviews", this, e); |
98 |
} catch (WritingException e) {
|
99 |
if (incrementableTask != null) |
100 |
incrementableTask.hideWindow(); |
101 |
RasterToolsUtil.messageBoxError("error_write_overviews", this, e); |
102 |
} |
103 |
} |
104 |
|
105 |
/*
|
106 |
* (non-Javadoc)
|
107 |
* @see org.gvsig.gui.beans.incrementabletask.IIncrementable#getPercent()
|
108 |
*/
|
109 |
public int getPercent() { |
110 |
return value;
|
111 |
} |
112 |
|
113 |
/*
|
114 |
* (non-Javadoc)
|
115 |
* @see org.gvsig.addo.IOverviewIncrement#setPercent(int)
|
116 |
*/
|
117 |
public void setPercent(int value) { |
118 |
this.value = value;
|
119 |
} |
120 |
|
121 |
/*
|
122 |
* (non-Javadoc)
|
123 |
* @see org.gvsig.gui.beans.incrementabletask.IIncrementable#getTitle()
|
124 |
*/
|
125 |
public String getTitle() { |
126 |
return PluginServices.getText(this, "incremento_overview"); |
127 |
} |
128 |
} |