Numerical Recipes Forum  

Go Back   Numerical Recipes Forum > Numerical Recipes Third Edition Forum > Methods: All Chapters in NR3

 
 
Thread Tools Rating: Thread Rating: 3 votes, 5.00 average. Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 04-07-2012, 05:46 PM
mikeme mikeme is offline
Registered User
 
Join Date: Apr 2012
Posts: 2
Chapter 21 - KD Tree

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.

PHP Code:
#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<3p(x[ii],y[ii],z[ii]);
        
VecPoints[ii] = p;
    }
    
    
// Construct KD Tree Based off of Mean Positions of RSO's
    
KDtree<3tree(VecPoints);
    
tree.nnearest(1,nn,dn,19);
    
cout << &VecPoints[1];
    return 
0;

Reply With Quote
 

Tags
chapter 21, computational geometry, kd tree, nearest neighbors

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -5. The time now is 08:41 AM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.