Add informative outputs when running

This commit is contained in:
Stephen Seo 2021-08-24 19:28:21 +09:00
parent b21d430116
commit 5e49ef542b
3 changed files with 12 additions and 4 deletions

View file

@ -127,10 +127,14 @@ int main(int argc, char **argv) {
// auto pixels = Ex02::RT::renderGraySphere( // auto pixels = Ex02::RT::renderGraySphere(
// outputWidth, outputHeight, threadCount); // outputWidth, outputHeight, threadCount);
std::cout << "Rendering image of width " << outputWidth << " and height "
<< outputHeight << " with " << threadCount << " thread(s)..."
<< std::endl;
auto pixels = auto pixels =
Ex02::RT::renderColorsWithSpheres(outputWidth, outputHeight, threadCount); Ex02::RT::renderColorsWithSpheres(outputWidth, outputHeight, threadCount);
pixels.writeToFile(outputFile); auto outFilename = pixels.writeToFile(outputFile);
std::cout << "Rendered image saved to " << outFilename << std::endl;
return 0; return 0;
} }

View file

@ -26,8 +26,9 @@ const Ex02::RT::Pixel &Ex02::RT::Image::getPixel(unsigned int x,
return data.at(x + y * width); return data.at(x + y * width);
} }
void Ex02::RT::Image::writeToFile(const std::string &filename) const { std::string Ex02::RT::Image::writeToFile(const std::string &filename) const {
std::ofstream out(filename + ".ppm"); std::string outfilename = filename + ".ppm";
std::ofstream out(outfilename);
out << "P3\n" << width << ' ' << data.size() / width << " 255" << '\n'; out << "P3\n" << width << ' ' << data.size() / width << " 255" << '\n';
for (unsigned int j = 0; j < data.size() / width; ++j) { for (unsigned int j = 0; j < data.size() / width; ++j) {
@ -38,6 +39,8 @@ void Ex02::RT::Image::writeToFile(const std::string &filename) const {
} }
out << '\n'; out << '\n';
} }
return outfilename;
} }
/* /*

View file

@ -31,7 +31,8 @@ public:
Pixel &getPixel(unsigned int x, unsigned int y); Pixel &getPixel(unsigned int x, unsigned int y);
const Pixel &getPixel(unsigned int x, unsigned int y) const; const Pixel &getPixel(unsigned int x, unsigned int y) const;
void writeToFile(const std::string &filename) const; // returns actual output filename
std::string writeToFile(const std::string &filename) const;
private: private:
unsigned int width; unsigned int width;