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 java.awt.geom.Point2D;
047:
048: import javax.media.j3d.PickConeSegment;
049: import javax.vecmath.Point3d;
050: import javax.vecmath.Vector3d;
051:
052: import org.deegree.model.spatialschema.GeometryException;
053: import org.deegree.model.spatialschema.GeometryFactory;
054: import org.deegree.model.spatialschema.Position;
055: import org.deegree.model.spatialschema.SurfaceInterpolation;
056: import org.deegree.model.spatialschema.SurfaceInterpolationImpl;
057: import org.deegree.ogcwebservices.wpvs.j3d.ViewPoint;
058:
059: /**
060: * This class represents the geometry needed for a request cone.
061: *
062: * @version $Revision: $
063: * @author <a href="mailto:cordes@lat-lon.de">Lyn Buesching</a>
064: * @author last edited by: $Author: $
065: *
066: * @version 1.0. $Revision: $, $Date: $
067: *
068: */
069: public class ConeRequest extends RequestGeometry {
070:
071: // end point of the view ray
072: private Point3d endPointLine;
073:
074: /**
075: * Initializes the two Geometries for the request with a cone.
076: *
077: * @param request
078: */
079: public ConeRequest(Get3DFeatureInfo request) {
080: super (request);
081: endPointLine = new Point3d(calcEndPoint(new ViewPoint(request
082: .getGetViewRequestCopy()), (int) request.getDepth(),
083: (int) request.getGetViewRequestCopy()
084: .getImageDimension().getWidth(), (int) request
085: .getGetViewRequestCopy().getImageDimension()
086: .getHeight(), request.getClickPoint().x,
087: request.getClickPoint().y));
088: }
089:
090: @Override
091: public void setPickshape() {
092: pickshape = new PickConeSegment(getBeginPointLine(),
093: endPointLine, getRequest().getApexAngle());
094: }
095:
096: @Override
097: public void setWfsReqGeom() throws GeometryException {
098:
099: Position[] pos = new Position[4];
100: int i = 0;
101: pos[i++] = GeometryFactory.createPosition(
102: getBeginPointLine().x, getBeginPointLine().y, 0);
103:
104: Vector3d tmp = new Vector3d();
105: tmp.sub(getBeginPointLine(), endPointLine);
106: double length = tmp.length();
107: double r = Math.tan(getRequest().getApexAngle()) * length;
108:
109: double dX = endPointLine.x - getBeginPointLine().x;
110: double dY = endPointLine.y - getBeginPointLine().y;
111: double lengthGround = Math.sqrt(Math.pow(dX, 2)
112: + Math.pow(dY, 2));
113:
114: double dif = Math.tan(getRequest().getApexAngle())
115: * (lengthGround + r);
116: double rot = Math.toRadians(90);
117: if (dY == 0 && dX > 0) {
118: rot = Math.toRadians(270);
119: } else if (dX != dY) {
120: rot = Math.atan(dX / dY);
121: }
122: if (dY < 0) {
123: rot = (rot + Math.toRadians(180));
124: } else {
125: rot = (rot + Math.toRadians(360));
126: }
127: rot = Math.toRadians(360) - (rot % Math.toRadians(360));
128:
129: // transformation
130: Point2D.Double point2 = trans2d(getBeginPointLine().x,
131: getBeginPointLine().y, rot, new Point2D.Double(dif,
132: lengthGround));
133: pos[i++] = GeometryFactory
134: .createPosition(point2.x, point2.y, 0);
135:
136: Point2D.Double point3 = trans2d(getBeginPointLine().x,
137: getBeginPointLine().y, rot, new Point2D.Double(-dif,
138: lengthGround));
139: pos[i++] = GeometryFactory
140: .createPosition(point3.x, point3.y, 0);
141:
142: pos[i++] = pos[0];
143:
144: SurfaceInterpolation si = new SurfaceInterpolationImpl(0);
145: wfsReqGeom = GeometryFactory.createSurface(pos,
146: new Position[0][0], si, getCrs());
147: }
148:
149: /**
150: * 3-parameter transformation
151: *
152: * @param translationX the translation in x
153: * @param translationY the translation in x
154: * @param rotation rotation of the transformation
155: * @param transPoint point to transform
156: *
157: * @return the point in the new coordinatsystem
158: */
159: private Point2D.Double trans2d(double translationX,
160: double translationY, double rotation,
161: Point2D.Double transPoint) {
162:
163: double xTrans = transPoint.x * Math.cos(rotation)
164: - transPoint.y * Math.sin(rotation) + translationX;
165: double yTrans = transPoint.x * Math.sin(rotation)
166: + transPoint.y * Math.cos(rotation) + translationY;
167: return new Point2D.Double(xTrans, yTrans);
168: }
169: }
|