Skip to content

Commit 0014297

Browse files
committed
improvements to Meshes class
1 parent 69865a9 commit 0014297

File tree

2 files changed

+38
-10
lines changed

2 files changed

+38
-10
lines changed

src/sparc_spy/meshes.py

Lines changed: 36 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,36 @@
55

66

77
class Meshes(pv.MultiBlock):
8-
def __init__(self) -> None:
8+
def __init__(self) -> None:
9+
"""
10+
This class is a subclass of pyvista.MultiBlock.
11+
It is used to store multiple meshes with labels from the scaffold.
12+
"""
913
super().__init__()
1014

11-
def add_mesh(self, label: str, mesh: pv.PolyData):
15+
def add_mesh(self, label: str, mesh: pv.PolyData):
16+
"""
17+
This function adds a mesh to the MultiBlock object.
18+
Args:
19+
label (str): Label of the mesh.
20+
mesh (pv.PolyData): Mesh to be added.
21+
"""
1222
self.append(label, mesh)
1323

14-
def export(self, output_filepath: str = "output.stl", base_path='.'):
24+
def export(self, output_filepath: str = "output.stl", base_path='.'):
25+
"""
26+
This function exports the meshes in the MultiBlock object to a single STL file.
27+
Args:
28+
output_filepath (str): Output file path.
29+
base_path (str): Base path.
30+
"""
1531
save_multiblock_stl(self, output_filepath, base_path)
1632

1733
def items(self):
1834
'''
19-
This function should return the label and meshes (pv.PolyData) in the MultiBlock object.
35+
This function should return the label and meshes (pv.PolyData) in the MultiBlock object.
36+
Returns:
37+
list: List of tuples containing label and mesh.
2038
'''
2139
blocks = []
2240
for name in self.keys():
@@ -26,7 +44,13 @@ def items(self):
2644

2745

2846
def save_multiblock_stl(multiblock, filename, base_path='.'):
29-
47+
"""
48+
This function saves the meshes in the MultiBlock object to a single STL file.
49+
Args:
50+
multiblock (MultiBlock): MultiBlock object containing meshes.
51+
filename (str): Output file path.
52+
base_path (str): Base path.
53+
"""
3054
names = multiblock.keys()
3155
oname, ext = os.path.splitext(filename)
3256
assert ext == '.stl'
@@ -56,8 +80,13 @@ def save_multiblock_stl(multiblock, filename, base_path='.'):
5680

5781
return
5882

59-
def change_first_line_of_file(filename, new_first_line):
60-
83+
def change_first_line_of_file(filename, new_first_line):
84+
"""
85+
This function changes the first line of a file.
86+
Args:
87+
filename (str): File name.
88+
new_first_line (str): New first line.
89+
"""
6190
fr = open(filename, 'r')
6291
first_line = fr.readline()
6392
fr.close()

src/sparc_spy/scaffold.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,11 +133,10 @@ def export(self, output_filepath: str = "output.stl", base_path="."):
133133
134134
Args:
135135
output_filepath (str, optional): output_filepath (str): Output file
136-
path to save .vtk file. Defaults to "output.vtk".
136+
path to save .stl file. Defaults to "output.stl".
137137
"""
138138
self.meshes.export(output_filepath, base_path)
139139

140-
141140
def get_metadata(self):
142141
"""Show a tabular view of metadata that is important to the user"""
143142
return
@@ -149,7 +148,7 @@ def add_mesh(self, mesh_name: str, mesh: pv.PolyData):
149148
mesh_name (str): User defined name for the mesh
150149
mesh (Mesh): Mesh containing new experimental data
151150
"""
152-
return
151+
self.meshes[mesh_name] = mesh
153152

154153
def get_mesh_details(self):
155154
"""List all meshes with their corresponding user defined names. These IDs

0 commit comments

Comments
 (0)