I suspect the Stock Lens Matching tool does not test the stock lenses twice (both direct and flipped). Can you confirm this?
I'm testing on a finite-conjugates system with two cemented doublets and it looks like the best result is not following the symmetry principle. Indeed, when I flip the first doublet I can reach far better results.
I strongly support this feature testing both orientations. By the way, I had requested that option years ago.
Excellent point Alberto, I'd also like to support this feature.
Cheers,
David
I also support this. I don't believe the stock lens matching tool is useful without trying both orientations.
Thank you for your comments. This is actually a good point and I have checked and it is logged as a feature request on our side. I will bring it to the attention of the product team.
Hi everyone,
This tool is invaluable in my work and I couldn't bear with it :p
Please find a ZOS-API implementation of the SLM tool that supports element reversal at this GitHUB repository. Few things to note:
- It is still in development (by myself in my free time...)
- Read the installation instructions carefully
- It has very little error handling, and is significantly slower than the native version
- I'm still unsure how the standard SLM tool works, so I'm not able to reliably reproduce its results
- I'm happy to hear your comments and make improvements to this tool if time permits
- The progress bar isn't really good because I don't know how to make it progress linearly for an unkown number of iterations (which depends on the number of lenses that are found in the catalogs)
That being said, it seems to work for me, but I don't want to take any responsibility for the results of this user-extension.
Let me know what you think.
Take care,
David
Hi everyone,
I fixed a bug in the tool that prevented the use of “variable-only” lenses, and I realized that when a matched lens Merit Function can’t be calculated, the returned MF value is zero in the ZOS-API. I’ve decided to discard those lenses, but this also means I’m discarding legitimate lenses that would produce a MF value of zero (highly unlikely).
Let me know if any of you has had the time to checkout this tool.
Take care,
David
I requested having the stock lens reversal feature years ago, and to date it still hasn’t been implemented. Someone on staff said they logged it as an action way back then. Sorry Sandrine, I know you mean well, but among us longtime users, “logged as a feature request” has become synonymous with “if we ignore it long enough maybe it will just go away”. We really wish Zemax developers would put a little more effort into responding to our requests as they also add new features.
So for what it’s worth I too, once again, add my vote for making the Stock Lens utility try both directions.
Mike
Hi
Can I ask you if you have some example files that I could try with my ZOS-API implementation of the stock lens matching reversal tool?
Take care,
David
Can this API consider the situation, that use the doublet or triplet to replace one singlet lens?
I also have an idea for the reverse lens.
In the Lens Catalog, we can choose the lens we like first, and load, and save as a zmx file. Then reverse the lens and save as a second lens file. We need to use API to do it.
And then we save all lens file in a folder and use the Make Private Catalog to convert the folder as a catalog. When we use the SLM tool, we can directly select the catalog we made. How about this idea?
Thank you!
Currently, the ZOSAPI solution does not try to replace a doublet or a triplet by an equivalent singlet, but this should not be too difficult to implement.
I really like the private catalog idea. Do you think that saving only those lenses that we are interested in might be faster than browsing through all the catalogs? One issue I have in this regards, and that you could relay to the developers, is that it is not possible to search the Lens Catalog for a specific lens. Imagine I know exactly what lens I want to insert from the catalog, say THORLABS AC254-30-C EFL for example. How do you search it in the Lens Catalog? I don’t think you currently can. Therefore, you need to search the whole catalog, and narrow it down to the parameters of the lens you are searching for, in this case a doublet from THORLABS with EPD of about 25 mm, and EFL of about 30 mm, (let me know if this makes sense).
I’m currently working on having the settings in a window like a normal analysis with the help of
Take good care of yourself,
David
Hi
Yes, I’m also asking developers to confirm what the SLM exactly do. I will reply it after I clear.
Regarding to the point you said “ it is not possible to search the Lens Catalog for a specific lens for SLM”, this is also the purpose why I said we can save the lens you like in a private catalog first. If you want to only search some specific lens in SLM, you can made them as a catalog first. And you can use the SLM to search only this catalog you assigned.
Maybe we can use API to automatically make a new catalog after we input some condition we set. Just an idea.
I’m really very happy to discuss with you here. Hope everything goes well.
Regards,
Yihua
Hi David,
Yihua had a discussion with the developers and at the moment the Stock Lens Matching tool looks at the
the shape factor. The shape factor describes the shape of the lens with values from of -2 to +2. The sign of the shape factor is based upon the orientation of the lens with respect to the object being imaged :
where C = 1/R is the curvature of the lens face.
Below are given some shape factors:
So OpticStudio tests if a singlet stock lens will be flipped by calculating the product of the lens shape factor in the original design and the stock lens shape factor. If the product is negative, then the two shape factors have a different sign and OpticStudio will flip the stock lens.
So for example below is an optical system:
OpticStudio finds the following stock lens:
OpticStudio will flip the stock lens to fit the shape factor of the original design:
What the software doesn’t do for now is change the shape factor of the original design.
Hi
Here is some explanation from development team.
The shape factor definition is different from my previous picture.
------------------------------------------------------------------
In the stock lens matching tool, we use the following shape factor:
where C = 1/R is the curvature of the lens face.
The test we make to determine if a singlet stock lens will be flipped is whether the product of the lens shape and the stock shape is less than zero. If that product is negative, that means the two shape factors have a different sign. If the original lens shape factor is exactly zero, the lens matching algorithm will not flip the stock lens.
Hi
Thank you for the clarification. It makes a lot of sense. I had observed that the stock lens matching tool was sometimes finding the right orientation of matched lenses, but not always.
I have the GUI version of the code ready, but I am not able to make a terminate button in case the user wants to cancel the tool before it finishes completion (because it is quite slow). I am using C# and CancellationTokenSource, do you know if this would work through the ZOS-API? I’m not too familiar with C# and tasks, any help would be appreciated.
Take care you two.
David
Hey David! I’m not sure so I’ll check.
Hi David!
I have reached out to Michael H and here is his reply:
There are many ways to terminate a C# script. However, except for the Terminate() method on a User Analysis (which attempts to call the same terminate function for a native analysis), there is no built-in way of terminating a script. A few recommendations would be:
- Attempt to make the code multithreaded so the GUI and the actual calculations are run on separate threads
- The GUI always has to run on the main thread in C#, so all the calculations should be called from a child thread
- For long running calculations, either use a while loop which is defaulted to true but checks if a user clicks a terminate button, which would then which the while statement to false
- Alternatively, if you’re using a for loop, then you can check for the terminate boolean either every loop or every X number of loops by using a modulus operator on the index (i.e., if (i % 5 == 0){} would enter the if statement every fifth loop)
I have attached a very simple example which illustrates how to do this.
Michael sent his answer before looking at the code so he was not sure that this would be along the lines of what you are looking for.
Let us know if that helps and we can look into this further if needed.
Hi
Don’t worry, I managed to do it with CancellationTokenSource. I’ll share the new code soon. Do you know if it is possible to run a User Analysis from the ZOS-API? I’m asking because I want to display the text-file results in OpticStudio, and the way I do it currently is through a User Analysis, but I have to run it manually.
Thanks for your help, and take care,
David
Hi Everyone,
Here are two new repositories that implement the previous Reverse SLM tool with a graphical user interface.
Display Reverse SLM into OpticStudio
The first repository has the User Extension, which should now look like that:
and the second repository is a User Analysis that can be run once the matching is complete. It opens the text file, provided it is still in the same folder as the lens file, within OpticStudio. This is how it looks like with the Petzval0 sample file (found in the repository).
Note that the Terminate button on the Running Extension window doesn’t work anymore. Instead you are supposed to use Terminate from the Reverse SLM button.
I am next going to work on what was discussed with
Let me know if this works for you, and if you’ve encountered any bugs.
Take care,
David
Hi
I’ve made a small step in the direction you suggested. The GUI has another checkbox now to ignore the element count in the nominal lenses. Basically, if this option is checked, the tool will try to match catalog lenses with ANY number of elements. It seems to work on simple examples on my end. The big issue that I foresee is that if you have Merit Function operands that depend on specific surface numbers, those numbers might go all over the place because we potentially add an arbitrary number of elements. I will work on studying this, and potentially fix it. In the meantime, always check the results to see if they make sense, particularly the Merit Function.
Take care,
David
Hi
For the problem of Merit Function operands that depend on specific surface numbers, I don’t think it’s a problem if you delete DMFS operant.
I made a short video to show if you add or delete surfaces, the operands depend on specific surface numbers will also automatically changed.
https://zemax-my.sharepoint.com/:v:/p/hsiao/Ef-yGabiWjdFvDdOJCYAxFEBxUa8PX3kc1yqOqopJqvr3w?e=dWdyii
Maybe I don’t fully understand your question, could you please give me some examples?
Thank you!
Hi
Thank you for the video, it is exactly what I was talking about. I have made a modification to the code, which removes the DMFS operand from the Merit Function (it prints a warning in the text file). There is still at least one issue, that I will demonstrate below with a new example: PlanoConvexSinglet2.ZOS (attached to this post).
If one runs the latest version of the reverse SLM tool on the aforementioned example, and the following settings:
One would get the following results:
And the best match:
The only issue is that because the singlet has been replaced by a doublet, the thickness tolerances are absent for Surface 4. I’m not sure how to fix this issue properly yet. Any idea is appreciated.
Take care,
David
If there is a symmetry system as blow pictures, that is, the right side doublet is totally picked up from the left hand side doublet, it’s better to consider this pick up to save the optimization time and ensure the two doublets are the same after taking SLM.
Below is the comparison between the build-in SLM and your Extension.
A) The original file in Zemax. The left lens and the right lens are the same in pickup.
B) Run the OpticStudio build-in SLM.
The result is as expected. If you look closely, you can see that the first doublet appears to be inverted.
C) Run David's Extension.
Pickup is not working, and group 1 and group 2 are different.
Also, if you look closely, you can see that the doublet of group 1 is a little bit wired.
The original file is as attachment.
Again, SONY expresses great pleasure in seeing this tool and would be happy to help you test various conditions and provide suggestions. Thank you again for your efforts!
Hi
Thank you so much for sharing all these pieces of information.
First, when I kept DMFS in the file, I ended up with the same Merit Function actually.
There were a couple of issues in the code that I’ve fixed:
- I had not considered the case of a lens with two consecutive elements of the same material
- Pickups are removed when I erase a lens to place a catalog lens, and I was not putting the pickups back to where they were. It should now work for Radius, Thickness, and Material surface pickup
If they try running the code on their file again, it should work better. The only thing I haven’t tested is the new ignore number of elements feature on their file, because it could mess with the pick-ups actually. Say the first doublet is replaced with a triplet, do we still want to pickup from the same doublet surfaces in the triplet? Does my question make sense?
Take care,
David
Reply
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.