diff --git a/Attractor.cpp b/Attractor.cpp index 422d014..8d5187f 100644 --- a/Attractor.cpp +++ b/Attractor.cpp @@ -18,7 +18,7 @@ Attractor::Attractor(const std::string& filename) : kernel(0), projector(0) { system.read(filename.c_str()); kernel = AttractorKernel::createAttractorKernel(system.getChild("AttractorKernel")); - projector = Projector::createProjector(system.getChild(system.getChild("Projector")), system); + projector = Projector::createProjector(system.getChild(system.getValue("Projector")), system); } Attractor::~Attractor(){ @@ -32,23 +32,6 @@ void Attractor::init_range() { for ( unsigned int i = 0; i < 100000; i++ ) { iterate(); } - - // 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(); - - projector->update_range(point); - } - projector->finish_range(); - } bool Attractor::is_chaos() { diff --git a/Projector.cpp b/Projector.cpp index 9f568f8..11736b9 100644 --- a/Projector.cpp +++ b/Projector.cpp @@ -1,8 +1,8 @@ #include "Logger.hpp" -#include -#include - #include "Projector.hpp" + +#include + #include "Canvas.hpp" #pragma mark - @@ -15,10 +15,11 @@ Projector::Projector(unsigned int inputDimension, unsigned int outputDimension) LogError("Couldn't construct Projector: %s\n", e.what()); deallocate(); } + std::fill_n(projectedPoint, outputDimension, 0.0); } Projector::~Projector(){ - deallocate()(); + deallocate(); } void Projector::allocate() { @@ -53,6 +54,8 @@ void Projector::plot(const double* point) { #include "projectors/Normalizer.hpp" Projector* Projector::createProjector(stfu::node const& projector, stfu::node const& system) { + Projector* output = new Normalizer(3); + return new Normalizer(3); } diff --git a/Projector.hpp b/Projector.hpp index 86bf2e9..ebe3d38 100644 --- a/Projector.hpp +++ b/Projector.hpp @@ -24,7 +24,7 @@ protected: virtual void project(const double* point) = 0; public: - Projector(unsigned int inputDimension, unsigned int outputDimension, unsigned int state); + Projector(unsigned int inputDimension, unsigned int outputDimension); virtual ~Projector(); // delegates forward trough the chain, know wha i'm sayin'? diff --git a/main.cpp b/main.cpp index b9d2d84..25b324f 100644 --- a/main.cpp +++ b/main.cpp @@ -66,15 +66,13 @@ int main(int argc, char* argv[]) { // initialising stuff Attractor myAttractor(attractorFile); - Projector projection; - unsigned int sizes[] = {128, 128, 128}; + /*unsigned int sizes[] = {128, 128, 128}; Canvas* canvas = new Raw(3, sizes); - projection.canvas = canvas; + projection.canvas = canvas;*/ - myAttractor.projector = &projection; myAttractor.init_range(); - projection.output(); + //projection.output(); LogInfo("\nRendering\n"); @@ -104,7 +102,7 @@ int main(int argc, char* argv[]) { sprintf(filename, "render/attractor_%04d-%02d-%02d_%02d-%02d-%02d-%01d.raw", lt->tm_year + 1900, lt->tm_mon + 1, lt->tm_mday, lt->tm_hour, lt->tm_min, lt->tm_sec, r); start = clock(); - canvas->output_file(filename); + //canvas->output_file(filename); end = clock(); totalTime = ((double)(end-start)/(double)(CLOCKS_PER_SEC)); diff --git a/projectors/Normalizer.cpp b/projectors/Normalizer.cpp index d34dc29..3fca94f 100644 --- a/projectors/Normalizer.cpp +++ b/projectors/Normalizer.cpp @@ -1,9 +1,10 @@ +#include "../Logger.hpp" #include "Normalizer.hpp" #pragma mark - #pragma mark memory -Normalizer::Normalizer(unsigned int dimension) : Projector(dimension, dimension) { +Normalizer::Normalizer(unsigned int dimension) : Projector(dimension, dimension), factor(1) { ready = false; try { @@ -12,16 +13,20 @@ Normalizer::Normalizer(unsigned int dimension) : Projector(dimension, dimension) LogError("Couldn't construct Normalizer (Projector): %s\n", e.what()); deallocate(); } + + std::fill_n(range_min, outputDimension, 0.0); + std::fill_n(range_max, outputDimension, 0.0); + std::fill_n(offset, outputDimension, 0.0); } Normalizer::~Normalizer() { - //dtor + deallocate(); } void Normalizer::allocate(){ range_min = new double[outputDimension]; range_max = new double[outputDimension]; - offset = new double[outputDimension] + offset = new double[outputDimension]; } void Normalizer::deallocate(){ @@ -37,9 +42,9 @@ void Normalizer::deallocate(){ #pragma mark plot void Normalizer::project(const double * point) { - projectedPoint[0] = point[0]*factor + offset[0]; - projectedPoint[1] = point[1]*factor + offset[1]; - projectedPoint[2] = point[2]*factor + offset[2]; + for ( unsigned int i = 0; i < inputDimension; ++i ) { + projectedPoint[0] = point[0]*factor + offset[0]; + } if(!ready){ static unsigned int state = 0; @@ -47,9 +52,8 @@ void Normalizer::project(const double * point) { switch(state) { case 0: init_range(); - state = kUpdate; break; - case 20000: + case 500000: finish_range(); ready = true; break; @@ -57,31 +61,33 @@ void Normalizer::project(const double * point) { update_range(); break; } + + ++state; } } #pragma mark - #pragma mark setting up -void Projector::init_range() { - for ( unsigned int i = 0; i < intern_dim; i++ ) { - range_min[i] = range_max[i] = project_point[i]; +void Normalizer::init_range() { + for ( unsigned int i = 0; i < outputDimension; i++ ) { + range_min[i] = range_max[i] = projectedPoint[i]; } } -void Projector::update_range() { - for ( unsigned int i = 0; i < intern_dim; i++ ) { - if ( project_point[i] < range_min[i] ) { - range_min[i] = project_point[i]; - } else if ( project_point[i] > range_max[i] ) { - range_max[i] = project_point[i]; +void Normalizer::update_range() { + for ( unsigned int i = 0; i < outputDimension; i++ ) { + if ( projectedPoint[i] < range_min[i] ) { + range_min[i] = projectedPoint[i]; + } else if ( projectedPoint[i] > range_max[i] ) { + range_max[i] = projectedPoint[i]; } } } -void Projector::finish_range() { +void Normalizer::finish_range() { factor = 2.0 / (range_max[0] - range_min[0]); - for ( unsigned int i = 1; i < intern_dim; i++ ) { + for ( unsigned int i = 1; i < outputDimension; i++ ) { double dist = range_max[i] - range_min[i]; if ( factor * dist > 2.0 ) { factor = 2.0 / dist; @@ -90,7 +96,7 @@ void Projector::finish_range() { } } - for ( unsigned int i = 0; i < intern_dim; i++ ) { + for ( unsigned int i = 0; i < outputDimension; i++ ) { offset[i] = -0.5*factor*(range_min[i] + range_max[i]); } } diff --git a/projectors/Normalizer.hpp b/projectors/Normalizer.hpp index f56b5cf..b943c91 100644 --- a/projectors/Normalizer.hpp +++ b/projectors/Normalizer.hpp @@ -1,7 +1,7 @@ #ifndef NORMALIZER_HPP #define NORMALIZER_HPP -#include "../Projector.h" +#include "../Projector.hpp" class Normalizer : public Projector { diff --git a/projectors/Projection.cpp b/projectors/Projection.cpp new file mode 100644 index 0000000..959c8dd --- /dev/null +++ b/projectors/Projection.cpp @@ -0,0 +1,10 @@ +#include "Projection.hpp" + +Projection::Projection(unsigned int inputDimension, unsigned int outputDimension) : Projector(inputDimension, outputDimension){ +} + +void Projection::project(const double* point){ + for ( unsigned int i = 0; i < inputDimension; ++i){ + projectedPoint[i] = point[i]; + } +} diff --git a/projectors/Projection.hpp b/projectors/Projection.hpp new file mode 100644 index 0000000..5115238 --- /dev/null +++ b/projectors/Projection.hpp @@ -0,0 +1,16 @@ +#ifndef PROJECTION_HPP +#define PROJECTION_HPP + +#include "../Projector.hpp" + + +class Projection : public Projector { +protected: + virtual void project(const double* point); + +public: + Projection(unsigned int inputDimension, unsigned int outputDimension); + +}; + +#endif // PROJECTION_HPP