Revision 1536

View differences:

org.gvsig.raster.cache/tags/2.0.0/prepare-workspace.xml
1
<project name="org.gvsig.initial.build" default="prepare-workspace">
2

  
3
	<dirname property="org.gvsig.initial.build.basedir" file="${ant.file.org.gvsig.initial.build}" />
4

  
5
	<property name="workspace.basedir" value="${org.gvsig.initial.build.basedir}/.." />
6
	<property name="build.basedir" value="${workspace.basedir}/org.gvsig.maven.base.build" description="Eclipse workspace location" />
7
	<property name="build.jar.version" value="1.0.8-SNAPSHOT" />
8
	<property name="build.jar.file" value="org.gvsig.maven.base.build-${build.jar.version}.jar" />
9

  
10
	<property name="ant.libs.dir" location="${build.basedir}" description="Additional ant tasks libs folder" />
11

  
12
	<target name="check-maven-base-build-available">
13
		<available file="${user.home}/.m2/repository/org/gvsig/org.gvsig.maven.base.build/${build.jar.version}/${build.jar.file}" property="maven-base-build-available" />
14
	</target>
15

  
16
	<target name="get-maven-base-build-local" depends="check-maven-base-build-available" if="maven-base-build-available">
17
		<!-- Unzip de build jar file from the maven repository into the workspace root folder -->
18
		<copy todir="${workspace.basedir}" preservelastmodified="false" filtering="false">
19
			<zipfileset src="${user.home}/.m2/repository/org/gvsig/org.gvsig.maven.base.build/${build.jar.version}/${build.jar.file}">
20
				<patternset>
21
					<exclude name="META-INF/**" />
22
				</patternset>
23
			</zipfileset>
24
		</copy>
25
	</target>
26

  
27
	<target name="get-maven-base-build-remote" depends="check-maven-base-build-available" unless="maven-base-build-available">
28
		<mkdir dir="target" />
29

  
30
		<!-- Download the build jar file -->
31
		<get src="http://devel.gvsig.org/m2repo/j2se/org/gvsig/org.gvsig.maven.base.build/${build.jar.version}/${build.jar.file}" dest="target/${build.jar.file}" verbose="true" />
32

  
33
		<!-- Unzip de build jar file into the workspace root folder -->
34
		<copy todir="${workspace.basedir}" preservelastmodified="false" filtering="false">
35
			<zipfileset src="target/${build.jar.file}">
36
				<patternset>
37
					<exclude name="META-INF/**" />
38
				</patternset>
39
			</zipfileset>
40
		</copy>
41

  
42
	</target>
43
	
44
	<target name="find.depends.natives.file">
45
	    <condition property="depends.natives.file.exists">
46
            <available file="${org.gvsig.initial.build.basedir}/DEPENDS_ON_NATIVE_LIBRARIES"/>
47
	    </condition>	
48
	</target>
49
	
50
	<target name="find.gvsig.platform.properties.file" 
51
			depends="find.depends.natives.file"
52
			if="depends.natives.file.exists">
53
	    <condition property="gvsig.platform.exists">
54
            <available file="${user.home}/.gvsig.platform.properties"/>
55
	    </condition>	
56
	</target>
57
	
58
	<target name="check.gvsig.platform.properties" 
59
			depends="find.gvsig.platform.properties.file">
60
		<fail if="depends.natives.file.exists" unless="gvsig.platform.exists">
61
ERROR!!
62
	
63
You have to define your gvSIG platform properties, 
64
by creating the file: ${user.home}/.gvsig.platform.properties
65
with the following content:
66

  
67
native_platform=linux
68
native_distribution=all
69
native_compiler=gcc4
70
native_arch=i386
71
native_libraryType=dynamic
72
export native_classifier=${native_platform}-${native_distribution}-${native_compiler}-${native_arch}-${native_libraryType}
73

  
74
Replace the fifth initial variables values with the ones appropiate 
75
to your platform.
76
	
77
If you use maven in the command line, you can use the previous file also
78
to define the MAVEN_OPTS environment variable, by adding to your 
79
.bash_rc file something like this:
80

  
81
if [ -f "${HOME}/.gvsig.platform.properties" ]
82
then
83
    . ${HOME}/.gvsig.platform.properties
84
    export MAVEN_OPTS="-Xmx256M -XX:MaxPermSize=64m -Dnative-classifier=${native_classifier}"
85
else
86
    export MAVEN_OPTS="-Xmx256M -XX:MaxPermSize=64m"
87
fi
88

  
89
It will work if you use the bash shell. In any other case or platform, you'll
90
have to define your MAVEN_OPTS environment variable and set the 
91
"native-classifier" parameter directly.
92
		</fail>			
93
	
94
	</target>
95

  
96
	<target name="prepare-workspace" depends="get-maven-base-build-local,get-maven-base-build-remote,check.gvsig.platform.properties">
97

  
98
		<mkdir dir="target" />
99

  
100
		<chmod dir="${build.basedir}/maven/bin" perm="u+x" includes="m2,mvn,mvnDebug" />
101

  
102
		<!-- Copy the maven launchers to the workspace metadata folder -->
103
		<copy todir="${workspace.basedir}/.metadata">
104
			<fileset dir="${build.basedir}/eclipse-launchers">
105
				<exclude name="**/org.eclipse.jdt.core.prefs" />
106
				<exclude name="**/org.eclipse.core.variables.prefs" />
107
			</fileset>
108
		</copy>
109

  
110
		<concat destfile="${workspace.basedir}/.metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.jdt.core.prefs" append="true">
111
			<filelist dir="${build.basedir}/eclipse-launchers/.plugins/org.eclipse.core.runtime/.settings" files="org.eclipse.jdt.core.prefs" />
112
		</concat>
113
		<concat destfile="${workspace.basedir}/.metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.core.variables.prefs" append="true">
114
			<filelist dir="${build.basedir}/eclipse-launchers/.plugins/org.eclipse.core.runtime/.settings" files="org.eclipse.core.variables.prefs" />
115
		</concat>
116

  
117
		<!-- Configure the eclipse workspace -->
118
		<ant antfile="${build.basedir}/maven-goals.xml" target="mvn-configure-eclipse-workspace" />
119

  
120
		<!-- Configure the gvSIG profile -->
121
		<ant antfile="${build.basedir}/check-gvsig-profile.xml" />
122

  
123
		<property name="user-settings-file-location" value="${user.home}/.m2/settings.xml" />
124

  
125
		<taskdef name="xmltask" classname="com.oopsconsultancy.xmltask.ant.XmlTask">
126
			<classpath>
127
				<pathelement location="${ant.libs.dir}/com.oopsconsultancy.xmltask-1.16.1.jar" />
128
			</classpath>
129
		</taskdef>
130

  
131
		<xmltask source="${user-settings-file-location}" dest="${user-settings-file-location}">
132
			<copy path="//:settings/:profiles/:profile[:id/text() = 'gvsig-install']/:properties/:gvsig.install.dir/text()" property="current-gvsig-location" />
133
		</xmltask>
134

  
135
		<replace file="${workspace.basedir}/.metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.jdt.core.prefs" token="@GVSIG_HOME@" value="${current-gvsig-location}" />
136
		<replace file="${workspace.basedir}/.metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.core.variables.prefs" token="@GVSIG_HOME@" value="${current-gvsig-location}" />
137

  
138
		<!-- Compile, install and generate eclipse projects -->
139
		<ant antfile="${build.basedir}/maven-goals.xml" target="mvn-install-and-eclipse-eclipse" />
140

  
141
		<echo>INFORMATION!!!</echo>
142
		<echo>Restart eclipse and then proceed to import the subprojects contained into the main project</echo>
143

  
144
		<!-- TODO: copiar al proyecto de configuración general -->
145
	</target>
146

  
147
	<target name="clean">
148
		<delete dir="target" />
149
	</target>
150
	
151
</project>
0 152

  
org.gvsig.raster.cache/tags/2.0.0/pom.xml
1
<?xml version="1.0" encoding="ISO-8859-1"?>
2
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3

  
4
    <modelVersion>4.0.0</modelVersion>
5
    <artifactId>org.gvsig.raster.cache</artifactId>
6
    <packaging>pom</packaging>
7
    <name>org.gvsig.raster.cache</name>
8
    <description>Cache management for raster files</description>
9
    <version>2.0.0</version>
10
    <scm>
11
        <connection>scm:svn:https://devel.gvsig.org/svn/gvsig-raster/org.gvsig.raster.cache/tags/2.0.0</connection>
12
        <developerConnection>scm:svn:https://devel.gvsig.org/svn/gvsig-raster/org.gvsig.raster.cache/tags/2.0.0</developerConnection>
13
        <url>https://devel.gvsig.org/redmine/projects/gvsig-raster/repository/show/org.gvsig.raster.cache/tags/2.0.0</url>
14
    </scm>
15
    <parent>
16
		<groupId>org.gvsig</groupId>
17
		<artifactId>org.gvsig.maven.base.pom</artifactId>
18
		<version>1.0.9</version>
19
	</parent>
20
    <developers>
21
        <developer>
22
            <id>nbrodin</id>
23
            <name>Nacho Brodin</name>
24
            <email>nachobrodin@gmail.com</email>
25
            <roles>
26
                <role>Architect</role>
27
                <role>Developer</role>
28
            </roles>
29
        </developer>
30
    </developers>
31
     <dependencyManagement>
32
        <dependencies>
33
	        <dependency>
34
				<groupId>org.gvsig</groupId>
35
				<artifactId>org.gvsig.jgdal</artifactId>
36
				<version>2.0.4-SNAPSHOT</version>
37
			</dependency>
38
	        <dependency>
39
	            <groupId>org.gvsig</groupId>
40
	            <artifactId>org.gvsig.jgdal</artifactId>
41
	            <version>2.0.4-SNAPSHOT</version>
42
	            <classifier>${native_classifier}</classifier>
43
	            <type>tar.gz</type>
44
	        </dependency>
45
		    <dependency>
46
				<groupId>org.gvsig</groupId>
47
				<artifactId>org.gvsig.raster.cache.lib.api</artifactId>
48
				<version>2.0.0</version>
49
			</dependency>
50
            
51
			<!-- DAL & gvSIG -->
52
			
53
        	<dependency>
54
				<groupId>org.gvsig</groupId>
55
				<artifactId>org.gvsig.core.maven.dependencies</artifactId>
56
				<version>2.0.1</version>
57
				<type>pom</type>
58
				<scope>import</scope>
59
			</dependency>
60
        </dependencies>
61
    </dependencyManagement>
62
    <dependencies>
63
        <dependency>
64
            <groupId>org.gvsig</groupId>
65
            <artifactId>org.gvsig.tools.lib</artifactId>
66
            <scope>compile</scope>
67
        </dependency>
68
    </dependencies>
69
    <build>
70
        <plugins>
71
            <plugin>
72
                <groupId>org.apache.maven.plugins</groupId>
73
                <artifactId>maven-release-plugin</artifactId>
74
                <configuration>
75
                    <tagBase>https://devel.gvsig.org/svn/gvsig-raster/org.gvsig.raster.cache/tags/</tagBase>
76
                </configuration>
77
            </plugin>
78
            <plugin>
79
				<groupId>org.apache.maven.plugins</groupId>
80
				<artifactId>maven-compiler-plugin</artifactId>
81
				<configuration>
82
					<source>1.5</source>
83
					<target>1.5</target>
84
				</configuration>
85
			</plugin>
86
			<plugin>
87
                <groupId>org.codehaus.mojo</groupId>
88
                <artifactId>animal-sniffer-maven-plugin</artifactId>
89
                <configuration>
90
                    <skip>true</skip>
91
                </configuration>
92
            </plugin>
93
        </plugins>
94
    </build>
95
    <modules>
96
        <module>org.gvsig.raster.cache.lib.api</module>
97
        <module>org.gvsig.raster.cache.lib.impl</module>
98
    </modules>
99
    <properties>
100
        <build-dir>${basedir}/../build</build-dir>
101
    </properties>
102
</project>
0 103

  
org.gvsig.raster.cache/tags/2.0.0/org.gvsig.raster.cache.lib.impl/src/main/java/org/gvsig/raster/cache/buffer/impl/datastruct/DefaultNoData.java
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.cache.buffer.impl.datastruct;
23

  
24
import java.util.ArrayList;
25
import java.util.List;
26

  
27
import org.gvsig.raster.cache.buffer.Buffer;
28
import org.gvsig.raster.cache.buffer.BufferNoData;
29

  
30
/**
31
 * This class represents the implementation of a nodata value.
32
 * 
33
 * @author Nacho Brodin (nachobrodin@gmail.com)
34
 */
