Commit d275d944 authored by Jean-Eric Campagne's avatar Jean-Eric Campagne
Browse files

(JEC/MR) 24/4/15 restructuration of the 2D Geometry interface; introduction of...

(JEC/MR) 24/4/15 restructuration of the 2D Geometry interface; introduction of direct method to access 2D pixel location and index which remove dependance from ANN
parent 1b065393
#include <ANN/ANN.h>
#include "lagsht_geom.h"
#include "lagsht_exceptions.h"
#define DEBUB 0
namespace LagSHT {
//// --------- Class gateway to Approximate Nearest Neighbor Searching -- //
class ANNServer {
//! Constructor default
ANNServer(): nNear_(1), dim_(2), eps_(0),
npts_(0), kdTree_(NULL), nnIdx_(NULL),
dists_(NULL), dataPts_(NULL) {
nnIdx_ = new ANNidx[nNear_]; // near neighboors indices
dists_ = new ANNdist[nNear_]; // --------------- dists
//! Constructor
ANNServer(geom_t vec):
nNear_(1), dim_(2), eps_(0),npts_(0), kdTree_(NULL), dataPts_(NULL) {
nnIdx_ = new ANNidx[nNear_];
dists_ = new ANNdist[nNear_];
//! Set kdtree
void SetkdTree(geom_t vec) {
npts_ = vec.size();
dataPts_ = annAllocPts(npts_, dim_);
if(dataPts_ == NULL) throw LagSHTError("ANN Failure dataPts alloc");
for(int i=0;i<npts_;i++){
ANNpoint p = dataPts_[i];
p[0] = vec[i].first;
p[1] = vec[i].second;
kdTree_ = new ANNkd_tree(dataPts_,npts_,dim_);
if(kdTree_ == NULL) throw LagSHTError("ANN Failure kdTree alloc");
//! Destructor
virtual ~ANNServer() {
if (dataPts_) annDeallocPts(dataPts_);
if (nnIdx_) delete [] nnIdx_;
if (dists_) delete [] dists_;
if (kdTree_) delete kdTree_;
//! Get the index of the closet point (theta, phi)
int GetClosestId(r_8 theta, r_8 phi) const {
ANNpoint queryPt;
queryPt = annAllocPt(dim_);
#if DEBUG >=1
if(queryPt == NULL) throw LagSHTError("Get Failure queryPt alloc");
queryPt[0] = theta;
queryPt[1] = phi;
#if DEBUG >=1
if (kdTree_ == NULL) throw LagSHTError("Get Failure kdTree alloc");
if (nnIdx_ == NULL) throw LagSHTError("Get Failure nnIdx alloc");
if (dists_ == NULL) throw LagSHTError("Get Failure dists alloc");
return nnIdx_[0]; //first closest
int nNear_; //<! nomber of solution to the closest point
int dim_; //<! dimsion of the point space
r_8 eps_; //<! error bound
int npts_; //<! number of points to fill the kdTree
ANNkd_tree* kdTree_; //<! the tree
ANNidxArray nnIdx_; //<! near neighbor indices
ANNdistArray dists_; //<! near neighbor distances
ANNpointArray dataPts_; //<! the initial grid points
}//end namespace
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment