|
|
|
#include "Logger.hpp"
|
|
|
|
#include <cmath>
|
|
|
|
#include <cassert>
|
|
|
|
|
|
|
|
#include "Projector.hpp"
|
|
|
|
#include "Canvas.hpp"
|
|
|
|
#include "myMath.hpp"
|
|
|
|
|
|
|
|
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() {
|
|
|
|
// double max_dist = 0.0;
|
|
|
|
// for ( unsigned int i = 0; i < intern_dim; i++ ) {
|
|
|
|
// const double dist = range_max[i] - range_min[i];
|
|
|
|
// if ( dist > max_dist )
|
|
|
|
// max_dist = dist;
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// factor = 0.9/max_dist;
|
|
|
|
// for ( unsigned int i = 0; i < intern_dim; i++ ) {
|
|
|
|
// offset[i] = -0.5*factor*(range_min[i] + range_max[i]);
|
|
|
|
// }
|
|
|
|
|
|
|
|
factor = canvas->size[0] / (range_max[0] - range_min[0]);
|
|
|
|
unsigned int teh_size = canvas->size[0];
|
|
|
|
for ( unsigned int i = 1; i < intern_dim; i++ ) {
|
|
|
|
double dist = range_max[i] - range_min[i];
|
|
|
|
if ( factor * dist > (double)canvas->size[i] ) {
|
|
|
|
factor = (double)canvas->size[i] / dist;
|
|
|
|
//teh_size = canvas->size[i];
|
|
|
|
LogDebug("Crap for dimension %d\n", i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
factor /= (double)teh_size;
|
|
|
|
|
|
|
|
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];
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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];
|
|
|
|
|
|
|
|
canvas->plot(x, y);
|
|
|
|
if ( even(point[2]*17) )
|
|
|
|
canvas->plot(x, y, 1);
|
|
|
|
if ( even(point[2]*17+0.6) )
|
|
|
|
canvas->plot(x, y, 2);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|