There are two errors in your code:
- You are never calling
CreateGrid()
(Grid::grid
is empty)
- The
Grid::grid
vectors are never allocated
To fix the first error call
CreateGrid()
in the constructor:
Grid(cv::Mat _map){
map = _map;
gridx = map.cols;
gridy = map.cols;
gridZise = map.cols;
CreateGrid();
}
To fix the second error initialise the
Node
s in
CreateGrid()
:
grid[i][j] = new Node(i, j, _walkable);
But it would be better to not use allocated
Node
s:
vector<vector<Node> > grid;
grid[i][j].walkable = _walkable;
grid[i][j].gridX = i;
grid[i][j].gridY = j;
void PrintGrid(){
for(int i=0; i <gridx;i++){
for(int j=0; j < gridy;j++){
cout << grid[i][j].NodeID <<endl;
}
}
}