Commit 01673d2c authored by Riegel's avatar Riegel
Browse files

Fix checks and methods being applied to transformed geom

parent 3f908256
package de.hft.stuttgart.citydoctor2.datastructure;
import de.hft.stuttgart.citydoctor2.check.Check;
import de.hft.stuttgart.citydoctor2.check.CheckError;
import de.hft.stuttgart.citydoctor2.check.CheckId;
import de.hft.stuttgart.citydoctor2.math.TransformationMatrix;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.citygml4j.core.model.core.ImplicitGeometry;
import java.io.Serial;
import java.util.List;
/**
* Datastructure for representation and resolving of implicit geometries
......@@ -20,59 +23,80 @@ public class ImplicitGeometryHolder extends Geometry {
private static final long serialVersionUID = -8938931081577196349L;
private ImplicitGeometry cgmlImplicitGeometry = null;
/*
LibraryObject and RelativeGeometry are mutually exclusive
*/
private final LibraryObject libObject;
private final RelativeGeometry relativeGeom;
private final PrototypeGeometryType type;
private final Geometry prototypeGeometry;
public ImplicitGeometryHolder(ImplicitGeometry cgmlImplicitGeometry, LibraryObject libObject) {
super(libObject.getType(), libObject.getLod());
this.libObject = libObject;
this.relativeGeom = null;
prototypeGeometry = libObject;
type = PrototypeGeometryType.LIBRARY_OBJECT;
this.cgmlImplicitGeometry = cgmlImplicitGeometry;
applyTransformation();
}
public ImplicitGeometryHolder(ImplicitGeometry cgmlImplicitGeometry, RelativeGeometry relativeGeometry) {
super(relativeGeometry.getType(), relativeGeometry.getLod());
this.libObject = null;
this.relativeGeom = relativeGeometry;
prototypeGeometry = relativeGeometry;
type = PrototypeGeometryType.RELATIVE_GEOMETRY;
this.cgmlImplicitGeometry = cgmlImplicitGeometry;
applyTransformation();
}
@Override
public void accept(Check c) {
/**
* Checks are only run on the referenced prototypical geometry.
*/
if (relativeGeom != null) {
relativeGeom.accept(c);
}
if (libObject != null) {
libObject.accept(c);
}
}
/**
* Applies the transformation matrix of the implicit geometry to a copy of the reference geometry and copies the resulting
* transformed geometry into this object.
*/
private void applyTransformation() {
TransformationMatrix transformMatrix = new TransformationMatrix(cgmlImplicitGeometry);
Geometry refGeo = null;
if (libObject == null) {
refGeo = relativeGeom;
} else if (relativeGeom == null) {
refGeo = libObject;
}
if (refGeo == null) {
throw new NullPointerException("Geometry reference object of ImplicitGeometryHolder is null!");
}
Geometry transformedGeom = transformMatrix.transformGeometry(refGeo);
Geometry transformedGeom = transformMatrix.transformGeometry(prototypeGeometry);
transformedGeom.getPolygons().forEach(this::addPolygon);
this.updateEdgesAndVertices();
}
public PrototypeGeometryType getPrototypeGeometryType() {
return type;
}
@Override
public void accept(Check c) {
prototypeGeometry.accept(c);
}
@Override
public boolean containsError(CheckId checkIdentifier) {
return prototypeGeometry.containsError(checkIdentifier);
}
@Override
public void clearAllContainedCheckResults() {
prototypeGeometry.clearAllContainedCheckResults();
}
@Override
public void collectContainedErrors(List<CheckError> errors) {
prototypeGeometry.clearAllContainedCheckResults();
}
@Override
public boolean containsAnyError() {
return prototypeGeometry.containsAnyError();
}
@Override
public void prepareForChecking() {
this.updateEdgesAndVertices();
prototypeGeometry.prepareForChecking();
}
@Override
public boolean isValidated() {
return prototypeGeometry.isValidated();
}
public enum PrototypeGeometryType {
LIBRARY_OBJECT, RELATIVE_GEOMETRY
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment