diff --git a/BuildTestRelease.ps1 b/BuildTestRelease.ps1 index 47095fa41..7c72de35a 100644 --- a/BuildTestRelease.ps1 +++ b/BuildTestRelease.ps1 @@ -1,5 +1,5 @@ -$mccl_version = "6.2.0" -$matlab_version = "7.0.0" +$mccl_version = "7.0.0" +$matlab_version = "8.0.0" Invoke-Expression ".\BuildTestReleaseMCCL.ps1 $mccl_version" Invoke-Expression ".\BuildTestReleaseMATLAB.ps1 $matlab_version" diff --git a/readme.md b/readme.md index f4e06f46d..578d9647e 100644 --- a/readme.md +++ b/readme.md @@ -15,11 +15,8 @@ The Virtual Photonics Technology Initiative was established by the Laser Microbe ## Virtual Tissue Simulator (VTS) The primary vehicle for the accomplishment of these goals is the ongoing development of the Virtual Tissue Simulator (VTS). The VTS is being designed as a modular and scalable platform to provide an integrated suite of computational tools to define, solve, visualize, and analyze relevant forward and inverse radiative transport problems in Biomedical Optics. We intend to develop specific Application ToolKits (ATKs) that will provide a user-interface customized for the simulation of issues specific to an application domain. Examples include Small Animal Imaging and Fiber Optic Probe development. -## Downloads -To download the latest version, click [here](https://github.com/VirtualPhotonics/VTS/wiki/Downloads) - -## Releases and Source Codes -To access all releases and source code, click [here](https://github.com/VirtualPhotonics/VTS/releases). +## Downloads and Latest Releases +To access the latest release, past releases and downloads, click [here](https://github.com/VirtualPhotonics/VTS/releases). ## Getting Started and Documentation To access getting started instructions in Linux, Mac or Windows, click diff --git a/readme.txt b/readme.txt deleted file mode 100644 index bff5575b2..000000000 --- a/readme.txt +++ /dev/null @@ -1,16 +0,0 @@ -Virtual Tissue Simulator (VTS) Project -Copyright (c) 2009 - 2019 Laser Microbeam and Medical Program - -The main solution Vts.sln contains a .NET Standard 2.0 project so you will need Visual Studio 2017 and all the latest updates and service packs. If .NET Standard 2.0 is still not recognized install the .NET Core 2.0 SDK - -In Visual Studio 2010, 2013 or 2015, open the file /src/Vts-VS2010-2015-Compatible.sln - -For detailed instructions on how to launch the VTS GUI visit: -https://github.com/VirtualPhotonics/VTS/wiki/Compile-and-run-the-VTS - -To Build, Test and Run the VTS without Visual Studio visit: -https://github.com/VirtualPhotonics/VTS/wiki/Without-Visual-Studio - -For more information about coding conventions and how to contribute to our Open Source effort see our developer website at: -https://github.com/VirtualPhotonics/VTS/wiki - diff --git a/src/Vts.Benchmark/Vts.Benchmark.csproj b/src/Vts.Benchmark/Vts.Benchmark.csproj index 434f0438f..30e955ce2 100644 --- a/src/Vts.Benchmark/Vts.Benchmark.csproj +++ b/src/Vts.Benchmark/Vts.Benchmark.csproj @@ -7,7 +7,7 @@ - + diff --git a/src/Vts.MonteCarlo.CommandLineApplication/Vts.MonteCarlo.CommandLineApplication.csproj b/src/Vts.MonteCarlo.CommandLineApplication/Vts.MonteCarlo.CommandLineApplication.csproj index 091d04da6..5079d383a 100644 --- a/src/Vts.MonteCarlo.CommandLineApplication/Vts.MonteCarlo.CommandLineApplication.csproj +++ b/src/Vts.MonteCarlo.CommandLineApplication/Vts.MonteCarlo.CommandLineApplication.csproj @@ -6,8 +6,8 @@ mc win-x64;linux-x64;osx-x64 Vts.MonteCarlo.CommandLineApplication - 6.2.0.0 - 6.2.0.0 + 7.0.0.0 + 7.0.0.0 false Virtual Photonics Technology Initiative MCCL @@ -20,7 +20,7 @@ https://github.com/VirtualPhotonics/VTS C#;Monte-Carlo Git - 6.2.0 + 7.0.0 diff --git a/src/Vts.MonteCarlo.CommandLineApplication/readme.txt b/src/Vts.MonteCarlo.CommandLineApplication/readme.txt deleted file mode 100644 index ad21103e4..000000000 --- a/src/Vts.MonteCarlo.CommandLineApplication/readme.txt +++ /dev/null @@ -1,22 +0,0 @@ -Virtual Tissue Simulator (VTS) Project -Monte Carlo Command-line Application -Copyright (c) 2018 Laser Microbeam and Medical Program - -Requirements: -.NET Framework 4.0 - download http://www.microsoft.com/downloads/en/details.aspx?familyid=9cfb2d51-5ff4-4491-b0e5-b386f32c0992&displaylang=en - -Useful Tools: -XML Notepad 2007 - download http://www.microsoft.com/downloads/en/details.aspx?FamilyID=72d6aa49-787d-4118-ba5f-4f30fe913628 - -Usages: -mc (runs the application with the default infile.txt) -mc infile=myinput outputtag=myoutput inputparam=mua1,0.01,0.04,0.01 inputparam=mus1,10,20,10 -mc infile=ROfRhoinput inputparam=mua1,0.01,0.04,0.01 inputparam=mus1,10,20,10 - - -For more information about the VTS and the Virtual Photonics effort visit: -http://www.virtualphotonics.org/ - -Developer website: -https://github.com/VirtualPhotonics - diff --git a/src/Vts.MonteCarlo.PostProcessor/Vts.MonteCarlo.PostProcessor.csproj b/src/Vts.MonteCarlo.PostProcessor/Vts.MonteCarlo.PostProcessor.csproj index 8bcde9d2a..03c61d3e5 100644 --- a/src/Vts.MonteCarlo.PostProcessor/Vts.MonteCarlo.PostProcessor.csproj +++ b/src/Vts.MonteCarlo.PostProcessor/Vts.MonteCarlo.PostProcessor.csproj @@ -6,8 +6,8 @@ Vts.MonteCarlo.PostProcessor mc_post win-x64;linux-x64;osx-x64 - 6.2.0.0 - 6.2.0.0 + 7.0.0.0 + 7.0.0.0 David Cuccia; Carole Hayakawa; Lisa Malenfant; Janaka Ranasinghesagara; Jennifer Nguyen; Adam Gardner; Michele Martinelli Virtual Photonics Technology Initiative MCPP @@ -20,7 +20,7 @@ Git C#;Monte-Carlo false - 6.2.0 + 7.0.0 diff --git a/src/Vts.Test/IO/FileIOTests.cs b/src/Vts.Test/IO/FileIOTests.cs index 4b41b1809..4f8f9cc38 100644 --- a/src/Vts.Test/IO/FileIOTests.cs +++ b/src/Vts.Test/IO/FileIOTests.cs @@ -185,17 +185,6 @@ public void validate_read_array_from_binary_in_resources_without_parameter_dimen Assert.IsTrue(Math.Abs(data[2] - 0.052445) < 0.000001); } - [Test] - public void validate_read_from_binary_in_resources() - { - var name = Assembly.GetExecutingAssembly().FullName; - var assemblyName = new AssemblyName(name).Name; - double data; - data = FileIO.ReadFromBinaryInResources( - "Resources/fileiotest/binarydbl", assemblyName); - Assert.AreEqual(10, data); - } - [Test] public void validate_read_from_binary_in_resources_custom() { @@ -221,25 +210,6 @@ public void validate_read_from_binary_custom() Assert.AreEqual(16, arrayRead[1]); } - [Test] - public void validate_read_from_binary_stream() - { - var name = Assembly.GetExecutingAssembly().FullName; - var assemblyName = new AssemblyName(name).Name; - int size = 100; - double[] arrayWritten; - // read file from resources and write it so that can be read in - arrayWritten = (double[])FileIO.ReadArrayFromBinaryInResources - ("Resources/fileiotest/ROfRho", assemblyName, size); - FileIO.WriteToBinary(arrayWritten, "array5"); - double[] arrayRead; - using (Stream stream = StreamFinder.GetFileStream("array5", FileMode.Open)) - { - arrayRead = FileIO.ReadFromBinaryStream(stream); - } - Assert.IsTrue(Math.Abs(arrayRead[2] - 0.052445) < 0.000001); - } - [Test] public void validate_read_from_json() { @@ -334,44 +304,6 @@ public void validate_write_scalar_value_to_binary_and_read_scalar_value_from_bin Assert.AreEqual(11, data); } - [Test] - public void validate_write_to_binary_and_read_from_binary() - { - double[] array = new double[3] { 4.0, 5.0, 6.0 }; - FileIO.WriteToBinary(array, "array2"); - Assert.IsTrue(FileIO.FileExists("array2")); - Assert.IsTrue(new FileInfo("array2").Length != 0); - var data = FileIO.ReadFromBinary("array2"); - Assert.AreEqual(4.0, data[0]); - } - - [Test] - public void Validate_write_to_binary_stream_throws_exception() - { - Assert.Throws(() => - { - using (Stream stream = new MemoryStream(8)) - { - FileIO.WriteToBinaryStream(null, stream); - } - }); - } - - [Test] - public void validate_write_2D_array_to_binary_and_read_from_binary() - { - var array = new double[,] - { - {1D, 2D}, - {3D, 4D} - }; - FileIO.WriteToBinary(array, "2darray"); - Assert.IsTrue(FileIO.FileExists("2darray")); - Assert.IsTrue(new FileInfo("2darray").Length != 0); - var data = FileIO.ReadFromBinary("2darray"); - Assert.AreEqual(2D, data[0, 1]); - } - [Test] public void validate_write_to_binary_custom() { @@ -382,24 +314,6 @@ public void validate_write_to_binary_custom() Assert.IsTrue(new FileInfo("array3").Length != 0); } - [Test] - public void validate_write_to_binary_stream_and_read_from_binary_stream() - { - // first create stream, write array, validate written and close stream - double[] array = new double[3] { 10, 11, 12 }; - Stream streamWrite = StreamFinder.GetFileStream("array4", FileMode.Create); - FileIO.WriteToBinaryStream(array, streamWrite); - Assert.IsNotNull(streamWrite); - Assert.IsTrue(FileIO.FileExists("array4")); - Assert.IsTrue(new FileInfo("array4").Length != 0); - streamWrite.Close(); - // then open stream, read array, validate values and close stream - Stream streamRead = StreamFinder.GetFileStream("array4", FileMode.Open); - var data = FileIO.ReadFromBinaryStream(streamRead); - Assert.AreEqual(10, data[0]); - streamRead.Close(); - } - [Test] public void validate_write_to_json() { diff --git a/src/Vts.Test/MonteCarlo/Factories/DetectorFactoryTests.cs b/src/Vts.Test/MonteCarlo/Factories/DetectorFactoryTests.cs index 52f39d4f8..37841a3fe 100644 --- a/src/Vts.Test/MonteCarlo/Factories/DetectorFactoryTests.cs +++ b/src/Vts.Test/MonteCarlo/Factories/DetectorFactoryTests.cs @@ -1,18 +1,17 @@ -using System; +using MathNet.Numerics.Random; +using Moq; +using NUnit.Framework; +using System; using System.Collections.Generic; +using System.IO; using System.Linq; -using System.Reflection; -using NUnit.Framework; +// using the following for user-defined ROfXDetector implementation +using System.Runtime.Serialization; using Vts.Common; +using Vts.IO; using Vts.MonteCarlo; using Vts.MonteCarlo.Detectors; using Vts.MonteCarlo.Factories; - -// using the following for user-defined ROfXDetector implementation -using System.Runtime.Serialization; -using MathNet.Numerics.Random; -using Moq; -using Vts.IO; using Vts.MonteCarlo.Helpers; using Vts.MonteCarlo.IO; using Vts.MonteCarlo.PhotonData; @@ -37,6 +36,7 @@ public class DetectorFactoryTests { "file.txt" // file that captures screen output of MC simulation }; + /// /// clear all generated folders and files /// @@ -46,18 +46,25 @@ public void Clear_folders_and_files() { foreach (var folder in listOfTestGeneratedFolders) { - FileIO.DeleteDirectory(folder); + if (Directory.Exists(folder)) + { + FileIO.DeleteDirectory(folder); + } } foreach (var file in listOfTestGeneratedFiles) { - FileIO.FileDelete(file); + if (File.Exists(file)) + { + FileIO.FileDelete(file); + } } } + /// /// Simulate null return of GetDetector(s) /// [Test] - public void Demonstate_GetDetectors_null_return_on_empty_list() + public void Demonstrate_GetDetectors_null_return_on_empty_list() { IEnumerable emptyDetectorList = null; Assert.IsNull(DetectorFactory.GetDetectors( @@ -120,6 +127,7 @@ public void Demonstrate_fluent_mc_creation() [Test] public void Demonstrate_user_defined_detector_usage() { + // Add detector to ConventionBasedConverter _classInfoDictionary DetectorFactory.RegisterDetector( typeof (ROfXDetectorInput), typeof (ROfXDetector)); var detectorInput = new ROfXDetectorInput @@ -141,9 +149,17 @@ public void Demonstrate_user_defined_detector_usage() Assert.IsTrue(detectorExists); var firstValue = ((ROfXDetector)detector).Mean.FirstOrDefault(); Assert.IsTrue(firstValue != 0); + + // write detector to folder "user_defined_detector" DetectorIO.WriteDetectorToFile(detector, "user_defined_detector"); - DetectorIO.ReadDetectorFromFile("user_defined_detector", ""); + + // read detector filename="My First R(x) Detector" from folder "user_defined_detector" + var detectorFromFile = DetectorIO.ReadDetectorFromFile(detectorInput.Name, "user_defined_detector"); + Assert.IsNotNull(detectorFromFile); + Assert.AreEqual(detector.Name, detectorFromFile.Name); + Assert.AreEqual(detector.TallyType, detectorFromFile.TallyType); } + /// /// tests to verify exception returns from RegisterDetector /// diff --git a/src/Vts/IO/ConventionBasedConverter.cs b/src/Vts/IO/ConventionBasedConverter.cs index 3c4ea65d8..cef77994e 100644 --- a/src/Vts/IO/ConventionBasedConverter.cs +++ b/src/Vts/IO/ConventionBasedConverter.cs @@ -1,8 +1,8 @@ -using System; +using Microsoft.Extensions.DependencyInjection; +using Newtonsoft.Json.Linq; +using System; using System.Collections.Generic; using System.Linq; -using Microsoft.Extensions.DependencyInjection; -using Newtonsoft.Json.Linq; namespace Vts.IO { @@ -16,6 +16,7 @@ public class ConventionBasedConverter : JsonCreationConverter _classInfoDictionary; private readonly ServiceProvider _serviceProvider; + private readonly List _userDefinedServiceProviders = new List(); /// /// Internal class for holding on to necessary class info for future instantiation @@ -114,10 +115,37 @@ protected override TInterface Create(Type objectType, JObject jObject) var classInfo = _classInfoDictionary[classPrefixString]; var classInstance = (TInterface)_serviceProvider.GetService(classInfo.ClassType); + + if (classInstance != null) return classInstance; + foreach (var instance in _userDefinedServiceProviders.Select(provider => (TInterface)provider.GetService(classInfo.ClassType)).Where(instance => instance != null)) + { + return instance; + } return classInstance; } + /// + /// + /// + /// + /// + /// + public void AddUserDefinedServices(Type objectType, string className, string classPrefixString) + { + var classInfo = new VtsClassInfo + { + ClassName = className, + ClassPrefixString = classPrefixString, + ClassType = objectType + }; + _classInfoDictionary.Add(classPrefixString, classInfo); + var services = new ServiceCollection(); + services.AddTransient(classInfo.ClassType); + var serviceProvider = services.BuildServiceProvider(); + _userDefinedServiceProviders.Add(serviceProvider); + } + /// /// method to determine if field exists /// diff --git a/src/Vts/IO/FileIO.cs b/src/Vts/IO/FileIO.cs index 2e7e358da..f88ca5af2 100644 --- a/src/Vts/IO/FileIO.cs +++ b/src/Vts/IO/FileIO.cs @@ -613,91 +613,5 @@ private static IEnumerable ReadStreamFromBinaryCustom(Stream s, Func - /// Read from a binary stream - /// - /// The Type to read from binary - /// File to be read - /// The object of type T - public static T ReadFromBinary(string filename) - { - using (Stream stream = StreamFinder.GetFileStream(filename, FileMode.Open)) - { - return ReadFromBinaryStream(stream); - } - } - - /// - /// Read an object of type T from a binary file in resources - /// - /// Type of the object - /// Name of the binary file in resources - /// Name of the project where the resources are located - /// The object of type T - public static T ReadFromBinaryInResources(string filename, string projectName) - { - using (Stream stream = StreamFinder.GetFileStreamFromResources(filename, projectName)) - { - return ReadFromBinaryStream(stream); - } - } - - /// - /// Write an object of type T to a binary file - /// - /// Type of the object - /// The object to write - /// Name of the binary file - public static void WriteToBinary(this T myObject, string filename) - { - using (Stream stream = StreamFinder.GetFileStream(filename, FileMode.Create)) - { - WriteToBinaryStream(myObject, stream); - } - } - - /// - /// Deserializes a stream into an object - /// - /// Type of the object - /// Stream to deserialize - /// The object of type T - public static T ReadFromBinaryStream(Stream s) - { - BinaryFormatter formatter = new BinaryFormatter(); - try - { - return (T)formatter.Deserialize(s); - } - catch (SerializationException e) - { - Console.WriteLine("Failed to deserialize. Reason: " + e.Message); - throw; - } - } - - /// - /// Serializes an object of type T to the given stream - /// - /// Type of the object - /// The object to write - /// Stream to which to write the object - public static void WriteToBinaryStream(T myObject, Stream s) - { - BinaryFormatter formatter = new BinaryFormatter(); - try - { - formatter.Serialize(s, myObject); - } - catch (SerializationException e) - { - Console.WriteLine("Failed to serialize. Reason: " + e.Message); - throw; - } - } - #endregion } } \ No newline at end of file diff --git a/src/Vts/MonteCarlo/Detectors/ROfFxAndMaxDepthDetector.cs b/src/Vts/MonteCarlo/Detectors/ROfFxAndMaxDepthDetector.cs index 6564c2be6..6686e6159 100644 --- a/src/Vts/MonteCarlo/Detectors/ROfFxAndMaxDepthDetector.cs +++ b/src/Vts/MonteCarlo/Detectors/ROfFxAndMaxDepthDetector.cs @@ -174,8 +174,6 @@ public void Tally(Photon photon) /// number of photons launched public void Normalize(long numPhotons) { - var normalizationFactor = 2.0 * Math.PI * Fx.Delta; - var sum = 0.0; for (int ifx = 0; ifx < Fx.Count; ifx++) { for (int id = 0; id < MaxDepth.Count - 1; id++) diff --git a/src/Vts/MonteCarlo/Factories/DetectorFactory.cs b/src/Vts/MonteCarlo/Factories/DetectorFactory.cs index c9e533d55..786abde28 100644 --- a/src/Vts/MonteCarlo/Factories/DetectorFactory.cs +++ b/src/Vts/MonteCarlo/Factories/DetectorFactory.cs @@ -53,6 +53,7 @@ public static IDetector GetDetector(IDetectorInput detectorInput, ITissue tissue return detector; } + /// /// method to register detector: currently not used /// @@ -83,11 +84,20 @@ public static void RegisterDetector(Type detectorInputType, Type detectorType) var detectorInput = (IDetectorInput) Activator.CreateInstance(detectorInputType); - VtsJsonSerializer.KnownConverters.AddRange(new JsonConverter[] + if (detectorInput == null) return; + + foreach (var knownConverter in VtsJsonSerializer.KnownConverters) + { + if (knownConverter.GetType() == typeof(ConventionBasedConverter)) { - new ConventionBasedConverter(detectorInputType, "TallyType", new[] { detectorInput.TallyType }), - new ConventionBasedConverter( detectorType, "TallyType", new[] { detectorInput.TallyType }) - }); + var knownDetectorInput = (ConventionBasedConverter)knownConverter; + knownDetectorInput.AddUserDefinedServices(detectorInputType, "TallyType", detectorInput.TallyType); + } + + if (knownConverter.GetType() != typeof(ConventionBasedConverter)) continue; + var knownDetector = (ConventionBasedConverter)knownConverter; + knownDetector.AddUserDefinedServices(detectorType, "TallyType", detectorInput.TallyType); + } } } } diff --git a/src/Vts/Vts.csproj b/src/Vts/Vts.csproj index b25fde5f0..a6425cb6f 100644 --- a/src/Vts/Vts.csproj +++ b/src/Vts/Vts.csproj @@ -5,7 +5,7 @@ The VTS (Virtual Tissue Simulator) is an open source library for .NET that was designed as a modular and scalable platform to provide an integrated suite of computational tools to define, solve, visualize, and analyze relevant forward and inverse radiative transport problems in Biomedical Optics. Virtual Photonics Technology Initiative Copyright © 2022 Laser Microbeam and Medical Program - 7.0.0 + 8.0.0 true David Cuccia; Carole Hayakawa; Lisa Malenfant; Janaka Ranasinghesagara; Jennifer Nguyen; Adam Gardner; Michele Martinelli VirtualPhotonics.Vts @@ -13,9 +13,11 @@ https://github.com/VirtualPhotonics/VTS/wiki https://github.com/VirtualPhotonics/VTS Git - Updated NuGet packages - 7.0.0.0 - 7.0.0.0 + * Updated NuGet packages +* Code cleanup including + * Fixing issues found by SonarCloud + 8.0.0.0 + 8.0.0.0 40 C:\Users\hayakawa\Documents\Visual Studio 2019\Projects\vts_210207\src\Backup\Vts\ 2.0