Browse Source

alomst done with the big thing

master
Joshua Moerman 14 years ago
parent
commit
c469d61717
  1. 1
      AttractorKernel.cpp
  2. 106
      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 factory function
#include "AttractorKernel.hpp"
#include "kernels/Logistic.hpp"
#include "kernels/Lorenz3D.hpp"
#include "kernels/Polynomial.hpp"

106
Projector.cpp

@ -4,22 +4,11 @@
#include "Projector.hpp"
#include "Canvas.hpp"
#include "myMath.hpp"
Projector* Projector::createProjector(stfu::node const& projector, stfu::node const& system){
}
#pragma mark -
#pragma mark memory
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) {
Projector::Projector(unsigned int inputDimension, unsigned int outputDimension) : canvas(0), projector(0), projectedPoint(0), inputDimension(inputDimension), outputDimension(outputDimension), ready(true) {
try {
allocate();
} catch(std::exception& e) {
@ -28,89 +17,42 @@ Projector::Projector(unsigned int inputDimension, unsigned int outputDimension)
}
}
void Projector::init(const double * point) {
init_vector();
project(point);
init_range();
Projector::~Projector(){
deallocate()();
}
void Projector::init_vector() {
project_point = new double[intern_dim];
offset = new double[intern_dim];
assert(project_point != NULL);
assert(offset != NULL);
void Projector::allocate() {
projectedPoint = new double[outputDimension];
}
void Projector::init_range() {
range_min = new double[intern_dim];
range_max = new double[intern_dim];
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::deallocate() {
delete[] projectedPoint;
projectedPoint = NULL;
}
void Projector::update_range(const double * point) {
#pragma mark -
#pragma mark plot
void Projector::plot(const double* 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() {
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);
}
if(ready) {
if(canvas != NULL) {
canvas->plot(projectedPoint);
}
for ( unsigned int i = 0; i < intern_dim; i++ ) {
offset[i] = -0.5*factor*(range_min[i] + range_max[i]);
if(projector != NULL) {
projector->plot(projectedPoint);
}
}
void Projector::project(const double * point) {
//assert(extern_dim >= 2);
project_point[0] = point[0];
project_point[1] = point[1];
project_point[2] = point[2];
}
#pragma mark -
#pragma mark factory function
void Projector::plot(const double * point) {
project(point);
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);
}
}
#include "projectors/Normalizer.hpp"
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]);
}
Projector* Projector::createProjector(stfu::node const& projector, stfu::node const& system) {
return new Normalizer(3);
}

37
Projector.hpp

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