Skip to content
This repository has been archived by the owner on Jul 31, 2024. It is now read-only.

Commit

Permalink
warnings log and skipping holes with less than 4 verts (triangles)
Browse files Browse the repository at this point in the history
  • Loading branch information
sambaas committed Apr 10, 2024
1 parent 5f429ee commit eae0c37
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 19 deletions.
43 changes: 27 additions & 16 deletions TileBakeLibrary/CityJSONParsing/CityJSON.cs
Original file line number Diff line number Diff line change
Expand Up @@ -180,11 +180,11 @@ private CityObject ReadCityObject(JSONNode node, string filter = "")
if (geometrynode["type"] == "Solid")
{
JSONNode boundaries = geometrynode["boundaries"];
surfaces = ReadSolid(geometrynode);
surfaces = ReadSolid(geometrynode, cityObject);
}
else if (geometrynode["type"] == "MultiSurface")
{
surfaces = ReadMultiSurface(geometrynode);
surfaces = ReadMultiSurface(geometrynode, cityObject);
}
else
{
Expand Down Expand Up @@ -284,21 +284,21 @@ private CityObject ReadCityObject(JSONNode node, string filter = "")
return cityObject;
}

private List<Surface> ReadSolid(JSONNode geometrynode)
private List<Surface> ReadSolid(JSONNode geometrynode, CityObject sourceCityObject)
{
JSONNode boundariesNode = geometrynode["boundaries"];
List<Surface> result = new List<Surface>();

//Read exterior shell
foreach (JSONNode surfacenode in boundariesNode[0])
{
result.Add(ReadSurfaceVectors(surfacenode));
{
result.Add(ReadSurfaceVectors(surfacenode,sourceCityObject,true,true));
}

return result;
}

private List<Surface> ReadMultiSurface(JSONNode geometrynode)
private List<Surface> ReadMultiSurface(JSONNode geometrynode, CityObject sourceCityObject)
{
JSONNode boundariesNode = geometrynode["boundaries"];
List<Surface> result = new List<Surface>();
Expand Down Expand Up @@ -372,31 +372,40 @@ private Surface AddSurfaceUVs(JSONNode UVValueNode, Surface surf)
}
return surf;
}
private Surface ReadSurfaceVectors(JSONNode surfacenode)
private Surface ReadSurfaceVectors(JSONNode surfacenode, CityObject sourceCityObject, bool createOuterRing = true, bool createInnerRings = true)
{
Surface surf = new Surface();
//read exteriorRing
List<Vector3Double> verts = new List<Vector3Double>();
foreach (JSONNode vectornode in surfacenode[0])

if(createOuterRing)
{
verts.Add(vertices[vectornode.AsInt]);
}
surf.outerRing = verts;
foreach (JSONNode vectornode in surfacenode[0])
{
verts.Add(vertices[vectornode.AsInt]);
}
surf.outerRing = verts;
}

int maxHoles = 3;
if(!createInnerRings)
return surf;
for (int i = 1; i < surfacenode.Count; i++)
{
if(i > maxHoles) return surf;

verts = new List<Vector3Double>();
foreach (JSONNode vectornode in surfacenode[i])
{
verts.Add(vertices[vectornode.AsInt]);
}

surf.innerRings.Add(verts);
//Only more than triangle as holes
if(verts.Count > 3) {
surf.innerRings.Add(verts);
}
else{
sourceCityObject.warnings += "- Holes in surface detected, but not supported. Ignoring holes.\n";
}
}

return surf;
}

Expand All @@ -423,6 +432,8 @@ public class CityObject
public string cityObjectType;
public string keyName = "";

public string warnings = "";

public CityObject()
{
semantics = new();
Expand Down
34 changes: 31 additions & 3 deletions TileBakeLibrary/CityJSONToTileConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ namespace TileBakeLibrary
{
public class CityJSONToTileConverter
{
private string logFileName = "";
private string sourcePath = "";
private string outputPath = "";
private string identifier = "";
Expand Down Expand Up @@ -177,6 +178,13 @@ public void SetObjectFilters(CityObjectFilter[] cityObjectFilters)
///
public void Convert()
{
//Create log file (overwrite)
var readableDateTime = DateTime.Now.ToString("yyyy-MM-dd_HH_mm");
var currentPath = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);

logFileName = currentPath + "/bakelog" + readableDateTime + ".txt";
File.WriteAllText(logFileName, string.Empty);

//If no specific filename or wildcard was supplied, default to .json files
var filter = Path.GetFileName(sourcePath);
if (filter == "") filter = "*.json";
Expand Down Expand Up @@ -227,12 +235,14 @@ public void Convert()
thread.Join();
cityJson = nextCityJSON;
}
Console.WriteLine($"Log file: {currentPath}/bakelog{readableDateTime}.txt");

//Optional compressed variant
if (brotliCompress)
{
CompressFiles();
}
Console.WriteLine($"Log file: {currentPath}/bakelog{readableDateTime}.txt");
}

/// <summary>
Expand All @@ -244,10 +254,21 @@ private void ReadCityJSON()
watch.Start();
tiles = new List<Tile>();

var cityObjects = CityJSONParseProcess(cityJson);
//Warnings bag
var warnings = new ConcurrentBag<string>();
var cityObjects = CityJSONParseProcess(cityJson, warnings);
allSubObjects.Clear();
allSubObjects = cityObjects;

//write warnings to log newlines
if(warnings.Count > 0)
File.AppendAllText(logFileName, $"Warnings for {cityJson.sourceFilePath}\n");
foreach (var warning in warnings)
{
File.AppendAllText(logFileName, warning + "\n");
}
File.AppendAllText(logFileName, "\n");

Console.WriteLine($"\n{allSubObjects.Count} CityObjects with LOD{lod} were imported");
PrepareTiles();
WriteTileData();
Expand Down Expand Up @@ -430,7 +451,7 @@ private void ParseExistingBinaryTile(Tile tile)
bmd = null;
}

private List<SubObject> CityJSONParseProcess(CityJSON cityJson)
private List<SubObject> CityJSONParseProcess(CityJSON cityJson, ConcurrentBag<string> warnings)
{
List<SubObject> filteredObjects = new List<SubObject>();
Console.WriteLine("");
Expand All @@ -444,6 +465,7 @@ private List<SubObject> CityJSONParseProcess(CityJSON cityJson)
int simplifying = 0;
int tiling = 0;
var filterObjectsBucket = new ConcurrentBag<SubObject>();
var failedSubObjects = new ConcurrentBag<string>();
int[] indices = Enumerable.Range(0, cityObjectCount).ToArray();

//Turn cityobjects (and their children) into SubObject mesh data
Expand All @@ -455,9 +477,15 @@ private List<SubObject> CityJSONParseProcess(CityJSON cityJson)
CityObject cityObject = cityJson.LoadCityObjectByIndex(i, lod);
var subObject = ToSubObjectMeshData(cityObject);
if(!string.IsNullOrEmpty(cityObject.warnings))
{
warnings.Add(cityObject.keyName + ":\n" + cityObject.warnings);
}
cityObject = null;
Interlocked.Decrement(ref parsing);
cityObject = null;
if (subObject == null)
{
Interlocked.Increment(ref done);
Expand Down
1 change: 1 addition & 0 deletions TileBakeLibrary/Triangulation/Poly2Mesh.cs
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,7 @@ public static void CreateMeshData(Polygon polygon, out Vector3[] vertices, out V
{
Console.WriteLine("Failed to triangulate polygon: " + e.Message);
Console.WriteLine("With name: " + cityObject.keyName);
cityObject.warnings += "- Failed to triangulate polygon: " + e.Message + "\n";
return;
}
// Now, to get back to our original positions, use our code-to-position map. We do
Expand Down

0 comments on commit eae0c37

Please sign in to comment.