001 //$HeadURL: svn+ssh://rbezema@svn.wald.intevation.org/deegree/base/branches/2.2_testing/src/org/deegree/ogcwebservices/wpvs/j3d/BackgroundFactory.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
044 package org.deegree.ogcwebservices.wpvs.j3d;
045
046 import java.awt.Color;
047 import java.awt.Dimension;
048 import java.awt.Graphics;
049 import java.awt.image.BufferedImage;
050 import java.io.IOException;
051 import java.net.URL;
052
053 import javax.imageio.ImageIO;
054 import javax.media.j3d.Background;
055 import javax.media.j3d.BoundingSphere;
056 import javax.media.j3d.ImageComponent2D;
057 import javax.vecmath.Color3f;
058 import javax.vecmath.Point3d;
059
060 import com.sun.j3d.utils.image.TextureLoader;
061
062 /**
063 * Factory for creating different types of Java3D objects to be used as background objects.
064 *
065 * @author <a href="mailto:taddei@lat-lon.de">Ugo Taddei</a>
066 * @author last edited by: $Author: apoth $
067 *
068 * @version 2.0, $Revision: 9345 $, $Date: 2007-12-27 17:22:25 +0100 (Do, 27 Dez 2007) $
069 *
070 * @since 2.0
071 */
072 public class BackgroundFactory {
073
074 private BackgroundFactory() {
075 // nothing to do
076 }
077
078 /**
079 * Creates Java 3D <code>background</code> object, drawn at infinity. This method is used
080 * for "box" views and/or when the users wants a fixed background image. Not the in the latter
081 * case for optimal results, the image should be of same dimensions as the <code>GetView</code>
082 * image
083 * @param vp the ViewPoint defining the observer's position
084 * @param color the background color (seen when image is null or doesn't cover the whole view)
085 * @param imgURL a URL pointing to an image
086 * @param reqImgDimension
087 * @return A Java3D Background Node
088 * @throws IOException
089 */
090 public static Background createSimpleBackgroundGroup( ViewPoint vp, Color color, URL imgURL, Dimension reqImgDimension ) throws IOException{
091
092 Point3d ftPrint = vp.getFootprint()[0];
093
094 Background bg = new Background( new Color3f( color ) );
095 Point3d origin = new Point3d( ftPrint.x, ftPrint.y, ftPrint.z );
096 BoundingSphere bounds = new BoundingSphere(origin, ftPrint.x );
097
098 bg.setApplicationBounds( bounds );
099
100 if( imgURL != null ) {
101 BufferedImage buffImg = ImageIO.read( imgURL );
102
103 // scale image to fill the whole bakground
104 BufferedImage tmpImg = new BufferedImage( reqImgDimension.width, reqImgDimension.height, buffImg.getType() );
105 Graphics g = tmpImg.getGraphics();
106 g.drawImage( buffImg, 0, 0, tmpImg.getWidth() - 1 ,tmpImg.getHeight() - 1, null );
107 g.dispose();
108
109 ImageComponent2D img = new TextureLoader( tmpImg ).getImage();
110 bg.setImage( img );
111 }
112
113 return bg;
114 }
115
116
117
118 }
119