Source Code Cross Referenced for SubsampleAverageTest.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) 2006, Geotools Project Managment Committee (PMC)
005:         *
006:         *    This library is free software; you can redistribute it and/or
007:         *    modify it under the terms of the GNU Lesser General Public
008:         *    License as published by the Free Software Foundation; either
009:         *    version 2.1 of the License, or (at your option) any later version.
010:         *
011:         *    This library is distributed in the hope that it will be useful,
012:         *    but WITHOUT ANY WARRANTY; without even the implied warranty of
013:         *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
014:         *    Lesser General Public License for more details.
015:         */
016:        package org.geotools.coverage.grid;
017:
018:        // J2SE and JAI dependencies
019:        import java.awt.RenderingHints;
020:        import java.awt.image.RenderedImage;
021:        import java.io.IOException;
022:        import javax.media.jai.BorderExtender;
023:        import javax.media.jai.BorderExtenderCopy;
024:        import javax.media.jai.Interpolation;
025:        import javax.media.jai.RenderedOp;
026:
027:        // JUnit dependencies
028:        import junit.framework.Test;
029:        import junit.framework.TestCase;
030:        import junit.framework.TestSuite;
031:
032:        // OpenGIS dependencies
033:        import org.opengis.parameter.ParameterValueGroup;
034:
035:        // Geotools dependencies
036:        import org.geotools.coverage.processing.AbstractProcessor;
037:        import org.geotools.coverage.processing.DefaultProcessor;
038:        import org.geotools.coverage.processing.Operations;
039:        import org.geotools.factory.Hints;
040:
041:        /**
042:         * Tests the Subsample Average operation.
043:         *
044:         * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/library/coverage/src/test/java/org/geotools/coverage/grid/SubsampleAverageTest.java $
045:         * @version $Id: SubsampleAverageTest.java 27848 2007-11-12 13:10:32Z desruisseaux $
046:         * @author Simone Giannecchini
047:         *
048:         * @since 2.3
049:         */
050:        public class SubsampleAverageTest extends GridCoverageTest {
051:            /**
052:             * {@code true} if the result should be displayed in windows during test execution.
053:             * Default to {@code false}. This flag is set to {@code true} only if this test suite
054:             * is executed explicitly though the {@link #main} method.
055:             */
056:            private static boolean SHOW;
057:
058:            /**
059:             * The source grid coverage.
060:             */
061:            private GridCoverage2D indexedCoverage;
062:
063:            private GridCoverage2D indexedCoverageWithTransparency;
064:
065:            private GridCoverage2D originallyIndexedCoverage;
066:
067:            /**
068:             * Creates a test suite for the given name.
069:             */
070:            public SubsampleAverageTest(String name) {
071:                super (name);
072:                // TODO Auto-generated constructor stub
073:            }
074:
075:            /**
076:             * Returns the test suite.
077:             */
078:            public static Test suite() {
079:                return new TestSuite(SubsampleAverageTest.class);
080:            }
081:
082:            /**
083:             * Run the suit from the command line.
084:             */
085:            public static void main(final String[] args) {
086:                SHOW = true;
087:                org.geotools.util.logging.Logging.GEOTOOLS
088:                        .forceMonolineConsoleOutput(AbstractProcessor.OPERATION);
089:                junit.textui.TestRunner.run(SubsampleAverageTest.class);
090:            }
091:
092:            /**
093:             * Set up common objects used for all tests.
094:             */
095:            //@Override
096:            protected void setUp() throws Exception {
097:                super .setUp();
098:                originallyIndexedCoverage = GridCoverageExamples.getExample(0);
099:                indexedCoverage = GridCoverageExamples.getExample(2);
100:                indexedCoverageWithTransparency = GridCoverageExamples
101:                        .getExample(3);
102:            }
103:
104:            /**
105:             * Tests the "SubsampleAverage" operation.
106:             * @throws IOException 
107:             */
108:            public void testSubsampleAverage() throws IOException {
109:                // on this one the Subsample average should do an RGB expansion
110:                subsampleAverage(indexedCoverage.geophysics(true));
111:                // on this one the Subsample average should do an RGB expansion
112:                // preserving alpha
113:                subsampleAverage(indexedCoverageWithTransparency
114:                        .geophysics(true));
115:                // on this one the subsample average should go back to the geophysiscs
116:                // view before being applied
117:                subsampleAverage(originallyIndexedCoverage.geophysics(true));
118:
119:                // on this one the Subsample average should do an RGB expansion
120:                subsampleAverage(indexedCoverage.geophysics(false));
121:                // on this one the Subsample average should do an RGB expansion
122:                // preserving alpha
123:                subsampleAverage(indexedCoverageWithTransparency
124:                        .geophysics(false));
125:                // on this one the subsample average should go back to the geophysiscs
126:                // view before being applied
127:                subsampleAverage(originallyIndexedCoverage.geophysics(false));
128:
129:                // on this one the subsample average should NOT go back to the
130:                // geophysiscs view before being applied
131:                subsampleAverage(GridCoverageExamples.getExample(4).geophysics(
132:                        false), new Hints(Hints.REPLACE_NON_GEOPHYSICS_VIEW,
133:                        Boolean.FALSE));
134:
135:                // on this one the subsample average should go back to the
136:                // geophysiscs view before being applied
137:                subsampleAverage(GridCoverageExamples.getExample(4).geophysics(
138:                        false), new Hints(Hints.REPLACE_NON_GEOPHYSICS_VIEW,
139:                        Boolean.FALSE));
140:            }
141:
142:            public void subsampleAverage(GridCoverage2D coverage) {
143:                subsampleAverage(coverage, null);
144:            }
145:
146:            public void subsampleAverage(GridCoverage2D coverage,
147:                    RenderingHints hints) {
148:                // caching initial properties
149:                RenderedImage originalImage = coverage.getRenderedImage();
150:                int w = originalImage.getWidth();
151:                int h = originalImage.getHeight();
152:
153:                // get the processor and prepare the first operation
154:                final DefaultProcessor processor = new DefaultProcessor(hints);
155:                final ParameterValueGroup param = processor.getOperation(
156:                        "SubsampleAverage").getParameters();
157:                param.parameter("Source").setValue(coverage);
158:                param.parameter("scaleX").setValue(new Double(0.5));
159:                param.parameter("scaleY").setValue(new Double(0.5));
160:                param
161:                        .parameter("Interpolation")
162:                        .setValue(
163:                                Interpolation
164:                                        .getInstance(Interpolation.INTERP_NEAREST));
165:                param.parameter("BorderExtender").setValue(
166:                        BorderExtenderCopy
167:                                .createInstance(BorderExtender.BORDER_COPY));
168:                GridCoverage2D scaled = (GridCoverage2D) processor
169:                        .doOperation(param);
170:                RenderedImage scaledImage = scaled.getRenderedImage();
171:                assertTrue(scaledImage.getWidth() == (int) (w / 2.0f));
172:                assertTrue(scaledImage.getHeight() == (int) (h / 2.0f));
173:                w = scaledImage.getWidth();
174:                h = scaledImage.getHeight();
175:
176:                // show the result
177:                if (SHOW) {
178:                    Viewer.show(coverage, coverage.getName().toString());
179:                    Viewer.show(scaled, scaled.getName().toString());
180:                } else {
181:                    // Force computation
182:                    assertNotNull(coverage.getRenderedImage().getData());
183:                    assertNotNull(scaled.getRenderedImage().getData());
184:                }
185:
186:                // use the default processor and then scale again
187:                scaled = (GridCoverage2D) Operations.DEFAULT.subsampleAverage(
188:                        scaled, 0.3333, 0.3333, Interpolation
189:                                .getInstance(Interpolation.INTERP_NEAREST),
190:                        BorderExtender
191:                                .createInstance(BorderExtender.BORDER_COPY));
192:                scaledImage = scaled.getRenderedImage();
193:                // I had to comment this out since sometimes this evaluation fails
194:                // unexpectedly. I think it is a JAI issue because here below I using
195:                // the rule they claim to follow.
196:                // assertTrue(scaledImage.getWidth() == (int)(w / 3.0f));
197:                // assertTrue(scaledImage.getHeight() == (int)(h / 3.0f));
198:
199:                if (SHOW) {
200:                    Viewer.show(scaled, scaled.getName().toString());
201:                } else {
202:                    // Force computation
203:                    assertNotNull(scaled.getRenderedImage().getData());
204:                }
205:            }
206:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.