GPv3: Add access functions for opacity and radius attributes #109733

Merged
Falk David merged 12 commits from amelief/blender:gpv3-attributes-api into main 2023-07-11 15:11:21 +02:00

We need setters and getters for these two very commonly accessed attributes of grease pencil.
The code is based on the implementation of CurvesGeometry::positions() and CurvesGeometry::positions_for_write().

We need setters and getters for these two very commonly accessed attributes of grease pencil. The code is based on the implementation of `CurvesGeometry::positions()` and `CurvesGeometry::positions_for_write()`.
Amélie Fondevilla added 1 commit 2023-07-05 12:15:44 +02:00
Amélie Fondevilla changed title from Add getters and setters for opacity and radius of a grease pencil drawing to GPv3 : Add getters and setters for opacity and radius of a grease pencil drawing 2023-07-05 12:15:56 +02:00
Amélie Fondevilla added this to the Grease Pencil project 2023-07-05 12:16:04 +02:00
Author
Member

Although, we needed to copy/paste the functions get_span_attribute, get_mutable_attribute, domain_num, domain_custom_data that are only defined in curves_geometry.cc and not visible from the API.
Is that ok, or should we make these functions visibles instead ?

Although, we needed to copy/paste the functions `get_span_attribute`, `get_mutable_attribute`, `domain_num`, `domain_custom_data` that are only defined in `curves_geometry.cc` and not visible from the API. Is that ok, or should we make these functions visibles instead ?
Amélie Fondevilla requested review from Hans Goudey 2023-07-05 12:21:22 +02:00
Amélie Fondevilla added 1 commit 2023-07-05 12:23:40 +02:00

Make domain_num, domain_custom_data, domain_custom_data functions through a switch. This should return 0 for an unsupported domains. Now it will be the size of the curves, which is not always correct.. This may not work correctly if used in conjunction with other attribute components in geometry processing code.
Also, make sure you don't use C-cast (https://wiki.blender.org/wiki/Style_Guide/C_Cpp).

Make `domain_num`, `domain_custom_data`, `domain_custom_data` functions through a switch. This should return 0 for an unsupported domains. Now it will be the size of the curves, which is not always correct.. This may not work correctly if used in conjunction with other attribute components in geometry processing code. Also, make sure you don't use C-cast (https://wiki.blender.org/wiki/Style_Guide/C_Cpp).
Member

The radii accessor makes just as much sense on the base CurvesGeometry class. We didn't add it yet though because unfortunately different code uses different defaults when the radii don't exist, this hasn't been standardized yet.

Maybe you could add an example of before and after?

The following isn't too bad when you get used to it IMO. But I understand the reasoning for avoiding writing it.
const VArray<float> opacity = *attributes.lookup_default<float>("opacity", ATTR_DOMAIN_POINT);

The radii accessor makes just as much sense on the base `CurvesGeometry` class. We didn't add it yet though because unfortunately different code uses different defaults when the radii don't exist, this hasn't been standardized yet. Maybe you could add an example of before and after? The following isn't too bad when you get used to it IMO. But I understand the reasoning for avoiding writing it. `const VArray<float> opacity = *attributes.lookup_default<float>("opacity", ATTR_DOMAIN_POINT);`
Member

@HooglyBoogly For the radii default value, I'm wondering if it would make sense to have a parameter in the function with a sensible default value. E.g. something like Span<float> radii(float default_radius = 1.0f) const;. So you can still just call curves.radii().

@HooglyBoogly For the radii default value, I'm wondering if it would make sense to have a parameter in the function with a sensible default value. E.g. something like `Span<float> radii(float default_radius = 1.0f) const;`. So you can still just call `curves.radii()`.
Member

Maybe you could add an example of before and after?

I'd like to have those function on the drawing, because opacity should really be a default attribute. And it's nice to not have to think about how the attribute is spelled, what the default should be etc.

> Maybe you could add an example of before and after? I'd like to have those function on the drawing, because `opacity` should really be a default attribute. And it's nice to not have to think about how the attribute is spelled, what the default should be etc.
Member

