@@ -89,6 +89,21 @@ def read_points3D_text(path):
8989 xyzs = None
9090 rgbs = None
9191 errors = None
92+ num_points = 0
93+ with open (path , "r" ) as fid :
94+ while True :
95+ line = fid .readline ()
96+ if not line :
97+ break
98+ line = line .strip ()
99+ if len (line ) > 0 and line [0 ] != "#" :
100+ num_points += 1
101+
102+
103+ xyzs = np .empty ((num_points , 3 ))
104+ rgbs = np .empty ((num_points , 3 ))
105+ errors = np .empty ((num_points , 1 ))
106+ count = 0
92107 with open (path , "r" ) as fid :
93108 while True :
94109 line = fid .readline ()
@@ -100,14 +115,11 @@ def read_points3D_text(path):
100115 xyz = np .array (tuple (map (float , elems [1 :4 ])))
101116 rgb = np .array (tuple (map (int , elems [4 :7 ])))
102117 error = np .array (float (elems [7 ]))
103- if xyzs is None :
104- xyzs = xyz [None , ...]
105- rgbs = rgb [None , ...]
106- errors = error [None , ...]
107- else :
108- xyzs = np .append (xyzs , xyz [None , ...], axis = 0 )
109- rgbs = np .append (rgbs , rgb [None , ...], axis = 0 )
110- errors = np .append (errors , error [None , ...], axis = 0 )
118+ xyzs [count ] = xyz
119+ rgbs [count ] = rgb
120+ errors [count ] = error
121+ count += 1
122+
111123 return xyzs , rgbs , errors
112124
113125def read_points3D_binary (path_to_model_file ):
0 commit comments