Source Code Cross Referenced for InterpolatorTest.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 and extensions
020:        import java.awt.geom.Point2D;
021:        import java.awt.image.Raster;
022:        import javax.media.jai.Interpolation;
023:
024:        // JUnit dependencies
025:        import junit.framework.Test;
026:        import junit.framework.TestSuite;
027:
028:        // OpenGIS dependencies
029:        import org.opengis.coverage.grid.GridRange;
030:        import org.opengis.geometry.Envelope;
031:
032:        // Geotools dependencies
033:        import org.geotools.coverage.grid.Interpolator2D;
034:
035:        /**
036:         * Tests the {@link Interpolator2D} implementation. This method inherit all tests from
037:         * {@link GridCoverageTest}. Because we override {@link #transform}, tests will be performed
038:         * on {@link Interpolator2D} objects instead of default {@link GridCoverage2D}.
039:         *
040:         * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/library/coverage/src/test/java/org/geotools/coverage/grid/InterpolatorTest.java $
041:         * @version $Id: InterpolatorTest.java 25591 2007-05-20 10:43:59Z desruisseaux $
042:         * @author Martin Desruisseaux
043:         */
044:        public class InterpolatorTest extends GridCoverageTest {
045:            /**
046:             * Small value for comparaison of sample values. Since most grid coverage implementation in
047:             * Geotools 2 store geophysics values as {@code float} numbers, this {@code EPS} value must
048:             * be of the order of {@code float} relative precision, not {@code double}.
049:             */
050:            private static final double EPS = 1E-5;
051:
052:            /**
053:             * The interpolators to use.
054:             */
055:            private Interpolation[] interpolations;
056:
057:            /**
058:             * Run the suite from the command line.
059:             */
060:            public static void main(final String[] args) {
061:                junit.textui.TestRunner.run(suite());
062:            }
063:
064:            /**
065:             * Returns the test suite.
066:             */
067:            public static Test suite() {
068:                return new TestSuite(InterpolatorTest.class);
069:            }
070:
071:            /**
072:             * Constructs a test case with the given name.
073:             */
074:            public InterpolatorTest(final String name) {
075:                super (name);
076:                final int[] types = { Interpolation.INTERP_BICUBIC,
077:                        Interpolation.INTERP_BILINEAR,
078:                        Interpolation.INTERP_NEAREST };
079:                interpolations = new Interpolation[types.length];
080:                for (int i = 0; i < interpolations.length; i++) {
081:                    interpolations[i] = Interpolation.getInstance(types[i]);
082:                }
083:            }
084:
085:            /**
086:             * Applies an operation on the specified coverage, if wanted.
087:             * The default implementation applies a set of interpolations
088:             * on <code>coverage</code>.
089:             */
090:            //@Override
091:            protected GridCoverage2D transform(final GridCoverage2D coverage) {
092:                return Interpolator2D.create(coverage, interpolations);
093:            }
094:
095:            /**
096:             * Tests the interpolations. Since <code>testGridCoverage()</code> tests value
097:             * at the center of pixels, all interpolations results should be identical to
098:             * a result without interpolation.
099:             */
100:            //@Override
101:            public void testGridCoverage() {
102:                final GridCoverage2D coverage = getRandomCoverage();
103:                assertTrue(coverage instanceof  Interpolator2D);
104:                assertTrue(coverage.geophysics(true) instanceof  Interpolator2D);
105:                assertTrue(coverage.geophysics(false) instanceof  Interpolator2D);
106:            }
107:
108:            /**
109:             * Tests bilinear intersection at pixel edges. It should be equals
110:             * to the average of the four pixels around.
111:             */
112:            public void testInterpolationAtEdges() {
113:                // Following constant is pixel size (in degrees).
114:                // This constant must be identical to the one defined in 'getRandomCoverage()'
115:                final double PIXEL_SIZE = 0.25;
116:
117:                final GridCoverage2D coverage = Interpolator2D.create(
118:                        getRandomCoverage().geophysics(true),
119:                        new Interpolation[] { Interpolation
120:                                .getInstance(Interpolation.INTERP_BILINEAR) });
121:
122:                final int band = 0; // Band to test.
123:                double[] buffer = null;
124:                final Raster data = coverage.getRenderedImage().getData();
125:                final Envelope envelope = coverage.getEnvelope();
126:                final GridRange range = coverage.getGridGeometry()
127:                        .getGridRange();
128:                final double left = envelope.getMinimum(0);
129:                final double upper = envelope.getMaximum(1);
130:                final Point2D.Double point = new Point2D.Double(); // Will maps to pixel upper-left corner
131:                for (int j = range.getLength(1); --j >= 1;) {
132:                    for (int i = range.getLength(0); --i >= 1;) {
133:                        point.x = left + PIXEL_SIZE * i;
134:                        point.y = upper - PIXEL_SIZE * j;
135:                        buffer = coverage.evaluate(point, buffer);
136:                        double t = buffer[band];
137:
138:                        // Computes the expected value:
139:                        double r00 = data.getSampleDouble(i - 0, j - 0, band);
140:                        double r01 = data.getSampleDouble(i - 0, j - 1, band);
141:                        double r10 = data.getSampleDouble(i - 1, j - 0, band);
142:                        double r11 = data.getSampleDouble(i - 1, j - 1, band);
143:                        double r = (r00 + r01 + r10 + r11) / 4;
144:                        if (Double.isNaN(r)) {
145:                            assertTrue("NaN", Double.isNaN(t));
146:                        } else {
147:                            assertEquals(r, t, EPS);
148:                        }
149:                    }
150:                }
151:            }
152:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.