I found this article among the most helpful to wrap my head around implementing this: https://www.mattkeeter.com/projects/contours/
I had to dig further and read some papers, but that was a great starting point.