Skip to content

Commit

Permalink
improved support of template appearances for the to-cityjson command
Browse files Browse the repository at this point in the history
  • Loading branch information
clausnagel committed Jan 27, 2024
1 parent 5d10284 commit acb7df7
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ public Integer call() throws ExecutionException {

log.debug("Reading global appearances, groups and implicit geometries from input file.");
GlobalObjects globalObjects = GlobalObjectsReader.defaults()
.withTemplateAppearances(true)
.read(inputFile, getCityGMLContext());

try (CityGMLReader reader = createSkippingCityGMLReader(in, inputFile, inputOptions,
Expand Down
33 changes: 19 additions & 14 deletions src/main/java/org/citygml4j/tools/util/GlobalObjects.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,9 @@

import org.citygml4j.core.model.appearance.Appearance;
import org.citygml4j.core.model.cityobjectgroup.CityObjectGroup;
import org.citygml4j.core.model.core.AbstractAppearanceProperty;
import org.citygml4j.core.model.core.ImplicitGeometry;
import org.citygml4j.core.util.reference.DefaultReferenceResolver;
import org.xmlobjects.gml.model.geometry.AbstractGeometry;
import org.xmlobjects.gml.util.reference.ReferenceResolver;

import javax.xml.namespace.QName;
import java.util.ArrayList;
Expand All @@ -47,8 +46,6 @@ public enum Type {
private final List<Appearance> appearances = new ArrayList<>();
private final List<CityObjectGroup> cityObjectGroups = new ArrayList<>();
private final Map<String, AbstractGeometry> templateGeometries = new HashMap<>();
private final ReferenceResolver referenceResolver = DefaultReferenceResolver.newInstance()
.storeRefereesWithReferencedObject(true);

GlobalObjects() {
}
Expand All @@ -75,18 +72,26 @@ void add(CityObjectGroup cityObjectGroup, QName name) {
cityObjectGroups.add(cityObjectGroup);
}

void add(ImplicitGeometry implicitGeometry) {
add(implicitGeometry, 0);
void add(ImplicitGeometry implicitGeometry, boolean withTemplateAppearances) {
add(implicitGeometry, 0, withTemplateAppearances);
}

void add(ImplicitGeometry implicitGeometry, int lod) {
if (implicitGeometry.getRelativeGeometry() != null
&& implicitGeometry.getRelativeGeometry().isSetInlineObject()
&& implicitGeometry.getRelativeGeometry().getObject().getId() != null) {
referenceResolver.resolveReferences(implicitGeometry);
AbstractGeometry template = implicitGeometry.getRelativeGeometry().getObject();
template.getLocalProperties().set(TEMPLATE_LOD, lod);
templateGeometries.put(template.getId(), template);
void add(ImplicitGeometry implicitGeometry, int lod, boolean withTemplateAppearances) {
if (implicitGeometry.getRelativeGeometry() != null) {
if (implicitGeometry.getRelativeGeometry().isSetInlineObject()
&& implicitGeometry.getRelativeGeometry().getObject().getId() != null) {
AbstractGeometry template = implicitGeometry.getRelativeGeometry().getObject();
template.getLocalProperties().set(TEMPLATE_LOD, lod);
templateGeometries.put(template.getId(), template);
}

if (withTemplateAppearances && implicitGeometry.isSetAppearances()) {
implicitGeometry.getAppearances().stream()
.map(AbstractAppearanceProperty::getObject)
.filter(Appearance.class::isInstance)
.map(Appearance.class::cast)
.forEach(appearances::add);
}
}
}
}
12 changes: 10 additions & 2 deletions src/main/java/org/citygml4j/tools/util/GlobalObjectsReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@

public class GlobalObjectsReader {
private final EnumSet<GlobalObjects.Type> types;
private boolean withTemplateAppearances;

private GlobalObjectsReader(EnumSet<GlobalObjects.Type> types) {
this.types = types;
Expand Down Expand Up @@ -71,6 +72,11 @@ public static GlobalObjectsReader onlyImplicitGeometries() {
return new GlobalObjectsReader(EnumSet.of(GlobalObjects.Type.IMPLICIT_GEOMETRY));
}

public GlobalObjectsReader withTemplateAppearances(boolean withTemplateAppearances) {
this.withTemplateAppearances = withTemplateAppearances;
return this;
}

public GlobalObjects read(Path file, CityGMLContext context) throws ExecutionException {
try {
GlobalObjects globalObjects = new GlobalObjects();
Expand All @@ -91,13 +97,15 @@ public GlobalObjects read(Path file, CityGMLContext context) throws ExecutionExc
geometryInfo.getImplicitGeometries(lod).stream()
.filter(ImplicitGeometryProperty::isSetInlineObject)
.map(ImplicitGeometryProperty::getObject)
.forEach(implicitGeometry -> globalObjects.add(implicitGeometry, lod));
.forEach(implicitGeometry ->
globalObjects.add(implicitGeometry, lod, withTemplateAppearances));
}

geometryInfo.getNonLodImplicitGeometries().stream()
.filter(ImplicitGeometryProperty::isSetInlineObject)
.map(ImplicitGeometryProperty::getObject)
.forEach(globalObjects::add);
.forEach(implicitGeometry ->
globalObjects.add(implicitGeometry, withTemplateAppearances));
}
}
}
Expand Down

0 comments on commit acb7df7

Please sign in to comment.