Browse Source

applied basicKernel everywhere

master
Joshua 15 years ago
parent
commit
9c88de6cc9
  1. 19
      AwesomeAttractor.cbp
  2. 15
      defines.hpp
  3. 5
      kernels/BasicKernel.cpp
  4. 14
      kernels/BasicKernel.h
  5. 19
      kernels/Logistic.cpp
  6. 26
      kernels/Logistic.hpp
  7. 17
      kernels/Lorenz3D.cpp
  8. 25
      kernels/Lorenz3D.hpp
  9. 20
      kernels/Polynomial.cpp
  10. 28
      kernels/Polynomial.hpp
  11. 16
      kernels/PolynomialA3D.cpp
  12. 28
      kernels/PolynomialA3D.hpp
  13. 16
      kernels/Unravel3D.cpp
  14. 28
      kernels/Unravel3D.hpp
  15. 10
      main.cpp

19
AwesomeAttractor.cbp

@ -12,18 +12,36 @@
<Option type="1" /> <Option type="1" />
<Option compiler="gcc" /> <Option compiler="gcc" />
<Compiler> <Compiler>
<Add option="-pg" />
<Add option="-g" /> <Add option="-g" />
</Compiler> </Compiler>
<Linker>
<Add option="-pg" />
</Linker>
</Target> </Target>
<Target title="Release"> <Target title="Release">
<Option output="bin/Release/AwesomeAttractor" prefix_auto="1" extension_auto="1" /> <Option output="bin/Release/AwesomeAttractor" prefix_auto="1" extension_auto="1" />
<Option object_output="obj/Release/" /> <Option object_output="obj/Release/" />
<Option type="1" /> <Option type="1" />
<Option compiler="gcc" /> <Option compiler="gcc" />
<Compiler>
<Add option="-fexpensive-optimizations" />
<Add option="-O3" />
</Compiler>
<Linker>
<Add option="-s" />
</Linker>
</Target>
<Target title="UniRelease">
<Option output="bin/UniRelease/AwesomeAttractor" prefix_auto="1" extension_auto="1" />
<Option object_output="obj/UniRelease/" />
<Option type="1" />
<Option compiler="gcc" />
<Compiler> <Compiler>
<Add option="-fexpensive-optimizations" /> <Add option="-fexpensive-optimizations" />
<Add option="-O3" /> <Add option="-O3" />
<Add option="-msse4.1" /> <Add option="-msse4.1" />
<Add option="-DUNI_BUILD" />
</Compiler> </Compiler>
<Linker> <Linker>
<Add option="-s" /> <Add option="-s" />
@ -49,6 +67,7 @@
<Unit filename="attractors/testLorenz.stf" /> <Unit filename="attractors/testLorenz.stf" />
<Unit filename="attractors/testPolynomial.stf" /> <Unit filename="attractors/testPolynomial.stf" />
<Unit filename="attractors/testUnravel.stf" /> <Unit filename="attractors/testUnravel.stf" />
<Unit filename="defines.hpp" />
<Unit filename="kernels/BasicKernel.cpp" /> <Unit filename="kernels/BasicKernel.cpp" />
<Unit filename="kernels/BasicKernel.h" /> <Unit filename="kernels/BasicKernel.h" />
<Unit filename="kernels/Logistic.cpp" /> <Unit filename="kernels/Logistic.cpp" />

15
defines.hpp

@ -0,0 +1,15 @@
//TODO: do this with files
#define ATTRACTOR_FILE "attractors/testPolynomial.stf"
#ifdef UNI_BUILD
#warning Building for the RU, are you sure?
#define WIDTH 8000
#define HEIGHT 8000
#define ITERATIONS 800000000
#else
#define WIDTH 800
#define HEIGHT 800
#define ITERATIONS 200000
#endif

5
kernels/BasicKernel.cpp

@ -1,6 +1,9 @@
#include "BasicKernel.h" #include "BasicKernel.h"
BasicKernel::BasicKernel():
myParameters(NULL), vectorNew(NULL), vectorOld(NULL) {
}
double * & BasicKernel::parameters() { double * & BasicKernel::parameters() {
return myParameters; return myParameters;
} }

14
kernels/BasicKernel.h

