|
|
57bda0 |
|
|
|
57bda0 |
#include <iostream></iostream>
|
|
|
57bda0 |
|
|
|
57bda0 |
#include "simulator.h"
|
|
|
57bda0 |
|
|
|
57bda0 |
|
|
|
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;
|
|
|
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 |
|