Revision 2644

View differences:

org.gvsig.raster.cache/tags/v2.2.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/v2.2.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.2.0</version>
10
    <scm>
11
        <connection>scm:svn:https://devel.gvsig.org/svn/gvsig-raster/org.gvsig.raster.cache/tags/v2.2.0</connection>
12
        <developerConnection>scm:svn:https://devel.gvsig.org/svn/gvsig-raster/org.gvsig.raster.cache/tags/v2.2.0</developerConnection>
13
        <url>https://devel.gvsig.org/redmine/projects/gvsig-raster/repository/show/org.gvsig.raster.cache/tags/v2.2.0</url>
14
    </scm>
15
    
16
    <repositories>
17
      <repository>
18
        <id>gvsig-public-http-repository</id>
19
        <name>gvSIG maven public HTTP repository</name>
20
        <url>http://devel.gvsig.org/m2repo/j2se</url>
21
        <releases>
22
          <enabled>true</enabled>
23
          <updatePolicy>daily</updatePolicy>
24
          <checksumPolicy>warn</checksumPolicy>
25
        </releases>
26
        <snapshots>
27
          <enabled>true</enabled>
28
          <updatePolicy>daily</updatePolicy>
29
          <checksumPolicy>warn</checksumPolicy>
30
        </snapshots>
31
      </repository>
32
    </repositories>
33
    
34
    <parent>
35
      <groupId>org.gvsig</groupId>
36
      <artifactId>org.gvsig.desktop</artifactId>
37
      <version>2.0.25</version>
38
    </parent>
39
    <developers>
40
        <developer>
41
            <id>nbrodin</id>
42
            <name>Nacho Brodin</name>
43
            <email>nachobrodin@gmail.com</email>
44
            <roles>
45
                <role>Architect</role>
46
                <role>Developer</role>
47
            </roles>
48
        </developer>
49
    </developers>
50
     <dependencyManagement>
51
        <dependencies>
52
	        <!--<dependency>
53
				<groupId>org.gvsig</groupId>
54
				<artifactId>org.gvsig.jgdal</artifactId>
55
				<version>2.0.4-SNAPSHOT</version>
56
			</dependency>
57
	        <dependency>
58
	            <groupId>org.gvsig</groupId>
59
	            <artifactId>org.gvsig.jgdal</artifactId>
60
	            <version>2.0.4-SNAPSHOT</version>
61
	            <classifier>${native_classifier}</classifier>
62
	            <type>tar.gz</type>
63
	        </dependency>-->
64
		    <dependency>
65
				<groupId>org.gvsig</groupId>
66
				<artifactId>org.gvsig.raster.cache.lib.api</artifactId>
67
				<version>2.2.0</version>
68
			</dependency>
69
        </dependencies>
70
    </dependencyManagement>
71
    <dependencies>
72
        <dependency>
73
            <groupId>org.gvsig</groupId>
74
            <artifactId>org.gvsig.tools.lib</artifactId>
75
            <scope>compile</scope>
76
        </dependency>
77
    </dependencies>
78
    <build>
79
        <plugins>
80
            <plugin>
81
                <groupId>org.apache.maven.plugins</groupId>
82
                <artifactId>maven-release-plugin</artifactId>
83
                <configuration>
84
                    <tagBase>https://devel.gvsig.org/svn/gvsig-raster/org.gvsig.raster.cache/tags/</tagBase>
85
                    <goals>deploy</goals>
86
                </configuration>
87
            </plugin>
88
            <plugin>
89
				<groupId>org.apache.maven.plugins</groupId>
90
				<artifactId>maven-compiler-plugin</artifactId>
91
				<configuration>
92
					<source>1.5</source>
93
					<target>1.5</target>
94
				</configuration>
95
			</plugin>
96
			<plugin>
97
                <groupId>org.codehaus.mojo</groupId>
98
                <artifactId>animal-sniffer-maven-plugin</artifactId>
99
                <configuration>
100
                    <skip>true</skip>
101
                </configuration>
102
            </plugin>
103
        </plugins>
104
    </build>
105
    <modules>
106
        <module>org.gvsig.raster.cache.lib.api</module>
107
        <module>org.gvsig.raster.cache.lib.impl</module>
108
    </modules>
109
</project>
0 110

  
org.gvsig.raster.cache/tags/v2.2.0/org.gvsig.raster.cache.lib.impl/deprecated/buffer/test/impl/TestInterpolationBSplineIncrease.java
1
package org.gvsig.raster.cache.buffer.impl;
2

  
3
import java.io.IOException;
4

  
5
import junit.framework.TestCase;
6

  
7
import org.gvsig.jgdal.GdalException;
8
import org.gvsig.raster.cache.buffer.Buffer;
9
import org.gvsig.raster.cache.buffer.exception.OperationNotSupportedException;
10
import org.gvsig.raster.cache.buffer.exception.ProcessInterruptedException;
11
import org.gvsig.raster.cache.buffer.impl.io.GdalRead;
12
import org.gvsig.raster.cache.buffer.impl.io.GdalWrite;
13
import org.gvsig.raster.cache.buffer.impl.memory.RasterMemoryBuffer;
14

  
15
/**
16
 * Copy the band 0 from a buffer over the band 2 in the same buffer using the
17
 * method getBandCopy.  
18
 * @author Nacho Brodin (nachobrodin@gmail.com)
19
 */
