Revision 2813

View differences:

tags/Root_jCMS04/libraries/libCq CMS for java.old/ant.xml
1
<project name="CMS for Java" default="dist" basedir=".">
2
    <description>
3
        Genera el jar con CMS y sus dependencias
4
    </description>
5
  <!-- set global properties for this build -->
6
  <property name="src" location="src"/>
7
  <property name="build" location="bin"/>
8
  <property name="dist"  location="dist"/>
9
  <property name="jar" value="cms"/>
10
  <!--property name="fmapdir" value="../FMAP"/-->
11
  <property name="targetDir1" location="../FMAP/lib"/>
12
  <property name="targetDir" location="../FMap 03/lib"/>
13
  <property name="targetDir2" location="."/>
14

  
15
  <target name="init">
16
    <!-- Create the time stamp -->
17
    <tstamp/>
18
    <!-- Create the build directory structure used by compile -->
19
    <mkdir dir="${build}"/>
20
  </target>
21

  
22
  <target name="compile" depends="init"
23
        description="compile the source " >
24
    <!-- Compile the java code from ${src} into ${build} 
25
    <javac srcdir="${src}" destdir="${build}"/>-->
26
  </target>
27

  
28
  <target name="dist" depends="compile"
29
        description="generate the distribution" >
30
    <!-- Create the distribution directory -->
31
    <mkdir dir="${dist}"/>
32

  
33
    <!-- Put everything in ${build} into the cms-${DSTAMP}.jar file --> 
34
    <jar jarfile="${dist}/${jar}.jar" basedir="${build}"/>
35
    <jar jarfile="${dist}/${jar}.jar" basedir="." includes = "images/*.gif" update="true" />
36
    <copy todir="${dist}">
37
    	<fileset dir="./lib" includes="*.jar"/>
38
    </copy>
39
    <copy todir="${targetDir1}/">
40
    	<fileset dir="${dist}" includes="**/**"/>
41
    </copy>
42
    <copy todir="${targetDir2}/">
43
    	<fileset dir="${dist}" includes="${jar}.jar"/>
44
    </copy>
45
    <move todir="${targetDir}/">
46
    	<fileset dir="${dist}" includes="**/**"/>
47
    </move>
48
  </target>
49

  
50
  <target name="clean"
51
        description="clean up" >
52
    <!-- Delete the ${build} and ${dist} directory trees -->
53
    <delete dir="${build}"/>
54
    <delete dir="${dist}"/>
55
  </target>
56
</project>
57

  
0 58

  
tags/Root_jCMS04/libraries/libCq CMS for java.old/.project
1
<?xml version="1.0" encoding="UTF-8"?>
2
<projectDescription>
3
	<name>Cq CMS for Java</name>
4
	<comment></comment>
5
	<projects>
6
		<project>CIT MapView</project>
7
		<project>CqMDT</project>
8
		<project>jmGRasterLib</project>
9
	</projects>
10
	<buildSpec>
11
		<buildCommand>
12
			<name>org.eclipse.jdt.core.javabuilder</name>
13
			<arguments>
14
			</arguments>
15
		</buildCommand>
16
	</buildSpec>
17
	<natures>
18
		<nature>org.eclipse.jem.workbench.JavaEMFNature</nature>
19
		<nature>org.eclipse.jdt.core.javanature</nature>
20
		<nature>org.eclipse.jem.beaninfo.BeanInfoNature</nature>
21
	</natures>
22
</projectDescription>
0 23

  
tags/Root_jCMS04/libraries/libCq CMS for java.old/src/.cvsignore
1
*.dfPackage
2
*.wmf
0 3

  
tags/Root_jCMS04/libraries/libCq CMS for java.old/src/org/cresques/io/IDataWriter.java
1
/*
2
 * Cresques Mapping Suite. Graphic Library for constructing mapping applications.
3
 *
4
 * Copyright (C) 2004-5.
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., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
19
 *
20
 * For more information, contact:
21
 *
22
 * cresques@gmail.com
23
 */
24
package org.cresques.io;
25

  
26

  
27
/**
28
 * Este interfaz debe ser implementado por las clases que vayan a
29
 * servir datos a los drivers de escritura.
30
 * @author Nacho Brodin (brodin_ign@gva.es)
31
 */
32
public interface IDataWriter {
33
    public int[] readData(int sizeX, int sizeY, int nBand);
34
}
0 35

  
tags/Root_jCMS04/libraries/libCq CMS for java.old/src/org/cresques/io/GmlFile.java
1
/*
2
 * Cresques Mapping Suite. Graphic Library for constructing mapping applications.
3
 *
4
 * Copyright (C) 2004-5.
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., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
19
 *
20
 * For more information, contact:
21
 *
22
 * cresques@gmail.com
23
 */
24
package org.cresques.io;
25

  
26
import org.cresques.cts.ICoordTrans;
27
import org.cresques.cts.IProjection;
28

  
29
import org.cresques.px.IObjList;
30
import org.cresques.px.gml.Feature;
31
import org.cresques.px.gml.FeatureCollection;
32
import org.cresques.px.gml.Geometry;
33
import org.cresques.px.gml.LineString;
34
import org.cresques.px.gml.MultiGeometry;
35
import org.cresques.px.gml.MultiPolygon;
36
import org.cresques.px.gml.Point;
37
import org.cresques.px.gml.Polygon;
38

  
39
import java.io.BufferedReader;
40
import java.io.FileNotFoundException;
41
import java.io.FileReader;
42
import java.io.IOException;
43
import java.io.InputStream;
44
import java.io.InputStreamReader;
45
import java.io.Reader;
46

  
47
import java.util.Hashtable;
48

  
49

  
50
/**
51
 * Cargador de ficheros .gml de JUMP de vivid solutions.
52
 * Actualmente lee un subconjunto de datos. Datos de prueba generados por JUMP.
53
 * @author "Luis W. Sevilla" <sevilla_lui@gva.es>
54
 */
55
public class GmlFile extends GeoFile {
56
    final static int NOWHERE = -1;
57
    final static int INCOORDINATES = 0;
58
    final static int INPROPERTY = 1;
59
    final static String LT = "<";
60
    final static String GT = ">";
61
    int where = NOWHERE;
62
    Hashtable tipos = new Hashtable();
63
    FeatureCollection collection = null;
64
    Feature activeFeature = null;
65
    Geometry activeGeometry = null;
66
    Geometry activeMember = null;
67
    String buf = null;
68
    String propName = null;
69
    long lineNr = 0;
70
    BufferedReader fi;
71
    long l = 0;
72
    int count = 0;
73

  
74
    /**
75
     * Constructor de la clase Gml
76
     *
77
     */
78
    public GmlFile(IProjection proj, String name) {
79
        super(proj, name);
80
    }
81

  
82
    /**
83
     * Carga un .gml
84
     * @param name nombre del fichero
85
     */
86
    public GeoFile load() {
87
        System.out.println("Cargando " + name + " ...");
88

  
89
        try {
90
            if (FileFolder.isUrl(name)) {
91
                ZipFileFolder zFolder = new ZipFileFolder(name);
92
                InputStream is = zFolder.getInputStream(name);
93

  
94
                return load(new InputStreamReader(is));
95
            } else {
96
                return load(new FileReader(name));
97
            }
98
        } catch (FileNotFoundException e) {
99
            e.printStackTrace();
100
        } catch (IOException ie) {
101
            System.err.println("ERROR." + l + "lineas leidas");
102
            ie.printStackTrace();
103
        }
104

  
105
        return this;
106
    }
107

  
108
    public GeoFile load(Reader fr) {
109
        try {
110
            fi = new BufferedReader(fr);
111

  
112
            while ((buf = fi.readLine()) != null) {
113
                //System.out.println(buf);
114
                l++;
115
                preParseLine(buf.trim());
116
            }
117

  
118
            fi.close();
119
            System.out.println("'" + name + "' cargado. (" + l + " l?neas).");
120
        } catch (FileNotFoundException e) {
121
            e.printStackTrace();
122
        } catch (IOException ie) {
123
            System.err.println("ERROR." + l + "lineas leidas");
124
            ie.printStackTrace();
125
        }
126

  
127
        this.lineNr = l;
128
        extent.add(collection.getExtent());
129

  
130
        return this;
131
    }
132

  
133
    /**
134
     * Analiza una l?nea del fichero .gml
135
     * @param l linea que analiza
136
     */
137
    void preParseLine(String l) {
138
        String line1;
139

  
140
        //System.err.println("pre0: '"+l+"'");
141
        //if (count++>500) System.exit(1);
142
        if (l.indexOf(LT) > 0) {
143
            line1 = l.substring(0, l.indexOf(LT)).trim();
144
            l = l.substring(l.indexOf(LT)).trim();
145

  
146
            //System.err.println("pre1: '"+line1+"', '"+l+"'");
147
            preParseLine(line1);
148
            preParseLine(l);
149

  
150
            return;
151
        }
152

  
153
        if ((l.indexOf(GT) >= 0) && (l.indexOf(GT) != (l.length() - 1))) {
154
            line1 = l.substring(0, l.indexOf(GT) + 1).trim();
155
            l = l.substring(l.indexOf(GT) + 1).trim();
156

  
157
            //System.err.println("pre2: '"+line1+"', '"+l+"'");
158
            preParseLine(line1);
159
            preParseLine(l);
160

  
161
            return;
162
        }
163

  
164
        parseToken(l);
165
    }
166

  
167
    /**
168
     * Analiza un token
169
     * @param l
170
     */
171
    void parseToken(String l) {
172
        String token = null;
173

  
174
        //System.err.println(l);
175
        if ((l.length() > 0) && (l.substring(0, 1).compareTo(LT) == 0)) {
176
            token = l.substring(1, l.indexOf(GT));
177

  
178
            if (token.compareTo("gml:coordinates") == 0) {
179
                where = INCOORDINATES;
180
            } else if (token.compareTo("/gml:coordinates") == 0) {
181
                where = NOWHERE;
182
            } else if (token.compareTo("gml:LinearRing") == 0) {
183
            } else if (token.compareTo("/gml:LinearRing") == 0) {
184
            } else if (token.compareTo("gml:Polygon") == 0) {
185
                activeMember = new Polygon();
186

  
187
                if (activeGeometry == null) {
188
                    activeGeometry = activeMember;
189
                }
190
            } else if (token.compareTo("/gml:Polygon") == 0) {
191
                if (activeGeometry.getClass() == MultiPolygon.class) {
192
                    ((MultiPolygon) activeGeometry).add(activeMember);
193
                }
194

  
195
                activeMember = null;
196
            } else if (token.compareTo("gml:LineString") == 0) {
197
                activeMember = new LineString();
198

  
199
                if (activeGeometry == null) {
200
                    activeGeometry = activeMember;
201
                }
202
            } else if (token.compareTo("/gml:LineString") == 0) {
203
                if (activeGeometry.getClass() == MultiGeometry.class) {
204
                    ((MultiGeometry) activeGeometry).add(activeMember);
205
                }
206

  
207
                activeMember = null;
208
            } else if (token.compareTo("gml:outerBoundaryIs") == 0) {
209
            } else if (token.compareTo("/gml:outerBoundaryIs") == 0) {
210
            } else if (token.compareTo("featureCollection") == 0) {
211
                collection = new FeatureCollection(proj);
212
            } else if (token.compareTo("/featureCollection") == 0) {
213
            } else if (token.compareTo("feature") == 0) {
214
                System.err.println("feature");
215
                activeFeature = new Feature();
216
            } else if (token.compareTo("/feature") == 0) {
217
                collection.add(activeFeature);
218
                activeFeature = null;
219
            } else if (token.compareTo("geometry") == 0) {
220
            } else if (token.compareTo("/geometry") == 0) {
221
                activeFeature.setGeometry(activeGeometry);
222
                activeGeometry = null;
223
                activeMember = null;
224
            } else if (token.compareTo("gml:Point") == 0) {
225
                activeMember = new Point();
226

  
227
                if (activeGeometry == null) {
228
                    activeGeometry = activeMember;
229
                }
230
            } else if (token.compareTo("/gml:Point") == 0) {
231
                activeMember = null;
232
            } else if (token.compareTo("gml:MultiPolygon") == 0) {
233
                activeGeometry = new MultiPolygon();
234
            } else if (token.compareTo("/gml:MultiPolygon") == 0) {
235
            } else if (token.compareTo("gml:MultiPoint") == 0) {
236
                //activeGeometry = new MultiPoint();
237
            } else if (token.compareTo("/gml:MultiPoint") == 0) {
238
            } else if (token.compareTo("gml:polygonMember") == 0) {
239
            } else if (token.compareTo("/gml:polygonMember") == 0) {
240
            } else if (token.compareTo("gml:innerBoundaryIs") == 0) {
241
                ((Polygon) activeMember).setInnerBoundary();
242
            } else if (token.compareTo("/gml:innerBoundaryIs") == 0) {
243
            } else if (token.startsWith("property")) {
244
                where = INPROPERTY;
245
                propName = l.substring(l.indexOf("\"") + 1);
246
                propName = propName.substring(0, propName.indexOf("\""));
247
            } else if (token.startsWith("/property")) {
248
                where = NOWHERE;
249

  
250
                Integer tipo = new Integer(0);
251

  
252
                if (tipos.containsKey(token)) {
253
                    tipo = (Integer) tipos.get(token);
254
                }
255

  
256
                tipos.put(token, new Integer(tipo.intValue() + 1));
257
            }
258
        } else {
259
            switch (where) {
260
            case INPROPERTY:
261
                activeFeature.setProp(propName, l);
262

  
263
                break;
264

  
265
            case INCOORDINATES:
266

  
267
                String[] txt = l.split(",");
268
                double[] pt = new double[3];
269

  
270
                for (int i = 0; i < txt.length; i++)
271
                    pt[i] = Double.parseDouble(txt[i]);
272

  
273
                activeMember.add(proj.createPoint(pt[0], pt[1]));
274

  
275
                break;
276
            }
277
        }
278
    }
279

  
280
    /**
281
     * Obtiene la lista de features.
282
     */
283
    public IObjList getObjects() {
284
        return collection;
285
    }
286

  
287
    /**
288
     * Saca las estadisticas del fichero por stdout.
289
     */
290
    public void pintaStats() {
291
        /*                print "GML file '%s': %d lineas" % (self.name, self.lineNr)
292
                        print "GML Tokens:"
293
                        kk = self.tipos.keys()
294
                        kk.sort()
295
                        for k in kk:
296
                                print k, self.tipos[k]
297
                        print "\nTotal Coordenadas %d\n" % geo.Polygon.numCoords
298
                        #print "\nExtent: min=(%.2f,%df), max=(%.2f,%.2f)" % (self.minX, self.minY, self.maxX, self.maxY)
299
                        print "\nExtent: ", (self.minX, self.minY, self.maxX, self.maxY)*/
300
        String txt = "GML file: '" + name + "': " + lineNr + " l?neas\n";
301
        txt += ("\nGML file: Total Coordenadas: " + Polygon.pointNr + "\n");
302
        txt += ("GML file: Total features: " + collection.size() + "\n");
303
        txt += ("GML file: " + collection.getExtent() + "\n");
304
        txt += ("GML file: " + ((Feature) collection.get(0)).getExtent());
305
        System.out.println(txt);
306
    }
307

  
308
    public void reProject(ICoordTrans rp) {
309
        collection.reProject(rp);
310
        setProjection(rp.getPDest());
311
    }
312

  
313
    /* (non-Javadoc)
314
     * @see org.cresques.io.GeoFile#close()
315
     */
316
    public void close() {
317
        // TODO Auto-generated method stub
318
    }
319
}
0 320

  
tags/Root_jCMS04/libraries/libCq CMS for java.old/src/org/cresques/io/raster/PixelFilter.java
1
/*
2
 * Cresques Mapping Suite. Graphic Library for constructing mapping applications.
3
 *
4
 * Copyright (C) 2004-5.
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., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
19
 *
20
 * For more information, contact:
21
 *
22
 * cresques@gmail.com
23
 */
