Reputation: 9540
I have two pymeshlab scripts:
import os
import argparse
import pymeshlab
from collections import Counter
def load_mesh(file_path):
ms = pymeshlab.MeshSet()
ms.load_new_mesh(file_path)
measures = ms.get_topological_measures()
print(measures)
def main():
# Parse command-line arguments
parser = argparse.ArgumentParser(description="Count the number of 'ok' meshes in a directory.")
parser.add_argument("-i", "--input", required=True, help="Path to the directory containing OBJ files.")
args = parser.parse_args()
results = load_mesh(args.input)
if __name__ == "__main__":
main()
And
import os
import argparse
import pymeshlab
from collections import Counter
def is_mesh_ok(file_path):
try:
ms = pymeshlab.MeshSet()
ms.load_new_mesh(file_path)
measures = ms.get_topological_measures()
except Exception as e:
print(f"Failed to load mesh '{file_path}': {e}")
return "Load Failed"
genus = measures['genus']
connected_components = measures['connected_components_number']
is_two_manifold = measures['is_mesh_two_manifold']
hole_count = measures['number_holes']
is_ok = (genus == 0) and (connected_components == 1) and (is_two_manifold is True) and (hole_count == 0)
if is_ok:
return "OK"
else:
failed_criteria = []
if genus != 0:
failed_criteria.append("Genus")
if connected_components != 1:
failed_criteria.append("Connected Components")
if not is_two_manifold:
failed_criteria.append("Is Two Manifold")
if hole_count != 0:
failed_criteria.append("Number of Holes")
return ", ".join(failed_criteria)
def count_ok_meshes(directory_path):
results = []
for filename in os.listdir(directory_path):
if filename.endswith('.obj'):
file_path = os.path.join(directory_path, filename)
result = is_mesh_ok(file_path)
results.append(result)
return results
def main():
# Parse command-line arguments
parser = argparse.ArgumentParser(description="Count the number of 'ok' meshes in a directory.")
parser.add_argument("-d", "--directory", required=True, help="Path to the directory containing OBJ files.")
args = parser.parse_args()
results = count_ok_meshes(args.directory)
counter = Counter(results)
print("Histogram of Failed Criteria:")
for key, value in counter.items():
print(f"{key}: {value}")
if __name__ == "__main__":
main()
I am calling both on the same files, they are on the same directory. The short script seems to work, but the large one claims it cannot find some of the files, I don;t understand how. For example the large one shows this error:
Failed to load mesh 'clean_results/mesh703.obj': File does not exists: clean_results/mesh703.obj
For the exact same file the small one returns:
{'boundary_edges': 0, 'connected_components_number': 1, 'edges_number': 4629, 'faces_number': 3086, 'genus': 0, 'incident_faces_on_non_two_manifold_edges': 0, 'incident_faces_on_non_two_manifold_vertices': 0, 'is_mesh_two_manifold': True, 'non_two_manifold_edges': 0, 'non_two_manifold_vertices': 0, 'number_holes': 0, 'unreferenced_vertices': 0, 'vertices_number': 1545}
It also only happens with some files, not all, and seems to change between invocations. I don't understand how this is happening. Why is the large script failing to find files using the exact same logic the small one is using?
Upvotes: 0
Views: 69