My old project for strange attractors
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.
 
 
 

123 lines
3.3 KiB

#include <iostream>
#include <fstream>
#include <ctime>
#include <cstring>
#include <cstdlib>
#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 <boost/program_options.hpp>
namespace po = boost::program_options;
int verbose = 3;
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(std::cout, "rendering");
for(unsigned int j = 1; j <= iterations; ++j) {
for(unsigned int i = 0; i < 1000000; ++i) {
myAttractor.iterate();
canvas.plot(myAttractor.projector->projectedPoint);
}
progress.show(j, iterations);
}
}
int main(int argc, char* argv[]) {
LogInfo("Awesome Attractor, version %s\n", __DATE__);
verbose = 0;
std::string attractorFile;
std::string output_path;
bool generate_random = false;
unsigned int iterations, width, height;
srand(time(0));
po::options_description desc("Usage");
desc.add_options()
("help,h", "produce help message")
("iterations,I", po::value<unsigned int>(&iterations)->default_value(DEFAULT_ITERATIONS), "set number of iterations (in milions)")
("width,W", po::value<unsigned int>(&width)->default_value(DEFAULT_WIDTH), "width of output image")
("height,H", po::value<unsigned int>(&height)->default_value(DEFAULT_HEIGHT), "height of output image")
("input-file,f", po::value<std::string>(&attractorFile)->default_value(""), "attractor file to read")
("output-path,P", po::value<std::string>(&output_path)->default_value("render/"), "path to output image")
("random,R", "use random parameters")
;
po::variables_map vm;
try {
po::store(po::parse_command_line(argc, argv, desc), vm);
po::notify(vm);
} catch(std::exception & e) {
std::cout << "Failed to read commandline: " << e.what() << std::endl;
std::cout << desc << std::endl;
return 1;
}
if (vm.count("help") || argc <= 1) {
std::cout << desc << std::endl;
return 1;
}
if(vm.count("random")) generate_random = true;
std::string filename = output_path + generate_filename();
Logger logger(std::cout);
Canvas2D canvas(width, height);
{
Attractor* my_attractor_ptr = 0;
if(attractorFile != "")
my_attractor_ptr = new Attractor(attractorFile);
else if(generate_random)
my_attractor_ptr = new Attractor();
if(my_attractor_ptr == 0){
LogError("Nothing todo\n");
exit(0);
}
my_attractor_ptr->init_range();
logger.start("rendering");
render(*my_attractor_ptr, canvas, iterations);
logger.stop();
{
std::string path(filename + ".stf");
std::ofstream file(path.c_str());
file << my_attractor_ptr->stf_output() << std::endl;
}
delete my_attractor_ptr;
}
{
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();
}
}