FeatureMapper.java 16.5 KB
Newer Older
Matthias Betz's avatar
Matthias Betz committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
/*-
 * Copyright 2021 Hochschule für Technik Stuttgart
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package de.hft.stuttgart.citygml.viewer.parser;

import java.awt.Color;
import java.util.ArrayList;
import java.util.List;
Matthias Betz's avatar
Matthias Betz committed
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50

import org.citygml4j.core.model.bridge.AbstractBridge;
import org.citygml4j.core.model.building.AbstractBuilding;
import org.citygml4j.core.model.building.BuildingInstallation;
import org.citygml4j.core.model.cityfurniture.CityFurniture;
import org.citygml4j.core.model.cityobjectgroup.CityObjectGroup;
import org.citygml4j.core.model.construction.AbstractFillingElement;
import org.citygml4j.core.model.construction.Door;
import org.citygml4j.core.model.construction.GroundSurface;
import org.citygml4j.core.model.construction.OtherConstruction;
import org.citygml4j.core.model.construction.RoofSurface;
import org.citygml4j.core.model.construction.Window;
import org.citygml4j.core.model.core.AbstractSpace;
import org.citygml4j.core.model.core.AbstractThematicSurface;
import org.citygml4j.core.model.core.ImplicitGeometry;
import org.citygml4j.core.model.core.ImplicitGeometryProperty;
import org.citygml4j.core.model.deprecated.building.DeprecatedPropertiesOfAbstractBuilding;
import org.citygml4j.core.model.deprecated.core.DeprecatedPropertiesOfAbstractThematicSurface;
import org.citygml4j.core.model.deprecated.transportation.DeprecatedPropertiesOfAbstractTransportationSpace;
import org.citygml4j.core.model.generics.GenericLogicalSpace;
import org.citygml4j.core.model.generics.GenericOccupiedSpace;
import org.citygml4j.core.model.generics.GenericThematicSurface;
import org.citygml4j.core.model.generics.GenericUnoccupiedSpace;
import org.citygml4j.core.model.landuse.LandUse;
import org.citygml4j.core.model.relief.TINRelief;
import org.citygml4j.core.model.transportation.AbstractTransportationSpace;
import org.citygml4j.core.model.vegetation.PlantCover;
import org.citygml4j.core.model.vegetation.SolitaryVegetationObject;
import org.citygml4j.core.model.waterbody.WaterBody;
import org.citygml4j.core.visitor.ObjectWalker;
Matthias Betz's avatar
Matthias Betz committed
51
52
53
54
55
import org.locationtech.proj4j.BasicCoordinateTransform;
import org.locationtech.proj4j.ProjCoordinate;
import org.xmlobjects.gml.model.geometry.AbstractGeometry;
import org.xmlobjects.gml.model.geometry.GeometricPositionList;
import org.xmlobjects.gml.model.geometry.GeometryProperty;
Matthias Betz's avatar
Matthias Betz committed
56
import org.xmlobjects.gml.model.geometry.aggregates.MultiSolidProperty;
Matthias Betz's avatar
Matthias Betz committed
57
58
59
import org.xmlobjects.gml.model.geometry.primitives.AbstractRing;
import org.xmlobjects.gml.model.geometry.primitives.AbstractRingProperty;
import org.xmlobjects.gml.model.geometry.primitives.LinearRing;
Matthias Betz's avatar
Matthias Betz committed
60
import org.xmlobjects.gml.model.geometry.primitives.SolidProperty;
Matthias Betz's avatar
Matthias Betz committed
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import org.xmlobjects.gml.model.geometry.primitives.Triangle;

import de.hft.stuttgart.citygml.viewer.datastructure.Polygon;
import de.hft.stuttgart.citygml.viewer.datastructure.Ring;
import de.hft.stuttgart.citygml.viewer.math.Vector3d;

public class FeatureMapper extends ObjectWalker {

	private ParserConfiguration config;
	private List<Polygon> lod1Polygons;
	private List<Polygon> lod2Polygons;
	private List<Polygon> lod3Polygons;
	private List<Polygon> lod4Polygons;

	private List<Polygon> currentPolygons = null;
	private Ring currentRing;
	private Color currentColor;

	private ProjCoordinate p1 = new ProjCoordinate();
	private ProjCoordinate p2 = new ProjCoordinate();

82
83
84
85
86
87
	private PolygonColorMapper colorMapper;
	private ColorHandler colorHandler;

	public FeatureMapper(ParserConfiguration config, PolygonColorMapper colorMapper, ColorHandler colorHandler) {
		this.colorMapper = colorMapper;
		this.colorHandler = colorHandler;
Matthias Betz's avatar
Matthias Betz committed
88
		this.config = config;
89
		currentColor = colorHandler.getWallColor();
Matthias Betz's avatar
Matthias Betz committed
90
91
92
93
94
95
		lod1Polygons = new ArrayList<>();
		lod2Polygons = new ArrayList<>();
		lod3Polygons = new ArrayList<>();
		lod4Polygons = new ArrayList<>();
	}

Matthias Betz's avatar
Matthias Betz committed
96
97
98
99
	@Override
	public void visit(org.xmlobjects.gml.model.geometry.primitives.Polygon gmlPoly) {
		if (currentPolygons == null) {
			return;
Matthias Betz's avatar
Matthias Betz committed
100
		}
101
102
		Color setColor = currentColor;
		if (gmlPoly.getId() != null) {
103
			Color mappedColor = colorMapper.getColorForPolygon(gmlPoly.getId());
104
105
106
107
108
			if (mappedColor != null) {
				setColor = mappedColor;
			}
		}
		Polygon viewerPoly = new Polygon(setColor);
Matthias Betz's avatar
Matthias Betz committed
109
110
111
112
113
114
115
116
117
118
119
120
121
		// parse rings
		Ring extRing = new Ring();
		viewerPoly.setExteriorRing(extRing);
		mapRing(gmlPoly.getExterior(), extRing);

		if (gmlPoly.getInterior() != null) {
			for (AbstractRingProperty arp : gmlPoly.getInterior()) {
				if (arp.getObject() != null) {
					Ring innerRing = new Ring();
					viewerPoly.addInteriorRing(innerRing);
					mapRing(arp, innerRing);
				}
			}
Matthias Betz's avatar
Matthias Betz committed
122
		}
Matthias Betz's avatar
Matthias Betz committed
123
		currentPolygons.add(viewerPoly);
Matthias Betz's avatar
Matthias Betz committed
124
125
126
	}

	@Override
Matthias Betz's avatar
Matthias Betz committed
127
	public void visit(org.xmlobjects.gml.model.geometry.primitives.PolygonPatch gmlPoly) {
Matthias Betz's avatar
Matthias Betz committed
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
		if (currentPolygons == null) {
			return;
		}
		Polygon viewerPoly = new Polygon(currentColor);
		// parse rings
		Ring extRing = new Ring();
		viewerPoly.setExteriorRing(extRing);
		mapRing(gmlPoly.getExterior(), extRing);

		if (gmlPoly.getInterior() != null) {
			for (AbstractRingProperty arp : gmlPoly.getInterior()) {
				if (arp.getObject() != null) {
					Ring innerRing = new Ring();
					viewerPoly.addInteriorRing(innerRing);
					mapRing(arp, innerRing);
				}
			}
		}
		currentPolygons.add(viewerPoly);
	}
148

Matthias Betz's avatar
Matthias Betz committed
149
150
	@Override
	public void visit(OtherConstruction otherConstruction) {
151
		currentColor = colorHandler.getWallColor();
Matthias Betz's avatar
Matthias Betz committed
152
153
		super.visit(otherConstruction);
	}
154

Matthias Betz's avatar
Matthias Betz committed
155
156
	@Override
	public void visit(CityFurniture cityFurniture) {
157
		currentColor = colorHandler.getWallColor();
Matthias Betz's avatar
Matthias Betz committed
158
159
		super.visit(cityFurniture);
	}
160

Matthias Betz's avatar
Matthias Betz committed
161
162
	@Override
	public void visit(CityObjectGroup cityObjectGroup) {
163
		currentColor = colorHandler.getWallColor();
Matthias Betz's avatar
Matthias Betz committed
164
165
		super.visit(cityObjectGroup);
	}
166

Matthias Betz's avatar
Matthias Betz committed
167
168
	@Override
	public void visit(GenericLogicalSpace genericLogicalSpace) {
169
		currentColor = colorHandler.getWallColor();
Matthias Betz's avatar
Matthias Betz committed
170
171
		super.visit(genericLogicalSpace);
	}
172

Matthias Betz's avatar
Matthias Betz committed
173
174
	@Override
	public void visit(GenericOccupiedSpace genericOccupiedSpace) {
175
		currentColor = colorHandler.getWallColor();
Matthias Betz's avatar
Matthias Betz committed
176
177
		super.visit(genericOccupiedSpace);
	}
178

Matthias Betz's avatar
Matthias Betz committed
179
180
	@Override
	public void visit(GenericThematicSurface genericThematicSurface) {
181
		currentColor = colorHandler.getWallColor();
Matthias Betz's avatar
Matthias Betz committed
182
183
		super.visit(genericThematicSurface);
	}
184

Matthias Betz's avatar
Matthias Betz committed
185
186
	@Override
	public void visit(GenericUnoccupiedSpace genericUnoccupiedSpace) {
187
		currentColor = colorHandler.getWallColor();
Matthias Betz's avatar
Matthias Betz committed
188
189
190
		super.visit(genericUnoccupiedSpace);
	}

Matthias Betz's avatar
Matthias Betz committed
191
192
193
194
195
196
197
198
199
200
201
202
203
204
	@Override
	public void visit(Triangle triangle) {
		if (currentPolygons == null) {
			return;
		}
		// triangle is only a special case of a polygon
		// so use a polygon
		Polygon viewerPoly = new Polygon(currentColor);
		// parse rings
		Ring extRing = new Ring();
		viewerPoly.setExteriorRing(extRing);
		mapRing(triangle.getExterior(), extRing);
		currentPolygons.add(viewerPoly);
	}
Matthias Betz's avatar
Matthias Betz committed
205

Matthias Betz's avatar
Matthias Betz committed
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
	private void mapRing(AbstractRingProperty gmlRing, Ring viewerRing) {
		if (gmlRing == null || gmlRing.getObject() == null) {
			return;
		}
		AbstractRing ringGeometry = gmlRing.getObject();
		currentRing = viewerRing;
		// jump to LinearRing or Ring visit
		ringGeometry.accept(this);
	}

	@Override
	public void visit(LinearRing linearRing) {
		if (linearRing.getControlPoints() != null) {
			int dimension = getDimension(linearRing);
			parseControlPoints(linearRing.getControlPoints(), dimension);
		}
	}

	private int getDimension(LinearRing linearRing) {
		int dimension = 3;
		if (linearRing.getSrsDimension() != null) {
			dimension = linearRing.getSrsDimension();
		}
		return dimension;
	}

	private void parseControlPoints(GeometricPositionList controlPoints, int dimension) {
		List<Double> coords = controlPoints.toCoordinateList3D();
		switch (dimension) {
		case 1:
			for (int i = 0; i < coords.size(); i++) {
				createVertex(coords.get(i), 0, 0);
			}
			break;
		case 2:
			for (int i = 0; i < coords.size(); i = i + 2) {
				createVertex(coords.get(i + 0), coords.get(i + 1), 0);
			}
			break;
		case 3:
			for (int i = 0; i < coords.size(); i = i + 3) {
				createVertex(coords.get(i + 0), coords.get(i + 1), coords.get(i + 2));
			}
			break;
		default:
			throw new UnsupportedOperationException("Cannot parse Coordinates with dimension:" + dimension);
		}
	}

	private void createVertex(double x, double y, double z) {
		// transform into utm, if available
		BasicCoordinateTransform trans = config.getTargetTransform();
		if (trans != null) {
			p1.setValue(x, y);
			trans.transform(p1, p2);
			x = p2.x;
			y = p2.y;
		}
		Vector3d v = new Vector3d(x, y, z);
		currentRing.addPoint(v);
	}

Matthias Betz's avatar
Matthias Betz committed
268
269
270
271
272
273
274
275
276
277
	@Override
	public void visit(AbstractSpace ab) {
		super.visit(ab);
		parseAbstractGeometry(ab.getLod0MultiSurface(), lod1Polygons);
		parseAbstractGeometry(ab.getLod2MultiSurface(), lod2Polygons);
		parseAbstractGeometry(ab.getLod3MultiSurface(), lod3Polygons);
		parseAbstractGeometry(ab.getLod1Solid(), lod1Polygons);
		parseAbstractGeometry(ab.getLod2Solid(), lod2Polygons);
		parseAbstractGeometry(ab.getLod3Solid(), lod3Polygons);
	}
278

Matthias Betz's avatar
Matthias Betz committed
279
280
	@Override
	public void visit(AbstractBuilding ab) {
281
		currentColor = colorHandler.getWallColor();
Matthias Betz's avatar
Matthias Betz committed
282
283
		super.visit(ab);
		DeprecatedPropertiesOfAbstractBuilding deprecatedProperties = ab.getDeprecatedProperties();
Matthias Betz's avatar
Matthias Betz committed
284
285
286
		parseAbstractGeometry(deprecatedProperties.getLod1MultiSurface(), lod1Polygons);
		parseAbstractGeometry(deprecatedProperties.getLod4MultiSurface(), lod4Polygons);
		parseAbstractGeometry(deprecatedProperties.getLod4Solid(), lod4Polygons);
Matthias Betz's avatar
Matthias Betz committed
287
	}
Matthias Betz's avatar
Matthias Betz committed
288

Matthias Betz's avatar
Matthias Betz committed
289
290
291
292
293
	@Override
	public void visit(TINRelief tinRelief) {
		if (tinRelief.getTin() == null || tinRelief.getTin().getObject() == null) {
			return;
		}
Matthias Betz's avatar
Matthias Betz committed
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
		switch (tinRelief.getLod()) {
		case 0, 1:
			currentPolygons = lod1Polygons;
			break;
		case 2:
			currentPolygons = lod2Polygons;
			break;
		case 3:
			currentPolygons = lod3Polygons;
			break;
		case 4:
			currentPolygons = lod4Polygons;
			break;
		default:
			currentPolygons = lod1Polygons;
			break;
		}
311
		currentColor = colorHandler.getLandColor();
Matthias Betz's avatar
Matthias Betz committed
312
		super.visit(tinRelief);
Matthias Betz's avatar
Matthias Betz committed
313
314
315
316
	}

	@Override
	public void visit(WaterBody wb) {
317
		currentColor = colorHandler.getWaterColor();
Matthias Betz's avatar
Matthias Betz committed
318
		super.visit(wb);
Matthias Betz's avatar
Matthias Betz committed
319
320
		parseAbstractGeometry(wb.getDeprecatedProperties().getLod1MultiSurface(), lod1Polygons);
		parseAbstractGeometry(wb.getDeprecatedProperties().getLod4Solid(), lod4Polygons);
Matthias Betz's avatar
Matthias Betz committed
321
322
323
324
	}

	@Override
	public void visit(PlantCover pc) {
325
		currentColor = colorHandler.getVegetationColor();
Matthias Betz's avatar
Matthias Betz committed
326
		super.visit(pc);
Matthias Betz's avatar
Matthias Betz committed
327
328
329
330
331
332
333
334
335
336
337
338
339
340
		parseAbstractGeometry(pc.getDeprecatedProperties().getLod1MultiSurface(), lod1Polygons);
		parseMultiSolid(pc.getDeprecatedProperties().getLod1MultiSolid(), lod1Polygons);
		parseMultiSolid(pc.getDeprecatedProperties().getLod2MultiSolid(), lod2Polygons);
		parseMultiSolid(pc.getDeprecatedProperties().getLod3MultiSolid(), lod3Polygons);
		parseMultiSolid(pc.getDeprecatedProperties().getLod4MultiSolid(), lod4Polygons);
	}

	private void parseMultiSolid(MultiSolidProperty ms, List<Polygon> polygons) {
		if (ms == null || ms.getObject() == null) {
			return;
		}
		for (SolidProperty sp : ms.getObject().getSolidMember()) {
			parseAbstractGeometry(sp, polygons);
		}
Matthias Betz's avatar
Matthias Betz committed
341
342
343
344
	}

	@Override
	public void visit(SolitaryVegetationObject svo) {
345
		currentColor = colorHandler.getVegetationColor();
Matthias Betz's avatar
Matthias Betz committed
346
		super.visit(svo);
Matthias Betz's avatar
Matthias Betz committed
347
348
349
350
351
		parseAbstractGeometry(svo.getDeprecatedProperties().getLod1Geometry(), lod1Polygons);
		parseAbstractGeometry(svo.getDeprecatedProperties().getLod2Geometry(), lod2Polygons);
		parseAbstractGeometry(svo.getDeprecatedProperties().getLod3Geometry(), lod3Polygons);
		parseAbstractGeometry(svo.getDeprecatedProperties().getLod4Geometry(), lod4Polygons);
	}
352

Matthias Betz's avatar
Matthias Betz committed
353
354
355
	@Override
	public void visit(GroundSurface groundSurface) {
		Color oldColor = currentColor;
356
		currentColor = colorHandler.getGroundColor();
Matthias Betz's avatar
Matthias Betz committed
357
358
359
360
		// process window
		super.visit(groundSurface);
		currentColor = oldColor;
	}
361

Matthias Betz's avatar
Matthias Betz committed
362
363
364
	@Override
	public void visit(RoofSurface roofSurface) {
		Color oldColor = currentColor;
365
		currentColor = colorHandler.getRoofColor();
Matthias Betz's avatar
Matthias Betz committed
366
367
368
		// process window
		super.visit(roofSurface);
		currentColor = oldColor;
Matthias Betz's avatar
Matthias Betz committed
369
370
371
372
373
374
	}

	@Override
	public void visit(AbstractThematicSurface abs) {
		super.visit(abs);
		DeprecatedPropertiesOfAbstractThematicSurface deprecatedProperties = abs.getDeprecatedProperties();
Matthias Betz's avatar
Matthias Betz committed
375
376
377
378
379
		parseAbstractGeometry(abs.getLod0MultiSurface(), lod1Polygons);
		parseAbstractGeometry(abs.getLod1MultiSurface(), lod1Polygons);
		parseAbstractGeometry(abs.getLod2MultiSurface(), lod2Polygons);
		parseAbstractGeometry(abs.getLod3MultiSurface(), lod3Polygons);
		parseAbstractGeometry(deprecatedProperties.getLod4MultiSurface(), lod4Polygons);
Matthias Betz's avatar
Matthias Betz committed
380
381
382
383
	}

	@Override
	public void visit(LandUse landUse) {
384
		currentColor = colorHandler.getLandColor();
Matthias Betz's avatar
Matthias Betz committed
385
386
		super.visit(landUse);
	}
387

Matthias Betz's avatar
Matthias Betz committed
388
	@Override
Matthias Betz's avatar
Matthias Betz committed
389
	public void visit(AbstractTransportationSpace ats) {
390
		currentColor = colorHandler.getTransportationColor();
Matthias Betz's avatar
Matthias Betz committed
391
392
393
394
395
396
397
398
399
		DeprecatedPropertiesOfAbstractTransportationSpace deprecatedProperties = ats.getDeprecatedProperties();
		parseAbstractGeometry(ats.getLod1Solid(), lod1Polygons);
		parseAbstractGeometry(ats.getLod2Solid(), lod1Polygons);
		parseAbstractGeometry(ats.getLod3Solid(), lod1Polygons);
		parseAbstractGeometry(ats.getLod0MultiSurface(), lod1Polygons);
		parseAbstractGeometry(deprecatedProperties.getLod1MultiSurface(), lod1Polygons);
		parseAbstractGeometry(ats.getLod2MultiSurface(), lod2Polygons);
		parseAbstractGeometry(ats.getLod3MultiSurface(), lod3Polygons);
		parseAbstractGeometry(deprecatedProperties.getLod4MultiSurface(), lod4Polygons);
Matthias Betz's avatar
Matthias Betz committed
400
	}
401

Matthias Betz's avatar
Matthias Betz committed
402
	@Override
Matthias Betz's avatar
Matthias Betz committed
403
404
	public void visit(Window window) {
		Color oldColor = currentColor;
405
		currentColor = colorHandler.getWindowColor();
Matthias Betz's avatar
Matthias Betz committed
406
407
408
		// process window
		super.visit(window);
		currentColor = oldColor;
Matthias Betz's avatar
Matthias Betz committed
409
	}
410

Matthias Betz's avatar
Matthias Betz committed
411
	@Override
Matthias Betz's avatar
Matthias Betz committed
412
413
	public void visit(Door door) {
		Color oldColor = currentColor;
414
		currentColor = colorHandler.getDoorColor();
Matthias Betz's avatar
Matthias Betz committed
415
416
		super.visit(door);
		currentColor = oldColor;
Matthias Betz's avatar
Matthias Betz committed
417
	}
418

Matthias Betz's avatar
Matthias Betz committed
419
420
421
	@Override
	public void visit(AbstractFillingElement ao) {
		super.visit(ao);
Matthias Betz's avatar
Matthias Betz committed
422
423
424
425
426
427
428
429
		parseAbstractGeometry(ao.getLod1Solid(), lod1Polygons);
		parseAbstractGeometry(ao.getLod2Solid(), lod2Polygons);
		parseAbstractGeometry(ao.getLod3Solid(), lod3Polygons);
		parseAbstractGeometry(ao.getLod2MultiSurface(), lod2Polygons);
		parseAbstractGeometry(ao.getLod3MultiSurface(), lod3Polygons);
		parseImplicitGeometry(ao.getLod1ImplicitRepresentation(), lod1Polygons);
		parseImplicitGeometry(ao.getLod2ImplicitRepresentation(), lod2Polygons);
		parseImplicitGeometry(ao.getLod3ImplicitRepresentation(), lod3Polygons);
Matthias Betz's avatar
Matthias Betz committed
430
431
432
433
	}

	@Override
	public void visit(AbstractBridge ab) {
434
		currentColor = colorHandler.getBridgeColor();
Matthias Betz's avatar
Matthias Betz committed
435
		super.visit(ab);
Matthias Betz's avatar
Matthias Betz committed
436
437
438
		parseAbstractGeometry(ab.getDeprecatedProperties().getLod1MultiSurface(), lod1Polygons);
		parseAbstractGeometry(ab.getDeprecatedProperties().getLod4MultiSurface(), lod4Polygons);
		parseAbstractGeometry(ab.getDeprecatedProperties().getLod4Solid(), lod4Polygons);
Matthias Betz's avatar
Matthias Betz committed
439
	}
Matthias Betz's avatar
Matthias Betz committed
440

Matthias Betz's avatar
Matthias Betz committed
441
442
	@Override
	public void visit(BuildingInstallation bi) {
443
		currentColor = colorHandler.getWallColor();
Matthias Betz's avatar
Matthias Betz committed
444
445
446
		super.visit(bi);
	}

Matthias Betz's avatar
Matthias Betz committed
447
	private void parseImplicitGeometry(ImplicitGeometryProperty irp, List<Polygon> polygons) {
Matthias Betz's avatar
Matthias Betz committed
448
449
450
451
		if (irp == null || irp.getObject() == null) {
			return;
		}
		ImplicitGeometry implicitGeometry = irp.getObject();
Matthias Betz's avatar
Matthias Betz committed
452
		parseAbstractGeometry(implicitGeometry.getRelativeGeometry(), polygons);
Matthias Betz's avatar
Matthias Betz committed
453
454
	}

Matthias Betz's avatar
Matthias Betz committed
455
	private void parseAbstractGeometry(GeometryProperty<? extends AbstractGeometry> geom, List<Polygon> polygons) {
Matthias Betz's avatar
Matthias Betz committed
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
		if (geom == null || geom.getObject() == null) {
			return;
		}
		currentPolygons = polygons;
		geom.getObject().accept(this);
		currentPolygons = null;
	}

	public List<Polygon> getLod1Polygons() {
		return lod1Polygons;
	}

	public List<Polygon> getLod2Polygons() {
		return lod2Polygons;
	}

	public List<Polygon> getLod3Polygons() {
		return lod3Polygons;
	}

	public List<Polygon> getLod4Polygons() {
		return lod4Polygons;
	}

	public void movePolygonsBy(Vector3d center) {
		movePolygonsBy(lod1Polygons, center);
		movePolygonsBy(lod2Polygons, center);
		movePolygonsBy(lod3Polygons, center);
		movePolygonsBy(lod4Polygons, center);
	}

	private void movePolygonsBy(List<Polygon> polygons, Vector3d center) {
		for (Polygon p : polygons) {
			for (Vector3d v : p.getExteriorRing().getVertices()) {
				movePointBy(v, center);
			}
			for (Ring r : p.getInteriorRings()) {
				for (Vector3d v : r.getVertices()) {
					movePointBy(v, center);
				}
			}
		}
	}

	private void movePointBy(Vector3d v, Vector3d center) {
		v.setX(v.getX() - center.getX());
		v.setY(v.getY() - center.getY());
		v.setZ(v.getZ() - center.getZ());
	}
}