Commit 583463e8 authored by Oleg Dzhimiev's avatar Oleg Dzhimiev

1. matching function 2. partial derivs for rotation matrix

parent b6eab19c
......@@ -426,6 +426,6 @@ html, body, #x3d_wrapper {
text-align:right;
}
#mpr_save, #mpr_save_marks{
#mpr_save, #mpr_save_marks,#mpr_match{
margin: 0px 5px 5px 5px;
}
......@@ -94,6 +94,7 @@ function manualposor_init(){
'<div>',
' <div><button id=\'mpr_save\'>save kmls</button></div>',
' <div><button id=\'mpr_save_marks\' title=\'save to file\' >save marks</button></div>',
' <div><button id=\'mpr_match\' title=\'run models matching algorithm\' >Match models</button></div>',
'</div>',
].join('\n'));
......@@ -212,12 +213,18 @@ function manualposor_init(){
});
$("#mpr_match").on('click',function(){
x3dom_align_models();
});
}
function mpr_marks_load(){
$.ajax({
url: [SETTINGS.basepath,SETTINGS.path,"marks.xml"].join("/"),
success: function(response){
$(response).find("record").each(function(){
......@@ -229,20 +236,28 @@ function mpr_marks_load(){
var p1 = $(marks[0]).attr("position").split(",");
var p1l = new x3dom.fields.SFVec3f(p1[0],p1[1],p1[2]);
var c1 = $(marks[0]).attr("camera").split(",");
var c1l = new x3dom.fields.SFVec3f(c1[0],c1[1],c1[2]);
var name2 = $(marks[1]).attr("model");
var p2 = $(marks[1]).attr("position").split(",");
var p2l = new x3dom.fields.SFVec3f(p2[0],p2[1],p2[2]);
var c2 = $(marks[1]).attr("camera").split(",");
var c2l = new x3dom.fields.SFVec3f(c2[0],c2[1],c2[2]);
// local position is constant
Data.mpr.markers.push({
uid: uid,
m1:{
name: name1,
position: p1l
position: p1l,
camera: c1l
},
m2:{
name: name2,
position: p2l
position: p2l,
camera: c2l
}
});
......@@ -251,9 +266,17 @@ function mpr_marks_load(){
MPR_MARKS_LOADED = true;
},
error: function(response){
if (response.status==200){
this.success(response.responseText);
}else{
console.log("mpr markers failed");
}
MPR_MARKS_LOADED = true;
}
});
}
......@@ -900,13 +923,18 @@ function manualposor_newMarksPair(ray1,ray2){
var size = 1*SETTINGS.markersize_k*d;
var color = x3dom_autocolor();
var vmat = Scene.element.runtime.viewMatrix().inverse();
var camera = vmat.e3();
var target1 = $("inline[name=x3d_"+name1+"]");
var m = x3dom_getTransorm_from_2_parents(target1);
var p1l = m.inverse().multMatrixVec(p1);
var c1l = m.inverse().multMatrixVec(camera);
var target2 = $("inline[name=x3d_"+name2+"]");
m = x3dom_getTransorm_from_2_parents(target2);
var p2l = m.inverse().multMatrixVec(p2);
var c2l = m.inverse().multMatrixVec(camera);
new MPRMarker({target:target1.parent(), uid:uid, model:name1, position:p1l, size: size, color: color});
new MPRMarker({target:target2.parent(), uid:uid, model:name2, position:p2l, size: size, color: color});
......@@ -916,11 +944,13 @@ function manualposor_newMarksPair(ray1,ray2){
uid: uid,
m1:{
name: name1,
position: p1l
position: p1l,
camera: c1l
},
m2:{
name: name2,
position: p2l
position: p2l,
camera: c2l
}
});
......@@ -1032,8 +1062,8 @@ function mpr_markers_to_xml(){
str[i] = [
' <record uid=\''+rec.uid+'\'>',
' <mark model=\''+rec.m1.name+'\' position=\''+rec.m1.position.x+','+rec.m1.position.y+','+rec.m1.position.z+'\'></mark>',
' <mark model=\''+rec.m2.name+'\' position=\''+rec.m2.position.x+','+rec.m2.position.y+','+rec.m2.position.z+'\'></mark>',
' <mark model=\''+rec.m1.name+'\' position=\''+rec.m1.position.x+','+rec.m1.position.y+','+rec.m1.position.z+'\' camera=\''+rec.m1.camera.x+','+rec.m1.camera.y+','+rec.m1.camera.z+'\'></mark>',
' <mark model=\''+rec.m2.name+'\' position=\''+rec.m2.position.x+','+rec.m2.position.y+','+rec.m2.position.z+'\' camera=\''+rec.m2.camera.x+','+rec.m2.camera.y+','+rec.m2.camera.z+'\'></mark>',
' </record>'
].join("\n");
......
function x3dom_align_models(){
// do models have to loaded?
var marks = Data.mpr.markers;
for(var i=0;i<marks.length;i++){
console.log("Marks pair # "+i);
var mark = marks[i];
var inline1 = $('inline[name=x3d_'+mark.m1.name+']');
var inline2 = $('inline[name=x3d_'+mark.m2.name+']');
if((inline1.length!=0)&&(inline2.length!=0)){
var p1_1 = mark.m1.position;
var p2_2 = mark.m2.position;
var c1 = mark.m1.camera;
var c2 = mark.m2.camera;
var m1 = x3dom_getTransorm_from_2_parents(inline1);
var m2 = x3dom_getTransorm_from_2_parents(inline2);
// from inline2 to inline1
var m = m1.inverse().mult(m2);
// p2 in inline1's coordinates
var p2_1 = m.multMatrixVec(p2_2);
var v1 = p1_1.subtract(c1);
var v2 = p2_1.subtract(c1);
var vcro = v1.cross(v2);
var vsca = v1.dot(v2);
console.log(" before scaling:"+vcro.toString());
console.log(" scalar product:"+vsca);
vcro = vcro.multiply(1/vsca);
console.log(" after scaling:"+vcro.toString());
console.log(" length:"+vcro.length());
// // from inline1 to inline2
// m = m.inverse();
// // p1 in inline2's coordinates
// var p1_2 = m.multMatrixVec(p1_1);
//
// var v1 = p1_2.subtract(c2);
// var v2 = p2_2.subtract(c2);
// var vcro = v1.cross(v2);
// var vsca = v1.dot(v2);
// console.log(" before scaling:"+vcro.toString());
// console.log(" scalar product:"+vsca);
// vcro = vcro.multiply(1/vsca);
// console.log(" after scaling:"+vcro.toString());
// console.log(" length:"+vcro.length());
}
}
}
function mpr_R(d){
var sin = Math.sin;
var cos = Math.cos;
var _00 = sin(d.psi)*sin(d.theta)*sin(d.phi)+cos(d.psi)*cos(d.phi);
var _01 = -sin(d.psi)*sin(d.theta)*cos(d.phi)+cos(d.psi)*sin(d.phi);
var _02 = -sin(d.psi)*cos(d.theta);
var _03 = -d.x;
var _10 = -cos(d.theta)*sin(d.phi);
var _11 = cos(d.theta)*cos(d.phi);
var _12 = -sin(d.theta);
var _13 = -d.y;
var _20 = -cos(d.psi)*sin(d.theta)*sin(d.phi)+sin(d.psi)*cos(d.phi);
var _21 = cos(d.psi)*sin(d.theta)*cos(d.phi)+sin(d.psi)*sin(d.phi);
var _22 = cos(d.psi)*cos(d.theta);
var _23 = -d.z;
var _30 = 0;
var _31 = 0;
var _32 = 0;
var _33 = 1;
var m = new x3dom.fields.SFMatrix4f(
_00, _01, _02, _03,
_10, _11, _12, _13,
_20, _21, _22, _23,
_30, _31, _32, _33
);
return m;
}
function mpr_dR_dpsi(d){
var sin = Math.sin;
var cos = Math.cos;
var _00 = cos(d.psi)*sin(d.theta)*sin(d.phi)-sin(d.psi)*cos(d.phi);
var _01 = -cos(d.psi)*sin(d.theta)*cos(d.phi)-sin(d.psi)*sin(d.phi);
var _02 = -cos(d.psi)*cos(d.theta);
var _03 = 0;
var _10 = 0;
var _11 = 0;
var _12 = 0;
var _13 = 0;
var _20 = sin(d.psi)*sin(d.theta)*sin(d.phi)+cos(d.psi)*cos(d.phi);
var _21 = -sin(d.psi)*sin(d.theta)*cos(d.phi)+cos(d.psi)*sin(d.phi);
var _22 = -sin(d.psi)*cos(d.theta);
var _23 = 0;
var _30 = 0;
var _31 = 0;
var _32 = 0;
var _33 = 0;
var m = new x3dom.fields.SFMatrix4f(
_00, _01, _02, _03,
_10, _11, _12, _13,
_20, _21, _22, _23,
_30, _31, _32, _33
);
return m;
}
function mpr_dR_dtheta(d){
var sin = Math.sin;
var cos = Math.cos;
var _00 = sin(d.psi)*cos(d.theta)*sin(d.phi);
var _01 = -sin(d.psi)*cos(d.theta)*cos(d.phi);
var _02 = sin(d.psi)*sin(d.theta);
var _03 = 0;
var _10 = sin(d.theta)*sin(d.phi);
var _11 = -sin(d.theta)*cos(d.phi);
var _12 = -cos(d.theta);
var _13 = 0;
var _20 = -cos(d.psi)*cos(d.theta)*sin(d.phi);
var _21 = cos(d.psi)*cos(d.theta)*cos(d.phi);
var _22 = -cos(d.psi)*sin(d.theta);
var _23 = 0;
var _30 = 0;
var _31 = 0;
var _32 = 0;
var _33 = 0;
var m = new x3dom.fields.SFMatrix4f(
_00, _01, _02, _03,
_10, _11, _12, _13,
_20, _21, _22, _23,
_30, _31, _32, _33
);
return m;
}
function mpr_dR_dphi(d){
var sin = Math.sin;
var cos = Math.cos;
var _00 = sin(d.psi)*sin(d.theta)*cos(d.phi)-cos(d.psi)*sin(d.phi);
var _01 = sin(d.psi)*sin(d.theta)*sin(d.phi)+cos(d.psi)*cos(d.phi);
var _02 = 0;
var _03 = 0;
var _10 = -cos(d.theta)*cos(d.phi);
var _11 = -cos(d.theta)*sin(d.phi);
var _12 = 0;
var _13 = 0;
var _20 = -cos(d.psi)*sin(d.theta)*cos(d.phi)-sin(d.psi)*sin(d.phi);
var _21 = -cos(d.psi)*sin(d.theta)*sin(d.phi)+sin(d.psi)*cos(d.phi);
var _22 = 0;
var _23 = 0;
var _30 = 0;
var _31 = 0;
var _32 = 0;
var _33 = 0;
var m = new x3dom.fields.SFMatrix4f(
_00, _01, _02, _03,
_10, _11, _12, _13,
_20, _21, _22, _23,
_30, _31, _32, _33
);
return m;
}
......@@ -447,6 +447,8 @@ function deep_init(){
if (SETTINGS.manualposor){
if (!MPR_MARKS_LOADED) mpr_marks_load();
manualposor_shootrays();
manualposor_rotate_glued();
......@@ -468,7 +470,7 @@ function deep_init(){
x3d_setShiftSpeed();
if (!MPR_MARKS_LOADED) mpr_marks_load();
//if (!MPR_MARKS_LOADED) mpr_marks_load();
}
// loading extra models?
......
......@@ -42,6 +42,7 @@
<script type='text/javascript' src='js/ui_functions.js'></script>
<script type='text/javascript' src='js/ui_align.js'></script>
<script type='text/javascript' src='js/ui_extra_models.js'></script>
<script type='text/javascript' src='js/ui_extra_models_match.js'></script>
<script type='text/javascript' src='js/align_functions.js'></script>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment