Implementing Magnetic Lasso for Krita

Kuntal Majumder hellozee at
Wed Mar 20 04:10:45 GMT 2019


So, I was going through the code of the different selection tools to try
understand how can I implement or better say re-implement the magnetic
lasso. I found out there are a total of three ways of how the selection
tools are implemented,

Outline, Similar and Contagious , directly inherit from KisToolSelect
and implement the functionality inside one class.

Elliptic, Rectangular and Polygonal, create a local tool which inherits
a base tool like ellipse, rectangle or polygon and then the local tool
is further inherited by KisSelectToolBase, which is then used to
implement the corresponding selection tool.

Path selection tool rather follows a different implementation, starts
the same by creating a local tool which inherits the KoCreatePathTool,
which is then passed down to the KisDelegatedTool with local tool as
delgate, then there is a wrapper around the delegated tool. The wrapper
gets inherited by KisSelectToolBase, used to implement the corresponding
selection tool just like the previous one.

The third approach seems a little bit buggy or as discussed with Boud is
kind of broken, upon changing the raw casts into dynamic_casts the tool
fails to activate and ends up crashing the whole program.

The previous attempt to restore the Magnetic Lasso followed the third
approach, which I don't think _if_ broken should be followed. So taking
the fact the tool will work the following way,

 1. User clicks on the canvas creating an anchor and moves the mouse
 2. We draw a line from the anchor to the current mouse position
 3. Add radius as the width of that line, getting the area (A) that we
are going to search for the edge
 4. Run our first approximation function over A to get the probable edges
 5. Start searching for the required edge by scanning across the width
of A, evaluating the possible edge points by the distance from the last
found edge point and deviation from the center line.
 6. Do the search and evaluate process until we hit the cursor or hit
the maximum distance (frequency) between each anchor, upon which we
place another anchor automatically and restart the process.

//Note : Need to add some mock-ups for it, I guess

Technically the anchors in this case wont be the same as nodes in a
bezier/polygon curve, they will just act as a checkpoints, if the user
wants he/she can remove the checkpoints with right click and redo the
edge. Hence I am not sure how to go on and implement the tool, I mean
which way should I pick up from the above mentioned 3 ways?

Also after a quick run around papers on edge detection algorithms based
on fuzzy logic, I am taking a look over some papers around scan-line
based algorithms to figure out edges. Added to that, as discussed
here[1], the already implemented LoG along with a A* search could also
work, though I don't know how would that fare in the long run?

Here is my proposal [WIP]

Kuntal M


More information about the kimageshop mailing list