Skip to content

Commit

Permalink
Merge pull request #1221 from p12tic/fix-cxx17-build
Browse files Browse the repository at this point in the history
Remove uses of features removed from C++17 standard
  • Loading branch information
fabiencastan authored Sep 16, 2022
2 parents 38fd06a + 54dcf95 commit 98b26d3
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 10 deletions.
16 changes: 13 additions & 3 deletions src/aliceVision/hdr/sampling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <aliceVision/system/Logger.hpp>

#include <OpenImageIO/imagebufalgo.h>
#include <random>


namespace aliceVision {
Expand Down Expand Up @@ -416,12 +417,15 @@ bool Sampling::extractSamplesFromImages(std::vector<ImageSample>& out_samples, c
}
}

std::random_device randomDevice;
std::mt19937 rng(randomDevice());

for (auto & item : counters)
{
if (item.second.size() > params.maxCountSample)
{
// Shuffle and ignore the exceeding samples
std::random_shuffle(item.second.begin(), item.second.end());
std::shuffle(item.second.begin(), item.second.end(), rng);
item.second.resize(params.maxCountSample);
}

Expand Down Expand Up @@ -469,14 +473,17 @@ void Sampling::analyzeSource(std::vector<ImageSample> & samples, int channelQuan
}
}

std::random_device randomDevice;
std::mt19937 rng(randomDevice());

for (auto & item : _positions)
{
// TODO: expose as parameters
const std::size_t maxSamples = 500;
if(item.second.size() > maxSamples)
{
// Shuffle and ignore the exceeding samples
std::random_shuffle(item.second.begin(), item.second.end());
std::shuffle(item.second.begin(), item.second.end(), rng);
item.second.resize(500);
}
}
Expand All @@ -488,6 +495,9 @@ void Sampling::filter(size_t maxTotalPoints)
size_t limitPerGroup = 510;
size_t total_points = maxTotalPoints + 1;

std::random_device randomDevice;
std::mt19937 rng(randomDevice());

while (total_points > maxTotalPoints)
{
limitPerGroup = limitPerGroup - 10;
Expand All @@ -498,7 +508,7 @@ void Sampling::filter(size_t maxTotalPoints)
if (item.second.size() > limitPerGroup)
{
// Shuffle and ignore the exceeding samples
std::random_shuffle(item.second.begin(), item.second.end());
std::shuffle(item.second.begin(), item.second.end(), rng);
item.second.resize(limitPerGroup);
}

Expand Down
3 changes: 2 additions & 1 deletion src/aliceVision/mvsUtils/MultiViewParams.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,8 @@ class MultiViewParams
const Matrix3x4& p34 = camArr.at(index); // projection matrix (3x4) scale = getDownscaleFactor()
const int downscale = getDownscaleFactor(index);
p44.assign(p34.m, p34.m + 12);
std::transform(p44.begin(), p44.begin() + 8, p44.begin(), std::bind1st(std::multiplies<double>(),downscale));
std::transform(p44.begin(), p44.begin() + 8, p44.begin(),
[&](double p){ return p * downscale; });
p44.push_back(0);
p44.push_back(0);
p44.push_back(0);
Expand Down
6 changes: 5 additions & 1 deletion src/aliceVision/sfmData/colorize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include <aliceVision/system/ProgressDisplay.hpp>

#include <map>
#include <random>
#include <vector>
#include <functional>
namespace aliceVision {
Expand Down Expand Up @@ -89,10 +90,13 @@ void colorizeTracks(SfMData& sfmData)
break;
}

std::random_device randomDevice;
std::mt19937 rng(randomDevice());

// create an unsorted index container
std::vector<int> unsortedIndexes(sortedViewsCardinal.size()) ;
std::iota(std::begin(unsortedIndexes), std::end(unsortedIndexes), 0);
std::random_shuffle(unsortedIndexes.begin(), unsortedIndexes.end());
std::shuffle(unsortedIndexes.begin(), unsortedIndexes.end(), rng);

// landmark colorization
#pragma omp parallel for
Expand Down
2 changes: 1 addition & 1 deletion src/aliceVision/track/TracksBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ void TracksBuilder::filter(bool clearForks, std::size_t minTrackLength, bool mul
}

std::for_each(set_classToErase.begin(), set_classToErase.end(),
std::bind1st(std::mem_fun(&UnionFindObject::eraseClass), _d->tracksUF.get()));
[&](int toErase){ _d->tracksUF->eraseClass(toErase); });
}

bool TracksBuilder::exportToStream(std::ostream& os)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#include <map>
#include <cassert>
#include <cstring>
#include <random>
#include <stdarg.h>

#include "flann/general.h"
Expand Down Expand Up @@ -251,6 +252,9 @@ class KDTreeIndex : public NNIndex<Distance>
*/
void buildIndexImpl()
{
std::random_device randomDevice;
std::mt19937 rng(randomDevice());

// Create a permutable array of indices to the input vectors.
std::vector<int> ind(size_);
for (size_t i = 0; i < size_; ++i) {
Expand All @@ -264,7 +268,7 @@ class KDTreeIndex : public NNIndex<Distance>
/* Construct the randomized trees. */
for (int i = 0; i < trees_; i++) {
/* Randomize the order of vectors to allow for unbiased sampling. */
std::random_shuffle(ind.begin(), ind.end());
std::shuffle(ind.begin(), ind.end(), rng);
tree_roots_[i] = divideTree(&ind[0], int(size_) );
}
delete[] mean_;
Expand Down
7 changes: 6 additions & 1 deletion src/dependencies/flann/src/cpp/flann/util/lsh_table.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <random>

#include <limits.h>
// TODO as soon as we use C++0x, use the code in USE_UNORDERED_MAP
#if USE_UNORDERED_MAP
Expand Down Expand Up @@ -357,14 +359,17 @@ class LshTable
template<>
inline LshTable<unsigned char>::LshTable(unsigned int feature_size, unsigned int subsignature_size)
{
std::random_device randomDevice;
std::mt19937 rng(randomDevice());

initialize(subsignature_size);
// Allocate the mask
mask_ = std::vector<size_t>((size_t)ceil((float)(feature_size * sizeof(char)) / (float)sizeof(size_t)), 0);

// A bit brutal but fast to code
std::vector<size_t> indices(feature_size * CHAR_BIT);
for (size_t i = 0; i < feature_size * CHAR_BIT; ++i) indices[i] = i;
std::random_shuffle(indices.begin(), indices.end());
std::shuffle(indices.begin(), indices.end(), rng);

// Generate a random set of order of subsignature_size_ bits
for (unsigned int i = 0; i < key_size_; ++i) {
Expand Down
7 changes: 5 additions & 2 deletions src/dependencies/flann/src/cpp/flann/util/random.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#include <algorithm>
#include <cstdlib>
#include <cstddef>
#include <random>
#include <vector>

#include "flann/general.h"
Expand Down Expand Up @@ -110,14 +111,16 @@ class UniqueRandom
*/
void init(int n)
{
static RandomGenerator generator;
std::random_device randomDevice;
std::mt19937 rng(randomDevice());

// create and initialize an array of size n
vals_.resize(n);
size_ = n;
for (int i = 0; i < size_; ++i) vals_[i] = i;

// shuffle the elements in the array
std::random_shuffle(vals_.begin(), vals_.end(), generator);
std::shuffle(vals_.begin(), vals_.end(), rng);

counter_ = 0;
}
Expand Down

0 comments on commit 98b26d3

Please sign in to comment.