Geometry Nodes: Add a 'Group ID' input to the Fill Curve node #114048

Merged
Hans Goudey merged 17 commits from Douglas-Paul/blender:group-id-for-fill-curve-node into main 2023-11-14 11:23:28 +01:00
Contributor

This adds a "Group ID" input to the Fill Curve node, per #102285.

The curve filling operation is performed separately for each group, so curves associated with different Group IDs do not intersect.

This implementation also supports Grease Pencil 3 curves.


The issue said to name the socket "Group Index", but I see that the preferred term has changed so I named it "Group ID" instead.

I have also attached a .blend file that exercises the new node input in a few different situations. (It includes a README text block that describes each test case.)

This adds a "Group ID" input to the Fill Curve node, per #102285. The curve filling operation is performed separately for each group, so curves associated with different Group IDs do not intersect. This implementation also supports Grease Pencil 3 curves. --- The issue said to name the socket "Group Index", but I see that [the preferred term has changed](https://projects.blender.org/blender/blender/commit/203ab983ceb7d791eae6d702f614f596314026d7) so I named it "Group ID" instead. I have also attached a .blend file that exercises the new node input in a few different situations. (It includes a README text block that describes each test case.)
Douglas Paul added 1 commit 2023-10-23 06:11:29 +02:00
Iliya Katushenock added this to the Nodes & Physics project 2023-10-23 06:22:09 +02:00
Iliya Katushenock added the
Interest
Geometry Nodes
label 2023-10-23 06:22:13 +02:00
Hans Goudey requested review from Hans Goudey 2023-10-23 09:23:47 +02:00
Member

Very nice, thanks for the PR! I should have some time to review this in the coming days.

Very nice, thanks for the PR! I should have some time to review this in the coming days.
Hans Goudey requested changes 2023-10-31 10:47:50 +01:00
Hans Goudey left a comment
Member

Looking good, I just have some suggestions for simplifications and performance improvements.

Looking good, I just have some suggestions for simplifications and performance improvements.
@ -32,2 +32,4 @@
b.add_input<decl::Geometry>("Curve").supported_type(
{GeometryComponent::Type::Curve, GeometryComponent::Type::GreasePencil});
b.add_input<decl::Int>("Group ID")
.default_value(0)
Member

.default_value(0) is unnecessary, that's the implicit default already.

`.default_value(0)` is unnecessary, that's the implicit default already.
Douglas-Paul marked this conversation as resolved
@ -78,0 +129,4 @@
data_evaluator.add(group_index_field);
data_evaluator.evaluate();
const VArray<int> curve_group_ids = data_evaluator.get_evaluated<int>(0);
Member

This can have a special case for curve_group_ids.is_single() to avoid building selections.

A simpler way to do this that will help optimization in the future is using a combination of VectorSet<int> and IndexMask::from_groups. There are some examples of that already.

This can have a special case for `curve_group_ids.is_single()` to avoid building selections. A simpler way to do this that will help optimization in the future is using a combination of `VectorSet<int>` and `IndexMask::from_groups`. There are some examples of that already.
Author
Contributor

This can have a special case for curve_group_ids.is_single() to avoid building selections.

Yeah, that had seemed like too much of a corner case to be worth adding special handling for, but I suppose it does make sense since it's low complexity.

A simpler way to do this that will help optimization in the future is using a combination of VectorSet<int> and IndexMask::from_groups. There are some examples of that already.

Okay, I made the changes based off of how I see things being done in node_geo_index_of_nearest.cc. I'm not sure I agree it's simpler, but I understand how it's likely more efficient.

> This can have a special case for `curve_group_ids.is_single()` to avoid building selections. Yeah, that had seemed like too much of a corner case to be worth adding special handling for, but I suppose it does make sense since it's low complexity. > A simpler way to do this that will help optimization in the future is using a combination of `VectorSet<int>` and `IndexMask::from_groups`. There are some examples of that already. Okay, I made the changes based off of how I see things being done in `node_geo_index_of_nearest.cc`. I'm not sure I agree it's _simpler_, but I understand how it's likely more efficient.
Member

Right, good point. Less so about simplicity I guess, more about making the pattern recognizable and making it use common code, so we can optimize them all at once at some point.

Right, good point. Less so about simplicity I guess, more about making the pattern recognizable and making it use common code, so we can optimize them all at once at some point.
Douglas-Paul marked this conversation as resolved
@ -113,2 +185,3 @@
static void curve_fill_calculate(GeometrySet &geometry_set, const GeometryNodeCurveFillMode mode)
/* Converts multiple CDT results into a single Mesh. */
static Mesh *cdts_to_mesh(const Vector<meshintersect::CDT_result<double>> &results)
Member

We should try to avoid duplicating the logic in cdt_to_mesh.
A better approach is probably creating the mesh, then filling each slice corresponding to a CDT result. Then the 1 mesh case is handled by that by default.

Also, you can pass const Span<meshintersect::CDT_result rather than a const reference to a vector.

We should try to avoid duplicating the logic in `cdt_to_mesh`. A better approach is probably creating the mesh, then filling each slice corresponding to a CDT result. Then the 1 mesh case is handled by that by default. Also, you can pass `const Span<meshintersect::CDT_result` rather than a const reference to a vector.
Author
Contributor

We should try to avoid duplicating the logic in cdt_to_mesh.
A better approach is probably creating the mesh, then filling each slice corresponding to a CDT result. Then the 1 mesh case is handled by that by default.

I definitely agree it's best to avoid duplicating the logic, but I don't see a way to combine them without a bit of a performance hit to the presumably much more common case of a single group.

Could you elaborate on what you mean by "filling each slice corresponding to a CDT result"? It sounds like you're talking about looping over the CDT results and adding each to the mesh, but that's what cdts_to_mesh() is already doing. I could eliminate cdt_to_mesh(), but again I'm not sure if that's worth the added complexity for the simple cases.

Also, you can pass const Span<meshintersect::CDT_result rather than a const reference to a vector.

Ah, yes, thank you. It will be a while before things like that jump out at me.

