701_Statistics.py 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. #!/usr/bin/env python
  2. #
  3. # This file is part of libigl, a simple c++ geometry processing library.
  4. #
  5. # Copyright (C) 2017 Sebastian Koch <s.koch@tu-berlin.de> and Daniele Panozzo <daniele.panozzo@gmail.com>
  6. #
  7. # This Source Code Form is subject to the terms of the Mozilla Public License
  8. # v. 2.0. If a copy of the MPL was not distributed with this file, You can
  9. # obtain one at http://mozilla.org/MPL/2.0/.
  10. import sys, os
  11. # Add the igl library to the modules search path
  12. import math
  13. sys.path.insert(0, os.getcwd() + "/../")
  14. import pyigl as igl
  15. from shared import TUTORIAL_SHARED_PATH, check_dependencies
  16. dependencies = []
  17. check_dependencies(dependencies)
  18. if __name__ == "__main__":
  19. V = igl.eigen.MatrixXd()
  20. F = igl.eigen.MatrixXi()
  21. # Load meshes in OFF format
  22. igl.readOBJ(TUTORIAL_SHARED_PATH + "horse_quad.obj", V, F)
  23. # Count the number of irregular vertices, the border is ignored
  24. irregular = igl.is_irregular_vertex(V, F)
  25. vertex_count = V.rows()
  26. irregular_vertex_count = sum(irregular)
  27. irregular_ratio = irregular_vertex_count / vertex_count
  28. print("Irregular vertices: \n%d/%d (%.2f%%)\n" % (
  29. irregular_vertex_count, vertex_count, irregular_ratio * 100))
  30. # Compute areas, min, max and standard deviation
  31. area = igl.eigen.MatrixXd()
  32. igl.doublearea(V, F, area)
  33. area /= 2.0
  34. area_avg = area.mean()
  35. area_min = area.minCoeff() / area_avg
  36. area_max = area.maxCoeff() / area_avg
  37. area_ns = (area - area_avg) / area_avg
  38. area_sigma = math.sqrt(area_ns.squaredMean())
  39. print("Areas (Min/Max)/Avg_Area Sigma: \n%.2f/%.2f (%.2f)\n" % (
  40. area_min, area_max, area_sigma))
  41. # Compute per face angles, min, max and standard deviation
  42. angles = igl.eigen.MatrixXd()
  43. igl.internal_angles(V, F, angles)
  44. angles = 360.0 * (angles / (2 * math.pi))
  45. angle_avg = angles.mean()
  46. angle_min = angles.minCoeff()
  47. angle_max = angles.maxCoeff()
  48. angle_ns = angles - angle_avg
  49. angle_sigma = math.sqrt(angle_ns.squaredMean())
  50. print("Angles in degrees (Min/Max) Sigma: \n%.2f/%.2f (%.2f)\n" % (
  51. angle_min, angle_max, angle_sigma))