提交 8fb53ca2 编写于 作者: M Marius Muja

Windows compilation fixes

上级 c4c1050b
......@@ -9,22 +9,26 @@
float* read_points(const char* filename, int rows, int cols)
{
int ret;
float* data;
float *p;
FILE* fin;
int i,j;
FILE* fin = fopen(filename,"r");
fin = fopen(filename,"r");
if (!fin) {
printf("Cannot open input file.\n");
exit(1);
}
float* data = (float*) malloc(rows*cols*sizeof(float));
data = (float*) malloc(rows*cols*sizeof(float));
if (!data) {
printf("Cannot allocate memory.\n");
exit(1);
}
float* p = data;
p = data;
for (int i=0;i<rows;++i) {
for (int j=0;j<cols;++j) {
for (i=0;i<rows;++i) {
for (j=0;j<cols;++j) {
ret = fscanf(fin,"%g ",p);
p++;
}
......@@ -37,15 +41,19 @@ float* read_points(const char* filename, int rows, int cols)
void write_results(const char* filename, int *data, int rows, int cols)
{
FILE* fout = fopen(filename,"w");
FILE* fout;
int* p;
int i,j;
fout = fopen(filename,"w");
if (!fout) {
printf("Cannot open output file.\n");
exit(1);
}
int* p = data;
for (int i=0;i<rows;++i) {
for (int j=0;j<cols;++j) {
p = data;
for (i=0;i<rows;++i) {
for (j=0;j<cols;++j) {
fprintf(fout,"%d ",*p);
p++;
}
......@@ -58,27 +66,36 @@ void write_results(const char* filename, int *data, int rows, int cols)
int main(int argc, char** argv)
{
float* dataset;
float* testset;
int nn;
int* result;
float* dists;
struct FLANNParameters p;
float speedup;
flann_index_t index_id;
int rows = 9000;
int cols = 128;
int tcount = 1000;
printf("Reading input data file.\n");
float* dataset = read_points("dataset.dat", rows, cols);
dataset = read_points("dataset.dat", rows, cols);
printf("Reading test data file.\n");
float* testset = read_points("testset.dat", tcount, cols);
testset = read_points("testset.dat", tcount, cols);
int nn = 3;
int* result = (int*) malloc(tcount*nn*sizeof(int));
float* dists = (float*) malloc(tcount*nn*sizeof(float));
nn = 3;
result = (int*) malloc(tcount*nn*sizeof(int));
dists = (float*) malloc(tcount*nn*sizeof(float));
struct FLANNParameters p = DEFAULT_FLANN_PARAMETERS;
p = DEFAULT_FLANN_PARAMETERS;
p.algorithm = KDTREE;
p.trees = 8;
p.log_level = LOG_INFO;
p.checks = 64;
float speedup;
printf("Computing index.\n");
flann_index_t index_id = flann_build_index(dataset, rows, cols, &speedup, &p);
index_id = flann_build_index(dataset, rows, cols, &speedup, &p);
flann_find_nearest_neighbors_index(index_id, testset, tcount, result, dists, nn, &p);
write_results("results.dat",result, tcount, nn);
......
......@@ -31,14 +31,14 @@
#ifdef WIN32
#define EXPORTED extern "C" __declspec(dllexport)
#define EXPORTED __declspec(dllexport)
#else
#define EXPORTED extern "C"
#define EXPORTED
#endif
#define FLANN_FIRST_MATCH
struct FLANNParameters DEFAULT_FLANN_PARAMETERS = {
EXPORTED struct FLANNParameters DEFAULT_FLANN_PARAMETERS = {
KDTREE,
32, 0.2, 0.0,
4, 4,
......
......@@ -57,7 +57,7 @@ extern "C" {
typedef void* FLANN_INDEX; /* deprecated */
typedef void* flann_index_t;
extern struct FLANNParameters DEFAULT_FLANN_PARAMETERS;
LIBSPEC extern struct FLANNParameters DEFAULT_FLANN_PARAMETERS;
/**
Sets the log level used for all flann functions (unless
......
......@@ -40,12 +40,6 @@
#include "flann/algorithms/all_indices.h"
#ifdef WIN32
#define EXPORTED extern "C" __declspec(dllexport)
#else
#define EXPORTED extern "C"
#endif
namespace flann
{
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册