Krita Source Code Documentation
Loading...
Searching...
No Matches
KisWatershedWorker Class Reference

#include <KisWatershedWorker.h>

Classes

struct  Private
 

Public Member Functions

void addKeyStroke (KisPaintDeviceSP dev, const KoColor &color)
 Adds a key stroke to the worker.
 
 KisWatershedWorker (KisPaintDeviceSP heightMap, KisPaintDeviceSP dst, const QRect &boundingRect, KoUpdater *progress=0)
 
void run (qreal cleanUpAmount=0.0)
 run the filling process using the passes height map, strokes, and write the result coloring into the destination device
 
int testingGroupAllyEdge (qint32 group, quint8 level)
 
int testingGroupConflicts (qint32 group, quint8 level, qint32 withGroup)
 
int testingGroupForeignEdge (qint32 group, quint8 level)
 
int testingGroupNegativeEdge (qint32 group, quint8 level)
 
int testingGroupPositiveEdge (qint32 group, quint8 level)
 
void testingTryRemoveGroup (qint32 group, quint8 level)
 
 ~KisWatershedWorker ()
 

Private Attributes

const QScopedPointer< Privatem_d
 

Detailed Description

Definition at line 17 of file KisWatershedWorker.h.

Constructor & Destructor Documentation

◆ KisWatershedWorker()

KisWatershedWorker::KisWatershedWorker ( KisPaintDeviceSP heightMap,
KisPaintDeviceSP dst,
const QRect & boundingRect,
KoUpdater * progress = 0 )

Creates an empty watershed worker without any strokes attached. The strokes should be attached manually with addKeyStroke() call.

Parameters
heightMapprefiltered height map in alpha8 colorspace, with "0" meaning background color and "255" meaning line art. Heightmap is never modified by the worker!
dstdestination device where the result will be written
boundingRectthe worker refuses to fill outside the bounding rect, considering that outer area as having +inf height
progressthe progress value

Definition at line 250 of file KisWatershedWorker.cpp.

251 : m_d(new Private)
252{
254
255 m_d->progressUpdater = progress;
256 m_d->heightMap = heightMap;
257 m_d->dstDevice = dst;
258 m_d->boundingRect = boundingRect;
259
260 // Just the simplest color space with 4 bytes per pixel. We use it as
261 // a storage for qint32-indexed group ids
262 m_d->groupsMap = new KisPaintDevice(KoColorSpaceRegistry::instance()->rgb8());
263}
const KoColorSpace * colorSpace() const
const QScopedPointer< Private > m_d
virtual quint32 pixelSize() const =0
#define KIS_SAFE_ASSERT_RECOVER_RETURN(cond)
Definition kis_assert.h:128
static KoColorSpaceRegistry * instance()

References KisPaintDevice::colorSpace(), KoColorSpaceRegistry::instance(), KIS_SAFE_ASSERT_RECOVER_RETURN, m_d, and KoColorSpace::pixelSize().

◆ ~KisWatershedWorker()

KisWatershedWorker::~KisWatershedWorker ( )

Definition at line 265 of file KisWatershedWorker.cpp.

266{
267}

Member Function Documentation

◆ addKeyStroke()

void KisWatershedWorker::addKeyStroke ( KisPaintDeviceSP dev,
const KoColor & color )

Adds a key stroke to the worker.

The key strokes may intersect, in which case the lastly added stroke will have a priority over all the previous ones.

Parameters
devalpha8 paint device of the key stroke, may contain disjoint areas
colorthe color of the stroke

Definition at line 269 of file KisWatershedWorker.cpp.

270{
271 m_d->keyStrokes << KeyStroke(new KisPaintDevice(*dev), color);
272
273 KisPaintDeviceSP lastDev = m_d->keyStrokes.back().dev;
274
275 for (auto it = m_d->keyStrokes.begin(); it != m_d->keyStrokes.end() - 1; ++it) {
276 KisPaintDeviceSP dev = it->dev;
277 const QRect rc = dev->exactBounds() & lastDev->exactBounds();
278 if (rc.isEmpty()) continue;
279
280 KisSequentialIterator devIt(dev, rc);
281 KisSequentialConstIterator lastDevIt(lastDev, rc);
282
283 while (devIt.nextPixel() &&
284 lastDevIt.nextPixel()) {
285
286 quint8 *devPtr = devIt.rawData();
287 const quint8 *lastDevPtr = lastDevIt.rawDataConst();
288
289 if (*devPtr > 0 && *lastDevPtr > 0) {
290 *devPtr = 0;
291 }
292
293 }
294 }
295}
QRect exactBounds() const

References KisPaintDevice::exactBounds(), m_d, KisSequentialIteratorBase< IteratorPolicy, SourcePolicy, ProgressPolicy >::nextPixel(), KisSequentialIteratorBase< IteratorPolicy, SourcePolicy, ProgressPolicy >::rawData(), and KisSequentialIteratorBase< IteratorPolicy, SourcePolicy, ProgressPolicy >::rawDataConst().

◆ run()

void KisWatershedWorker::run ( qreal cleanUpAmount = 0.0)

run the filling process using the passes height map, strokes, and write the result coloring into the destination device

Parameters
cleanUpAmountshows how aggressively we should try to clean up the final coloring. Should be in range [0.0...1.0]

Definition at line 297 of file KisWatershedWorker.cpp.

298{
299 if (!m_d->heightMap) return;
300
301 m_d->groups << FillGroup(-1);
302
303 for (int i = 0; i < m_d->keyStrokes.size(); i++) {
304 parseColorIntoGroups(m_d->groups, m_d->groupsMap,
305 m_d->heightMap,
306 i, m_d->keyStrokes[i].dev,
307 m_d->boundingRect);
308 }
309
310// m_d->dumpGroupMaps();
311// m_d->calcNumGroupMaps();
312
313 const QRect initRect =
314 m_d->boundingRect & m_d->groupsMap->nonDefaultPixelArea();
315
316 m_d->initializeQueueFromGroupMap(initRect);
317 m_d->processQueue(0);
318
319 if (!m_d->progressUpdater || !m_d->progressUpdater->interrupted()) {
320 // m_d->dumpGroupMaps();
321 // m_d->calcNumGroupMaps();
322
323 if (cleanUpAmount > 0) {
324 m_d->cleanupForeignEdgeGroups(cleanUpAmount);
325 }
326
327 // m_d->calcNumGroupMaps();
328
329 m_d->writeColoring();
330 }
331}

References m_d.

◆ testingGroupAllyEdge()

int KisWatershedWorker::testingGroupAllyEdge ( qint32 group,
quint8 level )

Definition at line 348 of file KisWatershedWorker.cpp.

349{
350 return m_d->groups[group].levels[level].allyEdgeSize;
351}

References m_d.

◆ testingGroupConflicts()

int KisWatershedWorker::testingGroupConflicts ( qint32 group,
quint8 level,
qint32 withGroup )

Definition at line 353 of file KisWatershedWorker.cpp.

354{
355 return m_d->groups[group].levels[level].conflictWithGroup[withGroup].size();
356}

References m_d.

◆ testingGroupForeignEdge()

int KisWatershedWorker::testingGroupForeignEdge ( qint32 group,
quint8 level )

Definition at line 343 of file KisWatershedWorker.cpp.

344{
345 return m_d->groups[group].levels[level].foreignEdgeSize;
346}

References m_d.

◆ testingGroupNegativeEdge()

int KisWatershedWorker::testingGroupNegativeEdge ( qint32 group,
quint8 level )

Definition at line 338 of file KisWatershedWorker.cpp.

339{
340 return m_d->groups[group].levels[level].negativeEdgeSize;
341}

References m_d.

◆ testingGroupPositiveEdge()

int KisWatershedWorker::testingGroupPositiveEdge ( qint32 group,
quint8 level )

Definition at line 333 of file KisWatershedWorker.cpp.

334{
335 return m_d->groups[group].levels[level].positiveEdgeSize;
336}

References m_d.

◆ testingTryRemoveGroup()

void KisWatershedWorker::testingTryRemoveGroup ( qint32 group,
quint8 level )

Definition at line 358 of file KisWatershedWorker.cpp.

359{
360 QVector<TaskPoint> taskPoints =
361 m_d->tryRemoveConflictingPlane(group, levelIndex);
362
363 if (!taskPoints.isEmpty()) {
364 Q_FOREACH (const TaskPoint &pt, taskPoints) {
365 m_d->pointsQueue.push(pt);
366 }
367 m_d->processQueue(group);
368 }
369 m_d->dumpGroupMaps();
370 m_d->calcNumGroupMaps();
371}

References m_d.

Member Data Documentation

◆ m_d

const QScopedPointer<Private> KisWatershedWorker::m_d
private

Definition at line 68 of file KisWatershedWorker.h.


The documentation for this class was generated from the following files: