diff --git a/Attractor.cpp b/Attractor.cpp index 1dc49a5..048a532 100644 --- a/Attractor.cpp +++ b/Attractor.cpp @@ -1,29 +1,16 @@ #include "Attractor.hpp" using namespace std; -/* - Constructors & initialisers -*/ Attractor::Attractor() { - myAttractor = new Lorenz3D(); - + // TODO: add default parameters } Attractor::Attractor(const char* const fileName) { - ifstream file(fileName); - cout << "Reading file " << fileName << "..." << endl; - if ( !file ) { - cerr << " Error reading file '" << fileName << "' dying now..." << endl; - exit(2); - } - - // TODO : Use stfu - stfu::node system; - system.read(file); + system.read(fileName); stfu::node attractor = system.getChild("attractor"); string attractorType = attractor.getValue("type"); @@ -72,7 +59,7 @@ Attractor::Attractor(const char* const fileName) { exit(3); } - unsigned int numberOfParameters = myAttractor->getNumberOfParameters(); + const unsigned int numberOfParameters = myAttractor->getNumberOfParameters(); double * & parameters = myAttractor->parameters(); for ( unsigned int i = 0; i < numberOfParameters; i++ ) { @@ -85,19 +72,18 @@ Attractor::Attractor(const char* const fileName) { } void Attractor::init_range() { -/* // stabilize attractor for ( unsigned int i = 0; i < 100000; i++ ) { iterate(); - if ( !is_chaos() ) { - cout << "Attractor died after " << i << " iterations" << endl; - exit(0); - } } - // initialize ranges + // initialize projectors with dimension and first point + const unsigned int* dim = (unsigned int*)myAttractor->getProperty("dimension"); + const unsigned int dimension = *dim; + delete dim; + const double * point = myAttractor->vector(); for ( vector::iterator it = projectors.begin(); it != projectors.end(); it++ ) { - (*it)->extern_dim = dim; + (*it)->extern_dim = dimension; (*it)->intern_dim = 2; (*it)->init(point); } @@ -105,20 +91,15 @@ void Attractor::init_range() { // update ranges for ( unsigned int i = 0; i < 100000; i++ ) { iterate(); - if ( !is_chaos() ) { - cout << "Attractor died after " << i << " iterations" << endl; - exit(0); - } for ( vector::iterator it = projectors.begin(); it != projectors.end(); it++ ) { (*it)->update_range(point); } - } for ( vector::iterator it = projectors.begin(); it != projectors.end(); it++ ) { (*it)->finish_range(); } -*/ + } bool Attractor::is_chaos() { @@ -164,12 +145,12 @@ void Attractor::plot() { */ void Attractor::output() { const unsigned int* dim = (unsigned int*)myAttractor->getProperty("dimension"); + const unsigned int dimension = *dim; + delete dim; const double * point = myAttractor->vector(); - for ( unsigned int i = 0; i < *dim; i++ ) { + for ( unsigned int i = 0; i < dimension; i++ ) { cout << point[i] << " "; } cout << endl; - - delete dim; } diff --git a/AwesomeAttractor.cbp b/AwesomeAttractor.cbp index 48aa764..d779f9c 100644 --- a/AwesomeAttractor.cbp +++ b/AwesomeAttractor.cbp @@ -43,6 +43,7 @@ + diff --git a/Canvas.cpp b/Canvas.cpp index 2072b56..bd61bd9 100644 --- a/Canvas.cpp +++ b/Canvas.cpp @@ -185,6 +185,15 @@ void Canvas::output_file(const char * filename){ delete max_int; delete power; + cout << "ready for writing file i suppose" << endl; + + ofstream file(filename); + if ( !file ) { + cout << "jij hebt pech, geen png voor jou" << endl; + } + cout << filename << endl; + + pngFile->close(); } diff --git a/Projector.cpp b/Projector.cpp index f66ea2c..20c4c8c 100644 --- a/Projector.cpp +++ b/Projector.cpp @@ -8,7 +8,7 @@ using namespace std; #include "Canvas.hpp" #include "myMath.hpp" -void Projector::init(double * point) { +void Projector::init(const double * point) { init_vector(); project(point); @@ -35,7 +35,7 @@ void Projector::init_range() { } } -void Projector::update_range(double * point) { +void Projector::update_range(const double * point) { project(point); for ( unsigned int i = 0; i < intern_dim; i++ ) { if ( project_point[i] < range_min[i] ) { diff --git a/Projector.hpp b/Projector.hpp index 84a8813..4dfcd9d 100644 --- a/Projector.hpp +++ b/Projector.hpp @@ -21,10 +21,10 @@ class Projector{ double factor; double * offset; - void init(double * point); + void init(const double * point); void init_vector(); void init_range(); - void update_range(double * point); + void update_range(const double * point); void finish_range(); diff --git a/attractors/testAttractor.stf b/attractors/testAttractor.stf index 12a4673..6d0625e 100644 --- a/attractors/testAttractor.stf +++ b/attractors/testAttractor.stf @@ -3,17 +3,19 @@ input: "attractor" output: "png" attractor: { - type: "polynomial" + type: "unravel" dimensions: "3" - orde: "2" iterations: "1000000" parameters: { - :"1.0" - :"0.0" - :"2.0" - :"0.0" + :"-0.78" + :"2.042" + :"1.22" + :"-1.267" + :"1.37" + :"2.3" + :"-2.195" } } diff --git a/main.cpp b/main.cpp index 0c44d44..c582516 100644 --- a/main.cpp +++ b/main.cpp @@ -8,11 +8,29 @@ using namespace std; int main(int argc, char *argv[]) { Attractor myAttractor("attractors/testAttractor.stf"); - for ( unsigned int i = 0; i < 50; i++ ) { - myAttractor.iterate(); + + Projector projection; + Canvas canvas(6400, 6400, 3); + projection.canvas = &canvas; + + myAttractor.projectors.push_back(&projection); + myAttractor.init_range(); + + projection.output(); + + unsigned int iterations = 2000000000; // twee miljard + for ( unsigned int j = 1; j <= 100; j++ ) { + for ( unsigned int i = 0; 100*i <= iterations; i++ ) { + myAttractor.iterate(); + myAttractor.plot(); + } + system("clear"); myAttractor.output(); + cout << j << "% done" << endl; } + canvas.output_file(); + /*if ( argc <= 2 ) { cout << endl << "nothing to do..." << endl; cout << "usage:" << endl;