-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmesh_stats.py
81 lines (63 loc) · 2.32 KB
/
mesh_stats.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
"""Mesh Area Volume Module"""
import numpy as np
import logging
import pymeshlab
import json
import argparse
import os
logger = logging.getLogger(__name__)
class MeshAnalyser:
"""
MeshAnalyser class for the volume and area computation of a mesh.
The class compute both the volume and area for a given mesh.
Parameters
----------
face_condition : float (default=-0.95)
The condition for face selection.
"""
def __init__(self, face_condition=-0.95):
self.face_condition = face_condition
def _get_area_volume(self, meshset):
meshset.meshing_remove_duplicate_vertices()
meshset.meshing_merge_close_vertices()
meshset.meshing_re_orient_faces_coherentely()
geom = meshset.get_geometric_measures()
if 'mesh_volume' in geom.keys():
volume = geom['mesh_volume']
else:
volume = 0
logger.debug(f'volume is {volume}')
if volume<0:
meshset.meshing_invert_face_orientation()
geom = meshset.get_geometric_measures()
volume = geom['mesh_volume']
logger.debug(f'after inverting, volume is now {volume}')
statement = ('(fnz < ' + str(self.face_condition) + ')')
meshset.compute_selection_by_condition_per_face(condselect=statement)
meshset.apply_selection_inverse(invfaces = True)
meshset.meshing_remove_selected_faces()
geom2 = meshset.get_geometric_measures()
logger.debug(f'floor area is {geom2["surface_area"]}')
floorarea = geom2['surface_area']
return volume, floorarea
def process(self, mesh):
"""
Parameters
----------
mesh : pmeshlab.Mesh
The pymeshlab Meshset.
Returns
-------
volume : float
The volume of the input mesh.
floorarea : float
The floorarea of the input mesh.
"""
logger.debug(f'Analysing mesh...')
try:
volume, floorarea = self._get_area_volume(mesh)
logger.debug(f'The volume of room is {volume:.2f} and the floorarea is {floorarea:.2f}')
except:
volume, floorarea = None, None
logger.debug(f'metrics cannot be calculated')
return volume, floorarea