forked from alicevision/AliceVision
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOctreeTracks.cpp
More file actions
827 lines (732 loc) · 24.6 KB
/
OctreeTracks.cpp
File metadata and controls
827 lines (732 loc) · 24.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
// This file is part of the AliceVision project.
// Copyright (c) 2017 AliceVision contributors.
// This Source Code Form is subject to the terms of the Mozilla Public License,
// v. 2.0. If a copy of the MPL was not distributed with this file,
// You can obtain one at https://mozilla.org/MPL/2.0/.
#include "OctreeTracks.hpp"
#include <aliceVision/system/Logger.hpp>
#include <aliceVision/mvsData/geometry.hpp>
#include <aliceVision/mvsUtils/common.hpp>
#include <aliceVision/mvsUtils/fileIO.hpp>
#include <boost/accumulators/accumulators.hpp>
#include <boost/accumulators/statistics.hpp>
#include <iostream>
namespace aliceVision {
namespace fuseCut {
OctreeTracks::Node::Node(NodeType type)
{
type_ = type;
}
OctreeTracks::trackStruct* OctreeTracks::getTrack(int x, int y, int z)
{
if(!((x >= 0 && x < size_) && (y >= 0 && y < size_) && (z >= 0 && z < size_)))
{
return nullptr;
}
Node** n = &root_;
int size = size_;
while(size != 1)
{
if(*n == nullptr)
{
return nullptr;
}
size /= 2;
n = &reinterpret_cast<Branch*>(*n)->children[!((x & size) == 0)][!((y & size) == 0)][!((z & size) == 0)];
}
if(*n == nullptr)
{
return nullptr;
}
return reinterpret_cast<trackStruct*>(*n);
}
void OctreeTracks::addPoint(int x, int y, int z, float sim, float pixSize, Point3d& p, int rc)
{
assert(x >= 0 && x < size_);
assert(y >= 0 && y < size_);
assert(z >= 0 && z < size_);
Node** n = &root_;
int size = size_;
while(size != 1)
{
if(*n == nullptr)
{
*n = new Branch();
}
else
{
size /= 2;
n = &reinterpret_cast<Branch*>(*n)->children[!((x & size) == 0)][!((y & size) == 0)][!((z & size) == 0)];
}
}
if(*n == nullptr)
{
*n = new trackStruct(sim, pixSize, p, rc);
leafsNumber_++;
}
else
{
reinterpret_cast<trackStruct*>(*n)->addPoint(sim, pixSize, p, rc);
}
}
void OctreeTracks::addTrack(int x, int y, int z, OctreeTracks::trackStruct* t)
{
assert(x >= 0 && x < size_);
assert(y >= 0 && y < size_);
assert(z >= 0 && z < size_);
Node** n = &root_;
int size = size_;
while(size != 1)
{
if(*n == nullptr)
{
*n = new Branch();
}
else
{
size /= 2;
n = &reinterpret_cast<Branch*>(*n)->children[!((x & size) == 0)][!((y & size) == 0)][!((z & size) == 0)];
}
}
if(*n == nullptr)
{
*n = new trackStruct(t);
leafsNumber_++;
}
else
{
reinterpret_cast<trackStruct*>(*n)->addTrack(t);
}
}
StaticVector<OctreeTracks::trackStruct*>* OctreeTracks::getAllPoints()
{
StaticVector<trackStruct*>* out = new StaticVector<trackStruct*>();
out->reserve(leafsNumber_);
if(root_ != nullptr)
{
getAllPointsRecursive(out, root_);
}
return out;
}
void OctreeTracks::getAllPointsRecursive(StaticVector<trackStruct*>* out, Node* node)
{
assert(node);
switch(node->type_)
{
case BranchNode:
{
Branch* b = reinterpret_cast<Branch*>(node);
for(int i = 0; i < 2; ++i)
{
for(int j = 0; j < 2; ++j)
{
for(int k = 0; k < 2; ++k)
{
if(b->children[i][j][k] != nullptr)
{
getAllPointsRecursive(out, b->children[i][j][k]);
}
}
}
}
}
break;
case LeafNode:
out->push_back(reinterpret_cast<trackStruct*>(node));
break;
}
}
void OctreeTracks::getNPointsByLevelsRecursive(Node* node, int level, StaticVector<int>* nptsAtLevel)
{
assert(node);
switch(node->type_)
{
case BranchNode:
{
Branch* b = reinterpret_cast<Branch*>(node);
for(int i = 0; i < 2; ++i)
{
for(int j = 0; j < 2; ++j)
{
for(int k = 0; k < 2; ++k)
{
if(b->children[i][j][k] != nullptr)
{
(*nptsAtLevel)[level + 1] += 1;
getNPointsByLevelsRecursive(b->children[i][j][k], level + 1, nptsAtLevel);
}
}
}
}
}
break;
case LeafNode:
//
break;
}
}
OctreeTracks::Branch::Branch()
: Node(BranchNode)
{
for(int i = 0; i < 2; ++i)
{
for(int j = 0; j < 2; ++j)
{
for(int k = 0; k < 2; ++k)
{
children[i][j][k] = nullptr;
}
}
}
}
OctreeTracks::Branch::~Branch()
{
for(int i = 0; i < 2; ++i)
{
for(int j = 0; j < 2; ++j)
{
for(int k = 0; k < 2; ++k)
{
assert(children[i][j][k] != this);
/*
Node *node = children[i][j][k];
if (node!=NULL) {
if ( node->type_ == BranchNode ) {
delete reinterpret_cast<Branch*>(node);
}else {
if ( node->type_ == LeafNode ) {
delete reinterpret_cast<trackStruct*>(node);
}else{
printf("WARNING unknows node type\n");
};
}
node = NULL;
children[i][j][k] = NULL;
}
*/
if(children[i][j][k] != nullptr)
{
if(children[i][j][k]->type_ == BranchNode)
{
delete reinterpret_cast<Branch*>(children[i][j][k]);
}
else
{
if(children[i][j][k]->type_ == LeafNode)
{
delete reinterpret_cast<trackStruct*>(children[i][j][k]);
}
else
{
ALICEVISION_LOG_WARNING("Unknows node type.");
}
}
children[i][j][k] = nullptr;
}
}
}
}
}
OctreeTracks::trackStruct::trackStruct(float sim, float pixSize, const Point3d& p, int rc)
: Node(LeafNode)
{
npts = 1;
point = p;
cams.reserve(10);
cams.push_back(Pixel(rc, 1));
minPixSize = pixSize;
minSim = sim;
}
OctreeTracks::trackStruct::trackStruct(trackStruct* t)
: Node(LeafNode)
{
npts = t->npts;
point = t->point;
cams = t->cams;
minPixSize = t->minPixSize;
minSim = t->minSim;
}
OctreeTracks::trackStruct::~trackStruct()
{
}
void OctreeTracks::trackStruct::addPoint(float sim, float pixSize, const Point3d& p, int rc)
{
int index = indexOf(rc);
if(index == -1)
{
cams.push_back(Pixel(rc, 1));
if(cams.size() > 1)
{
qsort(&cams[0], cams.size(), sizeof(Pixel), qSortComparePixelByXAsc);
}
}
else
{
cams[index].y += 1;
}
// strategy 1: average all values
// point = (point * (float)npts + p) / (float)(npts + 1);
// minPixSize = std::min(minPixSize, pixSize);
// minSim = std::min(minSim, sim);
// npts++;
// strategy 2: keep best from nearest cam
// if (pixSize < minPixSize * 1.2f) // if equivalent or better than the previous value
//{
// if ((sim < minSim) || (pixSize * 1.2f <= minPixSize))
// {
// point = p;
// minSim = sim;
// };
// minPixSize = std::min(minPixSize,pixSize);
//};
// strategy 3: average values with good precision (precision is given by pixel size)
if(pixSize < minPixSize * 0.8f) // if strongly better => replace previous values
{
point = p;
minPixSize = pixSize;
minSim = sim;
npts = 1;
}
else if(pixSize < minPixSize * 1.2f) // if close to the previous value => average
{
// average with previous values of the same precision
point = (point * (float)npts + p) / (float)(npts + 1);
minPixSize = std::min(minPixSize, pixSize);
minSim = std::min(minSim, sim);
npts++;
}
// else don't use the position information as it is less accurate.
}
void OctreeTracks::trackStruct::addDistinctNonzeroCamsFromTrackAsZeroCams(trackStruct* t)
{
for(int i = 0; i < t->cams.size(); i++)
{
if(t->cams[i].y > 0)
{
int rc = t->cams[i].x;
int index = indexOf(rc);
if(index == -1)
{
cams.push_back(Pixel(rc, 0));
if(cams.size() > 1)
{
qsort(&cams[0], cams.size(), sizeof(Pixel), qSortComparePixelByXAsc);
}
}
}
}
}
void OctreeTracks::trackStruct::addTrack(OctreeTracks::trackStruct* t)
{
for(int i = 0; i < t->cams.size(); i++)
{
int rc = t->cams[i].x;
int index = indexOf(rc);
if(index == -1)
{
cams.push_back(t->cams[i]);
if(cams.size() > 1)
{
qsort(&cams[0], cams.size(), sizeof(Pixel), qSortComparePixelByXAsc);
}
}
else
{
cams[index].y += t->cams[i].y;
}
}
// // to keep CG
// point = (point * (float)npts + t->point * (float)t->npts) / (float)(npts + t->npts);
// minPixSize = std::min(minPixSize, t->minPixSize);
// minSim = std::min(minSim, t->minSim);
// keep best from nearest cam
// if (t->minPixSize<minPixSize*1.2f)
//{
// if ((t->minSim<minSim)||(minPixSize>t->minPixSize*1.2f))
// {
// point = t->point;
// minSim = t->minSim;
// };
// minPixSize = std::min(minPixSize,t->minPixSize);
//};
// strategy 3: average values with good precision (precision is given by pixel size)
if(t->minPixSize < minPixSize * 0.8f) // if strongly better => replace previous values
{
point = t->point;
minPixSize = t->minPixSize;
minSim = t->minSim;
npts = t->npts;
}
else if(t->minPixSize < minPixSize * 1.2f) // if close to the previous value => average
{
// average with previous values of the same precision
point = (point * (float)npts + t->point * (float)t->npts) / (float)(npts + t->npts);
minPixSize = std::min(minPixSize, t->minPixSize);
minSim = std::min(minSim, t->minSim);
npts += t->npts;
}
// else don't use the position information as it is less accurate.
}
int OctreeTracks::trackStruct::indexOf(int val)
{
if(cams.size() == 0)
{
return -1;
}
int lef = 0;
int rig = cams.size() - 1;
int mid = lef + (rig - lef) / 2;
while((rig - lef) > 1)
{
if((val >= cams[lef].x) && (val < cams[mid].x))
{
//lef = lef;
rig = mid;
mid = lef + (rig - lef) / 2;
}
if((val >= cams[mid].x) && (val <= cams[rig].x))
{
lef = mid;
//rig = rig;
mid = lef + (rig - lef) / 2;
}
if((val < cams[lef].x) || (val > cams[rig].x))
{
lef = 0;
rig = 0;
mid = 0;
}
}
int id = -1;
if(val == cams[lef].x)
{
id = lef;
}
if(val == cams[rig].x)
{
id = rig;
}
// printf("index of %f is %i\n", (float)val, id);
return id;
}
void OctreeTracks::trackStruct::doPrintf()
{
ALICEVISION_LOG_INFO("point: " << point.x << " " << point.y << " " << point.z);
ALICEVISION_LOG_INFO("ncams: " << cams.size());
for(int i = 0; i < cams.size(); i++)
ALICEVISION_LOG_INFO("\t- cam: " << i << ", rc: " << cams[i].x << ", val: " << cams[i].y);
}
OctreeTracks::OctreeTracks(const Point3d* _voxel, mvsUtils::MultiViewParams* _mp, Voxel dimensions)
: Fuser(_mp)
{
numSubVoxsX = dimensions.x;
numSubVoxsY = dimensions.y;
numSubVoxsZ = dimensions.z;
for(int i = 0; i < 8; i++)
{
vox[i] = _voxel[i];
}
O = vox[0];
vx = vox[1] - vox[0];
vy = vox[3] - vox[0];
vz = vox[4] - vox[0];
svx = vx.size();
svy = vy.size();
svz = vz.size();
vx = vx.normalize();
vy = vy.normalize();
vz = vz.normalize();
sx = svx / (float)numSubVoxsX;
sy = svy / (float)numSubVoxsY;
sz = svz / (float)numSubVoxsZ;
doFilterOctreeTracks = mp->userParams.get<bool>("LargeScale.doFilterOctreeTracks", true);
doUseWeaklySupportedPoints = mp->userParams.get<bool>("LargeScale.doUseWeaklySupportedPoints", false);
doUseWeaklySupportedPointCam = mp->userParams.get<bool>("LargeScale.doUseWeaklySupportedPointCam", false);
minNumOfConsistentCams = mp->userParams.get<int>("filter.minNumOfConsistentCams", 2);
simWspThr = (float)mp->userParams.get<double>("LargeScale.simWspThr", -0.0f);
int maxNumSubVoxs = std::max(std::max(numSubVoxsX, numSubVoxsY), numSubVoxsZ);
size_ = 2;
while(size_ < maxNumSubVoxs)
{
size_ *= 2;
}
root_ = nullptr;
leafsNumber_ = 0;
}
OctreeTracks::~OctreeTracks()
{
// printf("deleting octree\n");
if(root_ != nullptr)
{
delete reinterpret_cast<Branch*>(root_);
}
// printf("deleted\n");
}
bool OctreeTracks::getVoxelOfOctreeFor3DPoint(Voxel& out, Point3d& tp)
{
out.x = (int)floor(orientedPointPlaneDistance(tp, O, vx) / sx);
out.y = (int)floor(orientedPointPlaneDistance(tp, O, vy) / sy);
out.z = (int)floor(orientedPointPlaneDistance(tp, O, vz) / sz);
return ((out.x >= 0) && (out.x < numSubVoxsX) && (out.y >= 0) && (out.y < numSubVoxsY) && (out.z >= 0) &&
(out.z < numSubVoxsZ));
}
void OctreeTracks::filterMinNumConsistentCams(StaticVector<trackStruct*>* tracks)
{
using namespace boost::accumulators;
StaticVector<trackStruct*> tracksOut;
tracksOut.reserve(tracks->size());
typedef accumulator_set<float,
stats<
tag::min,
tag::mean,
tag::max,
tag::median(with_p_square_quantile)> > Accumulator;
Accumulator accMinPixSize;
Accumulator accMinSim;
Accumulator accNbCamsA;
Accumulator accNbCamsB;
// long t1 = initEstimate();
for(int i = 0; i < tracks->size(); i++)
{
trackStruct* t = (*tracks)[i];
accNbCamsA(t->cams.size());
if(t->cams.size() >= minNumOfConsistentCams)
{
tracksOut.push_back((*tracks)[i]);
accMinPixSize(t->minPixSize);
accMinSim(t->minSim);
accNbCamsB(t->cams.size());
} // ELSE DO NOT DELETE BECAUSE IT IS POINTER TO THE STRUCTURE
// printfEstimate(i, tracks->size(), t1);
}
// finishEstimate();
ALICEVISION_LOG_INFO("filterMinNumConsistentCams: " << std::endl
<< "\t- minPixelSize min: " << boost::accumulators::min(accMinPixSize) << ", max: " << boost::accumulators::max(accMinPixSize) << ", mean: " << boost::accumulators::mean(accMinPixSize) << ", median: " << boost::accumulators::median(accMinPixSize) << std::endl
<< "\t- minSim min: " << boost::accumulators::min(accMinSim) << ", max: " << boost::accumulators::max(accMinSim) << ", mean: " << boost::accumulators::mean(accMinSim) << ", median: " << boost::accumulators::median(accMinSim) << std::endl
<< "\t- accNbCamsA min: " << boost::accumulators::min(accNbCamsA) << ", max: " << boost::accumulators::max(accNbCamsA) << ", mean: " << boost::accumulators::mean(accNbCamsA) << ", median: " << boost::accumulators::median(accNbCamsA) << std::endl
<< "\t- accNbCamsB min: " << boost::accumulators::min(accNbCamsB) << ", max: " << boost::accumulators::max(accNbCamsB) << ", mean: " << boost::accumulators::mean(accNbCamsB) << ", median: " << boost::accumulators::median(accNbCamsB) << std::endl);
tracks->swap(tracksOut);
}
// TODO this is not working well ...
// if there are two neighbouring voxels and their representants are closer than
// 1.2 minpixsize of each of them then they must have the same set of cameras
// this should preserve the case when the density of points is smaller than sx
void OctreeTracks::updateOctreeTracksCams(StaticVector<trackStruct*>* tracks)
{
float clusterSizeThr = 1.2f;
// long t1 = initEstimate();
for(int i = 0; i < tracks->size(); i++)
{
int n = (int)ceil(((*tracks)[i]->minPixSize * clusterSizeThr) / sx);
Voxel vox;
if((n > 1) && (getVoxelOfOctreeFor3DPoint(vox, (*tracks)[i]->point)))
{
// printf("n %i\n",n);
for(int xp = -n; xp <= n; xp++)
{
for(int yp = -n; yp <= n; yp++)
{
for(int zp = -n; zp <= n; zp++)
{
if((xp == 0) && (yp == 0) && (zp == 0))
{
assert(getTrack(vox.x + xp, vox.y + yp, vox.z + zp) == (*tracks)[i]);
continue;
}
trackStruct* neighborTrack = getTrack(vox.x + xp, vox.y + yp, vox.z + zp);
if(neighborTrack != nullptr)
{
trackStruct& currentTrack = *(*tracks)[i];
const float dist = (currentTrack.point - neighborTrack->point).size();
if((dist < currentTrack.minPixSize * 1.2f) || (dist < neighborTrack->minPixSize * 1.2f))
// (nt->minPixSize < (*tracks)[i]->minPixSize * 1.2f) && ((*tracks)[i]->minPixSize < nt->minPixSize * 1.2f)
{
// currentTrack.cams
currentTrack.addDistinctNonzeroCamsFromTrackAsZeroCams(neighborTrack);
neighborTrack->addDistinctNonzeroCamsFromTrackAsZeroCams((*tracks)[i]);
}
}
}
}
}
}
}
// finishEstimate();
}
/// if there is in near distance to actual track another track that has
/// smaller enough pix size then remove the actual track
void OctreeTracks::filterOctreeTracks2(StaticVector<trackStruct*>* tracks)
{
if(mp->verbose)
ALICEVISION_LOG_DEBUG("filterOctreeTracks2");
StaticVector<trackStruct*> tracksOut;
tracksOut.reserve(tracks->size());
float clusterSizeThr = mp->userParams.get<double>("OctreeTracks.clusterSizeThr", 2.0f);
// long t1 = initEstimate();
for(int i = 0; i < tracks->size(); i++)
{
int n = (int)ceil(((*tracks)[i]->minPixSize * clusterSizeThr) / sx);
bool ok = true;
Voxel vox;
if((n > 1) && (getVoxelOfOctreeFor3DPoint(vox, (*tracks)[i]->point)))
{
// printf("n %i\n",n);
for(int xp = -n; xp <= n; xp++)
{
for(int yp = -n; yp <= n; yp++)
{
for(int zp = -n; zp <= n; zp++)
{
trackStruct* nt = getTrack(vox.x + xp, vox.y + yp, vox.z + zp);
if((xp == 0) && (yp == 0) && (zp == 0))
{
assert(nt == (*tracks)[i]);
}
else
{
if((nt != nullptr) && ((*tracks)[i]->minPixSize > nt->minPixSize * 1.2f))
{
ok = false;
}
}
}
}
}
}
if(ok)
{
tracksOut.push_back((*tracks)[i]);
} // ELSE DO NOT DELETE BECAUSE IT IS POINTER TO THE STRUCTURE
// printfEstimate(i, tracks->size(), t1);
}
// finishEstimate();
tracks->swap(tracksOut);
}
StaticVector<OctreeTracks::trackStruct*>* OctreeTracks::fillOctree(int maxPts, std::string depthMapsPtsSimsTmpDir)
{
long t1 = clock();
StaticVector<int> cams = mp->findCamsWhichIntersectsHexahedron(vox, depthMapsPtsSimsTmpDir + "minMaxDepths.bin");
if(mp->verbose)
mvsUtils::printfElapsedTime(t1, "findCamsWhichIntersectsHexahedron");
if(mp->verbose)
ALICEVISION_LOG_DEBUG("ncams: " << cams.size());
t1 = clock();
// long t1=initEstimate();
for(int camid = 0; camid < cams.size(); camid++)
{
int rc = cams[camid];
StaticVector<Point3d>* pts =
loadArrayFromFile<Point3d>(depthMapsPtsSimsTmpDir + std::to_string(mp->getViewId(rc)) + "pts.bin");
StaticVector<float>* sims =
loadArrayFromFile<float>(depthMapsPtsSimsTmpDir + std::to_string(mp->getViewId(rc)) + "sims.bin");
// long tpts=initEstimate();
for(int i = 0; i < pts->size(); i++)
{
float sim = (*sims)[i];
Point3d p = (*pts)[i];
Voxel otVox;
if(((doUseWeaklySupportedPoints) || (sim < simWspThr)) && (getVoxelOfOctreeFor3DPoint(otVox, p))) // doUseWeaklySupportedPoints: false by default
{
if(doUseWeaklySupportedPointCam)
{
if(sim > 1.0f)
{
sim -= 2.0f;
}
}
float pixSize = mp->getCamPixelSize(p, rc);
addPoint(otVox.x, otVox.y, otVox.z, sim, pixSize, p, rc);
}
if(leafsNumber_ > 2 * maxPts)
{
return nullptr;
}
// printfEstimate(i, pts->size(), tpts);
} // for i
// finishEstimate();
delete pts;
delete sims;
// printfEstimate(camid, cams.size(), t1);
}
// finishEstimate();
StaticVector<trackStruct*>* tracks = getAllPoints();
if(mp->verbose)
mvsUtils::printfElapsedTime(t1, "fillOctree fill");
// TODO this is not working well ...
// updateOctreeTracksCams(tracks);
// if (mp->verbose) printfElapsedTime(t1,"updateOctreeTracksCams");
if(doFilterOctreeTracks)
{
if(mp->verbose)
ALICEVISION_LOG_DEBUG("# tracks before filtering: " << tracks->size());
long t2 = clock();
filterMinNumConsistentCams(tracks);
if(mp->verbose)
mvsUtils::printfElapsedTime(t2, "filterMinNumConsistentCams");
if(mp->verbose)
ALICEVISION_LOG_DEBUG("# tracks after filterMinNumConsistentCams: " << tracks->size());
t2 = clock();
// filter cameras observations that have a large pixelSize regarding the others
filterOctreeTracks2(tracks);
if(mp->verbose)
mvsUtils::printfElapsedTime(t2, "filterOctreeTracks2");
if(mp->verbose)
ALICEVISION_LOG_DEBUG("# tracks after filterOctreeTracks2: " << tracks->size());
if(mp->verbose)
ALICEVISION_LOG_DEBUG("# tracks after filtering: " << tracks->size());
}
if(tracks->size() > maxPts)
{
if(mp->verbose)
ALICEVISION_LOG_DEBUG("Too much tracks (" << tracks->size() << "), clear all.");
delete tracks; // DO NOT DELETE POINTER JUST DELETE THE ARRAY!!!
return nullptr;
}
if(mp->verbose)
ALICEVISION_LOG_DEBUG("number of tracks: " << tracks->size());
return tracks;
}
StaticVector<OctreeTracks::trackStruct*>*
OctreeTracks::fillOctreeFromTracks(StaticVector<OctreeTracks::trackStruct*>* tracksIn)
{
long t1 = clock();
for(int i = 0; i < tracksIn->size(); i++)
{
trackStruct* t = (*tracksIn)[i];
Voxel otVox;
if(getVoxelOfOctreeFor3DPoint(otVox, t->point))
{
addTrack(otVox.x, otVox.y, otVox.z, t);
}
} // for i
StaticVector<trackStruct*>* tracks = getAllPoints();
if(mp->verbose)
mvsUtils::printfElapsedTime(t1, "fillOctreeFromTracks");
return tracks;
}
StaticVector<int>* OctreeTracks::getTracksCams(StaticVector<OctreeTracks::trackStruct*>* tracks)
{
StaticVectorBool* camsb = new StaticVectorBool();
camsb->reserve(mp->ncams);
camsb->resize_with(mp->ncams, false);
for(int i = 0; i < tracks->size(); i++)
{
for(int c = 0; c < (*tracks)[i]->cams.size(); c++)
{
(*camsb)[(*tracks)[i]->cams[c].x] = true;
}
}
StaticVector<int>* cams = new StaticVector<int>();
cams->reserve(mp->ncams);
for(int i = 0; i < mp->ncams; i++)
{
if((*camsb)[i])
{
cams->push_back(i);
}
}
delete camsb;
return cams;
}
} // namespace fuseCut
} // namespace aliceVision