Skip to content

Commit d013a3f

Browse files
Copilotbertt
andcommitted
Implement tileHashes pattern like QuadtreeTiler
Co-authored-by: bertt <538812+bertt@users.noreply.github.com>
1 parent 57e0744 commit d013a3f

File tree

1 file changed

+30
-2
lines changed

1 file changed

+30
-2
lines changed

src/b3dm.tileset/OctreeTiler.cs

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ private HashSet<string> CreateTileForLargestGeometries3D(BoundingBox3D bbox, int
9898
{
9999
// clone processedGeometries to avoid modifying the original set in recursive calls
100100
var localProcessedGeometries = new HashSet<string>(processedGeometries);
101+
var tileHashes = new HashSet<string>();
101102

102103
// Get the largest geometries (up to MaxFeaturesPerTile) for this tile at this level
103104
int target_srs = tilingSettings.KeepProjection ? inputTable.EPSGCode : 4978;
@@ -108,24 +109,31 @@ private HashSet<string> CreateTileForLargestGeometries3D(BoundingBox3D bbox, int
108109
if (geometriesToProcess.Count > 0) {
109110
foreach (var geom in geometriesToProcess.Where(geom => !string.IsNullOrEmpty(geom.Hash))) {
110111
localProcessedGeometries.Add(geom.Hash);
112+
tileHashes.Add(geom.Hash);
111113
}
112114

113115
var file = $"{tilesetSettings.OutputSettings.ContentFolder}{Path.AltDirectorySeparatorChar}{tile.Level}_{tile.Z}_{tile.X}_{tile.Y}.glb";
114116
TileCreationHelper.WriteTileIfNeeded(geometriesToProcess, tilesetSettings.Translation, stylingSettings, tilesetSettings.Copyright, tilingSettings.CreateGltf, tilingSettings.SkipCreateTiles, file, file);
117+
118+
UpdateTileBoundingBox3D(tile, tileBounds, tileHashes, where);
119+
115120
tile.Available = true;
116121
}
117122

118123
tiles.Add(tile);
119124
if (tileBounds != null) {
120125
var key = $"{tile.Level}_{tile.Z}_{tile.X}_{tile.Y}";
121-
tileBounds[key] = bbox;
126+
if (!tileBounds.ContainsKey(key)) {
127+
tileBounds[key] = bbox;
128+
}
122129
}
123130

124131
return localProcessedGeometries;
125132
}
126133

127134
private void CreateTile3D(BoundingBox3D bbox, int level, Tile3D tile, List<Tile3D> tiles, Dictionary<string, BoundingBox3D> tileBounds, string where, HashSet<string> processedGeometries)
128135
{
136+
var tileHashes = new HashSet<string>();
129137
int target_srs = tilingSettings.KeepProjection ? inputTable.EPSGCode : 4978;
130138

131139
var bbox1 = new double[] { bbox.XMin, bbox.YMin, bbox.XMax, bbox.YMax, bbox.ZMin, bbox.ZMax };
@@ -134,11 +142,15 @@ private void CreateTile3D(BoundingBox3D bbox, int level, Tile3D tile, List<Tile3
134142
if (geometries.Count > 0) {
135143
// Collect hashes of processed geometries
136144
foreach (var geom in geometries.Where(geom => !string.IsNullOrEmpty(geom.Hash))) {
145+
tileHashes.Add(geom.Hash);
137146
processedGeometries.Add(geom.Hash);
138147
}
139148

140149
var file = $"{tilesetSettings.OutputSettings.ContentFolder}{Path.AltDirectorySeparatorChar}{tile.Level}_{tile.Z}_{tile.X}_{tile.Y}.glb";
141150
TileCreationHelper.WriteTileIfNeeded(geometries, tilesetSettings.Translation, stylingSettings, tilesetSettings.Copyright, tilingSettings.CreateGltf, tilingSettings.SkipCreateTiles, file, file);
151+
152+
UpdateTileBoundingBox3D(tile, tileBounds, tileHashes, where);
153+
142154
tile.Available = true;
143155
}
144156
else {
@@ -148,7 +160,23 @@ private void CreateTile3D(BoundingBox3D bbox, int level, Tile3D tile, List<Tile3
148160
tiles.Add(tile);
149161
if (tileBounds != null) {
150162
var key = $"{tile.Level}_{tile.Z}_{tile.X}_{tile.Y}";
151-
tileBounds[key] = bbox;
163+
if (!tileBounds.ContainsKey(key)) {
164+
tileBounds[key] = bbox;
165+
}
152166
}
153167
}
168+
169+
private void UpdateTileBoundingBox3D(Tile3D tile, Dictionary<string, BoundingBox3D> tileBounds, HashSet<string> tileHashes, string where)
170+
{
171+
if (tileBounds == null || tileHashes.Count == 0) {
172+
return;
173+
}
174+
175+
// Update bounding box based on actual geometries in the tile
176+
var bbox_geometries = GeometryRepository.GetGeometriesBoundingBox(conn, inputTable.TableName, inputTable.GeometryColumn, inputTable.EPSGCode, null, tileHashes, where, tilingSettings.KeepProjection);
177+
var bbox3d = new BoundingBox3D(bbox_geometries[0], bbox_geometries[1], bbox_geometries[4], bbox_geometries[2], bbox_geometries[3], bbox_geometries[5]);
178+
179+
var key = $"{tile.Level}_{tile.Z}_{tile.X}_{tile.Y}";
180+
tileBounds[key] = bbox3d;
181+
}
154182
}

0 commit comments

Comments
 (0)