24
package org.cresques.io.raster;
25

  
26

  
27
/**
28
 * @author Luis W. Sevilla (sevilla_lui@gva.es)
29
 */
30
public class PixelFilter {
31
    public boolean debug = false;
32
    int transparente = 0x10ffff00;
33
    int orColor = 0xff000000;
34
    int umbral = 0xf0f0f0;
35
    private int alpha = 0xff;
36

  
37
    /**
38
     * Constructor para el Oleico
39
     */
40
    public PixelFilter(int alpha) {
41
        transparente = 0x10ffff00;
42
        setAlpha(alpha);
43

  
44
        //orColor = 0xff000000 | (alpha * 0x1000000);
45
        umbral = 0xf0f0f0;
46
    }
47

  
48
    /**
49
     * Constructor.
50
     *
51
     * @param trans Color que sustituye a los pixeles filtrados
52
     * @param or        M?scara que se aplica a los pixeles restantes
53
     * @param pxMax        Umbral que determina los pixeles.
54
     */
55
    public PixelFilter(int trans, int or, int pxMax) {
56
        transparente = trans;
57
        setAlpha((orColor >> 24) & 0xff);
58
        orColor = or;
59
        umbral = pxMax;
60
    }
61

  
62
    public void setAlpha(int alpha) {
63
        this.alpha = alpha;
64
        orColor = (alpha << 24) & 0xff000000;
65
    }
66

  
67
    public int getAlpha() {
68
        return alpha;
69
    }
70

  
71
    /**
72
     * Filtra una l?nea de pixeles.
73
     *
74
     * @param pRGBArray
75
     */
76
    public void filterLine(int[] pRGBArray) {
77
        for (int i = 0; i < pRGBArray.length; i++) {
78
            /*if (debug)
79
                    System.out.print(""+i+":"+Integer.toHexString(pRGBArray[i])+",");*/
80
            if (pRGBArray[i] >= umbral) {
81
                pRGBArray[i] = transparente;
82
            } else {
83
                pRGBArray[i] |= orColor;
84
            }
85
        }
86

  
87
        /*if (debug)
88
                System.out.println("");*/
89
    }
90
}
0 91

  
tags/Root_jCMS04/libraries/libCq CMS for java.old/src/org/cresques/io/raster/RasterFilterStackManager.java
1
/*
2
 * Cresques Mapping Suite. Graphic Library for constructing mapping applications.
3
 *
4
 * Copyright (C) 2004-5.
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., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
19
 *
20
 * For more information, contact:
21
 *
22
 * cresques@gmail.com
23
 */
