Skip to content

Commit

Permalink
Merge pull request #1638 from alicevision/dev/cleanUpEigen
Browse files Browse the repository at this point in the history
Remove specifics required by Eigen prior to C++17
  • Loading branch information
fabiencastan authored Jan 8, 2024
2 parents 91ffed1 + 547149f commit 0d83606
Show file tree
Hide file tree
Showing 10 changed files with 78 additions and 98 deletions.
3 changes: 0 additions & 3 deletions src/aliceVision/geometry/Pose3.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,6 @@ class Pose3
}

const SE3::Matrix& getHomogeneous() const { return _homogeneous; }

public:
EIGEN_MAKE_ALIGNED_OPERATOR_NEW
};

/**
Expand Down
4 changes: 2 additions & 2 deletions src/aliceVision/image/convolution.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ void ImageHorizontalConvolution(const ImageTypeIn& img, const Kernel& kernel, Im
const int kernel_width = kernel.size();
const int half_kernel_width = kernel_width / 2;

std::vector<pix_t, Eigen::aligned_allocator<pix_t>> line(cols + kernel_width);
std::vector<pix_t> line(cols + kernel_width);

for (int row = 0; row < rows; ++row)
{
Expand Down Expand Up @@ -135,7 +135,7 @@ void ImageVerticalConvolution(const ImageTypeIn& img, const Kernel& kernel, Imag

out.resize(cols, rows);

std::vector<pix_t, Eigen::aligned_allocator<pix_t>> line(rows + kernel_width);
std::vector<pix_t> line(rows + kernel_width);

for (int col = 0; col < cols; ++col)
{
Expand Down
3 changes: 0 additions & 3 deletions src/aliceVision/sfmData/CameraPose.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,6 @@ class CameraPose
bool _locked = false;
/// Estimator state
EEstimatorParameterState _state = EEstimatorParameterState::REFINED;

public:
EIGEN_MAKE_ALIGNED_OPERATOR_NEW
};

} // namespace sfmData
Expand Down
11 changes: 1 addition & 10 deletions src/aliceVision/types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@
#include <set>
#include <vector>

#ifdef ALICEVISION_STD_UNORDERED_MAP
#include <unordered_map>
#endif

namespace aliceVision {

typedef uint32_t IndexT;
Expand All @@ -27,13 +23,8 @@ typedef std::pair<IndexT, IndexT> Pair;
typedef std::set<Pair> PairSet;
typedef std::vector<Pair> PairVec;

#ifdef ALICEVISION_UNORDERED_MAP
template<typename Key, typename Value>
using HashMap = std::unordered_map<Key, Value>;
#else
template<typename K, typename V>
using HashMap = std::map<K, V, std::less<K>, Eigen::aligned_allocator<std::pair<const K, V>>>;
#endif
using HashMap = std::map<Key, Value>;

struct EstimationStatus
{
Expand Down
10 changes: 5 additions & 5 deletions src/aliceVision/voctree/MutableVocabularyTree.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ namespace voctree {
*
* When loading and using an existing vocabulary tree, use VocabularyTree instead.
*/
template<class Feature, template<typename, typename> class Distance = L2, class FeatureAllocator = typename DefaultAllocator<Feature>::type>
class MutableVocabularyTree : public VocabularyTree<Feature, Distance, FeatureAllocator>
template<class Feature, template<typename, typename> class Distance = L2>
class MutableVocabularyTree : public VocabularyTree<Feature, Distance>
{
typedef VocabularyTree<Feature, Distance, FeatureAllocator> BaseClass;
typedef VocabularyTree<Feature, Distance> BaseClass;

public:
MutableVocabularyTree() {}
Expand All @@ -34,9 +34,9 @@ class MutableVocabularyTree : public VocabularyTree<Feature, Distance, FeatureAl

uint32_t nodes() const { return this->word_start_ + this->num_words_; }

std::vector<Feature, FeatureAllocator>& centers() { return this->centers_; }
std::vector<Feature>& centers() { return this->centers_; }

const std::vector<Feature, FeatureAllocator>& centers() const { return this->centers_; }
const std::vector<Feature>& centers() const { return this->centers_; }

std::vector<uint8_t>& validCenters() { return this->valid_centers_; }

Expand Down
64 changes: 31 additions & 33 deletions src/aliceVision/voctree/SimpleKmeans.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ namespace voctree {
*/
struct InitRandom
{
template<class Feature, class Distance, class FeatureAllocator>
template<class Feature, class Distance>
void operator()(const std::vector<Feature*>& features,
size_t k,
std::vector<Feature, FeatureAllocator>& centers,
std::vector<Feature>& centers,
Distance distance,
const int verbose = 0)
{
Expand Down Expand Up @@ -63,10 +63,10 @@ struct InitRandom
*/
struct InitKmeanspp
{
template<class Feature, class Distance, class FeatureAllocator>
template<class Feature, class Distance>
void operator()(const std::vector<Feature*>& features,
size_t k,
std::vector<Feature, FeatureAllocator>& centers,
std::vector<Feature>& centers,
Distance distance,
const int verbose = 0)
{
Expand Down Expand Up @@ -218,10 +218,10 @@ struct InitKmeanspp
*/
struct InitGiven
{
template<class Feature, class Distance, class FeatureAllocator>
template<class Feature, class Distance>
void operator()(const std::vector<Feature*>& features,
std::size_t k,
std::vector<Feature, FeatureAllocator>& centers,
std::vector<Feature>& centers,
Distance distance,
const int verbose = 0)
{
Expand All @@ -235,8 +235,8 @@ inline void printFeat(const Feature& f)
ALICEVISION_LOG_DEBUG(f);
}

template<class Feature, class FeatureAllocator = typename DefaultAllocator<Feature>::type>
void printFeatVector(const std::vector<Feature, FeatureAllocator>& f)
template<class Feature>
void printFeatVector(const std::vector<Feature>& f)
{
for (std::size_t j = 0; j < f.size(); ++j)
{
Expand Down Expand Up @@ -279,8 +279,8 @@ bool checkElements(const Feature& f, const char* str)
* @return true if everything is ok
* @see checkElements( const Feature &f, const char* str )
*/
template<class Feature, class FeatureAllocator = typename DefaultAllocator<Feature>::type>
bool checkVectorElements(const std::vector<Feature, FeatureAllocator>& f, const char* str)
template<class Feature>
bool checkVectorElements(const std::vector<Feature>& f, const char* str)
{
bool correct = true;
for (std::size_t i = 0; i < f.size(); ++i)
Expand All @@ -296,21 +296,19 @@ bool checkVectorElements(const std::vector<Feature, FeatureAllocator>& f, const
*
* The standard Lloyd's algorithm is used. By default, cluster centers are initialized randomly.
*/
template<class Feature, class Distance = L2<Feature, Feature>, class FeatureAllocator = typename DefaultAllocator<Feature>::type>
template<class Feature, class Distance = L2<Feature, Feature>>
class SimpleKmeans
{
public:
typedef typename Distance::result_type squared_distance_type;
typedef boost::function<void(const std::vector<Feature*>&, std::size_t, std::vector<Feature, FeatureAllocator>&, Distance, const int verbose)>
typedef boost::function<void(const std::vector<Feature*>&, std::size_t, std::vector<Feature>&, Distance, const int verbose)>
Initializer;

/**
* @brief Constructor
*
* @param zero Object representing zero in the feature space
* @param d Functor for calculating squared distance
*
* @todo FeatureAllocator parameter
*/
SimpleKmeans(const Feature& zero = Feature(), Distance d = Distance(), const int verbose = 0);

Expand Down Expand Up @@ -338,9 +336,9 @@ class SimpleKmeans
* @param[out] centers A set of k cluster centers.
* @param[out] membership Cluster assignment for each feature
*/
squared_distance_type cluster(const std::vector<Feature, FeatureAllocator>& features,
squared_distance_type cluster(const std::vector<Feature>& features,
std::size_t k,
std::vector<Feature, FeatureAllocator>& centers,
std::vector<Feature>& centers,
std::vector<unsigned int>& membership) const;

/**
Expand All @@ -356,13 +354,13 @@ class SimpleKmeans
*/
squared_distance_type clusterPointers(const std::vector<Feature*>& features,
std::size_t k,
std::vector<Feature, FeatureAllocator>& centers,
std::vector<Feature>& centers,
std::vector<unsigned int>& membership) const;

private:
squared_distance_type clusterOnce(const std::vector<Feature*>& features,
std::size_t k,
std::vector<Feature, FeatureAllocator>& centers,
std::vector<Feature>& centers,
std::vector<unsigned int>& membership) const;

Feature zero_;
Expand All @@ -373,8 +371,8 @@ class SimpleKmeans
int verbose_;
};

template<class Feature, class Distance, class FeatureAllocator>
SimpleKmeans<Feature, Distance, FeatureAllocator>::SimpleKmeans(const Feature& zero, Distance d, const int verbose)
template<class Feature, class Distance>
SimpleKmeans<Feature, Distance>::SimpleKmeans(const Feature& zero, Distance d, const int verbose)
: zero_(zero),
distance_(d),
// choose_centers_( InitRandom( ) ),
Expand All @@ -384,11 +382,11 @@ SimpleKmeans<Feature, Distance, FeatureAllocator>::SimpleKmeans(const Feature& z
restarts_(1)
{}

template<class Feature, class Distance, class FeatureAllocator>
typename SimpleKmeans<Feature, Distance, FeatureAllocator>::squared_distance_type SimpleKmeans<Feature, Distance, FeatureAllocator>::cluster(
const std::vector<Feature, FeatureAllocator>& features,
template<class Feature, class Distance>
typename SimpleKmeans<Feature, Distance>::squared_distance_type SimpleKmeans<Feature, Distance>::cluster(
const std::vector<Feature>& features,
size_t k,
std::vector<Feature, FeatureAllocator>& centers,
std::vector<Feature>& centers,
std::vector<unsigned int>& membership) const
{
std::vector<Feature*> feature_ptrs;
Expand All @@ -398,14 +396,14 @@ typename SimpleKmeans<Feature, Distance, FeatureAllocator>::squared_distance_typ
return clusterPointers(feature_ptrs, k, centers, membership);
}

template<class Feature, class Distance, class FeatureAllocator>
typename SimpleKmeans<Feature, Distance, FeatureAllocator>::squared_distance_type SimpleKmeans<Feature, Distance, FeatureAllocator>::clusterPointers(
template<class Feature, class Distance>
typename SimpleKmeans<Feature, Distance>::squared_distance_type SimpleKmeans<Feature, Distance>::clusterPointers(
const std::vector<Feature*>& features,
size_t k,
std::vector<Feature, FeatureAllocator>& centers,
std::vector<Feature>& centers,
std::vector<unsigned int>& membership) const
{
std::vector<Feature, FeatureAllocator> new_centers(centers);
std::vector<Feature> new_centers(centers);
new_centers.resize(k);
std::vector<unsigned int> new_membership(features.size());

Expand All @@ -432,18 +430,18 @@ typename SimpleKmeans<Feature, Distance, FeatureAllocator>::squared_distance_typ
return least_sse;
}

template<class Feature, class Distance, class FeatureAllocator>
typename SimpleKmeans<Feature, Distance, FeatureAllocator>::squared_distance_type SimpleKmeans<Feature, Distance, FeatureAllocator>::clusterOnce(
template<class Feature, class Distance>
typename SimpleKmeans<Feature, Distance>::squared_distance_type SimpleKmeans<Feature, Distance>::clusterOnce(
const std::vector<Feature*>& features,
std::size_t k,
std::vector<Feature, FeatureAllocator>& centers,
std::vector<Feature>& centers,
std::vector<unsigned int>& membership) const
{
typedef typename std::vector<Feature, FeatureAllocator>::value_type centerType;
typedef typename std::vector<Feature>::value_type centerType;
typedef typename Distance::value_type feature_value_type;

std::vector<std::size_t> new_center_counts(k);
std::vector<Feature, FeatureAllocator> new_centers(k);
std::vector<Feature> new_centers(k);
std::vector<std::mutex> centersLocks(k);
squared_distance_type max_center_shift = std::numeric_limits<squared_distance_type>::max();

Expand Down
16 changes: 8 additions & 8 deletions src/aliceVision/voctree/TreeBuilder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ namespace voctree {
* @brief Class for building a new vocabulary by hierarchically clustering
* a set of training features.
*/
template<class Feature, template<typename, typename> class DistanceT = L2, class FeatureAllocator = typename DefaultAllocator<Feature>::type>
template<class Feature, template<typename, typename> class DistanceT = L2>
class TreeBuilder
{
public:
typedef MutableVocabularyTree<Feature, DistanceT, FeatureAllocator> Tree;
typedef MutableVocabularyTree<Feature, DistanceT> Tree;
typedef DistanceT<Feature, Feature> Distance;
typedef SimpleKmeans<Feature, Distance, FeatureAllocator> Kmeans;
typedef std::vector<Feature, FeatureAllocator> FeatureVector;
typedef SimpleKmeans<Feature, Distance> Kmeans;
typedef std::vector<Feature> FeatureVector;

/**
* @brief Constructor
Expand Down Expand Up @@ -74,15 +74,15 @@ class TreeBuilder
unsigned char verbose_;
};

template<class Feature, template<typename, typename> class DistanceT, class FeatureAllocator>
TreeBuilder<Feature, DistanceT, FeatureAllocator>::TreeBuilder(const Feature& zero, Distance d, unsigned char verbose)
template<class Feature, template<typename, typename> class DistanceT>
TreeBuilder<Feature, DistanceT>::TreeBuilder(const Feature& zero, Distance d, unsigned char verbose)
: kmeans_(zero, d, verbose),
zero_(zero),
verbose_(verbose)
{}

template<class Feature, template<typename, typename> class DistanceT, class FeatureAllocator>
void TreeBuilder<Feature, DistanceT, FeatureAllocator>::build(const FeatureVector& training_features, uint32_t k, uint32_t levels)
template<class Feature, template<typename, typename> class DistanceT>
void TreeBuilder<Feature, DistanceT>::build(const FeatureVector& training_features, uint32_t k, uint32_t levels)
{
// Initial setup and memory allocation for the tree
tree_.clear();
Expand Down
Loading

0 comments on commit 0d83606

Please sign in to comment.