#include #include #include #include #include #include "Logger.hpp" #include "ostream_helpers.h" #include "defines.hpp" #include "AwesomeAttractorConfig.h" #include "Attractor.hpp" #include "Canvas.hpp" #include "Image.hpp" #include "Tonemapper.hpp" #include namespace po = boost::program_options; int verbose = 4; std::string generate_filename(){ char filename[64]; time_t t = time(0); struct tm* lt = localtime(&t); sprintf(filename, "attractor_%04d-%02d-%02d_%02d-%02d-%02d", lt->tm_year + 1900, lt->tm_mon + 1, lt->tm_mday, lt->tm_hour, lt->tm_min, lt->tm_sec); return std::string(filename); } void render(Attractor & myAttractor, Canvas2D & canvas, unsigned int iterations){ Progressbar progress(LOG_INFO, std::cout, "rendering"); for(unsigned int j = 1; j <= iterations; ++j) { for(unsigned int i = 0; i < 1000000; ++i) { myAttractor.iterate(); myAttractor.project(); canvas.plot(myAttractor.projector->projectedPoint); } progress.show(j, iterations); } } int main(int argc, char* argv[]) try { std::string attractorFile, output_path; unsigned int iterations, width, height; srand(time(0)); po::options_description desc("Options"); desc.add_options() ("help,h", "produce help message") ("iterations,I", po::value(&iterations)->default_value(DEFAULT_ITERATIONS), "set number of iterations (in milions)") ("width,W", po::value(&width)->default_value(DEFAULT_WIDTH), "width of output image") ("height,H", po::value(&height)->default_value(DEFAULT_HEIGHT), "height of output image") ("input-file,f", po::value(&attractorFile)->default_value(""), "attractor file to read") ("output-path,P", po::value(&output_path)->default_value("render/"), "path to output image") ; po::variables_map vm; po::store(po::parse_command_line(argc, argv, desc), vm); po::notify(vm); if (vm.count("help") || argc <= 1) { std::cout << desc << std::endl; return 1; } std::string filename = output_path + generate_filename(); Logger logger(LOG_VERBOSE, std::cout); Canvas2D canvas(width, height); { Attractor my_attractor(attractorFile); my_attractor.init_range(); logger.start("rendering"); render(my_attractor, canvas, iterations); logger.stop(); std::string path(filename + ".stf"); std::ofstream file(path.c_str()); file << my_attractor.stf_output() << std::endl; } { Tonemappers::GammaCorrector tonemapper; tonemapper.analyse(canvas); logger.start("saving image"); ImageFormats::png::png_stream image(canvas.size<0>(), canvas.size<1>(), filename + ".png"); tonemapper.process(canvas, image); logger.stop(); } } catch (std::exception & e) { std::cout << "Terminated because of: " << e.what() << std::endl; }