20
public class TestInterpolationBSplineIncrease extends TestCase {
21
	private String         rasterIn  = "./src/test/resources/image/001m09_1_0.tif";
22
	private String         rasterOut = "/tmp/out-interpBSpline.tif";
23
	private static int     REL       = 2;
24
	
25
	public void start() {
26
		this.setUp();
27
		this.testStack();
28
	}
29

  
30
	public void setUp() {
31
		System.err.println("TestInterpolationBSpline running...");
32
	}
33
	
34
	public void testStack() {
35
		long t1 = System.currentTimeMillis();
36
		GdalRead input = null;
37
		GdalWrite out = null;
38
		try {
39
			//Read input data
40
			input = new GdalRead(rasterIn);
41
			int readSize = 10;
42
			Object dataIn = input.readBlock(0, 0, readSize, readSize);
43
			
44
			//Create Buffer
45
			Buffer buf1 = new RasterMemoryBuffer(input.getRasterBufTypeFromGdalType(input.getDataType()), 
46
														readSize, 
47
														readSize,
48
														input.getBandCount(),
49
														true);
50
			
51
			//Set data to buffer
52
			setLines(dataIn, buf1);
53
			Buffer buf = buf1.getAdjustedWindow(readSize * REL, readSize * REL, BufferInterpolationImpl.INTERPOLATION_BSpline);
54
						
55
			//Write output file 
56
			out = new GdalWrite(rasterOut, 3, input.getDataType(), buf.getWidth(), buf.getHeight(), GdalWrite.COLOR_INTERP_RGB);
57
			out.writeBands(buf.getBands());
58
			out.close();	
59
			
60
			buf1.free();
61
		} catch (GdalException e) {
62
			e.printStackTrace();
63
		} catch (IOException e) {
64
			e.printStackTrace();
65
		} catch (ProcessInterruptedException e) {
66
			e.printStackTrace();
67
		} catch (OperationNotSupportedException e) {
68
			e.printStackTrace();
69
		}
70
		long t2 = System.currentTimeMillis();
71
		System.out.println("Tiempo TestInterpolationBSpline: " + (t2 - t1) + " milisegundos");
72
	}
73
	
74
	private void setLines(Object dataIn, Buffer buf) throws OperationNotSupportedException {
75
		if(dataIn instanceof byte[][][]) {
76
    		byte[][][] d = (byte[][][])dataIn;
77
    		for (int iBand = 0; iBand < d.length; iBand++) {
78
				for (int row = 0; row < d[iBand].length; row++) {
79
					buf.setLineInBandByte(d[iBand][row], row, iBand);
80
				}
81
			}
82
    	}
83
	}
84
	
85
}
86

  
0 87

  
org.gvsig.raster.cache/tags/v2.2.0/org.gvsig.raster.cache.lib.impl/deprecated/buffer/test/impl/TestInterpolationBSplineReduction.java
1
package org.gvsig.raster.cache.buffer.impl;
2

  
3
import java.io.IOException;
4

  
5
import junit.framework.TestCase;
6

  
7
import org.gvsig.jgdal.GdalException;
8
import org.gvsig.raster.cache.buffer.Buffer;
9
import org.gvsig.raster.cache.buffer.exception.OperationNotSupportedException;
10
import org.gvsig.raster.cache.buffer.exception.ProcessInterruptedException;
11
import org.gvsig.raster.cache.buffer.impl.io.GdalRead;
12
import org.gvsig.raster.cache.buffer.impl.io.GdalWrite;
13
import org.gvsig.raster.cache.buffer.impl.memory.RasterMemoryBuffer;
14

  
15
/**
16
 * Copy the band 0 from a buffer over the band 2 in the same buffer using the
17
 * method getBandCopy.  
18
 * @author Nacho Brodin (nachobrodin@gmail.com)
19
 */
20
public class TestInterpolationBSplineReduction extends TestCase {
21
	private String         rasterIn  = "./src/test/resources/image/001m09_1_0.tif";
22
	private String         rasterOut = "/tmp/out-interpBSplineReduction.tif";
23
	private static int     REL       = 5;
24
	
25
	public void start() {
26
		this.setUp();
27
		this.testStack();
28
	}
29

  
30
	public void setUp() {
31
		System.err.println("TestInterpolationBSplineReduction running...");
32
	}
33
	
34
	public void testStack() {
35
		long t1 = System.currentTimeMillis();
36
		GdalRead input = null;
37
		GdalWrite out = null;
38
		try {
39
			//Read input data
40
			input = new GdalRead(rasterIn);
41
			Object dataIn = input.readBlock(0, 0, input.getWidth(), input.getHeight());
42
						
43
			//Create Buffer
44
			Buffer buf1 = new RasterMemoryBuffer(input.getRasterBufTypeFromGdalType(input.getDataType()), 
45
														input.getWidth(), 
46
														input.getHeight(),
47
														input.getBandCount(),
48
														true);
49
			
50
			//Set data to buffer
51
			setLines(dataIn, buf1);
52
			Buffer buf = buf1.getAdjustedWindow(input.getWidth() / REL, input.getHeight() / REL, BufferInterpolationImpl.INTERPOLATION_BSpline);
53
						
54
			//Write output file 
55
			out = new GdalWrite(rasterOut, 3, input.getDataType(), buf.getWidth(), buf.getHeight(), GdalWrite.COLOR_INTERP_RGB);
56
			out.writeBands(buf.getBands());
57
			out.close();	
58
			
59
			buf1.free();
60
		} catch (GdalException e) {
61
			e.printStackTrace();
62
		} catch (IOException e) {
63
			e.printStackTrace();
64
		} catch (ProcessInterruptedException e) {
65
			e.printStackTrace();
66
		} catch (OperationNotSupportedException e) {
67
			e.printStackTrace();
68
		}
69
		long t2 = System.currentTimeMillis();
70
		System.out.println("Tiempo TestInterpolationBSplineReduction: " + (t2 - t1) + " milisegundos");
71
	}
72
	
73
	private void setLines(Object dataIn, Buffer buf) throws OperationNotSupportedException {
74
		if(dataIn instanceof byte[][][]) {
75
    		byte[][][] d = (byte[][][])dataIn;
76
    		for (int iBand = 0; iBand < d.length; iBand++) {
77
				for (int row = 0; row < d[iBand].length; row++) {
78
					buf.setLineInBandByte(d[iBand][row], row, iBand);
79
				}
80
			}
81
    	}
82
	}
83
	
84
}
85

  
0 86

  
org.gvsig.raster.cache/tags/v2.2.0/org.gvsig.raster.cache.lib.impl/deprecated/buffer/test/impl/TestInterpolationBicubicIncrease.java
1
package org.gvsig.raster.cache.buffer.impl;
2

  
3
import java.io.IOException;
4

  
5
import junit.framework.TestCase;
6

  
7
import org.gvsig.jgdal.GdalException;
8
import org.gvsig.raster.cache.buffer.Buffer;
9
import org.gvsig.raster.cache.buffer.exception.OperationNotSupportedException;
10
import org.gvsig.raster.cache.buffer.exception.ProcessInterruptedException;
11
import org.gvsig.raster.cache.buffer.impl.io.GdalRead;
12
import org.gvsig.raster.cache.buffer.impl.io.GdalWrite;
13
import org.gvsig.raster.cache.buffer.impl.memory.RasterMemoryBuffer;
14

  
15
/**
16
 * Copy the band 0 from a buffer over the band 2 in the same buffer using the
17
 * method getBandCopy.  
18
 * @author Nacho Brodin (nachobrodin@gmail.com)
19
 */
20
public class TestInterpolationBicubicIncrease extends TestCase {
21
	private String         rasterIn  = "./src/test/resources/image/001m09_1_0.tif";
22
	private String         rasterOut = "/tmp/out-interpBicubic.tif";
23
	private static int     REL       = 2;
24
	
25
	public void start() {
26
		this.setUp();
27
		this.testStack();
28
	}
29

  
30
	public void setUp() {
31
		System.err.println("TestInterpolationBicubic running...");
32
	}
33
	
34
	public void testStack() {
35
		long t1 = System.currentTimeMillis();
36
		GdalRead input = null;
37
		GdalWrite out = null;
38
		try {
39
			//Read input data
40
			input = new GdalRead(rasterIn);
41
			int readSize = 10;
42
			Object dataIn = input.readBlock(0, 0, readSize, readSize);
43
			
44
			//Create Buffer
45
			Buffer buf1 = new RasterMemoryBuffer(input.getRasterBufTypeFromGdalType(input.getDataType()), 
46
														readSize, 
47
														readSize,
48
														input.getBandCount(),
49
														true);
50
			
51
			//Set data to buffer
52
			setLines(dataIn, buf1);
53
			Buffer buf = buf1.getAdjustedWindow(readSize * REL, readSize * REL, BufferInterpolationImpl.INTERPOLATION_Bicubic);
54
						
55
			//Write output file 
56
			out = new GdalWrite(rasterOut, 3, input.getDataType(), buf.getWidth(), buf.getHeight(), GdalWrite.COLOR_INTERP_RGB);
57
			out.writeBands(buf.getBands());
58
			out.close();	
59
			
60
			buf1.free();
61
		} catch (GdalException e) {
62
			e.printStackTrace();
63
		} catch (IOException e) {
64
			e.printStackTrace();
65
		} catch (ProcessInterruptedException e) {
66
			e.printStackTrace();
67
		} catch (OperationNotSupportedException e) {
68
			e.printStackTrace();
69
		}
70
		long t2 = System.currentTimeMillis();
71
		System.out.println("Tiempo TestInterpolationBicubic: " + (t2 - t1) + " milisegundos");
72
	}
73
	
74
	private void setLines(Object dataIn, Buffer buf) throws OperationNotSupportedException {
75
		if(dataIn instanceof byte[][][]) {
76
    		byte[][][] d = (byte[][][])dataIn;
77
    		for (int iBand = 0; iBand < d.length; iBand++) {
78
				for (int row = 0; row < d[iBand].length; row++) {
79
					buf.setLineInBandByte(d[iBand][row], row, iBand);
80
				}
81
			}
82
    	}
83
	}
84
	
85
}
86

  
0 87

  
org.gvsig.raster.cache/tags/v2.2.0/org.gvsig.raster.cache.lib.impl/deprecated/buffer/test/impl/TestInterpolationNearestIncrease.java
1
package org.gvsig.raster.cache.buffer.impl;
2

  
3
import java.io.IOException;
4

  
5
import junit.framework.TestCase;
6

  
7
import org.gvsig.jgdal.GdalException;
8
import org.gvsig.raster.cache.buffer.Buffer;
9
import org.gvsig.raster.cache.buffer.exception.OperationNotSupportedException;
10
import org.gvsig.raster.cache.buffer.exception.ProcessInterruptedException;
11
import org.gvsig.raster.cache.buffer.impl.io.GdalRead;
12
import org.gvsig.raster.cache.buffer.impl.io.GdalWrite;
13
import org.gvsig.raster.cache.buffer.impl.memory.RasterMemoryBuffer;
14

  
15
/**
16
 * Copy the band 0 from a buffer over the band 2 in the same buffer using the
17
 * method getBandCopy.  
18
 * @author Nacho Brodin (nachobrodin@gmail.com)
19
 */
20
public class TestInterpolationNearestIncrease extends TestCase {
21
	private String         rasterIn  = "./src/test/resources/image/001m09_1_0.tif";
22
	private String         rasterOut = "/tmp/out-interpNearest.tif";
23
	private static int     REL       = 2;
24
	
25
	public void start() {
26
		this.setUp();
27
		this.testStack();
28
	}
29

  
30
	public void setUp() {
31
		System.err.println("MemoryBuffer TestCopyBand running...");
32
	}
33
	
34
	public void testStack() {
35
		long t1 = System.currentTimeMillis();
36
		GdalRead input = null;
37
		GdalWrite out = null;
38
		try {
39
			//Read input data
40
			input = new GdalRead(rasterIn);
41
			int readSize = 10;
42
			Object dataIn = input.readBlock(0, 0, readSize, readSize);
43
						
44
			//Create Buffer
45
			Buffer buf1 = new RasterMemoryBuffer(input.getRasterBufTypeFromGdalType(input.getDataType()), 
46
														readSize, 
47
														readSize,
48
														input.getBandCount(),
49
														true);
50
			
51
			//Set data to buffer
52
			setLines(dataIn, buf1);
53
			Buffer buf = buf1.getAdjustedWindow(readSize * REL, readSize * REL, BufferInterpolationImpl.INTERPOLATION_NearestNeighbour);
54
						
55
			//Write output file 
56
			out = new GdalWrite(rasterOut, 3, input.getDataType(), buf.getWidth(), buf.getHeight(), GdalWrite.COLOR_INTERP_RGB);
57
			out.writeBands(buf.getBands());
58
			out.close();	
59
			
60
			buf1.free();
61
		} catch (GdalException e) {
62
			e.printStackTrace();
63
		} catch (IOException e) {
64
			e.printStackTrace();
65
		} catch (ProcessInterruptedException e) {
66
			e.printStackTrace();
67
		} catch (OperationNotSupportedException e) {
68
			e.printStackTrace();
69
		}
70
		long t2 = System.currentTimeMillis();
71
		System.out.println("Tiempo MemoryBuffer TestCopyBand: " + (t2 - t1) + " milisegundos");
72
	}
73
	
74
	private void setLines(Object dataIn, Buffer buf) throws OperationNotSupportedException {
75
		if(dataIn instanceof byte[][][]) {
76
    		byte[][][] d = (byte[][][])dataIn;
77
    		for (int iBand = 0; iBand < d.length; iBand++) {
78
				for (int row = 0; row < d[iBand].length; row++) {
79
					buf.setLineInBandByte(d[iBand][row], row, iBand);
80
				}
81
			}
82
    	}
83
	}
84
	
85
}
86

  
0 87

  
org.gvsig.raster.cache/tags/v2.2.0/org.gvsig.raster.cache.lib.impl/deprecated/buffer/test/impl/others/ArrayVsArrayList.java
1
package org.gvsig.raster.cache.buffer.impl.others;
2

  
3
import java.util.ArrayList;
4

  
5
import org.gvsig.raster.cache.buffer.PxTile;
6
import org.gvsig.raster.cache.buffer.impl.PxTileImpl;
7
import org.gvsig.raster.cache.buffer.impl.rocache.ByteBand;
8
import org.gvsig.raster.cache.buffer.impl.rocache.ReadOnlyCacheBand;
9

  
10
/**
11
 * This test compare the access time of an element in two cases. The first
12
 * case is the access to an element in a simple array of objects. The second
13
 * case is the access to an element in an ArrayList.
14
 *  
15
 * @author Nacho Brodin (nachobrodin@gmail.com)
16
 *
17
 */
18
public class ArrayVsArrayList {
19
	public static int N = 500000;
20
	/**
21
	 * @param args
22
	 */
23
	public static void main(String[] args) {
24
		ArrayVsArrayList p = new ArrayVsArrayList();
25
		p.array();
26
		p.arrayList();
27
	}
28
	
29
	private void array() {
30
		long t1 = System.currentTimeMillis();
31
		ArrayList<PxTile> stripeList = new ArrayList<PxTile>();
32
		for (int i = 0; i < 1; i++) 
33
			stripeList.add(new PxTileImpl(0, 0, 0, 0));
34
		
35
		ReadOnlyCacheBand[] l = new ReadOnlyCacheBand[N];
36
		for (int i = 0; i < N; i++) {
37
			ByteBand b =  new ByteBand(stripeList, null, 15, 15, 15, 2345, 3244);
38
			l[i] = b;
39
		}
40
		int z = 0;
41
		for (int i = 0; i < N; i++) {
42
			int y = l[i].getBandNumber();
43
			z += y;
44
		}
45
		long t2 = System.currentTimeMillis();
46
		System.out.println("Time Array with " + N + " elements: " + (t2 - t1) + " milisegundos" + z);
47
		
48
	}
49
	
50
	private void arrayList() {
51
		long t1 = System.currentTimeMillis();
52
		ArrayList<PxTile> stripeList = new ArrayList<PxTile>();
53
		for (int i = 0; i < 1; i++) 
54
			stripeList.add(new PxTileImpl(0, 0, 0, 0));
55
		
56
		ArrayList<ReadOnlyCacheBand> l = new ArrayList<ReadOnlyCacheBand>();
57
		for (int i = 0; i < N; i++) {
58
			ByteBand b =  new ByteBand(stripeList, null, 15, 15, 15, 2345, 3244);
59
			l.add(b);
60
		}
61
		int z = 0;
62
		for (int i = 0; i < N; i++) {
63
			int y = l.get(i).getBandNumber();
64
			z += y;
65
		}
66
		long t2 = System.currentTimeMillis();
67
		System.out.println("Time ArrayList with " + N + " elements: " + (t2 - t1) + " milisegundos" + z);
68
	}
69

  
70
}
0 71

  
org.gvsig.raster.cache/tags/v2.2.0/org.gvsig.raster.cache.lib.impl/deprecated/buffer/test/impl/others/TestCacheVsMemory.java
1
package org.gvsig.raster.cache.buffer.impl.others;
2

  
3
import java.io.IOException;
4

  
5
import junit.framework.TestCase;
6

  
7
import org.gvsig.jgdal.GdalException;
8
import org.gvsig.raster.cache.buffer.Buffer;
9
import org.gvsig.raster.cache.buffer.exception.OperationNotSupportedException;
10
import org.gvsig.raster.cache.buffer.exception.ProcessInterruptedException;
11
import org.gvsig.raster.cache.buffer.impl.BufferCacheManagerImpl;
12
import org.gvsig.raster.cache.buffer.impl.io.GdalRead;
13
import org.gvsig.raster.cache.buffer.impl.memory.RasterMemoryBuffer;
14
import org.gvsig.raster.cache.buffer.impl.stripecache.horizontal.RasterCacheBuffer;
15

  
16
/**
17
 * Performance Test: It loads a complete image of 65MB in a cached buffer and after read the
18
 * same image in a memory buffer. For this test we use a small size of cache (2MB) and a size of
19
 * one page of 0.2MB
20
 *  
21
 * REPEAT = 1
22
 * Using setValues
23
 * Time cached: 1538 ms
24
 * Time memory: 1163 ms
25
 * 
26
 * REPEAT = 1
27
 * Using setLines
28
 * Time cached: 198 ms
29
 * Time memory: 171 ms
30
 *
31
 * REPEAT = 10
32
 * Using setValues
33
 * Time cached: 14317 ms
34
 * Time memory: 11168 ms
35
 * 
36
 * REPEAT = 10
37
 * Using setLines
38
 * Time cached: 1944 ms
39
 * Time memory: 1209 ms
40
 * 
41
 * Intel(R) Core(TM)2 CPU E8400  @ 3.00GHz
42
 * 2GB RAM DDR3 1066
43
 * HDD ATA 133
44
 * Linux Ubuntu 10.04 kernel 2.6.24
45
 * 
46
 * @author Nacho Brodin (nachobrodin@gmail.com)
47
 */
