Revision 12132

View differences:

org.gvsig.raster.cache/tags/org.gvsig.raster.cache-2.2.61/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.61</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.61</connection>
12
        <developerConnection>scm:svn:https://devel.gvsig.org/svn/gvsig-raster/org.gvsig.raster.cache/tags/org.gvsig.raster.cache-2.2.61</developerConnection>
13
        <url>https://devel.gvsig.org/redmine/projects/gvsig-raster/repository/show/org.gvsig.raster.cache/tags/org.gvsig.raster.cache-2.2.61</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.290</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.61</version>
63
            </dependency>
64
            <dependency>
65
                <groupId>org.gvsig</groupId>
66
                <artifactId>org.gvsig.raster.cache.lib.impl</artifactId>
67
                <version>2.2.61</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.61/org.gvsig.raster.cache.lib.impl/deprecated/buffer/test/impl/TestStatistics.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.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.io.BufferDataSourceImpl;
14
import org.gvsig.raster.cache.buffer.impl.io.GdalRead;
15
import org.gvsig.raster.cache.buffer.impl.memory.RasterMemoryBuffer;
16
import org.gvsig.raster.cache.buffer.impl.rocache.RasterReadOnlyBuffer;
17
import org.gvsig.raster.cache.buffer.impl.stripecache.horizontal.RasterCacheBuffer;
18

  
19
/**
20
 * This test calculate the statistics of a image and compare the result with 
21
 * the correct values. 
22
 *  
23
 * @author Nacho Brodin (nachobrodin@gmail.com)
24
 */
25
public class TestStatistics extends TestCase {
26
	private String rasterIn = "./src/test/resources/image/001m09_1_0.tif";
27
	
28
	public void start() {
29
		this.setUp();
30
		this.testStack();
31
	}
32

  
33
	public void setUp() {
34
		System.err.println("TestStatistics running...");
35
	}
36
	
37
	public void testStack() {
38
		long t1 = System.currentTimeMillis();
39
		GdalRead input = null;
40
		try {
41
	
42
			//Read input data
43
			input = new GdalRead(rasterIn);
44
			Object dataIn = input.readBlock(0, 0, input.getWidth(), input.getHeight());
45
			
46
			//MEMORY
47
			Buffer buf = 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, buf);
55
			buf.getStatistics().calculate();			
56
			test(buf);
57
			buf.free();
58
			
59
			//CACHE
60
			buf = new RasterCacheBuffer(input.getRasterBufTypeFromGdalType(input.getDataType()), 
61
										input.getWidth(), 
62
										input.getHeight(),
63
										input.getBandCount());
64
			
65
			//Set data to buffer
66
			setLines(dataIn, buf);
67
			buf.getStatistics().calculate();			
68
			test(buf);
69
			buf.free();
70
			
71
			//READ ONLY
72
			BufferDataSource ds = null;
73
			try {
74
				ds = new BufferDataSourceImpl(rasterIn);
75
			} catch (IOException e) {
76
				e.printStackTrace();
77
			}
78
			buf = new RasterReadOnlyBuffer(ds);
79
			buf.getStatistics().calculate();			
80
			test(buf);
81
			buf.free();
82
			
83
		} catch (GdalException e) {
84
			e.printStackTrace();
85
		} catch (IOException e) {
86
			e.printStackTrace();
87
		} catch (ProcessInterruptedException e) {
88
			e.printStackTrace();
89
		}  catch (OperationNotSupportedException e) {
90
			e.printStackTrace();
91
		}
92
		long t2 = System.currentTimeMillis();
93
		System.out.println("Tiempo TestStatistics: " + (t2 - t1) + " milisegundos");
94
	}
95
	
96
	private void test(Buffer buf) {
97
		for (int i = 0; i < buf.getBandCount(); i++) {
98
			Band b = buf.getBand(i);
99
			/*System.out.println("Band " + i);
100
			System.out.println("Max: " + b.getMax());
101
			System.out.println("Min: " + b.getMin());
102
			System.out.println("Max RGB: " + b.getMaxRGB());
103
			System.out.println("Min RGB: " + b.getMinRGB());
104
			System.out.println("SecondMax: " + b.getSecondMax());
105
			System.out.println("SecondMin: " + b.getSecondMin());
106
			System.out.println("SecondMax RGB: " + b.getSecondMaxRGB());
107
			System.out.println("SecondMin RGB: " + b.getSecondMinRGB());
108
			System.out.println("Mean: " + b.getMean());*/
109
			if(i == 0) {
110
				assertEquals((int)b.getMax(), 124);
111
				assertEquals((int)b.getMin(), -125);
112
				assertEquals((int)b.getMaxRGB(), 255);
113
				assertEquals((int)b.getMinRGB(), 0);
114
				assertEquals((int)b.getSecondMax(), 118);
115
				assertEquals((int)b.getSecondMin(), -119);
116
				assertEquals((int)b.getSecondMaxRGB(), 249);
117
				assertEquals((int)b.getSecondMinRGB(), 6);
118
				assertEquals((int)b.getMean(), 79);
119
			}
120
			if(i == 1) {
121
				assertEquals((int)b.getMax(), 120);
122
				assertEquals((int)b.getMin(), -128);
123
				assertEquals((int)b.getMaxRGB(), 255);
124
				assertEquals((int)b.getMinRGB(), 0);
125
				assertEquals((int)b.getSecondMax(), 113);
126
				assertEquals((int)b.getSecondMin(), -121);
127
				assertEquals((int)b.getSecondMaxRGB(), 248);
128
				assertEquals((int)b.getSecondMinRGB(), 8);
129
				assertEquals((int)b.getMean(), 88);
130
			}
131
			if(i == 2) {
132
				assertEquals((int)b.getMax(), 115);
133
				assertEquals((int)b.getMin(), -128);
134
				assertEquals((int)b.getMaxRGB(), 255);
135
				assertEquals((int)b.getMinRGB(), 0);
136
				assertEquals((int)b.getSecondMax(), 102);
137
				assertEquals((int)b.getSecondMin(), -116);
138
				assertEquals((int)b.getSecondMaxRGB(), 242);
139
				assertEquals((int)b.getSecondMinRGB(), 13);
140
				assertEquals((int)b.getMean(), 91);
141
			}
142
		}
143
	}
144
	
145
	private void setLines(Object dataIn, Buffer buf) throws OperationNotSupportedException {
146
		if(dataIn instanceof byte[][][]) {
147
    		byte[][][] d = (byte[][][])dataIn;
148
    		for (int iBand = 0; iBand < d.length; iBand++) {
149
				for (int row = 0; row < d[iBand].length; row++) {
150
					buf.setLineInBandByte(d[iBand][row], row, iBand);
151
				}
152
			}
153
    	}
154
	}
155
	
156
}
0 157

  
org.gvsig.raster.cache/tags/org.gvsig.raster.cache-2.2.61/org.gvsig.raster.cache.lib.impl/deprecated/buffer/test/impl/AllTests.java
1
package org.gvsig.raster.cache.buffer.impl;
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");
11
		//$JUnit-BEGIN$
12
		suite.addTestSuite(org.gvsig.raster.cache.buffer.impl.memory.TestSwapBands.class);
13
		suite.addTestSuite(org.gvsig.raster.cache.buffer.impl.memory.TestMemoryBuffer.class);
14
		suite.addTestSuite(org.gvsig.raster.cache.buffer.impl.memory.TestRemoveBand.class);
15
		suite.addTestSuite(org.gvsig.raster.cache.buffer.impl.memory.TestAddBand.class);
16
		suite.addTestSuite(org.gvsig.raster.cache.buffer.impl.memory.TestSwapTwoBands.class);
17
		suite.addTestSuite(org.gvsig.raster.cache.buffer.impl.memory.TestCopyBand.class);
18
		suite.addTestSuite(org.gvsig.raster.cache.buffer.impl.memory.TestGetBufferWithOneBand.class);
19
		suite.addTestSuite(org.gvsig.raster.cache.buffer.impl.memory.TestReplicateBand.class);
20
		suite.addTestSuite(org.gvsig.raster.cache.buffer.impl.memory.TestRWOneValue.class);
21
		suite.addTestSuite(org.gvsig.raster.cache.buffer.impl.memory.TestCopyBand2.class);
22
		suite.addTestSuite(org.gvsig.raster.cache.buffer.impl.memory.TestCreateBand.class);
23
		suite.addTestSuite(org.gvsig.raster.cache.buffer.impl.memory.TestAssignBand.class);
24
		suite.addTestSuite(org.gvsig.raster.cache.buffer.impl.memory.TestRWTiffAndCompareData.class);
25
		
26
		suite.addTestSuite(org.gvsig.raster.cache.buffer.impl.rocache.TestReplicateBand.class);
