Browse Source

alomst done with the big thing

master
Joshua Moerman 14 years ago
parent
commit
c469d61717
  1. 1
      AttractorKernel.cpp
  2. 110
      Projector.cpp
  3. 37
      Projector.hpp
  4. 96
      projectors/Normalizer.cpp
  5. 29
      projectors/Normalizer.hpp

1
AttractorKernel.cpp

@ -84,7 +84,6 @@ unsigned int AttractorKernel::getDimension() const{
#pragma mark - #pragma mark -
#pragma mark factory function #pragma mark factory function
#include "AttractorKernel.hpp"
#include "kernels/Logistic.hpp" #include "kernels/Logistic.hpp"
#include "kernels/Lorenz3D.hpp" #include "kernels/Lorenz3D.hpp"
#include "kernels/Polynomial.hpp" #include "kernels/Polynomial.hpp"

110
Projector.cpp

@ -4,113 +4,55 @@
#include "Projector.hpp" #include "Projector.hpp"
#include "Canvas.hpp" #include "Canvas.hpp"
#include "myMath.hpp"
Projector* Projector::createProjector(stfu::node const& projector, stfu::node const& system){ #pragma mark -
#pragma mark memory
} Projector::Projector(unsigned int inputDimension, unsigned int outputDimension) : canvas(0), projector(0), projectedPoint(0), inputDimension(inputDimension), outputDimension(outputDimension), ready(true) {
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 { try {
allocate(); allocate();
} catch (std::exception& e) { } catch(std::exception& e) {
LogError("Couldn't construct Projector: %s\n", e.what()); LogError("Couldn't construct Projector: %s\n", e.what());
deallocate(); deallocate();
} }
} }
void Projector::init(const double * point) { Projector::~Projector(){
init_vector(); deallocate()();
project(point);
init_range();
} }
void Projector::init_vector() { void Projector::allocate() {
project_point = new double[intern_dim]; projectedPoint = new double[outputDimension];
offset = new double[intern_dim];
assert(project_point != NULL);
assert(offset != NULL);
} }
void Projector::init_range() { void Projector::deallocate() {
range_min = new double[intern_dim]; delete[] projectedPoint;
range_max = new double[intern_dim]; projectedPoint = NULL;
assert(range_min != NULL);
assert(range_max != NULL);
for ( unsigned int i = 0; i < intern_dim; i++ ) {
range_min[i] = range_max[i] = project_point[i];
}
} }
void Projector::update_range(const double * point) { #pragma mark -
#pragma mark plot
void Projector::plot(const double* point) {
project(point); project(point);
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 Projector::finish_range() { if(ready) {
factor = 2.0 / (range_max[0] - range_min[0]); if(canvas != NULL) {
for ( unsigned int i = 1; i < intern_dim; i++ ) { canvas->plot(projectedPoint);
double dist = range_max[i] - range_min[i];
if ( factor * dist > 2.0 ) {
factor = 2.0 / dist;
//teh_size = canvas->size[i];
LogDebug("Crap for dimension %d\n", i);
} }
}
for ( unsigned int i = 0; i < intern_dim; i++ ) { if(projector != NULL) {
offset[i] = -0.5*factor*(range_min[i] + range_max[i]); projector->plot(projectedPoint);
}
} }
} }
#pragma mark -
#pragma mark factory function
void Projector::project(const double * point) { #include "projectors/Normalizer.hpp"
//assert(extern_dim >= 2);
project_point[0] = point[0];
project_point[1] = point[1];
project_point[2] = point[2];
}
void Projector::plot(const double * point) { Projector* Projector::createProjector(stfu::node const& projector, stfu::node const& system) {
project(point); return new Normalizer(3);
const double x = project_point[0]*factor + offset[0];
const double y = project_point[1]*factor + offset[1];
const double z = project_point[2]*factor + offset[2];
double position[] = {x,y,z};
if (-1.0 < x && x < 1.0 && -1.0 < y && y < 1.0 && -1.0 < z && z < 1.0){
canvas->plot(position);
}
}
void Projector::output(){
LogMoreInfo("Projector properties: \n");
LogMoreInfo(" factor: %f\n", factor);
for ( unsigned int i = 0; i < intern_dim; i++ ) {
LogMoreInfo(" dimension %d: offset: %f, range: [%f, %f]\n", i, offset[i], range_min[i], range_max[i]);
}
} }

37
Projector.hpp

@ -7,46 +7,31 @@ class Canvas;
class Projector { class Projector {
private: private:
void allocate();
void deallocate();
protected:
Canvas* canvas; Canvas* canvas;
Projector* projector; Projector* projector;
allocate(); double* projectedPoint;
deallocate();
protected:
unsigned int inputDimension; unsigned int inputDimension;
unsigned int outputDimension; unsigned int outputDimension;
double* projectedPoint; bool ready;
double* range_min;
double* range_max;
double factor;
double* offset;
void project(const double* point); virtual void project(const double* point) = 0;
public: public:
Projector(unsigned int inputDimension, unsigned int outputDimension, unsigned int state);
Projector(unsigned int inputDimension, unsigned int outputDimension);
virtual ~Projector(); virtual ~Projector();
static Projector* createProjector(stfu::node const& projector, stfu::node const& system); // delegates forward trough the chain, know wha i'm sayin'?
void init(const double* point);
void init_vector();
void init_range();
void update_range(const double* point);
void finish_range();
void plot(const double* point); void plot(const double* point);
// factory function
static Projector* createProjector(stfu::node const& projector, stfu::node const& system);
void output();
}; };
#endif // PROJECTOR_HPP #endif // PROJECTOR_HPP

96
projectors/Normalizer.cpp

@ -0,0 +1,96 @@
#include "Normalizer.hpp"
#pragma mark -
#pragma mark memory
Normalizer::Normalizer(unsigned int dimension) : Projector(dimension, dimension) {
ready = false;
try {
allocate();
} catch (std::exception& e) {
LogError("Couldn't construct Normalizer (Projector): %s\n", e.what());
deallocate();
}
}
Normalizer::~Normalizer() {
//dtor
}
void Normalizer::allocate(){
range_min = new double[outputDimension];
range_max = new double[outputDimension];
offset = new double[outputDimension]
}
void Normalizer::deallocate(){
delete[] range_min;
range_min = 0;
delete[] range_max;
range_max = 0;
delete[] offset;
offset = 0;
}
#pragma mark -
#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];
if(!ready){
static unsigned int state = 0;
switch(state) {
case 0:
init_range();
state = kUpdate;
break;
case 20000:
finish_range();
ready = true;
break;
default:
update_range();
break;
}
}
}
#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 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 Projector::finish_range() {
factor = 2.0 / (range_max[0] - range_min[0]);
for ( unsigned int i = 1; i < intern_dim; i++ ) {
double dist = range_max[i] - range_min[i];
if ( factor * dist > 2.0 ) {
factor = 2.0 / dist;
//teh_size = canvas->size[i];
LogDebug("Crap for dimension %d\n", i);
}
}
for ( unsigned int i = 0; i < intern_dim; i++ ) {
offset[i] = -0.5*factor*(range_min[i] + range_max[i]);
}
}

29
projectors/Normalizer.hpp

@ -0,0 +1,29 @@
#ifndef NORMALIZER_HPP
#define NORMALIZER_HPP
#include "../Projector.h"
class Normalizer : public Projector {
private:
double* range_min;
double* range_max;
double* offset;
double factor;
void allocate();
void deallocate();
void init_range();
void update_range();
void finish_range();
protected:
virtual void project(const double* point);
public:
Normalizer(unsigned int dimension);
virtual ~Normalizer();
};
#endif // NORMALIZER_HPP