|
Krita Source Code Documentation
|
A utility class to maintain a sparse grid of loaded/unloaded rects. More...
#include <KisRectsGrid.h>
Public Member Functions | |
| QVector< QRect > | addAlignedRect (const QRect &rc) |
| QVector< QRect > | addRect (const QRect &rc) |
| QRect | alignRect (const QRect &rc) const |
| QRect | boundingRect () const |
| bool | contains (const QRect &rc) const |
| KisRectsGrid (int gridSize=64) | |
| QVector< QRect > | removeAlignedRect (const QRect &rc) |
| QVector< QRect > | removeRect (const QRect &rc) |
Private Member Functions | |
| void | resize (const QRect &newMappedAreaSize) |
Static Private Member Functions | |
| static QRect | shrinkRectToAlignedGrid (const QRect &srcRect, int lod) |
Private Attributes | |
| int | m_gridSize |
| int | m_logGridSize |
| QRect | m_mappedAreaSize |
| QVector< quint8 > | m_mapping |
A utility class to maintain a sparse grid of loaded/unloaded rects.
KisRectsGrid manages the presence of the rectangular cells in the grid covering some specific area. The main usecase of the class is to maintain an overlay device over another paint device.
When you need to ensure that the overlay has some particular rect loaded, you just call grid->addRect(rect) and get a list of rects that have not yet been loaded into the overlay. The returned list may be empty if all the grid cells intersecting rect has already been loaded (added to the grid).
The size of the cell is defined at the construction stage and must be power of 2.
Definition at line 30 of file KisRectsGrid.h.
| KisRectsGrid::KisRectsGrid | ( | int | gridSize = 64 | ) |
Create a grid with cell size set to gridSize
Definition at line 18 of file KisRectsGrid.cpp.
References KisUsageLogger::log(), m_gridSize, m_logGridSize, and qFuzzyCompare().
| QVector< QRect > KisRectsGrid::addAlignedRect | ( | const QRect & | rc | ) |
Add an aligned rect to the grid
The grid will form a list of cells that intersect rc and have not not yet been loaded, mark them as loaded and return the list to the caller.
| rc | the rect to be added, the rect must be aligned |
Definition at line 62 of file KisRectsGrid.cpp.
References KisAlgebra2D::blowRect(), m_logGridSize, m_mappedAreaSize, m_mapping, resize(), KisLodTransformBase::scaledRect(), and KisLodTransformBase::upscaledRect().
| QVector< QRect > KisRectsGrid::addRect | ( | const QRect & | rc | ) |
Add an arbitrary (non-aligned) rect to the grid
The grid will form a list of cells that intersect rc and have not not yet been loaded, mark them as loaded and return the list to the caller.
| rc | the rect to be added, not necessary aligned to the grid |
Definition at line 57 of file KisRectsGrid.cpp.
References addAlignedRect(), and alignRect().
| QRect KisRectsGrid::alignRect | ( | const QRect & | rc | ) | const |
Grow rectangle rc until it becomes aligned to the grid cell borders.
Definition at line 52 of file KisRectsGrid.cpp.
References KisLodTransformBase::alignedRect(), and m_logGridSize.
| QRect KisRectsGrid::boundingRect | ( | ) | const |
Return the bounding box of the loaded cells of the grid
Definition at line 160 of file KisRectsGrid.cpp.
References m_logGridSize, m_mappedAreaSize, and KisLodTransformBase::upscaledRect().
| bool KisRectsGrid::contains | ( | const QRect & | rc | ) | const |
Return is rc is fully covered by the loaded cells of the grid
Definition at line 144 of file KisRectsGrid.cpp.
References alignRect(), m_logGridSize, m_mappedAreaSize, m_mapping, and KisLodTransformBase::scaledRect().
| QVector< QRect > KisRectsGrid::removeAlignedRect | ( | const QRect & | rc | ) |
Remove an aligned rect from the grid
The grid will form a list of loaded cells that are fully contained in rc, mark them as unloaded and return the list to the caller.
| rc | the rect to be removed, not necessary aligned to the grid |
Definition at line 123 of file KisRectsGrid.cpp.
References m_logGridSize, m_mappedAreaSize, m_mapping, KisLodTransformBase::scaledRect(), and KisLodTransformBase::upscaledRect().
| QVector< QRect > KisRectsGrid::removeRect | ( | const QRect & | rc | ) |
Remove an arbitrary (non-aligned) rect from the grid
The grid will form a list of loaded cells that are fully contained in rc, mark them as unloaded and return the list to the caller.
TODO: please note that removing two neighbouring non-aligned rectangles may still leave some cells marked as loaded. Perhaps we should change the meaning of this function to remove "all intersecting rectangles" instead of "all contained rectangles".
| rc | the rect to be removed, not necessary aligned to the grid |
Definition at line 117 of file KisRectsGrid.cpp.
References m_logGridSize, removeAlignedRect(), and shrinkRectToAlignedGrid().
|
private |
Definition at line 29 of file KisRectsGrid.cpp.
References KIS_SAFE_ASSERT_RECOVER_NOOP, m_mappedAreaSize, and m_mapping.
|
inlinestaticprivate |
Definition at line 88 of file KisRectsGrid.cpp.
References KisLodTransformBase::alignByPow2ButOneHi(), and KisLodTransformBase::alignByPow2Lo().
|
private |
Definition at line 109 of file KisRectsGrid.h.
|
private |
Definition at line 110 of file KisRectsGrid.h.
|
private |
Definition at line 112 of file KisRectsGrid.h.
|
private |
Definition at line 111 of file KisRectsGrid.h.