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