> We should try to avoid duplicating the logic in `cdt_to_mesh`. > A better approach is probably creating the mesh, then filling each slice corresponding to a CDT result. Then the 1 mesh case is handled by that by default. I definitely agree it's best to avoid duplicating the logic, but I don't see a way to combine them without a bit of a performance hit to the presumably much more common case of a single group. Could you elaborate on what you mean by "filling each slice corresponding to a CDT result"? It sounds like you're talking about looping over the CDT results and adding each to the mesh, but that's what `cdts_to_mesh()` is already doing. I could [eliminate `cdt_to_mesh()`](https://projects.blender.org/Douglas-Paul/blender/commit/dfa046b9223e50d163ac3b6da7a6974d99d7a491), but again I'm not sure if that's worth the added complexity for the simple cases. > Also, you can pass `const Span<meshintersect::CDT_result` rather than a const reference to a vector. Ah, yes, thank you. It will be a while before things like that jump out at me.
Member

Yes, I'd probably just remove cdt_to_mesh and make sure cdts_to_mesh isn't doing too much extra work in the 1 mesh case. But yeah, this can be changed later too.

Yes, I'd probably just remove `cdt_to_mesh` and make sure `cdts_to_mesh` isn't doing too much extra work in the 1 mesh case. But yeah, this can be changed later too.
Douglas-Paul marked this conversation as resolved
Douglas Paul added 4 commits 2023-11-03 05:28:38 +01:00
Hans Goudey requested changes 2023-11-03 09:31:51 +01:00
Hans Goudey left a comment
Member

Just a few comments about parallelism and some simplification now. I'd still probably try to have less duplication in the mesh copying, but I'm already planning to change this a fair amount in #111061 later, so that can wait.

Just a few comments about parallelism and some simplification now. I'd still probably try to have less duplication in the mesh copying, but I'm already planning to change this a fair amount in #111061 later, so that can wait.
@ -78,0 +96,4 @@
input.face.reinitialize(mask.size());
int i_vert = 0;
int i_face = 0;
Member

When writing this sort of code, we're always looking out for how we can make the serial part boil down to just integer addition. Here's my attempt at that:

  Array<int> offsets_data(mask.size() + 1);
  const OffsetIndices points_by_curve_masked = offset_indices::gather_selected_offsets(
      points_by_curve, mask, offsets_data);

  mask.foreach_index(GrainSize(1024), [&](const int src_curve, const int dst_curve) {
    const IndexRange src_points = points_by_curve[src_curve];
    const IndexRange dst_points = points_by_curve_masked[dst_curve];

    for (const int i : src_points.index_range()) {
      const int src = src_points[i];
      const int dst = dst_points[i];
      input.vert[dst] = double2(positions[src].x, positions[src].y);
    }

    input.face[dst_curve].resize(src_points.size());
    MutableSpan<int> face_verts = input.face[dst_curve];
    array_utils::fill_index_range<int>(input.face[dst_curve], dst_points.start());
  });

Not tested, but I think it works logically. In #111061 I'm also refactoring the CDT code to use something more like the OffsetIndices format, which would remove the need for the "vector of vectors" approach which is much slower.

When writing this sort of code, we're always looking out for how we can make the serial part boil down to just integer addition. Here's my attempt at that: ```cpp Array<int> offsets_data(mask.size() + 1); const OffsetIndices points_by_curve_masked = offset_indices::gather_selected_offsets( points_by_curve, mask, offsets_data); mask.foreach_index(GrainSize(1024), [&](const int src_curve, const int dst_curve) { const IndexRange src_points = points_by_curve[src_curve]; const IndexRange dst_points = points_by_curve_masked[dst_curve]; for (const int i : src_points.index_range()) { const int src = src_points[i]; const int dst = dst_points[i]; input.vert[dst] = double2(positions[src].x, positions[src].y); } input.face[dst_curve].resize(src_points.size()); MutableSpan<int> face_verts = input.face[dst_curve]; array_utils::fill_index_range<int>(input.face[dst_curve], dst_points.start()); }); ``` Not tested, but I think it works logically. In #111061 I'm also refactoring the CDT code to use something more like the `OffsetIndices` format, which would remove the need for the "vector of vectors" approach which is much slower.
Author
Contributor

Thank you, this makes a lot of sense. Just like "thinking with Portals", it will take some practice to get used to "thinking with offsets".

This inspired me to similarly re-implement cdts_to_mesh() using offsets.

Thank you, this makes a lot of sense. Just like "thinking with Portals", it will take some practice to get used to "thinking with offsets". This inspired me to similarly re-implement `cdts_to_mesh()` using offsets.
Douglas-Paul marked this conversation as resolved
@ -78,0 +139,4 @@
const VArraySpan<int> group_ids_span(curve_group_ids);
const int domain_size = group_ids_span.size();
VectorSet<int> group_indexing;
Member

This can be done in the constructor:

  const VectorSet<int> group_indexing(group_ids_span);
  const int groups_num = group_indexing.size();

This can be done in the constructor: ```cpp const VectorSet<int> group_indexing(group_ids_span); const int groups_num = group_indexing.size(); ```
Author
Contributor

I was going to let you know these lines were copied from node_geo_index_of_nearest.cc so you could apply the same fix there, but I see you already did that.

I was going to let you know these lines were copied from `node_geo_index_of_nearest.cc` so you could apply the same fix there, but I see [you already did that](https://projects.blender.org/blender/blender/commit/df4df75317f93516fe7079a455604bc66aa4409b).
Douglas-Paul marked this conversation as resolved
@ -172,12 +342,15 @@ static void curve_fill_calculate(GeometrySet &geometry_set, const GeometryNodeCu
static void node_geo_exec(GeoNodeExecParams params)
{
GeometrySet geometry_set = params.extract_input<GeometrySet>("Curve");
ValueOrField<int> group_index_value_or_field = params.extract_input<ValueOrField<int>>(
Member

I think this can be a bit simpler. Just Field should be fine here:

  const Field<int> group_index_value_or_field = params.extract_input<Field<int>>("Group ID");

The field evaluation should be basically free when the field just outputs a single value, then the other code should just fall back on the groups.size()==1 case already.

I think this can be a bit simpler. Just `Field` should be fine here: ```cpp const Field<int> group_index_value_or_field = params.extract_input<Field<int>>("Group ID"); ``` The field evaluation should be basically free when the field just outputs a single value, then the other code should just fall back on the `groups.size()==1` case already.
Douglas-Paul marked this conversation as resolved
Douglas Paul added 5 commits 2023-11-14 05:40:57 +01:00
Douglas Paul requested review from Hans Goudey 2023-11-14 05:45:40 +01:00
Hans Goudey added 7 commits 2023-11-14 11:18:25 +01:00
Hans Goudey approved these changes 2023-11-14 11:19:31 +01:00
Hans Goudey left a comment
Member

Thanks, that looks great! I made some tweaks to small style things, but other than that this is ready IMO.

Thanks, that looks great! I made some tweaks to small style things, but other than that this is ready IMO.
Hans Goudey merged commit 90de0368cd into main 2023-11-14 11:23:28 +01:00
Douglas Paul deleted branch group-id-for-fill-curve-node 2023-11-14 13:53:28 +01: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 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#114048
No description provided.