GPv3: Dissolve Operator #111079

Merged
Pratik Borhade merged 14 commits from casey-bianco-davis/blender:GPv3-dissolve into main 2023-08-24 11:06:26 +02:00

Adds the Dissolve operator.


note that this pull request contains some of the same menu code also included in #110938

Adds the Dissolve operator. --- note that this pull request contains some of the same menu code also included in #110938
casey-bianco-davis added 1 commit 2023-08-13 00:01:07 +02:00
Iliya Katushenock added this to the Grease Pencil project 2023-08-13 00:09:21 +02:00
Hans Goudey reviewed 2023-08-13 00:40:17 +02:00
Hans Goudey left a comment
Member

I'm sure Falk will have more comments, just commented about a couple things I noticed reading through the code.

I'm sure Falk will have more comments, just commented about a couple things I noticed reading through the code.
@ -561,0 +563,4 @@
* \{ */
enum DissolveMode {
/* dissolve all selected points */
Member

Comment style: https://wiki.blender.org/wiki/Style_Guide/C_Cpp#Comments

(begin with a capital, end with period)

Also, I'd suggest using enum class which forces nice name scoping:

enum class DissolveMode {
  Points,
  Between,
  Unselect,
};

...

DissolveMode::Points;
Comment style: https://wiki.blender.org/wiki/Style_Guide/C_Cpp#Comments (begin with a capital, end with period) Also, I'd suggest using `enum class` which forces nice name scoping: ``` enum class DissolveMode { Points, Between, Unselect, }; ... DissolveMode::Points; ```
Author
Member

I fixed the comments, but when tried the enum class it broke the EnumPropertyItem, because it could not be implicitly converted to int, but I don't know if that was just a mistake in how I implementing it.

I fixed the comments, but when tried the `enum class` it broke the `EnumPropertyItem`, because it could not be implicitly converted to int, but I don't know if that was just a mistake in how I implementing it.
Member

You can just use int(DissolveMode::Points). That should do the trick here.
Also can be enum class DissolveMode : int8_t { (since we know there won't be that many modes anyway).

You can just use `int(DissolveMode::Points)`. That should do the trick here. Also can be `enum class DissolveMode : int8_t {` (since we know there won't be that many modes anyway).
casey-bianco-davis marked this conversation as resolved
@ -561,0 +630,4 @@
curve_selection, false);
if (deselection_ranges.size() != 0) {
IndexRange first_range = deselection_ranges.first().shift(points.first());
Member

There's a lot of nesting here-- I'd suggest splitting the operation for a CurvesGeometry to a separate function ot make it clearer what's going on.

There's a lot of nesting here-- I'd suggest splitting the operation for a CurvesGeometry to a separate function ot make it clearer what's going on.
filedescriptor marked this conversation as resolved
@ -561,0 +635,4 @@
/* Because we are going to invert, fill with `!false` so that it does not get
* dissolved.*/
points_to_dissolve.as_mutable_span().slice(last_range).fill(!false);
Member

!false could just be written as true

`!false` could just be written as `true`
casey-bianco-davis marked this conversation as resolved
casey-bianco-davis added 1 commit 2023-08-14 03:59:53 +02:00
casey-bianco-davis added 1 commit 2023-08-14 04:18:40 +02:00
Falk David requested changes 2023-08-14 12:40:56 +02:00
Falk David left a comment
Member

Added some comments.

I somewhat agree with @HooglyBoogly in that I think everything inside the if (mode == DISSOLVE_BETWEEN || mode == DISSOLVE_UNSELECT) { should be put into a static function void get_points_to_dissolve(bke::CurvesGeometry &curves, const DissolveMode mode, MutableSpan<bool> r_points_to_dissolve).

Added some comments. I somewhat agree with @HooglyBoogly in that I think everything inside the `if (mode == DISSOLVE_BETWEEN || mode == DISSOLVE_UNSELECT) {` should be put into a static function `void get_points_to_dissolve(bke::CurvesGeometry &curves, const DissolveMode mode, MutableSpan<bool> r_points_to_dissolve)`.
@ -561,0 +613,4 @@
/* Both `between` and `unselect` have the unselected point being dissolved.*/
if (mode == DISSOLVE_BETWEEN || mode == DISSOLVE_UNSELECT) {
threading::parallel_for(curves.curves_range(), 128, [&](const IndexRange range) {
for (const int curve_i : range) {
Member

const int64_t curve_i

`const int64_t curve_i`
casey-bianco-davis marked this conversation as resolved
@ -561,0 +620,4 @@
if (!curve_selection.contains(true)) {
/* Because we are going to invert, fill with true so that it does not get
* dissolved.*/
points_to_dissolve.as_mutable_span().slice(points).fill(true);
Member

It might make sense to define a MutableSpan<bool> points_to_keep = points_to_dissolve.as_mutable_span(); with the comment above saying that this will be inverted later and thus it is the points to keep.

It might make sense to define a `MutableSpan<bool> points_to_keep = points_to_dissolve.as_mutable_span();` with the comment above saying that this will be inverted later and thus it is the points to keep.
casey-bianco-davis marked this conversation as resolved
@ -561,0 +648,4 @@
IndexMaskMemory memory;
IndexMask points_to_remove = IndexMask::from_bools(points_to_dissolve, memory);
if (!points_to_remove.is_empty()) {
Member

It might make sense to build the IndexMask inside this if and check if the Array<bool> contains true (using as_span().contains(true)).

It might make sense to build the `IndexMask` inside this if and check if the `Array<bool>` contains `true` (using `as_span().contains(true)`).
casey-bianco-davis marked this conversation as resolved
@ -561,0 +674,4 @@
/* Callbacks. */
ot->invoke = WM_menu_invoke;
ot->exec = grease_pencil_dissolve_exec;
ot->poll = editable_grease_pencil_poll;
Member

I think this operator should only be working in point selection mode. Use editable_grease_pencil_point_selection_poll.

I think this operator should only be working in point selection mode. Use `editable_grease_pencil_point_selection_poll`.
casey-bianco-davis marked this conversation as resolved
casey-bianco-davis added 4 commits 2023-08-14 23:08:34 +02:00
37df7d35c5 Fix: Bug when dissolving with end point selected.
The problem was that when dissolving between and a end point was selected the first/last range would not have had the first/last point in it. and so it would not dissolve some of the regions.
casey-bianco-davis added 1 commit 2023-08-14 23:15:36 +02:00
casey-bianco-davis added 1 commit 2023-08-14 23:30:22 +02:00
casey-bianco-davis added 1 commit 2023-08-15 00:37:39 +02:00
casey-bianco-davis requested review from Falk David 2023-08-15 00:37:56 +02:00
Falk David requested changes 2023-08-15 11:03:11 +02:00
Falk David left a comment
Member

Some comments to reduce indentations a bit more.

Some comments to reduce indentations a bit more.
@ -561,0 +595,4 @@
}
/* Both `between` and `unselect` have the unselected point being the ones dissolved so we need
* to invert.*/
else if (mode == DISSOLVE_BETWEEN || mode == DISSOLVE_UNSELECT) {
Member

The else case can be removed because we return in the if before (no-else-after-return).
If you'd like to make sure the mode is DISSOLVE_BETWEEN or DISSOLVE_UNSELECT then I'd suggest to put an assert here: BLI_assert(ELEM(mode, DISSOLVE_BETWEEN, DISSOLVE_UNSELECT).

The `else` case can be removed because we return in the `if` before (no-else-after-return). If you'd like to make sure the mode is `DISSOLVE_BETWEEN` or `DISSOLVE_UNSELECT` then I'd suggest to put an assert here: `BLI_assert(ELEM(mode, DISSOLVE_BETWEEN, DISSOLVE_UNSELECT)`.
casey-bianco-davis marked this conversation as resolved
@ -561,0 +607,4 @@
const Span<bool> curve_selection = points_to_dissolve.as_span().slice(points);
/* The unselected curves should not be dissolved.*/
if (!curve_selection.contains(true)) {
points_to_keep.slice(points).fill(true);
Member

We can continue; here.

We can `continue;` here.
casey-bianco-davis marked this conversation as resolved
@ -561,0 +611,4 @@
}
/* `between` is just `unselect` but with the first and last segments not geting
* dissolved.*/
else if (mode == DISSOLVE_BETWEEN) {
Member

Because there is no code after this, I would prefer a

if (mode != DISSOLVE_BETWEEN) {
 continue;
}
Because there is no code after this, I would prefer a ``` if (mode != DISSOLVE_BETWEEN) { continue; } ```
casey-bianco-davis marked this conversation as resolved
casey-bianco-davis added 1 commit 2023-08-15 21:26:43 +02:00
casey-bianco-davis requested review from Falk David 2023-08-15 21:28:17 +02:00
casey-bianco-davis added 1 commit 2023-08-15 21:39:20 +02:00
Falk David approved these changes 2023-08-16 11:29:35 +02:00
Falk David left a comment
Member

Looks good :) I will merge this soon.

Looks good :) I will merge this soon.
Pratik Borhade reviewed 2023-08-22 12:24:12 +02:00
Pratik Borhade left a comment
Member

Reminder to merge the PR :)

Could you update PR to match the comment style?: https://wiki.blender.org/wiki/Style_Guide/C_Cpp#Comments

Reminder to merge the PR :) Could you update PR to match the comment style?: https://wiki.blender.org/wiki/Style_Guide/C_Cpp#Comments
@ -561,0 +599,4 @@
}
/* Both `between` and `unselect` have the unselected point being the ones dissolved so we need
* to invert.*/
Member

add space between . and */
i.e.: ... to invert . */

add space between `.` and `*/` i.e.: `... to invert . */`
casey-bianco-davis marked this conversation as resolved
@ -561,0 +603,4 @@
BLI_assert(ELEM(mode, DissolveMode::BETWEEN, DissolveMode::UNSELECT));
const OffsetIndices<int> points_by_curve = curves.points_by_curve();
/* Because we are going to invert, these become the points to keep.*/
Member

add space between . and */

Above change is required at few more places in PR

add space between `.` and `*/` Above change is required at few more places in PR
casey-bianco-davis marked this conversation as resolved
casey-bianco-davis added 1 commit 2023-08-22 23:06:56 +02:00
buildbot/vexp-code-patch-coordinator Build done. Details
ac3cfdde47
Cleanup: Add space at the end of comments.
Member

@blender-bot build

@blender-bot build
Hans Goudey changed title from GPv3: Dissolve Operator. to GPv3: Dissolve Operator 2023-08-23 13:24:49 +02:00
Member

tests are failing on bots (very likely due to the outdated code).
@casey-bianco-davis , could you update again with main branch?
or should we merge the PR directly?
@HooglyBoogly ^

tests are failing on bots (very likely due to the outdated code). @casey-bianco-davis , could you update again with main branch? or should we merge the PR directly? @HooglyBoogly ^
Member

Fine to merge I think. Though that does raise the point of all of this new GP code being uncovered by regression tests!

Fine to merge I think. Though that does raise the point of all of this new GP code being uncovered by regression tests!
casey-bianco-davis added 1 commit 2023-08-23 19:39:41 +02:00
buildbot/vexp-code-patch-coordinator Build done. Details
7b70d4615b
Merge branch 'main' into GPv3-dissolve
Member

@blender-bot build

@blender-bot build
Pratik Borhade merged commit 5bed3ef827 into main 2023-08-24 11:06:26 +02:00
casey-bianco-davis deleted branch GPv3-dissolve 2023-08-24 21:25:29 +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
4 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#111079
No description provided.