svn-gvsig-desktop / branches / org.gvsig.desktop-2018a / org.gvsig.desktop.compat.cdc / org.gvsig.fmap.mapcontext / org.gvsig.fmap.mapcontext.impl / src / main / java / org / gvsig / raster / lib / legend / impl / operations / pansharpening / PansharpeningOperationFactory.java @ 43803
History | View | Annotate | Download (5.51 KB)
1 |
/* gvSIG. Desktop Geographic Information System.
|
---|---|
2 |
*
|
3 |
* Copyright ? 2007-2017 gvSIG Association
|
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., 51 Franklin Street, Fifth Floor, Boston,
|
18 |
* MA 02110-1301, USA.
|
19 |
*
|
20 |
* For any additional information, do not hesitate to contact us
|
21 |
* at info AT gvsig.com, or visit our website www.gvsig.com.
|
22 |
*/
|
23 |
package org.gvsig.raster.lib.legend.impl.operations.pansharpening; |
24 |
|
25 |
import java.io.IOException; |
26 |
import java.io.InputStream; |
27 |
import java.util.Map; |
28 |
|
29 |
import org.xmlpull.v1.XmlPullParserException; |
30 |
|
31 |
import org.gvsig.raster.lib.buffer.api.Buffer; |
32 |
import org.gvsig.raster.lib.buffer.api.BufferManager; |
33 |
import org.gvsig.raster.lib.buffer.api.operations.Operation; |
34 |
import org.gvsig.raster.lib.buffer.api.operations.OperationFactory; |
35 |
import org.gvsig.tools.ToolsLocator; |
36 |
import org.gvsig.tools.dynobject.DynObject; |
37 |
import org.gvsig.tools.dynobject.DynObjectManager; |
38 |
import org.gvsig.tools.dynobject.DynStruct; |
39 |
|
40 |
|
41 |
/**
|
42 |
* @author fdiaz
|
43 |
*
|
44 |
* @deprecated
|
45 |
* Possibly this class will be deleted
|
46 |
*/
|
47 |
@Deprecated
|
48 |
public class PansharpeningOperationFactory implements OperationFactory { |
49 |
public static String NAME="Pansharpening"; |
50 |
public static String DESCRIPTION="Pansharpening operation";//FIXME: |
51 |
private DynStruct definition;
|
52 |
|
53 |
/**
|
54 |
*
|
55 |
*/
|
56 |
public PansharpeningOperationFactory() {
|
57 |
// TODO Auto-generated constructor stub
|
58 |
} |
59 |
|
60 |
/* (non-Javadoc)
|
61 |
* @see org.gvsig.raster.lib.buffer.api.operations.OperationFactory#createParameters()
|
62 |
*/
|
63 |
@Override
|
64 |
public DynObject createParameters() {
|
65 |
DynObjectManager manager = ToolsLocator.getDynObjectManager(); |
66 |
if (definition == null) { |
67 |
definition = createParametersDefinition(); |
68 |
} |
69 |
DynObject parameters = manager.createDynObject(definition); |
70 |
return parameters;
|
71 |
} |
72 |
|
73 |
/* (non-Javadoc)
|
74 |
* @see org.gvsig.raster.lib.buffer.api.operations.OperationFactory#create()
|
75 |
*/
|
76 |
@Override
|
77 |
public Operation create() { |
78 |
return new PansharpeningOperation(this); |
79 |
} |
80 |
|
81 |
/* (non-Javadoc)
|
82 |
* @see org.gvsig.raster.lib.buffer.api.operations.OperationFactory#createParametersDefinition()
|
83 |
*/
|
84 |
@Override
|
85 |
public DynStruct createParametersDefinition() {
|
86 |
return registerParametersDefinition("PansharpeningOperationParameters", "org/gvsig/raster/lib/legend/impl/operations/pansharpening/PansharpeningOperationParameters.xml"); |
87 |
} |
88 |
|
89 |
/* (non-Javadoc)
|
90 |
* @see org.gvsig.raster.lib.buffer.api.operations.OperationFactory#getName()
|
91 |
*/
|
92 |
@Override
|
93 |
public String getName() { |
94 |
return NAME;
|
95 |
} |
96 |
|
97 |
/* (non-Javadoc)
|
98 |
* @see org.gvsig.raster.lib.buffer.api.operations.OperationFactory#getDescription()
|
99 |
*/
|
100 |
@Override
|
101 |
public String getDescription() { |
102 |
return DESCRIPTION;
|
103 |
} |
104 |
|
105 |
/* (non-Javadoc)
|
106 |
* @see org.gvsig.raster.lib.buffer.api.operations.OperationFactory#isApplicable(org.gvsig.raster.lib.buffer.api.Buffer)
|
107 |
*/
|
108 |
@Override
|
109 |
public Applicable isApplicable(Buffer buffer) { |
110 |
int bandsCount = buffer.getBandCount();
|
111 |
int byteBandsCount = 0; |
112 |
for(int band = 0; band<bandsCount; band++){ |
113 |
if (buffer.getBandTypes()[band]==BufferManager.TYPE_BYTE) {
|
114 |
byteBandsCount++; |
115 |
} |
116 |
} |
117 |
if(byteBandsCount==bandsCount){
|
118 |
return Applicable.YES;
|
119 |
} else if (byteBandsCount==0) { |
120 |
return Applicable.NO;
|
121 |
} |
122 |
return Applicable.UNKNOW;
|
123 |
} |
124 |
|
125 |
/* (non-Javadoc)
|
126 |
* @see org.gvsig.raster.lib.buffer.api.operations.OperationFactory#isApplicable(org.gvsig.raster.lib.buffer.api.operations.Operation)
|
127 |
*/
|
128 |
@Override
|
129 |
public Applicable isApplicable(Operation operation) { |
130 |
//FIXME:
|
131 |
return Applicable.YES;
|
132 |
} |
133 |
|
134 |
protected DynStruct registerParametersDefinition(String name, String filename) { |
135 |
DynStruct definition = null;
|
136 |
|
137 |
DynObjectManager manager = ToolsLocator.getDynObjectManager(); |
138 |
definition = manager.get(name); |
139 |
if ( definition == null) { |
140 |
InputStream stream = this.getClass().getResourceAsStream(filename); |
141 |
if( stream == null ) { |
142 |
throw new IllegalArgumentException("File '"+filename+"' not found"); |
143 |
} |
144 |
Map<String, DynStruct> definitions = null; |
145 |
try {
|
146 |
definitions = manager.importDynClassDefinitions(stream, this.getClass().getClassLoader());
|
147 |
} catch (XmlPullParserException e) {
|
148 |
throw new IllegalArgumentException("DynClass '"+name+"' can't parse file '"+filename+"'",e); |
149 |
} catch (IOException e) { |
150 |
throw new IllegalArgumentException("DynClass '"+name+"' can't read file '"+filename+"'",e); |
151 |
} |
152 |
definition = definitions.get(name); |
153 |
if ( definition == null) { |
154 |
throw new IllegalArgumentException("DynClass '"+name+"' not found in file '"+filename+"'"); |
155 |
} |
156 |
} |
157 |
return definition;
|
158 |
} |
159 |
|
160 |
} |