48
public class TestCacheVsMemory extends TestCase {
49
	private String rasterIn = "./src/test/resources/image/001m09_1_0.tif";
50
	private static int REPEAT = 10;
51
	
52
	public void start() {
53
		this.setUp();
54
		this.testStack();
55
	}
56

  
57
	public void setUp() {
58
		System.err.println("CacheVsMemory running...");
59
	}
60
	
61
	public void testStack() {
62
		
63
		try {
64
			GdalRead input = null;
65
			//Read input data
66
			input = new GdalRead(rasterIn);
67
			Object dataIn = input.readBlock(0, 0, input.getWidth(), input.getHeight());
68
			
69
			
70
			//Reducimos el tama?o de la cache para una prueba con menos datos
71
			BufferCacheManagerImpl.cacheSize = 25;
72
			BufferCacheManagerImpl.pageSize = 2;
73
		
74
			//****************CACHE**********************
75
			long t1 = System.currentTimeMillis();
76
			for (int iTimes = 0; iTimes < REPEAT; iTimes++) {
77

  
78
				//Create Buffer
79
				Buffer buf1 = new RasterCacheBuffer(input.getRasterBufTypeFromGdalType(input.getDataType()), 
80
						input.getWidth(), 
81
						input.getHeight(),
82
						input.getBandCount());
83

  
84
				//Set data to buffer
85
				setValues(dataIn, buf1);
86
				buf1.free();
87
			}
88
			
89
			long t2 = System.currentTimeMillis();
90
			System.out.println("Tiempo StripeCache : " + (t2 - t1) + " milisegundos");
91
			//****************FIN CACHE******************
92
			
93
			//****************MEMO***********************
94
			t1 = System.currentTimeMillis();
95
			for (int iTimes = 0; iTimes < REPEAT; iTimes++) {
96

  
97
				//Create Buffer
98
				Buffer buf2 = new RasterMemoryBuffer(input.getRasterBufTypeFromGdalType(input.getDataType()), 
99
						input.getWidth(), 
100
						input.getHeight(),
101
						input.getBandCount(),
102
						true);
103

  
104
				//Set data to buffer
105
				setValues(dataIn, buf2);
106
				buf2.free();
107
			}
108
			
109
			t2 = System.currentTimeMillis();
110
			System.out.println("Tiempo Memoria : " + (t2 - t1) + " milisegundos");
111
			//****************FIN MEMO******************
112
			
113
			input.close();
114
		} catch (GdalException e) {
115
			e.printStackTrace();
116
		} catch (IOException e) {
117
			e.printStackTrace();
118
		} catch (ProcessInterruptedException e) {
119
			e.printStackTrace();
120
		} catch (OperationNotSupportedException e) {
121
			e.printStackTrace();
122
		}
123
		
124
		
125
	}
126
	
127
	public void setValues(Object dataIn, Buffer buf) throws OperationNotSupportedException {
128
		if(dataIn instanceof byte[][][]) {
129
    		byte[][][] d = (byte[][][])dataIn;
130
    		for (int band = 0; band < d.length; band++) {
131
				for (int row = 0; row < d[band].length; row++) {
132
					for (int col = 0; col < d[band][row].length; col++) {
133
						buf.setElem(row, col, band, (byte)d[band][row][col]);
134
					}
135
				}
136
			}
137
    	}
138
	}
139
	
140
	public void setLines(Object dataIn, Buffer buf) throws OperationNotSupportedException {
141
		if(dataIn instanceof byte[][][]) {
142
    		byte[][][] d = (byte[][][])dataIn;
143
    		for (int iBand = 0; iBand < d.length; iBand++) {
144
				for (int row = 0; row < d[iBand].length; row++) {
145
					buf.setLineInBandByte(d[iBand][row], row, iBand);
146
				}
147
			}
148
    	}
149
	}
150
	
151
}
0 152

  
org.gvsig.raster.cache/tags/v2.2.0/org.gvsig.raster.cache.lib.impl/deprecated/buffer/test/impl/rocache/TestReadWindowAndCompareData.java
1
package org.gvsig.raster.cache.buffer.impl.rocache;
2

  
3
import java.io.IOException;
4

  
5
import junit.framework.TestCase;
6

  
7
import org.gvsig.jgdal.GdalException;
8
import org.gvsig.raster.cache.buffer.Buffer;
9
import org.gvsig.raster.cache.buffer.BufferParam;
10
import org.gvsig.raster.cache.buffer.exception.OperationNotSupportedException;
11
import org.gvsig.raster.cache.buffer.exception.ProcessInterruptedException;
12
import org.gvsig.raster.cache.buffer.impl.BufferCacheManagerImpl;
13
import org.gvsig.raster.cache.buffer.impl.BufferParamImpl;
14
import org.gvsig.raster.cache.buffer.impl.io.GdalRead;
15
import org.gvsig.raster.cache.buffer.impl.memory.RasterMemoryBuffer;
16

  
17
/**
18
 * Read a number from cache
19
 * @author Nacho Brodin (nachobrodin@gmail.com)
20
 */
21
public class TestReadWindowAndCompareData extends TestCase {
22
	private String in = "./src/test/resources/image/001m09_1_0.tif";
23
	private int    initX  = 200;
24
	private int    initY  = 200;
25
	private int    w      = 400;
26
	private int    h      = 400;
27
	
28
	public void start() {
29
		this.setUp();
30
		this.testStack();
31
	}
32

  
33
	public void setUp() {
34
		System.err.println("ROCache TestReadTiffAndCompareData running...");
35
	}
36
	
37
	public void testStack() {
38
		long t1 = System.currentTimeMillis();
39
		GdalRead input = null;
40
		
41
		BufferCacheManagerImpl.cacheSize = 1;
42
		BufferCacheManagerImpl.pageSize = 0.2;
43
		
44
		Buffer buf1 = null;
45
		try {
46
			input = new GdalRead(in);
47

  
48
			Object dataIn = input.readBlock(initX, initY, w, h);
49

  
50
			//Create Buffer
51
			buf1 = new RasterMemoryBuffer(input.getRasterBufTypeFromGdalType(input.getDataType()), 
52
											w, 
53
											h,
54
											input.getBandCount(),
55
											true);
56

  
57
			//Set data to buffer
58
			setLines(dataIn, buf1);
59
		} catch (GdalException e1) {
60
			e1.printStackTrace();
61
		} catch (IOException e1) {
62
			e1.printStackTrace();
63
		} catch (ProcessInterruptedException e1) {
64
			e1.printStackTrace();
65
		} catch (OperationNotSupportedException e1) {
66
			e1.printStackTrace();
67
		}
68
		
69
		RasterReadOnlyBuffer buf = null;
70
		try {
71
			BufferParam p = new BufferParamImpl(in, initX, initY, w, h, new int[]{0, 1, 2});
72
			buf = new RasterReadOnlyBuffer(p);
73
		} catch (IOException e) {
74
			e.printStackTrace();
75
		}
76
		
77
				
78
		for (int iBand = 0; iBand < buf.getBandCount(); iBand++) {
79
			for (int row = 0; row < buf.getHeight(); row++) {
80
				for (int col = 0; col < buf.getWidth(); col++) {
81
					byte n = buf.getElemByte(row, col, iBand);
82
					byte m = buf1.getElemByte(row, col, iBand);
83
					if(n != m)
84
						System.out.println(row + " " + col);
85
					assertEquals(n, m);
86
				}
87
			}
88
		}
89
		
90
		try {
91
			buf.free();
92
		} catch (IOException e) {
93
			// TODO Auto-generated catch block
94
			e.printStackTrace();
95
		}
96
		
97
		long t2 = System.currentTimeMillis();
98
		System.out.println("Tiempo ROCache TestRWOneValue: " + (t2 - t1) + " milisegundos");
99
	}
100
	
101
	private void setLines(Object dataIn, Buffer buf) throws OperationNotSupportedException {
102
		if(dataIn instanceof byte[][][]) {
103
    		byte[][][] d = (byte[][][])dataIn;
104
    		for (int iBand = 0; iBand < d.length; iBand++) {
105
				for (int row = 0; row < d[iBand].length; row++) {
106
					buf.setLineInBandByte(d[iBand][row], row, iBand);
107
				}
108
			}
109
    	}
110
	}
111
	
112
}
0 113

  
org.gvsig.raster.cache/tags/v2.2.0/org.gvsig.raster.cache.lib.impl/deprecated/buffer/test/impl/rocache/TestWindow.java
1
package org.gvsig.raster.cache.buffer.impl.rocache;
2

  
3
import java.io.IOException;
4

  
5
import junit.framework.TestCase;
6

  
7
import org.gvsig.jgdal.GdalException;
8
import org.gvsig.raster.cache.buffer.Band;
9
import org.gvsig.raster.cache.buffer.Buffer;
10
import org.gvsig.raster.cache.buffer.BufferDataSource;
11
import org.gvsig.raster.cache.buffer.exception.OperationNotSupportedException;
12
import org.gvsig.raster.cache.buffer.exception.ProcessInterruptedException;
13
import org.gvsig.raster.cache.buffer.impl.PxTileImpl;
14
import org.gvsig.raster.cache.buffer.impl.io.BufferDataSourceImpl;
15
import org.gvsig.raster.cache.buffer.impl.io.GdalRead;
16
import org.gvsig.raster.cache.buffer.impl.io.GdalWrite;
17
import org.gvsig.raster.cache.buffer.impl.memory.RasterMemoryBuffer;
18

  
19
/** 
20
 *  
21
 * @author Nacho Brodin (nachobrodin@gmail.com)
22
 */
23
public class TestWindow extends TestCase {
24
	private String rasterIn = "./src/test/resources/image/001m09_1_0.tif";
25
	private String rasterOut = "/tmp/window.tif";
26
	private String compare = "./src/test/resources/image/clip_test_robufer.tif";
27
	
28
	public void start() {
29
		this.setUp();
30
		this.testStack();
31
	}
32

  
33
	public void setUp() {
34
		System.err.println("ROCache TestWindow running...");
35
	}
36
	
37
	public void testStack() {
38
		long t1 = System.currentTimeMillis();
39
		GdalWrite output = null;
40
		try {
41
			
42
			BufferDataSource ds = null;
43
			try {
44
				ds = new BufferDataSourceImpl(rasterIn, new PxTileImpl(100, 100, 500, 400));
45
			} catch (IOException e) {
46
				e.printStackTrace();
47
			}
48
			Buffer buf = new RasterReadOnlyBuffer(ds);
49
			
50
			GdalRead input1 = new GdalRead(compare);
51
			output = new GdalWrite(rasterOut, 3, input1.getGdalTypeFromRasterBufType(ds.getDataType()), ds.getWidth(), ds.getHeight(), GdalWrite.COLOR_INTERP_RGB);
52
			output.writeBands(buf.getBands());
53
			output.close();
54
			
55
			//Read input data
56
			
57
			Object dataIn = input1.readBlock(0, 0, input1.getWidth(), input1.getHeight());
58
			
59
			//Create Buffer
60
			Buffer buf1 = new RasterMemoryBuffer(input1.getRasterBufTypeFromGdalType(input1.getDataType()), 
61
														input1.getWidth(), 
62
														input1.getHeight(),
63
														input1.getBandCount(),
64
														true);
65
			
66
			//Set data to buffer
67
			setLines(dataIn, buf1);
68
			for (int i = 0; i < buf.getBandCount(); i++) 
69
				compareBands(buf.getBand(i), buf.getBand(i));
70
			
71
			buf.free();
72
			buf1.free();
73
		} catch (GdalException e) {
74
			e.printStackTrace();
75
		} catch (IOException e) {
76
			e.printStackTrace();
77
		} catch (ProcessInterruptedException e) {
78
			e.printStackTrace();
79
		} catch (OperationNotSupportedException e) {
80
			e.printStackTrace();
81
		}
82
		long t2 = System.currentTimeMillis();
83
		System.out.println("Tiempo ROCache TestWindow: " + (t2 - t1) + " milisegundos");
84
	}
85
	
86
	
87
	public void compareBands(Band band1, Band band2) {
88
		for (int i = 0; i < band1.getHeight(); i++) {
89
			for (int j = 0; j < band1.getWidth(); j++) {
90
				byte b1 = band1.getElemByte(i, j);
91
				byte b2 = band2.getElemByte(i, j);
92
				assertEquals(b1, b2);
93
			}
94
		}
95
	}
96
	
97
	private void setLines(Object dataIn, Buffer buf) throws OperationNotSupportedException {
98
		if(dataIn instanceof byte[][][]) {
99
    		byte[][][] d = (byte[][][])dataIn;
100
    		for (int iBand = 0; iBand < d.length; iBand++) {
101
				for (int row = 0; row < d[iBand].length; row++) {
102
					buf.setLineInBandByte(d[iBand][row], row, iBand);
103
				}
104
			}
105
    	}
106
	}
107
}
0 108

  
org.gvsig.raster.cache/tags/v2.2.0/org.gvsig.raster.cache.lib.impl/deprecated/buffer/test/impl/rocache/TestReadTiffAndCompareData.java
1
package org.gvsig.raster.cache.buffer.impl.rocache;
2

  
3
import java.io.IOException;
4

  
5
import junit.framework.TestCase;
6

  
7
import org.gvsig.jgdal.GdalException;
8
import org.gvsig.raster.cache.buffer.Buffer;
9
import org.gvsig.raster.cache.buffer.BufferDataSource;
10
import org.gvsig.raster.cache.buffer.exception.OperationNotSupportedException;
11
import org.gvsig.raster.cache.buffer.exception.ProcessInterruptedException;
12
import org.gvsig.raster.cache.buffer.impl.BufferCacheManagerImpl;
13
import org.gvsig.raster.cache.buffer.impl.io.BufferDataSourceImpl;
14
import org.gvsig.raster.cache.buffer.impl.io.GdalRead;
15
import org.gvsig.raster.cache.buffer.impl.memory.RasterMemoryBuffer;
16

  
17
/**
18
 * Read a number from cache
19
 * @author Nacho Brodin (nachobrodin@gmail.com)
20
 */
