worked on 3d models within map
adjusted grid factory adjusted nav mesh factory minoor changes/fixes new helper classes refactoring
This commit is contained in:
53
math/stats/Histogram2.h
Normal file
53
math/stats/Histogram2.h
Normal file
@@ -0,0 +1,53 @@
|
||||
#ifndef HISTOGRAM2_H
|
||||
#define HISTOGRAM2_H
|
||||
|
||||
#include <vector>
|
||||
#include "../../geo/BBox2.h"
|
||||
|
||||
namespace Stats {
|
||||
|
||||
/** 2D histogram */
|
||||
template <typename Scalar> class Histogram2 {
|
||||
|
||||
std::vector<Scalar> vec;
|
||||
BBox2 bbox;
|
||||
int binsX;
|
||||
int binsY;
|
||||
|
||||
public:
|
||||
|
||||
/** ctor */
|
||||
Histogram2(BBox2 bbox, int binsX, int binsY) : bbox(bbox), binsX(binsX), binsY(binsY) {
|
||||
vec.resize(binsX*binsY);
|
||||
}
|
||||
|
||||
Scalar get(Scalar x, Scalar y) const {
|
||||
const int idx = binIdx(x,y);
|
||||
return vec[idx];
|
||||
}
|
||||
|
||||
void add(Scalar x, Scalar y, Scalar val) {
|
||||
const int idx = binIdx(x,y);
|
||||
vec[idx] += val;
|
||||
}
|
||||
|
||||
int binIdx(const Scalar x, const Scalar y) {
|
||||
const int ix = binIdxX(x);
|
||||
const int iy = binIdxY(y);
|
||||
return ix + iy*binsX;
|
||||
}
|
||||
|
||||
int binIdxX(const Scalar val) const {
|
||||
return (val - bbox.getMin().x) / (bbox.getSize().x) * binsX;
|
||||
}
|
||||
|
||||
int binIdxY(const Scalar val) const {
|
||||
return (val - bbox.getMin().y) / (bbox.getSize().y) * binsY;
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // HISTOGRAM2_H
|
||||
Reference in New Issue
Block a user