|
|
|
#include "Logger.hpp"
|
|
|
|
#include <cmath>
|
|
|
|
#include <cassert>
|
|
|
|
|
|
|
|
#include "Projector.hpp"
|
|
|
|
#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();
|
|
|
|
|
|
|
|
project(point);
|
|
|
|
init_range();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Projector::init_vector() {
|
|
|
|
project_point = new double[intern_dim];
|
|
|
|
offset = new double[intern_dim];
|
|
|
|
|
|
|
|
assert(project_point != NULL);
|
|
|
|
assert(offset != NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
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::update_range(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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for ( unsigned int i = 0; i < intern_dim; i++ ) {
|
|
|
|
offset[i] = -0.5*factor*(range_min[i] + range_max[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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];
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|