source: issm/oecreview/Archive/18296-19100/ISSM-18914-18915.diff

Last change on this file was 19102, checked in by Mathieu Morlighem, 10 years ago

NEW: added 18296-19100

File size: 1.9 KB
  • ../trunk-jpl/src/c/classes/kriging/Observations.cpp

     
    627627    double *obs          = NULL;
    628628    Observation observation=Observation(x_interp,y_interp,0.);
    629629    std::vector<Observation> kNN;
    630    
    631     /*If radius is not provided or is 0, return all observations*/
    632     if(radius==0.)
    633     {
    634         kNN=(this->covertree->getRoot())->getObservations();
    635     }
    636     else
    637     {
    638         kNN=(this->covertree->kNearestNeighbors(observation, maxdata));
    639                 //cout << "kNN's size: " << kNN.size() << endl;
    640                
    641     }
     630
     631         kNN=(this->covertree->kNearestNeighbors(observation, maxdata));
     632         //cout << "kNN's size: " << kNN.size() << endl;
    642633       
    643634        //kNN is sort from closest to farthest neighbor
    644635        //searches for the first neighbor that is out of radius
    645636        //deletes and resizes the kNN vector
    646637        vector<Observation>::iterator it;
    647         for (it = kNN.begin(); it != kNN.end(); ++it) {
    648                 //(*it).print();
    649                 //cout << "\n" << (*it).distance(observation) << endl;
    650                 if ((*it).distance(observation) > radius) {
    651                         break;
     638        if(radius>0.){
     639                for (it = kNN.begin(); it != kNN.end(); ++it) {
     640                        //(*it).print();
     641                        //cout << "\n" << (*it).distance(observation) << endl;
     642                        if ((*it).distance(observation) > radius) {
     643                                break;
     644                        }
    652645                }
     646                kNN.erase(it, kNN.end());
    653647        }
    654         kNN.erase(it, kNN.end());
    655648   
    656649        /*Allocate vectors*/
    657650        x   = new double[kNN.size()];
     
    660653
    661654        /*Loop over all observations and fill in x, y and obs*/
    662655        int i = 0;
    663         for (it = kNN.begin(); it != kNN.end(); ++it) {
     656        for(it = kNN.begin(); it != kNN.end(); ++it) {
    664657                (*it).WriteXYObs((*it), &x[i], &y[i], &obs[i]);
    665658                i++;
    666659        }
     
    668661    *px=x;
    669662    *py=y;
    670663    *pobs=obs;
    671         *pnobs = kNN.size();
     664         *pnobs = kNN.size();
    672665}/*}}}*/
Note: See TracBrowser for help on using the repository browser.