58 std::array<double, 3>
steps = { 1.0, 1.0, 1.0 };
59 std::array<int, 3>
sizes = { 1000, 1000, 1000 };
151 it->second( command );
172 const std::optional<double> &xValue,
173 const std::optional<double> &yValue,
174 const std::optional<double> &zValue )
178 if ( xValue.has_value() )
180 if ( yValue.has_value() )
182 if ( zValue.has_value() )
187 if ( xValue.has_value() )
189 if ( yValue.has_value() )
191 if ( zValue.has_value() )
204 std::array<double, 3>
206 const std::array<double, 4> &position_next )
208 std::array<double, 3> director_vector = { position_next[0] - position_prev[0],
209 position_next[1] - position_prev[1],
210 position_next[2] - position_prev[2] };
213 double norm = std::sqrt( director_vector[0] * director_vector[0] + director_vector[1] * director_vector[1] + director_vector[2] * director_vector[2] );
215 if ( std::abs( norm ) > 1e-16 ) {
216 director_vector[0] /= norm;
217 director_vector[1] /= norm;
218 director_vector[2] /= norm;
221 return director_vector;
235 double distance_acc = time_acc * ( v - vs ) / 60 / 2;
238 double distance_decc = time_decc * ( v - ve ) / 60 / 2;
240 return time_acc + time_decc + ( distance - distance_acc - distance_decc ) / v;
243 const Model get_model( std::array<double, 4> start, std::array<double, 4> end,
double h,
double w )
245 std::array<double, 3> dir = { end[0] - start[0], end[1] - start[1], 0 };
246 std::array<double, 3> n = { -dir[1], dir[0], dir[2] };
249 double norm_dir = std::sqrt( dir[0] * dir[0] + dir[1] * dir[1] + dir[2] * dir[2] );
255 double norm = std::sqrt( n[0] * n[0] + n[1] * n[1] + n[2] * n[2] );
256 n[0] *= w / 2 / norm;
257 n[1] *= w / 2 / norm;
258 n[2] *= w / 2 / norm;
260 Vertex v1( { { start[0] + n[0], start[1] + n[1], start[2] + n[2] - h }, { -dir[0] + n[0], -dir[1] + n[1], -1 } } );
261 Vertex v2( { { end[0] + n[0], end[1] + n[1], end[2] + n[2] - h }, { dir[0] + n[0], dir[1] + n[1], -1 } } );
262 Vertex v3( { { end[0] - n[0], end[1] - n[1], end[2] - n[2] - h }, { dir[0] - n[0], dir[1] - n[1], -1 } } );
263 Vertex v4( { { start[0] - n[0], start[1] - n[1], start[2] - n[2] - h }, { -dir[0] - n[0], -dir[1] - n[1], -1 } } );
265 Vertex v5( { { start[0] + n[0], start[1] + n[1], start[2] + n[2] }, { -dir[0] + n[0], -dir[1] + n[1], 1 } } );
266 Vertex v6( { { end[0] + n[0], end[1] + n[1], end[2] + n[2] }, { dir[0] + n[0], dir[1] + n[1], 1 } } );
267 Vertex v7( { { end[0] - n[0], end[1] - n[1], end[2] - n[2] }, { dir[0] - n[0], dir[1] - n[1], 1 } } );
268 Vertex v8( { { start[0] - n[0], start[1] - n[1], start[2] - n[2] }, { -dir[0] - n[0], -dir[1] - n[1], 1 } } );
277 Polygon p1( { v1, v2, v3, v4 } );
278 Polygon p2( { v8, v7, v6, v5 } );
279 Polygon p3( { v3, v7, v8, v4 } );
280 Polygon p4( { v5, v6, v2, v1 } );
281 Polygon p5( { v8, v5, v1, v4 } );
282 Polygon p6( { v6, v7, v3, v2 } );
302 if ( fValue.has_value() ) {
313 double dx =
position[0] - prev_position[0];
314 double dy =
position[1] - prev_position[1];
315 double dz =
position[2] - prev_position[2];
316 double distance = std::sqrt( dx * dx + dy * dy + dz * dz );
317 double dxy = std::sqrt( dx * dx + dy * dy );
320 std::array<double, 4> tmp_position =
position;
321 double lim_feedrate =
feedrate / 60;
329 std::array<double, 3> jerk = { dirVector[0] *
feedrate / 60,
334 lim_feedrate = std::min( lim_feedrate, jerk[0] );
338 lim_feedrate = std::min( lim_feedrate, jerk[1] );
342 lim_feedrate = std::min( lim_feedrate, jerk[2] );
345 tmp_position = newPosition;
362 if ( eValue.has_value() ) {
373 double de =
position[3] - prev_position[3];
377 if ( dxy > 0 && de > 0 && dz == 0 ) {
382 double w =
M_PI * r * r * de / ( dxy * h );
389 auto pt =
voxelGrid.get_indices_from_point( { prev_position[0], prev_position[1], prev_position[2] } );
391 int top = std::get<2>( pt ) + 1;
392 int bot = std::get<2>( pt2 ) - 1;
394 int minx = std::min( std::get<0>( pt ), std::get<0>( pt2 ) ) - 1;
395 int maxx = std::max( std::get<0>( pt ), std::get<0>( pt2 ) ) + 1;
396 int miny = std::min( std::get<1>( pt ), std::get<1>( pt2 ) ) - 1;
397 int maxy = std::max( std::get<1>( pt ), std::get<1>( pt2 ) ) + 1;
402 std::vector<int> indicesToCheck;
404 for (
int z = bot; z <= top; z++ ) {
405 for (
int x = minx; x <= maxx; x++ ) {
406 for (
int y = miny; y <= maxy; y++ ) {
407 indicesToCheck.push_back(
voxelGrid.get_index( x, y, z ) );
413 std::vector<std::tuple<int, double, double> > intersected_indices;
418 std::vector<std::tuple<int, double, double> > intersected_indices_local;
420#pragma omp for nowait
422 for (
size_t ix = 0; ix < indicesToCheck.size(); ix++ ) {
423 int i = indicesToCheck[ix];
427 if ( is.
volume() > 0.0 ) {
428 double vofFrac = is.
volume() / elvol;
429 intersected_indices_local.push_back( std::make_tuple( i,
statistics.time, vofFrac ) );
435 intersected_indices.insert( intersected_indices.end(), intersected_indices_local.begin(), intersected_indices_local.end() );
438 for (
const auto &v : intersected_indices ) {
439 voxelGrid.activate( std::get<0>( v ), std::get<1>( v ), std::get<2>( v ) );
477 std::array<double, 4>
position = { 0.0, 0.0, 0.0, 0.0 };
Model modelfrompolygons(const std::vector< Polygon > &polygons)
Model csgintersection(const Model &a, const Model &b)
LayerHeightModel
The LayerHeight enum class represents the layer height of the printer. The layer height can be consta...
ExtruderPositioning
The ExtruderPositioning enum class represents the positioning mode of the extruder.
VelocityModel
The VelocityModel enum class represents the velocity model of the printer. Acceleration and decelerat...
The GCodeCommand class represents a single G-code command.
std::optional< double > param_double(char paramLetter) const
Get the value of a parameter as a double.
std::string getCode() const
Get the G-code command.
void handleM83Command(const GCodeCommand &command)
Handle the M83 command to set the extruder positioning mode to relative.
void processCommand(const GCodeCommand &command)
Process a G-code command.
Printer()
Constructor to register default callbacks.
PrintStatistics getStatistics() const
Get the printer statistics.
double extrusion_multiplier
double chamberTemperature
VelocityModel velocity_model
double heatBedTemperature
void handleG1Command(const GCodeCommand &command)
Handle the G1 command to manage printer positions.
std::vector< GCodeCommand > commandQueue
PrintStatistics statistics
std::array< double, 3 > calculateDirectorVector(const std::array< double, 4 > &position_prev, const std::array< double, 4 > &position_next)
Calculate the director vector between two positions.
std::array< double, 4 > position
double depositionTemperature
LayerHeightModel layer_height_model
double max_acceleration[4]
double heatTransferFilmCoefficient
const Model get_model(std::array< double, 4 > start, std::array< double, 4 > end, double h, double w)
void addCommandToQueue(const GCodeCommand &command)
Add a G-code command to the command queue.
Printer(PrinterOptions options)
Constructor for Printer using PrinterOptions.
std::array< double, 4 > calculatePosition(std::array< double, 4 > position, const std::optional< double > &xValue, const std::optional< double > &yValue, const std::optional< double > &zValue)
Calculate the new position of the printer based on the given values.
ExtruderPositioning positioning
void registerCallback(const std::string &commandCode, CommandCallback callback)
Register a callback function for a specific G-code command.
ExtruderPositioning extruder_positioning
double depositedMaterialHeatPower
double calculateMoveTime(double distance, double vs, double v, double ve)
Calculate the time taken to move a certain distance with given velocities.
void popCommandFromQueue()
Remove the first G-code command from the command queue.
std::function< void(const GCodeCommand &)> CommandCallback
std::map< std::string, CommandCallback > commandCallbacks
A class to represent a 3D grid of voxels.
Model get_model(int index)
Get the triangulated model of a voxel at a given index.
The PrintStatistics struct is used to track statistics of the printer.
The PrinterOptions struct is used to configure the Printer class.
LayerHeightModel layerHeightModel
double heatBedTemperature
double depositedMaterialHeatPower
double depositionTemperature
VelocityModel velocityModel
std::array< int, 3 > sizes
std::array< double, 3 > steps
double heatTransferFilmCoefficient
double chamberTemperature