Source Code Cross Referenced for SampleTranscoderTest.java in  » GIS » GeoTools-2.4.1 » org » geotools » coverage » grid » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » GIS » GeoTools 2.4.1 » org.geotools.coverage.grid 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *    GeoTools - OpenSource mapping toolkit
003:         *    http://geotools.org
004:         *    (C) 2003-2006, Geotools Project Managment Committee (PMC)
005:         *    (C) 2002, Institut de Recherche pour le Développement
006:         *
007:         *    This library is free software; you can redistribute it and/or
008:         *    modify it under the terms of the GNU Lesser General Public
009:         *    License as published by the Free Software Foundation; either
010:         *    version 2.1 of the License, or (at your option) any later version.
011:         *
012:         *    This library is distributed in the hope that it will be useful,
013:         *    but WITHOUT ANY WARRANTY; without even the implied warranty of
014:         *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
015:         *    Lesser General Public License for more details.
016:         */
017:        package org.geotools.coverage.grid;
018:
019:        // J2SE dependencies
020:        import java.awt.image.BufferedImage;
021:        import java.awt.image.DataBuffer;
022:        import java.awt.image.DataBufferByte;
023:        import java.awt.image.RenderedImage;
024:        import java.util.Random;
025:
026:        // JAI dependencies
027:        import javax.media.jai.PlanarImage;
028:        import javax.media.jai.RenderedImageAdapter;
029:        import javax.media.jai.RenderedOp;
030:
031:        // JUnit dependencies
032:        import junit.framework.Test;
033:        import junit.framework.TestCase;
034:        import junit.framework.TestSuite;
035:
036:        // OpenGIS dependencies
037:        import org.opengis.referencing.operation.MathTransform;
038:        import org.opengis.referencing.operation.TransformException;
039:
040:        // Geotools dependencies
041:        import org.geotools.coverage.Category;
042:        import org.geotools.coverage.CategoryListTest;
043:        import org.geotools.coverage.FactoryFinder;
044:        import org.geotools.coverage.GridSampleDimension;
045:        import org.geotools.coverage.grid.GridCoverageFactory;
046:        import org.geotools.referencing.crs.DefaultGeographicCRS;
047:        import org.geotools.referencing.operation.transform.IdentityTransform;
048:
049:        /**
050:         * Test the {@link SampleTranscoder} implementation. Image adapter depends
051:         * heavily on {@link CategoryList}, so this one should be tested first.
052:         *
053:         * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/library/coverage/src/test/java/org/geotools/coverage/grid/SampleTranscoderTest.java $
054:         * @version $Id: SampleTranscoderTest.java 23211 2006-12-05 00:38:41Z desruisseaux $
055:         * @author Martin Desruisseaux
056:         */
057:        public class SampleTranscoderTest extends TestCase {
058:            /**
059:             * Small value for comparaisons. Remind: transformed values are stored in a new image
060:             * using the 'float' data type. So we can't expected as much precision than with a
061:             * 'double' data type.
062:             */
063:            private static final double EPS = 1E-5;
064:
065:            /**
066:             * Random number generator for this test.
067:             */
068:            private static final Random random = new Random(
069:                    6215962897884256696L);
070:
071:            /**
072:             * A sample dimension for a band.
073:             */
074:            private GridSampleDimension band1;
075:
076:            /**
077:             * Run the suite from the command line.
078:             */
079:            public static void main(final String[] args) {
080:                junit.textui.TestRunner.run(suite());
081:            }
082:
083:            /**
084:             * Returns the test suite.
085:             */
086:            public static Test suite() {
087:                return new TestSuite(SampleTranscoderTest.class);
088:            }
089:
090:            /**
091:             * Constructs a test case with the given name.
092:             */
093:            public SampleTranscoderTest(final String name) {
094:                super (name);
095:            }
096:
097:            /**
098:             * Set up common objects used for all tests.
099:             */
100:            protected void setUp() throws Exception {
101:                super .setUp();
102:                band1 = new GridSampleDimension("Temperature", new Category[] {
103:                        new Category("No data", null, 0),
104:                        new Category("Land", null, 1),
105:                        new Category("Clouds", null, 2),
106:                        new Category("Temperature", null, 3, 100, 0.1, 5),
107:                        new Category("Foo", null, 100, 160, -1, 3),
108:                        new Category("Tarzan", null, 160) }, null);
109:            }
110:
111:            /**
112:             * Tests the transformation using a random raster with only one band.
113:             */
114:            public void testOneBand() throws TransformException {
115:                assertTrue(testOneBand(1, 0) instanceof  RenderedImageAdapter);
116:                assertTrue(testOneBand(.8, 2) instanceof  RenderedOp);
117:                assertTrue(testOneBand(band1) instanceof  RenderedOp);
118:            }
119:
120:            /**
121:             * Tests the transformation using a random raster with only one band.
122:             * A sample dimension with only one category will be used.
123:             *
124:             * @param  scale The scale factor.
125:             * @param  offset The offset value.
126:             * @return The transformed image.
127:             */
128:            private RenderedImage testOneBand(final double scale,
129:                    final double offset) throws TransformException {
130:                final Category category = new Category("Values", null, 0, 256,
131:                        scale, offset);
132:                return testOneBand(new GridSampleDimension("Measure",
133:                        new Category[] { category }, null));
134:            }
135:
136:            /**
137:             * Tests the transformation using a random raster with only one band.
138:             *
139:             * @param  band The sample dimension for the only band.
140:             * @return The transformed image.
141:             */
142:            private RenderedImage testOneBand(final GridSampleDimension band)
143:                    throws TransformException {
144:                final int SIZE = 64;
145:                /*
146:                 * Constructs a 64x64 image with random values.
147:                 * Samples values are integer in the range 0..160 inclusive.
148:                 */
149:                final BufferedImage source = new BufferedImage(SIZE, SIZE,
150:                        BufferedImage.TYPE_BYTE_INDEXED);
151:                final DataBufferByte buffer = (DataBufferByte) source
152:                        .getRaster().getDataBuffer();
153:                final byte[] array = buffer.getData(0);
154:                for (int i = 0; i < array.length; i++) {
155:                    array[i] = (byte) random.nextInt(161);
156:                }
157:                final MathTransform identity = IdentityTransform.create(2);
158:                final GridCoverageFactory factory = FactoryFinder
159:                        .getGridCoverageFactory(null);
160:                GridCoverage2D coverage;
161:                coverage = (GridCoverage2D) factory.create("Test", source,
162:                        DefaultGeographicCRS.WGS84, identity,
163:                        new GridSampleDimension[] { band }, null, null);
164:                /*
165:                 * Apply the operation. The SampleTranscoder class is suppose to transform our
166:                 * integers into real-world values. Check if the result use floating-points.
167:                 */
168:                final RenderedImage target = coverage.geophysics(true)
169:                        .getRenderedImage();
170:                assertSame(target, PlanarImage.wrapRenderedImage(target));
171:                assertEquals(DataBuffer.TYPE_BYTE, source.getSampleModel()
172:                        .getDataType());
173:                if (coverage.getRenderedImage() != target) {
174:                    assertEquals(DataBuffer.TYPE_FLOAT, target.getSampleModel()
175:                            .getDataType());
176:                }
177:                /*
178:                 * Now, gets the data as an array and compare it with the expected values.
179:                 */
180:                double[] sourceData = source.getData().getSamples(0, 0, SIZE,
181:                        SIZE, 0, (double[]) null);
182:                double[] targetData = target.getData().getSamples(0, 0, SIZE,
183:                        SIZE, 0, (double[]) null);
184:                band.getSampleToGeophysics().transform(sourceData, 0,
185:                        sourceData, 0, sourceData.length);
186:                CategoryListTest.compare(sourceData, targetData, EPS);
187:                /*
188:                 * Construct a new image with the resulting data, and apply an inverse transformation.
189:                 * Compare the resulting values with the original data.
190:                 */
191:                RenderedImage back = PlanarImage.wrapRenderedImage(target)
192:                        .getAsBufferedImage();
193:                coverage = (GridCoverage2D) factory.create("Test", back,
194:                        DefaultGeographicCRS.WGS84, identity,
195:                        new GridSampleDimension[] { band.geophysics(true) },
196:                        null, null);
197:
198:                back = coverage.geophysics(false).getRenderedImage();
199:                assertEquals(DataBuffer.TYPE_BYTE, back.getSampleModel()
200:                        .getDataType());
201:                sourceData = source.getData().getSamples(0, 0, SIZE, SIZE, 0,
202:                        (double[]) null);
203:                targetData = back.getData().getSamples(0, 0, SIZE, SIZE, 0,
204:                        (double[]) null);
205:                CategoryListTest.compare(sourceData, targetData, 1 + EPS);
206:                /*
207:                 * Returns the "geophysics view" of the image.
208:                 */
209:                return target;
210:            }
211:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.