Skip to content

Feat: User defined line segments filters#699

Draft
EtienneParmentier wants to merge 2 commits into
epezent:masterfrom
EtienneParmentier:user-defined-line-segments-filters
Draft

Feat: User defined line segments filters#699
EtienneParmentier wants to merge 2 commits into
epezent:masterfrom
EtienneParmentier:user-defined-line-segments-filters

Conversation

@EtienneParmentier

Copy link
Copy Markdown

Solves #698 .
Here is a picture to be more explicit:
Capture d’écran 2026-04-23 173235
I have not tested all flags combination, I believe adding an example in the demo would help ?
Also I have no idea what to do with markers since their are not line segments, should we tell the user with an assert ?

@EtienneParmentier EtienneParmentier marked this pull request as draft April 23, 2026 15:41
@EtienneParmentier EtienneParmentier marked this pull request as ready for review April 28, 2026 13:19
@brenocq

brenocq commented Jun 2, 2026

Copy link
Copy Markdown
Collaborator

Hi @EtienneParmentier — thanks a lot for the contribution, and for taking the time to write up a clear issue and a working prototype! It's great to see you getting comfortable navigating the ImPlot internals, and I hope you'll stick around to help develop new features down the line. 🙂

That said, I don't think this filtering belongs in ImPlot itself. We try to keep the ImPlot API as small and focused as possible, and extensions that are specific to a particular application are generally better handled on the user side. Segment filtering falls into that category.

The good news is your use case is already fully achievable with the current API. PlotLine renders a NaN point as a gap by default (ImPlotLineFlags_SkipNaN is actually the flag to opt out of that). So you can break the line exactly where you want by inserting a NaN between the points — for your oscilloscope, wherever the phase resets:

// Rebuild only when the waveform changes, not every frame:
std::vector<ImPlotPoint> display;
display.reserve(N + 64);
for (int i = 0; i < N; ++i) {
    if (i > 0 && raw[i].x < raw[i-1].x)   // phase reset -> break the line here
        display.push_back({ NAN, NAN });
    display.push_back(raw[i]);
}

// Each frame — plain PlotLine, do NOT set SkipNaN:
ImPlot::PlotLine("signal", &display[0].x, &display[0].y,
                 (int)display.size(), 0, 0, sizeof(ImPlotPoint));

If you'd rather not keep a second buffer, the same idea works with PlotLineG by returning a NaN point for the break slots.

Let me know if this works for your application! And thanks again for the effort — really appreciate it.

@brenocq brenocq added type:feat New feature or request prio:medium Medium priority status:review The task is under review labels Jun 2, 2026
@brenocq brenocq changed the title [DRAFT] User defined line segments filters Feat: User defined line segments filters Jun 2, 2026
@brenocq brenocq marked this pull request as draft June 2, 2026 05:33
@EtienneParmentier

Copy link
Copy Markdown
Author

Thanks for your help ! You have guessed my intent: providing a way to filter on the fly (without allocating). I honestly didn't thought about re-purposing the nan filters. However I believe I can solve the non allocating property by moving the nan insertion elsewhere in the code: I have to copy the data between two buffers at some point, so adding the null insertion code there would solve my line segment problems and my zero allocation requirements.

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

Labels

prio:medium Medium priority status:review The task is under review type:feat New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants