projectors works again, made a testcase for stitch.science.ru.nl
This commit is contained in:
parent
3ffe76cf2c
commit
d26e30bf3b
7 changed files with 55 additions and 44 deletions
|
@ -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<Projector*>::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<Projector*>::iterator it = projectors.begin(); it != projectors.end(); it++ ) {
|
||||
(*it)->update_range(point);
|
||||
}
|
||||
|
||||
}
|
||||
for ( vector<Projector*>::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;
|
||||
}
|
||||
|
|
|
@ -43,6 +43,7 @@
|
|||
<Unit filename="Projector.hpp">
|
||||
<Option compilerVar="CC" />
|
||||
</Unit>
|
||||
<Unit filename="attractors/testAttractor.stf" />
|
||||
<Unit filename="kernels/Logistic.cpp" />
|
||||
<Unit filename="kernels/Logistic.hpp" />
|
||||
<Unit filename="kernels/Lorenz3D.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();
|
||||
|
||||
}
|
||||
|
|
|
@ -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] ) {
|
||||
|
|
|
@ -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();
|
||||
|
||||
|
||||
|
|
|
@ -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"
|
||||
}
|
||||
}
|
||||
|
||||
|
|
22
main.cpp
22
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;
|
||||
|
|
Reference in a new issue