Changeset 17805 for trunk/FACT++/www/viewer
- Timestamp:
- 05/08/14 12:44:38 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/FACT++/www/viewer/index.js
r17796 r17805 464 464 canv.dataAbs = new Array(1440); 465 465 for (var i=0; i<1440; i++) 466 if (data[i]!==undefined && data[i]!==null) 467 canv.dataAbs[i] = data[i]; 466 { 467 var val = data[map[i]]; 468 if (val!==undefined && val!==null) 469 canv.dataAbs[i] = val; 470 } 471 472 canv.hillas = Hillas(canv.dataAbs); 473 debug(JSON.stringify(canv.hillas)); 468 474 469 475 canv.min = Math.min.apply(Math, canv.dataAbs.filter(function(e){return !isNaN(e)})); … … 472 478 canv.dataRel = new Array(1440); 473 479 for (var i=0; i<1440; i++) 474 if (data[i]!==undefined && data[i]!==null) 475 canv.dataRel[i] = (data[i]-canv.min)/canv.max; 480 { 481 val = data[map[i]]; 482 if (val!==undefined && val!==null) 483 canv.dataRel[i] = (val-canv.min)/canv.max; 484 } 476 485 477 486 if (document.getElementById("cameraminon"+n).checked) … … 773 782 } 774 783 775 function onMarker()784 function refreshCameras() 776 785 { 777 786 drawFullCam("camera1"); … … 1328 1337 1329 1338 for (var i=0; i<1440; i++) 1330 drawHex(ctx, coord[i][0], coord[i][1], data[map[i]], min, max); 1339 drawHex(ctx, coord[i][0], coord[i][1], data[i], min, max); 1340 1341 // =================== Draw Pixel marker ==================== 1331 1342 1332 1343 if (document.getElementById('marker').checked) … … 1345 1356 } 1346 1357 1358 // ======================= Draw Ellipse ====================== 1359 1360 var h = canv.hillas; 1361 if (h && document.getElementById('image').checked) 1362 { 1363 ctx.save(); 1364 1365 ctx.translate(h.mean[0], h.mean[1]); 1366 ctx.rotate(h.phi); 1367 1368 ctx.save(); 1369 ctx.scale(h.axis[0], h.axis[1]); 1370 ctx.beginPath(); 1371 ctx.arc(0, 0, 1, 0, 2*Math.PI); 1372 ctx.restore(); 1373 1374 ctx.lineWidth = 0.15; 1375 ctx.strokeStyle = "#444"; 1376 ctx.stroke(); 1377 1378 ctx.strokeStyle = "#888"; 1379 ctx.beginPath(); 1380 ctx.moveTo(0, -h.disp); 1381 ctx.lineTo(0, h.disp); 1382 ctx.stroke(); 1383 1384 ctx.restore(); 1385 } 1386 1347 1387 ctx.restore(); 1348 1388 1349 1389 // ======================= Draw Legend ====================== 1350 1390 1351 var pval = parseFloat(canv.dataAbs[ map[pixel]]).toFixed(1);1391 var pval = parseFloat(canv.dataAbs[pixel]).toFixed(1); 1352 1392 var lmin = parseFloat(canv.min).toFixed(1); 1353 1393 var lmax = parseFloat(canv.max).toFixed(1); … … 1382 1422 ctx.strokeText(lmin, 5+mw, 5); 1383 1423 } 1424 1425 // =================================================================== 1426 1427 function Hillas(data) 1428 { 1429 var mx = 0; 1430 var my = 0; 1431 var sz = 0; 1432 1433 var cnt = 0; 1434 for (var i=0; i<1440; i++) 1435 { 1436 if (data[i]===undefined) 1437 continue; 1438 1439 sz += data[i]; 1440 mx += data[i] * coord[i][0]; 1441 my += data[i] * coord[i][1]; 1442 1443 cnt++; 1444 } 1445 1446 if (sz==0) 1447 return; 1448 1449 mx /= sz; 1450 my /= sz; 1451 1452 if (cnt<3) 1453 return; 1454 1455 var xx=0; 1456 var xy=0; 1457 var yy=0; 1458 1459 for (var i=0; i<1440; i++) 1460 { 1461 if (data[i]===undefined) 1462 continue; 1463 1464 var dx = coord[i][0] - mx; 1465 var dy = coord[i][1] - my; 1466 1467 xx += data[i] * dx*dx; 1468 xy += data[i] * dx*dy; 1469 yy += data[i] * dy*dy; 1470 } 1471 1472 var d0 = yy - xx; 1473 var d1 = xy*2; 1474 var d2 = Math.sqrt(d0*d0 + d1*d1) + d0; 1475 1476 var tand = d2==0 ? 0 : d2 / d1; 1477 var tand2 = tand*tand; 1478 1479 var s2 = tand2+1; 1480 var s = Math.sqrt(s2); 1481 1482 var phi = 0; 1483 var cos = 0; 1484 var sin = 1; 1485 1486 var axis1 = yy; 1487 var axis2 = xx; 1488 var ratio = xx/yy; 1489 1490 if (d1!=0 || d2==0) 1491 { 1492 phi = Math.atan(tand)-Math.PI/2; 1493 cos = 1.0 /s; 1494 sin = tand/s; 1495 1496 axis1 = (tand2*yy + d2 + xx)/s2; 1497 axis2 = (tand2*xx - d2 + yy)/s2; 1498 ratio = (tand2*xx - d2 + yy)/(tand2*yy + d2 + xx); 1499 } 1500 1501 var length = axis1<0 ? 0 : Math.sqrt(axis1/sz); 1502 var width = axis2<0 ? 0 : Math.sqrt(axis2/sz); 1503 1504 return { 1505 "mean": [ mx, my ], 1506 "axis": [ width, length ], 1507 "phi": phi, 1508 "delta": [ cos, sin ], 1509 "sumw": sz, 1510 "count": cnt, 1511 "disp": 1.42/0.1111*(1-Math.sqrt(ratio)), 1512 }; 1513 }
Note:
See TracChangeset
for help on using the changeset viewer.