21
public class TestReadTiffAndCompareData extends TestCase {
22
	private String in = "./src/test/resources/image/001m09_1_0.tif";
23
	
24
	public void start() {
25
		this.setUp();
26
		this.testStack();
27
	}
28

  
29
	public void setUp() {
30
		System.err.println("ROCache TestReadTiffAndCompareData running...");
31
	}
32
	
33
	public void testStack() {
34
		long t1 = System.currentTimeMillis();
35
		GdalRead input = null;
36
		
37
		BufferCacheManagerImpl.cacheSize = 1;
38
		BufferCacheManagerImpl.pageSize = 0.2;
39
		
40
		Buffer buf1 = null;
41
		try {
42
			input = new GdalRead(in);
43

  
44
			Object dataIn = input.readBlock(0, 0, input.getWidth(), input.getHeight());
45

  
46
			//Create Buffer
47
			buf1 = new RasterMemoryBuffer(input.getRasterBufTypeFromGdalType(input.getDataType()), 
48
											input.getWidth(), 
49
											input.getHeight(),
50
											input.getBandCount(),
51
											true);
52

  
53
			//Set data to buffer
54
			setLines(dataIn, buf1);
55
		} catch (GdalException e1) {
56
			e1.printStackTrace();
57
		} catch (IOException e1) {
58
			e1.printStackTrace();
59
		} catch (ProcessInterruptedException e1) {
60
			e1.printStackTrace();
61
		} catch (OperationNotSupportedException e1) {
62
			e1.printStackTrace();
63
		}
64
		
65
		
66
		BufferDataSource ds = null;
67
		try {
68
			ds = new BufferDataSourceImpl(in);
69
		} catch (IOException e) {
70
			e.printStackTrace();
71
		}
72
		RasterReadOnlyBuffer buf = new RasterReadOnlyBuffer(ds);
73
				
74
		for (int iBand = 0; iBand < buf.getBandCount(); iBand++) {
75
			for (int row = 0; row < buf.getHeight(); row++) {
76
				for (int col = 0; col < buf.getWidth(); col++) {
77
					byte n = buf.getElemByte(row, col, iBand);
78
					byte m = buf1.getElemByte(row, col, iBand);
79
					if(n != m)
80
						System.out.println(row + " " + col);
81
					assertEquals(n, m);
82
				}
83
			}
84
		}
85
		
86
		try {
87
			buf.free();
88
		} catch (IOException e) {
89
			// TODO Auto-generated catch block
90
			e.printStackTrace();
91
		}
92
		
93
		long t2 = System.currentTimeMillis();
94
		System.out.println("Tiempo ROCache TestRWOneValue: " + (t2 - t1) + " milisegundos");
95
	}
96
	
97
	private void setLines(Object dataIn, Buffer buf) throws OperationNotSupportedException {
98
		if(dataIn instanceof byte[][][]) {
99
    		byte[][][] d = (byte[][][])dataIn;
100
    		for (int iBand = 0; iBand < d.length; iBand++) {
101
				for (int row = 0; row < d[iBand].length; row++) {
102
					buf.setLineInBandByte(d[iBand][row], row, iBand);
103
				}
104
			}
105
    	}
106
	}
107
	
108
}
0 109

  
org.gvsig.raster.cache/tags/v2.2.0/org.gvsig.raster.cache.lib.impl/deprecated/buffer/test/impl/rocache/TestAssignBand.java
1
package org.gvsig.raster.cache.buffer.impl.rocache;
2

  
3
import java.io.IOException;
4

  
5
import junit.framework.TestCase;
6

  
7
import org.gvsig.jgdal.GdalException;
8
import org.gvsig.raster.cache.buffer.Band;
9
import org.gvsig.raster.cache.buffer.Buffer;
10
import org.gvsig.raster.cache.buffer.BufferDataSource;
11
import org.gvsig.raster.cache.buffer.exception.BandNotCompatibleException;
12
import org.gvsig.raster.cache.buffer.impl.io.BufferDataSourceImpl;
13
import org.gvsig.raster.cache.buffer.impl.io.GdalRead;
14
import org.gvsig.raster.cache.buffer.impl.io.GdalWrite;
15

  
16
/**
17
 * Assign by reference a band in a Buffer
18
 * @author Nacho Brodin (nachobrodin@gmail.com)
19
 */
