Spaces:
Runtime error
Runtime error
Download app/utils/geometry_utils.py from Newuserrr/stepfile_compare: direct link, hf CLI and curl.
- Browser
- Download file 1.03 kB
-
https://huggingface.co/spaces/Newuserrr/stepfile_compare/resolve/main/app/utils/geometry_utils.py
- Command line
-
hf download hf://spaces/Newuserrr/stepfile_compare/app/utils/geometry_utils.py
-
curl -L -o geometry_utils.py https://huggingface.co/spaces/Newuserrr/stepfile_compare/resolve/main/app/utils/geometry_utils.py
1.03 kB
| from OCC.Core.BRep import BRep_Tool | |
| from OCC.Core.BRepExtrema import BRepExtrema_DistShapeShape | |
| from OCC.Core.TopExp import TopExp_Explorer | |
| from OCC.Core.TopAbs import TopAbs_VERTEX, TopAbs_EDGE | |
| from OCC.Core.gp import gp_Pnt | |
| def compute_centroid(shape): | |
| """Calculate the centroid of a shape.""" | |
| extrema = BRepExtrema_DistShapeShape(shape, shape) | |
| extrema.Perform() | |
| if extrema.IsDone(): | |
| p1 = extrema.PointOnShape1(1) | |
| return {"x": p1.X(), "y": p1.Y(), "z": p1.Z()} | |
| return {"x": 0, "y": 0, "z": 0} | |
| def count_features(shape): | |
| """Count specific geometric features like vertices and edges.""" | |
| vertex_count = 0 | |
| edge_count = 0 | |
| # Count vertices | |
| explorer = TopExp_Explorer(shape, TopAbs_VERTEX) | |
| while explorer.More(): | |
| vertex_count += 1 | |
| explorer.Next() | |
| # Count edges | |
| explorer = TopExp_Explorer(shape, TopAbs_EDGE) | |
| while explorer.More(): | |
| edge_count += 1 | |
| explorer.Next() | |
| return {"vertices": vertex_count, "edges": edge_count} | |