How Can I Directly Use The Iterator Values?

Hello Professionals:

Good day. I am honestly a newbie of std::vector and I would like to know how can I convert my previous program into a new one? My old program looks like this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
float matA2[1000][1000];
int a = 0;
 for (int x = 0; x < count_g_polCoeffGerald; x++) {
	int b = 0;
        for (int y = 0; y < count_g_polCoeffGerald; y++) {
        x0 = values [a]; //x component
        y0 = values [a + 1]; //y component
        x1 = values [b] //x component of the next coordinate
        y1 = values [b + 1]; //y component of the next coordinate
        matA2[x][y] = LeastSquareDistance(x0,y0,x1,y1); //function computation
        b+=2; //go to next coordinate
        }
   a+=2; //go to next coordinate to be compared with all coordinates
 }


However, I am trying to incorporate the same algorithm to the code that I have right now, but I am having trouble with how can I can call the x,y,z values of indCell. I know that the code "glm::ivec3 indCell = it->first;" iterates to all the values of g_polCoeff and "indCell.x", "indCell.y" correspond to "x values" and "y values" of indCell, however, I was wondering how can I call the next x,y values of the next coordinate if I have the kind of syntax code below considering the iterator "it" I have below?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
std::unordered_map<glm::ivec3, float>::iterator it;
const int count_g_polCoeff = g_polCoeff.size();
for (it = g_polCoeff.begin(); it != g_polCoeff.end(); it++) {

glm::ivec3 indCell = it->first;
std::vector<float> matA2;

matA2.reserve(count_g_polCoeff * count_g_polCoeff);

int a = 0;
 for (int x = 0; x < count_g_polCoeffGerald; x++) {
	int b = 0;
        for (int y = 0; y < count_g_polCoeffGerald; y++) {
        x0 = ? 
        y0 = ?
        x1 = ?
        y1 =  ?
        matA2[ ] = LeastSquareDistance(x0,y0,x1,y1);
        b+=2; //go to next coordinate
        }
   a+=2; //go to next coordinate to be compared with all coordinates
 }

}


Up to this moment I am still guessing how to correspondingly translate my old program to the new one and it's still question mark for me. Thank you very much for your inputs in advance!
Last edited on
1
2
3
4
5
6
7
8
std::unordered_map<glm::ivec3, float>::iterator a, b;
a = b = g_polCoeff.begin();
++b;

x0 = a->first.x;
y0 = a->first.y;
x1 = b->first.x;
y1 = b->first.y;
notice that when `a' is pointing to the last element in your collection, `b' will be invalid.

1
2
3
4
5
matA2.reserve(count_g_polCoeff * count_g_polCoeff);
//...
matA2.push_back(LeastSquareDistance(x0,y0,x1,y1));
//later if you want to access cell (x,y)
matA2[x*number_of_columns + y]
Last edited on
Topic archived. No new replies allowed.