mikeme
04-07-2012, 05:46 PM
Hi all,
I'm very new to C++, but need to implement a kd tree for some research. I believe I've implemented the code correctly, however, I cannot obtain the output of the result of the nearest neighbor search. Additionally, in regards to the external file I've loaded in, does the selecti() routine alter the order of the points? If so, after the nearest neighbor indices are obtained, how do I match the actual point locations to each index? Any help would be much appreciated. I'm trying very hard to understand this, but I'm limited on time.
#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
#include <vector>
#include "nr3.h"
#include "pointbox.h"
#include "kdtree.h"
using namespace std;
Int main(){
// Initialize Variables
vector < Point<3> > VecPoints(2000);
Doub x[2000];
Doub y[2000];
Doub z[2000];
Int i=0;
Int j=0;
Int k=0;
Int *nn =new Int;
Doub *dn=new Doub;
// Load x-position data
ifstream infile1("meanposx1.txt", ios::in);
while(! infile1.eof())
{
infile1 >> x[i];
i++;
}
infile1.close();
// Load y-position data
ifstream infile2("meanposy1.txt", ios::in);
while(! infile2.eof())
{
infile2 >> y[j];
j++;
}
infile2.close();
// Load z-position data
ifstream infile3("meanposz1.txt", ios::in);
while(! infile3.eof())
{
infile3 >> z[k];
k++;
}
infile3.close();
// Create Vector of Points
for (Int ii=0;ii<2000;ii++)
{
Point<3> p(x[ii],y[ii],z[ii]);
VecPoints[ii] = p;
}
// Construct KD Tree Based off of Mean Positions of RSO's
KDtree<3> tree(VecPoints);
tree.nnearest(1,nn,dn,19);
cout << &VecPoints[1];
return 0;
}
I'm very new to C++, but need to implement a kd tree for some research. I believe I've implemented the code correctly, however, I cannot obtain the output of the result of the nearest neighbor search. Additionally, in regards to the external file I've loaded in, does the selecti() routine alter the order of the points? If so, after the nearest neighbor indices are obtained, how do I match the actual point locations to each index? Any help would be much appreciated. I'm trying very hard to understand this, but I'm limited on time.
#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
#include <vector>
#include "nr3.h"
#include "pointbox.h"
#include "kdtree.h"
using namespace std;
Int main(){
// Initialize Variables
vector < Point<3> > VecPoints(2000);
Doub x[2000];
Doub y[2000];
Doub z[2000];
Int i=0;
Int j=0;
Int k=0;
Int *nn =new Int;
Doub *dn=new Doub;
// Load x-position data
ifstream infile1("meanposx1.txt", ios::in);
while(! infile1.eof())
{
infile1 >> x[i];
i++;
}
infile1.close();
// Load y-position data
ifstream infile2("meanposy1.txt", ios::in);
while(! infile2.eof())
{
infile2 >> y[j];
j++;
}
infile2.close();
// Load z-position data
ifstream infile3("meanposz1.txt", ios::in);
while(! infile3.eof())
{
infile3 >> z[k];
k++;
}
infile3.close();
// Create Vector of Points
for (Int ii=0;ii<2000;ii++)
{
Point<3> p(x[ii],y[ii],z[ii]);
VecPoints[ii] = p;
}
// Construct KD Tree Based off of Mean Positions of RSO's
KDtree<3> tree(VecPoints);
tree.nnearest(1,nn,dn,19);
cout << &VecPoints[1];
return 0;
}