Source Code Cross Referenced for ObjectFileCompressor.java in  » 6.0-JDK-Modules » java-3d » org » jdesktop » j3d » examples » geometry_compression » 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 » 6.0 JDK Modules » java 3d » org.jdesktop.j3d.examples.geometry_compression 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * $RCSfile: ObjectFileCompressor.java,v $
003:         *
004:         * Copyright (c) 2007 Sun Microsystems, Inc. All rights reserved.
005:         *
006:         * Redistribution and use in source and binary forms, with or without
007:         * modification, are permitted provided that the following conditions
008:         * are met:
009:         *
010:         * - Redistribution of source code must retain the above copyright
011:         *   notice, this list of conditions and the following disclaimer.
012:         *
013:         * - Redistribution in binary form must reproduce the above copyright
014:         *   notice, this list of conditions and the following disclaimer in
015:         *   the documentation and/or other materials provided with the
016:         *   distribution.
017:         *
018:         * Neither the name of Sun Microsystems, Inc. or the names of
019:         * contributors may be used to endorse or promote products derived
020:         * from this software without specific prior written permission.
021:         *
022:         * This software is provided "AS IS," without a warranty of any
023:         * kind. ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND
024:         * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY,
025:         * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY
026:         * EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL
027:         * NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF
028:         * USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS
029:         * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR
030:         * ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL,
031:         * CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER CAUSED AND
032:         * REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF OR
033:         * INABILITY TO USE THIS SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE
034:         * POSSIBILITY OF SUCH DAMAGES.
035:         *
036:         * You acknowledge that this software is not designed, licensed or
037:         * intended for use in the design, construction, operation or
038:         * maintenance of any nuclear facility.
039:         *
040:         * $Revision: 1.3 $
041:         * $Date: 2007/02/09 17:21:40 $
042:         * $State: Exp $
043:         */
044:
045:        package org.jdesktop.j3d.examples.geometry_compression;
046:
047:        import com.sun.j3d.loaders.IncorrectFormatException;
048:        import com.sun.j3d.loaders.ParsingErrorException;
049:        import com.sun.j3d.loaders.Scene;
050:        import com.sun.j3d.loaders.objectfile.ObjectFile;
051:        import com.sun.j3d.utils.geometry.compression.*;
052:        import java.io.FileNotFoundException;
053:        import java.io.IOException;
054:        import java.io.Reader;
055:        import java.net.URL;
056:        import java.util.Hashtable;
057:        import javax.media.j3d.Shape3D;
058:
059:        /**
060:         * This extension of ObjectFile provides the methods setQuantization() and
061:         * compress() to compress Wavefront .obj files into the format described by
062:         * appendix B of the Java 3D specification.
063:         */
064:        public class ObjectFileCompressor extends ObjectFile {
065:            private GeometryCompressor compressor = null;
066:
067:            public ObjectFileCompressor() {
068:                super (STRIPIFY | TRIANGULATE);
069:                compressor = new GeometryCompressor();
070:            }
071:
072:            public ObjectFileCompressor(int flags) {
073:                super (flags | STRIPIFY | TRIANGULATE);
074:                compressor = new GeometryCompressor();
075:            }
076:
077:            public ObjectFileCompressor(int flags, float radians) {
078:                super (flags | STRIPIFY | TRIANGULATE, radians);
079:                compressor = new GeometryCompressor();
080:            }
081:
082:            public void setFlags(int flags) {
083:                super .setFlags(flags | STRIPIFY | TRIANGULATE);
084:            }
085:
086:            private int positionQuant = 10;
087:            private int colorQuant = 8;
088:            private int normalQuant = 3;
089:
090:            /**
091:             * Set the position, normal, and color quantization values for compression.
092:             * @param positionQuant number of bits to quantize each position's X, Y,
093:             * and Z components, ranging from 1 to 16 with a default of 10
094:             * @param colorQuant number of bits to quantize each color's R, G, B, and
095:             * alpha components, ranging from 2 to 16 with a default of 8
096:             * @param normalQuant number of bits for quantizing each normal's U and V
097:             * components, ranging from 0 to 6 with a default of 3
098:             */
099:            public void setQuantization(int positionQuant, int colorQuant,
100:                    int normalQuant) {
101:
102:                this .positionQuant = positionQuant;
103:                this .colorQuant = colorQuant;
104:                this .normalQuant = normalQuant;
105:            }
106:
107:            /**
108:             * Compress the specified .obj file into a CompressedGeometryData node
109:             * component.  
110:             * @param objFileName String object representing the path to a .obj file
111:             * @return a CompressedGeometryData node component
112:             */
113:            public CompressedGeometryData compress(String objFileName) {
114:                return compressScene(getScene(objFileName));
115:            }
116:
117:            /**
118:             * Compress the specified .obj file and add it to the end of an open
119:             * compressed geometry file.
120:             * @param objFileName String object representing the path to a .obj file
121:             * @param file a currently open CompressedGeometryFile object
122:             * @exception IOException - if write fails
123:             */
124:            public void compress(String objFileName, CompressedGeometryFile file)
125:                    throws IOException {
126:                compressScene(getScene(objFileName), file);
127:            }
128:
129:            /**
130:             * Compress the specified .obj file into a CompressedGeometryData node
131:             * component.
132:             * @param reader an open .obj file
133:             * @return a CompressedGeometryData node component
134:             */
135:            public CompressedGeometryData compress(Reader reader) {
136:                return compressScene(getScene(reader));
137:            }
138:
139:            /**
140:             * Compress the specified .obj file and add it to the end of an open
141:             * compressed geometry file.
142:             * @param reader an open .obj file
143:             * @param file an open CompressedGeometryFile object
144:             * @exception IOException - if write fails
145:             */
146:            public void compress(Reader reader, CompressedGeometryFile file)
147:                    throws IOException {
148:                compressScene(getScene(reader), file);
149:            }
150:
151:            /**
152:             * Compress the specified .obj file into a CompressedGeometryData node
153:             * component.
154:             * @param url Uniform Resource Locator for the .obj file
155:             * @return a CompressedGeometryData node component
156:             */
157:            public CompressedGeometryData compress(URL url) {
158:                return compressScene(getScene(url));
159:            }
160:
161:            /**
162:             * Compress the specified .obj file and add it to the end of an open
163:             * compressed geometry file.
164:             * @param url Uniform Resource Locator for the .obj file
165:             * @param file a currently open CompressedGeometryFile object
166:             * @exception IOException - if write fails
167:             */
168:            public void compress(URL url, CompressedGeometryFile file)
169:                    throws IOException {
170:                compressScene(getScene(url), file);
171:            }
172:
173:            private CompressedGeometryData compressScene(Scene scene) {
174:                return compressor.compress(getStream(scene));
175:            }
176:
177:            private void compressScene(Scene scene, CompressedGeometryFile file)
178:                    throws IOException {
179:                compressor.compress(getStream(scene), file);
180:            }
181:
182:            private CompressionStream getStream(Scene scene) {
183:                Hashtable objs = scene.getNamedObjects();
184:                Shape3D shapes[] = new Shape3D[objs.size()];
185:
186:                objs.values().toArray(shapes);
187:                return new CompressionStream(positionQuant, colorQuant,
188:                        normalQuant, shapes);
189:            }
190:
191:            private Scene getScene(String objFileName) {
192:                Scene scene = null;
193:                try {
194:                    scene = load(objFileName);
195:                } catch (FileNotFoundException e) {
196:                    System.err.println(e);
197:                    System.exit(1);
198:                } catch (ParsingErrorException e) {
199:                    System.err.println(e);
200:                    System.exit(1);
201:                } catch (IncorrectFormatException e) {
202:                    System.err.println(e);
203:                    System.exit(1);
204:                }
205:                return scene;
206:            }
207:
208:            private Scene getScene(Reader reader) {
209:                Scene scene = null;
210:                try {
211:                    scene = load(reader);
212:                } catch (FileNotFoundException e) {
213:                    System.err.println(e);
214:                    System.exit(1);
215:                } catch (ParsingErrorException e) {
216:                    System.err.println(e);
217:                    System.exit(1);
218:                } catch (IncorrectFormatException e) {
219:                    System.err.println(e);
220:                    System.exit(1);
221:                }
222:                return scene;
223:            }
224:
225:            private Scene getScene(URL url) {
226:                Scene scene = null;
227:                try {
228:                    scene = load(url);
229:                } catch (FileNotFoundException e) {
230:                    System.err.println(e);
231:                    System.exit(1);
232:                } catch (ParsingErrorException e) {
233:                    System.err.println(e);
234:                    System.exit(1);
235:                } catch (IncorrectFormatException e) {
236:                    System.err.println(e);
237:                    System.exit(1);
238:                }
239:                return scene;
240:            }
241:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.