Browse Source

projectors works again, made a testcase for stitch.science.ru.nl

master
Joshua 14 years ago
parent
commit
d26e30bf3b
  1. 45
      Attractor.cpp
  2. 1
      AwesomeAttractor.cbp
  3. 9
      Canvas.cpp
  4. 4
      Projector.cpp
  5. 4
      Projector.hpp
  6. 14
      attractors/testAttractor.stf
  7. 22
      main.cpp

45
Attractor.cpp

@ -1,29 +1,16 @@
#include "Attractor.hpp" #include "Attractor.hpp"
using namespace std; using namespace std;
/*
Constructors & initialisers
*/
Attractor::Attractor() { Attractor::Attractor() {
myAttractor = new Lorenz3D(); myAttractor = new Lorenz3D();
// TODO: add default parameters
} }
Attractor::Attractor(const char* const fileName) { Attractor::Attractor(const char* const fileName) {
ifstream file(fileName);
cout << "Reading file " << fileName << "..." << endl; cout << "Reading file " << fileName << "..." << endl;
if ( !file ) {
cerr << " Error reading file '" << fileName << "' dying now..." << endl;
exit(2);
}
// TODO : Use stfu
stfu::node system; stfu::node system;
system.read(file); system.read(fileName);
stfu::node attractor = system.getChild("attractor"); stfu::node attractor = system.getChild("attractor");
string attractorType = attractor.getValue("type"); string attractorType = attractor.getValue("type");
@ -72,7 +59,7 @@ Attractor::Attractor(const char* const fileName) {
exit(3); exit(3);
} }
unsigned int numberOfParameters = myAttractor->getNumberOfParameters(); const unsigned int numberOfParameters = myAttractor->getNumberOfParameters();
double * & parameters = myAttractor->parameters(); double * & parameters = myAttractor->parameters();
for ( unsigned int i = 0; i < numberOfParameters; i++ ) { for ( unsigned int i = 0; i < numberOfParameters; i++ ) {
@ -85,19 +72,18 @@ Attractor::Attractor(const char* const fileName) {
} }
void Attractor::init_range() { void Attractor::init_range() {
/*
// stabilize attractor // stabilize attractor
for ( unsigned int i = 0; i < 100000; i++ ) { for ( unsigned int i = 0; i < 100000; i++ ) {
iterate(); 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<Projector*>::iterator it = projectors.begin(); it != projectors.end(); it++ ) { for ( vector<Projector*>::iterator it = projectors.begin(); it != projectors.end(); it++ ) {
(*it)->extern_dim = dim; (*it)->extern_dim = dimension;
(*it)->intern_dim = 2; (*it)->intern_dim = 2;
(*it)->init(point); (*it)->init(point);
} }
@ -105,20 +91,15 @@ void Attractor::init_range() {
// update ranges // update ranges
for ( unsigned int i = 0; i < 100000; i++ ) { for ( unsigned int i = 0; i < 100000; i++ ) {
iterate(); iterate();
if ( !is_chaos() ) {
cout << "Attractor died after " << i << " iterations" << endl;
exit(0);
}
for ( vector<Projector*>::iterator it = projectors.begin(); it != projectors.end(); it++ ) { for ( vector<Projector*>::iterator it = projectors.begin(); it != projectors.end(); it++ ) {
(*it)->update_range(point); (*it)->update_range(point);
} }
} }
for ( vector<Projector*>::iterator it = projectors.begin(); it != projectors.end(); it++ ) { for ( vector<Projector*>::iterator it = projectors.begin(); it != projectors.end(); it++ ) {
(*it)->finish_range(); (*it)->finish_range();
} }
*/
} }
bool Attractor::is_chaos() { bool Attractor::is_chaos() {
@ -164,12 +145,12 @@ void Attractor::plot() {
*/ */
void Attractor::output() { void Attractor::output() {
const unsigned int* dim = (unsigned int*)myAttractor->getProperty("dimension"); const unsigned int* dim = (unsigned int*)myAttractor->getProperty("dimension");
const unsigned int dimension = *dim;
delete dim;
const double * point = myAttractor->vector(); 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 << point[i] << " ";
} }
cout << endl; cout << endl;
delete dim;
} }

1
AwesomeAttractor.cbp

@ -43,6 +43,7 @@
<Unit filename="Projector.hpp"> <Unit filename="Projector.hpp">
<Option compilerVar="CC" /> <Option compilerVar="CC" />
</Unit> </Unit>
<Unit filename="attractors/testAttractor.stf" />
<Unit filename="kernels/Logistic.cpp" /> <Unit filename="kernels/Logistic.cpp" />
<Unit filename="kernels/Logistic.hpp" /> <Unit filename="kernels/Logistic.hpp" />
<Unit filename="kernels/Lorenz3D.cpp" /> <Unit filename="kernels/Lorenz3D.cpp" />

9
Canvas.cpp

@ -185,6 +185,15 @@ void Canvas::output_file(const char * filename){
delete max_int; delete max_int;
delete power; 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(); pngFile->close();
} }

4
Projector.cpp

@ -8,7 +8,7 @@ using namespace std;
#include "Canvas.hpp" #include "Canvas.hpp"
#include "myMath.hpp" #include "myMath.hpp"
void Projector::init(double * point) { void Projector::init(const double * point) {
init_vector(); init_vector();
project(point); 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); project(point);
for ( unsigned int i = 0; i < intern_dim; i++ ) { for ( unsigned int i = 0; i < intern_dim; i++ ) {
if ( project_point[i] < range_min[i] ) { if ( project_point[i] < range_min[i] ) {

4
Projector.hpp

@ -21,10 +21,10 @@ class Projector{
double factor; double factor;
double * offset; double * offset;
void init(double * point); void init(const double * point);
void init_vector(); void init_vector();
void init_range(); void init_range();
void update_range(double * point); void update_range(const double * point);
void finish_range(); void finish_range();

14
attractors/testAttractor.stf

@ -3,17 +3,19 @@ input: "attractor"
output: "png" output: "png"
attractor: { attractor: {
type: "polynomial" type: "unravel"
dimensions: "3" dimensions: "3"
orde: "2"
iterations: "1000000" iterations: "1000000"
parameters: { parameters: {
:"1.0" :"-0.78"
:"0.0" :"2.042"
:"2.0" :"1.22"
:"0.0" :"-1.267"
:"1.37"
:"2.3"
:"-2.195"
} }
} }

22
main.cpp

@ -8,11 +8,29 @@ using namespace std;
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
Attractor myAttractor("attractors/testAttractor.stf"); 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(); myAttractor.output();
cout << j << "% done" << endl;
} }
canvas.output_file();
/*if ( argc <= 2 ) { /*if ( argc <= 2 ) {
cout << endl << "nothing to do..." << endl; cout << endl << "nothing to do..." << endl;
cout << "usage:" << endl; cout << "usage:" << endl;