49 #define _USE_MATH_DEFINES
56 #include <Eigen/Dense>
62 using namespace FIFFLIB;
63 using namespace Eigen;
72 , trans(MatrixXf::Identity(4,4))
73 , invtrans(MatrixXf::Identity(4,4))
82 , trans(MatrixXf::Identity(4,4))
83 , invtrans(MatrixXf::Identity(4,4))
85 if(!
read(p_IODevice, *
this))
87 printf(
"\tCoordindate transform not found.\n");
95 : from(p_FiffCoordTrans.from)
96 , to(p_FiffCoordTrans.to)
97 , trans(p_FiffCoordTrans.trans)
98 , invtrans(p_FiffCoordTrans.invtrans)
122 fiff_int_t from_new = this->
to;
124 this->
from = from_new;
137 printf(
"Reading coordinate transform from %s...\n", pStream->streamName().toUtf8().constData());
145 bool success =
false;
150 for ( qint32
k = 0;
k < pStream->dir().size(); ++
k )
154 pStream->read_tag(t_pTag,pStream->dir()[
k]->pos);
155 p_Trans = t_pTag->toCoordTrans();
169 printf(
"Write coordinate transform in %s...\n", pStream->streamName().toUtf8().constData());
186 MatrixX4f rr_ones = do_move ? MatrixX4f::Ones(rr.rows(),4) : MatrixX4f::Zero(rr.rows(),4);
187 rr_ones.block(0,0,rr.rows(),3) = rr;
188 return rr_ones*
trans.block<3,4>(0,0).transpose();
195 MatrixX4f rr_ones = do_move ? MatrixX4f::Ones(rr.rows(),4) : MatrixX4f::Zero(rr.rows(),4);
196 rr_ones.block(0,0,rr.rows(),3) = rr;
197 return rr_ones*
invtrans.block<3,4>(0,0).transpose();
205 case FIFFV_COORD_UNKNOWN:
return "unknown";
206 case FIFFV_COORD_DEVICE:
return "MEG device";
207 case FIFFV_COORD_ISOTRAK:
return "isotrak";
208 case FIFFV_COORD_HPI:
return "hpi";
209 case FIFFV_COORD_HEAD:
return "head";
210 case FIFFV_COORD_MRI:
return "MRI (surface RAS)";
212 case FIFFV_COORD_MRI_SLICE:
return "MRI slice";
213 case FIFFV_COORD_MRI_DISPLAY:
return "MRI display";
220 default:
return "unknown";
229 t.
trans = MatrixXf::Zero(4,4);
234 t.
trans.block<3,3>(0,0) = rot;
235 t.
trans.block<3,1>(0,3) = move;
255 t.
trans.row(3) = Vector4f(0,0,0,1);
275 std::cout <<
"Coordinate transformation: ";
276 std::cout << (QString(
"%1 -> %2\n").arg(
frame_name(this->from)).arg(
frame_name(this->to))).toUtf8().data();
278 for (
int p = 0; p < 3; p++)
279 printf(
"\t% 8.6f % 8.6f % 8.6f\t% 7.2f mm\n",
trans(p,0),
trans(p,1),
trans(p,2),1000*
trans(p,3));
287 MatrixX4f mDevHeadT = this->
trans;
288 Matrix3f mRot = mDevHeadT.block(0,0,3,3);
289 Matrix3f mRotNew = mTransDest.block(0,0,3,3);
291 Quaternionf quat(mRot);
292 Quaternionf quatNew(mRotNew);
297 Quaternionf quatCompare;
299 quatCompare = quat*quatNew.inverse();
300 fAngle = quat.angularDistance(quatNew);
301 fAngle = fAngle * 180 / M_PI;
310 VectorXf vTrans = this->
trans.col(3);
311 VectorXf vTransDest = mTransDest.col(3);
313 float fMove = (vTrans-vTransDest).norm();
324 tOld.
rot = this->
trans.block(0,0,3,3);