Wuvin commited on
Commit
6ade74b
1 Parent(s): 8239dcc
mesh_reconstruction/func.py CHANGED
@@ -115,4 +115,19 @@ def make_sphere(level:int=2,radius=1.,device='cuda') -> Tuple[torch.Tensor,torch
115
  sphere = trimesh.creation.icosphere(subdivisions=level, radius=1.0, color=None)
116
  vertices = torch.tensor(sphere.vertices, device=device, dtype=torch.float32) * radius
117
  faces = torch.tensor(sphere.faces, device=device, dtype=torch.long)
118
- return vertices,faces
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
115
  sphere = trimesh.creation.icosphere(subdivisions=level, radius=1.0, color=None)
116
  vertices = torch.tensor(sphere.vertices, device=device, dtype=torch.float32) * radius
117
  faces = torch.tensor(sphere.faces, device=device, dtype=torch.long)
118
+ return vertices,faces
119
+
120
+ from pytorch3d.renderer import (
121
+ FoVOrthographicCameras,
122
+ look_at_view_transform,
123
+ )
124
+
125
+ def get_camera(R, T, focal_length=1 / (2**0.5)):
126
+ focal_length = 1 / focal_length
127
+ camera = FoVOrthographicCameras(device=R.device, R=R, T=T, min_x=-focal_length, max_x=focal_length, min_y=-focal_length, max_y=focal_length)
128
+ return camera
129
+
130
+ def make_star_cameras_orthographic_py3d(azim_list, device, focal=2/1.35, dist=1.1):
131
+ R, T = look_at_view_transform(dist, 0, azim_list)
132
+ focal_length = 1 / focal
133
+ return FoVOrthographicCameras(device=R.device, R=R, T=T, min_x=-focal_length, max_x=focal_length, min_y=-focal_length, max_y=focal_length).to(device)
mesh_reconstruction/render.py CHANGED
@@ -123,16 +123,6 @@ class Pytorch3DNormalsRenderer:
123
  mesh = Meshes(verts=[vertices], faces=[faces], textures=TexturesVertex(verts_features=[(normals + 1) / 2])).to(self.device)
124
  return render_mesh_vertex_color(mesh, self.cameras, self._image_size[0], self._image_size[1], device=self.device)
125
 
126
- def get_camera(R, T, focal_length=1 / (2**0.5)):
127
- focal_length = 1 / focal_length
128
- camera = FoVOrthographicCameras(device=R.device, R=R, T=T, min_x=-focal_length, max_x=focal_length, min_y=-focal_length, max_y=focal_length)
129
- return camera
130
-
131
- def make_star_cameras_orthographic_py3d(azim_list, device, focal=2/1.35, dist=1.1):
132
- R, T = look_at_view_transform(dist, 0, azim_list)
133
- focal_length = 1 / focal
134
- return FoVOrthographicCameras(device=R.device, R=R, T=T, min_x=-focal_length, max_x=focal_length, min_y=-focal_length, max_y=focal_length).to(device)
135
-
136
  def save_tensor_to_img(tensor, save_dir):
137
  from PIL import Image
138
  import numpy as np
@@ -146,7 +136,7 @@ if __name__ == "__main__":
146
  import sys
147
  import os
148
  sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
149
- from mesh_reconstruction.func import make_star_cameras_orthographic
150
  cameras = make_star_cameras_orthographic_py3d([0, 270, 180, 90], device="cuda", focal=1., dist=4.0)
151
  mv,proj = make_star_cameras_orthographic(4, 1)
152
  resolution = 1024
 
123
  mesh = Meshes(verts=[vertices], faces=[faces], textures=TexturesVertex(verts_features=[(normals + 1) / 2])).to(self.device)
124
  return render_mesh_vertex_color(mesh, self.cameras, self._image_size[0], self._image_size[1], device=self.device)
125
 
 
 
 
 
 
 
 
 
 
 
126
  def save_tensor_to_img(tensor, save_dir):
127
  from PIL import Image
128
  import numpy as np
 
136
  import sys
137
  import os
138
  sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
139
+ from mesh_reconstruction.func import make_star_cameras_orthographic, make_star_cameras_orthographic_py3d
140
  cameras = make_star_cameras_orthographic_py3d([0, 270, 180, 90], device="cuda", focal=1., dist=4.0)
141
  mv,proj = make_star_cameras_orthographic(4, 1)
142
  resolution = 1024