Skip to content

[CURA-12961] Spike to add auto-brim option; DRAFT!#2320

Draft
rburema wants to merge 7 commits intomainfrom
CURA-12961_auto_brim_spike
Draft

[CURA-12961] Spike to add auto-brim option; DRAFT!#2320
rburema wants to merge 7 commits intomainfrom
CURA-12961_auto_brim_spike

Conversation

@rburema
Copy link
Copy Markdown
Member

@rburema rburema commented Apr 9, 2026

Very W.I.P. part of a spike to investigate whether we can actually automatically detect brim-width / basis for discussion.

Largely copied from other (open) sources (then heavily rewritten) at the moment.

To run from the front-end, use this PR: Ultimaker/Cura#21531

rburema and others added 6 commits April 7, 2026 09:52
Let's see if we can drag this potentially useful feature to Cura as well ;-) (rewrite from stuff in Orca; they've got more than enough of our source in their thing without any attribution more extensive than I did here and in the comment, so aparently it's fine :-p).

So far, it seems to spit out figures within the realm of reasonability, though you have to make the model really long and thin for it to split out anything above the minimum threshold of 5mm.

part of investigation spike CURA-12961
The normal one should work, even though it's way larger, since these are areas measured in square micron, and our own epsilon value is for muicron values.

done as part of CURA-12961
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 9, 2026

Test Results

0 tests   - 31   0 ✅  - 30   0s ⏱️ -4s
0 suites  -  1   0 💤 ± 0 
0 files    -  1   0 ❌  -  1 

Results for commit 35a9f8e. ± Comparison against base commit 8dd7956.

♻️ This comment has been updated with latest results.

Copy link
Copy Markdown
Contributor

@wawanbreton wawanbreton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code is a bit drafty as advertised, but overall looks good. Also you are slightly abusing std::accumulate 😛

Comment thread src/SkirtBrim.cpp
return all_brim_offsets;
}

void computeOverSegments(const Polygon& poly, const std::function<void(const Point2F&, const Point2F&)>& func)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it make sense that this function is a method of the Polygon class (or even Polyline) ?
Also maybe with a more explicit naming.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes and yes -- I wanted to have it self-contained for the spike, but we can move anything that is accepted to polygon/-line.

Any proposal for the name?

Comment thread src/SkirtBrim.cpp
}
}

bool compShapeProperties(const Shape& polys, Point2F& total_centroid, Point2F& total_moment)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe move to Shape or LinearAlg2D ?

Comment thread src/SkirtBrim.cpp Outdated
Comment thread src/SkirtBrim.cpp
Comment thread src/SkirtBrim.cpp
{
return std::max(value, static_cast<float>(mesh.settings_.get<coord_t>(setting_name.data())));
});
});
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using accumulate in this case is quite confusing 🤔 could you use ranges::max_element instead, with a projection function ?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I was trying to find that function 2 weeks ago. Yes, we should use that instead.

Comment thread src/SkirtBrim.cpp
AABB3D(),
[](const AABB3D& aabb, const Mesh& mesh)
{
return AABB3D(mesh.getAABB()).include(aabb);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As far as I can see, mesh.getAABB() return a AABB3D, so why the conversion ?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that might just be a leftover from when I had written something else there instead.

Comment thread src/SkirtBrim.cpp Outdated
Comment thread src/SkirtBrim.cpp Outdated
Comment thread src/SkirtBrim.cpp
// Calculate the result.
constexpr float height_to_area_normalization = 1920.0f;
const float height_to_area
= std::max(max_height / second_moment.x_ * INT2MM(width_depth.y_), max_height / second_moment.y_ * INT2MM(width_depth.x_)) * max_height / height_to_area_normalization;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can either second_moment.x_ or second_moment.y_ be null anyhow ?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, I think we should guard against that in any case. But that would be an object that'd require an infinitely large brim then 😄

I think I see another (small) division by zero potential in the accumulate_areas above as well now that you've pointed out this one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants