Changeset 12226


Ignore:
Timestamp:
05/08/12 13:35:24 (13 years ago)
Author:
Mathieu Morlighem
Message:

Added boxlength option

Location:
issm/trunk-jpl/src/c
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • issm/trunk-jpl/src/c/Container/Observations.cpp

    r12225 r12226  
    3232}
    3333/*}}}*/
    34 /*FUNCTION Observations::Observations(double* observations_list,double* x,double* y,int n){{{*/
    35 Observations::Observations(double* observations_list,double* x,double* y,int n){
     34/*FUNCTION Observations::Observations(double* observations_list,double* x,double* y,int n,Options* options){{{*/
     35Observations::Observations(double* observations_list,double* x,double* y,int n,Options* options){
    3636
    3737        /*Intermediaries*/
    38         int          i;
     38        int          i,maxdepth;
    3939        int          xi,yi;
    4040        double       xmin,xmax,ymin,ymax;
    41         double       offset;
     41        double       offset,minlength;
    4242        Observation *observation = NULL;
    4343
     
    5252        offset=0.05*(ymax-ymin); ymin-=offset; ymax+=offset;
    5353
     54        /*Get Minimum box size*/
     55        if(options->GetOption("boxlength")){
     56                options->Get(&minlength,"boxlength");
     57                if(minlength<=0)_error_("boxlength should be a positive number");
     58                maxdepth=int(log(max(xmax-xmin,ymax-ymin)/minlength +1)/log(2));
     59        }
     60        else{
     61                maxdepth = 30;
     62                minlength=max(xmax-xmin,ymax-ymin)/double((1L<<maxdepth)-1);
     63        }
     64
     65
    5466        /*Initialize Quadtree*/
    55         this->quadtree = new Quadtree(xmin,xmax,ymin,ymax,30);
     67        printf("Generating quadtree with a maximum box size %g (depth=%i)...",minlength,maxdepth);
     68        this->quadtree = new Quadtree(xmin,xmax,ymin,ymax,maxdepth);
    5669
    5770        /*Add observations one by one*/
     71        int level;
    5872        for(i=0;i<n;i++){
    5973                this->quadtree->IntergerCoordinates(&xi,&yi,x[i],y[i]);
    60                 observation = new Observation(x[i],y[i],xi,yi,observations_list[i]);
    61                 this->quadtree->Add(observation);
    62                 this->AddObject(observation);
     74                this->quadtree->QuadtreeDepth2(&level,xi,yi);
     75                if((int)level >= maxdepth){
     76                }
     77                else{
     78                        observation = new Observation(x[i],y[i],xi,yi,observations_list[i]);
     79                        this->quadtree->Add(observation);
     80                        this->AddObject(observation);
     81                }
    6382        }
     83        printf("done\n");
    6484}
    6585/*}}}*/
     
    105125void Observations::QuadtreeColoring(double* A,double *x,double *y,int n){
    106126
    107         int xi,yi;
     127        int xi,yi,level;
    108128
    109129        for(int i=0;i<n;i++){
    110130                this->quadtree->IntergerCoordinates(&xi,&yi,x[i],y[i]);
    111                 this->quadtree->QuadtreeColoring(&A[i],xi,yi);
     131                this->quadtree->QuadtreeDepth(&level,xi,yi);
     132                A[i]=(double)level;
    112133        }
    113134
  • issm/trunk-jpl/src/c/Container/Observations.h

    r12225 r12226  
    88class Obsevration;
    99class Quadtree;
     10class Options;
    1011
    1112class Observations: public DataSet{
     
    1819                /*constructors, destructors*/
    1920                Observations();
    20                 Observations(double* observations_list,double* x,double* y,int n);
     21                Observations(double* observations_list,double* x,double* y,int n,Options* options);
    2122                ~Observations();
    2223
  • issm/trunk-jpl/src/c/modules/Krigingx/Krigingx.cpp

    r12213 r12226  
    4040
    4141        /*Process observation dataset*/
    42         observations=new Observations(obs_list,obs_x,obs_y,obs_length);
     42        observations=new Observations(obs_list,obs_x,obs_y,obs_length,options);
    4343
    4444        /*Allocation output*/
  • issm/trunk-jpl/src/c/objects/Kriging/Quadtree.cpp

    r12225 r12226  
    312312        return newbox;
    313313}/*}}}*/
    314 /*FUNCTION Quadtree::QuadtreeColoring{{{1*/
    315 void Quadtree::QuadtreeColoring(double* A,int xi,int yi){
     314/*FUNCTION Quadtree::QuadtreeDepth{{{1*/
     315void Quadtree::QuadtreeDepth(int* A,int xi,int yi){
    316316
    317317        QuadtreeBox **pbox = NULL;
     
    336336                /*This box is not empty, add one level*/
    337337                level+=1;
     338        }
     339
     340        *A=level;
     341}/*}}}*/
     342/*FUNCTION Quadtree::QuadtreeDepth2{{{1*/
     343void Quadtree::QuadtreeDepth2(int* A,int xi,int yi){
     344
     345        QuadtreeBox **pbox = NULL;
     346        QuadtreeBox  *box  = NULL;
     347        int           level,levelbin;
     348
     349        /*Initialize levels*/
     350        level    = 0;
     351        levelbin = (1L<<this->MaxDepth);// = 2^30
     352
     353        /*Get inital box (the largest)*/
     354        pbox=&root;
     355
     356        /*Find the smallest box where this point is located*/
     357        while((box=*pbox) && (box->nbitems<0)){
     358
     359                levelbin>>=1; level+=1;
     360
     361                pbox = &box->box[IJ(xi,yi,levelbin)];
     362        }
     363        if(box && box->nbitems>0){
     364                /*This box is not empty, add one level*/
     365                level+=1;
     366        }
     367
     368        /*If we were to add the vertex, get level*/
     369        if(box && box->nbitems==4){
     370                int ij;
     371                bool flag=true;
     372                while(flag){
     373
     374                        levelbin>>=1; level+=1;
     375                        if(level>this->MaxDepth){
     376                                level+=1;
     377                                break;
     378                        }
     379
     380                        /*loop over the four observations*/
     381                        ij=IJ(box->obs[0]->xi,box->obs[0]->yi,levelbin);
     382                        for (int k=1;k<4;k++){
     383                                if(IJ(box->obs[k]->xi,box->obs[k]->yi,levelbin) != ij){
     384                                        flag = false;
     385                                }
     386                        }
     387                        if(IJ(xi,yi,levelbin)!=ij){
     388                                flag = false;
     389                        }
     390                }
    338391        }
    339392
  • issm/trunk-jpl/src/c/objects/Kriging/Quadtree.h

    r12225 r12226  
    5353                QuadtreeBox *NewQuadtreeBox(double xcenter,double ycenter,double length);
    5454                QuadtreeBox *NewQuadtreeBox(QuadtreeBox* master,int index);
    55                 void         QuadtreeColoring(double *A,int xi,int yi);
     55                void         QuadtreeDepth(int *A,int xi,int yi);
     56                void         QuadtreeDepth2(int *A,int xi,int yi);
    5657};
    5758#endif //_QUADTREEK_H
Note: See TracChangeset for help on using the changeset viewer.