Browse Source

removed old files, added command line arguments

master
Joshua Moerman 14 years ago
parent
commit
cc018547f0
  1. 6
      Attractor.cpp
  2. 3
      Attractor.hpp
  3. 110
      Parameters.cpp
  4. 34
      Parameters.hpp
  5. 126
      Vector.cpp
  6. 31
      Vector.hpp
  7. 2
      attractors/testAttractor.stf
  8. 2
      attractors/testPolynomial.stf
  9. 2
      attractors/testUnravel.stf
  10. 16
      defines.hpp
  11. 48
      main.cpp

6
Attractor.cpp

@ -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);

3
Attractor.hpp

@ -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

@ -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;
}

34
Parameters.hpp

@ -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

@ -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

@ -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
attractors/testAttractor.stf

@ -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
attractors/testPolynomial.stf

@ -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
attractors/testUnravel.stf

@ -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

@ -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

48
main.cpp

@ -1,6 +1,7 @@
#include <iostream>
#include <ctime>
#include <valarray>
#include <cstring>
#include "Attractor.hpp"
#include "Canvas.hpp"
@ -8,22 +9,34 @@
#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[]) {
clock_t start, end;
double totalTime, totalIterations;
std::cout << "Awesome Attractor, version " << __DATE__ << std::endl;
bool verbose = false;
std::string attractorFile = DEFAULT_ATTRACTOR_FILE;
unsigned int iterations = DEFAULT_ITERATIONS;
unsigned int width = DEFAULT_WIDTH;
unsigned int height = DEFAULT_HEIGHT;
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);
Attractor myAttractor(attractorFile);
Projector projection;
Canvas canvas(WIDTH, HEIGHT, 3);
Canvas canvas(width, height, 3);
projection.canvas = &canvas;
myAttractor.projectors.push_back(&projection);
@ -31,24 +44,21 @@ int main(int argc, char *argv[]) {
projection.output();
unsigned int iterations = ITERATIONS;
clock_t start, end;
start = clock();
for ( unsigned int j = 1; j <= 100; j++ ) {
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;
}
std::cout << "\r" << j << "% done" << std::flush;
}
end = clock();
totalIterations = 100.0*iterations;
totalTime = ((double)(end-start)/(double)(CLOCKS_PER_SEC));
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/((double)(end-start)/(double)(CLOCKS_PER_SEC)) << std::endl << std::endl;
std::cout << "average iterations per second: " << totalIterations/totalTime << std::endl << std::endl;
// saving output
start = clock();
@ -58,7 +68,7 @@ int main(int argc, char *argv[]) {
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;
return 0;