собсна, вот код:
Код | const int db = 10; const int len = 10; const int xsize = 1000; const int ysize = 1000; const int degsize = 360;
using namespace cv; using namespace std;
int myc(double d) { double i; if (modf(d,&i)>0.5) return ceil(d); else return floor(d); } class PPoint { private: public: int x,y; int angle; PPoint(int _x, int _y, int _an) { x = _x; y = _y; angle = _an; }
};
class graf { private: int mymap[ysize][xsize]; int state[ysize][xsize][degsize]; vector <vector< pair<int,int> > > g; int id; vector<PPoint> points; public: graf() { int i=1; } void calcDst(PPoint &p) { double an1, an2; double x1, y1, x2, y2; an1 = p.angle - db; an2 = p.angle+ db; x1 = cos(toRad(an1))*len + p.x; y1 = sin(toRad(an1))*len + p.y; x2 = cos(toRad(an2))*len + p.x; y2 = sin(toRad(an2))*len + p.y; double xmin, xmax, ymin, ymax; vector<Point2f> vect; vect.push_back(Point2f(p.x, p.y)); vect.push_back(Point2f(x1, y1)); vect.push_back(Point2f(x2, y2)); xmin = min(min(p.x, x1), x2);xmin=max(xmin, 0); ymin = min(min(p.y, y1), y2);ymin=max(ymin, 0); xmax = max(max(p.x, x1), x2);xmin=min(xmin, xsize-1); ymax = max(max(p.y, y1), y2);ymin=min(ymin, ysize-1); int i, imax, j, jmax; Mat mt = Mat(vect); double gamma, beta, dr; int deg; for(i = ceil(ymin); i < floor(ymax); i++)//y for(j = ceil(xmin); j < floor(xmax); j++)//x { if (pointPolygonTest(mt, Point2f(j, i), false) > 0 && mymap[i][j] == 1) { //inside gamma = atan(double(i-p.y)/(j-p.x)); beta = p.angle - toDeg(gamma); if (fabs(beta) > db) { gamma += M_PI; beta = p.angle - toDeg(gamma); } dr = fabs(beta)*2; deg = myc(dr); if (state[i][j][deg] == 0) {
[color=red]points.push_back(PPoint(j, i, deg));[/color]//тут красный int num = points.size()-1; state[i][j][deg] = 1; g[id].push_back(pair<int, int>(num, 1)); }
} dr=0; } }
void calcGraf() { int i, j; for(i = 0; i < ysize; i++) { for(j = 0; j < xsize; j++) mymap[i][j] = 1; } id = 0; vector<pair<int, int> > p; g.push_back(p); points.push_back(PPoint(50,50, 0)); calcDst(points[0]); id++; while(id != points.size()) { calcDst(points[id]); id++; } } }; graf g1;
int _tmain(int argc, _TCHAR* argv[]) { g1.calcGraf(); return 0; }
|
совершенно непонятное поведение на красной строчке. после того, как в вектор points заносится новый объект PPoint, портится переменная p. все три ее поля получают одно непонятно откуда взявшееся число (типа -1225435). почему так? мы ведь делаем пуш и он не должен трогать другие значения вектора.с моей точки зрения все корректно, нужен свежий взгляд |