Pushpak21 commited on
Commit
569908e
·
verified ·
1 Parent(s): 354747c

Upload folder using huggingface_hub

Browse files
Files changed (1) hide show
  1. index.html +78 -52
index.html CHANGED
@@ -7,78 +7,78 @@
7
  <title>DCM Assembly Visualizer</title>
8
  <script src="https://cdn.plot.ly/plotly-latest.min.js"></script>
9
  <style>
10
- body { font-family: sans-serif; padding: 20px; background-color: #111; color: white; }
11
- #plot { width: 100%; height: 700px; margin-top: 20px; }
12
- input, button { margin: 10px 0; padding: 8px; }
13
  </style>
14
  </head>
15
  <body>
16
  <h1>DCM Assembly Visualizer</h1>
17
 
18
- <label>Upload File A: <input type="file" id="file1" accept=".txt" /></label><br />
19
- <label>Upload File B: <input type="file" id="file2" accept=".txt" /></label><br />
20
- <button onclick="uploadFiles()">Visualize</button>
21
-
22
- <div id="plot"></div>
 
 
 
 
 
23
 
24
  <script>
25
- async function uploadFiles() {
26
- const file1 = document.getElementById("file1").files[0];
27
- const file2 = document.getElementById("file2").files[0];
28
 
29
- const traces = [];
 
 
 
 
 
30
 
31
- if (file1) {
32
- const data1 = await sendFile(file1);
33
- traces.push(...extractTraces(data1, 'red', 'blue'));
34
  }
35
 
36
- if (file2) {
37
- const data2 = await sendFile(file2);
38
- traces.push(...extractTraces(data2, 'orange', 'purple'));
39
- }
40
 
41
- Plotly.newPlot('plot', traces, {
42
  margin: { t: 30 },
43
  scene: { aspectmode: 'data' },
44
  title: '3D Assembly Viewer'
45
  });
46
  }
47
 
48
- async function sendFile(file) {
49
- const formData = new FormData();
50
- formData.append("file", file);
51
- const res = await fetch("/parse", {
52
- method: "POST",
53
- body: formData
54
- });
55
- return await res.json();
56
- }
57
-
58
  function extractTraces(data, baseColor, normalColor) {
59
- const traces = [];
60
-
61
  for (const [tag, g] of Object.entries(data.geometry)) {
62
  const [x, y, z] = g.base_point;
63
  const [nx, ny, nz] = g.normal;
 
 
64
 
65
- traces.push({
66
- type: 'scatter3d',
67
- mode: 'markers+text',
68
  x: [x], y: [y], z: [z],
69
  marker: { color: baseColor, size: 5 },
70
- text: [g.label || tag],
71
- textposition: 'top center'
72
- });
73
-
74
- traces.push({
75
- type: 'scatter3d',
76
- mode: 'lines',
77
- x: [x, x + nx],
78
- y: [y, y + ny],
79
- z: [z, z + nz],
80
- line: { color: normalColor, width: 2 }
81
- });
 
 
 
 
 
82
  }
83
 
84
  for (const c of data.constraints) {
@@ -87,17 +87,43 @@
87
  if (g1 && g2) {
88
  const [x1, y1, z1] = g1.base_point;
89
  const [x2, y2, z2] = g2.base_point;
90
- traces.push({
91
- type: 'scatter3d',
92
- mode: 'lines',
93
  x: [x1, x2], y: [y1, y2], z: [z1, z2],
94
- line: { color: 'green', dash: 'dot', width: 2 }
 
95
  });
96
  }
97
  }
 
98
 
99
- return traces;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
100
  }
 
 
 
 
 
 
 
 
 
 
 
101
  </script>
102
  </body>
103
  </html>
 
7
  <title>DCM Assembly Visualizer</title>
8
  <script src="https://cdn.plot.ly/plotly-latest.min.js"></script>
9
  <style>
10
+ body { font-family: sans-serif; padding: 20px; }
11
+ #plot { width: 100%; height: 700px; }
12
+ .controls { width: 200px; margin-right: 20px; }
13
  </style>
14
  </head>
15
  <body>
16
  <h1>DCM Assembly Visualizer</h1>
17
 
18
+ <div style="display: flex;">
19
+ <div class="controls">
20
+ <h3>Controls</h3>
21
+ <div id="partControls"></div>
22
+ <label><input type="checkbox" id="toggleConstraints" checked onchange="toggleConstraints()"> Show Constraints</label>
23
+ </div>
24
+ <div style="flex: 1;">
25
+ <div id="plot"></div>
26
+ </div>
27
+ </div>
28
 
29
  <script>
30
+ let allTraces = [];
31
+ let constraintTraces = [];
32
+ let partMap = {}; // { part: [traceIndices] }
33
 
34
+ async function drawFromServer() {
35
+ const res = await fetch("/parsed_data.json");
36
+ const payload = await res.json();
37
+ allTraces = [];
38
+ constraintTraces = [];
39
+ partMap = {};
40
 
41
+ for (const [color, label, data] of payload.files) {
42
+ extractTraces(data, color, label);
 
43
  }
44
 
45
+ renderPartControls();
 
 
 
46
 
47
+ Plotly.newPlot('plot', [...allTraces, ...constraintTraces], {
48
  margin: { t: 30 },
49
  scene: { aspectmode: 'data' },
50
  title: '3D Assembly Viewer'
51
  });
52
  }
53
 
 
 
 
 
 
 
 
 
 
 
54
  function extractTraces(data, baseColor, normalColor) {
 
 
55
  for (const [tag, g] of Object.entries(data.geometry)) {
56
  const [x, y, z] = g.base_point;
57
  const [nx, ny, nz] = g.normal;
58
+ const label = g.label || tag;
59
+ const part = label.split('@').pop()?.split('-')[0] || "unknown";
60
 
61
+ const baseTrace = {
62
+ type: 'scatter3d', mode: 'markers+text',
 
63
  x: [x], y: [y], z: [z],
64
  marker: { color: baseColor, size: 5 },
65
+ text: [label], textposition: 'top center',
66
+ name: `Base: ${label}`
67
+ };
68
+
69
+ const normalTrace = {
70
+ type: 'scatter3d', mode: 'lines',
71
+ x: [x, x + nx], y: [y, y + ny], z: [z, z + nz],
72
+ line: { color: normalColor, width: 2 },
73
+ name: `Normal: ${label}`
74
+ };
75
+
76
+ const baseIndex = allTraces.length;
77
+ allTraces.push(baseTrace);
78
+ allTraces.push(normalTrace);
79
+
80
+ if (!partMap[part]) partMap[part] = [];
81
+ partMap[part].push(baseIndex, baseIndex + 1);
82
  }
83
 
84
  for (const c of data.constraints) {
 
87
  if (g1 && g2) {
88
  const [x1, y1, z1] = g1.base_point;
89
  const [x2, y2, z2] = g2.base_point;
90
+ constraintTraces.push({
91
+ type: 'scatter3d', mode: 'lines',
 
92
  x: [x1, x2], y: [y1, y2], z: [z1, z2],
93
+ line: { color: 'green', dash: 'dot', width: 2 },
94
+ name: `Constraint: ${c.label || ''}`
95
  });
96
  }
97
  }
98
+ }
99
 
100
+ function renderPartControls() {
101
+ const container = document.getElementById("partControls");
102
+ container.innerHTML = '';
103
+ for (const part in partMap) {
104
+ const id = `part_${part}`;
105
+ container.innerHTML += `<label><input type='checkbox' id='${id}' checked onchange='togglePart("${part}")'> ${part}</label><br>`;
106
+ }
107
+ }
108
+
109
+ function togglePart(part) {
110
+ const indices = partMap[part];
111
+ const visible = document.getElementById(`part_${part}`).checked;
112
+ for (const i of indices) {
113
+ Plotly.restyle('plot', { visible: visible }, [i]);
114
+ }
115
  }
116
+
117
+ function toggleConstraints() {
118
+ const show = document.getElementById("toggleConstraints").checked;
119
+ const start = allTraces.length;
120
+ const end = start + constraintTraces.length;
121
+ for (let i = start; i < end; i++) {
122
+ Plotly.restyle('plot', { visible: show }, [i]);
123
+ }
124
+ }
125
+
126
+ drawFromServer();
127
  </script>
128
  </body>
129
  </html>