24
package org.cresques.io.raster;
25

  
26
import java.lang.reflect.Constructor;
27

  
28
import java.util.ArrayList;
29
import java.util.Hashtable;
30
import java.util.StringTokenizer;
31
import java.util.regex.Matcher;
32
import java.util.regex.Pattern;
33

  
34

  
35
/**
36
 * Esta clase es de la parte cliente y es la encargada de la gesti?n
37
 * de la pila de filtros. Es la que conoce el orden en que se deben apilar
38
 * estos para que la ejecuci?n sea correcta. Un cliente que desee aplicar un
39
 * filtro deber? introducirlo en la pila usando para ello esta clase.
40
 * @author Nacho Brodin (brodin_ign@gva.es)
41
 *
42
 */
43
public class RasterFilterStackManager implements IStackManager {
44
    protected RasterFilterStack filterStack = null;
45
    private boolean debug = false;
46
    protected Hashtable typeFilters = new Hashtable();
47
    public int[] order = null;
48
    private ArrayList managers = new ArrayList();
49
    protected ArrayList filterList = null;
50

  
51
    /**
52
     * Constructor
53
     * @param filterStack
54
     */
55
    public RasterFilterStackManager(RasterFilterStack filterStack) {
56
        this.filterStack = filterStack;
57
        typeFilters.put("transparency", new Integer(0));
58
        typeFilters.put("enhanced", new Integer(1));
59
        typeFilters.put("computeminmax", new Integer(2));
60
        typeFilters.put("tail", new Integer(3));
61
        typeFilters.put("removebands", new Integer(4));
62
        init();
63
        this.filterStack.setOrder(order);
64
    }
65

  
66
    /**
67
     * Registra un manager del sistema
68
     * @param manager
69
     */
70
    protected void register(IStackManager manager) {
71
        managers.add(manager);
72
    }
73

  
74
    /**
75
     * Inicializaci?n. Asigna el orden de los filtros
76
     *
77
     */
78
    protected void init() {
79
        order = new int[typeFilters.size()];
80
        order[0] = ((Integer) typeFilters.get("computeminmax")).intValue();
81
        order[1] = ((Integer) typeFilters.get("tail")).intValue();
82
        order[2] = ((Integer) typeFilters.get("enhanced")).intValue();
83
        order[3] = ((Integer) typeFilters.get("transparency")).intValue();
84
        order[4] = ((Integer) typeFilters.get("removebands")).intValue();
85
    }
86

  
87
    /**
88
     * A?ade un nuevo tipo de filtro
89
     * @param key        Nombre del filtro
90
     * @param type        Constante entera asignada a ese tipo
91
     */
92
    protected void addTypeFilter(String key, int type, int position) {
93
        typeFilters.put(key, new Integer(type));
94

  
95
        int[] newOrder = new int[order.length + 1];
96

  
97
        for (int i = 0; i < position; i++)
98
            newOrder[i] = order[i];
99

  
100
        newOrder[position] = type;
101

  
102
        for (int i = position + 1; i < newOrder.length; i++)
103
            newOrder[i] = order[i - 1];
104

  
105
        order = newOrder;
106
        this.filterStack.setOrder(order);
107
    }
108

  
109
    /**
110
     * Obtiene la constante correspondiente a un tipo de filtro
111
     * @param key        Clave para obtener la constante que corresponde al nombre del filtro
112
     * @return        Tipo de filtro
113
     */
114
    public int getTypeFilter(String key) {
115
        return ((Integer) typeFilters.get(key)).intValue();
116
    }
117

  
118
    /**
119
     * A?ade un filtro de transparencia
120
     * @param red        Intervalos de la banda del rojo a poner transparentes
121
     * @param green        Intervalos de la banda del verde a poner transparentes
122
     * @param blue        Intervalos de la banda del azul a poner transparentes
123
     * @param alpha        Transparencia
124
     * @param transparencyRed        Color en la banda del rojo de la transparencia
125
     * @param transparencyGreen        Color en la banda del verde de la transparencia
126
     * @param transparencyBlue        Color en la banda del azul de la transparencia
127
     */
128
    public void addTransparencyFilter(int[][] red, int[][] green, int[][] blue,
129
                                      int alpha, int transparencyRed,
130
                                      int transparencyGreen,
131
                                      int transparencyBlue) {
132
        RasterFilter filtro = null;
133

  
134
        switch (filterStack.getDataTypeInFilter(((Integer) typeFilters.get("transparency")).intValue())) {
135
        case RasterBuf.TYPE_IMAGE:
136
            filtro = new TransparencyImageFilter();
137

  
138
            break;
139

  
140
        case RasterBuf.TYPE_SHORT:
141
        case RasterBuf.TYPE_USHORT:
142
        case RasterBuf.TYPE_INT:
143
            filtro = new TransparencyShortFilter();
144

  
145
            break;
146
        }
147

  
148
        if (red != null) {
149
            filtro.addParam("red", red);
150
        }
151

  
152
        if (green != null) {
153
            filtro.addParam("green", green);
154
        }
155

  
156
        if (blue != null) {
157
            filtro.addParam("blue", blue);
158
        }
159

  
160
        filtro.addParam("alpha", new Integer(alpha));
161
        filtro.addParam("transparencyRed", new Integer(transparencyRed));
162
        filtro.addParam("transparencyGreen", new Integer(transparencyGreen));
163
        filtro.addParam("transparencyBlue", new Integer(transparencyBlue));
164

  
165
        //Elimina los filtros que son equivalentes a este
166
        /*for(int i=0;i<filterStack.lenght();i++){
167
                if( filterStack.get(i) instanceof TransparencyImageFilter ||
168
                        filterStack.get(i) instanceof TransparencyShortFilter){
169

  
170
                        //Si este filtro es equivalente a uno de la pila se elimina este
171
                        if(((TransparencyFilter)filtro).isEquivalent((TransparencyFilter)filterStack.get(i)))
172
                                filterStack.removeFilter(filterStack.get(i));
173

  
174
                }
175
        }
176

  
177
        //A?ade el filtro si no hay uno equivalente
178

  
179
        boolean equivalentFilter = false;
180
        for(int i=0;i<filterStack.lenght();i++){
181
                if( filterStack.get(i) instanceof TransparencyImageFilter ||
182
                        filterStack.get(i) instanceof TransparencyShortFilter){
183

  
184
                        //Si no existe en la pila un filtro equivalente se a?ade
185
                        if(((TransparencyFilter)filterStack.get(i)).isEquivalent((TransparencyFilter)filtro)){
186
                                equivalentFilter = true;
187
                                break;
188
                        }
189
                }
190
        }
191
        if(!equivalentFilter)*/
192
        filterStack.removeFilter(((Integer) typeFilters.get("transparency")).intValue());
193
        filterStack.addFilter(((Integer) typeFilters.get("transparency")).intValue(),
194
                              filtro);
195
        this.controlTypes();
196
    }
197

  
198
    /**
199
     * Obtiene el rango de rojo del filtro de transparencia de la pila
200
     * @return rango de rojo
201
     */
202
    public int[][] getTransparecyR() {
203
        for (int i = 0; i < filterStack.lenght(); i++) {
204
            if (filterStack.get(i) instanceof TransparencyImageFilter ||
205
                    filterStack.get(i) instanceof TransparencyShortFilter) {
206
                return ((TransparencyFilter) filterStack.get(i)).rangesR;
207
            }
208
        }
209

  
210
        return null;
211
    }
212

  
213
    /**
214
     * Obtiene el rango de verde del filtro de transparencia de la pila
215
     * @return rango de verde
216
     */
217
    public int[][] getTransparecyG() {
218
        for (int i = 0; i < filterStack.lenght(); i++) {
219
            if (filterStack.get(i) instanceof TransparencyImageFilter ||
220
                    filterStack.get(i) instanceof TransparencyShortFilter) {
221
                return ((TransparencyFilter) filterStack.get(i)).rangesG;
222
            }
223
        }
224

  
225
        return null;
226
    }
227

  
228
    /**
229
     * Obtiene el rango de azul del filtro de transparencia de la pila
230
     * @return rango de azul
231
     */
232
    public int[][] getTransparecyB() {
233
        for (int i = 0; i < filterStack.lenght(); i++) {
234
            if (filterStack.get(i) instanceof TransparencyImageFilter ||
235
                    filterStack.get(i) instanceof TransparencyShortFilter) {
236
                return ((TransparencyFilter) filterStack.get(i)).rangesB;
237
            }
238
        }
239

  
240
        return null;
241
    }
242

  
243
    /**
244
     * A?ade un filtro de eliminado de bandas. Las pone a 0
245
     * @param bands
246
     */
247
    public void addRemoveBands(String bands) {
248
        RasterFilter filtro = null;
249

  
250
        switch (filterStack.getDataTypeInFilter(((Integer) typeFilters.get("removebands")).intValue())) {
251
        case RasterBuf.TYPE_IMAGE:
252
            filtro = new RemoveBandsImageFilter();
253

  
254
            break;
255

  
256
        case RasterBuf.TYPE_SHORT:
257
        case RasterBuf.TYPE_USHORT:
258
        case RasterBuf.TYPE_INT:
259
            filtro = new RemoveBandsShortFilter();
260

  
261
            break;
262
        }
263

  
264
        filtro.addParam("stats", filterStack.getStats());
265
        filtro.addParam("bands", bands);
266

  
267
        filterStack.removeFilter(((Integer) typeFilters.get("removebands")).intValue());
268
        filterStack.addFilter(((Integer) typeFilters.get("removebands")).intValue(),
269
                              filtro);
270
        this.controlTypes();
271
    }
272

  
273
    /**
274
     * A?ade un filtro de recorte de colas.
275
     * @param tail        porcentaje de recorte
276
     * @param samples        porcentaje de muestras tomadas del total de la imagen
277
     */
278
    public void addTailFilter(double tail, double samples,
279
                              boolean removeMaxValue) {
280
        if (filterStack.isActive(((Integer) typeFilters.get("tail")).intValue())) {
281
            filterStack.removeFilter(((Integer) typeFilters.get("tail")).intValue());
282
        }
283

  
284
        RasterFilter filtro = null;
285

  
286
        switch (filterStack.getDataTypeInFilter(((Integer) typeFilters.get("tail")).intValue())) {
287
        case RasterBuf.TYPE_IMAGE:
288
            filtro = new PercentTailTrimImageFilter();
289

  
290
            break;
291

  
292
        case RasterBuf.TYPE_SHORT:
293
        case RasterBuf.TYPE_USHORT:
294
        case RasterBuf.TYPE_INT:
295
            filtro = new PercentTailTrimShortFilter();
296

  
297
            break;
298
        }
299

  
300
        filtro.addParam("stats", filterStack.getStats());
301
        filtro.addParam("tail", new Double(tail));
302
        filtro.addParam("samples", new Double(samples));
303
        filtro.addParam("remove", new Boolean(removeMaxValue));
304

  
305
        filterStack.addFilter(((Integer) typeFilters.get("tail")).intValue(),
306
                              filtro);
307
        this.controlTypes();
308
    }
309

  
310
    /**
311
     * A?ade un filtro de realce. Esta versi?n tiene el par?metro para a?adirle el nombre
312
     * del fichero. Esto se usa para que si a un fichero se le ha calculado ya el recorte de colas
313
     * no se vuelva a calcular, evitando as? que si hacemos un draw a una imagen por bloques cada
314
     * bloque tenga un calculo distinto para el recorte.
315
     */
316
    public void addEnhancedFilter(boolean remove, String fileName) {
317
        if (filterStack.isActive(((Integer) typeFilters.get("enhanced")).intValue())) {
318
            filterStack.removeFilter(((Integer) typeFilters.get("enhanced")).intValue());
319
        }
320

  
321
        RasterFilter filtro = null;
322

  
323
        switch (filterStack.getDataTypeInFilter(((Integer) typeFilters.get("enhanced")).intValue())) {
324
        case RasterBuf.TYPE_IMAGE:
325
            filtro = new LinearEnhancementImageFilter();
326

  
327
            break;
328

  
329
        case RasterBuf.TYPE_SHORT:
330
        case RasterBuf.TYPE_USHORT:
331
        case RasterBuf.TYPE_INT:
332
            filtro = new LinearEnhancementShortFilter();
333

  
334
            break;
335
        }
336

  
337
        filtro.addParam("stats", filterStack.getStats());
338

  
339
        if (remove) {
340
            filtro.addParam("remove", new Boolean(true));
341
        } else {
342
            filtro.addParam("remove", new Boolean(false));
343
        }
344

  
345
        if (fileName != null) {
346
            filtro.addParam("filename", fileName);
347
        } else {
348
            filtro.addParam("filename", new String(""));
349
        }
350

  
351
        filterStack.addFilter(((Integer) typeFilters.get("enhanced")).intValue(),
352
                              filtro);
353
        this.controlTypes();
354
    }
355

  
356
    /**
357
     * A?ade un filtro de realce
358
     */
359
    public void addEnhancedFilter(boolean remove) {
360
        addEnhancedFilter(remove, "");
361
    }
362

  
363
    /**
364
     * A?ade un filtro ComputeMinMax
365
     */
366
    public void addComputeMinMaxFilter() {
367
        if (!filterStack.isActive(((Integer) typeFilters.get("computeminmax")).intValue())) { //Solo lo a?adimos si no est?
368

  
369
            RasterFilter filtro = null;
370

  
371
            switch (filterStack.getDataTypeInFilter(((Integer) typeFilters.get("computeminmax")).intValue())) {
372
            case RasterBuf.TYPE_IMAGE:
373
                filtro = new ComputeMinMaxImageFilter();
374

  
375
                break;
376

  
377
            case RasterBuf.TYPE_SHORT:
378
            case RasterBuf.TYPE_USHORT:
379
            case RasterBuf.TYPE_INT:
380
                filtro = new ComputeMinMaxShortFilter();
381

  
382
                break;
383
            }
384

  
385
            filtro.addParam("stats", filterStack.getStats());
386
            filterStack.addFilter(((Integer) typeFilters.get("computeminmax")).intValue(),
387
                                  filtro);
388
        }
389

  
390
        this.controlTypes();
391
    }
392

  
393
    /**
394
     * Obtiene el tipo de filtro a partir del objeto RasterFilter
395
     * @param rasterFilter        Objeto RasterFilter del cual se quiere saber que tipo de filtro contiene
396
     * @return        Tipo de filtro seg?n las constantes contenidas en RasterFilterStackManager
397
     */
398
    protected int getType(RasterFilter rasterFilter) {
399
        if (rasterFilter instanceof TransparencyFilter) {
400
            return 0;
401
        }
402

  
403
        if (rasterFilter instanceof LinearEnhancementFilter) {
404
            return 1;
405
        }
406

  
407
        if (rasterFilter instanceof ComputeMinMaxFilter) {
408
            return 2;
409
        }
410

  
411
        if (rasterFilter instanceof PercentTailTrimFilter) {
412
            return 3;
413
        }
414

  
415
        return -1;
416
    }
417

  
418
    /**
419
     * Controla que los tipos de los filtros de la pila sean correctos, es decir, que
420
     * el tipo de salida de un filtro de salida coincida con el tipo de la entrada del
421
     * siguiente. En caso de no ser as? crea el filtro de tipo adecuado y lo sustituye
422
     * en el no coincidente. Esto es necesario ya que en la eliminaci?n de filtros puede
423
     * quedarse en inconsistencia de tipos.
424
     */
425
    protected void controlTypes() {
426
        if (debug) {
427
            filterStack.show();
428
        }
429

  
430
        for (int i = filterStack.lenght(); i >= 0; i--) {
431
            if ((i - 1) >= 0) {
432
                //Para el primer filtro comprobamos con el tipo de dato de entrada a la pila
433
                if (i == filterStack.lenght()) {
434
                    if (filterStack.getInitDataType() != filterStack.get(i - 1)
435
                                                                        .getInRasterDataType()) {
436
                        String oldClass = filterStack.get(i - 1).getClass()
437
                                                     .toString().substring(filterStack.get(i -
438
                                                                                           1)
439
                                                                                      .getClass()
440
                                                                                      .toString()
441
                                                                                      .lastIndexOf(".") +
442
                                                                           1,
443
                                                                           filterStack.get(i -
444
                                                                                           1)
445
                                                                                      .getClass()
446
                                                                                      .toString()
447
                                                                                      .length());
448
                        Pattern p = Pattern.compile(RasterBuf.typesToString(filterStack.get(i -
449
                                                                                            1)
450
                                                                                       .getInRasterDataType()));
451
                        Matcher m = p.matcher(oldClass);
452
                        String newClass = m.replaceAll(RasterBuf.typesToString(filterStack.getInitDataType()));
453

  
454
                        //System.out.println("==>"+oldClass+" "+newClass);
455
                        try {
456
                            Class filterClass = Class.forName("org.cresques.io.raster." +
457
                                                              newClass);
458
                            Constructor con = filterClass.getConstructor(null);
459
                            RasterFilter newFilter = (RasterFilter) con.newInstance(null);
460
                            newFilter.params = filterStack.get(i - 1).params;
461
                            filterStack.replace(newFilter, i - 1,
462
                                                this.getType(newFilter));
463
                        } catch (Exception e) {
464
                            e.printStackTrace();
465
                        }
466
                    }
467

  
468
                    //Desde el filtro 2 en adelante se compara la salida de uno con la entrada del siguiente
469
                } else if (filterStack.get(i).getOutRasterDataType() != filterStack.get(i -
470
                                                                                            1)
471
                                                                                       .getInRasterDataType()) {
472
                    String oldClass = filterStack.get(i - 1).getClass()
473
                                                 .toString().substring(filterStack.get(i -
474
                                                                                       1)
475
                                                                                  .getClass()
476
                                                                                  .toString()
477
                                                                                  .lastIndexOf(".") +
478
                                                                       1,
479
                                                                       filterStack.get(i -
480
                                                                                       1)
481
                                                                                  .getClass()
482
                                                                                  .toString()
483
                                                                                  .length());
484
                    Pattern p = Pattern.compile(RasterBuf.typesToString(filterStack.get(i -
485
                                                                                        1)
486
                                                                                   .getInRasterDataType()));
487
                    Matcher m = p.matcher(oldClass);
488
                    String newClass = m.replaceAll(RasterBuf.typesToString(filterStack.get(i)
489
                                                                                      .getOutRasterDataType()));
490

  
491
                    //System.out.println("==>"+oldClass+" "+newClass);
492
                    try {
493
                        Class filterClass = Class.forName("org.cresques.io.raster." +
494
                                                          newClass);
495
                        Constructor con = filterClass.getConstructor(null);
496
                        RasterFilter newFilter = (RasterFilter) con.newInstance(null);
497
                        newFilter.params = filterStack.get(i - 1).params;
498
                        filterStack.replace(newFilter, i - 1,
499
                                            this.getType(newFilter));
500
                    } catch (Exception e) {
501
                        e.printStackTrace();
502
                    }
503
                }
504
            }
505
        }
506

  
507
        if (debug) {
508
            filterStack.show();
509
        }
510
    }
511

  
512
    /**
513
     * M?todo que devuelve true si el tipo de filtro pasado por par?metro est? en la
514
     * pila y false si no lo est?.
515
     * @param filter        Tipo de filtro a comprobar
516
     * @return true si est? en la pila y false si no lo est?
517
     */
518
    public boolean isActive(int type) {
519
        return filterStack.isActive(type);
520
    }
521

  
522
    /**
523
     * Elimina los filtros de la pila de un determinado tipo
524
     * @param type        Tipo de filtro a eliminar
525
     */
526
    public void removeFilter(int type) {
527
        filterStack.removeFilter(type);
528
        this.controlTypes();
529
    }
530

  
531
    /**
532
     * Resetea el flag de temporalidad de los filtros de la pila.
533
     * Esto equivale a fijar los filtros que ya existen en la pila. A partir de
534
     * ese momento los filtros que se introduzcan podr?n ser eliminados de golpe
535
     * llamando a la funci?n deleteTempFilters
536
     */
537
    public void resetTempFilters() {
538
        filterStack.resetTempFilters();
539
    }
540

  
541
    /**
542
     * Elimina los filtros temporales, es decir, todos los filtros introducidos desde
543
     * el ?ltimo resetTempFilters que se ha realizado.
544
     */
545
    public void deleteTempFilters() {
546
        filterStack.deleteTempFilters();
547
    }
548

  
549
    /**
550
     * Obtiene el objeto de estadisticas asignado a la pila.
551
     * @return
552
     */
553
    public RasterStats getStackStats() {
554
        return filterStack.getStats();
555
    }
556

  
557
    /* (non-Javadoc)
558
     * @see org.cresques.io.raster.StackManager#getStringsFromStack()
559
     */
560
    public ArrayList getStringsFromStack() {
561
        filterList = new ArrayList();
562

  
563
        for (int i = 0; i < filterStack.lenght(); i++) {
564
            RasterFilter rf = filterStack.get(i);
565

  
566
            if (rf instanceof TransparencyFilter) {
567
                filterList.add("filter.transparency.active=true");
568
                filterList.add("filter.transparency.rangeR=" +
569
                               rangeToString(((TransparencyFilter) rf).getRangeR()));
570
                filterList.add("filter.transparency.rangeG=" +
571
                               rangeToString(((TransparencyFilter) rf).getRangeG()));
572
                filterList.add("filter.transparency.rangeB=" +
573
                               rangeToString(((TransparencyFilter) rf).getRangeB()));
574
            } else if (rf instanceof LinearEnhancementFilter) {
575
                filterList.add("filter.enhanced.active=true");
576
                filterList.add("filter.enhanced.remove=" +
577
                               ((LinearEnhancementFilter) rf).getRemoveExtrema()
578
                                .toString());
579
            } else if (rf instanceof ComputeMinMaxFilter) {
580
                filterList.add("filter.computeminmax.active=true");
581
            } else if (rf instanceof PercentTailTrimFilter) {
582
                filterList.add("filter.tail.active=true");
583
                filterList.add("filter.tail.value=" +
584
                               this.getStackStats().tailPercent);
585
                filterList.add("filter.tail.remove=" +
586
                               ((PercentTailTrimFilter) rf).removeMaxValue());
587
            } else if (rf instanceof RemoveBandsFilter) {
588
                filterList.add("filter.removebands.active=true");
589
                filterList.add("filter.removebands.bands=" +
590
                               ((RemoveBandsFilter) rf).bands);
591
            } else { //Se recorren todos los managers registrados comprobando si corresponde a la clase del filtro 
592

  
593
                for (int j = 0; j < managers.size(); j++)
594
                    ((IStackManager) managers.get(j)).getStringsFromStack();
595
            }
596
        }
597

  
598
        return filterList;
599
    }
600

  
601
    /**
602
     * Crea una pila de filtros a partir de un Array de Strings. Cada elemento del array debe
603
     * tener la forma elemento=valor.
604
     * @param filters
605
     */
606
    public void createStackFromStrings(ArrayList f) {
607
        this.createStackFromStrings(f, new Integer(0));
608
    }
609

  
610
    /* (non-Javadoc)
611
     * @see org.cresques.io.raster.StackManager#createStackFromStrings(java.util.ArrayList)
612
     */
613
    public void createStackFromStrings(ArrayList f, Integer pos) {
614
        ArrayList filters = (ArrayList) f.clone();
615
        filterStack.clear();
616

  
617
        int filteri = pos.intValue();
618

  
619
        //Busca un filtro activo y despu?s todas las propiedades que necesita ese filtro para
620
        //ser creado. Una vez las tiene a?ade en la pila el tipo de filtro.
621
        while ((filters.size() > 0) && (filteri < filters.size())) {
622
            String fil = (String) filters.get(filteri);
623

  
624
            if (fil.startsWith("filter.transparency.active") &&
625
                    getValue(fil).equals("true")) {
626
                filters.remove(filteri);
627

  
628
                int[][] r = null;
629
                int[][] g = null;
630
                int[][] b = null;
631

  
632
                for (int propFilter = 0; propFilter < filters.size();
633
                         propFilter++) {
634
                    String elem = (String) filters.get(propFilter);
635

  
636
                    if (elem.startsWith("filter.transparency.rangeR")) {
637
                        r = stringToRange(getValue(elem));
638
                        filters.remove(propFilter);
639
                        propFilter--;
640
                    }
641

  
642
                    if (elem.startsWith("filter.transparency.rangeG")) {
643
                        g = stringToRange(getValue(elem));
644
                        filters.remove(propFilter);
645
                        propFilter--;
646
                    }
647

  
648
                    if (elem.startsWith("filter.transparency.rangeB")) {
649
                        b = stringToRange(getValue(elem));
650
                        filters.remove(propFilter);
651
                        propFilter--;
652
                    }
653
                }
654

  
655
                this.addTransparencyFilter(r, g, b, 0x10, 0xff, 0xff, 0xff);
656
                filteri = -1;
657
            }
658

  
659
            if (fil.startsWith("filter.enhanced.active") &&
660
                    getValue(fil).equals("true")) {
661
                filters.remove(filteri);
662

  
663
                boolean remove = false;
664

  
665
                for (int propFilter = 0; propFilter < filters.size();
666
                         propFilter++) {
667
                    String elem = (String) filters.get(propFilter);
668

  
669
                    if (elem.startsWith("filter.enhanced.remove")) {
670
                        this.addEnhancedFilter(Boolean.valueOf(getValue(elem))
671
                                                      .booleanValue());
672
                        filters.remove(propFilter);
673
                        propFilter--;
674
                    }
675
                }
676

  
677
                this.addComputeMinMaxFilter();
678
                filteri = -1;
679
            }
680

  
681
            if (fil.startsWith("filter.tail.active") &&
682
                    getValue(fil).equals("true")) {
683
                filters.remove(filteri);
684
                this.removeFilter(this.getTypeFilter("computeminmax"));
685

  
686
                double recorte = 0D;
687
                boolean remove = false;
688

  
689
                for (int propFilter = 0; propFilter < filters.size();
690
                         propFilter++) {
691
                    String elem = (String) filters.get(propFilter);
692

  
693
                    if (elem.startsWith("filter.tail.value")) {
694
                        recorte = Double.parseDouble(getValue(elem));
695
                        filters.remove(propFilter);
696
                        propFilter--;
697
                    }
698

  
699
                    if (elem.startsWith("filter.tail.remove")) {
700
                        remove = Boolean.valueOf(getValue(elem)).booleanValue();
701
                        filters.remove(propFilter);
702
                        propFilter--;
703
                    }
704
                }
705

  
706
                this.addTailFilter(recorte, 0D, remove);
707
                filteri = -1;
708
            }
709

  
710
            if (fil.startsWith("filter.removebands.active") &&
711
                    getValue(fil).equals("true")) {
712
                filters.remove(filteri);
713

  
714
                boolean remove = false;
715

  
716
                for (int propFilter = 0; propFilter < filters.size();
717
                         propFilter++) {
718
                    String elem = (String) filters.get(propFilter);
719

  
720
                    if (elem.startsWith("filter.removebands.bands")) {
721
                        this.addRemoveBands(getValue(elem));
722
                        filters.remove(propFilter);
723
                        propFilter--;
724
                    }
725
                }
726

  
727
                filteri = -1;
728
            }
729

  
730
            for (int j = 0; j < managers.size(); j++)
731
                ((IStackManager) managers.get(j)).createStackFromStrings(filters,
732
                                                                         new Integer(filteri));
733

  
734
            filteri++;
735
        }
736
    }
737

  
738
    /**
739
     * Obtiene el elemento de una cadena de la forma elemento=valor
740
     * @param cadena
741
     * @return
742
     */
743
    public String getElem(String cadena) {
744
        if (cadena != null) {
745
            return cadena.substring(0, cadena.indexOf("="));
746
        } else {
747
            return null;
748
        }
749
    }
750

  
751
    /**
752
     * Obtiene el valor de una cadena de la forma elemento=valor
753
     * @param cadena
754
     * @return
755
     */
756
    public String getValue(String cadena) {
757
        if (cadena != null) {
758
            return cadena.substring(cadena.indexOf("=") + 1, cadena.length());
759
        } else {
760
            return null;
761
        }
762
    }
763

  
764
    /**
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff