I am new to learning C++ and one thing I have been doing to learn is to read through code others have written. I am interesting in image processing so I have being working with OpenCV.
My question has to do specifically with the usage of the pre-processor directive “#define”
It ‘s usage is defined as:
#define identifier replacement
Example:
#define THRESHOLD 100
The above replaces any occurrence of the word THRESHOLD with 100.
Sometimes I see #define used without a replacement. For example ("#define USE_FLANN" in the following)
:
The file where this segment of code comes from can be found here: http://sharesend.com/50nu3
What happens when #define is used without a replacement and why would one want to do that?
My question has to do specifically with the usage of the pre-processor directive “#define”
It ‘s usage is defined as:
#define identifier replacement
Example:
#define THRESHOLD 100
The above replaces any occurrence of the word THRESHOLD with 100.
Sometimes I see #define used without a replacement. For example ("#define USE_FLANN" in the following)
:
Rich (BB code):
#include <cv.h>
#include <highgui.h>
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <vector>
using namespace std;
// define whether to use approximate nearest-neighbor search
#define USE_FLANN
IplImage *image = 0;
double
compareSURFDescriptors( const float* d1, const float* d2, double best, int length )
{
double total_cost = 0;
assert( length % 4 == 0 );
for( int i = 0; i < length; i += 4 )
{
double t0 = d1 - d2;
double t1 = d1[i+1] - d2[i+1];
double t2 = d1[i+2] - d2[i+2];
double t3 = d1[i+3] - d2[i+3];
total_cost += t0*t0 + t1*t1 + t2*t2 + t3*t3;
if( total_cost > best )
break;
}
return total_cost;
}
What happens when #define is used without a replacement and why would one want to do that?