The idea behind unifying the radius attribute was that every place shouldn't have to manage its own default. But that is a bit tricky since it may not be intuitive for the curve to mesh node main input, for example. I still think its worth exploring though.

What do you mean by "default attribute"? Makes sense though!

The idea behind unifying the radius attribute was that every place shouldn't have to manage its own default. But that is a bit tricky since it may not be intuitive for the curve to mesh node main input, for example. I still think its worth exploring though. What do you mean by "default attribute"? Makes sense though!
Member

@HooglyBoogly Something that we expect every stroke to have.

@HooglyBoogly Something that we expect every stroke to have.
Member

@HooglyBoogly Something that we expect every stroke to have.

That seems a bit vague to me honestly, maybe it can be "expected" but code still has to handle the case where it doesn't exist, in which case the default should probably be 1.0, right? If so, the opacities() function should return a single-value virtual array.

> @HooglyBoogly Something that we expect every stroke to have. That seems a bit vague to me honestly, maybe it can be "expected" but code still has to handle the case where it doesn't exist, in which case the default should probably be 1.0, right? If so, the `opacities()` function should return a single-value virtual array.
Member

@HooglyBoogly Ok I see. Yes, we should instead use what CurvesGeometry is using now: get_varray_attribute. And the _for_write() functions can stay the same I think?

@HooglyBoogly Ok I see. Yes, we should instead use what `CurvesGeometry` is using now: `get_varray_attribute`. And the `_for_write()` functions can stay the same I think?
Hans Goudey changed title from GPv3 : Add getters and setters for opacity and radius of a grease pencil drawing to GPv3: Add getters and setters for opacity and radius of a grease pencil drawing 2023-07-10 13:44:00 +02:00
Amélie Fondevilla added 1 commit 2023-07-10 15:11:25 +02:00
Hans Goudey reviewed 2023-07-10 16:02:12 +02:00
@ -79,0 +81,4 @@
/**
* Per-point opacity value
*/
const VArray<float> opacities() const;
Member

Making a return value const when it's not a reference or a pointer doesn't have any effect. For example, you can still do this:

VArray<float> value = thing.opacities();
value = VArray<float>>::ForSingle(1,0.0f);
Making a return value `const` when it's not a reference or a pointer doesn't have any effect. For example, you can still do this: ``` VArray<float> value = thing.opacities(); value = VArray<float>>::ForSingle(1,0.0f); ```
filedescriptor marked this conversation as resolved
@ -79,0 +87,4 @@
/**
* Per-point radius value
*/
const VArray<float> radii() const;
Member

Hmm, my point with my comment about radii earlier is that we should wait to add this to CurvesGeometry directly when the current inconsistent situation is figured out.

Hmm, my point with my comment about radii earlier is that we should wait to add this to `CurvesGeometry` directly when the current inconsistent situation is figured out.
Member

Could we refactor that together with when that PR is happening?

Could we refactor that together with when that PR is happening?
Member

Sure, I guess that's fine too

Sure, I guess that's fine too
Author
Member

Yes, because we actually need that for the smoothing algorithm and we are gonna need it for further development in the next weeks.

Yes, because we actually need that for the smoothing algorithm and we are gonna need it for further development in the next weeks.
filedescriptor marked this conversation as resolved
Falk David added 2 commits 2023-07-11 10:48:10 +02:00
Falk David added 3 commits 2023-07-11 11:22:52 +02:00
Hans Goudey reviewed 2023-07-11 13:46:40 +02:00
Hans Goudey left a comment
Member

Would you consider using 0.01 for the default radius? That's the "most consistent" with curves, and it probably makes more sense at the scale most people work at anyway.

