MCPcopy Create free account
hub / github.com/InternRobotics/G2VLM / write_ply

Function write_ply

eval_code/recons/models/pi3/utils/basic.py:158–223  ·  view source on GitHub ↗
(
    xyz,
    rgb=None,
    path='output.ply',
)

Source from the content-addressed store, hash-verified

156
157
158def write_ply(
159 xyz,
160 rgb=None,
161 path='output.ply',
162) -> None:
163 if torch.is_tensor(xyz):
164 xyz = xyz.detach().cpu().numpy()
165
166 if torch.is_tensor(rgb):
167 rgb = rgb.detach().cpu().numpy()
168
169 if rgb is not None and rgb.max() > 1:
170 rgb = rgb / 255.
171
172 xyz = rotate_target_dim_to_last_axis(xyz, 3)
173 xyz = xyz.reshape(-1, 3)
174
175 if rgb is not None:
176 rgb = rotate_target_dim_to_last_axis(rgb, 3)
177 rgb = rgb.reshape(-1, 3)
178
179 if rgb is None:
180 min_coord = np.min(xyz, axis=0)
181 max_coord = np.max(xyz, axis=0)
182 normalized_coord = (xyz - min_coord) / (max_coord - min_coord + 1e-8)
183
184 hue = 0.7 * normalized_coord[:,0] + 0.2 * normalized_coord[:,1] + 0.1 * normalized_coord[:,2]
185 hsv = np.stack([hue, 0.9*np.ones_like(hue), 0.8*np.ones_like(hue)], axis=1)
186
187 c = hsv[:,2:] * hsv[:,1:2]
188 x = c * (1 - np.abs( (hsv[:,0:1]*6) % 2 - 1 ))
189 m = hsv[:,2:] - c
190
191 rgb = np.zeros_like(hsv)
192 cond = (0 <= hsv[:,0]*6%6) & (hsv[:,0]*6%6 < 1)
193 rgb[cond] = np.hstack([c[cond], x[cond], np.zeros_like(x[cond])])
194 cond = (1 <= hsv[:,0]*6%6) & (hsv[:,0]*6%6 < 2)
195 rgb[cond] = np.hstack([x[cond], c[cond], np.zeros_like(x[cond])])
196 cond = (2 <= hsv[:,0]*6%6) & (hsv[:,0]*6%6 < 3)
197 rgb[cond] = np.hstack([np.zeros_like(x[cond]), c[cond], x[cond]])
198 cond = (3 <= hsv[:,0]*6%6) & (hsv[:,0]*6%6 < 4)
199 rgb[cond] = np.hstack([np.zeros_like(x[cond]), x[cond], c[cond]])
200 cond = (4 <= hsv[:,0]*6%6) & (hsv[:,0]*6%6 < 5)
201 rgb[cond] = np.hstack([x[cond], np.zeros_like(x[cond]), c[cond]])
202 cond = (5 <= hsv[:,0]*6%6) & (hsv[:,0]*6%6 < 6)
203 rgb[cond] = np.hstack([c[cond], np.zeros_like(x[cond]), x[cond]])
204 rgb = (rgb + m)
205
206 dtype = [
207 ("x", "f4"),
208 ("y", "f4"),
209 ("z", "f4"),
210 ("nx", "f4"),
211 ("ny", "f4"),
212 ("nz", "f4"),
213 ("red", "u1"),
214 ("green", "u1"),
215 ("blue", "u1"),

Callers

nothing calls this directly

Calls 1

Tested by

no test coverage detected