701_Statistics.py 2.1 KB

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