Fly wing with different focal planes using Zeta 3D optical profilometer
Focus detection works much like how we see the world. The instrument determines what is in focus and what is out of focus by looking for sharp contrasts. Areas with sharp contrast are deemed in focus, and by knowing this focal length of the optics you can determine the distance. This generally works by scanning the optics in the Z direction and using the camera in order to create a three dimensional volume of data. After the data is acquired, the parts that are out of focus are cut out and you are left with a representation of the surface of the sample.
This technique can also be performed by using a zoom microscope with a variable focus to create the volume. This technique is generally simpler with less resolution at a lower cost. By using regular microscope objectives and precision Z movements, the X, Y and Z resolution can be greatly enhanced; the resolution is still lower than confocal or interferometry instruments.