17
17
18
18
from dataclasses import dataclass , field
19
19
from pathlib import Path
20
- from typing import Type
20
+ from typing import Optional , Type
21
21
22
22
import imageio
23
23
import numpy as np
24
+ import open3d as o3d
24
25
import torch
25
26
26
27
from nerfstudio .cameras .cameras import Cameras , CameraType
@@ -42,6 +43,9 @@ class BlenderDataParserConfig(DataParserConfig):
42
43
"""How much to scale the camera origins by."""
43
44
alpha_color : str = "white"
44
45
"""alpha color of background"""
46
+ ply_path : Optional [Path ] = None
47
+ """Path to PLY file to load 3D points from, defined relative to the dataset directory. This is helpful for
48
+ Gaussian splatting and generally unused otherwise. If `None`, points are initialized randomly."""
45
49
46
50
47
51
@dataclass
@@ -94,12 +98,29 @@ def _generate_dataparser_outputs(self, split="train"):
94
98
camera_type = CameraType .PERSPECTIVE ,
95
99
)
96
100
101
+ metadata = {}
102
+ if self .config .ply_path is not None :
103
+ metadata .update (self ._load_3D_points (self .config .data / self .config .ply_path ))
104
+
97
105
dataparser_outputs = DataparserOutputs (
98
106
image_filenames = image_filenames ,
99
107
cameras = cameras ,
100
108
alpha_color = self .alpha_color_tensor ,
101
109
scene_box = scene_box ,
102
110
dataparser_scale = self .scale_factor ,
111
+ metadata = metadata ,
103
112
)
104
113
105
114
return dataparser_outputs
115
+
116
+ def _load_3D_points (self , ply_file_path : Path ):
117
+ pcd = o3d .io .read_point_cloud (str (ply_file_path ))
118
+
119
+ points3D = torch .from_numpy (np .asarray (pcd .points , dtype = np .float32 ) * self .config .scale_factor )
120
+ points3D_rgb = torch .from_numpy ((np .asarray (pcd .colors ) * 255 ).astype (np .uint8 ))
121
+
122
+ out = {
123
+ "points3D_xyz" : points3D ,
124
+ "points3D_rgb" : points3D_rgb ,
125
+ }
126
+ return out
0 commit comments