GPv3: Refactor code for the hard eraser #111390

Merged
Amélie Fondevilla merged 9 commits from amelief/blender:gpv3-erase-operator-refactor into main 2023-08-23 14:13:56 +02:00

This patch refactors most of the code of the hard eraser, both for readability purpose, and to prepare the integration of the soft mode of the eraser.
The refactoring includes :

  • the use of specific structures and enum types SegmentCircleIntersection, PointCircleSide, and PointTransferData to handle the data more easily,
  • improve readability of the intersections functions (better naming, and more accurate and generic comments),
  • definition of a more generic compute_topology_change function that handles point insertion, removal, and curve splitting for curves geometry.
This patch refactors most of the code of the hard eraser, both for readability purpose, and to prepare the integration of the soft mode of the eraser. The refactoring includes : - the use of specific structures and enum types `SegmentCircleIntersection`, `PointCircleSide`, and `PointTransferData` to handle the data more easily, - improve readability of the intersections functions (better naming, and more accurate and generic comments), - definition of a more generic `compute_topology_change` function that handles point insertion, removal, and curve splitting for curves geometry.
Amélie Fondevilla added this to the Grease Pencil project 2023-08-22 16:12:00 +02:00
Amélie Fondevilla added a new dependency 2023-08-22 16:12:31 +02:00
Amélie Fondevilla requested review from Hans Goudey 2023-08-22 16:56:14 +02:00
Amélie Fondevilla force-pushed gpv3-erase-operator-refactor from b564fc1610 to 9dd9bc918d 2023-08-22 17:25:46 +02:00 Compare
Hans Goudey reviewed 2023-08-22 21:53:11 +02:00
Hans Goudey left a comment
Member

Take my comments in the context of what you find reasonable, obviously you have a better idea of what's possible here.

I'd guess the most efficient way to transfer attribute when some points are copied and some are interpolated is to do it in two loops, where one selects the source points with an index mask and the other uses the int,float combination. But it's probably not needed here, if this makes the code easier to deal with, that's good :)

Take my comments in the context of what you find reasonable, obviously you have a better idea of what's possible here. I'd guess the most efficient way to transfer attribute when some points are copied and some are interpolated is to do it in two loops, where one selects the source points with an index mask and the other uses the `int,float` combination. But it's probably not needed here, if this makes the code easier to deal with, that's good :)
@ -115,1 +115,4 @@
struct SegmentCircleIntersection {
/* Position of the intersection in the segment. */
float factor{0.0f};
Member

It's not in the style guide I guess, but usually these defaults are written with =

It's not in the style guide I guess, but usually these defaults are written with `=`
amelief marked this conversation as resolved
@ -116,0 +121,4 @@
* circle, false if it corresponds to an outside/inside transition . */
bool inside_outside_intersection{false};
};
enum PointCircleSide { Outside, OutsideInsideBoundary, InsideOutsideBoundary, Inside };
Member

enum class is generally preferred since it requires each item to be scoped with the name of the enum. Though it's a bit longer, the context is usually helpful when reading code.

`enum class` is generally preferred since it requires each item to be scoped with the name of the enum. Though it's a bit longer, the context is usually helpful when reading code.
amelief marked this conversation as resolved
@ -144,0 +148,4 @@
const int64_t squared_radius,
float &r_mu0,
float &r_mu1,
PointCircleSide &point_side,
Member

Return arguments usually have the r_ prefix

Return arguments usually have the `r_` prefix
amelief marked this conversation as resolved
@ -254,0 +258,4 @@
const bke::CurvesGeometry &src,
const Span<float2> screen_space_positions,
MutableSpan<PointCircleSide> r_point_side,
MutableSpan<Vector<SegmentCircleIntersection>> r_intersections) const
Member

Not sure about the details of this case, but though the Array<Vector>> storage is pretty easy to use, it can be very slow and memory intensive. The overhead of a vector per point can make a big difference. Ultimately that's the goal of classes like OffsetIndices-- to make one alternative, slicing larger contiguous arrays, more intuitive.

Not sure about the details of this case, but though the `Array<Vector>>` storage is pretty easy to use, it can be very slow and memory intensive. The overhead of a vector per point can make a big difference. Ultimately that's the goal of classes like `OffsetIndices`-- to make one alternative, slicing larger contiguous arrays, more intuitive.
Author
Member

Agree. It was so much easier to use Array<Vector> to figure out how to deal with intersections, because for the hard eraser there's a max of 2 intersections per segment, but for the soft eraser, this number can be larger, depending on the brush's falloff curve.
This number is the same for each segment though, so I think it's possible indeed to use a contiguous array while keeping multithread computation..
Let me know what you think of my proposed solution for this (commit 1d1f030ef0).

Agree. It was so much easier to use `Array<Vector>` to figure out how to deal with intersections, because for the hard eraser there's a max of 2 intersections per segment, but for the soft eraser, this number can be larger, depending on the brush's falloff curve. This number is the same for each segment though, so I think it's possible indeed to use a contiguous array while keeping multithread computation.. Let me know what you think of my proposed solution for this (commit 1d1f030ef0).
Member

Yeah, seems good-- a bit of a complexity cost but hopefully people notice the tool is fast :P And if intersections_max_per_segment is ever too big, making it wasteful, offsets could be used too.

Yeah, seems good-- a bit of a complexity cost but hopefully people notice the tool is fast :P And if `intersections_max_per_segment` is ever too big, making it wasteful, offsets could be used too.
amelief marked this conversation as resolved
@ -323,0 +365,4 @@
*
*/
struct PointTransferData {
int64_t src_point;
Member

I'd recommend sticking with 32 bit integers (int) unless there's a reason not to. For the forseable future I don't see us supporting more than 2 billion points in these geometries, and the 2x memory consumption cam also make a difference.

I'd recommend sticking with 32 bit integers (`int`) unless there's a reason not to. For the forseable future I don't see us supporting more than 2 billion points in these geometries, and the 2x memory consumption cam also make a difference.
amelief marked this conversation as resolved
@ -460,3 +476,1 @@
const IndexRange dst_points(dst_interm_curves_offsets[src_curve],
dst_interm_curves_offsets[src_curve + 1] -
dst_interm_curves_offsets[src_curve]);
const IndexRange dst_points_range(dst_interm_curves_offsets[src_curve],
Member

Looks like this variable rename might not be necessary?

Looks like this variable rename might not be necessary?
amelief marked this conversation as resolved
Amélie Fondevilla added 5 commits 2023-08-23 09:59:19 +02:00
Amélie Fondevilla added 1 commit 2023-08-23 10:50:45 +02:00
Hans Goudey approved these changes 2023-08-23 13:41:23 +02:00
Amélie Fondevilla added 1 commit 2023-08-23 14:11:09 +02:00
Amélie Fondevilla merged commit 1193f2d7ec into main 2023-08-23 14:13:56 +02:00
Amélie Fondevilla deleted branch gpv3-erase-operator-refactor 2023-08-23 14:13:58 +02:00
Amélie Fondevilla removed a dependency 2023-08-23 14:37:59 +02:00
Sign in to join this conversation.
No reviewers
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset Browser
Interest
Asset Browser Project Overview
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
Interest
EEVEE & Viewport
Interest
Freestyle
Interest
Geometry Nodes
Interest
Grease Pencil
Interest
ID Management
Interest
Images & Movies
Interest
Import Export
Interest
Line Art
Interest
Masking
Interest
Metal
Interest
Modeling
Interest
Modifiers
Interest
Motion Tracking
Interest
Nodes & Physics
Interest
OpenGL
Interest
Overlay
Interest
Overrides
Interest
Performance
Interest
Physics
Interest
Pipeline, Assets & IO
Interest
Platforms, Builds & Tests
Interest
Python API
Interest
Render & Cycles
Interest
Render Pipeline
Interest
Sculpt, Paint & Texture
Interest
Text Editor
Interest
Translations
Interest
Triaging
Interest
Undo
Interest
USD
Interest
User Interface
Interest
UV Editing
Interest
VFX & Video
Interest
Video Sequencer
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Blender 2.8 Project
Legacy
Milestone 1: Basic, Local Asset Browser
Legacy
OpenGL Error
Meta
Good First Issue
Meta
Papercut
Meta
Retrospective
Meta
Security
Module
Animation & Rigging
Module
Core
Module
Development Management
Module
EEVEE & Viewport
Module
Grease Pencil
Module
Modeling
Module
Nodes & Physics
Module
Pipeline, Assets & IO
Module
Platforms, Builds & Tests
Module
Python API
Module
Render & Cycles
Module
Sculpt, Paint & Texture
Module
Triaging
Module
User Interface
Module
VFX & Video
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Priority
High
Priority
Low
Priority
Normal
Priority
Unbreak Now!
Status
Archived
Status
Confirmed
Status
Duplicate
Status
Needs Info from Developers
Status
Needs Information from User
Status
Needs Triage
Status
Resolved
Type
Bug
Type
Design
Type
Known Issue
Type
Patch
Type
Report
Type
To Do
No Milestone
No project
No Assignees
2 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender#111390
No description provided.