@@ -142,7 +142,7 @@ int Octree::debugStructure(const int& depth) const
142142// / </summary>
143143// / <param name="position"></param>
144144// / <param name="indices">Vector to which the sorted indexes will be appened.</param>
145- void Octree::getSortedIndices (const QVector3D& position, std::vector<GLuint>& indices)
145+ void Octree::getSortedIndicesUsingCubes (const QVector3D& position, std::vector<GLuint>& indices)
146146{
147147 if (contained.size () > 0 ) {
148148 /* for (GLuint index : contained) {
@@ -186,7 +186,7 @@ void Octree::getSortedIndices(const QVector3D& position, std::vector<GLuint>& in
186186
187187 for (int index : orderedChildren) {
188188 if (children[index] != nullptr ) {
189- children[index]->getSortedIndices (position, indices);
189+ children[index]->getSortedIndicesUsingCubes (position, indices);
190190 }
191191 }
192192
@@ -205,12 +205,15 @@ WorkerThread::WorkerThread(
205205 QObject* parent = nullptr ,
206206 std::vector<std::vector<GLuint>>* inds = nullptr ,
207207 std::vector<float > pts = std::vector<float >(0 ),
208- std::vector<QVector3D>* cams = nullptr
209- ) : QThread(parent) {
208+ std::vector<QMatrix4x4>* camMatrices = nullptr
209+ ) : QThread(parent),
210+ previousCameraSide(std::vector<int >(camMatrices->size (), 0)),
211+ sliceSorts(std::vector<std::vector<GLuint>>(3 , std::vector<GLuint>(0 )))
212+ {
210213 indices = inds;
211214 points = pts;
212215 // Camera position relative to the cloud of points
213- camPos = cams ;
216+ cams = camMatrices ;
214217
215218 std::vector<GLuint> allIndices = std::vector<GLuint>(points.size () / 3 );
216219
@@ -228,6 +231,37 @@ WorkerThread::WorkerThread(
228231 // int treeSize = pointTree->debugStructure();
229232 // qDebug() << "Tree size " << treeSize;
230233 // qDebug() << "Indices size " << indices->size();
234+
235+ // Create the slice sorts
236+ for (int side = 0 ; side < 3 ; side++) {
237+ qDebug () << " Cretating slices for side : " << side;
238+ clock_t start = clock ();
239+ int nSlices = 100 ;
240+ float coordmin = -1 .f ;
241+ float coordmax = 1 .f ;
242+
243+ for (int k = 0 ; k < points.size () / 3 ; k++) {
244+ if (points[3 * k + side] < coordmin) {
245+ coordmin = points[3 * k + dataAxesConversion[side]] - 0 .1f ;
246+ }
247+ if (points[3 * k + side] > coordmax) {
248+ coordmax = points[3 * k + dataAxesConversion[side]] + 0 .1f ;
249+ }
250+ }
251+ for (int slice = 0 ; slice < nSlices; slice++) {
252+ for (int k = 0 ; k < points.size () / 3 ; k++) {
253+
254+ if (
255+ points[3 * k + dataAxesConversion[side]] >= coordmin + (coordmax - coordmin) * slice / nSlices
256+ && points[3 * k + dataAxesConversion[side]] < coordmin + (coordmax - coordmin) * (slice + 1 ) / nSlices
257+ ) {
258+ sliceSorts[side].push_back (k);
259+ }
260+
261+ }
262+ }
263+ qDebug () << " Cretated slices for side : " << side << " , in " << clock () - start;
264+ }
231265}
232266
233267WorkerThread::~WorkerThread () {
@@ -244,7 +278,7 @@ void WorkerThread::run() {
244278 while (true ) {
245279 for (int i = 0 ; i < 2 ; i++) {
246280 if (
247- (camPos-> at (i) - previousCameras[i]).length () > 0.01
281+ (getCamPos (i) - previousCameras[i]).length () > 0 .01f
248282 && clock () - start[i] > 0 .05f * CLOCKS_PER_SEC
249283 ) {
250284 start[i] = clock ();
@@ -262,19 +296,21 @@ void WorkerThread::run() {
262296 });*/
263297 // Bruteforce method - END
264298
265- // Octree based method
266- localIndices[i].clear ();
267- pointTree->getSortedIndices (camPos->at (i), localIndices[i]);
268- // Octree based method - END
299+ // // Octree based method
300+ // localIndices[i].clear();
301+ // pointTree->getSortedIndicesUsingCubes (camPos->at(i), localIndices[i]);
302+ // // Octree based method - END
269303
270- std::mutex mtx;
271- mtx.lock ();
272- indices->at (i).assign (localIndices[i].begin (), localIndices[i].end ());
273- mtx.unlock ();
304+ // std::mutex mtx;
305+ // mtx.lock();
306+ // indices->at(i).assign(localIndices[i].begin(), localIndices[i].end());
307+ // mtx.unlock();
308+ // emit resultReady(i);
274309
275- emit resultReady (i );
310+ sliceSort ( );
276311
277- previousCameras[i] = camPos->at (i);
312+
313+ previousCameras[i] = getCamPos (i);
278314
279315 }
280316
@@ -285,3 +321,38 @@ void WorkerThread::run() {
285321}
286322
287323
324+
325+ void WorkerThread::sliceSort () {
326+ std::vector<int > cameraSide = std::vector<int >(2 , 0 );
327+ // Determine f the front facing side has changed for each amera
328+ for (int cam = 0 ; cam < cameraSide.size (); cam++) {
329+ float biggestComponentValue = 0 ;
330+ for (int i = 0 ; i < 3 ; i++) {
331+ QVector3D unitVector = QVector3D (0 ,0 ,0 );
332+ unitVector[i] = 1 .0f ;
333+ float component = QVector3D::dotProduct (getCamDir (cam), unitVector);
334+ if (abs (component) >= biggestComponentValue) {
335+ cameraSide[cam] = i+1 ;
336+ if (component < 0 ) cameraSide[cam] *= -1 ;
337+ biggestComponentValue = abs (component);
338+ }
339+ }
340+ if (cameraSide[cam] != previousCameraSide[cam]) {
341+ qDebug () << " Cam dir" << getCamDir (cam);
342+ qDebug () << " Detected change in face on camera : " << cam << " , setting new face : " << cameraSide[cam];
343+ std::mutex mtx;
344+ mtx.lock ();
345+ qDebug () << abs (cameraSide[cam]) - 1 ;
346+ indices->at (cam).clear ();
347+ indices->at (cam).assign (sliceSorts[abs (cameraSide[cam]) - 1 ].begin (), sliceSorts[abs (cameraSide[cam]) - 1 ].end ());
348+ if (cameraSide[cam] < 0 ) {
349+ std::reverse (indices->at (cam).begin (), indices->at (cam).end ());
350+ }
351+ mtx.unlock ();
352+
353+ emit resultReady (cam);
354+ previousCameraSide[cam] = cameraSide[cam];
355+ }
356+ }
357+
358+ }
0 commit comments