001: /*---------------- FILE HEADER ------------------------------------------
002:
003: This file is part of deegree.
004: Copyright (C) 2001-2008 by:
005: EXSE, Department of Geography, University of Bonn
006: http://www.giub.uni-bonn.de/deegree/
007: lat/lon GmbH
008: http://www.lat-lon.de
009:
010: This library is free software; you can redistribute it and/or
011: modify it under the terms of the GNU Lesser General Public
012: License as published by the Free Software Foundation; either
013: version 2.1 of the License, or (at your option) any later version.
014:
015: This library is distributed in the hope that it will be useful,
016: but WITHOUT ANY WARRANTY; without even the implied warranty of
017: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
018: Lesser General Public License for more details.
019:
020: You should have received a copy of the GNU Lesser General Public
021: License along with this library; if not, write to the Free Software
022: Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
023:
024: Contact:
025:
026: Andreas Poth
027: lat/lon GmbH
028: Aennchenstr. 19
029: 53177 Bonn
030: Germany
031: E-Mail: poth@lat-lon.de
032:
033: Prof. Dr. Klaus Greve
034: Department of Geography
035: University of Bonn
036: Meckenheimer Allee 166
037: 53115 Bonn
038: Germany
039: E-Mail: greve@giub.uni-bonn.de
040:
041:
042: ---------------------------------------------------------------------------*/
043:
044: package org.deegree.ogcwebservices.wpvs.operation;
045:
046: import javax.media.j3d.PickShape;
047: import javax.media.j3d.Transform3D;
048: import javax.vecmath.AxisAngle4d;
049: import javax.vecmath.Point3d;
050: import javax.vecmath.Vector3d;
051:
052: import org.deegree.model.crs.CoordinateSystem;
053: import org.deegree.model.spatialschema.Geometry;
054: import org.deegree.model.spatialschema.GeometryException;
055: import org.deegree.ogcwebservices.wpvs.j3d.ViewPoint;
056:
057: /**
058: * This abstract class represents a geometry needed for Get3DFeatureInfoRequest. It contains the 3d geometry and its 2d
059: * projektion. The 2d geometry is required for WFS request, the 3d geometry for the final test of intersection.
060: *
061: * @version $Revision: $
062: * @author <a href="mailto:cordes@lat-lon.de">Lyn Buesching</a>
063: * @author last edited by: $Author: $
064: *
065: * @version 1.0. $Revision: $, $Date: $
066: *
067: */
068: public abstract class RequestGeometry {
069:
070: protected Get3DFeatureInfo request;
071:
072: // begin point of the view ray
073: private Point3d beginPointLine;
074:
075: private CoordinateSystem crs;
076:
077: // geometry for wfs query
078: protected Geometry wfsReqGeom;
079:
080: // 3d geometry: needed for final testing
081: protected PickShape pickshape;
082:
083: /**
084: * Constructor to initialize the attributes needed for all geometries
085: *
086: * @param request
087: * the Get3DFeatureInfoRequest
088: */
089: public RequestGeometry(Get3DFeatureInfo request) {
090: this .request = request;
091: crs = request.getGetViewRequestCopy().getCrs();
092: beginPointLine = new ViewPoint(request.getGetViewRequestCopy())
093: .getObserverPosition();
094: }
095:
096: /**
097: *
098: * @return the pickshape or <code>null</code> if it was not set.
099: */
100: public PickShape getPickshape() {
101: return pickshape;
102: }
103:
104: /**
105: * @return the geometry repsonse from the wfs-request or <code>null</code> if it was not set.
106: */
107: public Geometry getWfsReqGeom() {
108: return wfsReqGeom;
109: }
110:
111: /**
112: * @return the starting point of the line.
113: */
114: public Point3d getBeginPointLine() {
115: return beginPointLine;
116: }
117:
118: /**
119: * @return the crs of the request.
120: */
121: public CoordinateSystem getCrs() {
122: return crs;
123: }
124:
125: /**
126: * @return the request.
127: */
128: public Get3DFeatureInfo getRequest() {
129: return request;
130: }
131:
132: // abstract methods
133: /**
134: * sets the geometry needed for WFS request
135: *
136: * @throws GeometryException
137: * if something went wrong.
138: */
139: public abstract void setWfsReqGeom() throws GeometryException;
140:
141: /**
142: * Sets the geometry needed for final test of intersection
143: */
144: public abstract void setPickshape();
145:
146: /**
147: * Calculates a ray through the ViewPoint and the ClickPoint.
148: *
149: * @param viewPoint
150: * position of the request
151: * @param depth
152: * far clipping plane
153: * @param width
154: * of the request
155: * @param height
156: * of the request
157: * @param clickI
158: * x-axis
159: * @param clickJ
160: * y-axis
161: * @return The end point of the requestGeometry.
162: */
163: protected Point3d calcEndPoint(ViewPoint viewPoint, double depth,
164: int width, int height, int clickI, int clickJ) {
165: // sets extension of the ray
166: double extension = viewPoint.getFarClippingPlane();
167: if (depth > 0 && depth < extension) {
168: extension = depth;
169: }
170: GetView getView = request.getGetViewRequestCopy();
171:
172: // rotates the cklickpoint to the roll-angle
173: double roll = getView.getRoll();
174: double deltaI = -(width / 2) + clickI;
175: double deltaJ = (height / 2) - clickJ;
176:
177: double x = deltaI * Math.cos(roll) + deltaJ * Math.sin(roll);
178: double y = -deltaI * Math.sin(roll) + deltaJ * Math.cos(roll);
179:
180: // calculates the angles to rotate the vector (vp-poi)
181: double aov = viewPoint.getAngleOfView();
182: double distProj = (width / 2) / Math.tan(aov / 2);
183:
184: double angleI = Math.atan(x / distProj);
185: double angleJ = Math.atan(y / distProj);
186:
187: Point3d vp = viewPoint.getObserverPosition();
188: Point3d poi = viewPoint.getPointOfInterest();
189: Vector3d vectorVPtoPOI = new Vector3d();
190: vectorVPtoPOI.sub(poi, vp);
191:
192: Transform3D trans = new Transform3D();
193:
194: // rotation at angleJ (vertikal)
195: Vector3d rotJ = new Vector3d();
196: Vector3d eZ = new Vector3d(0, 0, 1);
197: rotJ.cross(vectorVPtoPOI, eZ);
198: AxisAngle4d axisAngleJ = new AxisAngle4d(rotJ, angleJ);
199: trans.set(axisAngleJ);
200: trans.transform(vectorVPtoPOI);
201:
202: // rotation at angleI (horizontal)
203: Vector3d rotI = new Vector3d();
204: rotI.cross(vectorVPtoPOI, rotJ);
205: AxisAngle4d axisAngleI = new AxisAngle4d(rotI, angleI);
206: trans.set(axisAngleI);
207: trans.transform(vectorVPtoPOI);
208:
209: // scale to extension
210: vectorVPtoPOI.normalize();
211: vectorVPtoPOI.scale(extension);
212: Point3d endPoint = new Point3d();
213:
214: // add to the viewpoint
215: endPoint.add(vp, vectorVPtoPOI);
216: return endPoint;
217: }
218: }
|