Naveenlara commited on
Commit
12b9b6d
Β·
verified Β·
1 Parent(s): 05aa7a7

Upload 3 files

Browse files
Files changed (3) hide show
  1. README.md +15 -17
  2. app.py +68 -0
  3. requirements.txt +2 -3
README.md CHANGED
@@ -1,20 +1,18 @@
1
- ---
2
- title: Step File Compare
3
- emoji: πŸš€
4
- colorFrom: red
5
- colorTo: red
6
- sdk: docker
7
- app_port: 8501
8
- tags:
9
- - streamlit
10
- pinned: false
11
- short_description: 'Compares 3D Models '
12
- license: mit
13
- ---
14
 
15
- # Welcome to Streamlit!
16
 
17
- Edit `/src/streamlit_app.py` to customize this app to your heart's desire. :heart:
18
 
19
- If you have any questions, checkout our [documentation](https://docs.streamlit.io) and [community
20
- forums](https://discuss.streamlit.io).
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
 
2
+ # STEP File Comparator
3
 
4
+ Upload and compare two STEP files with the same origin. This tool will calculate and visualize 3D geometric deviations.
5
 
6
+ ## Features
7
+ - STEP parsing with `pythonOCC-core`
8
+ - Basic surface point deviation analysis
9
+ - Streamlit frontend
10
+
11
+ ## Usage
12
+ 1. Upload two `.step` files
13
+ 2. View the max and average deviation
14
+ 3. Visualize with a simple deviation chart
15
+
16
+ ## Future Improvements
17
+ - Add 3D viewer for live inspection
18
+ - Export report to CSV
app.py ADDED
@@ -0,0 +1,68 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ import streamlit as st
3
+ import tempfile
4
+ from OCC.Extend.DataExchange import read_step_file
5
+ from OCC.Core.BRep import BRep_Tool
6
+ from OCC.Core.BRepMesh import BRepMesh_IncrementalMesh
7
+ from OCC.Core.TopExp import TopExp_Explorer
8
+ from OCC.Core.TopAbs import TopAbs_FACE
9
+ from OCC.Core.TopoDS import topods_Face
10
+ from OCC.Core.BRepTools import breptools_UVBounds
11
+ from OCC.Core.gp import gp_Pnt
12
+
13
+ def extract_faces_points(shape):
14
+ BRepMesh_IncrementalMesh(shape, 0.1)
15
+ exp = TopExp_Explorer(shape, TopAbs_FACE)
16
+ points = []
17
+
18
+ while exp.More():
19
+ face = topods_Face(exp.Current())
20
+ u_min, u_max, v_min, v_max = breptools_UVBounds(face)
21
+ for u in [u_min, (u_min + u_max)/2, u_max]:
22
+ for v in [v_min, (v_min + v_max)/2, v_max]:
23
+ pnt = gp_Pnt()
24
+ BRep_Tool().Surface(face).D0(u, v, pnt)
25
+ points.append((pnt.X(), pnt.Y(), pnt.Z()))
26
+ exp.Next()
27
+
28
+ return points
29
+
30
+ def compare_step_files(file1, file2):
31
+ shape1 = read_step_file(file1)
32
+ shape2 = read_step_file(file2)
33
+
34
+ points1 = extract_faces_points(shape1)
35
+ points2 = extract_faces_points(shape2)
36
+
37
+ diffs = []
38
+ for p1, p2 in zip(points1, points2):
39
+ diff = ((p1[0]-p2[0])**2 + (p1[1]-p2[1])**2 + (p1[2]-p2[2])**2) ** 0.5
40
+ diffs.append(diff)
41
+
42
+ max_dev = max(diffs)
43
+ avg_dev = sum(diffs) / len(diffs)
44
+
45
+ return max_dev, avg_dev, diffs
46
+
47
+ st.title("πŸ” STEP File Comparison Tool")
48
+ st.markdown("Upload two STEP files with the same origin and compare their 3D geometry.")
49
+
50
+ uploaded_file1 = st.file_uploader("πŸ“€ Upload STEP File 1", type=["step", "stp"])
51
+ uploaded_file2 = st.file_uploader("πŸ“€ Upload STEP File 2", type=["step", "stp"])
52
+
53
+ if uploaded_file1 and uploaded_file2:
54
+ with tempfile.NamedTemporaryFile(delete=False) as tmp1:
55
+ tmp1.write(uploaded_file1.read())
56
+ path1 = tmp1.name
57
+
58
+ with tempfile.NamedTemporaryFile(delete=False) as tmp2:
59
+ tmp2.write(uploaded_file2.read())
60
+ path2 = tmp2.name
61
+
62
+ st.info("πŸ”§ Processing and comparing files...")
63
+ max_dev, avg_dev, all_diffs = compare_step_files(path1, path2)
64
+
65
+ st.success(f"πŸ“ Max Deviation: {max_dev:.3f} mm")
66
+ st.info(f"πŸ“‰ Average Deviation: {avg_dev:.3f} mm")
67
+
68
+ st.line_chart(all_diffs[:100])
requirements.txt CHANGED
@@ -1,3 +1,2 @@
1
- altair
2
- pandas
3
- streamlit
 
1
+ streamlit
2
+ pythonOCC-core