Skip to content

Commit

Permalink
adding calculate normal method to parabolic reflector function to inc…
Browse files Browse the repository at this point in the history
…lude point and cell normals in the mesh.
  • Loading branch information
LyceanEM committed Jun 25, 2024
1 parent 041b1df commit 1f8dd7b
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
1 change: 1 addition & 0 deletions lyceanem/base_classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,7 @@ def structure_cells(array):
for item in triangle_meshes:
if item is not None:
new_mesh = pv.utilities.from_meshio(item)
structure_meshes.append(new_mesh)

point_sets = [self.export_all_points()]
for item in point_sets:
Expand Down
9 changes: 5 additions & 4 deletions lyceanem/geometry/geometryfunctions.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def mesh_transform(mesh, transform_matrix, rotate_only):

def compute_normals(mesh):
"""
Computes the Cell Normals for meshio mesh objects, this does not currently calculate the point normals, but this will be done soon.
Computes the Cell Normals for meshio mesh objects, the point normals will also be calculated for all points which are connected to a triangle, isolated points will be propulated with a normal vector of nan.
Parameters
----------
Expand Down Expand Up @@ -143,12 +143,13 @@ def compute_normals(mesh):
#calculate vertex normals
for inc, cell in enumerate(mesh.cells):
if cell.type == 'triangle':
point_normals=[]
point_normals=np.empty((0,3))
for inc in range(mesh.points.shape[0]):
associated_cells=np.where(inc==cell.data)[0]
point_normals.append(np.mean(mesh.cell_data['Normals'][0][associated_cells,:],axis=0))
print(associated_cells)
point_normals=np.append(point_normals,np.mean(mesh.cell_data['Normals'][0][associated_cells,:],axis=0).reshape(1,3),axis=0)

mesh.point_data['Normals']=point_normals
mesh.point_data['Normals']=point_normals/np.linalg.norm(point_normals,axis=1).reshape(-1,1)


return mesh
Expand Down
2 changes: 1 addition & 1 deletion lyceanem/geometry/targets.py
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ def parabola(x):
import meshio
triangle_cells = [("triangle", mesh_temp.cells[triangle_index].data)]
mesh = meshio.Mesh(mesh_temp.points, triangle_cells)

mesh = GF.compute_normals(mesh)
x_space = np.linspace(
mesh_size,
(diameter / 2),
Expand Down

0 comments on commit 1f8dd7b

Please sign in to comment.