01: /*
02: * The Unified Mapping Platform (JUMP) is an extensible, interactive GUI
03: * for visualizing and manipulating spatial features with geometry and attributes.
04: *
05: * Copyright (C) 2003 Vivid Solutions
06: *
07: * This program is free software; you can redistribute it and/or
08: * modify it under the terms of the GNU General Public License
09: * as published by the Free Software Foundation; either version 2
10: * of the License, or (at your option) any later version.
11: *
12: * This program is distributed in the hope that it will be useful,
13: * but WITHOUT ANY WARRANTY; without even the implied warranty of
14: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15: * GNU General Public License for more details.
16: *
17: * You should have received a copy of the GNU General Public License
18: * along with this program; if not, write to the Free Software
19: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20: *
21: * For more information, contact:
22: *
23: * Vivid Solutions
24: * Suite #1A
25: * 2328 Government Street
26: * Victoria BC V8T 5G5
27: * Canada
28: *
29: * (250)385-6040
30: * www.vividsolutions.com
31: */
32:
33: package com.vividsolutions.jump.warp;
34:
35: import java.util.Iterator;
36: import java.util.Map;
37:
38: import com.vividsolutions.jts.geom.Coordinate;
39: import com.vividsolutions.jts.util.Assert;
40: import com.vividsolutions.jump.task.TaskMonitor;
41:
42: /**
43: * Bilinear interpolated triangulation transform, also known as "rubber sheeting".
44: * See Saalfeld, Alan. 1985. A Fast Rubber-Sheeting Transformation Using
45: * Simplical Coordinates. "The American Cartographer" 12:2, 169-173.
46: */
47: public class BilinearInterpolatedTransform extends CoordinateTransform {
48: private Map triangleMap;
49: private TaskMonitor monitor;
50: private int coordinatesTransformed = 0;
51:
52: /**
53: * Creates a RubberSheetTransform using the given triangulation.
54: * @param triangleMap a map of source Triangle to destination Triangle
55: */
56: public BilinearInterpolatedTransform(Map triangleMap,
57: TaskMonitor monitor) {
58: this .triangleMap = triangleMap;
59: this .monitor = monitor;
60: monitor.report("Transforming...");
61: }
62:
63: /**
64: * Maps one Coordinate to another.
65: * @param c a Coordinate which must be inside one of the triangle keys passed
66: * into the constructor
67: * @return the transformed Coordinate
68: */
69: public Coordinate transform(Coordinate c) {
70: monitor.report(++coordinatesTransformed, -1, "coordinates");
71:
72: Triangle sourceTriangle = sourceTriangle(c);
73: Assert.isTrue(sourceTriangle != null,
74: "Unable to determine source triangle for " + c);
75:
76: Triangle destTriangle = destTriangle(sourceTriangle);
77:
78: return destTriangle.toEuclideanCoordinate(sourceTriangle
79: .toSimplicialCoordinate(c));
80: }
81:
82: private Triangle sourceTriangle(Coordinate c) {
83:
84: for (Iterator i = triangleMap.keySet().iterator(); i.hasNext();) {
85: Triangle triangle = (Triangle) i.next();
86: if (triangle.getEnvelope().contains(c)
87: && triangle.contains(c)) {
88: return triangle;
89: }
90: }
91:
92: return null;
93: }
94:
95: private Triangle destTriangle(Triangle sourceTriangle) {
96: return (Triangle) triangleMap.get(sourceTriangle);
97: }
98: }
|