diff --git a/Attractor.cpp b/Attractor.cpp index 2d44807..f67eec7 100644 --- a/Attractor.cpp +++ b/Attractor.cpp @@ -7,10 +7,7 @@ #include "AttractorKernel.hpp" #include "Projector.hpp" -Attractor::Attractor() - : projector(0) - , kernel(0) - { +void Attractor::generate_random(){ stfu::node kernel_node; switch(rand()%2+1){ case 0: diff --git a/Attractor.hpp b/Attractor.hpp index 8b8eee0..0fb0329 100644 --- a/Attractor.hpp +++ b/Attractor.hpp @@ -14,24 +14,24 @@ public: // should be private really Projector* projector; - Attractor(const std::string& filename) + Attractor(const std::string& filename = "") : projector(0) , kernel(0) { - LogInfo("Reading file '%s'...\n", filename.c_str()); + if (filename == "") { + LogInfo("Making random attractor\n"); + generate_random(); + } else { + LogInfo("Reading file '%s'\n", filename.c_str()); - stfu::node system; - if(!system.read(filename.c_str())){ - std::cerr << "Couldn't open file (" << filename << ") for reading\n"; - exit(-1); - } + stfu::node system; + if(!system.read(filename.c_str())) throw std::runtime_error(filename + " could not be opened"); - kernel = AttractorKernel::createAttractorKernel(system.getChild("AttractorKernel")); - projector = Projector::createProjector(system.getChild(system.getValue("Projector")), kernel->getDimension()); + kernel = AttractorKernel::createAttractorKernel(system.getChild("AttractorKernel")); + projector = Projector::createProjector(system.getChild(system.getValue("Projector")), kernel->getDimension()); + } } - Attractor(); - ~Attractor() { delete kernel; } @@ -79,6 +79,8 @@ public: friend std::ostream& operator<<(std::ostream& os, Attractor const& x); private: + void generate_random(); + AttractorKernel* kernel; Attractor(Attractor const &); diff --git a/AwesomeAttract0r.xcodeproj/project.pbxproj b/AwesomeAttract0r.xcodeproj/project.pbxproj index b37f340..031ed98 100644 --- a/AwesomeAttract0r.xcodeproj/project.pbxproj +++ b/AwesomeAttract0r.xcodeproj/project.pbxproj @@ -62,7 +62,7 @@ 427057A81475637B00CBE978 /* ImageFormatBMP.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = ImageFormatBMP.hpp; sourceTree = ""; }; 427057A91475637B00CBE978 /* ImageFormatPNG.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = ImageFormatPNG.hpp; sourceTree = ""; }; 427057AB1475637B00CBE978 /* Tonemapper.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = Tonemapper.hpp; sourceTree = ""; }; - 427057AC1475654E00CBE978 /* array.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = array.hpp; sourceTree = ""; }; + 427057AC1475654E00CBE978 /* array.hpp */ = {isa = PBXFileReference; fileEncoding = 4; path = array.hpp; sourceTree = ""; }; 427057AD147571FC00CBE978 /* libboost_program_options.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libboost_program_options.a; path = ../../../../../usr/local/lib/libboost_program_options.a; sourceTree = ""; }; /* End PBXFileReference section */ @@ -235,7 +235,6 @@ buildSettings = { ARCHS = "$(ARCHS_STANDARD_32_64_BIT)"; GCC_AUTO_VECTORIZATION = YES; - GCC_C_LANGUAGE_STANDARD = gnu99; GCC_DEBUGGING_SYMBOLS = full; GCC_FAST_MATH = YES; GCC_OPTIMIZATION_LEVEL = 3; @@ -283,7 +282,6 @@ isa = XCBuildConfiguration; buildSettings = { ARCHS = "$(ARCHS_STANDARD_32_64_BIT)"; - GCC_C_LANGUAGE_STANDARD = gnu99; GCC_OPTIMIZATION_LEVEL = 0; HEADER_SEARCH_PATHS = /usr/local/include; LIBRARY_SEARCH_PATHS = "/usr/local/lib//**"; diff --git a/array.hpp b/array.hpp index 98ec13e..10a89c4 100644 --- a/array.hpp +++ b/array.hpp @@ -13,6 +13,7 @@ #ifndef __APPLE__ #include +#include #else #include namespace std { diff --git a/batch.sh b/batch.sh index 5198d60..46d9a67 100755 --- a/batch.sh +++ b/batch.sh @@ -1,2 +1,2 @@ #!/bin/bash -while true; do ./build/Debug/AwesomeAttract0r -P ./render/ -R -I 50 -W 1280 -H 800 -f attractors/emptyUnravel3D.stf; done +while true; do ./build/Debug/AwesomeAttract0r -P ./render/ -I 50 -W 1280 -H 800 -f attractors/emptyUnravel3D.stf; done diff --git a/main.cpp b/main.cpp index dfd49b6..1aae64d 100644 --- a/main.cpp +++ b/main.cpp @@ -40,14 +40,12 @@ void render(Attractor & myAttractor, Canvas2D & canvas, unsigned int iterations) } } -int main(int argc, char* argv[]) { - std::string attractorFile; - std::string output_path; - bool generate_random = false; +int main(int argc, char* argv[]) try { + std::string attractorFile, output_path; unsigned int iterations, width, height; srand(time(0)); - po::options_description desc("Usage"); + 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)") @@ -55,55 +53,33 @@ int main(int argc, char* argv[]) { ("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") - ("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; - } + 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; } - if(vm.count("random")) generate_random = true; - std::string filename = output_path + generate_filename(); Logger logger(LOG_VERBOSE, 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); - } + Attractor my_attractor(attractorFile); - my_attractor_ptr->init_range(); + my_attractor.init_range(); logger.start("rendering"); - render(*my_attractor_ptr, canvas, iterations); + render(my_attractor, 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; + std::string path(filename + ".stf"); + std::ofstream file(path.c_str()); + file << my_attractor.stf_output() << std::endl; } { @@ -115,6 +91,8 @@ int main(int argc, char* argv[]) { tonemapper.process(canvas, image); logger.stop(); } +} catch (std::exception & e) { + std::cout << "Terminated because of: " << e.what() << std::endl; }