Antialiasing for custom graphs

First off, I'm not sure if what I'm asking can be accomplished within juce or if I have to roll my own algorithm. Either way, I'd appreciate any pointers since I've seen many juce UIs that seem to have tackled this.

I'm working on a general purpose graph display/breakpoint editor that can display arbitrary functions. That means I can't use a Path to draw the graph. Instead, what I'm currently doing is to compute the y-value for each x-coordinate of the component and then color that (x,y) coordinate. That works fine except that the resulting graph is obviously jagged and not smooth. So what I'm looking for is a way to draw smooth and antialiased curves, similar to e.g. the EQ curves of some more recent audio plugins (fabfilter and EQuick come to mind). 

One easy way is to draw the function at 4x resolution (without antialiasing) and then scale it down to 1x resolution.

1 Like

If you have a single y value per x value, then why can't you use a Path? It's just a series of connected lines, right? That's the normal way to draw something like an EQ curve or a zoomed-in waveform.

I did it the way that jules suggests. You can also use this to adjust some adaptive "level of detail" in case your function is dificult to calculate in real time. Say you have some slower notebook - you can set it to calculate just every third x coordinate, which makes you graph a little bit jagged, but still usable.


Another approach would be to draw some small gaussian mask instead of a single point. But that might be somewhat more expensive...

Wow, I feel stupid. Never occured to me to simply use a Path to connect the dots. I only thought of using Path in the context of approximating graphs with Bezier curves -- which of course doesn't work for arbitrary graphs.

In the meantime, I ended up reinventing (or rather reimplementing) the wheel by using Wu's antialiasing algorithm. For anybody who's interested, this paper was quite helpful in getting me started: