001 //$HeadURL: svn+ssh://rbezema@svn.wald.intevation.org/deegree/base/branches/2.2_testing/src/org/deegree/ogcwebservices/wpvs/j3d/TerrainModel.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 Aennchenstr. 19 030 53115 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 045 package org.deegree.ogcwebservices.wpvs.j3d; 046 047 import java.awt.image.BufferedImage; 048 049 import javax.media.j3d.Appearance; 050 import javax.media.j3d.Material; 051 import javax.media.j3d.RenderingAttributes; 052 import javax.media.j3d.Shape3D; 053 import javax.vecmath.Color3f; 054 055 import org.deegree.ogcwebservices.wpvs.configuration.RenderingConfiguration; 056 057 /** 058 * The <code>TerrainModel</code> class is a base class for all dgm's (terrains). It is capable of 059 * loading a texture onto the geometry of it's subclasses. 060 * 061 * @author <a href="mailto:bezema@lat-lon.de">Rutger Bezema</a> 062 * 063 * @author last edited by: $Author: apoth $ 064 * 065 * @version $Revision: 9345 $, $Date: 2007-12-27 17:22:25 +0100 (Do, 27 Dez 2007) $ 066 * 067 */ 068 069 public abstract class TerrainModel extends Shape3D { 070 071 private BufferedImage textureImage = null; 072 073 /** 074 * Creates a TerrainModel with a default Appearance set. 075 * <p> 076 * The default apearance of this terrain is defined as: 077 * <ul> 078 * <li> specularColor = new Color3f( 0.7f, 0.7f, 0.7f )</li> 079 * <li> ambientColor = white </li> 080 * <li> diffuseColor = white </li> 081 * <li> shininess = 75f </li> 082 * <li> lighting is enabled </li> 083 * <li> matieral is writable (Material.ALLOW_COMPONENT_WRITE) </li> 084 * </ul> 085 * </p> 086 */ 087 protected TerrainModel() { 088 setCapability( Shape3D.ALLOW_GEOMETRY_WRITE ); 089 setAppearance( createDefaultApperance() ); 090 } 091 092 protected TerrainModel( BufferedImage textureImage ) { 093 this(); 094 this.textureImage = textureImage; 095 } 096 097 /** 098 * This method implements all the necessary steps to generate a Shape3D Terrain (Elevation 099 * model). Before rendering this Class this method should therefor be called prior. 100 */ 101 public abstract void createTerrain(); 102 103 /** 104 * Creates a J3D Appearance for the surface 105 * 106 * @return a new Appearance object 107 */ 108 private Appearance createDefaultApperance() { 109 Appearance appearance = new Appearance(); 110 111 // create a material 112 Color3f specular = new Color3f( 0, 0, 0 ); 113 Color3f white = new Color3f( 1, 1, 1 ); 114 Material targetMaterial = new Material(); 115 targetMaterial.setAmbientColor( white ); 116 targetMaterial.setDiffuseColor( white ); 117 118 targetMaterial.setSpecularColor( specular ); 119 targetMaterial.setShininess( 65f ); 120 targetMaterial.setLightingEnable( true ); 121 targetMaterial.setCapability( Material.ALLOW_COMPONENT_WRITE ); 122 targetMaterial.setCapability( Material.ALLOW_COMPONENT_READ ); 123 // targetMaterial.setColorTarget( Material.AMBIENT_AND_DIFFUSE ); 124 appearance.setMaterial( targetMaterial ); 125 126 RenderingConfiguration rc = RenderingConfiguration.getInstance(); 127 128 appearance.setColoringAttributes( rc.getColoringAttributes() ); 129 130 appearance.setPolygonAttributes( rc.getTerrainPolygonAttributes() ); 131 132 RenderingAttributes ra = new RenderingAttributes(); 133 ra.setDepthBufferEnable(true); 134 appearance.setRenderingAttributes( ra ); 135 136 return appearance; 137 } 138 139 /** 140 * @param textureImage 141 * An other texture value. 142 */ 143 public void setTexture( BufferedImage textureImage ) { 144 if ( textureImage != null ) { 145 this.textureImage = textureImage; 146 Appearance appearance = getAppearance(); 147 148 RenderingConfiguration rc = RenderingConfiguration.getInstance(); 149 150 appearance.setTextureAttributes( rc.getTextureAttributes() ); 151 appearance.setTexture( rc.getTexture( textureImage ) ); 152 153 setAppearance( appearance ); 154 } 155 156 } 157 158 /** 159 * @return the BufferedImage which can be used as a texture or <code>null</code>if no texture was 160 * defined. 161 */ 162 public BufferedImage getTexture() { 163 return this.textureImage; 164 } 165 166 @Override 167 public String toString( ){ 168 StringBuilder sb = new StringBuilder( 512 ); 169 sb.append( "Elevationmodel as a J3D terrainModel: " ); 170 if( textureImage != null ){ 171 sb.append( " with textureImage and "); 172 } 173 sb.append( "Appearance: " ).append( getAppearance() ).append("\n" ); 174 return sb.toString(); 175 } 176 177 }