Feat: User defined line segments filters#699
Conversation
|
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. // 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 Let me know if this works for your application! And thanks again for the effort — really appreciate it. |
|
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. |
Solves #698 .

Here is a picture to be more explicit:
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 ?