Revision 12685

View differences:

org.gvsig.raster.cache/tags/org.gvsig.raster.cache-2.2.68/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.68</version>
10
    <scm>
11
        <connection>scm:svn:https://devel.gvsig.org/svn/gvsig-raster/org.gvsig.raster.cache/tags/org.gvsig.raster.cache-2.2.68</connection>
12
        <developerConnection>scm:svn:https://devel.gvsig.org/svn/gvsig-raster/org.gvsig.raster.cache/tags/org.gvsig.raster.cache-2.2.68</developerConnection>
13
        <url>https://devel.gvsig.org/redmine/projects/gvsig-raster/repository/show/org.gvsig.raster.cache/tags/org.gvsig.raster.cache-2.2.68</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.299</version>
38
    </parent>
39

  
40
    <developers>
41
        <developer>
42
            <id>nbrodin</id>
43
            <name>Nacho Brodin</name>
44
            <email>nachobrodin@gmail.com</email>
45
            <roles>
46
                <role>Architect</role>
47
                <role>Developer</role>
48
            </roles>
49
        </developer>
50
    </developers>
51

  
52
     <dependencyManagement>
53
        <dependencies>
54

  
55

  
56
            <!--
57
            Versions of child projects
58
            -->
59
            <dependency>
60
                <groupId>org.gvsig</groupId>
61
                <artifactId>org.gvsig.raster.cache.lib.api</artifactId>
62
                <version>2.2.68</version>
63
            </dependency>
64
            <dependency>
65
                <groupId>org.gvsig</groupId>
66
                <artifactId>org.gvsig.raster.cache.lib.impl</artifactId>
67
                <version>2.2.68</version>
68
            </dependency>
69

  
70

  
71
        </dependencies>
72
    </dependencyManagement>
73

  
74

  
75
    <build>
76
        <plugins>
77
            <plugin>
78
                <groupId>org.apache.maven.plugins</groupId>
79
                <artifactId>maven-release-plugin</artifactId>
80
                <configuration>
81
                    <tagBase>https://devel.gvsig.org/svn/gvsig-raster/org.gvsig.raster.cache/tags/</tagBase>
82
                    <goals>deploy</goals>
83
                </configuration>
84
            </plugin>
85
            <plugin>
86
				<groupId>org.apache.maven.plugins</groupId>
87
				<artifactId>maven-compiler-plugin</artifactId>
88
				<configuration>
89
					<source>1.5</source>
90
					<target>1.5</target>
91
				</configuration>
92
			</plugin>
93
			<plugin>
94
                <groupId>org.codehaus.mojo</groupId>
95
                <artifactId>animal-sniffer-maven-plugin</artifactId>
96
                <configuration>
97
                    <skip>true</skip>
98
                </configuration>
99
            </plugin>
100
        </plugins>
101
    </build>
102
    <modules>
103
        <module>org.gvsig.raster.cache.lib.api</module>
104
        <module>org.gvsig.raster.cache.lib.impl</module>
105
    </modules>
106
</project>
0 107

  
org.gvsig.raster.cache/tags/org.gvsig.raster.cache-2.2.68/org.gvsig.raster.cache.lib.impl/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/maven-v4_0_0.xsd">
3
	<modelVersion>4.0.0</modelVersion>
4
	<artifactId>org.gvsig.raster.cache.lib.impl</artifactId>
5
	<packaging>jar</packaging>
6
	<name>org.gvsig.raster.cache.lib.impl</name>
7
	<parent>
8
		<groupId>org.gvsig</groupId>
9
		<artifactId>org.gvsig.raster.cache</artifactId>
10
		<version>2.2.68</version>
11
	</parent>
12
	<dependencies>
13
		<dependency>
14
			<groupId>org.gvsig</groupId>
15
			<artifactId>org.gvsig.raster.cache.lib.api</artifactId>
16
            <scope>compile</scope>
17
		</dependency>
18
        <dependency>
19
            <groupId>org.gvsig</groupId>
20
            <artifactId>org.gvsig.fmap.dal.file.lib</artifactId>
21
            <scope>compile</scope>
22
        </dependency>
23
		<dependency>
24
            <groupId>org.gvsig</groupId>
25
            <artifactId>org.gvsig.compat.api</artifactId>
26
            <scope>compile</scope>
27
        </dependency>
28
        <dependency>
29
            <groupId>org.gvsig</groupId>
30
            <artifactId>org.gvsig.compat.se</artifactId>
31
            <scope>compile</scope>
32
        </dependency>
33
 
34
	</dependencies>
35
</project>
0 36

  
org.gvsig.raster.cache/tags/org.gvsig.raster.cache-2.2.68/org.gvsig.raster.cache.lib.impl/deprecated/buffer/test/impl/TestInterpolationBilinearIncrease.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 TestInterpolationBilinearIncrease extends TestCase {
21
	private String         rasterIn  = "./src/test/resources/image/001m09_1_0.tif";
22
	private String         rasterOut = "/tmp/out-interpBilinear.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("TestInterpolationBilinear 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_Bilinear);
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 TestInterpolationBilinear: " + (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/org.gvsig.raster.cache-2.2.68/org.gvsig.raster.cache.lib.impl/deprecated/buffer/test/impl/stripecache/horizontal/TestCreateBand.java
1
package org.gvsig.raster.cache.buffer.impl.stripecache.horizontal;
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.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.GdalRead;
14

  
15
/**
16
 * This test add a band in a raster of 3 bands. As a result of this test a raster
17
 * of four bands is created and saved in the hard disk. The value of additional band
18
 * is zero in all its elements. Finally it gets the band added and compare each values 
19
 * with 0. 
20
 *  
21
 * @author Nacho Brodin (nachobrodin@gmail.com)
22
 */
23
public class TestCreateBand extends TestCase {
24
	private String rasterIn = "./src/test/resources/image/001m09_1_0.tif";
25
	
26
	public void start() {
27
		this.setUp();
28
		this.testStack();
29
	}
30

  
31
	public void setUp() {
32
		System.err.println("StripeCache TestCreateBand running...");
33
	}
34
	
35
	public void testStack() {
36
		long t1 = System.currentTimeMillis();
37
		GdalRead input = null;
38
		try {
39
			//Reducimos el tama?o de la cache para una prueba con menos datos
40
			BufferCacheManagerImpl.cacheSize = 2;
41
			BufferCacheManagerImpl.pageSize = 0.2;
42
			
43
			//Read input data
44
			input = new GdalRead(rasterIn);
45
			Object dataIn = input.readBlock(0, 0, input.getWidth(), input.getHeight());
46
			
47
			//Create Buffer
48
			Buffer buf = new RasterCacheBuffer(input.getRasterBufTypeFromGdalType(input.getDataType()), 
49
														input.getWidth(), 
50
														input.getHeight(),
51
														input.getBandCount());
52
			
53
			//Set data to buffer
54
			setLines(dataIn, buf);
55
			Band rb = buf.createBand((byte)100);
56

  
57
			for (int i = 0; i < rb.getHeight(); i++) {
58
				for (int j = 0; j < rb.getWidth(); j++) {
59
					byte b = rb.getElemByte(i, j);
60
					assertEquals((byte)100, b);
61
				}
62
			}
63
			
64
			buf.free();
65
		} catch (GdalException e) {
66
			e.printStackTrace();
67
		} catch (IOException e) {
68
			e.printStackTrace();
69
		} catch (ProcessInterruptedException e) {
70
			e.printStackTrace();
71
		} catch (OperationNotSupportedException e) {
72
			e.printStackTrace();
73
		}
74
		long t2 = System.currentTimeMillis();
75
		System.out.println("Tiempo StripeCache TestCreateBand: " + (t2 - t1) + " milisegundos");
76
	}
77
	
78
	private void setLines(Object dataIn, Buffer buf) throws OperationNotSupportedException {
79
		if(dataIn instanceof byte[][][]) {
80
    		byte[][][] d = (byte[][][])dataIn;
81
    		for (int iBand = 0; iBand < d.length; iBand++) {
82
				for (int row = 0; row < d[iBand].length; row++) {
83
					buf.setLineInBandByte(d[iBand][row], row, iBand);
84
				}
85
			}
86
    	}
87
	}
88
	
89
}
0 90

  
org.gvsig.raster.cache/tags/org.gvsig.raster.cache-2.2.68/org.gvsig.raster.cache.lib.impl/deprecated/buffer/test/impl/stripecache/horizontal/TestAssignBand.java
1
package org.gvsig.raster.cache.buffer.impl.stripecache.horizontal;
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.exception.BandNotCompatibleException;
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.BufferCacheManagerImpl;
14
import org.gvsig.raster.cache.buffer.impl.io.GdalRead;
15
import org.gvsig.raster.cache.buffer.impl.io.GdalWrite;
16

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

  
30
	public void setUp() {
31
		System.err.println("StripeCache TestAssignBand running...");
32
	}
33
	
34
	public void testStack() {
35
		long t1 = System.currentTimeMillis();
36
		GdalRead input1 = null;
37
		GdalRead input2 = null;
38
		GdalWrite out = null;
39
		try {
40
			//Reducimos el tama?o de la cache para una prueba con menos datos
41
			BufferCacheManagerImpl.cacheSize = 2;
42
			BufferCacheManagerImpl.pageSize = 0.2;
43
			
44
			//Read input data
45
			input1 = new GdalRead(rasterIn);
46
			Object dataIn1 = input1.readBlock(0, 0, input1.getWidth(), input1.getHeight());
47
			input2 = new GdalRead(rasterIn);
48
			Object dataIn2 = input1.readBlock(0, 0, input2.getWidth(), input2.getHeight());
49
			
50
			//Create Buffer
51
			Buffer buf1 = new RasterCacheBuffer(input1.getRasterBufTypeFromGdalType(input1.getDataType()), 
52
														input1.getWidth(), 
53
														input1.getHeight(),
54
														input1.getBandCount());
55
			
56
			//Set data to buffer
57
			setLines(dataIn1, buf1);
58
			//Create Buffer
59
			Buffer buf2 = new RasterCacheBuffer(input2.getRasterBufTypeFromGdalType(input2.getDataType()), 
60
														input2.getWidth(), 
61
														input2.getHeight(),
62
														input2.getBandCount());
63
			
64
			//Set data to buffer
65
			setLines(dataIn2, buf2);
66
			
67
			Band rb = buf2.getBand(2);
68
			try {
69
				buf1.assignBand(1, rb);
70
			} catch (BandNotCompatibleException e) {
71
				e.printStackTrace();
72
			}
73
			
74
			//Write output file 
75
			out = new GdalWrite(rasterOut, 4, input1.getDataType(), input1.getWidth(), input1.getHeight(), GdalWrite.COLOR_INTERP_GRAY);
76
			out.writeBands(buf1.getBands());
77
			out.close();	
78
			
79
			Band band1 = buf1.getBand(1);
80
			Band band2 = buf1.getBand(3);
81
			for (int i = 0; i < band1.getHeight(); i++) {
82
				for (int j = 0; j < band1.getWidth(); j++) {
83
					byte b1 = band1.getElemByte(i, j);
84
					byte b2 = band2.getElemByte(i, j);
85
					assertEquals(b1, b2);
86
				}
87
			}
88
			
89
			buf1.free();
90
			buf2.free();
91
		} catch (GdalException e) {
92
			e.printStackTrace();
93
		} catch (IOException e) {
94
			e.printStackTrace();
95
		} catch (ProcessInterruptedException e) {
96
			e.printStackTrace();
97
		} catch (OperationNotSupportedException e) {
98
			e.printStackTrace();
99
		}
100
		long t2 = System.currentTimeMillis();
101
		System.out.println("Tiempo StripeCache TestAssignBand: " + (t2 - t1) + " milisegundos");
102
	}
