Skip to content

Commit

Permalink
Only write unpruned tileset in debug mode
Browse files Browse the repository at this point in the history
  • Loading branch information
balazsdukai committed Jul 17, 2023
1 parent fdcb659 commit 0997f87
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 38 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

### Changed
- The `--grid-export` switch does not export the feature centroids anymore. Use the `--grid-export-features` if you want to export the feature centroids together with the grid cells.
- Write both pruned and unpruned tilesets (for debugging).
- Write both pruned and unpruned tilesets. Unpruned tiles are only written in debug mode.
- Reduced the logging in debug mode.

### Fixed
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,8 @@ You can enable the `.tsv` export with the `--grid-export` flag.
With the `--grid-export-features` flag, also the feature feature centorids and their grid cell assignment will be exported.
Only use this for small amount of features.

In debug mode, *tyler* will write the unpruned tileset too, together with the tileset that was pruned after the glTF conversion.


## Roadmap

Expand Down
84 changes: 47 additions & 37 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -255,8 +255,11 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
}

// 3D Tiles

let tileset_path = cli.output.join("tileset.json");
let tileset_path_pruned = cli.output.join("tileset_pruned.json");
let subtrees_path = cli.output.join("subtrees");
let tileset_path_unpruned = cli.output.join("tileset_unpruned.json");
let subtrees_path_unpruned = cli.output.join("subtrees_unpruned");
info!("Generating 3D Tiles tileset");
let mut tileset = formats::cesium3dtiles::Tileset::from_quadtree(
&quadtree,
Expand All @@ -275,27 +278,37 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
info!("Converting to implicit tiling");
// Tileset.make_implicit() outputs the tiles that have content. If only the leaves have
// content, then only the leaves are outputted.
let tiles_subtrees =
tileset_implicit.make_implicit(&world.grid, &quadtree, cli.grid_export, None);

info!("Writing 3D Tiles tileset");
tileset_implicit.to_file(&tileset_path)?;
let components: Vec<_> = subtrees_path_unpruned
.components()
.map(|comp| comp.as_os_str())
.collect();
let subtrees_dir_option = components.last().cloned().unwrap().to_str();
let tiles_subtrees = tileset_implicit.make_implicit(
&world.grid,
&quadtree,
cli.grid_export,
subtrees_dir_option,
);

info!("Writing subtrees for implicit tiling");
let subtrees_path = cli.output.join("subtrees");
fs::create_dir_all(&subtrees_path)?;
for (subtree_id, subtree_bytes) in &tiles_subtrees.1 {
fs::create_dir_all(
subtrees_path.join(format!("{}/{}", subtree_id.level, subtree_id.x)),
)
.unwrap();
let out_path = subtrees_path
.join(&subtree_id.to_string())
.with_extension("subtree");
let mut subtree_file = File::create(&out_path)
.unwrap_or_else(|_| panic!("could not create {:?} for writing", &out_path));
if let Err(_e) = subtree_file.write_all(subtree_bytes) {
warn!("Failed to write subtree {} content", subtree_id);
if log_enabled!(Level::Debug) {
debug!("Writing unpruned 3D Tiles tileset");
tileset_implicit.to_file(&tileset_path_unpruned)?;

debug!("Writing unpruned subtrees for implicit tiling");
fs::create_dir_all(&subtrees_path_unpruned)?;
for (subtree_id, subtree_bytes) in &tiles_subtrees.1 {
fs::create_dir_all(
subtrees_path.join(format!("{}/{}", subtree_id.level, subtree_id.x)),
)
.unwrap();
let out_path = subtrees_path
.join(&subtree_id.to_string())
.with_extension("subtree");
let mut subtree_file = File::create(&out_path)
.unwrap_or_else(|_| panic!("could not create {:?} for writing", &out_path));
if let Err(_e) = subtree_file.write_all(subtree_bytes) {
warn!("Failed to write subtree {} content", subtree_id);
}
}
}

Expand All @@ -310,8 +323,8 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
.map(|tile_ref| (tile_ref.clone(), tile_ref.id.clone()))
.collect();

info!("Writing 3D Tiles tileset");
tileset.to_file(&tileset_path)?;
info!("Writing unpruned 3D Tiles tileset");
tileset.to_file(&tileset_path_unpruned)?;

(tiles, vec![])
}
Expand Down Expand Up @@ -748,10 +761,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
let tiles_failed_file = File::create("tiles_failed.bincode")?;
bincode::serialize_into(tiles_failed_file, &tiles_failed)?;
}
info!(
"Pruning tileset of failed tiles (failed: {})",
tiles_failed.len()
);
info!("Pruning tileset of {} failed tiles", tiles_failed.len());
for (i, failed) in tiles_failed.iter().enumerate() {
debug!("{}, removing failed from the tileset: {}", i, failed.id);
}
Expand All @@ -762,14 +772,14 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
// because it is simpler than flipping the bits of the unavailable tiles,
// because of the mixed up explicit/implicit tile IDs. But ideally, we
// flip the bits, so we won't need to duplicate the tileset here.
let (_, subtrees) = tileset.make_implicit(
&world.grid,
&quadtree,
cli.grid_export,
Some("subtrees_pruned"),
);
info!("Writing pruned subtrees for implicit tiling");
let subtrees_path = cli.output.join("subtrees_pruned");
let components: Vec<_> = subtrees_path
.components()
.map(|comp| comp.as_os_str())
.collect();
let subtrees_dir_option = components.last().cloned().unwrap().to_str();
let (_, subtrees) =
tileset.make_implicit(&world.grid, &quadtree, cli.grid_export, subtrees_dir_option);
info!("Writing subtrees for implicit tiling");
fs::create_dir_all(&subtrees_path)?;
for (subtree_id, subtree_bytes) in subtrees {
fs::create_dir_all(
Expand All @@ -786,8 +796,8 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
}
}
}
info!("Writing pruned 3D Tiles tileset");
tileset.to_file(&tileset_path_pruned)?;
info!("Writing 3D Tiles tileset");
tileset.to_file(&tileset_path)?;
}

Ok(())
Expand Down

0 comments on commit 0997f87

Please sign in to comment.