1515
1616#include " ITStracking/TrackerTraits.h"
1717
18+ #include < algorithm>
1819#include < cassert>
1920#include < iostream>
2021
@@ -394,8 +395,13 @@ void TrackerTraits::findCellsNeighbours(const int iteration)
394395
395396 int layerCellsNum{static_cast <int >(mTimeFrame ->getCells ()[iLayer].size ())};
396397 const int nextLayerCellsNum{static_cast <int >(mTimeFrame ->getCells ()[iLayer + 1 ].size ())};
397- mTimeFrame ->getCellsNeighbours ()[iLayer].resize (nextLayerCellsNum);
398398
399+ mTimeFrame ->getCellsNeighboursLUT ()[iLayer].clear ();
400+ mTimeFrame ->getCellsNeighboursLUT ()[iLayer].resize (nextLayerCellsNum, 0 );
401+ std::vector<std::pair<int , int >> cellsNeighbours;
402+ cellsNeighbours.reserve (nextLayerCellsNum);
403+
404+ std::vector<std::vector<int >> easyWay (nextLayerCellsNum);
399405 for (int iCell{0 }; iCell < layerCellsNum; ++iCell) {
400406
401407 const Cell& currentCell{mTimeFrame ->getCells ()[iLayer][iCell]};
@@ -426,15 +432,25 @@ void TrackerTraits::findCellsNeighbours(const int iteration)
426432 continue ;
427433 }
428434
429- mTimeFrame ->getCellsNeighbours ()[iLayer][iNextCell].push_back (iCell);
430-
435+ mTimeFrame ->getCellsNeighboursLUT ()[iLayer][iNextCell]++;
436+ cellsNeighbours.push_back (std::make_pair (iCell, iNextCell));
437+ easyWay[iNextCell].push_back (iCell);
431438 const int currentCellLevel{currentCell.getLevel ()};
432439
433440 if (currentCellLevel >= nextCell.getLevel ()) {
434441 nextCell.setLevel (currentCellLevel + 1 );
435442 }
436443 }
437444 }
445+ std::sort (cellsNeighbours.begin (), cellsNeighbours.end (), [](const std::pair<int , int >& a, const std::pair<int , int >& b) {
446+ return a.second < b.second ;
447+ });
448+ mTimeFrame ->getCellsNeighbours ()[iLayer].clear ();
449+ mTimeFrame ->getCellsNeighbours ()[iLayer].reserve (cellsNeighbours.size ());
450+ for (auto & cellNeighboursIndex : cellsNeighbours) {
451+ mTimeFrame ->getCellsNeighbours ()[iLayer].push_back (cellNeighboursIndex.first );
452+ }
453+ std::inclusive_scan (mTimeFrame ->getCellsNeighboursLUT ()[iLayer].begin (), mTimeFrame ->getCellsNeighboursLUT ()[iLayer].end (), mTimeFrame ->getCellsNeighboursLUT ()[iLayer].begin ());
438454 }
439455}
440456
@@ -457,11 +473,11 @@ void TrackerTraits::findRoads(const int iteration)
457473 if (iLevel == 1 ) {
458474 continue ;
459475 }
460- const int cellNeighboursNum{ static_cast < int >(
461- mTimeFrame ->getCellsNeighbours ()[iLayer - 1 ][iCell]. size ()) };
476+ const int startNeighbourId{iCell ? mTimeFrame -> getCellsNeighboursLUT ()[iLayer - 1 ][iCell - 1 ] : 0 };
477+ const int endNeighbourId{ mTimeFrame ->getCellsNeighboursLUT ()[iLayer - 1 ][iCell]};
462478 bool isFirstValidNeighbour = true ;
463- for (int iNeighbourCell{0 }; iNeighbourCell < cellNeighboursNum ; ++iNeighbourCell) {
464- const int neighbourCellId = mTimeFrame ->getCellsNeighbours ()[iLayer - 1 ][iCell][ iNeighbourCell];
479+ for (int iNeighbourCell{startNeighbourId }; iNeighbourCell < endNeighbourId ; ++iNeighbourCell) {
480+ const int neighbourCellId = mTimeFrame ->getCellsNeighbours ()[iLayer - 1 ][iNeighbourCell];
465481 const Cell& neighbourCell = mTimeFrame ->getCells ()[iLayer - 1 ][neighbourCellId];
466482 if (iLevel - 1 != neighbourCell.getLevel ()) {
467483 continue ;
@@ -973,14 +989,11 @@ void TrackerTraits::traverseCellsTree(const int currentCellId, const int current
973989 mTimeFrame ->getRoads ().back ().addCell (currentLayerId, currentCellId);
974990
975991 if (currentLayerId > 0 && currentCellLevel > 1 ) {
976- const int cellNeighboursNum{static_cast <int >(
977- mTimeFrame ->getCellsNeighbours ()[currentLayerId - 1 ][currentCellId].size ())};
978992 bool isFirstValidNeighbour = true ;
979-
980- for (int iNeighbourCell{0 }; iNeighbourCell < cellNeighboursNum; ++iNeighbourCell) {
981-
982- const int neighbourCellId =
983- mTimeFrame ->getCellsNeighbours ()[currentLayerId - 1 ][currentCellId][iNeighbourCell];
993+ const int startNeighbourId = currentCellId ? mTimeFrame ->getCellsNeighboursLUT ()[currentLayerId - 1 ][currentCellId - 1 ] : 0 ;
994+ const int endNeighbourId = mTimeFrame ->getCellsNeighboursLUT ()[currentLayerId - 1 ][currentCellId];
995+ for (int iNeighbourCell{startNeighbourId}; iNeighbourCell < endNeighbourId; ++iNeighbourCell) {
996+ const int neighbourCellId = mTimeFrame ->getCellsNeighbours ()[currentLayerId - 1 ][iNeighbourCell];
984997 const Cell& neighbourCell = mTimeFrame ->getCells ()[currentLayerId - 1 ][neighbourCellId];
985998
986999 if (currentCellLevel - 1 != neighbourCell.getLevel ()) {
0 commit comments