Source Code Cross Referenced for ScaleTest.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.InterpolationBilinear;
026:        import javax.media.jai.InterpolationNearest;
027:
028:        // JUnit dependencies
029:        import junit.framework.Test;
030:        import junit.framework.TestSuite;
031:
032:        // OpenGIS dependencies
033:        import org.opengis.parameter.ParameterValueGroup;
034:        import org.geotools.coverage.processing.AbstractProcessor;
035:        import org.geotools.coverage.processing.DefaultProcessor;
036:
037:        // Geotools dependencies
038:        import org.geotools.coverage.processing.Operations;
039:        import org.geotools.factory.Hints;
040:
041:        /**
042:         * Tests the scale operation.
043:         *
044:         * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/library/coverage/src/test/java/org/geotools/coverage/grid/ScaleTest.java $
045:         * @version $Id: ScaleTest.java 27848 2007-11-12 13:10:32Z desruisseaux $
046:         * @author Simone Giannecchini
047:         *
048:         * @since 2.3
049:         */
050:        public class ScaleTest 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:            private GridCoverage2D originallyIndexedCoverage;
059:
060:            private GridCoverage2D indexedCoverage;
061:
062:            private GridCoverage2D indexedCoverageWithTransparency;
063:
064:            private GridCoverage2D floatCoverage;
065:
066:            /**
067:             * Creates a test suite for the given name.
068:             */
069:            public ScaleTest(String name) {
070:                super (name);
071:            }
072:
073:            /**
074:             * Returns the test suite.
075:             */
076:            public static Test suite() {
077:                return new TestSuite(ScaleTest.class);
078:            }
079:
080:            /**
081:             * Run the suit from the command line.
082:             */
083:            public static void main(final String[] args) {
084:                SHOW = true;
085:                org.geotools.util.logging.Logging.GEOTOOLS
086:                        .forceMonolineConsoleOutput(AbstractProcessor.OPERATION);
087:                junit.textui.TestRunner.run(suite());
088:            }
089:
090:            /**
091:             * Set up common objects used for all tests.
092:             */
093:            protected void setUp() throws Exception {
094:                super .setUp();
095:                originallyIndexedCoverage = GridCoverageExamples.getExample(0);
096:                indexedCoverage = GridCoverageExamples.getExample(2);
097:                indexedCoverageWithTransparency = GridCoverageExamples
098:                        .getExample(3);
099:                floatCoverage = GridCoverageExamples.getExample(4);
100:            }
101:
102:            /**
103:             * Tests the "Scale" operation.
104:             * 
105:             * @throws IOException
106:             */
107:
108:            public void testScale() throws IOException {
109:                ///////////////////////////////////////////////////////////////////////
110:                //
111:                // Nearest neighbor interpolation and non-geo view 
112:                //
113:                ///////////////////////////////////////////////////////////////////////
114:                scale(originallyIndexedCoverage.geophysics(false),
115:                        new InterpolationNearest(), new RenderingHints(
116:                                Hints.REPLACE_NON_GEOPHYSICS_VIEW,
117:                                Boolean.FALSE));
118:                scale(indexedCoverage.geophysics(false),
119:                        new InterpolationNearest(), new RenderingHints(
120:                                Hints.REPLACE_NON_GEOPHYSICS_VIEW,
121:                                Boolean.FALSE));
122:                scale(indexedCoverageWithTransparency.geophysics(false),
123:                        new InterpolationNearest(), new RenderingHints(
124:                                Hints.REPLACE_NON_GEOPHYSICS_VIEW,
125:                                Boolean.FALSE));
126:
127:                ///////////////////////////////////////////////////////////////////////
128:                //
129:                // Nearest neighbor interpolation and geo view 
130:                //
131:                ///////////////////////////////////////////////////////////////////////
132:                scale(originallyIndexedCoverage.geophysics(true),
133:                        new InterpolationNearest(), new RenderingHints(
134:                                Hints.REPLACE_NON_GEOPHYSICS_VIEW,
135:                                Boolean.FALSE));
136:                scale(indexedCoverage.geophysics(true),
137:                        new InterpolationNearest(), new RenderingHints(
138:                                Hints.REPLACE_NON_GEOPHYSICS_VIEW,
139:                                Boolean.FALSE));
140:                scale(indexedCoverageWithTransparency.geophysics(true),
141:                        new InterpolationNearest(), new RenderingHints(
142:                                Hints.REPLACE_NON_GEOPHYSICS_VIEW,
143:                                Boolean.FALSE));
144:
145:                ///////////////////////////////////////////////////////////////////////
146:                //
147:                // Bilinear interpolation and non-geo view 
148:                //
149:                ///////////////////////////////////////////////////////////////////////
150:                scale(originallyIndexedCoverage.geophysics(false),
151:                        new InterpolationNearest(), new RenderingHints(
152:                                Hints.REPLACE_NON_GEOPHYSICS_VIEW,
153:                                Boolean.FALSE));
154:                scale(indexedCoverage.geophysics(false),
155:                        new InterpolationNearest(), new RenderingHints(
156:                                Hints.REPLACE_NON_GEOPHYSICS_VIEW,
157:                                Boolean.FALSE));
158:                scale(indexedCoverageWithTransparency.geophysics(false),
159:                        new InterpolationNearest(), new RenderingHints(
160:                                Hints.REPLACE_NON_GEOPHYSICS_VIEW,
161:                                Boolean.FALSE));
162:
163:                ///////////////////////////////////////////////////////////////////////
164:                //
165:                // Bilinear interpolation and geo view 
166:                //
167:                ///////////////////////////////////////////////////////////////////////
168:                scale(originallyIndexedCoverage.geophysics(true),
169:                        new InterpolationBilinear(), new RenderingHints(
170:                                Hints.REPLACE_NON_GEOPHYSICS_VIEW,
171:                                Boolean.FALSE));
172:                scale(indexedCoverage.geophysics(true),
173:                        new InterpolationBilinear(), new RenderingHints(
174:                                Hints.REPLACE_NON_GEOPHYSICS_VIEW,
175:                                Boolean.FALSE));
176:                scale(indexedCoverageWithTransparency.geophysics(true),
177:                        new InterpolationBilinear(), new RenderingHints(
178:                                Hints.REPLACE_NON_GEOPHYSICS_VIEW,
179:                                Boolean.FALSE));
180:
181:                ///////////////////////////////////////////////////////////////////////
182:                //
183:                // Bilinear interpolation and non-geo view for a float coverage
184:                //
185:                ///////////////////////////////////////////////////////////////////////
186:                // on this one the subsample average should NOT go back to the
187:                // geophysiscs view before being applied
188:                scale(floatCoverage.geophysics(false),
189:                        new InterpolationBilinear(), new RenderingHints(
190:                                Hints.REPLACE_NON_GEOPHYSICS_VIEW,
191:                                Boolean.FALSE));
192:
193:                ///////////////////////////////////////////////////////////////////////
194:                //
195:                // Nearest neighbor  interpolation and non-geo view for a float coverage
196:                //
197:                ///////////////////////////////////////////////////////////////////////
198:                // on this one the subsample average should NOT go back to the
199:                // geophysiscs
200:                // view before being applied
201:                scale(floatCoverage.geophysics(false),
202:                        new InterpolationNearest(), new RenderingHints(
203:                                Hints.REPLACE_NON_GEOPHYSICS_VIEW,
204:                                Boolean.FALSE));
205:            }
206:
207:            public void scale(GridCoverage2D coverage, Interpolation interp) {
208:                scale(coverage, interp, null);
209:            }
210:
211:            public void scale(GridCoverage2D coverage, Interpolation interp,
212:                    RenderingHints hints) {
213:                // caching initial properties
214:                RenderedImage originalImage = coverage.getRenderedImage();
215:                final int w = originalImage.getWidth();
216:                final int h = originalImage.getHeight();
217:
218:                // creating a default processor
219:                final DefaultProcessor processor = new DefaultProcessor(hints);
220:                // getting parameters for doing a scale
221:                final ParameterValueGroup param = processor.getOperation(
222:                        "Scale").getParameters();
223:                param.parameter("Source").setValue(coverage);
224:                param.parameter("xScale").setValue(new Float(0.5));
225:                param.parameter("yScale").setValue(new Float(0.5));
226:                param.parameter("xTrans").setValue(new Float(0));
227:                param.parameter("yTrans").setValue(new Float(0));
228:                param.parameter("Interpolation").setValue(interp);
229:                param.parameter("BorderExtender").setValue(
230:                        BorderExtenderCopy
231:                                .createInstance(BorderExtender.BORDER_COPY));
232:                // doing a first scale
233:                GridCoverage2D scaled = (GridCoverage2D) processor
234:                        .doOperation(param);
235:                RenderedImage scaledImage = scaled.getRenderedImage();
236:                assertTrue(scaledImage.getWidth() == w / 2.0f);
237:                assertTrue(scaledImage.getHeight() == h / 2.0f);
238:
239:                if (SHOW) {
240:                    Viewer.show(coverage, coverage.getName().toString());
241:                    Viewer.show(scaled, scaled.getName().toString());
242:                } else {
243:                    // Force computation
244:                    assertNotNull(coverage.getRenderedImage().getData());
245:                    assertNotNull(scaledImage.getData());
246:                }
247:
248:                // doing another scale using the Default processor
249:                scaled = (GridCoverage2D) Operations.DEFAULT.scale(scaled, 3,
250:                        3, 0.0, 0.0, interp, BorderExtender
251:                                .createInstance(BorderExtender.BORDER_COPY));
252:                scaledImage = scaled.getRenderedImage();
253:                assertTrue(scaledImage.getWidth() == 3 * w / 2.0f);
254:                assertTrue(scaledImage.getHeight() == 3 * h / 2.0f);
255:
256:                if (SHOW) {
257:                    Viewer.show(scaled, scaled.getName().toString());
258:                } else {
259:                    // Force computation
260:                    assertNotNull(scaledImage.getData());
261:                }
262:            }
263:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.