Joshua Moerman
14 years ago
5 changed files with 162 additions and 111 deletions
@ -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]); |
|||
} |
|||
} |
@ -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
|
Reference in new issue