63 register float sum = 0.0f;
65 for (
register int x = 0;
x < nDimension;
x++)
67 const float v = pVector1[
x] - pVector2[
x];
74 static inline float CrossCorrelation(
const float *pVector1,
const float *pVector2,
int nDimension)
76 register float sum = 0.0f;
78 for (
register int x = 0;
x < nDimension;
x++)
79 sum += pVector1[
x] * pVector2[
x];
122 void CKdTree::Build(
float **ppfValues,
int nLow,
int nHigh,
int nBucketSize,
int nDimensions,
int nUserDataSize)
151 const int nSize = nHigh - nLow + 1;
158 for (
int n = 0 ;
n < nSize;
n++)
161 pValues[d] = ppfValues[nLow +
n][d];
184 const int nMedianIndex = (nHigh - nLow) / 2 + nLow;
185 const float fMedianValue = ppfValues[nMedianIndex][nDimension];
188 const float fHigh = pCurrentBoundingBox->
pfHigh[nDimension];
189 const float fLow = pCurrentBoundingBox->
pfLow[nDimension];
196 pCurrentBoundingBox->
pfHigh[nDimension] = fMedianValue;
202 pCurrentBoundingBox->
pfHigh[nDimension] = fHigh;
203 pCurrentBoundingBox->
pfLow[nDimension] = fMedianValue;
209 pCurrentBoundingBox->
pfLow[nDimension] = fLow;
348 const int nSize = pNode->
m_nSize;
350 for (
int i = 0 ; i < nSize; i++)
374 const bool bFromLeft = fCutDifference < 0.0f;
396 const int nSize = pNode->
m_nSize;
398 for (
int i = 0; i < nSize; i++)
425 const float fCutDifference = pQuery[nDimension] - pNode->
m_fMedianValue;
427 if (fCutDifference < 0.0f)
430 float fBoxDifference = pNode->
m_Bounding.
fLow - pQuery[nDimension];
433 if (fBoxDifference < 0.0f)
434 fBoxDifference = 0.0f;
439 const float fChildDistanceBB = fDistanceBB - fBoxDifference * fBoxDifference + fCutDifference * fCutDifference;
453 if (fBoxDifference < 0.0f)
454 fBoxDifference = 0.0f;
459 const float fChildDistanceBB = fDistanceBB - fBoxDifference * fBoxDifference + fCutDifference * fCutDifference;
470 float fChildDistanceBB;
CKdTree(int nMaximumNumberOfNodes=10000)
int m_nMaximumLeavesToVisit
void NearestNeighborRecursiveBBF(CKdTreeNode *pNode, const float *pQuery, float fDistanceBB)
CKdTreeNode * m_pRightChild
CKdPriorityQueue * m_pNodeListBBF
KdBoundingBox CalculateEnclosingBoundingBox(float **ppValues, int nDimension, int nSize)
void Pop(float &fValue, void *&pMeta)
float GetDistanceFromBox(KdBoundingBox BoundingBox, const float *pValues, int nDimension)
CKdPriorityQueue * m_pNearestNeighborList_
static float SquaredEuclideanDistance(const float *pVector1, const float *pVector2, int nDimension)
void QuicksortByElementOfVector(float **ppValues, int nLow, int nHigh, int nSortByDimension)
CKdPriorityQueue * m_pNearestNeighborList
void NearestNeighborBBF(const float *pfQuery, float &fError, float *&pfNN, int nMaximumLeavesToVisit=-1)
CKdTreeNode * BuildRecursive(float **ppfValues, int nLow, int nHigh, KdBoundingBox *pCurrentBoundingBox, int nCurrentDepth)
CKdTreeNode * m_pLeftChild
void Build(float **ppfValues, int nLow, int nHigh, int nBucketSize, int nDimensions, int nUserDataSize)
void NearestNeighborRecursive(CKdTreeNode *pNode, const float *pQuery)
float * m_pNearestNeighbor
static float CrossCorrelation(const float *pVector1, const float *pVector2, int nDimension)
void DisposeRecursive(CKdTreeNode *pNode)
KdBoundingBox m_EnclosingBox
void NearestNeighbor(const float *pQuery, float &fError, float *&pfNN, int nMaximumLeavesToVisit=-1)
void Push(float fValue, void *pMeta)
float m_fCurrentMinDistance