Checks.java 5.47 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
/*-
 *  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.checks;

import java.util.ArrayList;
import java.util.EnumMap;
import java.util.List;
import java.util.Map;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import de.hft.stuttgart.citydoctor2.check.Check;
import de.hft.stuttgart.citydoctor2.check.CheckId;
Matthias Betz's avatar
Matthias Betz committed
31
32
import de.hft.stuttgart.citydoctor2.checks.geometry.RingNotClosedCheck;
import de.hft.stuttgart.citydoctor2.checks.geometry.MultipleConnectedComponentCheck;
33
import de.hft.stuttgart.citydoctor2.checks.geometry.DuplicatePointsCheck;
Matthias Betz's avatar
Matthias Betz committed
34
import de.hft.stuttgart.citydoctor2.checks.geometry.PolygonWrongOrientationCheck;
35
36
37
38
39
40
import de.hft.stuttgart.citydoctor2.checks.geometry.FaceOutCheck;
import de.hft.stuttgart.citydoctor2.checks.geometry.HoleOutsideCheck;
import de.hft.stuttgart.citydoctor2.checks.geometry.InteriorDisconnectedCheck;
import de.hft.stuttgart.citydoctor2.checks.geometry.ManifoldVertexCheck;
import de.hft.stuttgart.citydoctor2.checks.geometry.NestedRingsCheck;
import de.hft.stuttgart.citydoctor2.checks.geometry.NumPointsCheck;
Matthias Betz's avatar
Matthias Betz committed
41
import de.hft.stuttgart.citydoctor2.checks.geometry.NonManifoldEdgeCheck;
42
43
import de.hft.stuttgart.citydoctor2.checks.geometry.PlanarCheck;
import de.hft.stuttgart.citydoctor2.checks.geometry.PolygonSameOrientationCheck;
Matthias Betz's avatar
Matthias Betz committed
44
import de.hft.stuttgart.citydoctor2.checks.geometry.PolygonIntersectingRingsCheck;
45
46
47
48
49
50
51
52
53
import de.hft.stuttgart.citydoctor2.checks.geometry.RingSelfIntCheck;
import de.hft.stuttgart.citydoctor2.checks.geometry.SolidNotClosedCheck;
import de.hft.stuttgart.citydoctor2.checks.geometry.SolidSelfIntCheck;
import de.hft.stuttgart.citydoctor2.checks.geometry.TooFewPolygonsCheck;
import de.hft.stuttgart.citydoctor2.checks.semantics.IsCeilingCheck;
import de.hft.stuttgart.citydoctor2.checks.semantics.IsFloorCheck;
import de.hft.stuttgart.citydoctor2.checks.semantics.IsGroundCheck;
import de.hft.stuttgart.citydoctor2.checks.semantics.IsWallCheck;
import de.hft.stuttgart.citydoctor2.checks.semantics.RoofSurfaceUnfragmentedCheck;
Matthias Betz's avatar
Matthias Betz committed
54
import de.hft.stuttgart.citydoctor2.utils.Localization;
55
56
57
58
59
60
61
62
63
64

/**
 * Container class for all checks. If new checks are added, they need to be
 * published here to be accessed by the checker instance.
 * 
 * @author Matthias Betz
 *
 */
public class Checks {

Matthias Betz's avatar
Matthias Betz committed
65
	private static final Logger logger = LogManager.getLogger(Checks.class);
66
67
68
69
70
71
72
73
74
75
76
77

	private static List<CheckPrototype> checkPrototypes;
	private static Map<CheckId, CheckPrototype> prototypeMap;

	private Map<CheckId, Check> checkMap;

	static {
		checkPrototypes = new ArrayList<>();
		prototypeMap = new EnumMap<>(CheckId.class);

		// add new checks here
		publish(new NumPointsCheck());
Matthias Betz's avatar
Matthias Betz committed
78
		publish(new RingNotClosedCheck());
79
80
81
82
83
84
		publish(new DuplicatePointsCheck());
		publish(new RingSelfIntCheck());
		publish(new PlanarCheck());
		publish(new PolygonSameOrientationCheck());
		publish(new HoleOutsideCheck());
		publish(new NestedRingsCheck());
Matthias Betz's avatar
Matthias Betz committed
85
		publish(new PolygonIntersectingRingsCheck());
86
		publish(new InteriorDisconnectedCheck());
Matthias Betz's avatar
Matthias Betz committed
87
		publish(new MultipleConnectedComponentCheck());
88
		publish(new SolidNotClosedCheck());
Matthias Betz's avatar
Matthias Betz committed
89
90
		publish(new NonManifoldEdgeCheck());
		publish(new PolygonWrongOrientationCheck());
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
143
144
145
146
147
		publish(new FaceOutCheck());
		publish(new TooFewPolygonsCheck());
		publish(new ManifoldVertexCheck());
		publish(new SolidSelfIntCheck());

		// semantic checks
		publish(new IsWallCheck());
		publish(new IsFloorCheck());
		publish(new IsCeilingCheck());
		publish(new IsGroundCheck());
		publish(new RoofSurfaceUnfragmentedCheck());
	}

	/**
	 * Creates new checks for every available check prototype and stores them in
	 * this container. Access the checks with {@link Checks#getCheckForId(CheckId)}.
	 */
	public Checks() {
		checkMap = new EnumMap<>(CheckId.class);

		for (CheckPrototype proto : checkPrototypes) {
			Check check = proto.createCheck();
			checkMap.put(check.getCheckId(), check);
		}
	}

	private static void publish(Check check) {
		CheckPrototype prototype = new CheckPrototype(check);
		checkPrototypes.add(prototype);
		prototypeMap.put(prototype.getCheckId(), prototype);
	}

	/**
	 * 
	 * @return All available checks as prototypes, where they can be instantiated.
	 */
	public static List<CheckPrototype> getCheckPrototypes() {
		return checkPrototypes;
	}

	/**
	 * 
	 * @param key The check ID
	 * @return The prototype for the given ID or null if there is no such prototype.
	 */
	public static CheckPrototype getCheckPrototypeForId(CheckId key) {
		return prototypeMap.get(key);
	}

	/**
	 * 
	 * @param id The check ID
	 * @return The check for the check ID or null if it does not exist
	 */
	public Check getCheckForId(CheckId id) {
		Check c = checkMap.get(id);
		if (c == null) {
Matthias Betz's avatar
Matthias Betz committed
148
			logger.warn(Localization.getText("Checks.missingCheck"), id);
149
150
151
152
		}
		return c;
	}
}