From 64edaff53dbbc64e9116c0a32ffbc815cdca99bc Mon Sep 17 00:00:00 2001 From: YamamotoTakayuki Date: Wed, 14 Feb 2018 13:41:30 +0900 Subject: [PATCH] CLEM --- JS/CLEM.js | 295 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ JS/drawImage.js | 31 ++++++ JS/em.js | 16 +-- JS/log.js | 122 +++++++++++++++++++++++ JS/map.js | 63 ++++++++++++ index.html | 6 +- simplePhoto.html | 56 +++++++++-- test.bat | 1 + 8 files changed, 576 insertions(+), 14 deletions(-) create mode 100644 JS/CLEM.js create mode 100644 JS/log.js create mode 100644 JS/map.js create mode 100644 test.bat diff --git a/JS/CLEM.js b/JS/CLEM.js new file mode 100644 index 0000000..ed10ac3 --- /dev/null +++ b/JS/CLEM.js @@ -0,0 +1,295 @@ +$(function() { + var canvas = $('#canvasCLEM'); + var ctx = canvas[0].getContext("2d"); + + $('#CLEMimg').on('change', function CLEMmap() { //画像を選択時に呼び出される + + if (window.File) { //FileAPIを未対応ブラウザではアラート + + var files = $('#CLEMimg')[0].files[0]; + var reader = new FileReader(); + var img = new Image(); + + reader.onload = function(evt) { + img.onload = function() { + // 参考 https://qiita.com/PG0721/items/599ba2921b8339700fe3 + var imgAspect = img.width / img.height; + ctx.clearRect(0, 0, 512, 512); + if (imgAspect >= 1) { //画像が横長 + left = 0; + width = ctx.canvas.width; + height = ctx.canvas.height / imgAspect; + to = (ctx.canvas.height - height) / 2; + } else { //画像が縦長 + to = 0; + width = ctx.canvas.width * imgAspect; + height = ctx.canvas.height; + left = (ctx.canvas.width - width) / 2; + } + ctx.drawImage(img, 0, 0, img.width, img.height, left, to, width, height); //画像をアスペクト比を維持して中心に表示 + } + img.src = evt.target.result; + } + reader.readAsDataURL(files); + } else { + window.alert("本ブラウザではFile APIが使えません"); + } + }); //END CLEMmap() + + $('#setClemButton').on('click', function setClem() { + var tbody = document.getElementById("listCoord"); + var rowlen = tbody.rows.length; //行数 + // LM X Y EM X Y Mov Del + //cells 0 1 2 3 4 5 6 7 + + if (rowlen >= 2) { + + var LmVec = new Array(); + var EmVec = new Array(); + var rad = 0; + for (var i = 0; i < (rowlen - 1); i++) { + LmVec[i] = new Object(); + + LmVec[i].x = tbody.rows[0].cells[1].innerText - tbody.rows[i + 1].cells[1].innerText; + LmVec[i].y = tbody.rows[0].cells[2].innerText - tbody.rows[i + 1].cells[2].innerText; + // alert(LmVec[i].x+" , "+LmVec[i].y); + EmVec[i] = new Object(); + EmVec[i].x = tbody.rows[0].cells[4].innerText - tbody.rows[i + 1].cells[4].innerText; + EmVec[i].y = tbody.rows[0].cells[5].innerText - tbody.rows[i + 1].cells[5].innerText; + // alert(EmVec[i].x+" , "+EmVec[i].y); + var dist = Math.sqrt(LmVec[i].x * LmVec[i].x + LmVec[i].y * LmVec[i].y) * Math.sqrt(EmVec[i].x * EmVec[i].x + EmVec[i].y * EmVec[i].y); + if (dist == 0) { + alert("座標をセットし直して下さい"); + } else { + var cos = (LmVec[i].x * EmVec[i].x + LmVec[i].y * EmVec[i].y) / dist; + var sin = (LmVec[i].x * EmVec[i].y - LmVec[i].y * EmVec[i].x) / dist; + + //alert("cos:"+cos+" sin:"+sin); + var rad1 = Math.acos(cos); + var rad2 = Math.asin(sin); + + //alert("rad1:"+rad1+" rad2:"+rad2); + if (cos >= 0 && sin >= 0) { //0= 0 && sin < 0) { //-2/pi= 0) { //pi/2= 3) { + var target = { + x: innerTd.parentNode.parentNode.cells[1].innerText, + y: innerTd.parentNode.parentNode.cells[2].innerText + }; + var goal = { + x: 0, + y: 0 + }; + var LmVec = new Array(); + var EmVec = new Array(); + var rad = 0; + + alert("init x:" + goal.x + " ,y:" + goal.y); + for (var i = 0; i < (rowlen - 1); i++) { + LmVec[i] = new Object(); + + LmVec[i].x = tbody.rows[0].cells[1].innerText - tbody.rows[i + 1].cells[1].innerText; + LmVec[i].y = tbody.rows[0].cells[2].innerText - tbody.rows[i + 1].cells[2].innerText; + // alert(LmVec[i].x+" , "+LmVec[i].y); + EmVec[i] = new Object(); + EmVec[i].x = tbody.rows[0].cells[4].innerText - tbody.rows[i + 1].cells[4].innerText; + EmVec[i].y = tbody.rows[0].cells[5].innerText - tbody.rows[i + 1].cells[5].innerText; + } + + //target.x=LmVec.x*s+LmVec.y*t p=ax+by + //target.y=EmVec.x*s+EmVec.y*t q=cx+dy + + for (var i = 0; i < (rowlen - 2); i++) { //解法:クラメルの公式 + var Det = LmVec[0].x * LmVec[i + 1].y - LmVec[0].y + LmVec[i + 1].x; //ad-bc + alert("det:" + Det); + if (Det == 0) { + //解が一位に定まらない + } else { + var s = (target.x * LmVec[i + 1].y - LmVec[0].y * target.x) / Det; + var t = (LmVec[0].x * target.y - target.y + LmVec[i + 1].x) / Det; + alert("s:" + s + " ,t:" + t); + goal.x += s * EmVec[0].x + t * EmVec[i + 1].x; + goal.y += s * EmVec[0].y + t * EmVec[i + 1].y; + } + } + + goal.x = goal.x / (rowlen - 2); + goal.y = goal.y / (rowlen - 2); + goal.x = Math.round(goal.x); + goal.y = Math.round(goal.y); + alert("x:" + goal.x + " ,y:" + goal.y); + + var movexr = $("#movex").val(); + var moveyr = $("#movey").val(); + var movezr = $("#movez").val(); + console.log("movex="+movexr); + console.log("movey="+moveyr); + movexr = goal.x; + moveyr = goal.y; + $("#movex").val(String(movexr)); + $("#movey").val(String(moveyr)); + + $.ajax({ + type:"GET", + url:"http://" +UrlElement['sendIpAddress']+ + ":"+UrlElement['sendPortNumber']+"/"+UrlElement['sendManufacturer']+ + "/set/stagea?x="+encodeURIComponent(movexr)+ + "&y="+encodeURIComponent(moveyr)+ + "&z="+encodeURIComponent(movezr)+ + "&a="+encodeURIComponent(movezr), + success: function(data){ + console.log(data);//string型 + } + }); + + + } else { + alert("LM座標を3つ、EM座標を2つ以上指定して下さい"); + } +} // END moveEmCoordinate(innerTd); + + +//var txt=document.createTextNode("X:"+cod.x+" , Y:"+cod.y); +//first.appendChild(txt); +//coordinate.removeChild(); +// var txt=document.createTextNode(); +// coordinate.appendChild(txt); diff --git a/JS/drawImage.js b/JS/drawImage.js index c50f649..95b09d5 100644 --- a/JS/drawImage.js +++ b/JS/drawImage.js @@ -30,3 +30,34 @@ function drawMycrograph(ddata){ context.putImageData(imgData, 0, 0); } +$(function(){ + + var state="off" + var canvas = document.getElementById("canvasGuide"); + var ctx=canvas.getContext('2d'); + var center = {x:512/2,y:512/2}; + $("#dispGuideButton").click( function(){ + if(state=="on"){ + ctx.clearRect(0,0,512,512); + state="off"; + }else{ + + // 横線を引く + ctx.beginPath(); + ctx.moveTo(0, center.y); + ctx.lineTo(512, center.y); + ctx.closePath(); + ctx.stroke(); + + +// 縦線を引く + ctx.beginPath(); + ctx.moveTo(center.x, 0); + ctx.lineTo(center.x, 512); + ctx.closePath(); + ctx.stroke(); + ctx . clearRect(center.x-10,center.y-10, 20, 20); + state="on"; +} +}); +}); diff --git a/JS/em.js b/JS/em.js index d4c9334..979285e 100644 --- a/JS/em.js +++ b/JS/em.js @@ -49,27 +49,31 @@ function clickMove(direction){ console.log("movingdistance="+movingdistance); console.log("movex="+movexr); console.log("movey="+moveyr); - switch(directionSwitch){ - case "Up": + + case 'Up': moveyr = parseInt(moveyr) + (parseInt(movingdistance)); $("#movey").val(String(moveyr)); - break; + $('#movey').change(); + break; - case "Down": + case 'Down': moveyr = parseInt(moveyr) - (parseInt(movingdistance)); $("#movey").val(String(moveyr)); + $('#movey').change(); break; - case "Left": + case 'Left': movexr = parseInt(movexr) + (parseInt(movingdistance)); $("#movex").val(String(movexr)); + $('#movex').change(); break; - case "Right": + case 'Right': movexr = parseInt(movexr) - (parseInt(movingdistance)); $("#movex").val(String(movexr)); $("#currentx").val(String(movexr)); + $('#movex').change(); break; } $.ajax({ diff --git a/JS/log.js b/JS/log.js new file mode 100644 index 0000000..d35ca9a --- /dev/null +++ b/JS/log.js @@ -0,0 +1,122 @@ +//log instance +var LoadLogMemory = new LogMemory(); +var GETLogMemory = LoadLogMemory.LogMemoryInstance(); +var MemoryAll = LoadLogMemory.GETLog(); +//URL instance +var userSetting = new GetUrlElement(); +var UrlElement = userSetting.GetUrlElementInstance(); + + +/* +LogMemory() + Memory() +LogCollect() +LogSimplePhotoCondtionText() +*/ + +function LogMemory(Log){ + console.log("log"); + var arg = new Array(); + var i=0; + return { + LogMemoryInstance: function(log) { + arg[i] = log; + console.log(i); + console.log(arg[i]); + console.log(JSON.stringify(arg)); + i = i + 1; + return arg; + }, + GETLog: function(){ + var argall = ""; + for(var j=1;jhitachi

-

electron microscope name :

-

+

electron microscope name : +

+

+

em condition save

diff --git a/simplePhoto.html b/simplePhoto.html index 16ff4be..abd1c52 100644 --- a/simplePhoto.html +++ b/simplePhoto.html @@ -37,22 +37,42 @@
-
+


- +
+ +
+ +
+

+ +

+ +

X: , Y:

+

+ +

+ +

+ +
+ + +

Control Electron Microscopy

+

-
-

+

@@ -147,7 +167,7 @@    
-
+
TEM: Position:x=,y=,z=,a=
SpotSizeIndex: @@ -158,6 +178,29 @@ Speed:
+ + + +
+

Saved Coordinates

+ + + + + + + + + + + + + + + + + + @@ -167,10 +210,11 @@ + - + diff --git a/test.bat b/test.bat new file mode 100644 index 0000000..9daeafb --- /dev/null +++ b/test.bat @@ -0,0 +1 @@ +test -- 2.11.0
LM:XYEM:XY