daidedou commited on
Commit
ced27a8
·
1 Parent(s): ad6a975

Adapt to ZeroGPU (removed open3d)?

Browse files
Files changed (1) hide show
  1. utils/mesh.py +10 -26
utils/mesh.py CHANGED
@@ -3,11 +3,11 @@ from pathlib import Path
3
  import os
4
  from tqdm import tqdm
5
  import potpourri3d as pp3d
6
- import open3d as o3d
7
  import scipy.io as sio
8
  import numpy as np
9
  import re
10
  import sys
 
11
  sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))
12
  from shape_data import get_data_dirs
13
 
@@ -102,37 +102,21 @@ def save_ply(file_name, V, F, Rho=None, color=None):
102
  file.writelines(lines)
103
  file.close()
104
 
105
- def numpy_to_open3d_mesh(V, F):
106
- # Create an empty TriangleMesh object
107
- mesh = o3d.geometry.TriangleMesh()
108
- # Set vertices
109
- mesh.vertices = o3d.utility.Vector3dVector(V)
110
- # Set triangles
111
- mesh.triangles = o3d.utility.Vector3iVector(F)
112
- return mesh
113
-
114
 
115
 
116
  def load_mesh(filepath, scale=True, return_vnormals=False):
117
  V, F = pp3d.read_mesh(filepath)
118
- mesh = numpy_to_open3d_mesh(V, F)
119
-
120
- tmat = np.identity(4, dtype=np.float32)
121
- center = mesh.get_center()
122
- tmat[:3, 3] = -center
123
- area = mesh.get_surface_area()
124
  if scale:
125
- smat = np.identity(4, dtype=np.float32)
126
-
127
- smat[:3, :3] = np.identity(3, dtype=np.float32) / np.sqrt(area)
128
- tmat = smat @ tmat
129
- mesh.transform(tmat)
130
-
131
- vertices = np.asarray(mesh.vertices, dtype=np.float32)
132
- faces = np.asarray(mesh.triangles, dtype=np.int32)
133
  if return_vnormals:
134
- mesh.compute_vertex_normals()
135
- vnormals = np.asarray(mesh.vertex_normals, dtype=np.float32)
136
  if scale:
137
  return vertices, faces, vnormals, area, center
138
  return vertices, faces, vnormals, area, center
 
3
  import os
4
  from tqdm import tqdm
5
  import potpourri3d as pp3d
 
6
  import scipy.io as sio
7
  import numpy as np
8
  import re
9
  import sys
10
+ from utils.surfaces import Surface, centroid
11
  sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))
12
  from shape_data import get_data_dirs
13
 
 
102
  file.writelines(lines)
103
  file.close()
104
 
 
 
 
 
 
 
 
 
 
105
 
106
 
107
  def load_mesh(filepath, scale=True, return_vnormals=False):
108
  V, F = pp3d.read_mesh(filepath)
109
+ surf = Surface(FV=[F,V])
110
+ center, area = centroid(surf)
 
 
 
 
111
  if scale:
112
+ new_vertices = (surf.vertices - center)/area
113
+ else:
114
+ new_vertices = (surf.vertices - center)
115
+ vertices = np.asarray(new_vertices, dtype=np.float32)
116
+ faces = np.asarray(F, dtype=np.int32)
117
+
 
 
118
  if return_vnormals:
119
+ vnormals = surf.computeVertexNormals()
 
120
  if scale:
121
  return vertices, faces, vnormals, area, center
122
  return vertices, faces, vnormals, area, center