OrcaSlicer latest
OrcaSlicer
Loading...
Searching...
No Matches
Slic3r::EdgeGrid Namespace Reference

Classes

class  Contour
class  Grid

Functions

void save_png (const Grid &grid, const BoundingBox &bbox, coord_t resolution, const char *path, size_t scale=1)

Function Documentation

◆ save_png()

void Slic3r::EdgeGrid::save_png ( const Grid & grid,
const BoundingBox & bbox,
coord_t resolution,
const char * path,
size_t scale = 1 )
extern
1493{
1494 coord_t w = (bbox.max(0) - bbox.min(0) + resolution - 1) / resolution;
1495 coord_t h = (bbox.max(1) - bbox.min(1) + resolution - 1) / resolution;
1496
1497 std::vector<uint8_t> pixels(w * h * 3, 0);
1498
1499 const coord_t search_radius = grid.resolution() * 2;
1500 const coord_t display_blend_radius = grid.resolution() * 2;
1501 for (coord_t r = 0; r < h; ++r) {
1502 for (coord_t c = 0; c < w; ++ c) {
1503 unsigned char *pxl = pixels.data() + (((h - r - 1) * w) + c) * 3;
1504 Point pt(c * resolution + bbox.min(0), r * resolution + bbox.min(1));
1505 coordf_t min_dist;
1506 bool on_segment = true;
1507 #if 0
1508 if (grid.signed_distance_edges(pt, search_radius, min_dist, &on_segment)) {
1509 #else
1510 if (grid.signed_distance(pt, search_radius, min_dist)) {
1511 #endif
1512 float s = 255 * std::abs(min_dist) / float(display_blend_radius);
1513 int is = std::max(0, std::min(255, int(floor(s + 0.5f))));
1514 if (min_dist < 0) {
1515 if (on_segment) {
1516 pxl[0] = 255;
1517 pxl[1] = 255 - is;
1518 pxl[2] = 255 - is;
1519 } else {
1520 pxl[0] = 255;
1521 pxl[1] = 0;
1522 pxl[2] = 255 - is;
1523 }
1524 }
1525 else {
1526 if (on_segment) {
1527 pxl[0] = 255 - is;
1528 pxl[1] = 255 - is;
1529 pxl[2] = 255;
1530 } else {
1531 pxl[0] = 255 - is;
1532 pxl[1] = 0;
1533 pxl[2] = 255;
1534 }
1535 }
1536 } else {
1537 pxl[0] = 0;
1538 pxl[1] = 255;
1539 pxl[2] = 0;
1540 }
1541
1542 float gridx = float(pt(0) - grid.bbox().min(0)) / float(grid.resolution());
1543 float gridy = float(pt(1) - grid.bbox().min(1)) / float(grid.resolution());
1544 if (gridx >= -0.4f && gridy >= -0.4f && gridx <= grid.cols() + 0.4f && gridy <= grid.rows() + 0.4f) {
1545 int ix = int(floor(gridx + 0.5f));
1546 int iy = int(floor(gridy + 0.5f));
1547 float dx = gridx - float(ix);
1548 float dy = gridy - float(iy);
1549 float d = sqrt(dx*dx + dy*dy) * float(grid.resolution()) / float(resolution);
1550 if (d < 1.f) {
1551 // Less than 1 pixel from the grid point.
1552 float t = 0.5f + 0.5f * d;
1553 pxl[0] = (unsigned char)(t * pxl[0]);
1554 pxl[1] = (unsigned char)(t * pxl[1]);
1555 pxl[2] = (unsigned char)(t * pxl[2]);
1556 }
1557 }
1558
1559 float dgrid = fabs(min_dist) / float(grid.resolution());
1560 float igrid = floor(dgrid + 0.5f);
1561 dgrid = std::abs(dgrid - igrid) * float(grid.resolution()) / float(resolution);
1562 if (dgrid < 1.f) {
1563 // Less than 1 pixel from the grid point.
1564 float t = 0.5f + 0.5f * dgrid;
1565 pxl[0] = (unsigned char)(t * pxl[0]);
1566 pxl[1] = (unsigned char)(t * pxl[1]);
1567 pxl[2] = (unsigned char)(t * pxl[2]);
1568 if (igrid > 0.f) {
1569 // Other than zero iso contour.
1570 int g = pxl[1] + 255.f * (1.f - t);
1571 pxl[1] = std::min(g, 255);
1572 }
1573 }
1574 }
1575 }
1576
1577 png::write_rgb_to_file_scaled(path, w, h, pixels, scale);
1578}
int scale(const int val)
Definition WipeTowerDialog.cpp:58
PointType max
Definition BoundingBox.hpp:21
PointType min
Definition BoundingBox.hpp:20
Definition Point.hpp:199
int64_t coord_t
Definition libslic3r.h:48
bool write_rgb_to_file_scaled(const char *file_name_utf8, size_t width, size_t height, const uint8_t *data_rgb, size_t scale)
Definition PNGReadWrite.cpp:384
double coordf_t
Definition GUI_ObjectList.hpp:46
zaa_minimize_perimeter_height resolution((ConfigOptionFloats, retraction_minimum_travel))((ConfigOptionBools
std::vector< ArithmeticOnly< T > > grid(const T &start, const T &stop, const T &stride)
A set of equidistant values starting from 'start' (inclusive), ending in the closest multiple of 'str...
Definition MTUtils.hpp:127

References Slic3r::grid(), Slic3r::BoundingBoxBase< PointType, APointsType >::max, Slic3r::BoundingBoxBase< PointType, APointsType >::min, Slic3r::resolution(), scale(), and Slic3r::png::write_rgb_to_file_scaled().

Referenced by Slic3r::calculate_layer_edge_grid().

Here is the call graph for this function:
Here is the caller graph for this function: