From de5d99a3bf7cec132b922bae8bfbc575a772f241 Mon Sep 17 00:00:00 2001 From: Joshua Moerman Date: Mon, 18 Apr 2011 16:44:14 +0200 Subject: [PATCH] better main, done small stuffs --- Attractor.cpp | 5 +++++ Attractor.hpp | 1 + Projector.cpp | 2 +- Projector.hpp | 4 +++- canvae/PNG.cpp | 4 ++-- defines.hpp | 15 ++++----------- main.cpp | 50 +++++++++++++++++++++++++++++--------------------- 7 files changed, 45 insertions(+), 36 deletions(-) diff --git a/Attractor.cpp b/Attractor.cpp index d95b9b3..cfd8f94 100644 --- a/Attractor.cpp +++ b/Attractor.cpp @@ -21,6 +21,11 @@ Attractor::Attractor(const std::string& filename) : kernel(0), projector(0) { projector = Projector::createProjector(system.getChild(system.getValue("Projector")), system); } +Attractor::Attractor(){ + LogError("Not implemented yet (random attractor)\n"); + exit(1); +} + Attractor::~Attractor() { delete kernel; } diff --git a/Attractor.hpp b/Attractor.hpp index 8264492..57e732e 100644 --- a/Attractor.hpp +++ b/Attractor.hpp @@ -18,6 +18,7 @@ public: Projector* projector; Attractor(const std::string& filename); + Attractor(); ~Attractor(); void init_range(); diff --git a/Projector.cpp b/Projector.cpp index 8780a6c..8e2607e 100644 --- a/Projector.cpp +++ b/Projector.cpp @@ -56,6 +56,6 @@ void Projector::plot(const double* point) { Projector* Projector::createProjector(stfu::node const& projector, stfu::node const& system) { Projector* output = new Normalizer(3); - return new Normalizer(3); + return output; } diff --git a/Projector.hpp b/Projector.hpp index ebe3d38..fd0e492 100644 --- a/Projector.hpp +++ b/Projector.hpp @@ -11,7 +11,6 @@ private: void deallocate(); protected: - Canvas* canvas; Projector* projector; double* projectedPoint; @@ -24,6 +23,9 @@ protected: virtual void project(const double* point) = 0; public: + // SHOULD NOT BE HERE + Canvas* canvas; + Projector(unsigned int inputDimension, unsigned int outputDimension); virtual ~Projector(); diff --git a/canvae/PNG.cpp b/canvae/PNG.cpp index 46d7165..49213cc 100644 --- a/canvae/PNG.cpp +++ b/canvae/PNG.cpp @@ -27,7 +27,7 @@ void PNG::clear() { } } -void PNG::plot(double* position) { +void PNG::plot(const double* position) { const double& x = position[0]; const double& y = position[1]; @@ -44,7 +44,7 @@ void PNG::plot(double* position) { I/O functions */ -void PNG::output_file(const char* filename) { +void PNG::output_file(const char* filename) const { unsigned int* max_int = new unsigned int[num_colors]; double* power = new double[num_colors]; diff --git a/defines.hpp b/defines.hpp index 359187b..dc44719 100644 --- a/defines.hpp +++ b/defines.hpp @@ -1,12 +1,5 @@ -#define DEFAULT_ATTRACTOR_FILE "attractors/testUnravel.stf" -#ifdef UNI_BUILD -#warning Building for the RU, are you sure? -#define DEFAULT_WIDTH 8000 -#define DEFAULT_HEIGHT 8000 -#define DEFAULT_ITERATIONS 4200000000 -#else -#define DEFAULT_WIDTH 800 -#define DEFAULT_HEIGHT 800 -#define DEFAULT_ITERATIONS 1000000 -#endif +#define DEFAULT_WIDTH 1024 +#define DEFAULT_HEIGHT 1024 +#define DEFAULT_ITERATIONS 100 + diff --git a/main.cpp b/main.cpp index d24f6c4..90dd633 100644 --- a/main.cpp +++ b/main.cpp @@ -8,7 +8,7 @@ #include "Canvas.hpp" #include "Projector.hpp" -#include "canvae/Raw.hpp" +#include "canvae/PNG.hpp" #include "ostream_helpers.h" #include "defines.hpp" @@ -19,22 +19,24 @@ int verbose; void showHelpText() { std::cout << "Awesome Attractor, version " __DATE__ "\n" - "Usage: AwesomeAttractor [OPTION]... FILE\n" + "Usage: AwesomeAttractor [OPTION]* [FILE]\n" "Optons:\n" " -h, --help Shows this help\n" " -q quiet mode\n" " -v verbose mode\n" " -V loud mode\n" - " -W N Sets width of output image to N\n" - " -H N Sets height of output image to N\n" - " -I N Sets number of iterations to N\n" + " -W N Sets width of output image (1024)\n" + " -H N Sets height of output image (1024)\n" + " -I N Sets number of milions of iterations (100)\n" + " -R Random attractor (no file will be read)\n" << std::endl; exit(0); } int main(int argc, char* argv[]) { verbose = 0; - std::string attractorFile = DEFAULT_ATTRACTOR_FILE; + std::string attractorFile = ""; + bool generate_random = false; unsigned int iterations = DEFAULT_ITERATIONS; unsigned int width = DEFAULT_WIDTH; unsigned int height = DEFAULT_HEIGHT; @@ -46,20 +48,22 @@ int main(int argc, char* argv[]) { for(int i = 1; i < argc; ++i) { if(strcmp(argv[i], "-v") == 0) { verbose = 1; + } else if(strcmp(argv[i], "-V") == 0) { + verbose = 3; } else if(strcmp(argv[i], "-q") == 0) { verbose = -1; } else if(strcmp(argv[i], "--help") == 0) { showHelpText(); } else if(strcmp(argv[i], "-h") == 0) { showHelpText(); - } else if(strcmp(argv[i], "-V") == 0) { - verbose = 3; } else if(strcmp(argv[i], "-W") == 0) { width = atoi(argv[++i]); } else if(strcmp(argv[i], "-H") == 0) { height = atoi(argv[++i]); } else if(strcmp(argv[i], "-I") == 0) { iterations = atoi(argv[++i]); + } else if(strcmp(argv[i], "-R") == 0) { + generate_random = true; } else { attractorFile = argv[i]; } @@ -67,33 +71,37 @@ int main(int argc, char* argv[]) { LogInfo("Awesome Attractor, version %s\n", __DATE__); - // initialising stuff - Attractor myAttractor(attractorFile); + Attractor* my_attractor_ptr = 0; + if(attractorFile != "") + my_attractor_ptr = new Attractor(attractorFile); + else if(generate_random) + my_attractor_ptr = new Attractor(); - /*unsigned int sizes[] = {128, 128, 128}; - Canvas* canvas = new Raw(3, sizes); - projection.canvas = canvas;*/ + if(my_attractor_ptr == 0){ + LogError("Nothing todo\n"); + exit(0); + } + Attractor& myAttractor = *my_attractor_ptr; + myAttractor.projector->canvas = new PNG(width, height, 3); myAttractor.init_range(); - //projection.output(); - LogInfo("\nRendering\n"); clock_t start, end; start = clock(); - for(unsigned int j = 1; j <= 100; ++j) { - for(unsigned int i = 0; i <= iterations; i++) { + for(unsigned int j = 1; j <= iterations; ++j) { + for(unsigned int i = 0; i < 1000000; ++i) { myAttractor.iterate(); myAttractor.plot(); } if(verbose >= 0) { - std::cout << "\r" << j << "% done" << std::flush; + std::cout << "\r" << j << " out of " << iterations << " done." << std::flush; } } end = clock(); - double totalIterations = 100.0*iterations; + double totalIterations = 1000000.0*iterations; double totalTime = ((double)(end-start)/(double)(CLOCKS_PER_SEC)); LogInfo("\nTotal clock time: %f\n", totalTime); LogMoreInfo("Average iterations per second: %f\n\n", totalIterations/totalTime); @@ -106,7 +114,7 @@ int main(int argc, char* argv[]) { sprintf(filename, "render/attractor_%04d-%02d-%02d_%02d-%02d-%02d-%01d.raw", lt->tm_year + 1900, lt->tm_mon + 1, lt->tm_mday, lt->tm_hour, lt->tm_min, lt->tm_sec, r); start = clock(); - //canvas->output_file(filename); + myAttractor.projector->canvas->output_file(filename); end = clock(); totalTime = ((double)(end-start)/(double)(CLOCKS_PER_SEC)); @@ -114,7 +122,7 @@ int main(int argc, char* argv[]) { LogInfo("Total clock time for writing png: %f\n", totalTime); - + delete my_attractor_ptr; return 0; }