|
|
57bda0 |
|
|
|
57bda0 |
#include <iostream></iostream>
|
|
|
57bda0 |
|
|
|
57bda0 |
#include "simulator.h"
|
|
|
57bda0 |
|
|
|
57bda0 |
|
|
|
0a0ecd |
void SimulatorXYZ::simulate(const Track &track, const Tool &tool) {
|
|
|
0a0ecd |
points.clear();
|
|
|
0a0ecd |
simu_index = 0;
|
|
|
0a0ecd |
raster.x0 = raster.x1 = raster.y0 = raster.y1 = raster.min_value = raster.max_value = 0;
|
|
|
0a0ecd |
|
|
|
0a0ecd |
if (!raster.raster.get_data() || track.points.empty()) return;
|
|
|
0a0ecd |
|
|
|
0a0ecd |
std::cout << "SimulatorXYZ::simulate" << std::endl;
|
|
|
0a0ecd |
std::cout << "SimulatorXYZ::simulate: track points: " << track.points.size() << std::endl;
|
|
|
0a0ecd |
|
|
|
0a0ecd |
const TrackPoint &first = track.points.front();
|
|
|
0a0ecd |
raster.x0 = raster.x1 = first.position.x;
|
|
|
0a0ecd |
raster.y0 = raster.y1 = first.position.y;
|
|
|
0a0ecd |
raster.min_value = raster.max_value = first.position.z;
|
|
|
0a0ecd |
for(TrackPointList::const_iterator i = track.points.begin(); i != track.points.end(); ++i) {
|
|
|
0a0ecd |
if (raster.x0 > i->position.x) raster.x0 = i->position.x;
|
|
|
0a0ecd |
if (raster.x1 < i->position.x) raster.x1 = i->position.x;
|
|
|
0a0ecd |
if (raster.y0 > i->position.y) raster.y0 = i->position.y;
|
|
|
0a0ecd |
if (raster.y1 < i->position.y) raster.y1 = i->position.y;
|
|
|
0a0ecd |
if (raster.min_value > i->position.z) raster.min_value = i->position.z;
|
|
|
0a0ecd |
if (raster.max_value < i->position.z) raster.max_value = i->position.z;
|
|
|
0a0ecd |
}
|
|
|
0a0ecd |
|
|
|
0a0ecd |
const Real precision = 1e-5;
|
|
|
0a0ecd |
if ( raster.x1 + precision < raster.x0
|
|
|
0a0ecd |
|| raster.y1 + precision < raster.y0
|
|
|
0a0ecd |
|| raster.max_value + precision < raster.min_value )
|
|
|
0a0ecd |
{
|
|
|
0a0ecd |
std::cout << "SimulatorXYZ::simulate: zero bounds" << std::endl;
|
|
|
0a0ecd |
return;
|
|
|
0a0ecd |
}
|
|
|
0a0ecd |
|
|
|
0a0ecd |
raster.raster.fill(raster.max_value);
|
|
|
0a0ecd |
|
|
|
0a0ecd |
Real x0 = raster.x0;
|
|
|
0a0ecd |
Real y0 = raster.y0;
|
|
|
0a0ecd |
Real dx = raster.x1 - x0;
|
|
|
0a0ecd |
Real dy = raster.y1 - y0;
|
|
|
0a0ecd |
Real w = raster.raster.get_width();
|
|
|
0a0ecd |
Real h = raster.raster.get_height();
|
|
|
0a0ecd |
|
|
|
0a0ecd |
Vector2 scale_to_raster(w/dx , h/dy);
|
|
|
0a0ecd |
Vector2 scale_to_tool (dx/w , dy/h);
|
|
|
0a0ecd |
FlatToolPainter painter(&tool, scale_to_tool);
|
|
|
0a0ecd |
|
|
|
0a0ecd |
unsigned long long max_count = 2ull*1024*1024*1024/sizeof(points.front());
|
|
|
0a0ecd |
|
|
|
0a0ecd |
int index = 0;
|
|
|
0a0ecd |
for(TrackPointList::const_iterator i = track.points.begin(); i != track.points.end(); ++i, ++index) {
|
|
|
0a0ecd |
painter.distance = i->position.z;
|
|
|
0a0ecd |
|
|
|
0a0ecd |
Vector2 position(
|
|
|
0a0ecd |
scale_to_raster.x * (i->position.x - x0),
|
|
|
0a0ecd |
scale_to_raster.y * (i->position.y - y0) );
|
|
|
0a0ecd |
|
|
|
0a0ecd |
raster.raster.touch(painter, position, index, points);
|
|
|
0a0ecd |
if (points.size() >= max_count) {
|
|
|
0a0ecd |
std::cerr << "SimulatorXYZ::simulate: reached memory limit at time " << i->time << std::endl;
|
|
|
0a0ecd |
break;
|
|
|
0a0ecd |
}
|
|
|
0a0ecd |
|
|
|
0a0ecd |
if (index % 1000 == 0)
|
|
|
0a0ecd |
std::cout << "." << std::flush;
|
|
|
0a0ecd |
if (index % 100000 == 0)
|
|
|
0a0ecd |
std::cout << std::endl << std::flush;
|
|
|
0a0ecd |
}
|
|
|
0a0ecd |
simu_index = (int)points.size();
|
|
|
0a0ecd |
|
|
|
0a0ecd |
std::cout << std::endl;
|
|
|
0a0ecd |
std::cout << "SimulatorXYZ::simulate: done" << std::endl;
|
|
|
0a0ecd |
}
|
|
|
0a0ecd |
|
|
|
0a0ecd |
void SimulatorXYZ::scroll_to(int index) {
|
|
|
0a0ecd |
while(simu_index < (int)points.size() && points[simu_index].index <= index)
|
|
|
0a0ecd |
points[simu_index++].apply_next(raster.raster);
|
|
|
0a0ecd |
while(simu_index > 0 && points[simu_index-1].index > index)
|
|
|
0a0ecd |
points[--simu_index].apply_prev(raster.raster);
|
|
|
0a0ecd |
}
|
|
|
0a0ecd |
|
|
|
0a0ecd |
|
|
|
d2b2b5 |
void SimulatorXYZA::simulate(const Track &track, const Tool &tool) {
|
|
|
57bda0 |
points.clear();
|
|
|
57bda0 |
simu_index = 0;
|
|
|
d2b2b5 |
raster.x0 = raster.x1 = raster.min_value = raster.max_value = 0;
|
|
|
57bda0 |
|
|
|
d2b2b5 |
if (!raster.raster.get_data() || track.points.empty()) return;
|
|
|
57bda0 |
|
|
|
57bda0 |
std::cout << "SimulatorXYZA::simulate" << std::endl;
|
|
|
1bcd85 |
std::cout << "SimulatorXYZA::simulate: track points: " << track.points.size() << std::endl;
|
|
|
57bda0 |
|
|
|
d2b2b5 |
raster.x0 = raster.x1 = track.points.front().position.x;
|
|
|
d2b2b5 |
for(TrackPointList::const_iterator i = track.points.begin(); i != track.points.end(); ++i) {
|
|
|
d2b2b5 |
Real distance = sqrt(i->position.y*i->position.y + i->position.z*i->position.z);
|
|
|
d2b2b5 |
if (raster.max_value < distance) raster.max_value = distance;
|
|
|
d2b2b5 |
if (raster.x0 > i->position.x) raster.x0 = i->position.x;
|
|
|
d2b2b5 |
if (raster.x1 < i->position.x) raster.x1 = i->position.x;
|
|
|
57bda0 |
}
|
|
|
d2b2b5 |
raster.raster.fill(raster.max_value);
|
|
|
57bda0 |
|
|
|
d2b2b5 |
if (raster.x1 + 1e-5 < raster.x0) {
|
|
|
57bda0 |
std::cout << "SimulatorXYZA::simulate: zero bound" << std::endl;
|
|
|
57bda0 |
return;
|
|
|
57bda0 |
}
|
|
|
57bda0 |
|
|
|
d2b2b5 |
Real x0 = raster.x0;
|
|
|
d2b2b5 |
Real dx = raster.x1 - x0;
|
|
|
d2b2b5 |
Real h = raster.raster.get_height();
|
|
|
d2b2b5 |
Real w = raster.raster.get_width();
|
|
|
d2b2b5 |
|
|
|
d2b2b5 |
Vector2 scale_to_raster( w/dx , 1.0/360.0 );
|
|
|
d2b2b5 |
Vector2 scale_to_tool ( dx/w , 2*M_PI/h );
|
|
|
d2b2b5 |
PolarToolPainter painter(&tool, scale_to_tool, 1);
|
|
|
57bda0 |
|
|
|
d2b2b5 |
unsigned long long max_count = 2ull*1024*1024*1024/sizeof(points.front());
|
|
|
d2b2b5 |
|
|
|
57bda0 |
int index = 0;
|
|
|
d2b2b5 |
for(TrackPointList::const_iterator i = track.points.begin(); i != track.points.end(); ++i, ++index) {
|
|
|
d2b2b5 |
painter.distance = sqrt(i->position.y*i->position.y + i->position.z*i->position.z);
|
|
|
d2b2b5 |
if (painter.distance < 1e-5) painter.distance = 1e-5;
|
|
|
57bda0 |
|
|
|
d2b2b5 |
Vector2 position(
|
|
|
d2b2b5 |
scale_to_raster.x * (i->position.x - x0),
|
|
|
d2b2b5 |
scale_to_raster.y * i->angle );
|
|
|
d2b2b5 |
position.y = (position.y - floor(position.y))*h;
|
|
|
d2b2b5 |
Vector2 rxy = painter.get_radius_xy();
|
|
|
57bda0 |
|
|
|
d2b2b5 |
raster.raster.touch(painter, position, index, points);
|
|
|
d2b2b5 |
if (position.y - rxy.y < 0)
|
|
|
d2b2b5 |
raster.raster.touch(painter, Vector2(position.x, position.y + h), index, points);
|
|
|
d2b2b5 |
if (position.y + rxy.y > h)
|
|
|
d2b2b5 |
raster.raster.touch(painter, Vector2(position.x, position.y - h), index, points);
|
|
|
d2b2b5 |
if (points.size() >= max_count) {
|
|
|
d2b2b5 |
std::cerr << "SimulatorXYZA::simulate: reached memory limit at time " << i->time << std::endl;
|
|
|
d2b2b5 |
break;
|
|
|
d2b2b5 |
}
|
|
|
57bda0 |
|
|
|
57bda0 |
if (index % 1000 == 0)
|
|
|
57bda0 |
std::cout << "." << std::flush;
|
|
|
57bda0 |
if (index % 100000 == 0)
|
|
|
57bda0 |
std::cout << std::endl << std::flush;
|
|
|
57bda0 |
}
|
|
|
57bda0 |
simu_index = (int)points.size();
|
|
|
57bda0 |
|
|
|
d2b2b5 |
std::cout << std::endl;
|
|
|
57bda0 |
std::cout << "SimulatorXYZA::simulate: done" << std::endl;
|
|
|
57bda0 |
}
|
|
|
57bda0 |
|
|
|
57bda0 |
void SimulatorXYZA::scroll_to(int index) {
|
|
|
57bda0 |
while(simu_index < (int)points.size() && points[simu_index].index <= index)
|
|
|
d2b2b5 |
points[simu_index++].apply_next(raster.raster);
|
|
|
57bda0 |
while(simu_index > 0 && points[simu_index-1].index > index)
|
|
|
d2b2b5 |
points[--simu_index].apply_prev(raster.raster);
|
|
|
57bda0 |
}
|
|
|
57bda0 |
|