Prefixed constants in flann with FLANN_ to prevent clashes with constants from other includes, closes bug #890
This commit is contained in:
@@ -49,19 +49,19 @@ NNIndex<T>* create_index_by_type(const Matrix<T>& dataset, const IndexParams& pa
|
||||
|
||||
NNIndex<T>* nnIndex;
|
||||
switch (index_type) {
|
||||
case LINEAR:
|
||||
case FLANN_INDEX_LINEAR:
|
||||
nnIndex = new LinearIndex<T>(dataset, (const LinearIndexParams&)params);
|
||||
break;
|
||||
case KDTREE:
|
||||
case FLANN_INDEX_KDTREE:
|
||||
nnIndex = new KDTreeIndex<T>(dataset, (const KDTreeIndexParams&)params);
|
||||
break;
|
||||
case KMEANS:
|
||||
case FLANN_INDEX_KMEANS:
|
||||
nnIndex = new KMeansIndex<T>(dataset, (const KMeansIndexParams&)params);
|
||||
break;
|
||||
case COMPOSITE:
|
||||
case FLANN_INDEX_COMPOSITE:
|
||||
nnIndex = new CompositeIndex<T>(dataset, (const CompositeIndexParams&) params);
|
||||
break;
|
||||
case AUTOTUNED:
|
||||
case FLANN_INDEX_AUTOTUNED:
|
||||
nnIndex = new AutotunedIndex<T>(dataset, (const AutotunedIndexParams&) params);
|
||||
break;
|
||||
default:
|
||||
|
@@ -44,7 +44,7 @@ namespace cvflann
|
||||
struct AutotunedIndexParams : public IndexParams {
|
||||
AutotunedIndexParams( float target_precision_ = 0.8, float build_weight_ = 0.01,
|
||||
float memory_weight_ = 0, float sample_fraction_ = 0.1) :
|
||||
IndexParams(AUTOTUNED),
|
||||
IndexParams(FLANN_INDEX_AUTOTUNED),
|
||||
target_precision(target_precision_),
|
||||
build_weight(build_weight_),
|
||||
memory_weight(memory_weight_),
|
||||
@@ -55,8 +55,6 @@ struct AutotunedIndexParams : public IndexParams {
|
||||
float memory_weight; // index memory weighting factor
|
||||
float sample_fraction; // what fraction of the dataset to use for autotuning
|
||||
|
||||
flann_algorithm_t getIndexType() const { return algorithm; }
|
||||
|
||||
void print() const
|
||||
{
|
||||
logger().info("Index type: %d\n",(int)algorithm);
|
||||
@@ -123,13 +121,13 @@ public:
|
||||
logger().info("----------------------------------------------------\n");
|
||||
flann_algorithm_t index_type = bestParams->getIndexType();
|
||||
switch (index_type) {
|
||||
case LINEAR:
|
||||
case FLANN_INDEX_LINEAR:
|
||||
bestIndex = new LinearIndex<ELEM_TYPE>(dataset, (const LinearIndexParams&)*bestParams);
|
||||
break;
|
||||
case KDTREE:
|
||||
case FLANN_INDEX_KDTREE:
|
||||
bestIndex = new KDTreeIndex<ELEM_TYPE>(dataset, (const KDTreeIndexParams&)*bestParams);
|
||||
break;
|
||||
case KMEANS:
|
||||
case FLANN_INDEX_KMEANS:
|
||||
bestIndex = new KMeansIndex<ELEM_TYPE>(dataset, (const KMeansIndexParams&)*bestParams);
|
||||
break;
|
||||
default:
|
||||
@@ -211,7 +209,7 @@ public:
|
||||
*/
|
||||
virtual flann_algorithm_t getType() const
|
||||
{
|
||||
return AUTOTUNED;
|
||||
return FLANN_INDEX_AUTOTUNED;
|
||||
}
|
||||
|
||||
private:
|
||||
@@ -347,7 +345,7 @@ private:
|
||||
for (size_t i=0; i<ARRAY_LEN(maxIterations); ++i) {
|
||||
for (size_t j=0; j<ARRAY_LEN(branchingFactors); ++j) {
|
||||
|
||||
kmeansCosts[cnt].second.centers_init = CENTERS_RANDOM;
|
||||
kmeansCosts[cnt].second.centers_init = FLANN_CENTERS_RANDOM;
|
||||
kmeansCosts[cnt].second.iterations = maxIterations[i];
|
||||
kmeansCosts[cnt].second.branching = branchingFactors[j];
|
||||
|
||||
@@ -569,7 +567,7 @@ private:
|
||||
|
||||
float searchTime;
|
||||
float cb_index;
|
||||
if (bestIndex->getType() == KMEANS) {
|
||||
if (bestIndex->getType() == FLANN_INDEX_KMEANS) {
|
||||
logger().info("KMeans algorithm, estimating cluster border factor\n");
|
||||
KMeansIndex<ELEM_TYPE>* kmeans = (KMeansIndex<ELEM_TYPE>*)bestIndex;
|
||||
float bestSearchTime = -1;
|
||||
|
@@ -40,8 +40,8 @@ namespace cvflann
|
||||
|
||||
struct CompositeIndexParams : public IndexParams {
|
||||
CompositeIndexParams(int trees_ = 4, int branching_ = 32, int iterations_ = 11,
|
||||
flann_centers_init_t centers_init_ = CENTERS_RANDOM, float cb_index_ = 0.2 ) :
|
||||
IndexParams(COMPOSITE),
|
||||
flann_centers_init_t centers_init_ = FLANN_CENTERS_RANDOM, float cb_index_ = 0.2 ) :
|
||||
IndexParams(FLANN_INDEX_COMPOSITE),
|
||||
trees(trees_),
|
||||
branching(branching_),
|
||||
iterations(iterations_),
|
||||
@@ -54,8 +54,6 @@ struct CompositeIndexParams : public IndexParams {
|
||||
flann_centers_init_t centers_init; // algorithm used for picking the initial cluster centers for kmeans tree
|
||||
float cb_index; // cluster boundary index. Used when searching the kmeans tree
|
||||
|
||||
flann_algorithm_t getIndexType() const { return algorithm; }
|
||||
|
||||
void print() const
|
||||
{
|
||||
logger().info("Index type: %d\n",(int)algorithm);
|
||||
@@ -102,7 +100,7 @@ public:
|
||||
|
||||
flann_algorithm_t getType() const
|
||||
{
|
||||
return COMPOSITE;
|
||||
return FLANN_INDEX_COMPOSITE;
|
||||
}
|
||||
|
||||
|
||||
|
@@ -304,21 +304,21 @@ template <typename Iterator1, typename Iterator2>
|
||||
double custom_dist(Iterator1 first1, Iterator1 last1, Iterator2 first2, double acc = 0)
|
||||
{
|
||||
switch (flann_distance_type()) {
|
||||
case EUCLIDEAN:
|
||||
case FLANN_DIST_EUCLIDEAN:
|
||||
return euclidean_dist(first1, last1, first2, acc);
|
||||
case MANHATTAN:
|
||||
case FLANN_DIST_MANHATTAN:
|
||||
return manhattan_dist(first1, last1, first2, acc);
|
||||
case MINKOWSKI:
|
||||
case FLANN_DIST_MINKOWSKI:
|
||||
return minkowski_dist(first1, last1, first2, acc);
|
||||
case MAX_DIST:
|
||||
case FLANN_DIST_MAX:
|
||||
return max_dist(first1, last1, first2, acc);
|
||||
case HIK:
|
||||
case FLANN_DIST_HIST_INTERSECT:
|
||||
return hist_intersection_dist_sq(first1, last1, first2, acc);
|
||||
case HELLINGER:
|
||||
case FLANN_DIST_HELLINGER:
|
||||
return hellinger_dist(first1, last1, first2, acc);
|
||||
case CS:
|
||||
case FLANN_DIST_CS:
|
||||
return chi_square_dist(first1, last1, first2, acc);
|
||||
case KL:
|
||||
case FLANN_DIST_KL:
|
||||
return kl_divergence(first1, last1, first2, acc);
|
||||
default:
|
||||
return euclidean_dist(first1, last1, first2, acc);
|
||||
|
@@ -67,12 +67,10 @@ CV_EXPORTS void set_distance_type(flann_distance_t distance_type, int order);
|
||||
|
||||
|
||||
struct CV_EXPORTS SavedIndexParams : public IndexParams {
|
||||
SavedIndexParams(std::string filename_) : IndexParams(SAVED), filename(filename_) {}
|
||||
SavedIndexParams(std::string filename_) : IndexParams(FLANN_INDEX_SAVED), filename(filename_) {}
|
||||
|
||||
std::string filename; // filename of the stored index
|
||||
|
||||
flann_algorithm_t getIndexType() const { return algorithm; }
|
||||
|
||||
void print() const
|
||||
{
|
||||
logger().info("Index type: %d\n",(int)algorithm);
|
||||
@@ -138,7 +136,7 @@ Index<T>::Index(const Matrix<T>& dataset, const IndexParams& params)
|
||||
flann_algorithm_t index_type = params.getIndexType();
|
||||
built = false;
|
||||
|
||||
if (index_type==SAVED) {
|
||||
if (index_type==FLANN_INDEX_SAVED) {
|
||||
nnIndex = load_saved_index(dataset, ((const SavedIndexParams&)params).filename);
|
||||
built = true;
|
||||
}
|
||||
|
@@ -44,18 +44,18 @@ namespace cvflann {
|
||||
|
||||
/* Nearest neighbour index algorithms */
|
||||
enum flann_algorithm_t {
|
||||
LINEAR = 0,
|
||||
KDTREE = 1,
|
||||
KMEANS = 2,
|
||||
COMPOSITE = 3,
|
||||
SAVED = 254,
|
||||
AUTOTUNED = 255
|
||||
FLANN_INDEX_LINEAR = 0,
|
||||
FLANN_INDEX_KDTREE = 1,
|
||||
FLANN_INDEX_KMEANS = 2,
|
||||
FLANN_INDEX_COMPOSITE = 3,
|
||||
FLANN_INDEX_SAVED = 254,
|
||||
FLANN_INDEX_AUTOTUNED = 255
|
||||
};
|
||||
|
||||
enum flann_centers_init_t {
|
||||
CENTERS_RANDOM = 0,
|
||||
CENTERS_GONZALES = 1,
|
||||
CENTERS_KMEANSPP = 2
|
||||
FLANN_CENTERS_RANDOM = 0,
|
||||
FLANN_CENTERS_GONZALES = 1,
|
||||
FLANN_CENTERS_KMEANSPP = 2
|
||||
};
|
||||
|
||||
enum flann_log_level_t {
|
||||
@@ -67,29 +67,31 @@ enum flann_log_level_t {
|
||||
};
|
||||
|
||||
enum flann_distance_t {
|
||||
EUCLIDEAN = 1,
|
||||
MANHATTAN = 2,
|
||||
MINKOWSKI = 3,
|
||||
MAX_DIST = 4,
|
||||
HIK = 5,
|
||||
HELLINGER = 6,
|
||||
CS = 7,
|
||||
CHI_SQUARE = 7,
|
||||
KL = 8,
|
||||
KULLBACK_LEIBLER = 8
|
||||
FLANN_DIST_EUCLIDEAN = 1,
|
||||
FLANN_DIST_L2 = 1,
|
||||
FLANN_DIST_MANHATTAN = 2,
|
||||
FLANN_DIST_L1 = 2,
|
||||
FLANN_DIST_MINKOWSKI = 3,
|
||||
FLANN_DIST_MAX = 4,
|
||||
FLANN_DIST_HIST_INTERSECT = 5,
|
||||
FLANN_DIST_HELLINGER = 6,
|
||||
FLANN_DIST_CHI_SQUARE = 7,
|
||||
FLANN_DIST_CS = 7,
|
||||
FLANN_DIST_KULLBACK_LEIBLER = 8,
|
||||
FLANN_DIST_KL = 8
|
||||
};
|
||||
|
||||
enum flann_datatype_t {
|
||||
INT8 = 0,
|
||||
INT16 = 1,
|
||||
INT32 = 2,
|
||||
INT64 = 3,
|
||||
UINT8 = 4,
|
||||
UINT16 = 5,
|
||||
UINT32 = 6,
|
||||
UINT64 = 7,
|
||||
FLOAT32 = 8,
|
||||
FLOAT64 = 9
|
||||
FLANN_INT8 = 0,
|
||||
FLANN_INT16 = 1,
|
||||
FLANN_INT32 = 2,
|
||||
FLANN_INT64 = 3,
|
||||
FLANN_UINT8 = 4,
|
||||
FLANN_UINT16 = 5,
|
||||
FLANN_UINT32 = 6,
|
||||
FLANN_UINT64 = 7,
|
||||
FLANN_FLOAT32 = 8,
|
||||
FLANN_FLOAT64 = 9
|
||||
};
|
||||
|
||||
template <typename ELEM_TYPE>
|
||||
@@ -125,7 +127,7 @@ protected:
|
||||
|
||||
public:
|
||||
virtual ~IndexParams() {}
|
||||
virtual flann_algorithm_t getIndexType() const = 0;
|
||||
virtual flann_algorithm_t getIndexType() const { return algorithm; }
|
||||
|
||||
virtual void print() const = 0;
|
||||
|
||||
|
@@ -50,12 +50,10 @@ namespace cvflann
|
||||
{
|
||||
|
||||
struct CV_EXPORTS KDTreeIndexParams : public IndexParams {
|
||||
KDTreeIndexParams(int trees_ = 4) : IndexParams(KDTREE), trees(trees_) {};
|
||||
KDTreeIndexParams(int trees_ = 4) : IndexParams(FLANN_INDEX_KDTREE), trees(trees_) {};
|
||||
|
||||
int trees; // number of randomized trees to use (for kdtree)
|
||||
|
||||
flann_algorithm_t getIndexType() const { return algorithm; }
|
||||
|
||||
void print() const
|
||||
{
|
||||
logger().info("Index type: %d\n",(int)algorithm);
|
||||
@@ -167,7 +165,7 @@ public:
|
||||
|
||||
flann_algorithm_t getType() const
|
||||
{
|
||||
return KDTREE;
|
||||
return FLANN_INDEX_KDTREE;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -52,8 +52,8 @@ namespace cvflann
|
||||
|
||||
struct CV_EXPORTS KMeansIndexParams : public IndexParams {
|
||||
KMeansIndexParams(int branching_ = 32, int iterations_ = 11,
|
||||
flann_centers_init_t centers_init_ = CENTERS_RANDOM, float cb_index_ = 0.2 ) :
|
||||
IndexParams(KMEANS),
|
||||
flann_centers_init_t centers_init_ = FLANN_CENTERS_RANDOM, float cb_index_ = 0.2 ) :
|
||||
IndexParams(FLANN_INDEX_KMEANS),
|
||||
branching(branching_),
|
||||
iterations(iterations_),
|
||||
centers_init(centers_init_),
|
||||
@@ -64,8 +64,6 @@ struct CV_EXPORTS KMeansIndexParams : public IndexParams {
|
||||
flann_centers_init_t centers_init; // algorithm used for picking the initial cluster centers for kmeans tree
|
||||
float cb_index; // cluster boundary index. Used when searching the kmeans tree
|
||||
|
||||
flann_algorithm_t getIndexType() const { return KMEANS; }
|
||||
|
||||
void print() const
|
||||
{
|
||||
logger().info("Index type: %d\n",(int)algorithm);
|
||||
@@ -379,7 +377,7 @@ public:
|
||||
|
||||
flann_algorithm_t getType() const
|
||||
{
|
||||
return KMEANS;
|
||||
return FLANN_INDEX_KMEANS;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -404,13 +402,13 @@ public:
|
||||
}
|
||||
flann_centers_init_t centersInit = params.centers_init;
|
||||
|
||||
if (centersInit==CENTERS_RANDOM) {
|
||||
if (centersInit==FLANN_CENTERS_RANDOM) {
|
||||
chooseCenters = &KMeansIndex::chooseCentersRandom;
|
||||
}
|
||||
else if (centersInit==CENTERS_GONZALES) {
|
||||
else if (centersInit==FLANN_CENTERS_GONZALES) {
|
||||
chooseCenters = &KMeansIndex::chooseCentersGonzales;
|
||||
}
|
||||
else if (centersInit==CENTERS_KMEANSPP) {
|
||||
else if (centersInit==FLANN_CENTERS_KMEANSPP) {
|
||||
chooseCenters = &KMeansIndex::chooseCentersKMeanspp;
|
||||
}
|
||||
else {
|
||||
|
@@ -39,9 +39,7 @@ namespace cvflann
|
||||
{
|
||||
|
||||
struct CV_EXPORTS LinearIndexParams : public IndexParams {
|
||||
LinearIndexParams() : IndexParams(LINEAR) {};
|
||||
|
||||
flann_algorithm_t getIndexType() const { return algorithm; }
|
||||
LinearIndexParams() : IndexParams(FLANN_INDEX_LINEAR) {};
|
||||
|
||||
void print() const
|
||||
{
|
||||
@@ -65,7 +63,7 @@ public:
|
||||
|
||||
flann_algorithm_t getType() const
|
||||
{
|
||||
return LINEAR;
|
||||
return FLANN_INDEX_LINEAR;
|
||||
}
|
||||
|
||||
|
||||
|
@@ -37,14 +37,14 @@
|
||||
namespace cvflann
|
||||
{
|
||||
template <typename T> struct Datatype {};
|
||||
template<> struct Datatype<char> { static flann_datatype_t type() { return INT8; } };
|
||||
template<> struct Datatype<short> { static flann_datatype_t type() { return INT16; } };
|
||||
template<> struct Datatype<int> { static flann_datatype_t type() { return INT32; } };
|
||||
template<> struct Datatype<unsigned char> { static flann_datatype_t type() { return UINT8; } };
|
||||
template<> struct Datatype<unsigned short> { static flann_datatype_t type() { return UINT16; } };
|
||||
template<> struct Datatype<unsigned int> { static flann_datatype_t type() { return UINT32; } };
|
||||
template<> struct Datatype<float> { static flann_datatype_t type() { return FLOAT32; } };
|
||||
template<> struct Datatype<double> { static flann_datatype_t type() { return FLOAT64; } };
|
||||
template<> struct Datatype<char> { static flann_datatype_t type() { return FLANN_INT8; } };
|
||||
template<> struct Datatype<short> { static flann_datatype_t type() { return FLANN_INT16; } };
|
||||
template<> struct Datatype<int> { static flann_datatype_t type() { return FLANN_INT32; } };
|
||||
template<> struct Datatype<unsigned char> { static flann_datatype_t type() { return FLANN_UINT8; } };
|
||||
template<> struct Datatype<unsigned short> { static flann_datatype_t type() { return FLANN_UINT16; } };
|
||||
template<> struct Datatype<unsigned int> { static flann_datatype_t type() { return FLANN_UINT32; } };
|
||||
template<> struct Datatype<float> { static flann_datatype_t type() { return FLANN_FLOAT32; } };
|
||||
template<> struct Datatype<double> { static flann_datatype_t type() { return FLANN_FLOAT64; } };
|
||||
|
||||
|
||||
CV_EXPORTS const char* FLANN_SIGNATURE();
|
||||
|
@@ -35,7 +35,7 @@ namespace cvflann
|
||||
/** Global variable indicating the distance metric
|
||||
* to be used.
|
||||
*/
|
||||
flann_distance_t flann_distance_type_ = EUCLIDEAN;
|
||||
flann_distance_t flann_distance_type_ = FLANN_DIST_EUCLIDEAN;
|
||||
flann_distance_t flann_distance_type() { return flann_distance_type_; }
|
||||
|
||||
/**
|
||||
@@ -208,12 +208,12 @@ class StaticInit
|
||||
public:
|
||||
StaticInit()
|
||||
{
|
||||
ParamsFactory_instance().register_<LinearIndexParams>(LINEAR);
|
||||
ParamsFactory_instance().register_<KDTreeIndexParams>(KDTREE);
|
||||
ParamsFactory_instance().register_<KMeansIndexParams>(KMEANS);
|
||||
ParamsFactory_instance().register_<CompositeIndexParams>(COMPOSITE);
|
||||
ParamsFactory_instance().register_<AutotunedIndexParams>(AUTOTUNED);
|
||||
// ParamsFactory::instance().register_<SavedIndexParams>(SAVED);
|
||||
ParamsFactory_instance().register_<LinearIndexParams>(FLANN_INDEX_LINEAR);
|
||||
ParamsFactory_instance().register_<KDTreeIndexParams>(FLANN_INDEX_KDTREE);
|
||||
ParamsFactory_instance().register_<KMeansIndexParams>(FLANN_INDEX_KMEANS);
|
||||
ParamsFactory_instance().register_<CompositeIndexParams>(FLANN_INDEX_COMPOSITE);
|
||||
ParamsFactory_instance().register_<AutotunedIndexParams>(FLANN_INDEX_AUTOTUNED);
|
||||
// ParamsFactory::instance().register_<SavedIndexParams>(FLANN_INDEX_SAVED);
|
||||
}
|
||||
};
|
||||
StaticInit __init;
|
||||
|
Reference in New Issue
Block a user