Skip to content

Commit

Permalink
ruff formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
CardiacMangoes committed Jan 18, 2024
1 parent 473656b commit c7115d3
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
19 changes: 11 additions & 8 deletions nerfstudio/data/dataparsers/nerfstudio_dataparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,30 +335,34 @@ def _generate_dataparser_outputs(self, split="train"):
elif colmap_path.exists():
from rich.prompt import Confirm

# check if user wants to make a point cloud from colmap points
self.create_pc = Confirm.ask("load_3D_points is true, but the dataset was processed with an outdated ns-process-data that didn't convert colmap points to .ply! Update the colmap dataset automatically?")

# check if user wants to make a point cloud from colmap points
self.create_pc = Confirm.ask(
"load_3D_points is true, but the dataset was processed with an outdated ns-process-data that didn't convert colmap points to .ply! Update the colmap dataset automatically?"
)

if self.create_pc:
import json

from nerfstudio.process_data.colmap_utils import create_ply_from_colmap

with open(self.config.data / "transforms.json") as f:
transforms = json.load(f)

print(self.config.data)
create_ply_from_colmap(recon_dir=colmap_path, output_dir=self.config.data)
ply_file_path = data_dir / 'sparse_pc.ply'
ply_file_path = data_dir / "sparse_pc.ply"
transforms["ply_file_path"] = "sparse_pc.ply"

with open(self.config.data / "transforms.json", "w", encoding="utf-8") as f:
json.dump(transforms, f, indent=4)
else:
ply_file_path = None
else:
CONSOLE.print("[bold yellow]Warning: load_3D_points set to true but no point cloud found. gaussian-splatting models will use random point cloud initialization.")
CONSOLE.print(
"[bold yellow]Warning: load_3D_points set to true but no point cloud found. gaussian-splatting models will use random point cloud initialization."
)
ply_file_path = None

if ply_file_path:
sparse_points = self._load_3D_points(ply_file_path, transform_matrix, scale_factor)
if sparse_points is not None:
Expand Down Expand Up @@ -393,7 +397,6 @@ def _load_3D_points(self, ply_file_path: Path, transform_matrix: torch.Tensor, s
"""
import open3d as o3d # Importing open3d is slow, so we only do it if we need it.


pcd = o3d.io.read_point_cloud(str(ply_file_path))

# if no points found don't read in an initial point cloud
Expand Down
8 changes: 4 additions & 4 deletions nerfstudio/process_data/colmap_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,7 @@ def colmap_to_json(

# create ply from colmap
create_ply_from_colmap(recon_dir, output_dir)
out["ply_file_path"] = 'sparse_pc.ply'
out["ply_file_path"] = "sparse_pc.ply"

with open(output_dir / "transforms.json", "w", encoding="utf-8") as f:
json.dump(out, f, indent=4)
Expand Down Expand Up @@ -657,14 +657,14 @@ def create_ply_from_colmap(recon_dir, output_dir):
colmap_points = read_points3D_text(recon_dir / "points3D.txt")
else:
raise ValueError(f"Could not find points3D.txt or points3D.bin in {recon_dir}")

# Load point Positions
points3D = torch.from_numpy(np.array([p.xyz for p in colmap_points.values()], dtype=np.float32))
# Load point colours
points3D_rgb = torch.from_numpy(np.array([p.rgb for p in colmap_points.values()], dtype=np.uint8))

# write ply
with open(output_dir / 'sparse_pc.ply', 'w') as f:
with open(output_dir / "sparse_pc.ply", "w") as f:
# Header
f.write("ply\n")
f.write("format ascii 1.0\n")
Expand All @@ -680,4 +680,4 @@ def create_ply_from_colmap(recon_dir, output_dir):
for coord, color in zip(points3D, points3D_rgb):
x, y, z = coord.to(torch.float)
r, g, b = (color * 255).to(torch.uint8)
f.write(f"{x:8f} {y:8f} {z:8f} {r} {g} {b}\n")
f.write(f"{x:8f} {y:8f} {z:8f} {r} {g} {b}\n")

0 comments on commit c7115d3

Please sign in to comment.