removed old files, added command line arguments
This commit is contained in:
parent
a0f07490e3
commit
cc018547f0
11 changed files with 65 additions and 357 deletions
|
@ -10,12 +10,12 @@
|
|||
#include "Projector.hpp"
|
||||
|
||||
|
||||
Attractor::Attractor(const char* const fileName) {
|
||||
Attractor::Attractor(const std::string& filename) {
|
||||
// opening file
|
||||
std::cout << "Reading file " << fileName << "..." << std::endl;
|
||||
std::cout << "Reading file " << filename << "..." << std::endl;
|
||||
|
||||
stfu::node system;
|
||||
system.read(fileName);
|
||||
system.read(filename.c_str());
|
||||
stfu::node attractor = system.getChild("AttractorKernel");
|
||||
|
||||
myAttractor = AttractorKernel::createAttractorKernel(attractor);
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#ifndef ATTRACTOR_HPP
|
||||
#define ATTRACTOR_HPP
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
class Projector;
|
||||
|
@ -16,7 +17,7 @@ public:
|
|||
// should be private really
|
||||
std::vector<Projector *> projectors;
|
||||
|
||||
Attractor(const char* const filename);
|
||||
Attractor(const std::string& filename);
|
||||
~Attractor();
|
||||
|
||||
void init_range();
|
||||
|
|
110
Parameters.cpp
110
Parameters.cpp
|
@ -1,110 +0,0 @@
|
|||
#include <iostream>
|
||||
using namespace std;
|
||||
|
||||
#include "Parameters.hpp"
|
||||
|
||||
|
||||
Parameters::Parameters(unsigned int num_parameters, float default_val):
|
||||
num_parameters(num_parameters) {
|
||||
begin = new (nothrow) Vector(num_parameters, default_val);
|
||||
eind = new (nothrow) Vector(num_parameters, default_val);
|
||||
interpolated = new (nothrow) Vector(num_parameters, default_val);
|
||||
// *interpolated = *begin
|
||||
|
||||
check_pointers();
|
||||
|
||||
#ifdef HARDDEBUG
|
||||
cout << "New Parameters with one default val:" << endl << *this << endl;
|
||||
#endif
|
||||
}
|
||||
|
||||
/*Parameters::Parameters(unsigned int num_parameters, float default_val1, float default_val2):
|
||||
num_parameters(num_parameters) {
|
||||
begin = new (nothrow) Vector(num_parameters, default_val1);
|
||||
eind = new (nothrow) Vector(num_parameters, default_val2);
|
||||
interpolated = new (nothrow) Vector(num_parameters, default_val1);
|
||||
// *interpolated = *begin
|
||||
|
||||
check_pointers();
|
||||
|
||||
#ifdef HARDDEBUG
|
||||
cout << "New Parameters with two default vals:" << endl << *this << endl;
|
||||
#endif
|
||||
}*/
|
||||
|
||||
Parameters::~Parameters() {
|
||||
delete begin;
|
||||
delete eind;
|
||||
delete interpolated;
|
||||
|
||||
#ifdef HARDDEBUG
|
||||
cout << "Parameters deleted" << endl;
|
||||
#endif
|
||||
}
|
||||
|
||||
void Parameters::check_pointers() {
|
||||
assert(begin != NULL);
|
||||
assert(eind != NULL);
|
||||
assert(interpolated != NULL);
|
||||
}
|
||||
|
||||
void Parameters::set(unsigned int parameter, float val1, float val2) {
|
||||
assert(parameter < num_parameters);
|
||||
|
||||
begin->coordinates[parameter] = val1;
|
||||
eind->coordinates[parameter] = val2;
|
||||
interpolated->coordinates[parameter] = val1;
|
||||
|
||||
#ifdef HARDDEBUG
|
||||
cout << "Parameter " << parameter << " set to: " << val1 << " - " << val2 << endl;
|
||||
#endif
|
||||
}
|
||||
|
||||
void Parameters::set(unsigned int parameter, float val) {
|
||||
assert(parameter < num_parameters);
|
||||
|
||||
begin->coordinates[parameter] = val;
|
||||
eind->coordinates[parameter] = val;
|
||||
interpolated->coordinates[parameter] = val;
|
||||
|
||||
#ifdef HARDDEBUG
|
||||
cout << "Parameter " << parameter << " set to: " << val << endl;
|
||||
#endif
|
||||
}
|
||||
|
||||
float Parameters::get(unsigned int parameter) {
|
||||
assert(parameter < num_parameters);
|
||||
|
||||
#ifdef HARDDEBUG
|
||||
cout << "Asked for parameter " << parameter << " with value:" << interpolated->coordinates[parameter] << endl;
|
||||
#endif
|
||||
|
||||
return interpolated->coordinates[parameter];
|
||||
|
||||
}
|
||||
|
||||
void Parameters::interpolate(float time) {
|
||||
/*
|
||||
Dit is mogelijk met vector rekenen:
|
||||
(*interpolated) = (*begin) * ( 1.0 - time ) + (*eind) * time;
|
||||
Maar we doen het per element, zodat we simpelere code hebben,
|
||||
geen vectoren hoeven te returnen en makkelijker kunnen optimaliseren
|
||||
*/
|
||||
const float invtime = 1.0 - time;
|
||||
for ( unsigned int i = 0; i < num_parameters; i++ ) {
|
||||
interpolated->coordinates[i] = invtime * begin->coordinates[i] + time * eind->coordinates[i];
|
||||
}
|
||||
|
||||
#ifdef HARDDEBUG
|
||||
cout << "interpolate() result" << endl << *interpolated << endl;
|
||||
#endif
|
||||
}
|
||||
|
||||
ostream& operator<<(ostream& os, const Parameters& param) {
|
||||
os << param.num_parameters << endl;
|
||||
os << "Begin:" << endl << *param.begin << endl;
|
||||
os << "Eind:" << endl << *param.eind << endl;
|
||||
os << "Interpolated:" << endl << *param.interpolated << endl;
|
||||
os <<endl;
|
||||
return os;
|
||||
}
|
|
@ -1,34 +0,0 @@
|
|||
#ifndef PARAMETER_HPP
|
||||
#define PARAMETER_HPP
|
||||
|
||||
#include "Vector.hpp"
|
||||
|
||||
class Parameters {
|
||||
|
||||
Vector * begin;
|
||||
Vector * eind;
|
||||
Vector * interpolated;
|
||||
|
||||
void check_pointers();
|
||||
|
||||
|
||||
public:
|
||||
|
||||
// for checks and assertions
|
||||
unsigned int num_parameters;
|
||||
|
||||
Parameters(unsigned int num_parameters, float default_val = 0.0);
|
||||
//Parameters(unsigned int num_parameters, float default_val1, float default_val2);
|
||||
~Parameters();
|
||||
|
||||
void set(unsigned int parameter, float val1, float val2);
|
||||
void set(unsigned int parameter, float val);
|
||||
float get(unsigned int parameter);
|
||||
|
||||
void interpolate(float time);
|
||||
|
||||
// output operator
|
||||
friend ostream& operator<<(ostream& os, const Parameters& param);
|
||||
};
|
||||
|
||||
#endif // PARAMETER_HPP
|
126
Vector.cpp
126
Vector.cpp
|
@ -1,126 +0,0 @@
|
|||
#include <iostream>
|
||||
using namespace std;
|
||||
|
||||
#include "Vector.hpp"
|
||||
|
||||
Vector::Vector():
|
||||
dimension(0) {
|
||||
|
||||
coordinates = new (nothrow) float[0];
|
||||
|
||||
assert(coordinates != NULL);
|
||||
|
||||
#ifdef HARDDEBUG
|
||||
cout << "New vector (without elements)" << endl;
|
||||
#endif
|
||||
}
|
||||
|
||||
Vector::Vector(unsigned int d):
|
||||
dimension(d) {
|
||||
|
||||
coordinates = new (nothrow) float[dimension];
|
||||
|
||||
assert(coordinates != NULL);
|
||||
|
||||
#ifdef HARDDEBUG
|
||||
cout << "New vector:" << endl << *this << endl;
|
||||
#endif
|
||||
}
|
||||
|
||||
Vector::Vector(unsigned int d, float default_val):
|
||||
dimension(d) {
|
||||
|
||||
coordinates = new (nothrow) float[dimension];
|
||||
|
||||
assert(coordinates != NULL);
|
||||
|
||||
for (unsigned int i = 0; i < dimension; i++) {
|
||||
coordinates[i] = default_val;
|
||||
}
|
||||
|
||||
#ifdef HARDDEBUG
|
||||
cout << "New vector with default values:" << endl << *this << endl;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
Vector::~Vector() {
|
||||
delete[] coordinates;
|
||||
|
||||
#ifdef HARDDEBUG
|
||||
cout << "coordinates deleted" << endl;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
Vector& Vector::operator=(const Vector& a) {
|
||||
if ( dimension != a.dimension ) {
|
||||
dimension = a.dimension;
|
||||
delete[] coordinates;
|
||||
coordinates = new float[dimension];
|
||||
|
||||
#ifdef HARDDEBUG
|
||||
cout << "Dimensions were not equal, made new vector" << endl;
|
||||
#endif
|
||||
}
|
||||
|
||||
for ( unsigned int i = 0; i < dimension; i++ ) {
|
||||
coordinates[i] = a.coordinates[i];
|
||||
}
|
||||
|
||||
#ifdef HARDDEBUG
|
||||
cout << "operator= result" << endl << *this << endl;
|
||||
#endif
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
ostream& operator<<(ostream& os, const Vector& a) {
|
||||
os << a.dimension << endl;
|
||||
for ( unsigned int i = 0; i < a.dimension; i++ ) {
|
||||
os << a.coordinates[i] << " ";
|
||||
}
|
||||
|
||||
os << endl;
|
||||
return os;
|
||||
}
|
||||
|
||||
|
||||
float& Vector::operator[](const unsigned int index) {
|
||||
assert(index < dimension);
|
||||
return coordinates[index];
|
||||
}
|
||||
|
||||
// matig werkende optelling en scalaire vermenigvuldiging van vectoren
|
||||
/*
|
||||
Vector Vector::operator+(const Vector a) const {
|
||||
if ( dimension != a.dimension ) {
|
||||
cout << "WARNING: dimensions not equal in vector addition" << endl;
|
||||
exit(1);
|
||||
} else {
|
||||
static Vector ret(dimension);
|
||||
for ( unsigned int i = 0; i < dimension; i++ ) {
|
||||
ret.coordinates[i] = coordinates[i] + a.coordinates[i];
|
||||
}
|
||||
|
||||
#ifdef HARDDEBUG
|
||||
cout << "operator+ result" << endl << ret << endl;
|
||||
#endif
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Vector Vector::operator*(const float a) const {
|
||||
static Vector ret(dimension);
|
||||
for ( unsigned int i = 0; i < dimension; i++ ) {
|
||||
ret.coordinates[i] = coordinates[i] * a;
|
||||
}
|
||||
|
||||
#ifdef HARDDEBUG
|
||||
cout << "operator* result" << endl << ret << endl;
|
||||
#endif
|
||||
return ret;
|
||||
}
|
||||
*/
|
31
Vector.hpp
31
Vector.hpp
|
@ -1,31 +0,0 @@
|
|||
#ifndef VECTOR_HPP
|
||||
#define VECTOR_HPP
|
||||
|
||||
class Vector {
|
||||
public:
|
||||
|
||||
unsigned int dimension;
|
||||
float * coordinates;
|
||||
|
||||
// const, dest
|
||||
Vector();
|
||||
Vector(unsigned int d);
|
||||
Vector(unsigned int d, float default_val);
|
||||
~Vector();
|
||||
|
||||
// output operator
|
||||
friend ostream& operator<<(ostream& os, const Vector& a);
|
||||
|
||||
// easy access
|
||||
float& Vector::operator[](const unsigned int index);
|
||||
|
||||
// vector rekenen
|
||||
Vector& operator=(const Vector& a);
|
||||
// faaloperatoren
|
||||
// Vector operator+(const Vector a) const;
|
||||
// Vector operator*(const float a) const;
|
||||
};
|
||||
|
||||
|
||||
#endif // VECTOR_HPP
|
||||
|
|
@ -2,7 +2,7 @@
|
|||
input: "attractor"
|
||||
output: "png"
|
||||
|
||||
attractor: {
|
||||
AttractorKernel: {
|
||||
type: lorenz/unravel/polynomial/polynomial a/logistic
|
||||
=> "polynomial"
|
||||
dimensions: most types only support 3D
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
input: "attractor"
|
||||
output: "png"
|
||||
|
||||
attractor: {
|
||||
AttractorKernel: {
|
||||
type: lorenz/unravel/polynomial/polynomial a/logistic
|
||||
=> "polynomial"
|
||||
dimensions: most types only support 3D
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
input: "attractor"
|
||||
output: "png"
|
||||
|
||||
attractor: {
|
||||
AttractorKernel: {
|
||||
type: lorenz/unravel/polynomial/polynomial a/logistic
|
||||
=> "unravel"
|
||||
dimensions: most types only support 3D
|
||||
|
|
16
defines.hpp
16
defines.hpp
|
@ -1,15 +1,13 @@
|
|||
|
||||
|
||||
//TODO: do this with files
|
||||
#define ATTRACTOR_FILE "attractors/testUnravel.stf"
|
||||
#define DEFAULT_ATTRACTOR_FILE "attractors/testUnravel.stf"
|
||||
|
||||
#ifdef UNI_BUILD
|
||||
#warning Building for the RU, are you sure?
|
||||
#define WIDTH 8000
|
||||
#define HEIGHT 8000
|
||||
#define ITERATIONS 4200000000
|
||||
#define DEFAULT_WIDTH 8000
|
||||
#define DEFAULT_HEIGHT 8000
|
||||
#define DEFAULT_ITERATIONS 4200000000
|
||||
#else
|
||||
#define WIDTH 800
|
||||
#define HEIGHT 800
|
||||
#define ITERATIONS 1000000
|
||||
#define DEFAULT_WIDTH 800
|
||||
#define DEFAULT_HEIGHT 800
|
||||
#define DEFAULT_ITERATIONS 1000000
|
||||
#endif
|
||||
|
|
90
main.cpp
90
main.cpp
|
@ -1,6 +1,7 @@
|
|||
#include <iostream>
|
||||
#include <ctime>
|
||||
#include <valarray>
|
||||
#include <cstring>
|
||||
|
||||
#include "Attractor.hpp"
|
||||
#include "Canvas.hpp"
|
||||
|
@ -8,59 +9,68 @@
|
|||
|
||||
#include "defines.hpp"
|
||||
|
||||
/*
|
||||
I compared the performance of C-style arrays with valarray. My conclusion is that accessing and setting elements makes no difference (sometimes C-syle array's were just 2% faster, but sometimes valarray was 2% faster (5000000 samples)). But the allocation and initialisation of the valrray was like 30% faster, so it might be a good idea to change my C-style array to valarray. It is also nicer in use, one can use functions like sum, etc. How valarray manages memory may also be more efficient, but all i know is that a valarray<double> is bigger than a double* (in means of sizeof()), but that is not really an issue. So valarray!!!
|
||||
*/
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
std::cout << "Awesome Attractor, version " << __DATE__ << std::endl;
|
||||
|
||||
clock_t start, end;
|
||||
double totalTime, totalIterations;
|
||||
bool verbose = false;
|
||||
std::string attractorFile = DEFAULT_ATTRACTOR_FILE;
|
||||
unsigned int iterations = DEFAULT_ITERATIONS;
|
||||
unsigned int width = DEFAULT_WIDTH;
|
||||
unsigned int height = DEFAULT_HEIGHT;
|
||||
|
||||
bool verbose = false;
|
||||
for ( int i = 1; i < argc; ++i ) {
|
||||
if ( strcmp(argv[i], "-v") == 0 ) {
|
||||
verbose = true;
|
||||
} 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 {
|
||||
attractorFile = argv[i];
|
||||
}
|
||||
}
|
||||
|
||||
// initialising stuff
|
||||
Attractor myAttractor(ATTRACTOR_FILE);
|
||||
// initialising stuff
|
||||
Attractor myAttractor(attractorFile);
|
||||
|
||||
Projector projection;
|
||||
Canvas canvas(WIDTH, HEIGHT, 3);
|
||||
projection.canvas = &canvas;
|
||||
Projector projection;
|
||||
Canvas canvas(width, height, 3);
|
||||
projection.canvas = &canvas;
|
||||
|
||||
myAttractor.projectors.push_back(&projection);
|
||||
myAttractor.init_range();
|
||||
myAttractor.projectors.push_back(&projection);
|
||||
myAttractor.init_range();
|
||||
|
||||
projection.output();
|
||||
projection.output();
|
||||
|
||||
unsigned int iterations = ITERATIONS;
|
||||
start = clock();
|
||||
for ( unsigned int j = 1; j <= 100; j++ ) {
|
||||
for ( unsigned int i = 0; i <= iterations; i++ ) {
|
||||
myAttractor.iterate();
|
||||
myAttractor.plot();
|
||||
}
|
||||
if (verbose) {
|
||||
myAttractor.output();
|
||||
std::cout << j << "% done" << std::endl;
|
||||
}
|
||||
}
|
||||
end = clock();
|
||||
clock_t start, end;
|
||||
start = clock();
|
||||
for ( unsigned int j = 1; j <= 100; ++j ) {
|
||||
for ( unsigned int i = 0; i <= iterations; i++ ) {
|
||||
myAttractor.iterate();
|
||||
myAttractor.plot();
|
||||
}
|
||||
std::cout << "\r" << j << "% done" << std::flush;
|
||||
}
|
||||
end = clock();
|
||||
|
||||
totalIterations = 100.0*iterations;
|
||||
totalTime = ((double)(end-start)/(double)(CLOCKS_PER_SEC));
|
||||
std::cout << std::endl << "total clock time: " << totalTime << std::endl;
|
||||
std::cout << "average iterations per second: " << totalIterations/((double)(end-start)/(double)(CLOCKS_PER_SEC)) << std::endl << std::endl;
|
||||
double totalIterations = 100.0*iterations;
|
||||
double totalTime = ((double)(end-start)/(double)(CLOCKS_PER_SEC));
|
||||
std::cout << std::endl << "total clock time: " << totalTime << std::endl;
|
||||
std::cout << "average iterations per second: " << totalIterations/totalTime << std::endl << std::endl;
|
||||
|
||||
// saving output
|
||||
start = clock();
|
||||
canvas.output_file();
|
||||
end = clock();
|
||||
// saving output
|
||||
start = clock();
|
||||
canvas.output_file();
|
||||
end = clock();
|
||||
|
||||
totalTime = ((double)(end-start)/(double)(CLOCKS_PER_SEC));
|
||||
totalTime = ((double)(end-start)/(double)(CLOCKS_PER_SEC));
|
||||
|
||||
std::cout << "total clock time for writing png: " << totalTime << std::endl;
|
||||
std::cout << std::endl << "Awesome Attractor, version " << __DATE__ << std::endl;
|
||||
std::cout << "total clock time for writing png: " << totalTime << std::endl;
|
||||
|
||||
|
||||
return 0;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
Reference in a new issue