@ -1,20 +1,26 @@
#ifndef BASICKERNEL_HPP #ifndef BASICKERNEL_HPP
#define BASICKERNEL_HPP #define BASICKERNEL_HPP
#include <cassert>
#include <iostream> #include <iostream>
#include "../AttractorKernel.hpp" #include "../AttractorKernel.hpp"
/*
A basic abstract implementatoin of the AttractorKernel, should
be used to avoid copying the same stuff in all attractorKernels
*/
class BasicKernel : public AttractorKernel { class BasicKernel : public AttractorKernel {
protected: protected:
double * myParameters; double * myParameters;
double * vectorNew; double * vectorNew;
double * vectorOld; double * vectorOld;
public: public:
BasicKernel();
// parameters are stored in a array of doubles // parameters are stored in a array of doubles
// if you want to use other types, use the properties // if you want to use other types, use the properties
@ -27,5 +33,5 @@ class BasicKernel : public AttractorKernel {
}; };
#endif // POLYNOMIAL_HPP #endif

19
kernels/Logistic.cpp

@ -9,14 +9,14 @@
#include "Logistic.hpp" #include "Logistic.hpp"
Logistic::Logistic(): Logistic::Logistic():
myParameters(NULL), vectorNew(NULL), vectorOld(NULL) { BasicKernel() {
dimension = 3; dimension = 3;
init(); init();
} }
Logistic::Logistic(const unsigned int dimension): Logistic::Logistic(const unsigned int dimension):
myParameters(NULL), vectorNew(NULL), vectorOld(NULL), dimension(dimension) { BasicKernel(), dimension(dimension) {
init(); init();
} }
@ -76,22 +76,7 @@ void Logistic::setProperty(const string identifier, const void * _value) {
} }
} }
double * & Logistic::parameters() {
return myParameters;
}
double & Logistic::parameter(const unsigned int index) {
return myParameters[index];
}
unsigned int Logistic::getNumberOfParameters() { unsigned int Logistic::getNumberOfParameters() {
return dimension; return dimension;
} }
double * & Logistic::vector() {
return vectorNew;
}
double * & Logistic::previousVector() {
return vectorOld;
}

26
kernels/Logistic.hpp

@ -4,42 +4,26 @@
#include <cassert> #include <cassert>
#include "../AttractorKernel.hpp" #include "../AttractorKernel.hpp"
#include "BasicKernel.h"
class Logistic : public AttractorKernel { class Logistic : public BasicKernel {
double * myParameters;
double * vectorNew;
double * vectorOld;
unsigned int dimension; unsigned int dimension;
void init(); void init();
public: public:
Logistic(); Logistic();
Logistic(const unsigned int dimension); Logistic(const unsigned int dimension);
// parameters are stored in a array of doubles
// if you want to use other types, use the properties
virtual double& parameter(const unsigned int index);
virtual double*& parameters();
virtual unsigned int getNumberOfParameters(); virtual void iterate();
// get properties of the attractor
// such as the dimension
// you should delete the void pointer if you used it
virtual void * getProperty(const string identifier); virtual void * getProperty(const string identifier);
virtual void setProperty(const string identifier, const void * value); virtual void setProperty(const string identifier, const void * value);
virtual unsigned int getNumberOfParameters();
// iterate his formula
// vector pointers will be swapped! so new remains new and old remains old
virtual void iterate();
// getter functions for teh resulta
virtual double * & vector();
virtual double * & previousVector();
}; };
#endif // LOGISTIC_HPP #endif // LOGISTIC_HPP

17
kernels/Lorenz3D.cpp

@ -57,24 +57,7 @@ void Lorenz3D::setProperty(const string identifier, const void * value) {
return; return;
} }
//double * & Lorenz3D::parameters() {
// return myParameters;
//}
//
//double & Lorenz3D::parameter(const unsigned int index) {
// return myParameters[index];
//}
unsigned int Lorenz3D::getNumberOfParameters() { unsigned int Lorenz3D::getNumberOfParameters() {
return numberOfParameters; return numberOfParameters;
} }
//double * & Lorenz3D::vector() {
// return vectorNew;
//}
//
//double * & Lorenz3D::previousVector() {
// return vectorOld;
//}

25
kernels/Lorenz3D.hpp

@ -12,38 +12,19 @@ using namespace std;
class Lorenz3D : public BasicKernel { class Lorenz3D : public BasicKernel {
// double * myParameters;
//
// double * vectorNew;
// double * vectorOld;
void init(); void init();
public: public:
Lorenz3D(); Lorenz3D();
Lorenz3D(const unsigned int dimensions); Lorenz3D(const unsigned int dimensions);
// parameters are stored in a array of doubles
// if you want to use other types, use the properties
// virtual double& parameter(const unsigned int index);
// virtual double*& parameters();
virtual unsigned int getNumberOfParameters(); virtual void iterate();
// get properties of the attractor
// such as the dimension
// you should delete the void pointer if you used it
virtual void * getProperty(const string identifier); virtual void * getProperty(const string identifier);
virtual void setProperty(const string identifier, const void * value); virtual void setProperty(const string identifier, const void * value);
virtual unsigned int getNumberOfParameters();
// iterate his formula
// vector pointers will be swapped! so new remains new and old remains old
virtual void iterate();
// getter functions for teh resulta
// virtual double * & vector();
// virtual double * & previousVector();
}; };

