Skip to content

Commit 3ae1b80

Browse files
Fabien Servantcbentejac
authored andcommitted
move boxstats out of numeric header
1 parent 3eb9554 commit 3ae1b80

File tree

9 files changed

+94
-66
lines changed

9 files changed

+94
-66
lines changed

src/aliceVision/multiview/rotationAveraging/l1.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
#include "ceres/ceres.h"
3030
#include "ceres/rotation.h"
3131

32+
#include <aliceVision/numeric/BoxStats.hpp>
33+
3234
#include <map>
3335
#include <queue>
3436
#include <stdint.h>
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
// This file is part of the AliceVision project.
2+
// Copyright (c) 2024 AliceVision contributors.
3+
// Copyright (c) 2012 openMVG contributors.
4+
// This Source Code Form is subject to the terms of the Mozilla Public License,
5+
// v. 2.0. If a copy of the MPL was not distributed with this file,
6+
// You can obtain one at https://mozilla.org/MPL/2.0/.
7+
8+
#pragma once
9+
10+
11+
#include <algorithm>
12+
#include <cmath>
13+
#include <numeric>
14+
#include <string>
15+
#include <iostream>
16+
#include <vector>
17+
18+
namespace aliceVision {
19+
20+
21+
/** Get back the min, mean, median and the max
22+
* values of an iterable sequence.
23+
*/
24+
template<typename Type>
25+
struct BoxStats
26+
{
27+
Type min{}, max{}, mean{}, median{}, firstQuartile{}, thirdQuartile{};
28+
29+
BoxStats() = default;
30+
31+
template<typename DataInputIterator>
32+
BoxStats(DataInputIterator begin, DataInputIterator end)
33+
{
34+
compute(begin, end);
35+
}
36+
37+
template<typename DataInputIterator>
38+
void compute(DataInputIterator begin, DataInputIterator end)
39+
{
40+
if (std::distance(begin, end) < 1)
41+
{
42+
min = 0;
43+
max = 0;
44+
mean = 0;
45+
median = 0;
46+
firstQuartile = 0;
47+
thirdQuartile = 0;
48+
return;
49+
}
50+
51+
std::vector<Type> vec_val(begin, end);
52+
std::sort(vec_val.begin(), vec_val.end());
53+
min = vec_val[0];
54+
max = vec_val[vec_val.size() - 1];
55+
mean = accumulate(vec_val.begin(), vec_val.end(), Type(0)) / static_cast<Type>(vec_val.size());
56+
median = vec_val[vec_val.size() / 2];
57+
firstQuartile = vec_val[vec_val.size() / 4];
58+
thirdQuartile = vec_val[(vec_val.size() * 3) / 4];
59+
}
60+
};
61+
62+
template<typename Type>
63+
inline std::ostream& operator<<(std::ostream& os, const BoxStats<Type> obj)
64+
{
65+
os << "\t min: " << obj.min
66+
<< "\n"
67+
"\t mean: "
68+
<< obj.mean
69+
<< "\n"
70+
"\t median: "
71+
<< obj.median
72+
<< "\n"
73+
"\t max: "
74+
<< obj.max
75+
<< "\n"
76+
"\t first quartile: "
77+
<< obj.firstQuartile
78+
<< "\n"
79+
"\t third quartile: "
80+
<< obj.thirdQuartile;
81+
82+
return os;
83+
}
84+
85+
86+
} // namespace aliceVision

src/aliceVision/numeric/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ set(numeric_files_headers
55
projection.hpp
66
gps.hpp
77
algebra.hpp
8+
BoxStats.hpp
89
)
910

1011
# Sources

src/aliceVision/numeric/numeric.hpp

Lines changed: 0 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -385,70 +385,6 @@ inline int is_finite(const double val)
385385
#endif
386386
}
387387

