Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
79 commits
Select commit Hold shift + click to select a range
eff1af4
MC: start of integration with ray tracing output
hayakawa16 Mar 13, 2021
b9d3309
MC: determined format of ZRD uncompressed file and was able to read i…
hayakawa16 Mar 13, 2021
ae70e58
MC: started working on source classes that will use ray database.
hayakawa16 Mar 14, 2021
cf45185
Merge branch 'master' into ch-210312-raytrace-MC
hayakawa16 Mar 15, 2021
f3f39cc
Merge branch 'master' into ch-210312-raytrace-MC
hayakawa16 Mar 15, 2021
5f34b3b
Merge branch 'master' into ch-210312-raytrace-MC
hayakawa16 Apr 22, 2021
45d1c57
RayTrace: added links to Desktop that were missing.
hayakawa16 Apr 22, 2021
fbb220b
Merge branch 'master' into ch-210312-raytrace-MC
hayakawa16 Apr 23, 2021
4dd7232
Wrote code to write the ZRDRayDataPoints to a ZRD binary file. Added…
hayakawa16 Apr 24, 2021
ca98fec
Attempt at moving code that read and wrote ZRD file from ZRDRayDataba…
hayakawa16 Apr 25, 2021
50d435c
Added unit test to verify results from FromFileSource.GetNextPhoton.
hayakawa16 Apr 25, 2021
69797fe
The code now reads and write to a ZRD file *using* established code c…
hayakawa16 Apr 26, 2021
da5ff75
Modifications to specify ZRDFileSource in SimulationInput and for the…
hayakawa16 Apr 27, 2021
e1b5165
Corrected code by writing *two* ZRDRayDataPoints to match Zemax outpu…
hayakawa16 May 17, 2021
2bc2f18
Merge branch 'master' into ch-210312-raytrace-MC
hayakawa16 May 21, 2021
45788e9
Merge branch 'master' into ch-210312-raytrace-MC
hayakawa16 Jun 23, 2021
18548fa
Merge branch 'master' into ch-210312-raytrace-MC
hayakawa16 Jul 22, 2021
9085a13
Found straggler file from merging master into branch. Unit test that…
hayakawa16 Jul 22, 2021
f7cc2d1
Merge branch 'master' into ch-210312-raytrace-MC
hayakawa16 Aug 11, 2021
59c1b95
Merge branch 'master' into ch-210312-raytrace-MC and resolved conflic…
hayakawa16 Dec 16, 2021
d29284e
Code cleanup. This could use some more, e.g. making public values pr…
hayakawa16 Dec 17, 2021
96bad29
Merge branch 'master' into ch-210312-raytrace-MC
hayakawa16 May 26, 2022
d55ba3f
Merge branch 'master' into ch-210312-raytrace-MC
hayakawa16 Jul 18, 2022
c976982
Redesign to write to intermediate MCCL ray database consisting of jus…
hayakawa16 Aug 8, 2022
d9c9d98
Now all unit tests pass except those for RayDatabase and ZRDRayDatabase.
hayakawa16 Aug 9, 2022
01f88ed
Start at creating app to convert ZRD ray database file to MCCL source…
hayakawa16 Aug 11, 2022
d461eb1
Created new app Vts.MonteCarlo.ZemaxDatabaseConverter app and Test pr…
hayakawa16 Aug 19, 2022
f1e55e7
Wrote initial unit tests for new Vts.MonteCarlo.ZemaxDatabaseConverte…
hayakawa16 Aug 20, 2022
2f41f85
Expanded unit tests. Problems: 1) Vts.MonteCarlo.ZemaxDatabaseConver…
hayakawa16 Aug 20, 2022
b38fdff
Updates to try to read actual ZRD database file working.
hayakawa16 Aug 23, 2022
9733318
Got code that converts Zemax ZRD file to MCCL database working. Need…
hayakawa16 Aug 24, 2022
ae772a2
Rename from ZRD to Zrd to be Pascal type. Windows did not catch file…
hayakawa16 Aug 25, 2022
e139a45
Rename files from ZRD... to Zrd... Had to do this on Linux because W…
hayakawa16 Aug 25, 2022
4ede536
When I pushed from Linux, the release folder got pushed. I am deleti…
hayakawa16 Aug 25, 2022
b1b4e1c
Merge branch 'master' into ch-210312-raytrace-MC and resolved conflicts
hayakawa16 Aug 25, 2022
c882384
Created new Vts.Zemax library and moved classes in Zemax folder of Vt…
hayakawa16 Aug 25, 2022
9244740
All folders back with correct files and all building currently.
hayakawa16 Aug 25, 2022
a1352bd
Still can't determine why unit tests pass individually but not in a r…
hayakawa16 Aug 26, 2022
ba3df7c
Added example infile in SimulationInputProvider to specify generation…
hayakawa16 Aug 26, 2022
d9bec5f
Renamed test file to add "s" at end. More code cleanup.
hayakawa16 Aug 26, 2022
c3adb4e
Merge branch 'master' into ch-210312-raytrace-MC
hayakawa16 Aug 29, 2022
3aa6bc6
Updates csproj files for Vts.Zemax, Vts.MonteCarlo.ZemaxDatabaseConve…
hayakawa16 Sep 1, 2022
536a4e7
Just edited to ease stepping through. Still 1 out of 3 tests failing…
hayakawa16 Sep 1, 2022
256a272
Updated NuGet packages and changed the Zemax library .NET version
Sep 16, 2022
3a5cbcd
Removed MCCL as a dependency from Vts.MonteCarlo.ZemaxDatabaseConvert…
hayakawa16 Sep 16, 2022
c6782fa
Merge branch 'master' into ch-210312-raytrace-MC
hayakawa16 Sep 19, 2022
81864ca
Removed obsolete projects that were removed before but returned somehow.
hayakawa16 Sep 19, 2022
fd62f7d
Removed obsolete project.
hayakawa16 Sep 19, 2022
df8ce54
DatabaseConverter: Moved enumerator out of writing loop because shoul…
hayakawa16 Sep 20, 2022
bf1429b
Cleaned up code in ZrdRayDataPointSerializer and coded up alternative…
hayakawa16 Sep 21, 2022
c9e98e0
Removed "static" from local variables in ZrdRayDataPointSerializer wh…
hayakawa16 Sep 26, 2022
0567ced
Unit test file cleanup fixes.
hayakawa16 Sep 27, 2022
f47e3b5
Final unit test clean up fix. Now no stragglers during unit tests in…
hayakawa16 Sep 27, 2022
603c34b
Initial clean up: 1) made properties out of fields in ZrdRayDataPoint…
hayakawa16 Oct 5, 2022
3eb364f
Some resharper code updates, corrected return values and code of Zema…
hayakawa16 Oct 14, 2022
e3dc309
More resharper suggested fixes.
hayakawa16 Oct 18, 2022
ca395bc
Merge branch 'master' into ch-210312-raytrace-MC, resolved conflicts …
hayakawa16 Oct 27, 2022
fa17825
Merge branch 'master' into ch-210312-raytrace-MC and resolved conflic…
hayakawa16 Dec 9, 2022
f2a3312
Merge branch 'master' into ch-210312-raytrace-MC and corrected confli…
hayakawa16 Dec 21, 2022
1efd7ca
Merge branch 'master' into ch-210312-raytrace-MC
hayakawa16 Feb 17, 2023
37c68ab
Merge branch 'master' into ch-210312-raytrace-MC
hayakawa16 Apr 14, 2023
62bc1ee
Merge branch 'master' into ch-210312-raytrace-MC
hayakawa16 May 31, 2023
b0691ae
Merge branch 'master' into ch-210312-raytrace-MC and corrected confli…
hayakawa16 Jun 15, 2023
6f9993e
Merge branch 'master' into ch-210312-raytrace-MC
hayakawa16 Jul 31, 2023
b535e3c
Merge branch 'master' into ch-210312-raytrace-MC resolved conflicts i…
lmalenfant Aug 24, 2023
10d9211
Merge branch 'master' into ch-210312-raytrace-MC and resolved conflic…
hayakawa16 Aug 31, 2023
1014917
Merge branch 'master' into ch-210312-raytrace-MC, resolved conflicts …
hayakawa16 Nov 3, 2023
2ac863a
Merge branch 'master' into ch-210312-raytrace-MC and resolved conflic…
hayakawa16 Jan 11, 2024
c359bc4
Merge branch 'master' into ch-210312-raytrace-MC
hayakawa16 Apr 17, 2024
b283a7c
Merge branch 'master' into ch-210312-raytrace-MC
hayakawa16 Aug 23, 2024
6dc4347
Merge branch 'master' into ch-210312-raytrace-MC
hayakawa16 Nov 7, 2024
9ee0479
Updated to .NET 8 in csproj files.
hayakawa16 Nov 7, 2024
8325384
Merge branch 'master' into ch-210312-raytrace-MC and resolved conflic…
hayakawa16 Feb 11, 2025
d63f173
Merge branch 'master' into ch-210312-raytrace-MC
hayakawa16 Mar 4, 2025
7e7f622
Merge branch 'master' into ch-210312-raytrace-MC
hayakawa16 Mar 5, 2025
6c51adc
Modified Asserts in test code not in main branch.
hayakawa16 Mar 5, 2025
8bba0a0
Merge branch 'master' into ch-210312-raytrace-MC and resolved conflic…
hayakawa16 Mar 27, 2025
6f9e2d4
Merge branch 'master' into ch-210312-raytrace-MC
hayakawa16 Aug 11, 2025
761d7e5
Merge branch 'master' into ch-210312-raytrace-MC
hayakawa16 Oct 2, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ public class ProgramTests
"two_layer_ROfRho",
"two_layer_ROfRho_TOfRho_with_databases",
"voxel_ROfXAndY_FluenceOfXAndYAndZ",
"surface_fiber_detector"
"surface_fiber_detector",
"ray_database_generator"
};
private readonly List<string> _listOfInfilesThatRequireExistingResultsToRun = new List<string>()
{
Expand Down
3 changes: 2 additions & 1 deletion src/Vts.MonteCarlo.PostProcessor.Test/ProgramTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ public class ProgramTests
"two_layer_ROfRho",
"two_layer_ROfRho_TOfRho_with_databases",
"voxel_ROfXAndY_FluenceOfXAndYAndZ",
"surface_fiber_detector"
"surface_fiber_detector",
"ray_database_generator"
};

/// <summary>
Expand Down
165 changes: 165 additions & 0 deletions src/Vts.MonteCarlo.ZemaxDatabaseConverter.Test/ProgramTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
using NUnit.Framework;
using System.Collections.Generic;
using System;
using Vts.IO;
using Vts.MonteCarlo.RayData;
using System.Threading.Tasks;
using System.IO;
using System.Reflection;

namespace Vts.MonteCarlo.ZemaxDatabaseConverter.Test
{
[TestFixture]
public class ProgramTests
{
// This tests code that would be executed to convert ZRD DB to/from MCCL compatible DB
// An actual Zemax output ZRD file was first used to verify tests, however file too large
// to add to resources. Instead this program is used to convert a MCCL DB to Zemax DB
// and that is used to test

/// <summary>
/// list of temporary files created by these unit tests
/// </summary>
readonly List<string> listOfTestGeneratedFiles = new List<string>()
{
"testzrdraydatabase",
"testzrdraydatabase.txt",
"testmcclraydatabase",
"testmcclraydatabase.txt",
};
readonly List<string> listOfTestGeneratedFolders = new List<string>()
{
"mcclraydatabase",
"zrdraydatabase"
};


/// <summary>
/// Set up simulation specifying RayDatabase to be written
/// </summary>
[OneTimeSetUp]
public void Setup_simulation_input_components()
{
// delete previously generated files
Clear_folders_and_files();
}

/// <summary>
/// clear all previously generated files.
/// </summary>
[OneTimeTearDown]
public void Clear_folders_and_files()
{
// delete any previously generated files
foreach (var file in listOfTestGeneratedFiles)
{
if (File.Exists(file))
{
FileIO.FileDelete(file);
}
}
// delete any previously generated folders
foreach (var folder in listOfTestGeneratedFolders)
{
if (Directory.Exists(folder))
{
FileIO.DeleteDirectory(folder);
}
}

}
/// <summary>
/// Test to verify sanity check on input works correctly
/// </summary>
[Test]
public async Task Validate_VerifyInputs_method_returns_correct_values()
{
// the following will fail because only 1 argument and file does not exist
string[] arguments = new string[] { "infile=databaseToConvert" };
var status = await Task.Run(() => Program.Main(arguments));
Assert.IsTrue(status == 1);
// no successful mccl-to-zrd test is tested here because tested in other tests
}
/// <summary>
/// Test that uses app to convert RayDatabase written in OneTimeSetup to a Zemax ZRD ray database
/// Validation values used from prior test
/// </summary>
[Test]
public async Task Validate_conversion_from_MCCL_RayDatabase_to_Zemax_ZrdDatabase_successful()
{
// copy MCCL RayDatabase from Resources
var folder = "mcclraydatabase";
FileIO.CopyFolderFromEmbeddedResources(folder, "",
Assembly.GetExecutingAssembly().FullName, true);
// run database converter on MCCL Ray Database generated in OneTimeSetup
var arguments = new string[] {
"infile=mcclraydatabase/RayDiffuseReflectanceDatabase",
"infiletype=mccl",
"outfile=testzrdraydatabase" };
await Task.Run(() => Program.Main(arguments));
// read file written
var rayDatabase = Zemax.ZrdRayDatabase.FromFile("testzrdraydatabase");
Assert.AreEqual(88, rayDatabase.NumberOfElements);

// manually enumerate through the first element
var enumerator = rayDatabase.DataPoints.GetEnumerator();
// advance to the first point and test that the point is valid
enumerator.MoveNext();
var dp1 = enumerator.Current;
Assert.IsTrue(Math.Abs(dp1.X - 4.18911) < 1e-5);
Assert.IsTrue(Math.Abs(dp1.Y + 22.1217) < 1e-4);
Assert.IsTrue(Math.Abs(dp1.Z - 0.0) < 1e-6);
Assert.IsTrue(Math.Abs(dp1.Ux - 0.654227) < 1e-6);
Assert.IsTrue(Math.Abs(dp1.Uy - 0.223239) < 1e-6);
Assert.IsTrue(Math.Abs(dp1.Uz + 0.722600) < 1e-6); // negative because exiting
Assert.IsTrue(Math.Abs(dp1.Weight - 0.021116) < 1e-6);
// advance to the second point and test that the point is valid
enumerator.MoveNext();
var dp2 = enumerator.Current;
Assert.IsTrue(Math.Abs(dp2.X - 0.382333) < 1e-6);
Assert.IsTrue(Math.Abs(dp2.Y + 2.13952) < 1e-5);
Assert.IsTrue(Math.Abs(dp2.Z - 0.0) < 1e-6);
Assert.IsTrue(Math.Abs(dp2.Ux + 0.711575) < 1e-6);
Assert.IsTrue(Math.Abs(dp2.Uy + 0.493464) < 1e-6);
Assert.IsTrue(Math.Abs(dp2.Uz + 0.500153) < 1e-6);
Assert.IsTrue(Math.Abs(dp2.Weight - 0.911520) < 1e-6);
enumerator.Dispose();
}
/// <summary>
/// test to verify reading actual Zemax ZRD file on hold until we can generate
/// a small one ourselves. In the meantime, convert MCCL Ray Database generated
/// in OneTimeSetup and then convert back to ZRD formatted database
/// </summary>
[Test]
public async Task Validate_conversion_from_Zemax_ZrdDatabase_to_MCCL_RayDatabase_successful()
{
//actual ZRD DB is in @"C:\Users\hayakawa\Desktop\RP\Zemax\ZWOutput\lightfromsourcefile"
// copy ZRD RayDatabase from Resources
var folder = "zrdraydatabase";
FileIO.CopyFolderFromEmbeddedResources(folder, "",
Assembly.GetExecutingAssembly().FullName, true);
// use actual zrd database and convert to mccl database
var arguments = new string[] {
"infile=zrdraydatabase/Lightfromsourcefile",
"infiletype=zrd",
"outfile=testmcclraydatabase" };
await Task.Run(() => Program.Main(arguments));
var rayDatabase = RayDatabase.FromFile("testmcclraydatabase");
Assert.AreEqual(10, rayDatabase.NumberOfElements);
var enumerator = rayDatabase.DataPoints.GetEnumerator();
// advance to the first point and test that the point is valid
enumerator.MoveNext();
var dp1 = enumerator.Current;
Assert.IsTrue(Math.Abs(dp1.Position.X - 0.003760) < 1e-6);
Assert.IsTrue(Math.Abs(dp1.Position.Y - 0.001500) < 1e-6);
Assert.IsTrue(Math.Abs(dp1.Position.Z - 0.490243) < 1e-6);
Assert.IsTrue(Math.Abs(dp1.Direction.Ux - 0.005315) < 1e-6);
Assert.IsTrue(Math.Abs(dp1.Direction.Uy - 0.992280) < 1e-6);
Assert.IsTrue(Math.Abs(dp1.Direction.Uz - 0.123897) < 1e-6); // why is this neg?
Assert.IsTrue(Math.Abs(dp1.Weight - 0.000730) < 1e-6);
enumerator.Dispose();
}


}
}
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"NumberOfElements": 88
}
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"NumberOfElements": 10
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>

