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. 28
      attractors/testUnravelNew.stf
  10. 35
      main.cpp
  11. 24
      ostream_helpers.h

43
Attractor.cpp

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

6
Attractor.hpp

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

3
AttractorKernel.cpp

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

1
AttractorKernel.hpp

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

58
AwesomeAttractor.cbp

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

1
Logger.hpp

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

22
Projector.cpp

@ -6,6 +6,28 @@
#include "Canvas.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) {
init_vector();

52
Projector.hpp

@ -1,38 +1,50 @@
#ifndef PROJECTOR_HPP
#define PROJECTOR_HPP
#include "stfu/stf.hpp"
class Canvas;
class Projector{
public:
class Projector {
private:
Canvas* canvas;
Projector* projector;
allocate();
deallocate();
unsigned int extern_dim;
unsigned int intern_dim;
protected:
unsigned int inputDimension;
unsigned int outputDimension;
Canvas * canvas;
double * project_point;
double* projectedPoint;
double * range_min;
double * range_max;
double* range_min;
double* range_max;
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_range();
void update_range(const double * point);
void update_range(const double* point);
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();
};

28
attractors/testUnravelNew.stf

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

35
main.cpp

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