Robust 'Curve Boolean' using Region Difference and Region Intersection

I am currently creating a topographic terrain curve generator for laser cut architectural models.

The Inputs are:

XYZ Points
Boundary Geometry (to define the region that will be contoured - the model will likely be smaller than the full XYZ document)
Contour Height (defined by the sheets which will be laser cut)

It is important that the ‘visible surfaces’ of the model can be selected so building or street outlines/names etc. can be projected onto them. This terrain model photo is a good example of what I am trying to achieve with engraving.

The output will be:

Closed Curves (often multiple) for each layer for laser cutting
Curves on another layer with the projected engraving needs.

Open Nest will then be used to create a fully automated laser ready document.

Problem (Selecting the ‘correct’ visible surfaces using Region Difference and Region Intersection):

Given the vast array of different possibilities that arise with different XYZ Points I am yet to find a solution to ‘selecting’ the correct ‘visible surfaces’ shown here in colour in my explanation photo. For example: the visible surface 0 is a Region Difference between the closed curves from Contour level 1 and Contour level 0.

The visible surface #6 is the Region Intersection between Contour Level 6 and Contour Level 5. Singular Elevations can appear at any height in a XYZ document and may not be at the highest height in the data and it may be a singular ‘mountaintop’ and within the same data also another curve at the same level which is also a Region Intersection. That means I cannot simply take the heights points.

I would greatly appreciate if anyone could give me some assistance in how I can move forward with this script and also any other tips in regards to streamlining my script are also welcome!

Thanks in advance.
Terrain_contour_surfaces.gh (132.7 KB)

I think, I could solve the Region Difference, have a look. The path-structure is maintained. Since the surfaces are ordered, the top-surface will allways be visible, so there is no processing required.
RE Terrain_contour_surfaces.gh (130.9 KB)

Hey @ferry59

Thank you for the quick and clever response! Your solution really solves the visible surface problem! I greatly appreciate it!

I just tested it and the surfaces work perfectly but I am unable to get the curves I wish to project for example here it is now projecting all the necessary lines onto two surfaces that are on one level on the level 2 (orange level)

I’ll keep looking to see if I can find the solution but if you know what it is, I’d love to hear it!

Nevermind I just had to graft the sorted contour curves. Thank you! All solved!