57 #include <QRegularExpression>
63 using namespace UTILSLIB;
64 using namespace Eigen;
70 MatrixXf
Warp::calculate(
const MatrixXf &sLm,
const MatrixXf &dLm,
const MatrixXf &sVert)
72 MatrixXf warpWeight, polWeight;
73 calcWeighting(sLm, dLm, warpWeight, polWeight);
74 MatrixXf wVert = warpVertices(sVert, sLm, warpWeight, polWeight);
80 void Warp::calculate(
const MatrixXf & sLm,
const MatrixXf &dLm, QList<MatrixXf> & vertList)
82 MatrixXf warpWeight, polWeight;
83 calcWeighting(sLm, dLm, warpWeight, polWeight);
85 for (
int i=0; i<vertList.size(); i++)
87 vertList.replace(i,warpVertices(vertList.at(i), sLm, warpWeight, polWeight));
94 bool Warp::calcWeighting(
const MatrixXf &sLm,
const MatrixXf &dLm, MatrixXf& warpWeight, MatrixXf& polWeight)
96 MatrixXf K = MatrixXf::Zero(sLm.rows(),sLm.rows());
97 for (
int i=0; i<sLm.rows(); i++)
98 K.col(i)=((sLm.rowwise()-sLm.row(i)).rowwise().norm());
102 MatrixXf P (sLm.rows(),4);
103 P << MatrixXf::Ones(sLm.rows(),1),sLm;
106 MatrixXf L ((sLm.rows()+4),(sLm.rows()+4));
108 P.transpose(),MatrixXf::Zero(4,4);
111 MatrixXf Y ((dLm.rows()+4),3);
119 MatrixXf W ((dLm.rows()+4),3);
120 Eigen::FullPivLU <MatrixXf> Lu(L);
124 warpWeight = W.topRows(sLm.rows());
125 polWeight = W.bottomRows(4);
132 MatrixXf Warp::warpVertices(
const MatrixXf &sVert,
const MatrixXf & sLm,
const MatrixXf& warpWeight,
const MatrixXf& polWeight)
134 MatrixXf wVert = sVert * polWeight.bottomRows(3);
135 wVert.rowwise() += polWeight.row(0);
140 MatrixXf K = MatrixXf::Zero(sVert.rows(),sLm.rows());
141 for (
int i=0; i<sVert.rows(); i++)
142 K.row(i)=((sLm.rowwise()-sVert.row(i)).rowwise().norm().transpose());
145 wVert += K*warpWeight;
155 QFile file(electrodeFileName);
157 if(!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
158 qDebug()<<
"Error opening file";
163 double numberElectrodes;
164 QTextStream in(&file);
169 QString line = in.readLine();
170 QStringList fields = line.split(QRegularExpression(
"\\s+"));
173 if(fields.at(fields.size()-1) ==
"")
178 numberElectrodes = fields.at(fields.size()-1).toDouble();
179 electrodes = MatrixXf::Zero(numberElectrodes, 3);
184 x << fields.at(fields.size()-3).toFloat(),fields.at(fields.size()-2).toFloat(),fields.at(fields.size()-1).toFloat();
185 electrodes.row(i-1)=x.transpose();
197 std::ifstream inFile(electrodeFileName);
199 if(!inFile.is_open()) {
200 qDebug()<<
"Error opening file";
206 double numberElectrodes;
210 while(std::getline(inFile, line)){
211 std::vector<std::string> fields;
212 std::stringstream stream{line};
216 while(stream >> element){
217 fields.push_back(std::move(element));
223 numberElectrodes = std::stod(fields.at(fields.size()-1));
224 electrodes = MatrixXf::Zero(numberElectrodes, 3);
230 x << std::stof(fields.at(fields.size()-3)), std::stof(fields.at(fields.size()-2)), std::stof(fields.at(fields.size()-1));
231 electrodes.row(i-1)=x.transpose();