<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<None Remove="Resources\RayDiffuseReflectanceDatabase" />
<None Remove="Resources\RayDiffuseReflectanceDatabase.txt" />
<None Remove="Resources\zrdraydatabase\Lightfromsourcefile" />
<None Remove="Resources\zrdraydatabase\Lightfromsourcefile.txt" />
</ItemGroup>

<ItemGroup>
<EmbeddedResource Include="Resources\mcclraydatabase\RayDiffuseReflectanceDatabase" />
<EmbeddedResource Include="Resources\mcclraydatabase\RayDiffuseReflectanceDatabase.txt" />
<EmbeddedResource Include="Resources\zrdraydatabase\Lightfromsourcefile" />
<EmbeddedResource Include="Resources\zrdraydatabase\Lightfromsourcefile.txt" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.3.1" />
<PackageReference Include="nunit" Version="3.13.3" />
<PackageReference Include="NUnit3TestAdapter" Version="4.2.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Vts.MonteCarlo.ZemaxDatabaseConverter\Vts.MonteCarlo.ZemaxDatabaseConverter.csproj" />
<ProjectReference Include="..\Vts\Vts.csproj" />
<ProjectReference Include="..\Vts.Zemax\Vts.Zemax.csproj" />
</ItemGroup>

</Project>
130 changes: 130 additions & 0 deletions src/Vts.MonteCarlo.ZemaxDatabaseConverter/DatabaseConverter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
using System;
using System.IO;
using Vts.Common;
using Vts.MonteCarlo.RayData;
using Vts.Zemax;

namespace Vts.MonteCarlo.ZemaxDatabaseConverter
{
public static class DatabaseConverter
{
/// <summary>
/// method to verify input arguments
/// </summary>
/// <param name="inputFile">Database to be converted</param>
/// <param name="outputFile">Converted database</param>
/// <returns>Boolean indicating inputs are valid</returns>
public static bool VerifyInputs(string inputFile, string outputFile)
{
try
{
if (string.IsNullOrEmpty(inputFile))
{
Console.WriteLine("\nNo input database file specified");
return false;
}

if (!string.IsNullOrEmpty(outputFile)) return true;
Console.WriteLine("\nNo output database file specified");
return false;
}
catch (Exception e)
{
Console.WriteLine(e.Message);
return false;
}
}

/// <summary>
/// method to convert Zemax ray database to MCCL source database
/// </summary>
/// <param name="inputFile">Database to be converted</param>
/// <param name="outputFile">Converted database</param>
public static void ConvertZemaxDatabaseToMcclSourceDatabase(string inputFile, string outputFile)
{
try
{
//get the full path for the input file
var fullFilePath = Path.GetFullPath(inputFile);

var fileToConvert = ZrdRayDatabase.FromFile(fullFilePath);

// enumerate through the elements
var enumerator = fileToConvert.DataPoints.GetEnumerator();

using (var dbWriter = new RayDatabaseWriter(
VirtualBoundaryType.DiffuseReflectance, outputFile))
{
for (var i = 0; i < fileToConvert.NumberOfElements; i++)
{
// advance to the next ray data
enumerator.MoveNext();
var dp = enumerator.Current;
// excise Position,Direction,Weight from Zemax struct
if (dp != null)
{
dbWriter.Write(new RayDataPoint(
new Position(dp.X, dp.Y, dp.Z),
new Direction(dp.Ux, dp.Uy, dp.Uz),
dp.Weight));
}
}
dbWriter.Close();
}
enumerator.Dispose();
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
}
/// <summary>
/// method to convert zemax ray database to MCCL source database
/// </summary>
/// <param name="inputFile">Database to be converted</param>
/// <param name="outputFile">Converted database</param>
public static void ConvertMcclDatabaseToZemaxSourceDatabase(string inputFile, string outputFile)
{
try
{
//get the full path for the input file
var fullFilePath = Path.GetFullPath(inputFile);

var fileToConvert = RayDatabase.FromFile(fullFilePath);

// enumerate through the elements
var enumerator = fileToConvert.DataPoints.GetEnumerator();

using (var dbWriter = new ZrdRayDatabaseWriter(
VirtualBoundaryType.DiffuseReflectance, outputFile))
{
for (var i = 0; i < fileToConvert.NumberOfElements; i++)
{
// advance to the next ray data
enumerator.MoveNext();
var dp = enumerator.Current;
if (dp == null) continue;
var zrdRayDataPoint = new ZrdRayDataPoint
{
// set Position,Direction,Weight in Zemax struct
X = dp.Position.X,
Y = dp.Position.Y,
Z = dp.Position.Z,
Ux = dp.Direction.Ux,
Uy = dp.Direction.Uy,
Uz = dp.Direction.Uz,
Weight = dp.Weight
};
dbWriter.Write(zrdRayDataPoint);
}
dbWriter.Close();
}
enumerator.Dispose();
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
}
}
}
Loading