Would you consider using `0.01` for the default radius? That's the "most consistent" with curves, and it probably makes more sense at the scale most people work at anyway.
@ -78,1 +79,4 @@
void tag_positions_changed();
/**
* Per-point radius value.
Member

For these high-level doc strings, I'd suggest going beyond the bare minimum of documentation. For example-- "the radius is mainly used to determine the thickness of the stroke when rendering" or "how transparent each point is, also affecting the influence of the blah blah"

If there really is nothing more to add that's less basic, maybe that's fine, but it's nice to help out all future readers of this header file :)

For these high-level doc strings, I'd suggest going beyond the bare minimum of documentation. For example-- "the radius is mainly used to determine the thickness of the stroke when rendering" or "how transparent each point is, also affecting the influence of the blah blah" If there really is nothing more to add that's less basic, maybe that's fine, but it's nice to help out all future readers of this header file :)
filedescriptor marked this conversation as resolved
@ -346,1 +381,4 @@
VArray<float> Drawing::radii() const
{
return *strokes().attributes().lookup_or_default<float>(ATTR_RADIUS, ATTR_DOMAIN_POINT, 1.0f);
Member

this->strokes()

Generally class methods are referred to with that prefix.

`this->strokes()` Generally class methods are referred to with that prefix.
filedescriptor marked this conversation as resolved
Falk David added 3 commits 2023-07-11 14:26:01 +02:00

const int num = domain_num(curves, domain); -> curves.attributes().domain_size(domain)
const int num -> const int domain_size
MutableSpan<T> span = {data, num}; -> MutableSpan<T> values(data, num);
T *data = (T *)Cu.. -> T *data = static_cast<T *>(Cu
num > 0 really necessary?
span.first() != default_value why might this be so? There after all or garbage, or zeros?
template<typename T> static MutableSpan<T> get_mutable_attribute can be generic?

`const int num = domain_num(curves, domain);` -> `curves.attributes().domain_size(domain)` `const int num` -> `const int domain_size` `MutableSpan<T> span = {data, num};` -> `MutableSpan<T> values(data, num);` `T *data = (T *)Cu..` -> `T *data = static_cast<T *>(Cu` `num > 0` really necessary? `span.first() != default_value` why might this be so? There after all or garbage, or zeros? `template<typename T> static MutableSpan<T> get_mutable_attribute` can be generic?
Member

@mod_moder I appreciate the feedback, but it would be nice if you could add these comments to the lines in the diff.

@mod_moder I appreciate the feedback, but it would be nice if you could add these comments to the lines in the diff.

@filedescriptor After issuecomment i'm trying to be more careful in this part

@filedescriptor After [issuecomment](https://projects.blender.org/blender/blender/pulls/109405#issuecomment-968538) i'm trying to be more careful in this part
Member

@mod_moder Right, you can use the Start Review button instead of adding single comments, to bunch them all up into one.

@mod_moder Right, you can use the `Start Review` button instead of adding single comments, to bunch them all up into one.
Hans Goudey approved these changes 2023-07-11 14:50:10 +02:00
Hans Goudey left a comment
Member

Noted one mistake inline, other than that looks good. Some of Iliya's comments are reasonable too, though I understand this code is a copy & paste so that could be handled separately.

Noted one mistake inline, other than that looks good. Some of Iliya's comments are reasonable too, though I understand this code is a copy & paste so that could be handled separately.
@ -347,0 +386,4 @@
MutableSpan<float> Drawing::radii_for_write()
{
return get_mutable_attribute<float>(this->geometry.wrap(), ATTR_DOMAIN_POINT, ATTR_RADIUS);
Member

specify the default value here too

specify the default value here too
filedescriptor marked this conversation as resolved
Hans Goudey changed title from GPv3: Add getters and setters for opacity and radius of a grease pencil drawing to GPv3: Add access functions for opacity and radius attributes 2023-07-11 14:50:40 +02:00
Falk David added 1 commit 2023-07-11 14:56:41 +02:00
Falk David merged commit f2d3d321bb into main 2023-07-11 15:11:21 +02:00
Falk David deleted branch gpv3-attributes-api 2023-07-11 15:11:22 +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#109733
No description provided.