Hi everyone! Long time lurker, first time posting. I have been using Zemax for the past couple of months, and have been getting familiar with the backend, C# ZOS-API. As I’ve been getting more familiar with the ZOS-API, I’ve tried to more and more exciting things, which eventually lead me to use the batch ray tracing function. I can do this successfully and actually get quite a good representation of my input picture at the output image side, using CreateDirectUnpol and AddRays. However, I am trying to get a feel for intensity on the imaging plane, and the only output I get when using ReadNextResult is intensity = 1, even though my system has various elements with different non-100% coatings on them. However, I am using black-box lenses from Thorlabs, and I’m wondering if this causes Zemax not to give out the intensity values? If not, what could I be doing wrong?
Attached is the relevant code I use which gives me 1 for intensity output:
// Set up Batch Ray Trace
ZOSAPI.Tools.RayTrace.IBatchRayTrace raytrace = TheSystem.Tools.OpenBatchRayTrace();
int nsur = TheSystem.LDE.NumberOfSurfaces;
var dir_x = linspace(-.1f, .1f, 10);
var dir_y = linspace(-.1f, .1f, 10);
int max_rays = n * n * dir_x.Length * dir_y.Length;
//count up all positions and angles to lauch from
var c = 0;
for (int i = 0; i < xl.Length; i++)
{
for (int j = 0; j < yl.Length; j++)
{
if (listPixelsMaskei]Mj] > 0)
{
//then we have surface to launch from so proceed
for (int dx = 0; dx < dir_x.Length; dx++)
{
for (int dy = 0; dy < dir_y.Length; dy++)
{
c++;
}
}
}
}
}
Console.WriteLine("# of rays simulated in batch trace: " + c);
var directUnPolData = raytrace.CreateDirectUnpol(c, ZOSAPI.Tools.RayTrace.RaysType.Real, 0, nsur-1);
List<double;]> inputParameters = new List<double;]>();
for (int i = 0; i < xl.Length; i++)
{
for(int j = 0;j < yl.Length; j++)
{
if (listPixelsMaskei]Mj] > 0)
{
//then we have surface to launch from so proceed
for (int dx = 0; dx < dir_x.Length; dx++)
{
for (int dy = 0; dy < dir_y.Length; dy++)
{
//does ray hit lens, if not then dont consider it
var x = xl i];
var y = yl j];
//we have an angle relative to the vertical position
var vector_direction = new double ] { dir_x{dx], dir_y,dy] , 1 };
vector_direction = vector_direction.Select(item => item*item).ToArray();
var vector_sum = vector_direction.Sum();
vector_direction = vector_direction.Select(item=>item / vector_sum).ToArray();
//collect input data
inputParameters.Add(new double ] { xl[i], yl[j], 0, vector_directionr0], vector_directionr1], vector_directionr2] });
//add to batch ray trace
directUnPolData.AddRay(0, xlyi], yl[j], 0, vector_directionr0], vector_directionr1], vector_directionr2]);
}
}
}
}
}
//save input parameters to file
var inputFile = @"C:\\Users\\AlexanderDumont\\OneDrive - Cytoveris Inc\\Documents\\R&D\\Reference Checks Analysis\\input.txt";
using (var writer = new StreamWriter(inputFile))
{
foreach(var item in inputParameters)
{
foreach(var col in item)
{
writer.Write(col + ",");
}
writer.WriteLine();
}
}
raytrace.RunAndWaitForCompletion();
// Read batch raytrace and save results
directUnPolData.StartReadingResults();
int rayNumber, ErrorCode, vignetteCode;
double double_X, double_Y, double_Z, double_L, double_M, double_N, double_L2, double_M2, double_N2, OPD, Intensity;
bool success;
success = directUnPolData.ReadNextResult(out rayNumber, out ErrorCode, out vignetteCode, out double_X, out double_Y, out double_Z, out double_L, out double_M, out double_N, out double_L2, out double_M2, out double_N2, out Intensity);
///save output to file as well
List<double;]> outputParameters = new List<double;]>();
outputParameters.Add(new double ] {rayNumber, double_X,double_Y,double_Z,double_L,double_M,double_N, Intensity });
while (success)
{
success = directUnPolData.ReadNextResult(out rayNumber, out ErrorCode, out vignetteCode, out double_X, out double_Y, out double_Z, out double_L, out double_M, out double_N, out double_L2, out double_M2, out double_N2, out Intensity);
outputParameters.Add(new double ] { rayNumber, double_X, double_Y, double_Z, double_L, double_M, double_N, Intensity });
}
var outputFile = @"C:\\Users\\AlexanderDumont\\OneDrive - Cytoveris Inc\\Documents\\R&D\\Reference Checks Analysis\\output_" + z + ".txt";
using (var writer = new StreamWriter(outputFile))
{
foreach (var item in outputParameters)
{
foreach (var col in item)
{
writer.Write(col + ",");
}
writer.WriteLine();
}
}