388-
/** Get back the min, mean, median and the max
389-
* values of an iterable sequence.
390-
*/
391-
template<typename Type>
392-
struct BoxStats
393-
{
394-
Type min{}, max{}, mean{}, median{}, firstQuartile{}, thirdQuartile{};
395-
396-
BoxStats() = default;
397-
398-
template<typename DataInputIterator>
399-
BoxStats(DataInputIterator begin, DataInputIterator end)
400-
{
401-
compute(begin, end);
402-
}
403-
404-
template<typename DataInputIterator>
405-
void compute(DataInputIterator begin, DataInputIterator end)
406-
{
407-
if (std::distance(begin, end) < 1)
408-
{
409-
min = 0;
410-
max = 0;
411-
mean = 0;
412-
median = 0;
413-
firstQuartile = 0;
414-
thirdQuartile = 0;
415-
return;
416-
}
417-
418-
std::vector<Type> vec_val(begin, end);
419-
std::sort(vec_val.begin(), vec_val.end());
420-
min = vec_val[0];
421-
max = vec_val[vec_val.size() - 1];
422-
mean = accumulate(vec_val.begin(), vec_val.end(), Type(0)) / static_cast<Type>(vec_val.size());
423-
median = vec_val[vec_val.size() / 2];
424-
firstQuartile = vec_val[vec_val.size() / 4];
425-
thirdQuartile = vec_val[(vec_val.size() * 3) / 4];
426-
}
427-
};
428-
429-
template<typename Type>
430-
inline std::ostream& operator<<(std::ostream& os, const BoxStats<Type> obj)
431-
{
432-
os << "\t min: " << obj.min
433-
<< "\n"
434-
"\t mean: "
435-
<< obj.mean
436-
<< "\n"
437-
"\t median: "
438-
<< obj.median
439-
<< "\n"
440-
"\t max: "
441-
<< obj.max
442-
<< "\n"
443-
"\t first quartile: "
444-
<< obj.firstQuartile
445-
<< "\n"
446-
"\t third quartile: "
447-
<< obj.thirdQuartile;
448-
449-
return os;
450-
}
451-
452388
/**
453389
** Split a range [ a ; b [ into a set of n ranges :
454390
[ a ; c1 [ U [ c1 ; c2 [ U ... U [ c(n-1) ; b [

src/aliceVision/sfm/generateReport.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
#include "generateReport.hpp"
99
#include <aliceVision/sfmData/SfMData.hpp>
10+
#include <aliceVision/numeric/BoxStats.hpp>
1011

1112
#include <aliceVision/utils/Histogram.hpp>
1213
#include <dependencies/htmlDoc/htmlDoc.hpp>

src/aliceVision/sfm/pipeline/global/GlobalSfMRotationAveragingSolver.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#include <aliceVision/graph/graph.hpp>
1111
#include <aliceVision/multiview/rotationAveraging/rotationAveraging.hpp>
1212
#include <aliceVision/stl/mapUtils.hpp>
13-
13+
#include <aliceVision/numeric/BoxStats.hpp>
1414
#include <aliceVision/utils/Histogram.hpp>
1515

1616
namespace aliceVision {

src/aliceVision/sfm/pipeline/sequential/ReconstructionEngine_sequentialSfM.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include <aliceVision/sfm/sfmFilters.hpp>
1414
#include <aliceVision/sfm/sfmStatistics.hpp>
1515
#include <aliceVision/sfm/utils/preprocess.hpp>
16+
#include <aliceVision/numeric/BoxStats.hpp>
1617

1718
#include <aliceVision/feature/FeaturesPerView.hpp>
1819
#include <aliceVision/graph/connectedComponent.hpp>

src/aliceVision/sfm/sfmStatistics.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
#include <aliceVision/track/Track.hpp>
1212
#include <aliceVision/track/tracksUtils.hpp>
1313
#include <aliceVision/stl/mapUtils.hpp>
14-
14+
#include <aliceVision/numeric/BoxStats.hpp>
1515
#include <aliceVision/utils/Histogram.hpp>
1616

1717
namespace aliceVision {

src/software/utils/precisionEvaluationToGt.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
#include <aliceVision/numeric/numeric.hpp>
1111
#include <aliceVision/geometry/rigidTransformation3D.hpp>
12+
#include <aliceVision/numeric/BoxStats.hpp>
1213

1314
#include <aliceVision/utils/Histogram.hpp>
1415
#include <dependencies/htmlDoc/htmlDoc.hpp>

0 commit comments

Comments
 (0)