|
| 1 | + /********************************************************************** |
| 2 | + * Copyright (C) by Michael Loesler, http//derletztekick.com * |
| 3 | + * * |
| 4 | + * This program is free software; you can redistribute it and/or modify * |
| 5 | + * it under the terms of the GNU General Public License as published by * |
| 6 | + * the Free Software Foundation; either version 3 of the License, or * |
| 7 | + * (at your option) any later version. * |
| 8 | + * * |
| 9 | + * This program is distributed in the hope that it will be useful, * |
| 10 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of * |
| 11 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
| 12 | + * GNU General Public License for more details. * |
| 13 | + * * |
| 14 | + * You should have received a copy of the GNU General Public License * |
| 15 | + * along with this program; if not, see <http://www.gnu.org/licenses/> * |
| 16 | + * or write to the * |
| 17 | + * Free Software Foundation, Inc., * |
| 18 | + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * |
| 19 | + * * |
| 20 | + **********************************************************************/ |
| 21 | + |
| 22 | +package com.derletztekick.geodesy.bundleadjustment.v2.pointgroup; |
| 23 | +import java.util.ArrayList; |
| 24 | +import java.util.LinkedHashMap; |
| 25 | +import java.util.List; |
| 26 | +import java.util.Map; |
| 27 | + |
| 28 | +import no.uib.cipr.matrix.Matrix; |
| 29 | + |
| 30 | +import com.derletztekick.geodesy.bundleadjustment.v2.unknown.point.Point; |
| 31 | +import com.derletztekick.geodesy.bundleadjustment.v2.unknown.point.Point3D; |
| 32 | +import com.derletztekick.geodesy.bundleadjustment.v2.unknown.transformationparameter.TransformationParameter; |
| 33 | +import com.derletztekick.geodesy.bundleadjustment.v2.unknown.transformationparameter.TransformationParameterSet; |
| 34 | +import com.derletztekick.tools.geodesy.MathExtension; |
| 35 | + |
| 36 | + |
| 37 | +/** |
| 38 | + * Gruppierung von Punkten gleichen Typs (=Dimension) |
| 39 | + * @author Michael Loesler <derletztekick.com> |
| 40 | + * |
| 41 | + */ |
| 42 | +public class PointGroup { |
| 43 | + private int id; |
| 44 | + private int dimension = -1; // Keine Dimension, wenn -1 |
| 45 | + private Matrix CoVar = null; |
| 46 | + private Map<String,Point> pointHashMap = new LinkedHashMap<String,Point>(); |
| 47 | + private List<Point> pointArrayList = new ArrayList<Point>(); |
| 48 | + private TransformationParameterSet transformationParameterSet; |
| 49 | + |
| 50 | + /** |
| 51 | + * Konstruktor fuer Punktgruppe |
| 52 | + * @param id GruppenId |
| 53 | + */ |
| 54 | + public PointGroup(int id) { |
| 55 | + this.id = id; |
| 56 | + } |
| 57 | + |
| 58 | + /** |
| 59 | + * Liefert die Punktgruppenid |
| 60 | + * @return id |
| 61 | + */ |
| 62 | + public final int getId() { |
| 63 | + return this.id; |
| 64 | + } |
| 65 | + |
| 66 | + /** |
| 67 | + * Fuegt einen Punkt der Kollektion hinzu |
| 68 | + * @param point Punkt |
| 69 | + * @return isAdded |
| 70 | + */ |
| 71 | + public boolean add(Point point) { |
| 72 | + //String pointId = ((Point)point).getId(); |
| 73 | + String pointId = point.getId(); |
| 74 | + int pointDim = point.getDimension(); |
| 75 | + |
| 76 | + if (this.dimension<0) |
| 77 | + this.dimension = pointDim; |
| 78 | + |
| 79 | + if (this.dimension != pointDim || this.pointHashMap.containsKey( pointId )) |
| 80 | + return false; |
| 81 | + |
| 82 | + this.pointHashMap.put( pointId, point ); |
| 83 | + this.pointArrayList.add( point ); |
| 84 | + point.setPointGroup(this); |
| 85 | + |
| 86 | + return true; |
| 87 | + } |
| 88 | + |
| 89 | + /** |
| 90 | + * Gibt Punkt an der Stelle <code>index</code> |
| 91 | + * aus der Kollektion zurueck |
| 92 | + * @param index Index |
| 93 | + * @return Point |
| 94 | + * @throws ArrayIndexOutOfBoundsException |
| 95 | + */ |
| 96 | + public Point get( int index ) throws ArrayIndexOutOfBoundsException{ |
| 97 | + return this.pointArrayList.get( index ); |
| 98 | + } |
| 99 | + |
| 100 | + /** |
| 101 | + * Gibt Punkt mit der Punktnummer <code>pointId</code> |
| 102 | + * aus der Kollektion zurueck |
| 103 | + * @param pointId Punktnummer |
| 104 | + * @return Point |
| 105 | + */ |
| 106 | + public Point get( String pointId ) { |
| 107 | + return this.pointHashMap.get( pointId ); |
| 108 | + } |
| 109 | + |
| 110 | + /** |
| 111 | + * Gibt die Anzahl der Punkte zurueck |
| 112 | + * @return size |
| 113 | + */ |
| 114 | + public int size() { |
| 115 | + return this.pointArrayList.size(); |
| 116 | + } |
| 117 | + |
| 118 | + /** |
| 119 | + * Liefert die Dimension der Punkte |
| 120 | + * aus der Gruppe zurueck, enthaelt die |
| 121 | + * Gruppe keine Punkte, wird -1 geliefert |
| 122 | + * @return dimension |
| 123 | + */ |
| 124 | + public int getDimension() { |
| 125 | + return this.dimension; |
| 126 | + } |
| 127 | + |
| 128 | + |
| 129 | + /** |
| 130 | + * Liefert Klassenspezifischen String |
| 131 | + * @return str |
| 132 | + */ |
| 133 | + @Override |
| 134 | + public String toString() { |
| 135 | + return new String(this.getClass() + " " + this.id + " Points in Group: " + this.size()); |
| 136 | + } |
| 137 | + |
| 138 | + |
| 139 | + /** |
| 140 | + * @see java.lang.Object#equals(java.lang.Object) |
| 141 | + */ |
| 142 | + @Override |
| 143 | + public boolean equals(Object obj) { |
| 144 | + if (this == obj) |
| 145 | + return true; |
| 146 | + if (obj == null) |
| 147 | + return false; |
| 148 | + if (getClass() != obj.getClass()) |
| 149 | + return false; |
| 150 | + final PointGroup pointGroup = (PointGroup) obj; |
| 151 | + if (id != pointGroup.id) |
| 152 | + return false; |
| 153 | + if (pointArrayList == null) { |
| 154 | + if (pointGroup.pointArrayList != null) |
| 155 | + return false; |
| 156 | + } else if (!pointArrayList.equals(pointGroup.pointArrayList)) |
| 157 | + return false; |
| 158 | + if (pointHashMap == null) { |
| 159 | + if (pointGroup.pointHashMap != null) |
| 160 | + return false; |
| 161 | + } else if (!pointHashMap.equals(pointGroup.pointHashMap)) |
| 162 | + return false; |
| 163 | + return true; |
| 164 | + } |
| 165 | + |
| 166 | + /** |
| 167 | + * Berechnet den Schwerpunkt einer Punktgruppe |
| 168 | + * @return centerPoint Schwerpunkt |
| 169 | + */ |
| 170 | + public Point getCenterPoint() { |
| 171 | + double x = 0.0, |
| 172 | + y = 0.0, |
| 173 | + z = 0.0; |
| 174 | + |
| 175 | + for (int i=0; i<this.size(); i++) { |
| 176 | + if (this.getDimension() > 1) { |
| 177 | + x += this.get(i).getX(); |
| 178 | + y += this.get(i).getY(); |
| 179 | + } |
| 180 | + if (this.getDimension() != 2) { |
| 181 | + z += this.get(i).getZ(); |
| 182 | + } |
| 183 | + } |
| 184 | + |
| 185 | +// if (this.getDimension() == 1) |
| 186 | +// return new Point1D("c", z/this.size()); |
| 187 | +// |
| 188 | +// else if (this.getDimension() == 2) |
| 189 | +// return new Point2D("c", x/this.size(), y/this.size()); |
| 190 | +// |
| 191 | +// else |
| 192 | + if (this.getDimension() == 3) |
| 193 | + return new Point3D(this.getClass().getSimpleName(), x/this.size(), y/this.size(), z/this.size()); |
| 194 | + |
| 195 | + return null; |
| 196 | + } |
| 197 | + |
| 198 | + /** |
| 199 | + * Liefert <ocde>true</code>, wenn ein Punkt mit der Punktnummer bereits existiert. |
| 200 | + * Die Koordinaten werden nicht verglichen! |
| 201 | + * @param point |
| 202 | + * @return contains |
| 203 | + */ |
| 204 | + public boolean contains(Point point) { |
| 205 | + return this.pointHashMap.containsKey(point.getId()); |
| 206 | + } |
| 207 | + |
| 208 | + /** |
| 209 | + * Liefert <ocde>true</code>, wenn ein Punkt mit der Punktnummer bereits existiert. |
| 210 | + * @param pointId |
| 211 | + * @return contains |
| 212 | + */ |
| 213 | + public boolean contains(String pointId) { |
| 214 | + return this.pointHashMap.containsKey(pointId); |
| 215 | + } |
| 216 | + |
| 217 | + /** |
| 218 | + * Liefert die Kovarianzmatrix der Punktgruppe |
| 219 | + * @return CoVar |
| 220 | + */ |
| 221 | + public Matrix getCovarianceMatrix() { |
| 222 | + int len = this.size()*this.getDimension(); |
| 223 | + |
| 224 | + if (this.CoVar == null || !this.CoVar.isSquare() || this.CoVar.numColumns() != len) |
| 225 | + return MathExtension.identity(len); |
| 226 | + |
| 227 | + return this.CoVar; |
| 228 | + } |
| 229 | + |
| 230 | + /** |
| 231 | + * Setzt die Kovarianzmatrix der Punktgruppe |
| 232 | + * @param CoVar |
| 233 | + */ |
| 234 | + public void setCovarianceMatrix(Matrix CoVar) { |
| 235 | + this.CoVar = CoVar; |
| 236 | + } |
| 237 | + |
| 238 | + /** |
| 239 | + * Setzt die Transformationsparameter der Punktgruppe |
| 240 | + * @param trafoSet |
| 241 | + */ |
| 242 | + public void setTransformationParameterSet(TransformationParameterSet trafoSet) { |
| 243 | + this.transformationParameterSet = trafoSet; |
| 244 | + TransformationParameter trafoParam[] = this.transformationParameterSet.getTransformationParameters(); |
| 245 | + for (int i=0; i<trafoParam.length; i++) |
| 246 | + trafoParam[i].setPointGroup(this); |
| 247 | + } |
| 248 | + |
| 249 | + /** |
| 250 | + * Liefert die Transformationsparameter der Punktgruppe |
| 251 | + * @return trafoSet |
| 252 | + */ |
| 253 | + public TransformationParameterSet getTransformationParameterSet() { |
| 254 | + return this.transformationParameterSet; |
| 255 | + } |
| 256 | + |
| 257 | +} |
0 commit comments