20
public class TestAssignBand extends TestCase {
21
	private String rasterIn = "./src/test/resources/image/001m09_1_0.tif";
22
	private String rasterOut = "/tmp/out-4bands.tif";
23
	
24
	public void start() {
25
		this.setUp();
26
		this.testStack();
27
	}
28

  
29
	public void setUp() {
30
		System.err.println("ROCache TestAssignBand running...");
31
	}
32
	
33
	public void testStack() {
34
		long t1 = System.currentTimeMillis();
35
		GdalRead input1 = null;
36

  
37
		GdalWrite out = null;
38
		try {
39
						
40
			//Read input data
41
			input1 = new GdalRead(rasterIn);
42
						
43
			BufferDataSource ds = null;
44
			try {
45
				ds = new BufferDataSourceImpl(rasterIn);
46
			} catch (IOException e) {
47
				e.printStackTrace();
48
			}
49
			Buffer buf1 = new RasterReadOnlyBuffer(ds);
50
			
51
			BufferDataSource ds1 = null;
52
			try {
53
				ds1 = new BufferDataSourceImpl(rasterIn);
54
			} catch (IOException e) {
55
				e.printStackTrace();
56
			}
57
			Buffer buf2 = new RasterReadOnlyBuffer(ds1);
58
			
59
			Band rb = buf2.getBand(2);
60
			try {
61
				buf1.assignBand(1, rb);
62
			} catch (BandNotCompatibleException e) {
63
				e.printStackTrace();
64
			}
65
			
66
			//Write output file 
67
			out = new GdalWrite(rasterOut, 4, input1.getDataType(), input1.getWidth(), input1.getHeight(), GdalWrite.COLOR_INTERP_GRAY);
68
			out.writeBands(buf1.getBands());
69
			out.close();	
70
			
71
			Band band1 = buf1.getBand(1);
72
			Band band2 = buf1.getBand(3);
73
			for (int i = 0; i < band1.getHeight(); i++) {
74
				for (int j = 0; j < band1.getWidth(); j++) {
75
					byte b1 = band1.getElemByte(i, j);
76
					byte b2 = band2.getElemByte(i, j);
77
					assertEquals(b1, b2);
78
				}
79
			}
80
			
81
			buf1.free();
82
			buf2.free();
83
		} catch (GdalException e) {
84
			e.printStackTrace();
85
		} catch (IOException e) {
86
			e.printStackTrace();
87
		}
88
		long t2 = System.currentTimeMillis();
89
		System.out.println("Tiempo ROCache TestAssignBand: " + (t2 - t1) + " milisegundos");
90
	}
91
}
0 92

  
org.gvsig.raster.cache/tags/v2.2.0/org.gvsig.raster.cache.lib.impl/deprecated/buffer/test/impl/rocache/TestMultifile.java
1
package org.gvsig.raster.cache.buffer.impl.rocache;
2

  
3
import java.io.IOException;
4

  
5
import junit.framework.TestCase;
6

  
7
import org.gvsig.jgdal.GdalException;
8
import org.gvsig.raster.cache.buffer.Buffer;
9
import org.gvsig.raster.cache.buffer.BufferDataSource;
10
import org.gvsig.raster.cache.buffer.BufferParam;
11
import org.gvsig.raster.cache.buffer.exception.OperationNotSupportedException;
12
import org.gvsig.raster.cache.buffer.impl.BufferParamImpl;
13
import org.gvsig.raster.cache.buffer.impl.io.BufferDataSourceImpl;
14
import org.gvsig.raster.cache.buffer.impl.io.GdalRead;
15
import org.gvsig.raster.cache.buffer.impl.io.GdalWrite;
16

  
17
/**
18
 * This test gets bands from a raster with the method getBufferWithOneBand() and compare
19
 * each band from original source with obtained bands 
20
 * @author Nacho Brodin (nachobrodin@gmail.com)
21
 */
22
public class TestMultifile extends TestCase {
23
	private String rasterIn = "./src/test/resources/image/001m09_1_0.tif";
24
	private String rasterOut1 = "/tmp/out-b1.tif";
25
	private String rasterOut2 = "/tmp/out-b2.tif";
26
	private String rasterOut3 = "/tmp/out-b3.tif";
27
	private int    x      = 200;
28
	private int    y      = 200;
29
	private int    w      = 800;
30
	private int    h      = 800;
31
	
32
	public void start() {
33
		this.setUp();
34
		this.testStack();
35
	}
36

  
37
	public void setUp() {
38
		System.err.println("ROCache TestGetBufferWithOneBand running...");
39
	}
40
	
41
	public void testStack() {
42
		long t1 = System.currentTimeMillis();
43
		GdalRead input = null;
44
		try {
45
			//Read input data
46
			input = new GdalRead(rasterIn);
47
			
48
			BufferDataSource ds = null;
49
			try {
50
				ds = new BufferDataSourceImpl(rasterIn);
51
			} catch (IOException e) {
52
				e.printStackTrace();
53
			}
54
			Buffer buf = new RasterReadOnlyBuffer(ds);
55
						
56
			Buffer b0 = buf.getBufferWithOneBand(0);
57
			Buffer b1 = buf.getBufferWithOneBand(1);
58
			Buffer b2 = buf.getBufferWithOneBand(2);
59
			
60
			//Write output file 
61
			GdalWrite out1 = new GdalWrite(rasterOut1, 1, input.getDataType(), input.getWidth(), input.getHeight(), GdalWrite.COLOR_INTERP_GRAY);
62
			out1.writeBands(b0.getBands());
63
			out1.close();
64
			
65
			GdalWrite out2 = new GdalWrite(rasterOut2, 1, input.getDataType(), input.getWidth(), input.getHeight(), GdalWrite.COLOR_INTERP_GRAY);
66
			out2.writeBands(b1.getBands());
67
			out2.close();
68
			
69
			GdalWrite out3 = new GdalWrite(rasterOut3, 1, input.getDataType(), input.getWidth(), input.getHeight(), GdalWrite.COLOR_INTERP_GRAY);
70
			out3.writeBands(b2.getBands());
71
			out3.close();
72
			
73
			BufferParam params = new BufferParamImpl(
74
					new String[]{rasterOut1, rasterOut2, rasterOut3}, 
75
					x, y, w, h, null);
76
			RasterReadOnlyBuffer multiband = new RasterReadOnlyBuffer(params);
77
						
78
			for (int row = 0; row < multiband.getHeight(); row++) {
79
				for (int col = 0; col < multiband.getWidth(); col++) {
80
					byte b_0 = multiband.getElemByte(row, col, 0);
81
					byte b_1 = multiband.getElemByte(row, col, 1);
82
					byte b_2 = multiband.getElemByte(row, col, 2);
83
					assertEquals(b_0, b0.getElemByte(row + y, col + x, 0));
84
					assertEquals(b_1, b1.getElemByte(row + y, col + x, 0));
85
					assertEquals(b_2, b2.getElemByte(row + y, col + x, 0));
86
				}
87
			}
88
						
89
			b0.free();
90
			b1.free();
91
			b2.free();
92
			buf.free();
93
				
94
		} catch (GdalException e) {
95
			e.printStackTrace();
96
		} catch (IOException e) {
97
			e.printStackTrace();
98
		} catch (OperationNotSupportedException e) {
99
			e.printStackTrace();
100
		}
101
		long t2 = System.currentTimeMillis();
102
		System.out.println("Tiempo ROCache TestGetBufferWithOneBand: " + (t2 - t1) + " milisegundos");
103
	}
104
	
105
}
0 106

  
org.gvsig.raster.cache/tags/v2.2.0/org.gvsig.raster.cache.lib.impl/deprecated/buffer/test/impl/rocache/AllTests.java
1
package org.gvsig.raster.cache.buffer.impl.rocache;
2

  
3
import junit.framework.Test;
4
import junit.framework.TestSuite;
5

  
6
public class AllTests {
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff