![]() |
Prusa Slicer 2.6.0
|
Sparse grid which can locate spatially nearby elements efficiently. More...
#include <src/libslic3r/Arachne/utils/SparseGrid.hpp>
Inheritance diagram for Slic3r::Arachne::SparseGrid< ElemT >:
Collaboration diagram for Slic3r::Arachne::SparseGrid< ElemT >:Public Types | |
| using | Elem = ElemT |
| using | GridPoint = SquareGrid::GridPoint |
| using | grid_coord_t = SquareGrid::grid_coord_t |
| using | GridMap = std::unordered_multimap< GridPoint, Elem, PointHash > |
| using | iterator = typename GridMap::iterator |
| using | const_iterator = typename GridMap::const_iterator |
Public Member Functions | |
| SparseGrid (coord_t cell_size, size_t elem_reserve=0U, float max_load_factor=1.0f) | |
| Constructs a sparse grid with the specified cell size. | |
| iterator | begin () |
| iterator | end () |
| const_iterator | begin () const |
| const_iterator | end () const |
| std::vector< Elem > | getNearby (const Point &query_pt, coord_t radius) const |
| Returns all data within radius of query_pt. | |
| bool | processNearby (const Point &query_pt, coord_t radius, const std::function< bool(const ElemT &)> &process_func) const |
| Process elements from cells that might contain sought after points. | |
| coord_t | getCellSize () const |
| bool | processLineCells (const std::pair< Point, Point > line, const std::function< bool(GridPoint)> &process_cell_func) |
Process cells along a line indicated by line. | |
| bool | processLineCells (const std::pair< Point, Point > line, const std::function< bool(GridPoint)> &process_cell_func) const |
Process cells along a line indicated by line. | |
| bool | processNearby (const Point &query_pt, coord_t radius, const std::function< bool(const GridPoint &)> &process_func) const |
| Process cells that might contain sought after points. | |
| GridPoint | toGridPoint (const Vec2i64 &point) const |
| Compute the grid coordinates of a point. | |
| grid_coord_t | toGridCoord (const int64_t &coord) const |
| Compute the grid coordinate of a real space coordinate. | |
| coord_t | toLowerCoord (const grid_coord_t &grid_coord) const |
| Compute the lowest coord in a grid cell. The lowest point is the point in the grid cell closest to the origin. | |
Protected Member Functions | |
| bool | processFromCell (const GridPoint &grid_pt, const std::function< bool(const Elem &)> &process_func) const |
Process elements from the cell indicated by grid_pt. | |
| grid_coord_t | nonzeroSign (grid_coord_t z) const |
Protected Attributes | |
| GridMap | m_grid |
| Map from grid locations (GridPoint) to elements (Elem). | |
| coord_t | cell_size |
| The cell (square) size. | |
Sparse grid which can locate spatially nearby elements efficiently.
| ElemT | The element type to store. |
| using Slic3r::Arachne::SparseGrid< ElemT >::const_iterator = typename GridMap::const_iterator |
| using Slic3r::Arachne::SparseGrid< ElemT >::Elem = ElemT |
| using Slic3r::Arachne::SparseGrid< ElemT >::grid_coord_t = SquareGrid::grid_coord_t |
| using Slic3r::Arachne::SparseGrid< ElemT >::GridMap = std::unordered_multimap<GridPoint, Elem, PointHash> |
| using Slic3r::Arachne::SparseGrid< ElemT >::GridPoint = SquareGrid::GridPoint |
| using Slic3r::Arachne::SparseGrid< ElemT >::iterator = typename GridMap::iterator |
| Slic3r::Arachne::SparseGrid< ElemT >::SparseGrid | ( | coord_t | cell_size, |
| size_t | elem_reserve = 0U, |
||
| float | max_load_factor = 1.0f |
||
| ) |
Constructs a sparse grid with the specified cell size.
| [in] | cell_size | The size to use for a cell (square) in the grid. Typical values would be around 0.5-2x of expected query radius. |
| [in] | elem_reserve | Number of elements to research space for. |
| [in] | max_load_factor | Maximum average load factor before rehashing. |
References Slic3r::Arachne::SparseGrid< ElemT >::m_grid.
|
inline |
References Slic3r::Arachne::SparseGrid< ElemT >::m_grid.
|
inline |
References Slic3r::Arachne::SparseGrid< ElemT >::m_grid.
|
inline |
References Slic3r::Arachne::SparseGrid< ElemT >::m_grid.
|
inline |
References Slic3r::Arachne::SparseGrid< ElemT >::m_grid.
|
inherited |
Get the cell size this grid was created for.
References Slic3r::Arachne::SquareGrid::cell_size.
| std::vector< typename SparseGrid< ElemT >::Elem > Slic3r::Arachne::SparseGrid< ElemT >::getNearby | ( | const Point & | query_pt, |
| coord_t | radius | ||
| ) | const |
Returns all data within radius of query_pt.
Finds all elements with location within radius of query_pt. May return additional elements that are beyond radius.
Average running time is a*(1 + 2 * radius / cell_size)**2 + b*cnt where a and b are proportionality constance and cnt is the number of returned items. The search will return items in an area of (2*radius + cell_size)**2 on average. The max range of an item from the query_point is radius + cell_size.
| [in] | query_pt | The point to search around. |
| [in] | radius | The search radius. |
|
protectedinherited |
Compute the sign of a number.
The number 0 will result in a positive sign (1).
| z | The number to find the sign of. |
Referenced by Slic3r::Arachne::SquareGrid::processLineCells().
Here is the caller graph for this function:
|
protected |
Process elements from the cell indicated by grid_pt.
| [in] | grid_pt | The grid coordinates of the cell. |
| [in] | process_func | Processes each element. process_func(elem) is called for each element in the cell. Processing stops if function returns false. |
|
inherited |
Process cells along a line indicated by line.
| line | The line along which to process cells. |
| process_func | Processes each cell. process_func(elem) is called for each cell. Processing stops if function returns false. |
References Slic3r::Arachne::SquareGrid::processLineCells().
Referenced by Slic3r::Arachne::SparseLineGrid< ElemT, Locator >::insert(), and Slic3r::Arachne::SquareGrid::processLineCells().
Here is the call graph for this function:
Here is the caller graph for this function:
|
inherited |
Process cells along a line indicated by line.
| line | The line along which to process cells |
| process_func | Processes each cell. process_func(elem) is called for each cell. Processing stops if function returns false. |
References Slic3r::area(), Slic3r::Arachne::SquareGrid::nonzeroSign(), Slic3r::Arachne::SquareGrid::toGridCoord(), Slic3r::Arachne::SquareGrid::toGridPoint(), and Slic3r::Arachne::SquareGrid::toLowerCoord().
Here is the call graph for this function:| bool Slic3r::Arachne::SparseGrid< ElemT >::processNearby | ( | const Point & | query_pt, |
| coord_t | radius, | ||
| const std::function< bool(const ElemT &)> & | process_func | ||
| ) | const |
Process elements from cells that might contain sought after points.
Processes elements from cell that might have elements within radius of query_pt. Processes all elements that are within radius of query_pt. May process elements that are up to radius + cell_size from query_pt.
| [in] | query_pt | The point to search around. |
| [in] | radius | The search radius. |
| [in] | process_func | Processes each element. process_func(elem) is called for each element in the cell. Processing stops if function returns false. |
References Slic3r::Arachne::SquareGrid::processNearby().
Referenced by Slic3r::Arachne::SparsePointGrid< ElemT, Locator >::getAnyNearby().
Here is the call graph for this function:
Here is the caller graph for this function:
|
inherited |
Process cells that might contain sought after points.
Processes cells that might be within a square with twice radius as width, centered around query_pt. May process elements that are up to radius + cell_size from query_pt.
| query_pt | The point to search around. |
| radius | The search radius. |
| process_func | Processes each cell. process_func(loc) is called for each cell coord within range. Processing stops if function returns false. |
References Slic3r::Arachne::SquareGrid::toGridPoint().
Referenced by Slic3r::Arachne::SparseGrid< ElemT >::processNearby().
Here is the call graph for this function:
Here is the caller graph for this function:
|
inherited |
Compute the grid coordinate of a real space coordinate.
| coord | The actual location. |
coord. References Slic3r::Arachne::SquareGrid::cell_size.
Referenced by Slic3r::Arachne::SquareGrid::processLineCells(), and Slic3r::Arachne::SquareGrid::toGridPoint().
Here is the caller graph for this function:
|
inherited |
Compute the grid coordinates of a point.
| point | The actual location. |
point. References Slic3r::Arachne::SquareGrid::toGridCoord().
Referenced by Slic3r::Arachne::SparsePointGrid< ElemT, Locator >::insert(), Slic3r::Arachne::SquareGrid::processLineCells(), and Slic3r::Arachne::SquareGrid::processNearby().
Here is the call graph for this function:
Here is the caller graph for this function:
|
inherited |
Compute the lowest coord in a grid cell. The lowest point is the point in the grid cell closest to the origin.
| grid_coord | The grid coordinate. |
grid_coord. References Slic3r::Arachne::SquareGrid::cell_size.
Referenced by Slic3r::Arachne::SquareGrid::processLineCells().
Here is the caller graph for this function:
|
protectedinherited |
The cell (square) size.
Referenced by Slic3r::Arachne::SquareGrid::SquareGrid(), Slic3r::Arachne::SquareGrid::getCellSize(), Slic3r::Arachne::SquareGrid::toGridCoord(), and Slic3r::Arachne::SquareGrid::toLowerCoord().
|
protected |
Map from grid locations (GridPoint) to elements (Elem).
Referenced by Slic3r::Arachne::SparseGrid< ElemT >::SparseGrid(), Slic3r::Arachne::SparseGrid< ElemT >::begin(), Slic3r::Arachne::SparseGrid< ElemT >::begin(), Slic3r::Arachne::SparseGrid< ElemT >::end(), and Slic3r::Arachne::SparseGrid< ElemT >::end().