Ice Sheet System Model  4.18
Code documentation
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
Public Member Functions | Data Fields
Quadtree::QuadtreeBox Class Reference
Inheritance diagram for Quadtree::QuadtreeBox:
Object

Public Member Functions

Objectcopy ()
 
void DeepEcho ()
 
void Echo ()
 
int Id ()
 
void Marshall (char **pmarshalled_data, int *pmarshalled_data_size, int marshall_direction)
 
int ObjectEnum ()
 
int IsWithinRange (double x, double y, double range)
 
void RangeSearch (int *indices, int *pnobs, double x, double y, double range)
 
void WriteObservations (int *indices, int *pnobs)
 
- Public Member Functions inherited from Object
virtual ~Object ()
 

Data Fields

int nbitems
 
double xcenter
 
double ycenter
 
double length
 
union {
   QuadtreeBox *   box [4]
 
   Observation *   obs [4]
 
}; 
 

Detailed Description

Definition at line 16 of file Quadtree.h.

Member Function Documentation

◆ copy()

Object * Quadtree::QuadtreeBox::copy ( void  )
virtual

Implements Object.

Definition at line 491 of file Quadtree.cpp.

491  {/*{{{*/
492 
493  QuadtreeBox* qtreebox = new QuadtreeBox(*this);
494 
495  for (int i=0; i<4; ++i){
496  if(this->box[i]) qtreebox->box[i] = reinterpret_cast<QuadtreeBox*>(this->box[i]->copy());
497  else qtreebox->box[i] = NULL;
498  }
499  for (int i=0; i<4; ++i){
500  if(this->obs[i]) qtreebox->obs[i] = reinterpret_cast<Observation*>(this->obs[i]->copy());
501  else qtreebox->obs[i] = NULL;
502  }
503 
504  return (Object*) qtreebox;
505 }

◆ DeepEcho()

void Quadtree::QuadtreeBox::DeepEcho ( void  )
inlinevirtual

Implements Object.

Definition at line 29 of file Quadtree.h.

29 {_error_("not implemented yet"); };

◆ Echo()

void Quadtree::QuadtreeBox::Echo ( void  )
virtual

Implements Object.

Definition at line 507 of file Quadtree.cpp.

507  {/*{{{*/
508 
509  _printf_("QuadtreeBox:\n");
510  _printf_(" nbitems = " << this->nbitems << "\n");
511  _printf_(" xcenter = " << this->xcenter << "\n");
512  _printf_(" ycenter = " << this->ycenter << "\n");
513  _printf_(" length = " << this->length << "\n");
514 
515 }/*}}}*/

◆ Id()

int Quadtree::QuadtreeBox::Id ( void  )
inlinevirtual

Implements Object.

Definition at line 31 of file Quadtree.h.

31 {_error_("not implemented yet"); };

◆ Marshall()

void Quadtree::QuadtreeBox::Marshall ( char **  pmarshalled_data,
int *  pmarshalled_data_size,
int  marshall_direction 
)
inlinevirtual

Implements Object.

Definition at line 32 of file Quadtree.h.

32 { _error_("not implemented yet!");};

◆ ObjectEnum()

int Quadtree::QuadtreeBox::ObjectEnum ( void  )
inlinevirtual

Implements Object.

Definition at line 33 of file Quadtree.h.

33 {_error_("not implemented yet"); };

◆ IsWithinRange()

int Quadtree::QuadtreeBox::IsWithinRange ( double  x,
double  y,
double  range 
)

Definition at line 516 of file Quadtree.cpp.

516  {/*{{{*/
517 
518  /*Return 0 if the 2 boxes do not overlap*/
519  if(this->xcenter+this->length/2 < x-range) return 0;
520  if(this->xcenter-this->length/2 > x+range) return 0;
521  if(this->ycenter+this->length/2 < y-range) return 0;
522  if(this->ycenter-this->length/2 > y+range) return 0;
523 
524  /*Return 2 if the this box is included in the range*/
525  if(this->xcenter+this->length/2 <= x+range &&
526  this->ycenter+this->length/2 <= y+range &&
527  this->xcenter-this->length/2 >= x-range &&
528  this->ycenter-this->length/2 >= y-range) return 2;
529 
530  /*This is a simple overlap*/
531  return 1;
532 
533 }/*}}}*/

◆ RangeSearch()

void Quadtree::QuadtreeBox::RangeSearch ( int *  indices,
int *  pnobs,
double  x,
double  y,
double  range 
)

Definition at line 534 of file Quadtree.cpp.

534  {/*{{{*/
535 
536  /*Intermediaries*/
537  int i,nobs;
538 
539  /*Recover current number of observations*/
540  nobs = *pnobs;
541 
542  switch(this->IsWithinRange(x,y,range)){
543  case 0:
544  /*If this box is not within range, return*/
545  break;
546  case 2:
547  /*This box is included in range*/
548  this->WriteObservations(indices,&nobs);
549  break;
550  case 1:
551  /*This box is partly included*/
552  if(this->nbitems>0){
553  /*If this box has only observations, add indices that are within range*/
554  for(i=0;i<this->nbitems;i++){
555  if(fabs(this->obs[i]->x-x) <= range && fabs(this->obs[i]->y-y) <= range){
556  indices[nobs++]=this->obs[i]->index;
557  }
558  }
559  }
560  else{
561  /*This box points toward boxes*/
562  if(this->box[0]) this->box[0]->RangeSearch(indices,&nobs,x,y,range);
563  if(this->box[1]) this->box[1]->RangeSearch(indices,&nobs,x,y,range);
564  if(this->box[2]) this->box[2]->RangeSearch(indices,&nobs,x,y,range);
565  if(this->box[3]) this->box[3]->RangeSearch(indices,&nobs,x,y,range);
566  }
567  break;
568  default:
569  _error_("Case " << this->IsWithinRange(x,y,range) << " not supported");
570  }
571 
572  /*Assign output pointers: */
573  *pnobs=nobs;
574 }/*}}}*/

◆ WriteObservations()

void Quadtree::QuadtreeBox::WriteObservations ( int *  indices,
int *  pnobs 
)

Definition at line 575 of file Quadtree.cpp.

575  {/*{{{*/
576 
577  /*Intermediaries*/
578  int i,nobs;
579 
580  /*Recover current number of observations*/
581  nobs = *pnobs;
582 
583  if(this->nbitems>0){
584  /*If this box has only observations, add all indices*/
585  for(i=0;i<this->nbitems;i++){
586  indices[nobs++]=this->obs[i]->index;
587  }
588  }
589  else{
590  /*This box points toward boxes, */
591  if(this->box[0]) this->box[0]->WriteObservations(indices,&nobs);
592  if(this->box[1]) this->box[1]->WriteObservations(indices,&nobs);
593  if(this->box[2]) this->box[2]->WriteObservations(indices,&nobs);
594  if(this->box[3]) this->box[3]->WriteObservations(indices,&nobs);
595  }
596 
597  /*Assign output pointers: */
598  *pnobs=nobs;
599 }/*}}}*/

Field Documentation

◆ nbitems

int Quadtree::QuadtreeBox::nbitems

Definition at line 18 of file Quadtree.h.

◆ xcenter

double Quadtree::QuadtreeBox::xcenter

Definition at line 19 of file Quadtree.h.

◆ ycenter

double Quadtree::QuadtreeBox::ycenter

Definition at line 20 of file Quadtree.h.

◆ length

double Quadtree::QuadtreeBox::length

Definition at line 21 of file Quadtree.h.

◆ box

QuadtreeBox* Quadtree::QuadtreeBox::box[4]

Definition at line 23 of file Quadtree.h.

◆ obs

Observation* Quadtree::QuadtreeBox::obs[4]

Definition at line 24 of file Quadtree.h.

◆ @1

union { ... }

The documentation for this class was generated from the following files:
Quadtree::QuadtreeBox::copy
Object * copy()
Definition: Quadtree.cpp:491
Observation
Definition: Observation.h:10
Quadtree::QuadtreeBox::ycenter
double ycenter
Definition: Quadtree.h:20
_printf_
#define _printf_(StreamArgs)
Definition: Print.h:22
Quadtree::QuadtreeBox::IsWithinRange
int IsWithinRange(double x, double y, double range)
Definition: Quadtree.cpp:516
Quadtree::QuadtreeBox::obs
Observation * obs[4]
Definition: Quadtree.h:24
Object
Definition: Object.h:13
Observation::index
int index
Definition: Observation.h:15
Quadtree::QuadtreeBox::length
double length
Definition: Quadtree.h:21
Quadtree::QuadtreeBox::box
QuadtreeBox * box[4]
Definition: Quadtree.h:23
Quadtree::QuadtreeBox::RangeSearch
void RangeSearch(int *indices, int *pnobs, double x, double y, double range)
Definition: Quadtree.cpp:534
_error_
#define _error_(StreamArgs)
Definition: exceptions.h:49
Quadtree::QuadtreeBox::nbitems
int nbitems
Definition: Quadtree.h:18
Quadtree::QuadtreeBox::WriteObservations
void WriteObservations(int *indices, int *pnobs)
Definition: Quadtree.cpp:575
Quadtree::QuadtreeBox::xcenter
double xcenter
Definition: Quadtree.h:19
Observation::copy
Object * copy()
Definition: Observation.cpp:43