-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
688 lines (597 loc) · 23.8 KB
/
index.html
File metadata and controls
688 lines (597 loc) · 23.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>点云抓取可视化系统</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r128/three.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/three@0.128.0/examples/js/controls/OrbitControls.js"></script>
<style>
body {
margin: 0;
font-family: Arial, sans-serif;
background-color: #f0f0f0;
}
.container {
display: flex;
min-height: 100vh;
}
.sidebar {
width: 300px;
background-color: #fff;
padding: 20px;
box-shadow: 2px 0 5px rgba(0,0,0,0.1);
}
.main-content {
flex: 1;
padding: 20px;
display: flex;
flex-direction: column;
}
.visualization-container {
flex: 1;
background: #000;
border-radius: 8px;
overflow: hidden;
position: relative;
}
.control-panel {
background: rgba(0,0,0,0.7);
padding: 15px;
border-radius: 8px;
margin-top: 20px;
color: white;
}
.control-group {
margin-bottom: 15px;
}
.control-group h3 {
margin: 0 0 10px 0;
color: #fff;
}
button {
background-color: #4CAF50;
color: white;
border: none;
padding: 8px 15px;
border-radius: 4px;
cursor: pointer;
margin: 5px;
transition: background-color 0.3s;
}
button:hover {
background-color: #45a049;
}
.slider-container {
margin: 10px 0;
}
.slider-container label {
display: block;
margin-bottom: 5px;
color: #fff;
}
input[type="range"] {
width: 100%;
}
.status-panel {
background: #fff;
padding: 15px;
border-radius: 8px;
margin-top: 20px;
box-shadow: 0 2px 5px rgba(0,0,0,0.1);
}
.status-item {
margin: 5px 0;
padding: 5px;
border-bottom: 1px solid #eee;
}
.param-item {
margin: 10px 0;
}
.param-item label {
display: block;
margin-bottom: 5px;
color: #333;
}
.param-item input,
.param-item select {
width: 100%;
padding: 5px;
border: 1px solid #ddd;
border-radius: 4px;
}
.param-item input[type="number"] {
width: 100px;
}
.param-item select {
width: 100%;
padding: 8px;
border: 1px solid #ddd;
border-radius: 4px;
background-color: white;
cursor: pointer;
}
.param-item select:hover {
border-color: #4CAF50;
}
/* 添加指南弹窗样式 */
.guide-modal {
display: none;
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: rgba(0, 0, 0, 0.5);
z-index: 1000;
overflow-y: auto;
}
.guide-content {
position: relative;
background-color: #fff;
margin: 5% auto;
padding: 20px;
width: 80%;
max-width: 800px;
border-radius: 8px;
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}
.guide-header {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 20px;
padding-bottom: 10px;
border-bottom: 1px solid #eee;
}
.guide-header h2 {
margin: 0;
color: #333;
}
.guide-close {
background: none;
border: none;
font-size: 24px;
cursor: pointer;
color: #666;
padding: 5px;
}
.guide-close:hover {
color: #333;
}
.guide-body {
max-height: 70vh;
overflow-y: auto;
padding-right: 10px;
}
.guide-body h3 {
color: #4CAF50;
margin-top: 20px;
}
.guide-body p {
line-height: 1.6;
color: #666;
}
.guide-body ul {
padding-left: 20px;
}
.guide-body li {
margin: 10px 0;
color: #666;
}
.guide-button {
position: fixed;
bottom: 20px;
right: 20px;
background-color: #4CAF50;
color: white;
padding: 10px 20px;
border: none;
border-radius: 4px;
cursor: pointer;
z-index: 999;
box-shadow: 0 2px 5px rgba(0,0,0,0.2);
}
.guide-button:hover {
background-color: #45a049;
}
</style>
</head>
<body>
<!-- 添加指南弹窗 -->
<div id="guideModal" class="guide-modal">
<div class="guide-content">
<div class="guide-header">
<h2>点云抓取可视化系统使用指南</h2>
<button class="guide-close" onclick="closeGuide()">×</button>
</div>
<div class="guide-body">
<h3>欢迎使用</h3>
<p>欢迎使用我们的点云抓取可视化系统!本系统旨在帮助您直观地查看和分析机器人抓取预测结果。通过本指南,您将了解如何充分利用系统的各项功能。</p>
<h3>快速入门</h3>
<h4>1. 加载数据</h4>
<ul>
<li>点击"加载数据"按钮加载默认数据</li>
<li>或通过文件选择器上传您的H5格式点云文件</li>
<li>系统会自动处理并显示点云数据</li>
</ul>
<h4>2. 基本操作</h4>
<ul>
<li><strong>旋转视角</strong>:按住鼠标左键拖动</li>
<li><strong>缩放</strong>:使用鼠标滚轮</li>
<li><strong>平移</strong>:按住鼠标右键拖动</li>
<li><strong>重置视角</strong>:点击"重置视角"按钮</li>
<li><strong>自动旋转</strong>:点击"切换自动旋转"按钮</li>
</ul>
<h3>功能详解</h3>
<h4>显示控制</h4>
<ul>
<li><strong>切换抓取点显示</strong>:显示/隐藏蓝色抓取点</li>
<li><strong>切换抓取姿态显示</strong>:显示/隐藏夹爪模型</li>
<li>所有显示元素都可以独立控制</li>
</ul>
<h4>参数设置</h4>
<ol>
<li><strong>抓取分数阈值</strong>
<ul>
<li>使用滑块调节(0-1之间)</li>
<li>数值越大,显示的抓取点质量越高</li>
<li>实时更新显示效果</li>
</ul>
</li>
<li><strong>模型参数</strong>
<ul>
<li><strong>模型选择</strong>:GraspNet或DGCNN</li>
<li><strong>物体类别</strong>:支持多种物体类型</li>
<li><strong>采样点数</strong>:可选择512/1024/2048点</li>
</ul>
</li>
</ol>
<h3>使用技巧</h3>
<h4>最佳实践</h4>
<ol>
<li><strong>数据加载</strong>
<ul>
<li>建议先使用默认数据熟悉系统</li>
<li>上传自定义数据时确保格式正确</li>
</ul>
</li>
<li><strong>参数调节</strong>
<ul>
<li>从默认参数开始调整</li>
<li>分数阈值建议从0.5开始调节</li>
<li>采样点数根据物体复杂度选择</li>
</ul>
</li>
<li><strong>视角控制</strong>
<ul>
<li>使用自动旋转功能观察整体效果</li>
<li>需要细节观察时关闭自动旋转</li>
<li>使用重置视角快速回到初始状态</li>
</ul>
</li>
</ol>
<h3>注意事项</h3>
<ul>
<li>确保浏览器支持WebGL</li>
<li>建议使用Chrome或Firefox浏览器</li>
<li>大文件加载可能需要等待</li>
<li>定期保存重要参数设置</li>
</ul>
</div>
</div>
</div>
<!-- 添加指南按钮 -->
<button class="guide-button" onclick="openGuide()">查看使用指南</button>
<div class="container">
<!-- 侧边栏 -->
<div class="sidebar">
<h2>控制面板</h2>
<div class="control-group">
<h3>数据加载</h3>
<button onclick="loadData()">加载数据</button>
<input type="file" id="h5FileInput" accept=".h5" style="margin-top:10px;" onchange="uploadH5File(event)">
</div>
<div class="control-group">
<h3>显示控制</h3>
<button onclick="toggleGraspPoints()">切换抓取点显示</button>
<button onclick="toggleGraspPoses()">切换抓取姿态显示</button>
</div>
<div class="control-group">
<h3>抓取参数</h3>
<div class="slider-container">
<div style="font-weight:bold; color:#333; margin-bottom:4px;">阈值设置</div>
<label for="graspScore">抓取分数阈值: <span id="graspScoreValue">0.5</span></label>
<input type="range" id="graspScore" min="0" max="1" step="0.1" value="0.5" onchange="updateGraspScore()">
</div>
</div>
<div class="control-group">
<h3>模型参数</h3>
<div class="param-item">
<label for="modelSelect">模型选择:</label>
<select id="modelSelect" onchange="updateParams()">
<option value="GraspNet">GraspNet</option>
<option value="DGCNN">DGCNN</option>
</select>
</div>
<div class="param-item">
<label for="category">物体类别:</label>
<select id="category" onchange="updateParams()">
<option value="eyeglasses">eyeglasses</option>
<option value="scissors">scissors</option>
<option value="laptop">laptop</option>
</select>
</div>
<div class="param-item">
<label for="npoint">采样点数:</label>
<select id="npoint" onchange="updateParams()">
<option value="512">512</option>
<option value="1024">1024</option>
<option value="2048" selected>2048</option>
</select>
</div>
</div>
<div class="status-panel">
<h3>系统状态</h3>
<div class="status-item">点云数量: <span id="pointCount">0</span></div>
<div class="status-item">抓取点数量: <span id="graspCount">0</span></div>
<div class="status-item">当前分数阈值: <span id="currentScore">0.5</span></div>
</div>
</div>
<!-- 主要内容区 -->
<div class="main-content">
<div class="visualization-container" id="pointcloud-container"></div>
<div class="control-panel">
<h3>实时控制</h3>
<div class="control-group">
<button onclick="resetCamera()">重置视角</button>
<button onclick="toggleAutoRotate()">切换自动旋转</button>
</div>
</div>
</div>
</div>
<script>
let scene, camera, renderer, controls;
let pointCloud, graspPoints, graspPoses;
let showGraspPoints = true;
let showGraspPoses = true;
let graspScoreThreshold = 0.5;
let autoRotate = false;
let modelParams = {
model: 'GraspNet',
category: 'eyeglasses',
npoint: 2048
};
let uploadedH5Path = null;
init();
animate();
function init() {
const container = document.getElementById('pointcloud-container');
scene = new THREE.Scene();
camera = new THREE.PerspectiveCamera(75, container.clientWidth / container.clientHeight, 0.1, 1000);
renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setSize(container.clientWidth, container.clientHeight);
container.appendChild(renderer.domElement);
controls = new THREE.OrbitControls(camera, renderer.domElement);
camera.position.z = 5;
// 添加环境光
const ambientLight = new THREE.AmbientLight(0xffffff, 0.5);
scene.add(ambientLight);
// 添加平行光
const directionalLight = new THREE.DirectionalLight(0xffffff, 0.5);
directionalLight.position.set(0, 1, 0);
scene.add(directionalLight);
}
function animate() {
requestAnimationFrame(animate);
controls.update();
renderer.render(scene, camera);
}
function updateParams() {
modelParams.model = document.getElementById('modelSelect').value;
modelParams.category = document.getElementById('category').value;
modelParams.npoint = parseInt(document.getElementById('npoint').value);
}
function uploadH5File(event) {
const file = event.target.files[0];
if (!file) return;
const formData = new FormData();
formData.append('file', file);
const serverUrl = window.location.hostname === 'localhost' ? 'http://localhost:8000' : '';
fetch(`${serverUrl}/upload`, {
method: 'POST',
body: formData
})
.then(response => response.json())
.then(data => {
if (data.error) {
alert('文件上传失败: ' + data.error);
} else {
uploadedH5Path = data.path;
alert('文件上传成功,自动加载!');
loadData();
}
})
.catch(err => {
alert('文件上传失败: ' + err.message);
});
}
function loadData() {
const serverUrl = window.location.hostname === 'localhost' ? 'http://localhost:8000' : '';
fetch(`${serverUrl}/predict`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
model: modelParams.model,
log_dir: modelParams.category, // 使用类别作为日志目录
npoint: modelParams.npoint,
category: modelParams.category,
input_h5_path: uploadedH5Path || `/16T/guoyuefan/grasp_data/${modelParams.category}/001402.h5`,
score_threshold: graspScoreThreshold // 添加阈值参数
})
})
.then(response => {
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
return response.json();
})
.then(data => {
if (data.error) {
throw new Error(data.error);
}
visualizeData(data);
updateStatus(data);
})
.catch(error => {
console.error('Error:', error);
alert('加载数据失败: ' + error.message);
});
}
function visualizeData(data) {
// 清除现有的点云和抓取点
if (pointCloud) scene.remove(pointCloud);
if (graspPoints) scene.remove(graspPoints);
if (graspPoses) {
graspPoses.forEach(pose => scene.remove(pose));
graspPoses = [];
}
// 创建点云(灰色)
const geometry = new THREE.BufferGeometry();
const positions = new Float32Array(data.input_points.flat());
geometry.setAttribute('position', new THREE.BufferAttribute(positions, 3));
const material = new THREE.PointsMaterial({
color: 0x808080,
size: 0.015,
transparent: true,
opacity: 0.6
});
pointCloud = new THREE.Points(geometry, material);
scene.add(pointCloud);
// 创建抓取点(蓝色)
const graspGeometry = new THREE.BufferGeometry();
const graspPositions = new Float32Array(data.grasp_mask_points.flat());
graspGeometry.setAttribute('position', new THREE.BufferAttribute(graspPositions, 3));
const graspMaterial = new THREE.PointsMaterial({
color: 0x0088ff,
size: 0.02,
transparent: true,
opacity: 0.8
});
graspPoints = new THREE.Points(graspGeometry, graspMaterial);
scene.add(graspPoints);
// 创建抓取姿态
graspPoses = [];
data.top_grasp_points.forEach((point, index) => {
const quat = data.top_quats[index];
const pose = createGraspPose(point, quat);
graspPoses.push(pose);
scene.add(pose);
});
// 调整相机位置以适应点云
const box = new THREE.Box3().setFromObject(pointCloud);
const center = box.getCenter(new THREE.Vector3());
const size = box.getSize(new THREE.Vector3());
const maxDim = Math.max(size.x, size.y, size.z);
const fov = camera.fov * (Math.PI / 180);
let cameraZ = Math.abs(maxDim / Math.sin(fov / 2));
camera.position.set(center.x, center.y, center.z + cameraZ * 1.5);
camera.lookAt(center);
controls.target.copy(center);
}
function createGraspPose(point, quat) {
const group = new THREE.Group();
// 掌心(深灰色)
const palmGeometry = new THREE.BoxGeometry(0.04, 0.01, 0.02);
const palmMaterial = new THREE.MeshPhongMaterial({ color: 0x444444, shininess: 80, specular: 0x888888 });
const palm = new THREE.Mesh(palmGeometry, palmMaterial);
palm.position.set(0, 0, 0.01);
group.add(palm);
// 左指(红色,带高光)
const fingerGeometry = new THREE.BoxGeometry(0.01, 0.04, 0.01);
const fingerMaterial = new THREE.MeshPhongMaterial({ color: 0xff3333, shininess: 100, specular: 0xffffff });
const leftFinger = new THREE.Mesh(fingerGeometry, fingerMaterial);
leftFinger.position.set(-0.015, 0.025, 0.01);
group.add(leftFinger);
// 右指(红色,带高光)
const rightFinger = new THREE.Mesh(fingerGeometry, fingerMaterial);
rightFinger.position.set(0.015, 0.025, 0.01);
group.add(rightFinger);
// 坐标系
const axesHelper = new THREE.AxesHelper(0.03);
group.add(axesHelper);
// 设置位置和旋转
group.position.set(point[0], point[1], point[2]);
group.quaternion.set(quat[0], quat[1], quat[2], quat[3]);
return group;
}
function toggleGraspPoints() {
if (graspPoints) {
graspPoints.visible = !graspPoints.visible;
}
}
function toggleGraspPoses() {
if (graspPoses) {
graspPoses.forEach(pose => {
pose.visible = !pose.visible;
});
}
}
function updateGraspScore() {
graspScoreThreshold = parseFloat(document.getElementById('graspScore').value);
document.getElementById('currentScore').textContent = graspScoreThreshold.toFixed(1);
document.getElementById('graspScoreValue').textContent = graspScoreThreshold.toFixed(1);
loadData(); // 当阈值改变时重新加载数据
}
function updateStatus(data) {
document.getElementById('pointCount').textContent = data.input_points.length;
document.getElementById('graspCount').textContent = data.grasp_mask_points.length;
}
function resetCamera() {
if (pointCloud) {
const box = new THREE.Box3().setFromObject(pointCloud);
const center = box.getCenter(new THREE.Vector3());
const size = box.getSize(new THREE.Vector3());
const maxDim = Math.max(size.x, size.y, size.z);
const fov = camera.fov * (Math.PI / 180);
let cameraZ = Math.abs(maxDim / Math.sin(fov / 2));
camera.position.set(center.x, center.y, center.z + cameraZ * 1.5);
camera.lookAt(center);
controls.target.copy(center);
}
}
function toggleAutoRotate() {
autoRotate = !autoRotate;
controls.autoRotate = autoRotate;
}
// 响应窗口大小变化
window.addEventListener('resize', onWindowResize, false);
function onWindowResize() {
const container = document.getElementById('pointcloud-container');
camera.aspect = container.clientWidth / container.clientHeight;
camera.updateProjectionMatrix();
renderer.setSize(container.clientWidth, container.clientHeight);
}
// 添加指南弹窗控制函数
function openGuide() {
document.getElementById('guideModal').style.display = 'block';
}
function closeGuide() {
document.getElementById('guideModal').style.display = 'none';
}
// 页面加载时自动打开指南
window.onload = function() {
openGuide();
};
// 点击弹窗外部关闭弹窗
window.onclick = function(event) {
const modal = document.getElementById('guideModal');
if (event.target == modal) {
closeGuide();
}
}
</script>
</body>
</html>