Code: Select all
(in the header file)
deque<deque<deque<int> > > openlist;
deque<deque<deque<int> > >::iterator openlist_Iterator;
(in the cpp file)
for(int i=-1;i<=1;i++) //For the 8 surrounding pixels around some pixel (initially startPixel), find white pixels and add them to open list
{
for(int j=-1;j<=1;j++)
{
currentcolor=image.pixel(currentPixel[0]+i,currentPixel[1]+j);
if(qGreen(currentcolor)==g && qRed(currentcolor)==r && qBlue(currentcolor)==b)
{
openlist[0][0].push_back(currentPixel[0]+i); //openlist[0] is the position of the pixel on the open list
openlist[0][1].push_back(currentPixel[1]+j);
openlist[1][0].push_back(currentPixel[0]); //openlist[1] is its parent pixel
openlist[1][1].push_back(currentPixel[1]);
if((i==0 || j==0) && !(i==0 && j==0))//openlist[2][0] is the G cost
{openlist[2][0].push_back(10);}
else
{openlist[2][0].push_back(14);}
openlist[2][1].push_back(manhattan());//openlist[2][1] is the H cost
}
}
}
The only reason I'm using iterators is to try out something new. According to http://www.cprogramming.com/tutorial/stl/iterators.html the following works:
Code: Select all
for(myIntVectorIterator = myIntVector.begin();
myIntVectorIterator != myIntVector.end();
myIntVectorIterator++)
{
cout<<*myIntVectorIterator<<" ";
//Should output 1 4 8
}
But actually this doesn't? WTF? VS2003 gives me an error C2100 about not being able to dereference something that isn't a pointer. I don't know how else to do this.
Code: Select all
for(openlist_Iterator=openlist.begin();openlist_Iterator!=openlist.end();openlist_Iterator++) //find the lowest F cost square
{
(*openlist_Iterator[2][0])+(*openlist_Iterator[2][1]);
}
Are the new features in C++ supposed to be THIS hard to learn? BTW I have no clue how to traditionally (C array style) access the xth element of a 3D deque, where an element of the 3D array in this program's case has 6 values.