35
public class DefaultNoData implements BufferNoData {
36
	private List<Number>             noDataByBand        = new ArrayList<Number>();
37
	private List<Number>             nativeNoDataByBand  = new ArrayList<Number>();
38
	private int                      bandCount           = 1;
39
	private String                   fileName            = null;
40
	private boolean                  noDataAsTransparent = true;
41
	private int                      dataType            = Buffer.TYPE_UNDEFINED;
42
	
43
	/**
44
	 * Constructor
45
	 */
46
	public DefaultNoData() {
47
	}
48
	
49
	/**
50
	 * Constructor.
51
	 * @param fileName
52
	 * 	      Name of file owner of this nodata value. This string is useful to 
53
	 *        save and load throw the rmf.
54
	 */
55
	public DefaultNoData(String fileName) {
56
		this.fileName = fileName;
57
	}
58
	
59
	/**
60
	 * Constructor. Only for rasters with one band
61
	 * 
62
	 * @param noData
63
	 *        value to assign to all bands
64
	 * @param nativeNoData
65
	 *        The native is the original value
66
	 *        saved in the head of the file or its metadata.
67
	 * @param fileName
68
	 *        Name of file owner of this nodata value. This string is useful to 
69
	 *        save and load throw the rmf.
70
	 */
71
	public DefaultNoData(Number noData, Number nativeNoData, String fileName) {
72
		setValue(noData);
73
		setNativeValue(nativeNoData);
74
		this.fileName = fileName;
75
		setDataType(noData);
76
	}
77
	
78
	private void setDataType(Number number) {
79
		if(number instanceof Byte)
80
			dataType = Buffer.TYPE_BYTE;
81
		if(number instanceof Short)
82
			dataType = Buffer.TYPE_SHORT;
83
		if(number instanceof Integer)
84
			dataType = Buffer.TYPE_INT;
85
		if(number instanceof Float)
86
			dataType = Buffer.TYPE_FLOAT;
87
		if(number instanceof Double)
88
			dataType = Buffer.TYPE_DOUBLE;
89
	}
90
	
91
	/**
92
	 * Constructor
93
	 * 
94
	 * @param noData
95
	 *        value to assign to all bands
96
	 * @param nativeNoData
97
	 *        The native is the original value
98
	 *        saved in the head of the file or its metadata.
99
	 * @param fileName
100
	 *        Name of file owner of this nodata value. This string is useful to
101
	 *        save the rmf file
102
	 * @param bandCount
103
	 *        Number of bands of the file
104
	 */
105
	public DefaultNoData(Number noData, Number nativeNoData, String fileName, int bandCount) {
106
		setValue(noData);
107
		setNativeValue(nativeNoData);
108
		this.fileName = fileName;
109
		setDataType(noData);
110
		if(bandCount > 1)
111
			this.bandCount = bandCount;
112
	}
113
	
114
	/*
115
	 * (non-Javadoc)
116
	 * @see org.gvsig.fmap.dal.coverage.datastruct.NoData#getValue()
117
	 */
118
	public Number getValue() {
119
		try {
120
			return noDataByBand.get(0);
121
		} catch (ArrayIndexOutOfBoundsException e) {
122
			return null;
123
		}
124
	}
125
	
126
	/*
127
	 * (non-Javadoc)
128
	 * @see org.gvsig.fmap.dal.coverage.datastruct.NoData#isDefined()
129
	 */
130
	public boolean isDefined() {
131
		return (getValue() != null);
132
	}
133

  
134
	/*
135
	 * (non-Javadoc)
136
	 * @see org.gvsig.fmap.dal.coverage.datastruct.NoData#setValue(java.lang.Number)
137
	 */
138
	public void setValue(Number noData) {
139
		noDataByBand.clear();
140
		for (int i = 0; i < bandCount; i++) {
141
			noDataByBand.add(noData);	
142
		}
143
		setDataType(noData);
144
	}
145
	
146
	public Number getNativeValue() {
147
		try {
148
			return nativeNoDataByBand.get(0);
149
		} catch (ArrayIndexOutOfBoundsException e) {
150
			return null;
151
		}
152
	}
153
	
154
	/*
155
	 * (non-Javadoc)
156
	 * @see org.gvsig.fmap.dal.coverage.datastruct.NoData#setNativeValue(double)
157
	 */
158
	public void setNativeValue(Number nativeNoDataValue) {
159
		nativeNoDataByBand.clear();
160
		for (int i = 0; i < bandCount; i++) {
161
			nativeNoDataByBand.add(nativeNoDataValue);	
162
		}
163
		setDataType(nativeNoDataValue);
164
	}
165

  
166
	/*
167
	 * (non-Javadoc)
168
	 * @see org.gvsig.fmap.dal.coverage.datastruct.NoData#delete()
169
	 */
170
	public void delete() {
171
		noDataByBand.clear();
172
		for (int i = 0; i < bandCount; i++) {
173
			noDataByBand.add(null);	
174
		}
175
	}
176

  
177
	/*
178
	 * (non-Javadoc)
179
	 * @see org.gvsig.fmap.dal.coverage.datastruct.NoData#restore()
180
	 */
181
	public void restore() {
182
		noDataByBand.clear();
183
		for (int i = 0; i < bandCount; i++) {
184
			noDataByBand.add(nativeNoDataByBand.get(i));	
185
		}
186
	}
187
	
188
	/*
189
	 * (non-Javadoc)
190
	 * @see org.gvsig.fmap.dal.coverage.datastruct.NoData#setFileName(java.lang.String)
191
	 */
192
	public void setFileName(String fileName) {
193
		this.fileName = fileName;
194
	}
195
	
196
	/*
197
	 * (non-Javadoc)
198
	 * @see org.gvsig.raster.cache.buffer.BufferNoData#getFileName()
199
	 */
200
	public String getFileName() {
201
		return fileName;
202
	}
203
	
204
	/*
205
	 * (non-Javadoc)
206
	 * @see org.gvsig.fmap.dal.coverage.datastruct.NoData#isNoDataTransparent()
207
	 */
208
	public boolean isNoDataTransparent() {
209
		return noDataAsTransparent;
210
	}
211

  
212
	/*
213
	 * (non-Javadoc)
214
	 * @see org.gvsig.fmap.dal.coverage.datastruct.NoData#setNoDataTransparent(boolean)
215
	 */
216
	public void setNoDataTransparent(boolean noDataAsTransparent) {
217
		this.noDataAsTransparent = noDataAsTransparent;
218
	}
219
	
220
	/*
221
	 * (non-Javadoc)
222
	 * @see org.gvsig.fmap.dal.coverage.datastruct.NoData#getDataType()
223
	 */
224
	public int getDataType() {
225
		return dataType;
226
	}
227
	
228
	/*
229
	 * (non-Javadoc)
230
	 * @see org.gvsig.fmap.dal.coverage.datastruct.NoData#setDataType(int)
231
	 */
232
	public void setDataType(int datatype) {
233
		this.dataType = datatype;
234
	}
235
	
236
	/*
237
	 * (non-Javadoc)
238
	 * @see org.gvsig.fmap.dal.coverage.datastruct.NoData#compare(org.gvsig.fmap.dal.coverage.datastruct.NoData)
239
	 */
240
	@SuppressWarnings("unchecked")
241
	public boolean compare(BufferNoData noData) {	
242
		String f = ((DefaultNoData)noData).fileName;
243
		
244
		if((f == null || fileName == null) && f != fileName)
245
			return false;
246
		
247
		if( fileName != null &&  f != null &&
248
			fileName.compareTo(f) != 0)
249
			return false;
250
		
251
		if(bandCount != ((DefaultNoData)noData).bandCount)
252
			return false;
253
		
254
		if(dataType != ((DefaultNoData)noData).dataType)
255
			return false;
256
		
257
		for (int i = 0; i < noDataByBand.size(); i++) {
258
			if(((Comparable)noDataByBand.get(i)).compareTo(noData.getValue()) != 0)
259
				return false;
260
		}
261
		for (int i = 0; i < nativeNoDataByBand.size(); i++) {
262
			if(((Comparable)nativeNoDataByBand.get(i)).compareTo(noData.getValue()) != 0)
263
				return false;
264
		}
265
		return true;
266
	}
267
	
268
	/*
269
	 * (non-Javadoc)
270
	 * @see java.lang.Object#clone()
271
	 */
272
	public Object clone() {
273
		return new DefaultNoData(getValue(), getNativeValue(), fileName, bandCount);
274
	}
275
	
276
	//***********************************************
277
	//Only for file with more than one band
278
	
279
	/*
280
	 * (non-Javadoc)
281
	 * @see org.gvsig.fmap.dal.coverage.datastruct.NoData#getValueByBand(int)
282
	 */
283
	public Number getValueByBand(int nBand) {
284
		try {
285
			return noDataByBand.get(nBand);
286
		} catch (ArrayIndexOutOfBoundsException e) {
287
			return null;
288
		}
289
	}
290
	
291
	/*
292
	 * (non-Javadoc)
293
	 * @see org.gvsig.fmap.dal.coverage.datastruct.NoData#setValueByBand(java.lang.Number, int)
294
	 */
295
	public void setValueByBand(Number noDataValue, int nBand) {
296
		noDataByBand.add(nBand, noDataValue);
297
		setDataType(noDataValue);
298
	}
299

  
300
	/*
301
	 * (non-Javadoc)
302
	 * @see org.gvsig.fmap.dal.coverage.datastruct.NoData#getBandCount()
303
	 */
304
	public int getBandCount() {
305
		return bandCount;
306
	}
307
	
308
	/*
309
	 * (non-Javadoc)
310
	 * @see org.gvsig.fmap.dal.coverage.datastruct.NoData#setBandCount(int)
311
	 */
312
	public void setBandCount(int bandCount) {
313
		this.bandCount = bandCount;
314
	}
315
	
316
}
0 317

  
org.gvsig.raster.cache/tags/2.0.0/org.gvsig.raster.cache.lib.impl/src/main/java/org/gvsig/raster/cache/buffer/impl/BufferInterpolationImpl.java
1
package org.gvsig.raster.cache.buffer.impl;
2

  
3
import org.gvsig.raster.cache.buffer.Buffer;
4
import org.gvsig.raster.cache.buffer.BufferInterpolation;
5
import org.gvsig.raster.cache.buffer.exception.OperationNotSupportedException;
6
import org.gvsig.raster.cache.buffer.exception.ProcessInterruptedException;
7
import org.gvsig.raster.cache.buffer.impl.task.DefaultTaskEventManager;
8
import org.gvsig.raster.cache.buffer.task.TaskEventManager;
9

  
10

  
11

  
12
/**
13
 * <p>
14
 * This class is a coverage of a RasterBuffer and contains diferents algorithms to interpolate data buffers. The methods
15
 * implemented here are nearest neighbour, bilinear, inverse distance, bspline and
16
 * bicubic.
17
 * </p>
18
 * 
19
 * @version 07/05/2007
20
 * @author Nacho Brodin (nachobrodin@gmail.com)
21
 *
22
 */
23
public class BufferInterpolationImpl implements BufferInterpolation {
24
	private Buffer                  buffer          = null;
25
	private double                  percent         = 0;
26
	private BufferCacheManagerImpl  manager         = null;
27
	
28
	/**
29
	 * Set the data to be interpolated
30
	 * @param buf
31
	 */
32
	public BufferInterpolationImpl(Buffer buf) {
33
		this.buffer = buf;
34
		manager = new BufferCacheManagerImpl();
35
	}
36
		
37
	/**
38
	 * Calcula los vectores de desplazamiento en pixels en X e Y cuando se supersamplea.
39
	 * @param r Array de desplazamientos para las filas. Debe tener espacio reservado
40
	 * @param c Array de desplazamientos para las columnas. Debe tener espacio reservado
41
	 * cargados.
42
	 */
43
	private void calcSupersamplingStepsArrays(int[] r, int[] c, double[] superSampStep) {
44
		double pos = superSampStep[1];
45
		for(int row = 0; row < r.length; row ++) {
46
			r[row] = (int)(pos / superSampStep[3]);
47
			pos ++;
48
		}
49
		pos = superSampStep[0];
50
		for(int col = 0; col < c.length; col ++) {
51
			c[col] = (int)(pos / superSampStep[2]);
52
			pos ++;
53
		}
54
	}
55
	
56
	/*
57
	 * (non-Javadoc)
58
	 * @see org.cachete.api.buffer.IBufferInterpolation#getSupersampledScrolledNearestNeighbour(double[], int, int)
59
	 */
60
	public Buffer getSupersampledScrolledNearestNeighbour(double[] superSampStep, int w, int h) throws ProcessInterruptedException {
61
		TaskEventManager task = new DefaultTaskEventManager(this);
62
		
63
		int[] rowStep = new int[h];
64
		int[] colStep = new int[w];
65
		calcSupersamplingStepsArrays(rowStep, colStep, superSampStep);
66
		
67
		BufferParamImpl param = new BufferParamImpl(w, h); 
68
		param.setDataType(buffer.getDataType()); 
69
		param.setBandCount(buffer.getBandCount());
70
		Buffer bufOut = manager.createBuffer(param);
71
		try {
72
			switch(param.getDataType()) {
73
			case RasterBuffer.TYPE_BYTE:
74
				for (int iBand = 0; iBand < buffer.getBandCount(); iBand++) {
75
					for (int row = 0; row < h; row++) {
76
						for (int col = 0; col < w; col++) {
77
							try {
78
								bufOut.setElem(row, col, iBand, buffer.getElemByte(rowStep[row], colStep[col], iBand));
79
							} catch (ArrayIndexOutOfBoundsException e) {/*System.out.println("->" + row + " " + col);*/break;}
80
						}
81
						if(task.getEvent() != null)
82
							task.manageEvent(task.getEvent());
83
					}
84
				}
85
				break;
86
			case RasterBuffer.TYPE_SHORT:
87
				for (int iBand = 0; iBand < buffer.getBandCount(); iBand++) {
88
					for (int row = 0; row < h; row++) {
89
						for (int col = 0; col < w; col++) {
90
							try {
91
								bufOut.setElem(row, col, iBand, buffer.getElemShort(rowStep[row], colStep[col], iBand));
92
							} catch (ArrayIndexOutOfBoundsException e) {/*System.out.println("->" + row + " " + col);*/break;}
93
						}
94
						if(task.getEvent() != null)
95
							task.manageEvent(task.getEvent());
96
					}
97
				}
98
				break;
99

  
100
			case RasterBuffer.TYPE_INT:
101
				for (int iBand = 0; iBand < buffer.getBandCount(); iBand++) {
102
					for (int row = 0; row < h; row++) {
103
						for (int col = 0; col < w; col++) {
104
							try {
105
								bufOut.setElem(row, col, iBand, buffer.getElemInt(rowStep[row], colStep[col], iBand));
106
							} catch (ArrayIndexOutOfBoundsException e) {/*System.out.println("->" + row + " " + col);*/break;}
107
						}
108
						if(task.getEvent() != null)
109
							task.manageEvent(task.getEvent());
110
					}
111
				}
112
				break;
113
			case RasterBuffer.TYPE_FLOAT:
114
				for (int iBand = 0; iBand < buffer.getBandCount(); iBand++) {
115
					for (int row = 0; row < h; row++) {
116
						for (int col = 0; col < w; col++) {
117
							try {
118
								bufOut.setElem(row, col, iBand, buffer.getElemFloat(rowStep[row], colStep[col], iBand));
119
							} catch (ArrayIndexOutOfBoundsException e) {/*System.out.println("->" + row + " " + col);*/break;}
120
						}
121
						if(task.getEvent() != null)
122
							task.manageEvent(task.getEvent());
123
					}
124
				}
125
				break;
126
			case RasterBuffer.TYPE_DOUBLE:
127
				for (int iBand = 0; iBand < buffer.getBandCount(); iBand++) {
128
					for (int row = 0; row < h; row++) {
129
						for (int col = 0; col < w; col++) {
130
							try {
131
								bufOut.setElem(row, col, iBand, buffer.getElemDouble(rowStep[row], colStep[col], iBand));
132
							} catch (ArrayIndexOutOfBoundsException e) {/*System.out.println("->" + row + " " + col);*/break;}
133
						}
134
						if(task.getEvent() != null)
135
							task.manageEvent(task.getEvent());
136
					}
137
				}
138
				break;
139
			}
140
		} catch (OperationNotSupportedException e) {
141
			//It is not possible because the RW buffer is created inside of this function 
142
		}
143
		return bufOut;
144
	}
145
	
146
	/*
147
	 * (non-Javadoc)
148
	 * @see org.cachete.api.buffer.IBufferInterpolation#getSupersampledScrolledBilinearInterpolation(double[], int, int)
149
	 */
150
	public Buffer getSupersampledScrolledBilinearInterpolation(double[] superSampStep, int w, int h) throws ProcessInterruptedException {
151
		TaskEventManager task = new DefaultTaskEventManager(this);
152

  
153
		int[] rowStep = new int[h];
154
		int[] colStep = new int[w];
155
		calcSupersamplingStepsArrays(rowStep, colStep, superSampStep);
156
		
157
		double pxSize = (double) buffer.getWidth() / (double) w;
158
		BufferParamImpl params = new BufferParamImpl(w, h);
159
		params.setDataType(buffer.getDataType());
160
		params.setBandCount(buffer.getBandCount());
161
		Buffer rasterBuf = manager.createBuffer(params);
162

  
163
		double posX = pxSize / 2D; // Empieza en el centro del primer pixel
164
		double posY = posX;
165
		double dx = 0D, dy = 0D;
166

  
167
		try {
168
			percent = 0;
169
			double multip = 100.0D / (h * buffer.getBandCount());
170

  
171
			for (int iBand = 0; iBand < buffer.getBandCount(); iBand++) {
172
				posY = pxSize / 2D;
173
				switch (buffer.getDataType()) {
174
				case RasterBuffer.TYPE_BYTE:
175
					for (int iRow = 0; iRow < h; iRow++) {
176
						dy = posY - ((int) posY);
177
						posX = pxSize / 2D;
178
						for (int iCol = 0; iCol < w; iCol++) {
179
							dx = posX - ((int) posX);
180
							try {
181
								double[] kernel = getKernelByte(((int) posX), ((int) posY), iBand);
182
								rasterBuf.setElem(iRow, iCol, iBand, (byte) ((byte) getBilinearValue(dx, dy, kernel) & 0xff));
183
							} catch (ArrayIndexOutOfBoundsException e) {
184
								// System.out.println(posX + " " + posY);
185
							}
186
							posX += pxSize;
187
						}
188
						posY += pxSize;
189
						percent = (iBand * h + iRow) * multip;
190
						if (task.getEvent() != null)
191
							task.manageEvent(task.getEvent());
192
					}
193
					break;
194
				case RasterBuffer.TYPE_SHORT:
195
					for (int iRow = 0; iRow < h; iRow++) {
196
						dy = posY - ((int) posY);
197
						posX = pxSize / 2D;
198
						for (int iCol = 0; iCol < w; iCol++) {
199
							dx = posX - ((int) posX);
200
							try {
201
								double[] kernel = getKernelShort(((int) posX), ((int) posY), iBand);
202
								rasterBuf.setElem(iRow, iCol, iBand, (short) ((short) getBilinearValue(dx, dy, kernel) & 0xffff));
203
							} catch (ArrayIndexOutOfBoundsException e) {
204
								// System.out.println(posX + " " + posY);
205
							}
206
							posX += pxSize;
207
						}
208
						posY += pxSize;
209
						percent = (iBand * h + iRow) * multip;
210
						if (task.getEvent() != null)
211
							task.manageEvent(task.getEvent());
212
					}
213
					break;
214
				case RasterBuffer.TYPE_INT:
215
					for (int iRow = 0; iRow < h; iRow++) {
216
						dy = posY - ((int) posY);
217
						posX = pxSize / 2D;
218
						for (int iCol = 0; iCol < w; iCol++) {
219
							dx = posX - ((int) posX);
220
							try {
221
								double[] kernel = getKernelInt(((int) posX), ((int) posY), iBand);
222
								rasterBuf.setElem(iRow, iCol, iBand, (int) ((int) getBilinearValue(dx, dy, kernel) & 0xff));
223
							} catch (ArrayIndexOutOfBoundsException e) {
224
								// System.out.println(posX + " " + posY);
225
							}
226
							posX += pxSize;
227
						}
228
						posY += pxSize;
229
						percent = (iBand * h + iRow) * multip;
230
						if (task.getEvent() != null)
231
							task.manageEvent(task.getEvent());
232
					}
233
					break;
234
				case RasterBuffer.TYPE_FLOAT:
235
					for (int iRow = 0; iRow < h; iRow++) {
236
						dy = posY - ((int) posY);
237
						posX = pxSize / 2D;
238
						for (int iCol = 0; iCol < w; iCol++) {
239
							dx = posX - ((int) posX);
240
							try {
241
								double[] kernel = getKernelInt(((int) posX), ((int) posY), iBand);
242
								rasterBuf.setElem(iRow, iCol, iBand, (float) getBilinearValue(dx, dy, kernel));
243
							} catch (ArrayIndexOutOfBoundsException e) {
244
								// System.out.println(posX + " " + posY);
245
							}
246
							posX += pxSize;
247
						}
248
						posY += pxSize;
249
						percent = (iBand * h + iRow) * multip;
250
						if (task.getEvent() != null)
251
							task.manageEvent(task.getEvent());
252
					}
253
					break;
254
				case RasterBuffer.TYPE_DOUBLE:
255
					for (int iRow = 0; iRow < h; iRow++) {
256
						dy = posY - ((int) posY);
257
						posX = pxSize / 2D;
258
						for (int iCol = 0; iCol < w; iCol++) {
259
							dx = posX - ((int) posX);
260
							try {
261
								double[] kernel = getKernelInt(((int) posX), ((int) posY), iBand);
262
								rasterBuf.setElem(iRow, iCol, iBand, (double) getBilinearValue(dx, dy, kernel));
263
							} catch (ArrayIndexOutOfBoundsException e) {
264
								// System.out.println(posX + " " + posY);
265
							}
266
							posX += pxSize;
267
						}
268
						posY += pxSize;
269
						percent = (iBand * h + iRow) * multip;
270
						if (task.getEvent() != null)
271
							task.manageEvent(task.getEvent());
272
					}
273
					break;
274
				}
275
			}
276
		} catch (OperationNotSupportedException e) {
277
			//This exception is only possible with a read only buffer
278
		}
279
		return rasterBuf;
280
	}
281

  
282
	
283
	/*
284
	 * (non-Javadoc)
285
	 * @see org.cachete.api.buffer.IBufferInterpolation#adjustRasterNearestNeighbourInterpolation(int, int)
286
	 */
287
	public Buffer adjustRasterNearestNeighbourInterpolation(int w, int h) throws ProcessInterruptedException {
288
		TaskEventManager task = new DefaultTaskEventManager(this);
289

  
290
		double stepX = (double) w / (double) buffer.getWidth();
291
		double stepY = (double) h / (double) buffer.getHeight();
292
		BufferParamImpl params = new BufferParamImpl(w, h);
293
		params.setDataType(buffer.getDataType());
294
		params.setBandCount(buffer.getBandCount());
295
		Buffer rasterBuf = manager.createBuffer(params);
296

  
297
		try {
298
			int[] bands = new int[rasterBuf.getBandCount()];
299
			for (int iBand = 0; iBand < rasterBuf.getBandCount(); iBand++)
300
				bands[iBand] = iBand;
301

  
302
			percent = 0;
303
			double multip = 100.0D / (buffer.getHeight() * bands.length);
304
			switch (buffer.getDataType()) {
305
			case RasterBuffer.TYPE_BYTE:
306
				for (int iBand = 0; iBand < bands.length; iBand++) {
307
					if (w <= buffer.getWidth()) { // submuestreo
308
						for (int iRow = 0; iRow < buffer.getHeight(); iRow++) {
309
							for (int iCol = 0; iCol < buffer.getWidth(); iCol++)
310
								rasterBuf.setElem((int) (iRow * stepY), (int) (iCol * stepX), bands[iBand], buffer.getElemByte(iRow, iCol, iBand));
311
							percent = (iBand * buffer.getHeight() + iRow) * multip;
312
							if (task.getEvent() != null)
313
								task.manageEvent(task.getEvent());
314
						}
315
					} else { // supermuestreo
316
						for (int iRow = 0; iRow < h; iRow++) {
317
							for (int iCol = 0; iCol < w; iCol++)
318
								rasterBuf.setElem(iRow, iCol, bands[iBand], buffer.getElemByte((int) (iRow / stepY), (int) (iCol / stepX), iBand));
319
							percent = (iBand * buffer.getHeight() + iRow) * multip;
320
							if (task.getEvent() != null)
321
								task.manageEvent(task.getEvent());
322
						}
323
					}
324
				}
325
				break;
326
			case RasterBuffer.TYPE_DOUBLE:
327
				for (int iBand = 0; iBand < bands.length; iBand++) {
328
					if (w <= buffer.getWidth()) { // submuestreo
329
						for (int iRow = 0; iRow < buffer.getHeight(); iRow++) {
330
							for (int iCol = 0; iCol < buffer.getWidth(); iCol++)
331
								rasterBuf.setElem((int) (iRow * stepY), (int) (iCol * stepX), bands[iBand], buffer.getElemDouble(iRow, iCol, iBand));
332
							percent = (iBand * buffer.getHeight() + iRow) * multip;
333
							if (task.getEvent() != null)
334
								task.manageEvent(task.getEvent());
335
						}
336
					} else { // supermuestreo
337
						for (int iRow = 0; iRow < h; iRow++) {
338
							for (int iCol = 0; iCol < w; iCol++)
339
								rasterBuf.setElem(iRow, iCol, bands[iBand], buffer.getElemDouble((int) (iRow / stepY), (int) (iCol / stepX), iBand));
340
							percent = (iBand * buffer.getHeight() + iRow) * multip;
341
							if (task.getEvent() != null)
342
								task.manageEvent(task.getEvent());
343
						}
344
					}
345
				}
346
				break;
347
			case RasterBuffer.TYPE_FLOAT:
348
				for (int iBand = 0; iBand < bands.length; iBand++) {
349
					if (w <= buffer.getWidth()) { // submuestreo
350
						for (int iRow = 0; iRow < buffer.getHeight(); iRow++) {
351
							for (int iCol = 0; iCol < buffer.getWidth(); iCol++)
352
								rasterBuf.setElem((int) (iRow * stepY), (int) (iCol * stepX), bands[iBand], buffer.getElemFloat(iRow, iCol, iBand));
353
							percent = (iBand * buffer.getHeight() + iRow) * multip;
354
							if (task.getEvent() != null)
355
								task.manageEvent(task.getEvent());
356
						}
357
					} else { // supermuestreo
358
						for (int iRow = 0; iRow < h; iRow++) {
359
							for (int iCol = 0; iCol < w; iCol++)
360
								rasterBuf.setElem(iRow, iCol, bands[iBand], buffer.getElemFloat((int) (iRow / stepY), (int) (iCol / stepX), iBand));
361
							percent = (iBand * buffer.getHeight() + iRow) * multip;
362
							if (task.getEvent() != null)
363
								task.manageEvent(task.getEvent());
364
						}
365
					}
366
				}
367
				break;
368
			case RasterBuffer.TYPE_INT:
369
				for (int iBand = 0; iBand < bands.length; iBand++) {
370
					if (w <= buffer.getWidth()) { // submuestreo
371
						for (int iRow = 0; iRow < buffer.getHeight(); iRow++) {
372
							for (int iCol = 0; iCol < buffer.getWidth(); iCol++)
373
								rasterBuf.setElem((int) (iRow * stepY), (int) (iCol * stepX), bands[iBand], buffer.getElemInt(iRow, iCol, iBand));
374
							percent = (iBand * buffer.getHeight() + iRow) * multip;
375
							if (task.getEvent() != null)
376
								task.manageEvent(task.getEvent());
377
						}
378
					} else { // supermuestreo
379
						for (int iRow = 0; iRow < h; iRow++) {
380
							for (int iCol = 0; iCol < w; iCol++)
381
								rasterBuf.setElem(iRow, iCol, bands[iBand], buffer.getElemInt((int) (iRow / stepY), (int) (iCol / stepX), iBand));
382
							percent = (iBand * buffer.getHeight() + iRow) * multip;
383
							if (task.getEvent() != null)
384
								task.manageEvent(task.getEvent());
385
						}
386
					}
387
				}
388
				break;
389
			case RasterBuffer.TYPE_USHORT:
390
			case RasterBuffer.TYPE_SHORT:
391
				for (int iBand = 0; iBand < bands.length; iBand++) {
392
					if (w <= buffer.getWidth()) { // submuestreo
393
						for (int iRow = 0; iRow < buffer.getHeight(); iRow++) {
394
							for (int iCol = 0; iCol < buffer.getWidth(); iCol++)
395
								rasterBuf.setElem((int) (iRow * stepY), (int) (iCol * stepX), bands[iBand], buffer.getElemShort(iRow, iCol, iBand));
396
							percent = (iBand * buffer.getHeight() + iRow) * multip;
397
							if (task.getEvent() != null)
398
								task.manageEvent(task.getEvent());
399
						}
400
					} else { // supermuestreo
401
						for (int iRow = 0; iRow < h; iRow++) {
402
							for (int iCol = 0; iCol < w; iCol++)
403
								rasterBuf.setElem(iRow, iCol, bands[iBand], buffer.getElemShort((int) (iRow / stepY), (int) (iCol / stepX), iBand));
404
							percent = (iBand * buffer.getHeight() + iRow) * multip;
405
							if (task.getEvent() != null)
406
								task.manageEvent(task.getEvent());
407
						}
408
					}
409
				}
410
				break;
411
			}
412
		} catch (OperationNotSupportedException e) {
413
			//This exception is only possible with a read only buffer
414
		}
415
		return rasterBuf; 
416
	}
417

  
418
	/*
419
	 * (non-Javadoc)
420
	 * @see org.cachete.api.buffer.IBufferInterpolation#adjustRasterBilinearInterpolation(int, int)
421
	 */
422
	public Buffer adjustRasterBilinearInterpolation(int w, int h) throws ProcessInterruptedException {
423
		TaskEventManager task = new DefaultTaskEventManager(this);//BufferCacheLocator.getManager().getTask();
424

  
425
		double pxSize = (double) buffer.getWidth() / (double) w;
426
		BufferParamImpl params = new BufferParamImpl(w, h);
427
		params.setDataType(buffer.getDataType());
428
		params.setBandCount(buffer.getBandCount());
429
		Buffer rasterBuf = manager.createBuffer(params);
430

  
431
		double posX = pxSize / 2D; // Empieza en el centro del primer pixel
432
		double posY = posX;
433
		double dx = 0D, dy = 0D;
434

  
435
		try {
436
			percent = 0;
437
			double multip = 100.0D / (h * buffer.getBandCount());
438

  
439
			for (int iBand = 0; iBand < buffer.getBandCount(); iBand++) {
440
				posY = pxSize / 2D;
441
				switch (buffer.getDataType()) {
442
				case RasterBuffer.TYPE_BYTE:
443
					for (int iRow = 0; iRow < h; iRow++) {
444
						dy = posY - ((int) posY);
445
						posX = pxSize / 2D;
446
						for (int iCol = 0; iCol < w; iCol++) {
447
							dx = posX - ((int) posX);
448
							try {
449
								double[] kernel = getKernelByte(((int) posX), ((int) posY), iBand);
450
								rasterBuf.setElem(iRow, iCol, iBand, (byte) ((byte) getBilinearValue(dx, dy, kernel) & 0xff));
451
							} catch (ArrayIndexOutOfBoundsException e) {
452
								// System.out.println(posX + " " + posY);
453
							}
454
							posX += pxSize;
455
						}
456
						posY += pxSize;
457
						percent = (iBand * h + iRow) * multip;
458
						if (task.getEvent() != null)
459
							task.manageEvent(task.getEvent());
460
					}
461
					break;
462
				case RasterBuffer.TYPE_SHORT:
463
					for (int iRow = 0; iRow < h; iRow++) {
464
						dy = posY - ((int) posY);
465
						posX = pxSize / 2D;
466
						for (int iCol = 0; iCol < w; iCol++) {
467
							dx = posX - ((int) posX);
468
							try {
469
								double[] kernel = getKernelShort(((int) posX), ((int) posY), iBand);
470
								rasterBuf.setElem(iRow, iCol, iBand, (short) ((short) getBilinearValue(dx, dy, kernel) & 0xffff));
471
							} catch (ArrayIndexOutOfBoundsException e) {
472
								// System.out.println(posX + " " + posY);
473
							}
474
							posX += pxSize;
475
						}
476
						posY += pxSize;
477
						percent = (iBand * h + iRow) * multip;
478
						if (task.getEvent() != null)
479
							task.manageEvent(task.getEvent());
480
					}
481
					break;
482
				case RasterBuffer.TYPE_INT:
483
					for (int iRow = 0; iRow < h; iRow++) {
484
						dy = posY - ((int) posY);
485
						posX = pxSize / 2D;
486
						for (int iCol = 0; iCol < w; iCol++) {
487
							dx = posX - ((int) posX);
488
							try {
489
								double[] kernel = getKernelInt(((int) posX), ((int) posY), iBand);
490
								rasterBuf.setElem(iRow, iCol, iBand, (int) ((int) getBilinearValue(dx, dy, kernel) & 0xff));
491
							} catch (ArrayIndexOutOfBoundsException e) {
492
								// System.out.println(posX + " " + posY);
493
							}
494
							posX += pxSize;
495
						}
496
						posY += pxSize;
497
						percent = (iBand * h + iRow) * multip;
498
						if (task.getEvent() != null)
499
							task.manageEvent(task.getEvent());
500
					}
501
					break;
502
				case RasterBuffer.TYPE_FLOAT:
503
					for (int iRow = 0; iRow < h; iRow++) {
504
						dy = posY - ((int) posY);
505
						posX = pxSize / 2D;
506
						for (int iCol = 0; iCol < w; iCol++) {
507
							dx = posX - ((int) posX);
508
							try {
509
								double[] kernel = getKernelInt(((int) posX), ((int) posY), iBand);
510
								rasterBuf.setElem(iRow, iCol, iBand, (float) getBilinearValue(dx, dy, kernel));
511
							} catch (ArrayIndexOutOfBoundsException e) {
512
								// System.out.println(posX + " " + posY);
513
							}
514
							posX += pxSize;
515
						}
516
						posY += pxSize;
517
						percent = (iBand * h + iRow) * multip;
518
						if (task.getEvent() != null)
519
							task.manageEvent(task.getEvent());
520
					}
521
					break;
522
				case RasterBuffer.TYPE_DOUBLE:
523
					for (int iRow = 0; iRow < h; iRow++) {
524
						dy = posY - ((int) posY);
525
						posX = pxSize / 2D;
526
						for (int iCol = 0; iCol < w; iCol++) {
527
							dx = posX - ((int) posX);
528
							try {
529
								double[] kernel = getKernelInt(((int) posX), ((int) posY), iBand);
530
								rasterBuf.setElem(iRow, iCol, iBand, (double) getBilinearValue(dx, dy, kernel));
531
							} catch (ArrayIndexOutOfBoundsException e) {
532
								// System.out.println(posX + " " + posY);
533
							}
534
							posX += pxSize;
535
						}
536
						posY += pxSize;
537
						percent = (iBand * h + iRow) * multip;
538
						if (task.getEvent() != null)
539
							task.manageEvent(task.getEvent());
540
					}
541
					break;
542
				}
543
			}
544
		} catch (OperationNotSupportedException e) {
545
			//This exception is only possible with a read only buffer
546
		}
547
		return rasterBuf;
548
	}
549

  
550
	/*
551
	 * (non-Javadoc)
552
	 * @see org.cachete.api.buffer.IBufferInterpolation#adjustRasterInverseDistanceInterpolation(int, int)
553
	 */
554
	public Buffer adjustRasterInverseDistanceInterpolation(int w, int h) throws ProcessInterruptedException {
555
		TaskEventManager task = new DefaultTaskEventManager(this);
556

  
557
		double pxSize = (double) buffer.getWidth() / (double) w;
558
		BufferParamImpl params = new BufferParamImpl(w, h);
559
		params.setDataType(buffer.getDataType());
560
		params.setBandCount(buffer.getBandCount());
561
		Buffer rasterBuf = manager.createBuffer(params);
562

  
563
		double posX = pxSize / 2D;
564
		double posY = posX;
565
		double dx = 0D, dy = 0D;
566

  
567
		try {
568
			percent = 0;
569
			double multip = 100.0D / (h * buffer.getBandCount());
570

  
571
			for (int iBand = 0; iBand < buffer.getBandCount(); iBand++) {
572
				posY = pxSize / 2D;
573
				switch (buffer.getDataType()) {
574
				case RasterBuffer.TYPE_BYTE:
575
					for (int iRow = 0; iRow < h; iRow++) {
576
						dy = posY - ((int) posY);
577
						posX = pxSize / 2D;
578
						for (int iCol = 0; iCol < w; iCol++) {
579
							dx = posX - ((int) posX);
580
							try {
581
								double[] kernel = getKernelByte(((int) posX), ((int) posY), iBand);
582
								rasterBuf.setElem(iRow, iCol, iBand, (byte) ((byte) getInverseDistanceValue(dx, dy, kernel) & 0xff));
583
							} catch (ArrayIndexOutOfBoundsException e) {
584
								// System.out.println(posX + " " + posY);
585
							}
586
							posX += pxSize;
587
						}
588
						posY += pxSize;
589
						percent = (iBand * h + iRow) * multip;
590
						if (task.getEvent() != null)
591
							task.manageEvent(task.getEvent());
592
					}
593
					break;
594
				case RasterBuffer.TYPE_SHORT:
595
					for (int iRow = 0; iRow < h; iRow++) {
596
						dy = posY - ((int) posY);
597
						posX = pxSize / 2D;
598
						for (int iCol = 0; iCol < w; iCol++) {
599
							dx = posX - ((int) posX);
600
							try {
601
								double[] kernel = getKernelShort(((int) posX), ((int) posY), iBand);
602
								rasterBuf.setElem(iRow, iCol, iBand, (short) ((short) getInverseDistanceValue(dx, dy, kernel) & 0xffff));
603
							} catch (ArrayIndexOutOfBoundsException e) {
604
								// System.out.println(posX + " " + posY);
605
							}
606
							posX += pxSize;
607
						}
608
						posY += pxSize;
609
						percent = (iBand * h + iRow) * multip;
610
						if (task.getEvent() != null)
611
							task.manageEvent(task.getEvent());
612
					}
613
					break;
614
				case RasterBuffer.TYPE_INT:
615
					for (int iRow = 0; iRow < h; iRow++) {
616
						dy = posY - ((int) posY);
617
						posX = pxSize / 2D;
618
						for (int iCol = 0; iCol < w; iCol++) {
619
							dx = posX - ((int) posX);
620
							try {
621
								double[] kernel = getKernelInt(((int) posX), ((int) posY), iBand);
622
								rasterBuf.setElem(iRow, iCol, iBand, (int) ((int) getInverseDistanceValue(dx, dy, kernel) & 0xff));
623
							} catch (ArrayIndexOutOfBoundsException e) {
624
								// System.out.println(posX + " " + posY);
625
							}
626
							posX += pxSize;
627
						}
628
						posY += pxSize;
629
						percent = (iBand * h + iRow) * multip;
630
						if (task.getEvent() != null)
631
							task.manageEvent(task.getEvent());
632
					}
633
					break;
634
				case RasterBuffer.TYPE_FLOAT:
635
					for (int iRow = 0; iRow < h; iRow++) {
636
						dy = posY - ((int) posY);
637
						posX = pxSize / 2D;
638
						for (int iCol = 0; iCol < w; iCol++) {
639
							dx = posX - ((int) posX);
640
							try {
641
								double[] kernel = getKernelFloat(((int) posX), ((int) posY), iBand);
642
								rasterBuf.setElem(iRow, iCol, iBand, (float) getInverseDistanceValue(dx, dy, kernel));
643
							} catch (ArrayIndexOutOfBoundsException e) {
644
								// System.out.println(posX + " " + posY);
645
							}
646
							posX += pxSize;
647
						}
648
						posY += pxSize;
649
						percent = (iBand * h + iRow) * multip;
650
						if (task.getEvent() != null)
651
							task.manageEvent(task.getEvent());
652
					}
653
					break;
654
				case RasterBuffer.TYPE_DOUBLE:
655
					for (int iRow = 0; iRow < h; iRow++) {
656
						dy = posY - ((int) posY);
657
						posX = pxSize / 2D;
658
						for (int iCol = 0; iCol < w; iCol++) {
659
							dx = posX - ((int) posX);
660
							try {
661
								double[] kernel = getKernelDouble(((int) posX), ((int) posY), iBand);
662
								rasterBuf.setElem(iRow, iCol, iBand, (double) getInverseDistanceValue(dx, dy, kernel));
663
							} catch (ArrayIndexOutOfBoundsException e) {
664
								// System.out.println(posX + " " + posY);
665
							}
666
							posX += pxSize;
667
						}
668
						posY += pxSize;
669
						percent = (iBand * h + iRow) * multip;
670
						if (task.getEvent() != null)
671
							task.manageEvent(task.getEvent());
672
					}
673
					break;
674
				}
675
			}
676
		} catch (OperationNotSupportedException e) {
677
			//This exception is only possible with a read only buffer
678
		}
679
		return rasterBuf;
680
	}
681

  
682
	/*
683
	 * (non-Javadoc)
684
	 * @see org.cachete.api.buffer.IBufferInterpolation#adjustRasterBSplineInterpolation(int, int)
685
	 */
686
	public Buffer adjustRasterBSplineInterpolation(int w, int h) throws ProcessInterruptedException {
687
		TaskEventManager task = new DefaultTaskEventManager(this);
688

  
689
		double pxSize = (double) buffer.getWidth() / (double) w;
690
		BufferParamImpl params = new BufferParamImpl(w, h);
691
		params.setDataType(buffer.getDataType());
692
		params.setBandCount(buffer.getBandCount());
693
		Buffer rasterBuf = manager.createBuffer(params);
694

  
695
		double posX = pxSize / 2D;
696
		double posY = posX;
697
		double dx = 0D, dy = 0D;
698

  
699
		try {
700
			percent = 0;
701
			double multip = 100.0D / (h * buffer.getBandCount());
702

  
703
			for (int iBand = 0; iBand < buffer.getBandCount(); iBand++) {
704
				posY = pxSize / 2D;
705
				switch (buffer.getDataType()) {
706
				case RasterBuffer.TYPE_BYTE:
707
					for (int iRow = 0; iRow < h; iRow++) {
708
						dy = posY - ((int) posY);
709
						posX = pxSize / 2D;
710
						for (int iCol = 0; iCol < w; iCol++) {
711
							dx = posX - ((int) posX);
712
							try {
713
								double[][] kernel = get4x4Submatrix(((int) posX), ((int) posY), iBand);
714
								if (kernel == null) {
715
									double[] k = getKernelByte(((int) posX), ((int) posY), iBand);
716
									rasterBuf.setElem(iRow, iCol, iBand, (byte) ((byte) getBilinearValue(dx, dy, k) & 0xff));
717
								} else
718
									rasterBuf.setElem(iRow, iCol, iBand, (byte) ((byte) getBSplineValue(dx, dy, kernel) & 0xff));
719
							} catch (ArrayIndexOutOfBoundsException e) {
720
								// System.out.println(posX + " " + posY);
721
							}
722
							posX += pxSize;
723
						}
724
						posY += pxSize;
725
						percent = (iBand * h + iRow) * multip;
726
						if (task.getEvent() != null)
727
							task.manageEvent(task.getEvent());
728
					}
729
					break;
730
				case RasterBuffer.TYPE_SHORT:
731
					for (int iRow = 0; iRow < h; iRow++) {
732
						dy = posY - ((int) posY);
733
						posX = pxSize / 2D;
734
						for (int iCol = 0; iCol < w; iCol++) {
735
							dx = posX - ((int) posX);
736
							try {
737
								double[][] kernel = get4x4Submatrix(((int) posX), ((int) posY), iBand);
738
								if (kernel == null) {
739
									double[] k = getKernelShort(((int) posX), ((int) posY), iBand);
740
									rasterBuf.setElem(iRow, iCol, iBand, (short) ((short) getBilinearValue(dx, dy, k) & 0xffff));
741
								} else
742
									rasterBuf.setElem(iRow, iCol, iBand, (short) ((short) getBSplineValue(dx, dy, kernel) & 0xffff));
743
							} catch (ArrayIndexOutOfBoundsException e) {
744
								// System.out.println(posX + " " + posY);
745
							}
746
							posX += pxSize;
747
						}
748
						posY += pxSize;
749
						percent = (iBand * h + iRow) * multip;
750
						if (task.getEvent() != null)
751
							task.manageEvent(task.getEvent());
752
					}
753
					break;
754
				case RasterBuffer.TYPE_INT:
755
					for (int iRow = 0; iRow < h; iRow++) {
756
						dy = posY - ((int) posY);
757
						posX = pxSize / 2D;
758
						for (int iCol = 0; iCol < w; iCol++) {
759
							dx = posX - ((int) posX);
760
							try {
761
								double[][] kernel = get4x4Submatrix(((int) posX), ((int) posY), iBand);
762
								if (kernel == null) {
763
									double[] k = getKernelInt(((int) posX), ((int) posY), iBand);
764
									rasterBuf.setElem(iRow, iCol, iBand, (int) ((int) getBilinearValue(dx, dy, k) & 0xffffffff));
765
								} else
766
									rasterBuf.setElem(iRow, iCol, iBand, (int) ((int) getBSplineValue(dx, dy, kernel) & 0xffffffff));
767
							} catch (ArrayIndexOutOfBoundsException e) {
768
								// System.out.println(posX + " " + posY);
769
							}
770
							posX += pxSize;
771
						}
772
						posY += pxSize;
773
						percent = (iBand * h + iRow) * multip;
774
						if (task.getEvent() != null)
775
							task.manageEvent(task.getEvent());
776
					}
777
					break;
778
				case RasterBuffer.TYPE_FLOAT:
779
					for (int iRow = 0; iRow < h; iRow++) {
780
						dy = posY - ((int) posY);
781
						posX = pxSize / 2D;
782
						for (int iCol = 0; iCol < w; iCol++) {
783
							dx = posX - ((int) posX);
784
							try {
785
								double[][] kernel = get4x4Submatrix(((int) posX), ((int) posY), iBand);
786
								if (kernel == null) {
787
									double[] k = getKernelFloat(((int) posX), ((int) posY), iBand);
788
									rasterBuf.setElem(iRow, iCol, iBand, (float) getBilinearValue(dx, dy, k));
789
								} else
790
									rasterBuf.setElem(iRow, iCol, iBand, (float) getBSplineValue(dx, dy, kernel));
791
							} catch (ArrayIndexOutOfBoundsException e) {
792
								// System.out.println(posX + " " + posY);
793
							}
794
							posX += pxSize;
795
						}
796
						posY += pxSize;
797
						percent = (iBand * h + iRow) * multip;
798
						if (task.getEvent() != null)
799
							task.manageEvent(task.getEvent());
800
					}
801
					break;
802
				case RasterBuffer.TYPE_DOUBLE:
803
					for (int iRow = 0; iRow < h; iRow++) {
804
						dy = posY - ((int) posY);
805
						posX = pxSize / 2D;
806
						for (int iCol = 0; iCol < w; iCol++) {
807
							dx = posX - ((int) posX);
808
							try {
809
								double[][] kernel = get4x4Submatrix(((int) posX), ((int) posY), iBand);
810
								if (kernel == null) {
811
									double[] k = getKernelDouble(((int) posX), ((int) posY), iBand);
812
									rasterBuf.setElem(iRow, iCol, iBand, (double) getBilinearValue(dx, dy, k));
813
								} else
814
									rasterBuf.setElem(iRow, iCol, iBand, (double) getBSplineValue(dx, dy, kernel));
815
							} catch (ArrayIndexOutOfBoundsException e) {
816
								// System.out.println(posX + " " + posY);
817
							}
818
							posX += pxSize;
819
						}
820
						posY += pxSize;
821
						percent = (iBand * h + iRow) * multip;
822
						if (task.getEvent() != null)
823
							task.manageEvent(task.getEvent());
824
					}
825
					break;
826
				}
827
			}
828
		} catch (OperationNotSupportedException e) {
829
			//This exception is only possible with a read only buffer
830
		}
831
		return rasterBuf;
832
	}
833

  
834
	/*
835
	 * (non-Javadoc)
836
	 * @see org.cachete.api.buffer.IBufferInterpolation#adjustRasterBicubicSplineInterpolation(int, int)
837
	 */
838
	public Buffer adjustRasterBicubicSplineInterpolation(int w, int h) throws ProcessInterruptedException {
839
		TaskEventManager task = new DefaultTaskEventManager(this);
840

  
841
		double pxSize = (double) buffer.getWidth() / (double) w;
842
		BufferParamImpl params = new BufferParamImpl(w, h);
843
		params.setDataType(buffer.getDataType());
844
		params.setBandCount(buffer.getBandCount());
845
		Buffer rasterBuf = manager.createBuffer(params);
846

  
847
		double posX = pxSize / 2D;
848
		double posY = posX;
849
		double dx = 0D, dy = 0D;
850

  
851
		try {
852
			percent = 0;
853
			double multip = 100.0D / (h * buffer.getBandCount());
854

  
855
			for (int iBand = 0; iBand < buffer.getBandCount(); iBand++) {
856
				posY = pxSize / 2D;
857
				switch (buffer.getDataType()) {
858
				case RasterBuffer.TYPE_BYTE:
859
					for (int iRow = 0; iRow < h; iRow++) {
860
						dy = posY - ((int) posY);
861
						posX = pxSize / 2D;
862
						for (int iCol = 0; iCol < w; iCol++) {
863
							dx = posX - ((int) posX);
864
							try {
865
								double[][] kernel = get4x4Submatrix(((int) posX), ((int) posY), iBand);
866
								if (kernel == null) {
867
									double[] k = getKernelByte(((int) posX), ((int) posY), iBand);
868
									rasterBuf.setElem(iRow, iCol, iBand, (byte) ((byte) getBilinearValue(dx, dy, k) & 0xff));
869
								} else
870
									rasterBuf.setElem(iRow, iCol, iBand, (byte) ((byte) getBicubicSplineValue(dx, dy, kernel)));
871
							} catch (ArrayIndexOutOfBoundsException e) {
872
								// System.out.println(posX + " " + posY);
873
							}
874
							posX += pxSize;
875
						}
876
						posY += pxSize;
877
						percent = (iBand * h + iRow) * multip;
878
						if (task.getEvent() != null)
879
							task.manageEvent(task.getEvent());
880
					}
881
					break;
882
				case RasterBuffer.TYPE_SHORT:
883
					for (int iRow = 0; iRow < h; iRow++) {
884
						dy = posY - ((int) posY);
885
						posX = pxSize / 2D;
886
						for (int iCol = 0; iCol < w; iCol++) {
887
							dx = posX - ((int) posX);
888
							try {
889
								double[][] kernel = get4x4Submatrix(((int) posX), ((int) posY), iBand);
890
								if (kernel == null) {
891
									double[] k = getKernelShort(((int) posX), ((int) posY), iBand);
892
									rasterBuf.setElem(iRow, iCol, iBand, (short) ((short) getBilinearValue(dx, dy, k) & 0xffff));
893
								} else
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff