PositionBased2dValueGenerator.cpp

Go to the documentation of this file.
00001 
00012 #include "PositionBased2dValueGenerator.h"
00013 
00014 #include <iostream>
00015 using std::cout;
00016 using std::cerr;
00017 using std::endl;
00018 
00019 
00020 PositionBased2dValueGenerator::PositionBased2dValueGenerator(const vector<double> &values, int size_x, int size_y, 
00021     double offset_x, double offset_y, double scale_x, double scale_y)
00022     : values(values), size_x(size_x), size_y(size_y)
00023     , offset_x(offset_x), offset_y(offset_y)
00024     , scale_x(scale_x), scale_y(scale_y) 
00025 {       
00026 }
00027 
00028 
00029 PositionBased2dValueGenerator::~PositionBased2dValueGenerator()
00030 {
00031 }
00032 
00033 
00034 double PositionBased2dValueGenerator::generate(RandomEngine *rnd)
00035 {
00036         Point3D<double> pos = m_pop->getLocation(m_idx);
00037     
00038     int x = (int)round((pos.x()+offset_x)*scale_x);
00039     int y = (int)round((pos.y()+offset_y)*scale_y);
00040 
00041     if (x<0)
00042         x=0;
00043     if (x>=size_x)
00044         x=size_x-1;
00045          
00046     if (y<0) 
00047         y=0;
00048     if (y>=size_y) 
00049         y=size_y-1;
00050         
00051 //    int index = y*size_x + x;
00052 //    cout << "index:" << index << ", x:" << x << ", y:" << y << ", pos.x:" << pos.x() << ", pos.y:" << pos.y() << endl;    
00053     return values[y*size_x+x];
00054 }
00055 
00056 
00057 
00058 PopObjectValueGenerator* PositionBased2dValueGenerator::clone(void) const
00059 {
00060     return new PositionBased2dValueGenerator(values, size_x, size_y, offset_x, offset_y, scale_x, scale_y);
00061 }

Generated on Wed Jul 9 16:34:37 2008 for PCSIM by  doxygen 1.5.5