56 #include <QtConcurrent/QtConcurrent>
66 using namespace DISP3DLIB;
67 using namespace Eigen;
68 using namespace FIFFLIB;
79 const QVector<QVector<int> > &vecNeighborVertices,
80 QVector<int> &vecVertSubset,
84 qint32 iCols = vecVertSubset.size();
85 if(vecVertSubset.empty()) {
87 qDebug() <<
"[WARNING] SCDC received empty subset, calculating full distance table, make sure you have enough memory !";
88 vecVertSubset.reserve(matVertices.rows());
89 for(qint32
id = 0;
id < matVertices.rows(); ++id) {
90 vecVertSubset.push_back(
id);
92 iCols = matVertices.rows();
96 QSharedPointer<MatrixXd> returnMat = QSharedPointer<MatrixXd>::create(matVertices.rows(), iCols);
99 int iCores = QThread::idealThreadCount();
106 qint32 iSubArraySize = int(
double(vecVertSubset.size()) /
double(iCores));
107 QVector<QFuture<void> > vecThreads(iCores);
109 qint32 iEnd = iSubArraySize;
111 for (
int i = 0; i < vecThreads.size(); ++i) {
113 if(i == vecThreads.size()-1)
115 vecThreads[i] = QtConcurrent::run(std::bind(iterativeDijkstra,
117 std::cref(matVertices),
118 std::cref(vecNeighborVertices),
119 std::cref(vecVertSubset),
121 vecVertSubset.size(),
127 vecThreads[i] = QtConcurrent::run(std::bind(iterativeDijkstra,
129 std::cref(matVertices),
130 std::cref(vecNeighborVertices),
131 std::cref(vecVertSubset),
135 iBegin += iSubArraySize;
136 iEnd += iSubArraySize;
141 for (QFuture<void>& f : vecThreads) {
151 const QVector<Vector3f> &vecSensorPositions)
153 QVector<int> vecOutputArray;
155 qint32 iCores = QThread::idealThreadCount();
162 const qint32 iSubArraySize = int(
double(vecSensorPositions.size()) /
double(iCores));
165 if(iSubArraySize <= 1)
167 vecOutputArray.append(nearestNeighbor(matVertices,
168 vecSensorPositions.constBegin(),
169 vecSensorPositions.constEnd()));
170 return vecOutputArray;
174 QVector<QFuture<QVector<int> > > vecThreads(iCores);
175 qint32 iBeginOffset = 0;
176 qint32 iEndOffset = iBeginOffset + iSubArraySize;
177 for(qint32 i = 0; i < vecThreads.size(); ++i)
180 if(i == vecThreads.size()-1)
182 vecThreads[i] = QtConcurrent::run(nearestNeighbor,
184 vecSensorPositions.constBegin() + iBeginOffset,
185 vecSensorPositions.constEnd());
190 vecThreads[i] = QtConcurrent::run(nearestNeighbor,
192 vecSensorPositions.constBegin() + iBeginOffset,
193 vecSensorPositions.constBegin() + iEndOffset);
194 iBeginOffset = iEndOffset;
195 iEndOffset += iSubArraySize;
200 for (QFuture<QVector<int> >& f : vecThreads) {
205 for(qint32 i = 0; i < vecThreads.size(); ++i)
207 vecOutputArray.append(std::move(vecThreads[i].result()));
210 return vecOutputArray;
216 QVector<Vector3f>::const_iterator itSensorBegin,
217 QVector<Vector3f>::const_iterator itSensorEnd)
220 QVector<int> vecMappedSensors;
221 vecMappedSensors.reserve(std::distance(itSensorBegin, itSensorEnd));
223 for(
auto sensor = itSensorBegin; sensor != itSensorEnd; ++sensor)
226 double iChampDist = std::numeric_limits<double>::max();
227 for(qint32 i = 0; i < matVertices.rows(); ++i)
230 double dDist = sqrt(squared(matVertices(i, 0) - (*sensor)[0])
231 + squared(matVertices(i, 1) - (*sensor)[1])
232 + squared(matVertices(i, 2) - (*sensor)[2]));
233 if(dDist < iChampDist)
240 vecMappedSensors.push_back(iChampionId);
243 return vecMappedSensors;
249 const MatrixX3f &matVertices,
250 const QVector<QVector<int> > &vecNeighborVertices,
251 const QVector<int> &vecVertSubset,
254 double dCancelDistance) {
256 const QVector<QVector<int> > &vecAdjacency = vecNeighborVertices;
257 qint32 n = vecAdjacency.size();
258 QVector<double> vecMinDists(n);
259 std::set< std::pair< double, qint32> > vertexQ;
260 const double INF = FLOAT_INFINITY;
263 for (qint32 i = iBegin; i < iEnd; ++i) {
266 qDebug() <<
"blabla";
267 qint32 iRoot = vecVertSubset.at(i);
269 vecMinDists.fill(INF);
270 vecMinDists[iRoot] = 0.0;
271 vertexQ.insert(std::make_pair(vecMinDists[iRoot], iRoot));
274 while (vertexQ.empty() ==
false) {
276 const double dDist = vertexQ.begin()->first;
277 const qint32 u = vertexQ.begin()->second;
278 vertexQ.erase(vertexQ.begin());
281 if (dDist <= dCancelDistance) {
283 const QVector<int>& vecNeighbours = vecAdjacency[u];
285 for (qint32 ne = 0; ne < vecNeighbours.length(); ++ne) {
286 qint32 v = vecNeighbours[ne];
290 const double dDistX = matVertices(u, 0) - matVertices(v, 0);
291 const double dDistY = matVertices(u, 1) - matVertices(v, 1);
292 const double dDistZ = matVertices(u, 2) - matVertices(v, 2);
293 const double dDistWithU = dDist + sqrt(dDistX * dDistX + dDistY * dDistY + dDistZ * dDistZ);
295 if (dDistWithU < vecMinDists[v]) {
297 vertexQ.erase(std::make_pair(vecMinDists[v], v));
298 vecMinDists[v] = dDistWithU;
299 vertexQ.insert(std::make_pair(vecMinDists[v], v));
306 for (qint32 m = 0; m < vecMinDists.size(); ++m) {
307 matOutputDistMatrix->coeffRef(m , i) = vecMinDists[m];
316 qint32 iSensorType) {
318 QVector<int> vecBadColumns;
319 QVector<const FiffChInfo*> vecSensors;
322 if(s.
kind == iSensorType && (s.
unit == FIFF_UNIT_T || s.
unit == FIFF_UNIT_V)){
323 vecSensors.push_back(&s);
328 for(
const QString& b : fiffInfo.
bads){
329 for(
int col = 0; col < vecSensors.size(); ++col){
330 if(vecSensors[col]->ch_name == b){
332 vecBadColumns.push_back(col);
333 for(
int row = 0; row < matDistanceTable->rows(); ++row){
334 matDistanceTable->coeffRef(row, col) = FLOAT_INFINITY;
340 return vecBadColumns;