Browse Source

middle of something big

master
Joshua Moerman 14 years ago
parent
commit
8914552abf
  1. 43
      Attractor.cpp
  2. 6
      Attractor.hpp
  3. 3
      AttractorKernel.cpp
  4. 1
      AttractorKernel.hpp
  5. 58
      AwesomeAttractor.cbp
  6. 1
      Logger.hpp
  7. 22
      Projector.cpp
  8. 52
      Projector.hpp
  9. 16
      attractors/testUnravelNew.stf
  10. 35
      main.cpp
  11. 24
      ostream_helpers.h

43
Attractor.cpp

@ -10,19 +10,19 @@
#include "Projector.hpp" #include "Projector.hpp"
Attractor::Attractor(const std::string& filename) { Attractor::Attractor(const std::string& filename) : kernel(0), projector(0) {
// opening file // opening file
LogInfo("Reading file '%s'...\n", filename.c_str()); LogInfo("Reading file '%s'...\n", filename.c_str());
stfu::node system; stfu::node system;
system.read(filename.c_str()); system.read(filename.c_str());
stfu::node attractor = system.getChild("AttractorKernel");
myAttractor = AttractorKernel::createAttractorKernel(attractor); kernel = AttractorKernel::createAttractorKernel(system.getChild("AttractorKernel"));
projector = Projector::createProjector(system.getChild(system.getChild("Projector")), system);
} }
Attractor::~Attractor(){ Attractor::~Attractor(){
delete myAttractor; delete kernel;
} }
@ -33,26 +33,21 @@ void Attractor::init_range() {
iterate(); iterate();
} }
// initialize projectors with dimension and first point // initialize projector with dimension and first point
const unsigned int dimension = myAttractor->getDimension(); const unsigned int dimension = kernel->getDimension();
const double * point = myAttractor->vector(); const double * point = kernel->vector();
for ( std::vector<Projector*>::iterator it = projectors.begin(); it != projectors.end(); it++ ) {
(*it)->extern_dim = dimension; projector->extern_dim = dimension;
(*it)->intern_dim = 3; projector->intern_dim = 3;
(*it)->init(point); projector->init(point);
}
// update ranges // update ranges
for ( unsigned int i = 0; i < 500000; i++ ) { for ( unsigned int i = 0; i < 500000; i++ ) {
iterate(); iterate();
for ( std::vector<Projector*>::iterator it = projectors.begin(); it != projectors.end(); it++ ) { projector->update_range(point);
(*it)->update_range(point);
}
}
for ( std::vector<Projector*>::iterator it = projectors.begin(); it != projectors.end(); it++ ) {
(*it)->finish_range();
} }
projector->finish_range();
} }
@ -83,14 +78,12 @@ bool Attractor::is_chaos() {
} }
void Attractor::iterate() { void Attractor::iterate() {
(*myAttractor)(); (*kernel)();
} }
void Attractor::plot() { void Attractor::plot() {
for ( std::vector<Projector *>::iterator it = projectors.begin(); it != projectors.end(); it++ ) { const double * point = kernel->vector();
const double * point = myAttractor->vector(); projector->plot(point);
(*it)->plot(point);
}
} }
@ -98,8 +91,8 @@ void Attractor::plot() {
IO & control IO & control
*/ */
void Attractor::output() { void Attractor::output() {
const unsigned int dimension = myAttractor->getDimension(); const unsigned int dimension = kernel->getDimension();
const double * point = myAttractor->vector(); const double * point = kernel->vector();
for ( unsigned int i = 0; i < dimension; i++ ) { for ( unsigned int i = 0; i < dimension; i++ ) {
LogMoreInfo("%f, ", point[i]); LogMoreInfo("%f, ", point[i]);

6
Attractor.hpp

@ -10,12 +10,12 @@ class AttractorKernel;
class Attractor { class Attractor {
private: private:
AttractorKernel * myAttractor; AttractorKernel * kernel;
public: public:
// should be private really // should be private really
std::vector<Projector *> projectors; Projector* projector;
Attractor(const std::string& filename); Attractor(const std::string& filename);
~Attractor(); ~Attractor();
@ -27,6 +27,8 @@ public:
void plot(); void plot();
void output(); void output();
friend std::ostream& operator<<(std::ostream& os, Attractor const& x);
}; };
#endif // ATTRACTOR_HPP #endif // ATTRACTOR_HPP

3
AttractorKernel.cpp

@ -19,8 +19,7 @@ numberOfParameters(numberOfParameters), dimension(dimension){
try { try {
allocate(); allocate();
} } catch (std::exception& e) {
catch (std::exception& e) {
LogError("Couldn't construct Attractorkernel: %s\n", e.what()); LogError("Couldn't construct Attractorkernel: %s\n", e.what());
dealloc(); dealloc();
} }

1
AttractorKernel.hpp

@ -46,5 +46,6 @@ public:
}; };
#endif // ATTRACTORKERNEL_HPP #endif // ATTRACTORKERNEL_HPP

58
AwesomeAttractor.cbp

@ -7,8 +7,8 @@
<Option compiler="gcc" /> <Option compiler="gcc" />
<Build> <Build>
<Target title="Debug"> <Target title="Debug">
<Option output="bin\Debug\AwesomeAttractor" prefix_auto="1" extension_auto="1" /> <Option output="bin/Debug/AwesomeAttractor" prefix_auto="1" extension_auto="1" />
<Option object_output="obj\Debug\" /> <Option object_output="obj/Debug/" />
<Option type="1" /> <Option type="1" />
<Option compiler="gcc" /> <Option compiler="gcc" />
<Compiler> <Compiler>
@ -20,8 +20,8 @@
</Linker> </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> <Compiler>
@ -33,8 +33,8 @@
</Linker> </Linker>
</Target> </Target>
<Target title="UniRelease"> <Target title="UniRelease">
<Option output="bin\UniRelease\AwesomeAttractor" prefix_auto="1" extension_auto="1" /> <Option output="bin/UniRelease/AwesomeAttractor" prefix_auto="1" extension_auto="1" />
<Option object_output="obj\UniRelease\" /> <Option object_output="obj/UniRelease/" />
<Option type="1" /> <Option type="1" />
<Option compiler="gcc" /> <Option compiler="gcc" />
<Compiler> <Compiler>
@ -58,43 +58,45 @@
<Unit filename="AttractorKernel.hpp" /> <Unit filename="AttractorKernel.hpp" />
<Unit filename="Canvas.cpp" /> <Unit filename="Canvas.cpp" />
<Unit filename="Canvas.hpp" /> <Unit filename="Canvas.hpp" />
<Unit filename="Logger.hpp" />
<Unit filename="Projector.cpp" /> <Unit filename="Projector.cpp" />
<Unit filename="Projector.hpp"> <Unit filename="Projector.hpp">
<Option compilerVar="CC" /> <Option compilerVar="CC" />
</Unit> </Unit>
<Unit filename="attractors\testAttractor.stf" /> <Unit filename="attractors/testAttractor.stf" />
<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="canvae\PNG.cpp"> <Unit filename="canvae/PNG.cpp">
<Option target="&lt;{~None~}&gt;" /> <Option target="&lt;{~None~}&gt;" />
</Unit> </Unit>
<Unit filename="canvae\PNG.hpp"> <Unit filename="canvae/PNG.hpp">
<Option target="&lt;{~None~}&gt;" /> <Option target="&lt;{~None~}&gt;" />
</Unit> </Unit>
<Unit filename="canvae\Raw.cpp" /> <Unit filename="canvae/Raw.cpp" />
<Unit filename="canvae\Raw.hpp" /> <Unit filename="canvae/Raw.hpp" />
<Unit filename="defines.hpp" /> <Unit filename="defines.hpp" />
<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" />
<Unit filename="kernels\Lorenz3D.hpp" /> <Unit filename="kernels/Lorenz3D.hpp" />
<Unit filename="kernels\Polynomial.cpp" /> <Unit filename="kernels/Polynomial.cpp" />
<Unit filename="kernels\Polynomial.hpp" /> <Unit filename="kernels/Polynomial.hpp" />
<Unit filename="kernels\PolynomialA3D.cpp" /> <Unit filename="kernels/PolynomialA3D.cpp" />
<Unit filename="kernels\PolynomialA3D.hpp" /> <Unit filename="kernels/PolynomialA3D.hpp" />
<Unit filename="kernels\Unravel3D.cpp" /> <Unit filename="kernels/Unravel3D.cpp" />
<Unit filename="kernels\Unravel3D.hpp" /> <Unit filename="kernels/Unravel3D.hpp" />
<Unit filename="main.cpp" /> <Unit filename="main.cpp" />
<Unit filename="myMath.hpp" /> <Unit filename="myMath.hpp" />
<Unit filename="pngwriter\pngwriter.cc"> <Unit filename="ostream_helpers.h" />
<Unit filename="pngwriter/pngwriter.cc">
<Option target="&lt;{~None~}&gt;" /> <Option target="&lt;{~None~}&gt;" />
</Unit> </Unit>
<Unit filename="pngwriter\pngwriter.h"> <Unit filename="pngwriter/pngwriter.h">
<Option target="&lt;{~None~}&gt;" /> <Option target="&lt;{~None~}&gt;" />
</Unit> </Unit>
<Unit filename="stfu\stf.cpp" /> <Unit filename="stfu/stf.cpp" />
<Unit filename="stfu\stf.hpp" /> <Unit filename="stfu/stf.hpp" />
<Extensions> <Extensions>
<code_completion /> <code_completion />
<envvars /> <envvars />

1
Logger.hpp

@ -18,4 +18,5 @@ extern int verbose;
if ( verbose >= 0 ) { printf("%s, %d: ", __FILE__, __LINE__); printf(s, ##__VA_ARGS__); } if ( verbose >= 0 ) { printf("%s, %d: ", __FILE__, __LINE__); printf(s, ##__VA_ARGS__); }
#endif // LOGGER_HPP_INCLUDED #endif // LOGGER_HPP_INCLUDED

22
Projector.cpp

@ -6,6 +6,28 @@
#include "Canvas.hpp" #include "Canvas.hpp"
#include "myMath.hpp" #include "myMath.hpp"
Projector* Projector::createProjector(stfu::node const& projector, stfu::node const& system){
}
void Projector::allocate(){
projectedPoint = new double[outputDimension];
}
void Projector::deallocate(){
delete[] projectedPoint;
projectedPoint = NULL;
}
Projector::Projector(unsigned int inputDimension, unsigned int outputDimension) : inputDimension(inputDimension), outputDimension(outputDimension) {
try {
allocate();
} catch (std::exception& e) {
LogError("Couldn't construct Projector: %s\n", e.what());
deallocate();
}
}
void Projector::init(const double * point) { void Projector::init(const double * point) {
init_vector(); init_vector();

52
Projector.hpp

@ -1,38 +1,50 @@
#ifndef PROJECTOR_HPP #ifndef PROJECTOR_HPP
#define PROJECTOR_HPP #define PROJECTOR_HPP
#include "stfu/stf.hpp"
class Canvas; class Canvas;
class Projector{ class Projector {
public: private:
Canvas* canvas;
Projector* projector;
allocate();
deallocate();
unsigned int extern_dim; protected:
unsigned int intern_dim; unsigned int inputDimension;
unsigned int outputDimension;
Canvas * canvas; double* projectedPoint;
double * project_point;
double * range_min; double* range_min;
double * range_max; double* range_max;
double factor; double factor;
double * offset; double* offset;
void project(const double* point);
public:
Projector(unsigned int inputDimension, unsigned int outputDimension);
void init(const double * point); virtual ~Projector();
static Projector* createProjector(stfu::node const& projector, stfu::node const& system);
void init(const double* point);
void init_vector(); void init_vector();
void init_range(); void init_range();
void update_range(const double * point); void update_range(const double* point);
void finish_range(); void finish_range();
void plot(const double* point);
// TODO : Matrix gebruiken voor lineaire afbeelding
// TODO : Over kleuren nadenken
/*
Kleurmodi:
-genormalizeerde coordinaten als kleurintensiteit (gebruikt fp canvas)
-kleurbanden, dus met een periodieke functie (gebruikt int canvas)
*/
void project(const double * point);
void plot(const double * point);
void output(); void output();
}; };

16
attractors/testUnravelNew.stf

@ -1,6 +1,5 @@
input: "AttractorKernel" Projector: "FirstProjector"
output: "Canvas"
iterations: "100000" iterations: "100000"
AttractorKernel: { AttractorKernel: {
@ -19,11 +18,13 @@ AttractorKernel: {
} }
} }
projections: Applied in order they appear { FirstProjector: {
:{
type: "auto center" type: "auto center"
}
:{ Projector: "SecondProjector"
}
SecondProjector {
type: "lineair map" type: "lineair map"
matrix: matrix:
@ -31,7 +32,8 @@ projections: Applied in order they appear {
:{ :"1" :"0" :"0" } :{ :"1" :"0" :"0" }
:{ :"0" :"1" :"0" } :{ :"0" :"1" :"0" }
} }
}
Canvas: "Canvas"
} }
Canvas: { Canvas: {

35
main.cpp

@ -8,14 +8,15 @@
#include "Canvas.hpp" #include "Canvas.hpp"
#include "Projector.hpp" #include "Projector.hpp"
#include "canvae\Raw.hpp" #include "canvae/Raw.hpp"
#include "ostream_helpers.h"
#include "defines.hpp" #include "defines.hpp"
int verbose; int verbose;
void showHelpText(){ void showHelpText() {
std::cout << "Awesome Attractor, version " << __DATE__ << std::endl; std::cout << "Awesome Attractor, version " << __DATE__ << std::endl;
std::cout << "Usage: AwesomeAttractor [OPTION]... FILE" << std::endl << std::endl; std::cout << "Usage: AwesomeAttractor [OPTION]... FILE" << std::endl << std::endl;
std::cout << "Optons:" << std::endl; std::cout << "Optons:" << std::endl;
@ -29,31 +30,31 @@ void showHelpText(){
exit(0); exit(0);
} }
int main(int argc, char *argv[]) { int main(int argc, char* argv[]) {
verbose = 0; verbose = 0;
std::string attractorFile = DEFAULT_ATTRACTOR_FILE; std::string attractorFile = DEFAULT_ATTRACTOR_FILE;
unsigned int iterations = DEFAULT_ITERATIONS; unsigned int iterations = DEFAULT_ITERATIONS;
unsigned int width = DEFAULT_WIDTH; unsigned int width = DEFAULT_WIDTH;
unsigned int height = DEFAULT_HEIGHT; unsigned int height = DEFAULT_HEIGHT;
if ( argc <= 1 ) { if(argc <= 1) {
showHelpText(); showHelpText();
} }
for ( int i = 1; i < argc; ++i ) { for(int i = 1; i < argc; ++i) {
if ( strcmp(argv[i], "-v") == 0 ) { if(strcmp(argv[i], "-v") == 0) {
verbose = 1; verbose = 1;
} else if ( strcmp(argv[i], "-q") == 0 ) { } else if(strcmp(argv[i], "-q") == 0) {
verbose = -1; verbose = -1;
} else if ( strcmp(argv[i], "--help") == 0 ) { } else if(strcmp(argv[i], "--help") == 0) {
showHelpText(); showHelpText();
} else if ( strcmp(argv[i], "-V") == 0 ) { } else if(strcmp(argv[i], "-V") == 0) {
verbose = 3; verbose = 3;
} else if ( strcmp(argv[i], "-w") == 0 ) { } else if(strcmp(argv[i], "-w") == 0) {
width = atoi(argv[++i]); width = atoi(argv[++i]);
} else if ( strcmp(argv[i], "-h") == 0 ) { } else if(strcmp(argv[i], "-h") == 0) {
height = atoi(argv[++i]); height = atoi(argv[++i]);
} else if ( strcmp(argv[i], "-i") == 0 ) { } else if(strcmp(argv[i], "-i") == 0) {
iterations = atoi(argv[++i]); iterations = atoi(argv[++i]);
} else { } else {
attractorFile = argv[i]; attractorFile = argv[i];
@ -70,7 +71,7 @@ int main(int argc, char *argv[]) {
Canvas* canvas = new Raw(3, sizes); Canvas* canvas = new Raw(3, sizes);
projection.canvas = canvas; projection.canvas = canvas;
myAttractor.projectors.push_back(&projection); myAttractor.projector = &projection;
myAttractor.init_range(); myAttractor.init_range();
projection.output(); projection.output();
@ -79,12 +80,12 @@ int main(int argc, char *argv[]) {
clock_t start, end; clock_t start, end;
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++) {
myAttractor.iterate(); myAttractor.iterate();
myAttractor.plot(); myAttractor.plot();
} }
if ( verbose >= 0 ) { if(verbose >= 0) {
std::cout << "\r" << j << "% done" << std::flush; std::cout << "\r" << j << "% done" << std::flush;
} }
} }
@ -115,3 +116,5 @@ int main(int argc, char *argv[]) {
return 0; return 0;
} }

24
ostream_helpers.h

@ -0,0 +1,24 @@
#ifndef OSTREAM_HELPERS_HPP
#define OSTREAM_HELPERS_HPP
#include <iterator>
#include <algorithm>
#include "AttractorKernel.hpp"
#include "Attractor.hpp"
std::ostream& operator<<(std::ostream& os, AttractorKernel const& x) {
const unsigned int dimension = x.getDimension();
const double * point = x.vector();
std::copy(point, point+dimension, std::ostream_iterator<double>(os, ", "));
return os;
}
std::ostream& operator<<(std::ostream& os, Attractor const& x) {
os << x.kernel << "\n";
os << x.projector << "\n";
return os;
}
#endif // OSTREAM_HELPERS_HPP