001    //$HeadURL: svn+ssh://rbezema@svn.wald.intevation.org/deegree/base/tags/2.1/src/org/deegree/ogcwebservices/wpvs/j3d/BackgroundFactory.java $
002    /*----------------    FILE HEADER  ------------------------------------------
003    
004     This file is part of deegree.
005     Copyright (C) 2001-2006 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: bezema $
067     * 
068     * @version 2.0, $Revision: 6259 $, $Date: 2007-03-20 10:15:15 +0100 (Di, 20 Mär 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    
120    
121    /* ********************************************************************
122    Changes to this class. What the people have been up to:
123    $Log$
124    Revision 1.9  2006/12/06 15:34:36  bezema
125    removed warnings and unsafe lists
126    
127    Revision 1.8  2006/11/27 09:07:52  poth
128    JNI integration of proj4 has been removed. The CRS functionality now will be done by native deegree code.
129    
130    Revision 1.7  2006/11/23 11:46:40  bezema
131    The initial version of the new wpvs
132    
133    Revision 1.6  2006/07/05 15:59:13  poth
134    comments corrected
135    
136    Revision 1.5  2006/07/05 11:23:07  taddei
137    background img is scaled to fit req dimensions
138    
139    Revision 1.4  2006/06/20 10:16:01  taddei
140    clean up and javadoc
141    
142    Revision 1.3  2006/04/06 20:25:28  poth
143    *** empty log message ***
144    
145    Revision 1.2  2006/03/30 21:20:28  poth
146    *** empty log message ***
147    
148    Revision 1.1  2006/02/24 11:42:41  taddei
149    refactoring (background)
150    
151    
152    ********************************************************************** */