I am currently trying to write a PPM file using geographic data.
I created a class PPM which works perfectly and allow me with this code to write my PPM.
PPM ppm1(2000,2000);
for (int i=0; i<2000;i++)
for (int j=0;j<2000;j++){
ppm1.image[i][j].r = 0;
ppm1.image[i][j].g = 0;
ppm1.image[i][j].b = 0;
}
ppm1.set_version("P6");
ppm1.save("RGB.ppm");
My problem is : I have a function convertRGB which gives me the table {red,green,blue} corresponding to the depth z of a point (x,y) of my structure "coordinates" when i call it: (to create a sort of heat map, but for depth)
int rgb[3] = {0};
double maxZ = max(coordinates.z);
convertRGB(rgb,coordinates.z[0]*(255/maxZ));
cout << rgb[0] << endl;
cout << rgb[1] << endl;
cout << rgb[2] << endl;
_____
0
50
255
How can I create my ppm ? I have tried the following but I have a core dump...
PPM ppm1(2000,2000);
for (int k=0; k<coordinates.x.size();k++)
convertRGB((rgb,coordinates.z[0]*(255/maxZ))
for (int i=0; i<2000;i++)
for (int j=0;j<2000;j++){
ppm1.image[i][j].r = rgb[0];
ppm1.image[i][j].g = rgb[1];
ppm1.image[i][j].b = rgb[2];
}
ppm1.set_version("P6");
ppm1.save("RGB.ppm");
Thanks for the help!
question from:
https://stackoverflow.com/questions/65646999/writing-ppm-with-a-function-returning-r-g-b 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…