27
		suite.addTestSuite(org.gvsig.raster.cache.buffer.impl.rocache.TestSwapBands.class);
28
		suite.addTestSuite(org.gvsig.raster.cache.buffer.impl.rocache.TestReadTiffAndCompareData.class);
29
		suite.addTestSuite(org.gvsig.raster.cache.buffer.impl.rocache.TestSwapTwoBands.class);
30
		suite.addTestSuite(org.gvsig.raster.cache.buffer.impl.rocache.TestRemoveBand.class);
31
		suite.addTestSuite(org.gvsig.raster.cache.buffer.impl.rocache.TestGetBufferWithOneBand.class);
32
		suite.addTestSuite(org.gvsig.raster.cache.buffer.impl.rocache.TestAssignBand.class);
33
		suite.addTestSuite(org.gvsig.raster.cache.buffer.impl.rocache.TestCopyBand.class);
34
		suite.addTestSuite(org.gvsig.raster.cache.buffer.impl.rocache.TestAddBand.class);
35
		suite.addTestSuite(org.gvsig.raster.cache.buffer.impl.rocache.TestWindow.class);
36
		
37
		suite.addTestSuite(org.gvsig.raster.cache.buffer.impl.stripecache.horizontal.TestSwapTwoBands.class);
38
		suite.addTestSuite(org.gvsig.raster.cache.buffer.impl.stripecache.horizontal.TestAssignBand.class);
39
		suite.addTestSuite(org.gvsig.raster.cache.buffer.impl.stripecache.horizontal.TestCopyBand.class);
40
		suite.addTestSuite(org.gvsig.raster.cache.buffer.impl.stripecache.horizontal.TestRemoveBand.class);
41
		suite.addTestSuite(org.gvsig.raster.cache.buffer.impl.stripecache.horizontal.TestReplicateBand.class);
42
		suite.addTestSuite(org.gvsig.raster.cache.buffer.impl.stripecache.horizontal.TestAddBand.class);
43
		suite.addTestSuite(org.gvsig.raster.cache.buffer.impl.stripecache.horizontal.TestRWOneValue.class);
44
		suite.addTestSuite(org.gvsig.raster.cache.buffer.impl.stripecache.horizontal.TestCreateBand.class);
45
		suite.addTestSuite(org.gvsig.raster.cache.buffer.impl.stripecache.horizontal.TestRWTiffAndCompareData.class);
46
		suite.addTestSuite(org.gvsig.raster.cache.buffer.impl.stripecache.horizontal.TestSwapBands.class);
47
		suite.addTestSuite(org.gvsig.raster.cache.buffer.impl.stripecache.horizontal.TestCopyBand2.class);
48
		suite.addTestSuite(org.gvsig.raster.cache.buffer.impl.stripecache.horizontal.TestGetBufferWithOneBand.class);
49
		
50
		suite.addTestSuite(TestInterpolationBicubicIncrease.class);
51
		suite.addTestSuite(TestInterpolationBicubicReduction.class);
52
		suite.addTestSuite(TestInterpolationBilinearIncrease.class);
53
		suite.addTestSuite(TestInterpolationBilinearReduction.class);
54
		suite.addTestSuite(TestInterpolationBSplineIncrease.class);
55
		suite.addTestSuite(TestInterpolationBSplineReduction.class);
56
		suite.addTestSuite(TestInterpolationInvDistanceIncrease.class);
57
		suite.addTestSuite(TestInterpolationInvDistanceReduction.class);
58
		suite.addTestSuite(TestInterpolationNearestIncrease.class);
59
		suite.addTestSuite(TestInterpolationNearestReduction.class);
60
		suite.addTestSuite(TestStatistics.class);
61
		//$JUnit-END$
62
		return suite;
63
	}
64

  
65
}
0 66

  
org.gvsig.raster.cache/tags/org.gvsig.raster.cache-2.2.61/org.gvsig.raster.cache.lib.impl/deprecated/buffer/test/impl/TestInterpolationInvDistanceReduction.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 TestInterpolationInvDistanceReduction extends TestCase {
21
	private String         rasterIn  = "./src/test/resources/image/001m09_1_0.tif";
22
	private String         rasterOut = "/tmp/out-interpInvDistanceReduction.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("TestInterpolationInvDistanceReduction 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_InverseDistance);
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 TestInterpolationInvDistanceReduction: " + (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/org.gvsig.raster.cache-2.2.61/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.61/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.61/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.61/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.61/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.61/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.61/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.61/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.61/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.61/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++) {
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff