Source Code Cross Referenced for Abstract3DRenderingEngine.java in  » GIS » deegree » org » deegree » ogcwebservices » wpvs » j3d » 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 » deegree » org.deegree.ogcwebservices.wpvs.j3d 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        //$HeadURL: https://svn.wald.intevation.org/svn/deegree/base/trunk/src/org/deegree/ogcwebservices/wpvs/j3d/Abstract3DRenderingEngine.java $
002:        /*----------------    FILE HEADER  ------------------------------------------
003:
004:         This file is part of deegree.
005:         Copyright (C) 2001-2008 by:
006:         EXSE, Department of Geography, University of Bonn
007:         http://www.giub.uni-bonn.de/deegree/
008:         lat/lon GmbH
009:         http://www.lat-lon.de
010:
011:         This library is free software; you can redistribute it and/or
012:         modify it under the terms of the GNU Lesser General Public
013:         License as published by the Free Software Foundation; either
014:         version 2.1 of the License, or (at your option) any later version.
015:
016:         This library is distributed in the hope that it will be useful,
017:         but WITHOUT ANY WARRANTY; without even the implied warranty of
018:         MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
019:         Lesser General Public License for more details.
020:
021:         You should have received a copy of the GNU Lesser General Public
022:         License along with this library; if not, write to the Free Software
023:         Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
024:
025:         Contact:
026:
027:         Andreas Poth
028:         lat/lon GmbH
029:         Aennchenstraße 19
030:         53177 Bonn
031:         Germany
032:         E-Mail: poth@lat-lon.de
033:
034:         Prof. Dr. Klaus Greve
035:         Department of Geography
036:         University of Bonn
037:         Meckenheimer Allee 166
038:         53115 Bonn
039:         Germany
040:         E-Mail: greve@giub.uni-bonn.de
041:        
042:         ---------------------------------------------------------------------------*/
043:        package org.deegree.ogcwebservices.wpvs.j3d;
044:
045:        import java.awt.GraphicsConfigTemplate;
046:        import java.awt.GraphicsDevice;
047:        import java.awt.GraphicsEnvironment;
048:
049:        import javax.media.j3d.BranchGroup;
050:        import javax.media.j3d.Canvas3D;
051:        import javax.media.j3d.GraphicsConfigTemplate3D;
052:        import javax.media.j3d.Group;
053:        import javax.media.j3d.Node;
054:        import javax.media.j3d.PhysicalBody;
055:        import javax.media.j3d.PhysicalEnvironment;
056:        import javax.media.j3d.TransformGroup;
057:        import javax.media.j3d.View;
058:        import javax.media.j3d.ViewPlatform;
059:
060:        /**
061:         * 
062:         * This class serves a a superclass for all rendering engines of the WPV Service.
063:         * 
064:         * @author <a href="mailto:poth@lat-lon.de">Andreas Poth</a>
065:         * @version $Revision: 9345 $ $Date: 2007-12-27 08:22:25 -0800 (Thu, 27 Dec 2007) $
066:         */
067:        abstract public class Abstract3DRenderingEngine implements 
068:                RenderingEngine {
069:
070:            protected WPVSScene scene;
071:
072:            protected float farClippingPlane;
073:
074:            protected double nearClippingPlane;
075:
076:            /**
077:             * Creates a new Abstract3DRenderEngine object with a nearclippingplane of 2.
078:             * 
079:             * @param scene to be rendered
080:             */
081:            public Abstract3DRenderingEngine(WPVSScene scene) {
082:                this (scene, 2);
083:            }
084:
085:            /**
086:             * Creates a new Abstract3DRenderEngine object.
087:             * 
088:             * @param scene to be rendered
089:             * @param nearClippingPlane of the viewport
090:             */
091:            public Abstract3DRenderingEngine(WPVSScene scene,
092:                    double nearClippingPlane) {
093:                this .scene = scene;
094:                // clipping default
095:                // farClippingPlane = (float)scene.getViewPoint().getFarClippingPlane();
096:                farClippingPlane = (float) scene.getViewPoint()
097:                        .getFarClippingPlane();
098:                this .nearClippingPlane = nearClippingPlane;
099:            }
100:
101:            /**
102:             * Creates a new canvas each time this is called.
103:             * 
104:             * The Canvas3D class provides a drawing canvas for 3D rendering. The Canvas3D object extends
105:             * the Canvas object to include 3D-related information such as the size of the canvas in pixels,
106:             * the Canvas3D's location, also in pixels, within a Screen3D object, and whether or not the
107:             * canvas has stereo enabled. Because all Canvas3D objects contain a reference to a Screen3D
108:             * object and because Screen3D objects define the size of a pixel in physical units, Java 3D can
109:             * convert a Canvas3D size in pixels to a physical world size in meters. It can also determine
110:             * the Canvas3D's position and orientation in the physical world.
111:             * 
112:             * @param offscreen
113:             *            true if the canvas3D is an offsreen canvas.
114:             * 
115:             * @return A new canvas instance or <code>null</code> if no GraphicsEnvironment was found.
116:             */
117:            protected Canvas3D createCanvas(boolean offscreen) {
118:                // This class is used to obtain a valid GraphicsConfiguration that can be used by Java 3D.
119:                // It instantiates objects and then sets all non-default attributes as desired.
120:                GraphicsDevice[] gd = GraphicsEnvironment
121:                        .getLocalGraphicsEnvironment().getScreenDevices();
122:                GraphicsConfigTemplate3D gc3D = new GraphicsConfigTemplate3D();
123:                gc3D.setSceneAntialiasing(GraphicsConfigTemplate.PREFERRED);
124:                gc3D.setDoubleBuffer(GraphicsConfigTemplate.REQUIRED);
125:
126:                if (gd != null && gd.length > 0) {
127:                    Canvas3D canvas = new Canvas3D(gd[0]
128:                            .getBestConfiguration(gc3D), offscreen);
129:                    return canvas;
130:                }
131:                return null;
132:            }
133:
134:            /**
135:             * A transform group is aplied as the transformation to the branches
136:             * 
137:             * @return the transformgroup with ALLOW_TRANSFORM_READ, ALLOW_TRANSFORM_WRITE and
138:             *         ALLOW_LOCAL_TO_VWORLD_READ set.
139:             */
140:            protected TransformGroup createTransformGroup() {
141:                // creates the TransformGroup
142:                // The TransformGroup node specifies a single spatial transformation, via a Transform3D
143:                // object,
144:                // that can position, orient, and scale all of its children.
145:                TransformGroup viewTG = new TransformGroup();
146:
147:                // Specifies that the node allows access to its object's transform information.
148:                viewTG.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
149:
150:                // Specifies that the node allows writing its object's transform information.
151:                //viewTG.setCapability( TransformGroup.ALLOW_TRANSFORM_WRITE );
152:
153:                // Specifies that this Node allows read access to its local coordinates to virtual world
154:                // (Vworld) coordinates transform.
155:                //viewTG.setCapability( Node.ALLOW_LOCAL_TO_VWORLD_READ );
156:
157:                return viewTG;
158:            }
159:
160:            /**
161:             * sets/defines the <code>View</code> of the scene and adds it to the submitted
162:             * <code>BranchGroup</code>
163:             * 
164:             * @param view
165:             *            the scenes view
166:             * @param viewGroup
167:             */
168:            protected void setView(View view, BranchGroup viewGroup) {
169:                ViewPoint viewPoint = scene.getViewPoint();
170:
171:                // The ViewPatform class is used to set up the "view" side of a Java 3D scene graph.
172:                ViewPlatform camera = new ViewPlatform();
173:
174:                // RELATIVE_TO_FIELD_OF_VIEW tells Java 3D that it should modify the eyepoint position so it
175:                // is located
176:                // at the appropriate place relative to the window to match the specified field of view.
177:                // This implies that the view frustum will change whenever the application changes the field
178:                // of view.
179:                camera.setViewAttachPolicy(View.RELATIVE_TO_FIELD_OF_VIEW);
180:                camera.setViewAttachPolicy(View.NOMINAL_HEAD);
181:
182:                view.setFieldOfView(viewPoint.getAngleOfView());
183:                view.setWindowEyepointPolicy(View.RELATIVE_TO_FIELD_OF_VIEW);
184:
185:                //set view parameters
186:                view.setUserHeadToVworldEnable(true);
187:                view.setSceneAntialiasingEnable(true);
188:
189:                // The View object contains all parameters needed in rendering a three dimensional scene
190:                // from one viewpoint.
191:                view.setBackClipDistance(farClippingPlane);
192:                view.setFrontClipDistance(nearClippingPlane);
193:
194:                // creates the PhysicalBody and PhysicalEnvironment for the View
195:                // and attachs it to the View
196:                PhysicalEnvironment pe = new PhysicalEnvironment();
197:                pe.setCoexistenceCenterInPworldPolicy(View.NOMINAL_HEAD);
198:                view.setPhysicalEnvironment(pe);
199:                PhysicalBody pb = new PhysicalBody(scene.getViewPoint()
200:                        .getObserverPosition(), scene.getViewPoint()
201:                        .getObserverPosition());
202:
203:                view.setPhysicalBody(pb);
204:
205:                // attach the View to the ViewPlatform
206:                view.attachViewPlatform(camera);
207:
208:                TransformGroup viewTG = createTransformGroup();
209:                viewTG.addChild(camera);
210:                viewTG.setTransform(viewPoint.getViewMatrix());
211:                viewGroup.addChild(viewTG);
212:                //       viewGroup.addChild( camera );
213:            }
214:
215:            /**
216:             * adds a background to the scene
217:             * 
218:             * @param vp
219:             *            viewpoint
220:             * @param background
221:             *            the node to render in the background
222:             * @param worldGroup
223:             *            to add the Background to
224:             */
225:            protected void addBackground(@SuppressWarnings("unused")
226:            ViewPoint vp, Group worldGroup, Node background) {
227:                // Point3d pp = vp.getObserverPosition();
228:                // Point3d origin = new Point3d( pp.x, pp.y, pp.z );
229:                // Bounds bounds = new BoundingSphere( origin, farClippingPlane );
230:                // ExponentialFog fog = new ExponentialFog();
231:                // fog.setColor( new Color3f( 0.7f, 0.7f, 0.7f ) );
232:                // fog.setDensity( 0.001f );
233:                // LinearFog fog = new LinearFog();
234:                // fog.setColor( new Color3f( 0.7f, 0.7f, 0.7f ) );
235:                // fog.setFrontDistance( 0 );
236:                // fog.setBackDistance( 2000 );
237:                // fog.setInfluencingBounds( bounds );
238:                // worldGroup.addChild( fog );
239:
240:                worldGroup.addChild(background);
241:
242:            }
243:
244:            /**
245:             * sets the scenes back clip distance. default is 15000
246:             * 
247:             * @param distance
248:             */
249:            public void setBackClipDistance(float distance) {
250:                farClippingPlane = distance;
251:            }
252:
253:            /**
254:             * sets the scenes front clip distance. default is 2
255:             * 
256:             * @param distance
257:             */
258:            public void setFrontClipDistance(float distance) {
259:                nearClippingPlane = distance;
260:            }
261:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.