Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
424 views
in Technique[技术] by (71.8m points)

c++ - Writing PPM with a function returning {r,g,b}

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...