20
kernels/Polynomial.cpp

@ -11,7 +11,7 @@
using namespace std; using namespace std;
Polynomial::Polynomial(): Polynomial::Polynomial():
myParameters(NULL), vectorNew(NULL), vectorOld(NULL) { BasicKernel() {
dimension = 3; dimension = 3;
orde = 2; orde = 2;
@ -19,7 +19,7 @@ Polynomial::Polynomial():
} }
Polynomial::Polynomial(const unsigned int dimension, const unsigned int orde): Polynomial::Polynomial(const unsigned int dimension, const unsigned int orde):
myParameters(NULL), vectorNew(NULL), vectorOld(NULL), dimension(dimension), orde(orde) { BasicKernel(), dimension(dimension), orde(orde) {
init(); init();
} }
@ -124,22 +124,6 @@ void Polynomial::setProperty(const string identifier, const void * _value) {
} }
} }
double * & Polynomial::parameters() {
return myParameters;
}
double & Polynomial::parameter(const unsigned int index) {
return myParameters[index];
}
unsigned int Polynomial::getNumberOfParameters() { unsigned int Polynomial::getNumberOfParameters() {
return numberOfParameters; return numberOfParameters;
} }
double * & Polynomial::vector() {
return vectorNew;
}
double * & Polynomial::previousVector() {
return vectorOld;
}

28
kernels/Polynomial.hpp

@ -5,13 +5,9 @@
#include <iostream> #include <iostream>
#include "../AttractorKernel.hpp" #include "../AttractorKernel.hpp"
#include "BasicKernel.h"
class Polynomial : public AttractorKernel { class Polynomial : public BasicKernel {
double * myParameters;
double * vectorNew;
double * vectorOld;
unsigned int dimension; unsigned int dimension;
unsigned int orde; unsigned int orde;
@ -21,31 +17,17 @@ class Polynomial : public AttractorKernel {
void calculateNumberOfParameters(); void calculateNumberOfParameters();
void recur(unsigned int curr_dimension, unsigned int prev_i, unsigned int n, unsigned int& m, double prev_product=1.0); void recur(unsigned int curr_dimension, unsigned int prev_i, unsigned int n, unsigned int& m, double prev_product=1.0);
public: public:
Polynomial(); Polynomial();
Polynomial(const unsigned int dimensions, const unsigned int orde); Polynomial(const unsigned int dimensions, const unsigned int orde);
// parameters are stored in a array of doubles
// if you want to use other types, use the properties
virtual double& parameter(const unsigned int index);
virtual double*& parameters();
virtual unsigned int getNumberOfParameters(); virtual void iterate();
// get properties of the attractor
// such as the dimension
// you should delete the void pointer if you used it
virtual void * getProperty(const string identifier); virtual void * getProperty(const string identifier);
virtual void setProperty(const string identifier, const void * value); virtual void setProperty(const string identifier, const void * value);
virtual unsigned int getNumberOfParameters();
// iterate his formula
// vector pointers will be swapped! so new remains new and old remains old
virtual void iterate();
// getter functions for teh resulta
virtual double * & vector();
virtual double * & previousVector();
}; };

16
kernels/PolynomialA3D.cpp

@ -60,22 +60,6 @@ void PolynomialA3D::setProperty(const string identifier, const void * _value) {
} }
double * & PolynomialA3D::parameters() {
return myParameters;
}
double & PolynomialA3D::parameter(const unsigned int index) {
return myParameters[index];
}
unsigned int PolynomialA3D::getNumberOfParameters() { unsigned int PolynomialA3D::getNumberOfParameters() {
return numberOfParameters; return numberOfParameters;
} }
double * & PolynomialA3D::vector() {
return vectorNew;
}
double * & PolynomialA3D::previousVector() {
return vectorOld;
}

28
kernels/PolynomialA3D.hpp

