GENIEGenerator
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Public Member Functions | Private Member Functions | List of all members
genie::BLI2DUnifGrid Class Reference

Bilinear interpolation of 2D functions on a regular grid. More...

#include <BLI2D.h>

Inheritance diagram for genie::BLI2DUnifGrid:
Inheritance graph
[legend]
Collaboration diagram for genie::BLI2DUnifGrid:
Collaboration graph
[legend]

Public Member Functions

 BLI2DUnifGrid ()
 
 BLI2DUnifGrid (int nx, double xmin, double xmax, int ny, double ymin, double ymax)
 
 BLI2DUnifGrid (int nx, int ny, double *x, double *y, double *z)
 
bool AddPoint (double x, double y, double z)
 
double Evaluate (double x, double y) const
 
- Public Member Functions inherited from genie::BLI2DGrid
 BLI2DGrid ()
 
virtual ~BLI2DGrid ()
 
double XMin (void) const
 
double XMax (void) const
 
double YMin (void) const
 
double YMax (void) const
 
double ZMin (void) const
 
double ZMax (void) const
 

Private Member Functions

void Init (int nx=0, double xmin=0, double xmax=0, int ny=0, double ymin=0, double ymax=0)
 

Additional Inherited Members

- Protected Member Functions inherited from genie::BLI2DGrid
int IdxZ (int ix, int iy) const
 
- Protected Attributes inherited from genie::BLI2DGrid
int fNX
 
int fNY
 
int fNZ
 
double * fX
 
double * fY
 
double * fZ
 
double fDX
 
double fDY
 
double fXmin
 
double fXmax
 
double fYmin
 
double fYmax
 
double fZmin
 
double fZmax
 

Detailed Description

Bilinear interpolation of 2D functions on a regular grid.

Author
Costas Andreopoulos <c.andreopoulos cern.ch> University of Liverpool
Created:
May 30, 2009
License:
Copyright (c) 2003-2024, The GENIE Collaboration For the full text of the license visit http://copyright.genie-mc.org

Definition at line 75 of file BLI2D.h.

Constructor & Destructor Documentation

BLI2DUnifGrid::BLI2DUnifGrid ( )

Definition at line 45 of file BLI2D.cxx.

References Init().

46 {
47  this->Init();
48 }
void Init(int nx=0, double xmin=0, double xmax=0, int ny=0, double ymin=0, double ymax=0)
Definition: BLI2D.cxx:130
BLI2DUnifGrid::BLI2DUnifGrid ( int  nx,
double  xmin,
double  xmax,
int  ny,
double  ymin,
double  ymax 
)

Definition at line 50 of file BLI2D.cxx.

References Init().

52 {
53  this->Init(nx, xmin, xmax, ny, ymin, ymax);
54 }
void Init(int nx=0, double xmin=0, double xmax=0, int ny=0, double ymin=0, double ymax=0)
Definition: BLI2D.cxx:130
BLI2DUnifGrid::BLI2DUnifGrid ( int  nx,
int  ny,
double *  x,
double *  y,
double *  z 
)

Definition at line 56 of file BLI2D.cxx.

References AddPoint(), genie::BLI2DGrid::IdxZ(), and Init().

58 {
59  double xmin = x[0];
60  double xmax = x[nx-1];
61  double ymin = y[0];
62  double ymax = y[nx-1];
63 
64  this->Init(nx, xmin, xmax, ny, ymin, ymax);
65 
66  for(int ix=0; ix<nx; ix++) {
67  for(int iy=0; iy<ny; iy++) {
68  this->AddPoint(x[ix], y[iy], z[this->IdxZ(ix,iy)]);
69  }
70  }
71 }
void Init(int nx=0, double xmin=0, double xmax=0, int ny=0, double ymin=0, double ymax=0)
Definition: BLI2D.cxx:130
bool AddPoint(double x, double y, double z)
Definition: BLI2D.cxx:73
int IdxZ(int ix, int iy) const
Definition: BLI2D.cxx:36

Member Function Documentation

bool BLI2DUnifGrid::AddPoint ( double  x,
double  y,
double  z 
)
virtual

Implements genie::BLI2DGrid.

Definition at line 73 of file BLI2D.cxx.

References genie::BLI2DGrid::fDX, genie::BLI2DGrid::fDY, genie::BLI2DGrid::fXmin, genie::BLI2DGrid::fYmin, genie::BLI2DGrid::fZ, genie::BLI2DGrid::fZmax, genie::BLI2DGrid::fZmin, genie::BLI2DGrid::IdxZ(), LOG, and pDEBUG.

Referenced by BLI2DUnifGrid(), and main().

74 {
75  int ix = TMath::FloorNint( (x - fXmin + fDX/2) / fDX );
76  int iy = TMath::FloorNint( (y - fYmin + fDY/2) / fDY );
77  int iz = this->IdxZ(ix,iy);
78 
79  fZ[iz] = z;
80 
81  fZmin = TMath::Min(z, fZmin);
82  fZmax = TMath::Max(z, fZmax);
83 
84  LOG("BLI2DUnifGrid", pDEBUG)
85  << "Added x = " << x << " (ix = " << ix << ")"
86  << " y = " << y << " (iy = " << iy << ") -> "
87  << " z = " << z << " (iz = " << iz << ")";
88 
89  return true;
90 }
double fXmin
Definition: BLI2D.h:62
double fZmax
Definition: BLI2D.h:67
double fDX
Definition: BLI2D.h:60
double fDY
Definition: BLI2D.h:61
#define LOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a string (using the FILE...
Definition: Messenger.h:96
int IdxZ(int ix, int iy) const
Definition: BLI2D.cxx:36
double fYmin
Definition: BLI2D.h:64
double fZmin
Definition: BLI2D.h:66
double * fZ
Definition: BLI2D.h:59
#define pDEBUG
Definition: Messenger.h:63
double BLI2DUnifGrid::Evaluate ( double  x,
double  y 
) const
virtual

Implements genie::BLI2DGrid.

Definition at line 92 of file BLI2D.cxx.

References genie::BLI2DGrid::fDX, genie::BLI2DGrid::fDY, genie::BLI2DGrid::fX, genie::BLI2DGrid::fXmax, genie::BLI2DGrid::fXmin, genie::BLI2DGrid::fY, genie::BLI2DGrid::fYmax, genie::BLI2DGrid::fYmin, genie::BLI2DGrid::fZ, and genie::BLI2DGrid::IdxZ().

Referenced by main().

93 {
94  if(x < fXmin || x > fXmax) return 0.;
95  if(y < fYmin || y > fYmax) return 0.;
96 
97  int ix_lo = TMath::FloorNint( (x - fXmin) / fDX );
98  int iy_lo = TMath::FloorNint( (y - fYmin) / fDY );
99  int ix_hi = ix_lo + 1;
100  int iy_hi = iy_lo + 1;
101 
102  double x1 = fX[ix_lo];
103  double x2 = fX[ix_hi];
104  double y1 = fY[iy_lo];
105  double y2 = fY[iy_hi];
106 
107  double z11 = fZ[ this->IdxZ(ix_lo,iy_lo) ];
108  double z21 = fZ[ this->IdxZ(ix_hi,iy_lo) ];
109  double z12 = fZ[ this->IdxZ(ix_lo,iy_hi) ];
110  double z22 = fZ[ this->IdxZ(ix_hi,iy_hi) ];
111 
112  double z1 = z11 * (x2-x)/(x2-x1) + z21 * (x-x1)/(x2-x1);
113  double z2 = z12 * (x2-x)/(x2-x1) + z22 * (x-x1)/(x2-x1);
114  double z = z1 * (y2-y)/(y2-y1) + z2 * (y-y1)/(y2-y1);
115 
116 /*
117  LOG("BLI2DUnifGrid", pDEBUG) << "x = " << x << " -> nearby nodes: " << x1 << ", " << x2;
118  LOG("BLI2DUnifGrid", pDEBUG) << "y = " << y << " -> nearby nodes: " << y1 << ", " << y2;
119  LOG("BLI2DUnifGrid", pDEBUG) << "z11 := z(" << this->IdxZ(ix_lo,iy_lo) << ") = " << z11;
120  LOG("BLI2DUnifGrid", pDEBUG) << "z21 := z(" << this->IdxZ(ix_hi,iy_lo) << ") = " << z21;
121  LOG("BLI2DUnifGrid", pDEBUG) << "z12 := z(" << this->IdxZ(ix_lo,iy_hi) << ") = " << z12;
122  LOG("BLI2DUnifGrid", pDEBUG) << "z22 := z(" << this->IdxZ(ix_hi,iy_hi) << ") = " << z22;
123  LOG("BLI2DUnifGrid", pDEBUG) << "z1 = " << z1 << ", z2 = " << z2;
124  LOG("BLI2DUnifGrid", pDEBUG) << "interpolated z(x,y) = " << z;
125 */
126 
127  return z;
128 }
double fXmin
Definition: BLI2D.h:62
double fYmax
Definition: BLI2D.h:65
double * fY
Definition: BLI2D.h:58
double * fX
Definition: BLI2D.h:57
double fDX
Definition: BLI2D.h:60
double fDY
Definition: BLI2D.h:61
int IdxZ(int ix, int iy) const
Definition: BLI2D.cxx:36
double fYmin
Definition: BLI2D.h:64
double fXmax
Definition: BLI2D.h:63
double * fZ
Definition: BLI2D.h:59
void BLI2DUnifGrid::Init ( int  nx = 0,
double  xmin = 0,
double  xmax = 0,
int  ny = 0,
double  ymin = 0,
double  ymax = 0 
)
privatevirtual

Implements genie::BLI2DGrid.

Definition at line 130 of file BLI2D.cxx.

References genie::BLI2DGrid::fDX, genie::BLI2DGrid::fDY, genie::BLI2DGrid::fNX, genie::BLI2DGrid::fNY, genie::BLI2DGrid::fNZ, genie::BLI2DGrid::fX, genie::BLI2DGrid::fXmax, genie::BLI2DGrid::fXmin, genie::BLI2DGrid::fY, genie::BLI2DGrid::fYmax, genie::BLI2DGrid::fYmin, genie::BLI2DGrid::fZ, genie::BLI2DGrid::fZmax, and genie::BLI2DGrid::fZmin.

Referenced by BLI2DUnifGrid().

132 {
133  fNX = 0;
134  fNY = 0;
135  fNZ = 0;
136  fXmin = 0.;
137  fXmax = 0.;
138  fYmin = 0.;
139  fYmax = 0.;
140  fZmin = std::numeric_limits<double>::max();
141  fZmax = std::numeric_limits<double>::min();
142  fDX = 0.;
143  fDY = 0.;
144  fX = 0;
145  fY = 0;
146  fZ = 0;
147 
148  if(nx>1 && ny>1) {
149  fNX = nx;
150  fNY = ny;
151  fNZ = nx * ny;
152 
153  fXmin = xmin;
154  fXmax = xmax;
155  fYmin = ymin;
156  fYmax = ymax;
157  fZmin = std::numeric_limits<double>::max();
158  fZmax = std::numeric_limits<double>::min();
159 
160  fDX = (xmax-xmin)/(nx-1);
161  fDY = (ymax-ymin)/(ny-1);
162 
163  fX = new double[fNX];
164  fY = new double[fNY];
165  fZ = new double[fNZ];
166 
167  for(int i=0; i<fNX; i++) { fX[i] = xmin + i*fDX; }
168  for(int i=0; i<fNY; i++) { fY[i] = ymin + i*fDY; }
169  for(int i=0; i<fNZ; i++) { fZ[i] = 0.; }
170  }
171 }
double fXmin
Definition: BLI2D.h:62
double fYmax
Definition: BLI2D.h:65
double * fY
Definition: BLI2D.h:58
double fZmax
Definition: BLI2D.h:67
double * fX
Definition: BLI2D.h:57
double fDX
Definition: BLI2D.h:60
double fDY
Definition: BLI2D.h:61
double fYmin
Definition: BLI2D.h:64
double fXmax
Definition: BLI2D.h:63
double fZmin
Definition: BLI2D.h:66
double * fZ
Definition: BLI2D.h:59

The documentation for this class was generated from the following files: