GeometryTest.java 4.91 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
/*-
 *  Copyright 2020 Beuth Hochschule für Technik Berlin, Hochschule für Technik Stuttgart
 * 
 *  This file is part of CityDoctor2.
 *
 *  CityDoctor2 is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU Lesser General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  CityDoctor2 is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public License
 *  along with CityDoctor2.  If not, see <https://www.gnu.org/licenses/>.
 */
package de.hft.stuttgart.citydoctor2.datastructure;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;

import org.citygml4j.factory.GMLGeometryFactory;
import org.citygml4j.model.citygml.building.AbstractBoundarySurface;
import org.citygml4j.model.citygml.building.WallSurface;
import org.junit.Test;

import de.hft.stuttgart.citydoctor2.datastructure.LinearRing.LinearRingType;
import de.hft.stuttgart.citydoctor2.parser.ParserConfiguration;

/**
 * 
 * @author Matthias Betz
 *
 */
public class GeometryTest {

	@Test
	public void testCreate() {
		Geometry geom = new Geometry(GeometryType.SOLID, Lod.LOD0);
		
		assertNotNull(geom);
		assertSame(GeometryType.SOLID, geom.getType());
		assertSame(Lod.LOD0, geom.getLod());
	}
	
	@Test
	public void testAddPolygon() {
		Geometry geom = new Geometry(GeometryType.SOLID, Lod.LOD0);
		
		Polygon p = new ConcretePolygon();
		geom.addPolygon(p);
		
		assertEquals(1, geom.getPolygons().size());
		assertSame(geom, p.getParent());
		assertSame(geom.getPolygons().get(0), p);
	}
	
	@Test
	public void testRemovePolygon() {
		ParserConfiguration config = new ParserConfiguration(4, false);
		AbstractBoundarySurface abs = new WallSurface();
		BoundarySurface bs = new BoundarySurface(SurfaceFeatureType.BUILDING, BoundarySurfaceType.WALL, abs);
		org.citygml4j.model.citygml.building.BuildingInstallation gmlBi = new org.citygml4j.model.citygml.building.BuildingInstallation();
		BuildingInstallation bi = new BuildingInstallation();
		bi.setGmlObject(gmlBi);
		Geometry geom = new Geometry(GeometryType.SOLID, Lod.LOD2);

		Polygon p = new ConcretePolygon();
		LinearRing lr = new LinearRing(LinearRingType.EXTERIOR);
		p.setExteriorRing(lr);
		lr.addVertex(new Vertex(0, 0, 0));
		
		geom.addPolygon(p);
		p.setPartOfSurface(bs);
		p.setPartOfInstallation(bi);
		
		geom.removePolygon(p);
		
		assertEquals(0, geom.getPolygons().size());
		
		bs.reCreateGeometries(new GMLGeometryFactory(), config);
		assertNull(abs.getLod2MultiSurface());
		
		bi.reCreateGeometries(new GMLGeometryFactory(), config);
		assertNull(gmlBi.getLod2Geometry());
	}
	
	@Test
	public void testReplacePolygon() {
		ParserConfiguration config = new ParserConfiguration(4, false);
		AbstractBoundarySurface abs = new WallSurface();
		BoundarySurface bs = new BoundarySurface(SurfaceFeatureType.BUILDING, BoundarySurfaceType.WALL, abs);
		org.citygml4j.model.citygml.building.BuildingInstallation gmlBi = new org.citygml4j.model.citygml.building.BuildingInstallation();
		BuildingInstallation bi = new BuildingInstallation();
		bi.setGmlObject(gmlBi);
		bi.addBoundarySurface(bs);
		Geometry geom2 = new Geometry(GeometryType.MULTI_SURFACE, Lod.LOD2);
		ConcretePolygon p = new ConcretePolygon();
		geom2.addPolygon(p);
		LinearRing lr = new LinearRing(LinearRingType.EXTERIOR);
		p.setExteriorRing(lr);
		lr.addVertex(new Vertex(0, 0, 0));
		p.setPartOfSurface(bs);
		p.setPartOfInstallation(bi);
		bs.addGeometry(geom2);
		
		
		Geometry geom = new Geometry(GeometryType.SOLID, Lod.LOD2);
		Polygon linkedPoly = new LinkedPolygon(p, geom);
		geom.addPolygon(linkedPoly);
		
		ConcretePolygon p2 = new ConcretePolygon();
		p2.setExteriorRing(lr);

		ConcretePolygon p3 = new ConcretePolygon();
		p3.setExteriorRing(lr);
		
		geom.replacePolygon(linkedPoly, p2, p3);
		
		assertEquals(2, geom.getPolygons().size());
		assertEquals(2, geom2.getPolygons().size());
		
		bi.reCreateGeometries(new GMLGeometryFactory(), config);
		assertNull(gmlBi.getLod2Geometry());
		assertNull(gmlBi.getLod3Geometry());
		assertNull(gmlBi.getLod4Geometry());
		
		bs.reCreateGeometries(new GMLGeometryFactory(), config);
		assertNotNull(abs.getLod2MultiSurface());
		assertNotNull(abs.getLod2MultiSurface().getMultiSurface());
		assertNotNull(abs.getLod2MultiSurface().getMultiSurface().getSurfaceMember());
		assertFalse(abs.getLod2MultiSurface().getMultiSurface().getSurfaceMember().isEmpty());
		assertEquals(2, abs.getLod2MultiSurface().getMultiSurface().getSurfaceMember().size());
		assertNull(gmlBi.getLod2Geometry());
	}

}