@ -4,41 +4,23 @@
#include <cassert> #include <cassert>
#include "../AttractorKernel.hpp" #include "../AttractorKernel.hpp"
#include "BasicKernel.h"
class PolynomialA3D : public AttractorKernel { class PolynomialA3D : public BasicKernel {
// of course this can be seen as a subclasse of Polynomial // of course this can be seen as a subclasse of Polynomial
double * myParameters;
double * vectorNew;
double * vectorOld;
void init(); void init();
public: public:
PolynomialA3D(); PolynomialA3D();
// parameters are stored in a array of doubles
// if you want to use other types, use the properties
virtual double& parameter(const unsigned int index);
virtual double*& parameters();
virtual unsigned int getNumberOfParameters(); virtual void iterate();
// get properties of the attractor
// such as the dimension
// you should delete the void pointer if you used it
virtual void * getProperty(const string identifier); virtual void * getProperty(const string identifier);
virtual void setProperty(const string identifier, const void * value); virtual void setProperty(const string identifier, const void * value);
virtual unsigned int getNumberOfParameters();
// iterate his formula
// vector pointers will be swapped! so new remains new and old remains old
virtual void iterate();
// getter functions for teh resulta
virtual double * & vector();
virtual double * & previousVector();
}; };

16
kernels/Unravel3D.cpp

@ -57,22 +57,6 @@ void Unravel3D::setProperty(const string identifier, const void * value) {
return; return;
} }
double * & Unravel3D::parameters() {
return myParameters;
}
double & Unravel3D::parameter(const unsigned int index) {
return myParameters[index];
}
unsigned int Unravel3D::getNumberOfParameters() { unsigned int Unravel3D::getNumberOfParameters() {
return numberOfParameters; return numberOfParameters;
} }
double * & Unravel3D::vector() {
return vectorNew;
}
double * & Unravel3D::previousVector() {
return vectorOld;
}

28
kernels/Unravel3D.hpp

@ -9,41 +9,23 @@
using namespace std; using namespace std;
#include "../AttractorKernel.hpp" #include "../AttractorKernel.hpp"
#include "BasicKernel.h"
class Unravel3D : public AttractorKernel { class Unravel3D : public BasicKernel {
double * myParameters;
double * vectorNew;
double * vectorOld;
void init(); void init();
public: public:
Unravel3D(); Unravel3D();
Unravel3D(const unsigned int dimensions); Unravel3D(const unsigned int dimensions);
// parameters are stored in a array of doubles
// if you want to use other types, use the properties
virtual double& parameter(const unsigned int index);
virtual double*& parameters();
virtual unsigned int getNumberOfParameters(); virtual void iterate();
// get properties of the attractor
// such as the dimension
// you should delete the void pointer if you used it
virtual void * getProperty(const string identifier); virtual void * getProperty(const string identifier);
virtual void setProperty(const string identifier, const void * value); virtual void setProperty(const string identifier, const void * value);
virtual unsigned int getNumberOfParameters();
// iterate his formula
// vector pointers will be swapped! so new remains new and old remains old
virtual void iterate();
// getter functions for teh resulta
virtual double * & vector();
virtual double * & previousVector();
}; };

10
main.cpp

@ -6,15 +6,17 @@ using namespace std;
#include "Canvas.hpp" #include "Canvas.hpp"
#include "Projector.hpp" #include "Projector.hpp"
#include "defines.hpp"
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
clock_t start, end; clock_t start, end;
double totalTime, totalIterations; double totalTime, totalIterations;
// initialising stuff // initialising stuff
Attractor myAttractor("attractors/testPolynomial.stf"); Attractor myAttractor(ATTRACTOR_FILE);
Projector projection; Projector projection;
Canvas canvas(8000, 8000, 3); Canvas canvas(WIDTH, HEIGHT, 3);
projection.canvas = &canvas; projection.canvas = &canvas;
myAttractor.projectors.push_back(&projection); myAttractor.projectors.push_back(&projection);
@ -22,8 +24,7 @@ int main(int argc, char *argv[]) {
projection.output(); projection.output();
// iterating 4 evah unsigned int iterations = ITERATIONS;
unsigned int iterations = 800000000; // acht honderd miljoen
start = clock(); 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++ ) { for ( unsigned int i = 0; i <= iterations; i++ ) {
@ -49,6 +50,7 @@ int main(int argc, char *argv[]) {
totalTime = ((double)(end-start)/(double)(CLOCKS_PER_SEC)); totalTime = ((double)(end-start)/(double)(CLOCKS_PER_SEC));
printf("total clock time for writing png: %f\n", totalTime ); printf("total clock time for writing png: %f\n", totalTime );
printf("\n Awesome Attractor, version %s\n", __DATE__);
/*if ( argc <= 2 ) { /*if ( argc <= 2 ) {
cout << endl << "nothing to do..." << endl; cout << endl << "nothing to do..." << endl;