103
	
104
	private void setLines(Object dataIn, Buffer buf) throws OperationNotSupportedException {
105
		if(dataIn instanceof byte[][][]) {
106
    		byte[][][] d = (byte[][][])dataIn;
107
    		for (int iBand = 0; iBand < d.length; iBand++) {
108
				for (int row = 0; row < d[iBand].length; row++) {
109
					buf.setLineInBandByte(d[iBand][row], row, iBand);
110
				}
111
			}
112
    	}
113
	}
114
	
115
}
0 116

  
org.gvsig.raster.cache/tags/org.gvsig.raster.cache-2.2.68/org.gvsig.raster.cache.lib.impl/deprecated/buffer/test/impl/stripecache/horizontal/AllTests.java
1
package org.gvsig.raster.cache.buffer.impl.stripecache.horizontal;
2

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

  
6
public class AllTests {
7

  
8
	public static Test suite() {
9
		TestSuite suite = new TestSuite(
10
				"Test for org.gvsig.raster.buffer.stripecache");
11
		//$JUnit-BEGIN$
12
		suite.addTestSuite(TestSwapTwoBands.class);
13
		suite.addTestSuite(TestAssignBand.class);
14
		suite.addTestSuite(TestCopyBand.class);
15
		suite.addTestSuite(TestRemoveBand.class);
16
		suite.addTestSuite(TestReplicateBand.class);
17
		suite.addTestSuite(TestAddBand.class);
18
		suite.addTestSuite(TestRWOneValue.class);
19
		suite.addTestSuite(TestCreateBand.class);
20
		suite.addTestSuite(TestRWTiffAndCompareData.class);
21
		suite.addTestSuite(TestSwapBands.class);
22
		suite.addTestSuite(TestCopyBand2.class);
23
		suite.addTestSuite(TestGetBufferWithOneBand.class);
24
		//$JUnit-END$
25
		return suite;
26
	}
27

  
28
}
0 29

  
org.gvsig.raster.cache/tags/org.gvsig.raster.cache-2.2.68/org.gvsig.raster.cache.lib.impl/deprecated/buffer/test/impl/stripecache/horizontal/TestGetBufferWithOneBand.java
1
package org.gvsig.raster.cache.buffer.impl.stripecache.horizontal;
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.io.GdalWrite;
14

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

  
31
	public void setUp() {
32
		System.err.println("StripeCache TestGetBufferWithOneBand running...");
33
	}
34
	
35
	public void testStack() {
36
		long t1 = System.currentTimeMillis();
37
		GdalRead input = null;
38
		try {
39
			//Reducimos el tama?o de la cache para una prueba con menos datos
40
			BufferCacheManagerImpl.cacheSize = 2;
41
			BufferCacheManagerImpl.pageSize = 0.2;
42
			
43
			//Read input data
44
			input = new GdalRead(rasterIn);
45
			Object dataIn = input.readBlock(0, 0, input.getWidth(), input.getHeight());
46
			
47
			//Create Buffer
48
			Buffer buf = new RasterCacheBuffer(input.getRasterBufTypeFromGdalType(input.getDataType()), 
49
														input.getWidth(), 
50
														input.getHeight(),
51
														input.getBandCount());
52
			
53
			//Set data to buffer
54
			setLines(dataIn, buf);
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
			for (int row = 0; row < buf.getHeight(); row++) {
74
				for (int col = 0; col < buf.getWidth(); col++) {
75
					byte b_0 = buf.getElemByte(row, col, 0);
76
					byte b_1 = buf.getElemByte(row, col, 1);
77
					byte b_2 = buf.getElemByte(row, col, 2);
78
					assertEquals(b_0, b0.getElemByte(row, col, 0));
79
					assertEquals(b_1, b1.getElemByte(row, col, 0));
80
					assertEquals(b_2, b2.getElemByte(row, col, 0));
81
				}
82
			}
83
			
84
			b0.free();
85
			b1.free();
86
			b2.free();
87
			buf.free();
88
				
89
		} catch (GdalException e) {
90
			e.printStackTrace();
91
		} catch (IOException e) {
92
			e.printStackTrace();
93
		} catch (ProcessInterruptedException e) {
94
			e.printStackTrace();
95
		} catch (OperationNotSupportedException e) {
96
			e.printStackTrace();
97
		}
98
		long t2 = System.currentTimeMillis();
99
		System.out.println("Tiempo StripeCache TestGetBufferWithOneBand: " + (t2 - t1) + " milisegundos");
100
	}
101
	
102
	private void setLines(Object dataIn, Buffer buf) throws OperationNotSupportedException {
103
		if(dataIn instanceof byte[][][]) {
104
    		byte[][][] d = (byte[][][])dataIn;
105
    		for (int iBand = 0; iBand < d.length; iBand++) {
106
				for (int row = 0; row < d[iBand].length; row++) {
107
					buf.setLineInBandByte(d[iBand][row], row, iBand);
108
				}
109
			}
110
    	}
111
	}
112
	
113
}
0 114

  
org.gvsig.raster.cache/tags/org.gvsig.raster.cache-2.2.68/org.gvsig.raster.cache.lib.impl/deprecated/buffer/test/impl/stripecache/horizontal/TestSwapTwoBands.java
1
package org.gvsig.raster.cache.buffer.impl.stripecache.horizontal;
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.exception.OperationNotSupportedException;
11
import org.gvsig.raster.cache.buffer.exception.ProcessInterruptedException;
12
import org.gvsig.raster.cache.buffer.exception.WrongParameterException;
13
import org.gvsig.raster.cache.buffer.impl.BufferCacheManagerImpl;
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 swap two bands of a raster and save the result in other file.
19
 * Finally it compares the output bands with the input bands.
20
 * 
21
 * @author Nacho Brodin (nachobrodin@gmail.com)
22
 */
23
public class TestSwapTwoBands extends TestCase {
24
	private String rasterIn = "./src/test/resources/image/001m09_1_0.tif";
25
	private String rasterOut = "/tmp/out-swapedTwo.tif";
26
	
27
	public void start() {
28
		this.setUp();
29
		this.testStack();
30
	}
31

  
32
	public void setUp() {
33
		System.err.println("StripeCache TestSwapTwoBands running...");
34
	}
35
	
36
	public void testStack() {
37
		long t1 = System.currentTimeMillis();
38
		GdalRead input1 = null;
39
		GdalWrite out = null;
40
		try {
41
			//Reducimos el tama?o de la cache para una prueba con menos datos
42
			BufferCacheManagerImpl.cacheSize = 2;
43
			BufferCacheManagerImpl.pageSize = 0.2;
44
			
45
			//Read input data
46
			input1 = new GdalRead(rasterIn);
47
			Object dataIn1 = input1.readBlock(0, 0, input1.getWidth(), input1.getHeight());
48
						
49
			//Create Buffer
50
			Buffer buf1 = new RasterCacheBuffer(input1.getRasterBufTypeFromGdalType(input1.getDataType()), 
51
														input1.getWidth(), 
52
														input1.getHeight(),
53
														input1.getBandCount());
54
			
55
			//Set data to buffer
56
			setLines(dataIn1, buf1);
57
						
58
			Buffer buf2 = new RasterCacheBuffer(input1.getRasterBufTypeFromGdalType(input1.getDataType()), 
59
														input1.getWidth(), 
60
														input1.getHeight(),
61
														input1.getBandCount());
62

  
63
			//Set data to buffer
64
			setLines(dataIn1, buf2);
65
			try {
66
				buf2.swapBands(0, 2);
67
			} catch (WrongParameterException e) {
68
				e.printStackTrace();
69
			}
70
			
71
			//Write output file 
72
			out = new GdalWrite(rasterOut, input1.getBandCount(), input1.getDataType(), input1.getWidth(), input1.getHeight(), GdalWrite.COLOR_INTERP_RGB);
73
			out.writeBands(buf2.getBands());
74
			out.close();	
75
			
76
			Band band1 = buf1.getBand(0);
77
			Band band2 = buf2.getBand(2);
78
			compareBands(band1, band2);
79
			
80
			band1 = buf1.getBand(2);
81
			band2 = buf2.getBand(0);
82
			compareBands(band1, band2);
83
			
84
			band1 = buf1.getBand(1);
85
			band2 = buf2.getBand(1);
86
			compareBands(band1, band2);
87
			
88
			buf1.free();
89
			buf2.free();
90
		} catch (GdalException e) {
91
			e.printStackTrace();
92
		} catch (IOException e) {
93
			e.printStackTrace();
94
		} catch (ProcessInterruptedException e) {
95
			e.printStackTrace();
96
		} catch (OperationNotSupportedException e) {
97
			e.printStackTrace();
98
		}
99
		long t2 = System.currentTimeMillis();
100
		System.out.println("Tiempo StripeCache TestSwapTwoBands: " + (t2 - t1) + " milisegundos");
101
	}
102
	
103
	public void compareBands(Band band1, Band band2) {
104
		for (int i = 0; i < band1.getHeight(); i++) {
105
			for (int j = 0; j < band1.getWidth(); j++) {
106
				byte b1 = band1.getElemByte(i, j);
107
				byte b2 = band2.getElemByte(i, j);
108
				assertEquals(b1, b2);
109
			}
110
		}
111
	}
112
	
113
	private void setLines(Object dataIn, Buffer buf) throws OperationNotSupportedException {
114
		if(dataIn instanceof byte[][][]) {
115
    		byte[][][] d = (byte[][][])dataIn;
116
    		for (int iBand = 0; iBand < d.length; iBand++) {
117
				for (int row = 0; row < d[iBand].length; row++) {
118
					buf.setLineInBandByte(d[iBand][row], row, iBand);
119
				}
120
			}
121
    	}
122
	}
123
	
124
}
0 125

  
org.gvsig.raster.cache/tags/org.gvsig.raster.cache-2.2.68/org.gvsig.raster.cache.lib.impl/deprecated/buffer/test/impl/stripecache/horizontal/TestAddBand.java
1
package org.gvsig.raster.cache.buffer.impl.stripecache.horizontal;
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.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.GdalRead;
14
import org.gvsig.raster.cache.buffer.impl.io.GdalWrite;
15

  
16
/**
17
 * This test add a band in a raster of 3 bands. As a result of this test a raster
18
 * of four bands is created and saved in the hard disk. The value of additional band
19
 * is zero in all its elements. Finally it gets the band added and compare each values 
20
 * with 0. 
21
 *  
22
 * @author Nacho Brodin (nachobrodin@gmail.com)
23
 */
24
public class TestAddBand extends TestCase {
25
	private String rasterIn = "./src/test/resources/image/001m09_1_0.tif";
26
	private String rasterOut = "/tmp/out-4bands.tif";
27
	
28
	public void start() {
29
		this.setUp();
30
		this.testStack();
31
	}
32

  
33
	public void setUp() {
34
		System.err.println("StripeCache TestAddBand running...");
35
	}
36
	
37
	public void testStack() {
38
		long t1 = System.currentTimeMillis();
39
		GdalRead input = null;
40
		GdalWrite out = null;
41
		try {
42
			//Reducimos el tama?o de la cache para una prueba con menos datos
43
			BufferCacheManagerImpl.cacheSize = 2;
44
			BufferCacheManagerImpl.pageSize = 0.2;
45
			
46
			//Read input data
47
			input = new GdalRead(rasterIn);
48
			Object dataIn = input.readBlock(0, 0, input.getWidth(), input.getHeight());
49
			
50
			//Create Buffer
51
			Buffer buf = new RasterCacheBuffer(input.getRasterBufTypeFromGdalType(input.getDataType()), 
52
														input.getWidth(), 
53
														input.getHeight(),
54
														input.getBandCount());
55
			
56
			//Set data to buffer
57
			setLines(dataIn, buf);
58
			buf.addBand(1);
59
			
60
			//Write output file 
61
			out = new GdalWrite(rasterOut, 4, input.getDataType(), input.getWidth(), input.getHeight(), GdalWrite.COLOR_INTERP_GRAY);
62
			out.writeBands(buf.getBands());
63
			out.close();	
64
			
65
			Band band = buf.getBand(1);
66
			for (int i = 0; i < band.getHeight(); i++) {
67
				for (int j = 0; j < band.getWidth(); j++) {
68
					byte b = band.getElemByte(i, j);
69
					assertEquals(0, b);
70
				}
71
			}
72
			
73
			buf.free();
74
		} catch (GdalException e) {
75
			e.printStackTrace();
76
		} catch (IOException e) {
77
			e.printStackTrace();
78
		} catch (ProcessInterruptedException e) {
79
			e.printStackTrace();
80
		} catch (OperationNotSupportedException e) {
81
			e.printStackTrace();
82
		}
83
		long t2 = System.currentTimeMillis();
84
		System.out.println("Tiempo StripeCache TestAddBand: " + (t2 - t1) + " milisegundos");
85
	}
86
	
87
	private void setLines(Object dataIn, Buffer buf) throws OperationNotSupportedException {
88
		if(dataIn instanceof byte[][][]) {
89
    		byte[][][] d = (byte[][][])dataIn;
90
    		for (int iBand = 0; iBand < d.length; iBand++) {
91
				for (int row = 0; row < d[iBand].length; row++) {
92
					buf.setLineInBandByte(d[iBand][row], row, iBand);
93
				}
94
			}
95
    	}
96
	}
97
	
98
}
0 99

  
org.gvsig.raster.cache/tags/org.gvsig.raster.cache-2.2.68/org.gvsig.raster.cache.lib.impl/deprecated/buffer/test/impl/stripecache/horizontal/TestReplicateBand.java
1
package org.gvsig.raster.cache.buffer.impl.stripecache.horizontal;
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.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.GdalRead;
14
import org.gvsig.raster.cache.buffer.impl.io.GdalWrite;
15

  
16
/** 
17
 * This test insert one band at the end of the layer. The data of this new band is a copy 
18
 * of the band in position zero. Finally data of band zero and band three are compared
19
 * checking if both have the same values. 
20
 *  
21
 * @author Nacho Brodin (nachobrodin@gmail.com)
22
 */
23
public class TestReplicateBand extends TestCase {
24
	private String rasterIn = "./src/test/resources/image/001m09_1_0.tif";
25
	private String rasterOut = "/tmp/out-replicateBands.tif";
26
	
27
	public void start() {
28
		this.setUp();
29
		this.testStack();
30
	}
31

  
32
	public void setUp() {
33
		System.err.println("StripeCache TestReplicateBand running...");
34
	}
35
	
36
	public void testStack() {
37
		long t1 = System.currentTimeMillis();
38
		GdalRead input1 = null;
39
		GdalWrite out = null;
40
		try {
41
			//Reducimos el tama?o de la cache para una prueba con menos datos
42
			BufferCacheManagerImpl.cacheSize = 2;
43
			BufferCacheManagerImpl.pageSize = 0.2;
44
			
45
			//Read input data
46
			input1 = new GdalRead(rasterIn);
47
			Object dataIn1 = input1.readBlock(0, 0, input1.getWidth(), input1.getHeight());
48
			
49
			//Create Buffer
50
			Buffer buf1 = new RasterCacheBuffer(input1.getRasterBufTypeFromGdalType(input1.getDataType()), 
51
														input1.getWidth(), 
52
														input1.getHeight(),
53
														input1.getBandCount());
54
			
55
			//Set data to buffer
56
			setLines(dataIn1, buf1);
57
						
58
			buf1.replicateBand(0, 3);
59
			
60
			//Write output file 
61
			out = new GdalWrite(rasterOut, 4, input1.getDataType(), input1.getWidth(), input1.getHeight(), GdalWrite.COLOR_INTERP_GRAY);
62
			out.writeBands(buf1.getBands());
63
			out.close();	
64
			
65
			Band band1 = buf1.getBand(0);
66
			Band band2 = buf1.getBand(3);
67
			for (int i = 0; i < band1.getHeight(); i++) {
68
				for (int j = 0; j < band1.getWidth(); j++) {
69
					byte b1 = band1.getElemByte(i, j);
70
					byte b2 = band2.getElemByte(i, j);
71
					assertEquals(b1, b2);
72
				}
73
			}
74
			
75
			buf1.free();
76
		} catch (GdalException e) {
77
			e.printStackTrace();
78
		} catch (IOException e) {
79
			e.printStackTrace();
80
		} catch (ProcessInterruptedException e) {
81
			e.printStackTrace();
82
		} catch (OperationNotSupportedException e) {
83
			e.printStackTrace();
84
		}
85
		long t2 = System.currentTimeMillis();
86
		System.out.println("Tiempo StripeCache TestReplicateBand: " + (t2 - t1) + " milisegundos");
87
	}
88
	
89
	private void setLines(Object dataIn, Buffer buf) throws OperationNotSupportedException {  
90
		if(dataIn instanceof byte[][][]) {
91
    		byte[][][] d = (byte[][][])dataIn;
92
    		for (int iBand = 0; iBand < d.length; iBand++) {
93
				for (int row = 0; row < d[iBand].length; row++) {
94
					buf.setLineInBandByte(d[iBand][row], row, iBand);
95
				}
96
			}
97
    	}
98
	}
99
	
100
}
0 101

  
org.gvsig.raster.cache/tags/org.gvsig.raster.cache-2.2.68/org.gvsig.raster.cache.lib.impl/deprecated/buffer/test/impl/stripecache/horizontal/TestCopyBand.java
1
package org.gvsig.raster.cache.buffer.impl.stripecache.horizontal;
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.exception.BandNotCompatibleException;
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.BufferCacheManagerImpl;
14
import org.gvsig.raster.cache.buffer.impl.io.GdalRead;
15
import org.gvsig.raster.cache.buffer.impl.io.GdalWrite;
16

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

  
31
	public void setUp() {
32
		System.err.println("StripeCache TestCopyBand running...");
33
	}
34
	
35
	public void testStack() {
36
		long t1 = System.currentTimeMillis();
37
		GdalRead input = null;
38
		GdalWrite out = null;
39
		try {
40
			//Reducimos el tama?o de la cache para una prueba con menos datos
41
			BufferCacheManagerImpl.cacheSize = 2;
42
			BufferCacheManagerImpl.pageSize = 0.2;
43
			
44
			//Read input data
45
			input = new GdalRead(rasterIn);
46
			Object dataIn = input.readBlock(0, 0, input.getWidth(), input.getHeight());
47
			
48
			//Create Buffer
49
			Buffer buf1 = new RasterCacheBuffer(input.getRasterBufTypeFromGdalType(input.getDataType()), 
50
														input.getWidth(), 
51
														input.getHeight(),
52
														input.getBandCount());
53
			
54
			//Set data to buffer
55
			setLines(dataIn, buf1);
56
			
57
			
58
			Band rb = buf1.getBandCopy(0);
59
			
60
			try {
61
				buf1.copyBand(2, rb);
62
			} catch (BandNotCompatibleException e) {
63
				e.printStackTrace();
64
			}
65
			
66
			//Write output file 
67
			out = new GdalWrite(rasterOut, 3, input.getDataType(), input.getWidth(), input.getHeight(), GdalWrite.COLOR_INTERP_RGB);
68
			out.writeBands(buf1.getBands());
69
			out.close();	
70
			
71
			Band band1 = buf1.getBand(0);
72
			Band band2 = buf1.getBand(2);
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
		} catch (GdalException e) {
83
			e.printStackTrace();
84
		} catch (IOException e) {
85
			e.printStackTrace();
86
		} catch (ProcessInterruptedException e) {
87
			e.printStackTrace();
88
		} catch (OperationNotSupportedException e) {
89
			e.printStackTrace();
90
		}
91
		long t2 = System.currentTimeMillis();
92
		System.out.println("Tiempo StripeCache TestCopyBand: " + (t2 - t1) + " milisegundos");
93
	}
94
	
95
	private void setLines(Object dataIn, Buffer buf) throws OperationNotSupportedException {
96
		if(dataIn instanceof byte[][][]) {
97
    		byte[][][] d = (byte[][][])dataIn;
98
    		for (int iBand = 0; iBand < d.length; iBand++) {
99
				for (int row = 0; row < d[iBand].length; row++) {
100
					buf.setLineInBandByte(d[iBand][row], row, iBand);
101
				}
102
			}
103
    	}
104
	}
105
	
106
}
0 107

  
org.gvsig.raster.cache/tags/org.gvsig.raster.cache-2.2.68/org.gvsig.raster.cache.lib.impl/deprecated/buffer/test/impl/stripecache/horizontal/TestCopyBand2.java
1
package org.gvsig.raster.cache.buffer.impl.stripecache.horizontal;
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.exception.BandNotCompatibleException;
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.BufferCacheManagerImpl;
14
import org.gvsig.raster.cache.buffer.impl.io.GdalRead;
15
import org.gvsig.raster.cache.buffer.impl.io.GdalWrite;
16

  
17
/**
18
 * Copy the band 0 from a buffer over the band 2 of other buffer using the
19
 * method getBand (reference).
20
 * @author Nacho Brodin (nachobrodin@gmail.com)
21
 */
22
public class TestCopyBand2 extends TestCase {
23
	private String rasterIn = "./src/test/resources/image/001m09_1_0.tif";
24
	private String rasterOut = "/tmp/out-copyFirstBand.tif";
25
	
26
	public void start() {
27
		this.setUp();
28
		this.testStack();
29
	}
30

  
31
	public void setUp() {
32
		System.err.println("StripeCache TestCopyBand2 running...");
33
	}
34
	
35
	public void testStack() {
36
		long t1 = System.currentTimeMillis();
37
		GdalRead input = null;
38
		GdalWrite out = null;
39
		try {
40
			//Reducimos el tama?o de la cache para una prueba con menos datos
41
			BufferCacheManagerImpl.cacheSize = 2;
42
			BufferCacheManagerImpl.pageSize = 0.2;
43
			
44
			//Read input data
45
			input = new GdalRead(rasterIn);
46
			Object dataIn = input.readBlock(0, 0, input.getWidth(), input.getHeight());
47
			
48
			//Create Buffer
49
			Buffer buf1 = new RasterCacheBuffer(input.getRasterBufTypeFromGdalType(input.getDataType()), 
50
														input.getWidth(), 
51
														input.getHeight(),
52
														input.getBandCount());
53
			
54
			//Set data to buffer
55
			setLines(dataIn, buf1);
56
			
57
			//Create Buffer
58
			Buffer buf2 = new RasterCacheBuffer(input.getRasterBufTypeFromGdalType(input.getDataType()), 
59
														input.getWidth(), 
60
														input.getHeight(),
61
														input.getBandCount());
62
			
63
			//Set data to buffer
64
			setLines(dataIn, buf2);
65
			
66
			Band rb = buf1.getBand(0);
67
			
68
			try {
69
				buf2.copyBand(2, rb);
70
			} catch (BandNotCompatibleException e) {
71
				e.printStackTrace();
72
			}
73
			
74
			//Write output file 
75
			out = new GdalWrite(rasterOut, 3, input.getDataType(), input.getWidth(), input.getHeight(), GdalWrite.COLOR_INTERP_RGB);
76
			out.writeBands(buf2.getBands());
77
			out.close();	
78
			
79
			Band band1 = buf1.getBand(0);
80
			Band band2 = buf2.getBand(2);
81
			for (int i = 0; i < band1.getHeight(); i++) {
82
				for (int j = 0; j < band1.getWidth(); j++) {
83
					byte b1 = band1.getElemByte(i, j);
84
					byte b2 = band2.getElemByte(i, j);
85
					assertEquals(b1, b2);
86
				}
87
			}
88
			
89
			buf1.free();
90
			buf2.free();
91
		} catch (GdalException e) {
92
			e.printStackTrace();
93
		} catch (IOException e) {
94
			e.printStackTrace();
95
		} catch (ProcessInterruptedException e) {
96
			e.printStackTrace();
97
		} catch (OperationNotSupportedException e) {
98
			e.printStackTrace();
99
		}
100
		long t2 = System.currentTimeMillis();
101
		System.out.println("Tiempo StripeCache TestCopyBand2: " + (t2 - t1) + " milisegundos");
102
	}
103
	
104
	private void setLines(Object dataIn, Buffer buf) throws OperationNotSupportedException {
105
		if(dataIn instanceof byte[][][]) {
106
    		byte[][][] d = (byte[][][])dataIn;
107
    		for (int iBand = 0; iBand < d.length; iBand++) {
108
				for (int row = 0; row < d[iBand].length; row++) {
109
					buf.setLineInBandByte(d[iBand][row], row, iBand);
110
				}
111
			}
112
    	}
113
	}
114
	
115
}
0 116

  
org.gvsig.raster.cache/tags/org.gvsig.raster.cache-2.2.68/org.gvsig.raster.cache.lib.impl/deprecated/buffer/test/impl/stripecache/horizontal/TestRemoveBand.java
1
package org.gvsig.raster.cache.buffer.impl.stripecache.horizontal;
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.io.GdalWrite;
14

  
15
/**
16
 * This test read a RGB image and remove one band from the read buffer. Then compare 
17
 * the bands that have not been removed with the source bands. As a result of this test a raster
18
 * of two bands is created and saved in the hard disk
19
 * 
20
 * @author Nacho Brodin (nachobrodin@gmail.com)
21
 */
22
public class TestRemoveBand extends TestCase {
23
	private String rasterIn = "./src/test/resources/image/001m09_1_0.tif";
24
	private String rasterOut = "/tmp/out-2bands.tif";
25
	
26
	public void start() {
27
		this.setUp();
28
		this.testStack();
29
	}
30

  
31
	public void setUp() {
32
		System.err.println("StripeCache TestRemoveBand running...");
33
	}
34
	
35
	public void testStack() {
36
		long t1 = System.currentTimeMillis();
37
		GdalRead input = null;
38
		GdalWrite out = null;
39
		try {
40
			//Reducimos el tama?o de la cache para una prueba con menos datos
41
			BufferCacheManagerImpl.cacheSize = 2;
42
			BufferCacheManagerImpl.pageSize = 0.2;
43
			
44
			//Read input data
45
			input = new GdalRead(rasterIn);
46
			Object dataIn = input.readBlock(0, 0, input.getWidth(), input.getHeight());
47
			
48
			//Create Buffer
49
			Buffer buf = new RasterCacheBuffer(input.getRasterBufTypeFromGdalType(input.getDataType()), 
50
														input.getWidth(), 
51
														input.getHeight(),
52
														input.getBandCount());
53
			
54
			//Set data to buffer
55
			setLines(dataIn, buf);
56
			buf.removeBand(1);
57
			
58
			//Write output file 
59
			out = new GdalWrite(rasterOut, 2, input.getDataType(), input.getWidth(), input.getHeight(), GdalWrite.COLOR_INTERP_GRAY);
60
			out.writeBands(buf.getBands());
61
			buf.free();
62
			out.close();	
63
			
64
			//Open output file and compare
65
			GdalRead newFile = new GdalRead(rasterOut);
66
			Object dataOut = newFile.readBlock(0, 0, input.getWidth(), input.getHeight());
67
			
68
			byte[][][] d1 = (byte[][][])dataOut;
69
			byte[][][] d2 = (byte[][][])dataIn;
70
			
71
			for (int row = 0; row < buf.getHeight(); row++) {
72
				for (int col = 0; col < buf.getWidth(); col++) {
73
					if(d1[0][row][col] != d2[0][row][col])
74
						System.out.println("BAND:" + 0 +" ROW:" + row + " COL:" + col + " " + d1[0][row][col] + " " + d2[0][row][col]);
75
					assertEquals(d1[0][row][col], d2[0][row][col]);
76
				}
77
			}
78
				
79
			for (int row = 0; row < buf.getHeight(); row++) {
80
				for (int col = 0; col < buf.getWidth(); col++) {
81
					if(d1[1][row][col] != d2[2][row][col])
82
						System.out.println("BAND:" + 1 +" ROW:" + row + " COL:" + col + " " + d1[1][row][col] + " " + d2[2][row][col]);
83
					assertEquals(d1[1][row][col], d2[2][row][col]);
84
				}
85
			}
86
			
87
		} catch (GdalException e) {
88
			e.printStackTrace();
89
		} catch (IOException e) {
90
			e.printStackTrace();
91
		} catch (ProcessInterruptedException e) {
92
			e.printStackTrace();
93
		} catch (OperationNotSupportedException e) {
94
			e.printStackTrace();
95
		}
96
		long t2 = System.currentTimeMillis();
97
		System.out.println("Tiempo StripeCache TestRemoveBand: " + (t2 - t1) + " milisegundos");
98
	}
99
	
100
	private void setLines(Object dataIn, Buffer buf) throws OperationNotSupportedException {
101
		if(dataIn instanceof byte[][][]) {
102
    		byte[][][] d = (byte[][][])dataIn;
103
    		for (int iBand = 0; iBand < d.length; iBand++) {
104
				for (int row = 0; row < d[iBand].length; row++) {
105
					buf.setLineInBandByte(d[iBand][row], row, iBand);
106
				}
107
			}
108
    	}
109
	}
110
	
111
}
0 112

  
org.gvsig.raster.cache/tags/org.gvsig.raster.cache-2.2.68/org.gvsig.raster.cache.lib.impl/deprecated/buffer/test/impl/stripecache/horizontal/TestSwapBands.java
1
package org.gvsig.raster.cache.buffer.impl.stripecache.horizontal;
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.exception.OperationNotSupportedException;
11
import org.gvsig.raster.cache.buffer.exception.ProcessInterruptedException;
12
import org.gvsig.raster.cache.buffer.exception.WrongParameterException;
13
import org.gvsig.raster.cache.buffer.impl.BufferCacheManagerImpl;
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 swap several bands of a raster and save the result in other file.
19
 * Finally it compares the output bands with the input bands.
20
 * <P>
21
 * The array to test is {2, 0, 1}. That means the band 0 goes to the position two, the
22
 * band one goes to the position zero and the band two goes to the position one. 
23
 * When the swap operation is executed, this test will check comparing the result 
24
 * bands with the input bands 
25
 * </P>
26
 * @author Nacho Brodin (nachobrodin@gmail.com)
27
 */
28
public class TestSwapBands extends TestCase {
29
	private String rasterIn = "./src/test/resources/image/001m09_1_0.tif";
30
	private String rasterOut = "/tmp/out-swaped.tif";
31
	
32
	public void start() {
33
		this.setUp();
34
		this.testStack();
35
	}
36

  
37
	public void setUp() {
38
		System.err.println("StripeCache TestSwapBands running...");
39
	}
40
	
41
	public void testStack() {
42
		long t1 = System.currentTimeMillis();
43
		GdalRead input1 = null;
44
		GdalWrite out = null;
45
		try {
46
			//Reducimos el tama?o de la cache para una prueba con menos datos
47
			BufferCacheManagerImpl.cacheSize = 2;
48
			BufferCacheManagerImpl.pageSize = 0.2;
49
			
50
			//Read input data
51
			input1 = new GdalRead(rasterIn);
52
			Object dataIn1 = input1.readBlock(0, 0, input1.getWidth(), input1.getHeight());
53
						
54
			//Create Buffer
55
			Buffer buf1 = new RasterCacheBuffer(input1.getRasterBufTypeFromGdalType(input1.getDataType()), 
56
														input1.getWidth(), 
57
														input1.getHeight(),
58
														input1.getBandCount());
59
			
60
			//Set data to buffer
61
			setBytes(dataIn1, buf1);
62
						
63
			Buffer buf2 = new RasterCacheBuffer(input1.getRasterBufTypeFromGdalType(input1.getDataType()), 
64
														input1.getWidth(), 
65
														input1.getHeight(),
66
														input1.getBandCount());
67

  
68
			//Set data to buffer
69
			setBytes(dataIn1, buf2);
70
			try {
71
				buf2.swapBands(new int[]{2, 0, 1});
72
			} catch (WrongParameterException e) {
73
				e.printStackTrace();
74
			}
75
			
76
			//Write output file 
77
			out = new GdalWrite(rasterOut, input1.getBandCount(), input1.getDataType(), input1.getWidth(), input1.getHeight(), GdalWrite.COLOR_INTERP_RGB);
78
			out.writeBands(buf2.getBands());
79
			out.close();	
80
			
81
			Band band1 = buf1.getBand(0);
82
			Band band2 = buf2.getBand(1);
83
			compareBands(band1, band2);
84
			
85
			band1 = buf1.getBand(1);
86
			band2 = buf2.getBand(2);
87
			compareBands(band1, band2);
88
			
89
			band1 = buf1.getBand(2);
90
			band2 = buf2.getBand(0);
91
			compareBands(band1, band2);
92
			
93
			buf1.free();
94
			buf2.free();
95
		} catch (GdalException e) {
96
			e.printStackTrace();
97
		} catch (IOException e) {
98
			e.printStackTrace();
99
		} catch (ProcessInterruptedException e) {
100
			e.printStackTrace();
101
		} catch (OperationNotSupportedException e) {
102
			e.printStackTrace();
103
		}
104
		long t2 = System.currentTimeMillis();
105
		System.out.println("Tiempo StripeCache TestSwapBands: " + (t2 - t1) + " milisegundos");
106
	}
107
	
108
	public void compareBands(Band band1, Band band2) {
109
		for (int i = 0; i < band1.getHeight(); i++) {
110
			for (int j = 0; j < band1.getWidth(); j++) {
111
				byte b1 = band1.getElemByte(i, j);
112
				byte b2 = band2.getElemByte(i, j);
113
				assertEquals(b1, b2);
114
			}
115
		}
116
	}
117
	
118
	/*private void setLines(Object dataIn, Buffer buf) throws OperationNotSupportedException {
119
		if(dataIn instanceof byte[][][]) {
120
    		byte[][][] d = (byte[][][])dataIn;
121
    		for (int iBand = 0; iBand < d.length; iBand++) {
122
				for (int row = 0; row < d[iBand].length; row++) {
123
					buf.setLineInBandByte(d[iBand][row], row, iBand);
124
				}
125
			}
126
    	}
127
	}*/
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff