public void VerifyROfRhoMonteCarloMeasuredNoNoiseMonteCarloModel() { var independentValues = new double[] { 1, 2, 3, 4, 5, 6 }; // rho [mm] var actualProperties = new OpticalProperties(mua: 0.01, musp: 1.0, g: 0.8, n: 1.4); var initialGuess = new OpticalProperties(mua: 0.02, musp: 1.2, g: 0.8, n: 1.4); var simulatedMeasured = ComputationFactory.ComputeReflectance( ForwardSolverType.MonteCarlo, SolutionDomainType.ROfRho, ForwardAnalysisType.R, new object[] { new[] { actualProperties }, independentValues }); var standardDeviation = simulatedMeasured; double[] fit = ComputationFactory.SolveInverse( ForwardSolverType.MonteCarlo, OptimizerType.MPFitLevenbergMarquardt, SolutionDomainType.ROfRho, simulatedMeasured, standardDeviation, InverseFitType.MuaMusp, new object[] { new[] { initialGuess }, independentValues }); var convergedMua = fit[0]; var convergedMusp = fit[1]; Assert.Less(Math.Abs(convergedMua - 0.01), 1e-6); Assert.Less(Math.Abs(convergedMusp - 1.0), 1e-6); }
/// <summary> /// Create a DiffusionParameters object from OpticalProperties object and a ForwardModel /// choice. /// </summary> /// <param name="op">OpticalProperties object</param> /// <param name="fm">ForwardModel enum</param> /// <returns>new DiffusionParameters object</returns> public static DiffusionParameters Create(OpticalProperties op, ForwardModel fm) { var mua = op.Mua; var mutr = op.Mua + op.Musp; var cn = GlobalConstants.C / op.N; var D = 1 / (3 * mutr); var A = CalculatorToolbox.GetCubicAParameter(op.N); var mueff = Math.Sqrt(3 * op.Mua * mutr); var zb = 2 / (3 * mutr) * A; double musTilde; double gTilde; switch (fm) { case ForwardModel.SDA: default: musTilde = op.Musp; gTilde = op.G; break; case ForwardModel.DeltaPOne: musTilde = op.Musp * (1 - op.G * op.G) / (1 - op.G); gTilde = op.G / (op.G + 1); break; } var mutTilde = op.Mua + musTilde; var zp = 1 / mutTilde; return(new DiffusionParameters(A, mueff, zb, zp, mutTilde, musTilde, mutr, gTilde, D, cn, mua)); }
/// <summary> /// SurfaceFiberTissueRegion assumes SurfaceFiber axis is parallel with z-axis /// </summary> /// <param name="center">center position</param> /// <param name="radius">radius in x-y plane</param> /// <param name="op">optical properties of SurfaceFiber</param> public SurfaceFiberTissueRegion(Position center, double radius, OpticalProperties op) { TissueRegionType = "SurfaceFiber"; Center = center; Radius = radius; RegionOP = op; }
private static void Report2DForwardSolver(ForwardSolverType[] fSTs, SpatialDomainType sDT, TimeDomainType tDT, OpticalProperties op, string inputPath, string projectName) { var filename = "musp" + op.Musp.ToString() + "mua" + op.Mua.ToString(); filename = filename.Replace(".", "p"); Console.WriteLine("Looking for file {0} in spatial domain type {1} and temporal domain type{2}", filename, sDT.ToString(), tDT.ToString()); if (File.Exists(inputPath + sDT.ToString() + "/SteadyState/" + filename) || File.Exists(inputPath + sDT.ToString() + "/" + tDT.ToString() + "/" + filename)) { Console.WriteLine("The file {0} has been found.", filename); int sDim = GetSpatialNumberOfPoints(sDT); int tDim = GetTemporalNumberOfPoints(sDT, tDT); int[] dims = { sDim, tDim }; var spatialVariable = (IEnumerable <double>)FileIO.ReadArrayFromBinaryInResources <double> ("Resources/" + sDT.ToString() + "/" + "SteadyState/" + filename, projectName, sDim); var temporalVariable = (double[, ])FileIO.ReadArrayFromBinaryInResources <double> ("Resources/" + sDT.ToString() + "/" + tDT.ToString() + "/" + filename, projectName, dims); foreach (var fST in fSTs) { EvaluateAndWriteForwardSolver2DResults(fST, sDT, tDT, op, spatialVariable, temporalVariable); } } else { Console.WriteLine("The file {0} has not been found", filename); } }
public void Test_deserialize_inverse_solver_data() { var postData = "{\"inverseSolverType\":\"PointSourceSDA\",\"optimizerType\":\"MPFitLevenbergMarquardt\",\"optimizationParameters\":\"MuaMusp\",\"solutionDomain\":\"ROfRho\",\"measuredData\":[[0.5,0.034828428710495074],[0.7571428571428571,0.029420531983087726],[1.0142857142857142,0.02093360911749075],[1.2714285714285714,0.01665715182769329],[1.5285714285714285,0.014364183918250022],[1.7857142857142856,0.011454828142680954],[2.0428571428571427,0.009079166450343084],[2.3,0.00766922059364649],[2.557142857142857,0.005969062618866233],[2.814285714285714,0.005133772121534473],[3.071428571428571,0.004173573203610217],[3.3285714285714283,0.0037753248321977808],[3.5857142857142854,0.0033053865379579577],[3.8428571428571425,0.0025773098635545667],[4.1,0.00232888357135617],[4.357142857142857,0.001995707298051381],[4.614285714285714,0.0016130076959352349],[4.871428571428571,0.0015272034490867183],[5.128571428571428,0.0013992385402248396],[5.385714285714285,0.0011945241210807522],[5.642857142857142,0.0010810369822821084],[5.8999999999999995,0.0009448803801525864],[6.157142857142857,0.0009198316127711655],[6.414285714285714,0.0006943417260433173],[6.671428571428571,0.0006333583166048397],[6.928571428571428,0.0006216988605675773],[7.185714285714285,0.000512835051348594],[7.442857142857142,0.0004826500754318199],[7.699999999999999,0.00043617857542623087],[7.957142857142856,0.0003878849790650086],[8.214285714285714,0.000378880207382442],[8.471428571428572,0.00031667904143385504],[8.728571428571428,0.00026887511680669254],[8.985714285714284,0.00025470774216120143],[9.24285714285714,0.00022926547222261112],[9.499999999999996,0.000201735054811538]],\"independentAxes\":{\"label\":\"t\",\"value\":0.05},\"xAxis\":{\"start\":0.5,\"stop\":9.5,\"count\":\"36\"},\"opticalProperties\":{\"mua\":0.01,\"musp\":1,\"g\":0.8,\"n\":1.4}}"; var xAxis = new DoubleRange(0.5, 9.5, 36); var opticalProperties = new OpticalProperties(0.01, 1, 0.8, 1.4); var measuredData = new List <double[]> { new [] { 0.5, 0.034828428710495074 }, new [] { 0.7571428571428571, 0.029420531983087726 }, new [] { 1.0142857142857142, 0.02093360911749075 }, new [] { 1.2714285714285714, 0.01665715182769329 }, new [] { 1.5285714285714285, 0.014364183918250022 }, new [] { 1.7857142857142856, 0.011454828142680954 }, new [] { 2.0428571428571427, 0.009079166450343084 }, new [] { 2.3, 0.00766922059364649 }, new [] { 2.557142857142857, 0.005969062618866233 }, new [] { 2.814285714285714, 0.005133772121534473 } }; var solutionDomainPlotParameters = JsonConvert.DeserializeObject <SolutionDomainPlotParameters>(postData); Assert.AreEqual(xAxis.Start, solutionDomainPlotParameters.XAxis.Start); Assert.AreEqual(xAxis.Stop, solutionDomainPlotParameters.XAxis.Stop); Assert.AreEqual(xAxis.Count, solutionDomainPlotParameters.XAxis.Count); Assert.AreEqual(xAxis.Delta, solutionDomainPlotParameters.XAxis.Delta); Assert.AreEqual(ForwardSolverType.PointSourceSDA, solutionDomainPlotParameters.ForwardSolverType); Assert.AreEqual(ForwardSolverType.PointSourceSDA, solutionDomainPlotParameters.InverseSolverType); Assert.AreEqual(SolutionDomainType.ROfRho, solutionDomainPlotParameters.SolutionDomain); Assert.AreEqual(opticalProperties.Mua, solutionDomainPlotParameters.OpticalProperties.Mua); Assert.AreEqual(OptimizerType.MPFitLevenbergMarquardt, solutionDomainPlotParameters.OptimizerType); Assert.AreEqual(InverseFitType.MuaMusp, solutionDomainPlotParameters.OptimizationParameters); Assert.AreEqual(0, solutionDomainPlotParameters.NoiseValue); Assert.AreEqual(ForwardAnalysisType.R, solutionDomainPlotParameters.ModelAnalysis); Assert.AreEqual(measuredData[3][0], solutionDomainPlotParameters.MeasuredData[3][0]); Assert.AreEqual(measuredData[7][1], solutionDomainPlotParameters.MeasuredData[7][1]); Assert.AreEqual(measuredData[5][0], solutionDomainPlotParameters.MeasuredData[5][0]); }
public void VerifyROfRhoMonteCarloMeasuredNoNoiseSDAModel() { var independentValues = new double[] { 10, 11, 12, 13, 14, 15 }; // rho [mm] var actualProperties = new OpticalProperties(mua: 0.01, musp: 1.0, g: 0.8, n: 1.4); var initialGuess = new OpticalProperties(mua: 0.02, musp: 1.2, g: 0.8, n: 1.4); var lowerBounds = new double[] { 0, 0, 0, 0 }; var upperBounds = new double[] { double.PositiveInfinity, double.PositiveInfinity, double.PositiveInfinity, double.PositiveInfinity }; var simulatedMeasured = ComputationFactory.ComputeReflectance( ForwardSolverType.MonteCarlo, SolutionDomainType.ROfRho, ForwardAnalysisType.R, new object[] { new[] { actualProperties }, independentValues }); var standardDeviation = simulatedMeasured; double[] fit = ComputationFactory.SolveInverse( ForwardSolverType.DistributedPointSourceSDA, OptimizerType.MPFitLevenbergMarquardt, SolutionDomainType.ROfRho, simulatedMeasured, standardDeviation, InverseFitType.MuaMusp, new object[] { new[] { initialGuess }, independentValues }, lowerBounds, upperBounds); var convergedMua = fit[0]; var convergedMusp = fit[1]; Assert.Less(Math.Abs(convergedMua - 0.01), 0.002); Assert.Less(Math.Abs(convergedMusp - 1.0), 0.11); }
/// <summary> /// CylinderTissueRegion assumes cylinder axis is parallel with z-axis /// </summary> /// <param name="center">center position</param> /// <param name="radius">radius in x-y plane</param> /// <param name="op">optical properties of cylinder</param> public InfiniteCylinderTissueRegion(Position center, double radius, OpticalProperties op) { TissueRegionType = "InfiniteCylinder"; Center = center; Radius = radius; RegionOP = op; }
public void validate_serialization_of_OpticalProperties() { var op = new OpticalProperties(0.011, 1.1, 0.99, 1.44); var jsonSerialized = VtsJsonSerializer.WriteToJson(op); Assert.IsTrue(jsonSerialized != null && jsonSerialized.Length > 0); }
public static Complex[] ComputeFluenceComplex( IForwardSolver forwardSolver, FluenceSolutionDomainType solutionDomainType, // keeping us from uniting the above. needs to be a single SolutionDomainType enum IndependentVariableAxis[] independentAxesTypes, double[][] independentValues, OpticalProperties opticalProperties, params double[] constantValues) { var parameters = new double[4] { opticalProperties.Mua, opticalProperties.Musp, opticalProperties.G, opticalProperties.N }; // todo: current assumption below is that the second axes is z. need to generalize var func = GetForwardFluenceFuncComplex(forwardSolver, solutionDomainType, independentAxesTypes[0]); // create a list of inputs (besides optical properties) that corresponds to the behavior of the function above List <object> inputValues = new List <object>(independentValues); constantValues.ForEach(cv => inputValues.Add(cv)); return(func(parameters, inputValues.ToArray())); }
/// <summary> /// Analytic solution for homogeneous slab of length Time. This assumes /// Q0, the source term, is 1. /// </summary> /// <param name="slabThickness">thickness of slab</param> /// <param name="ops">optical properties of slab</param> /// <param name="direction">direction of radiance (uz=1 downward, uz=-1 upward)</param> /// <param name="position">position of interest in slab</param> /// <returns></returns> public static double GetBidirectionalRadianceInSlab(double slabThickness, OpticalProperties ops, int direction, double position) { // Pf = prob. of forward scattering, Pb = prob. of backward scattering // Pf+Pb = 1, Pf-Pb=g => Pf=(1+g)/2 double Pf = (1 + ops.G) / 2; double a = (ops.Mua + ops.Mus) - ops.Mus * Pf; double b = ops.Mus * (1 - Pf); double delta = Math.Sqrt(a * a - b * b); double denom = (delta + a) + (delta - a) * Math.Exp(-2 * delta * slabThickness); if (direction == 1) // downward moving radiance { // answer=d1*exp(delta*x)+d2*exp(-delta*x) // below is the more numerically stable equivalent var d1 = (delta - a) * Math.Exp(-2 * delta * slabThickness) / denom; var d2 = (delta + a) / denom; return(((delta - a) * Math.Exp(-2 * delta * slabThickness + delta * position) + (delta + a) * Math.Exp(-delta * position)) / denom); } else // upward moving radiance { // answer=d1*exp(delta*x)+d2*exp(-delta*x) // below is the more nuerically stable equivalent var d1 = -b *Math.Exp(-2 *delta *slabThickness) / denom; var d2 = b / denom; return((-b * Math.Exp(-2 * delta * slabThickness + delta * position) + b * Math.Exp(-delta * position)) / denom); } }
public static double GetBidirectionalRadianceIntegratedOverInterval(double slabThickness, OpticalProperties ops, int direction, double position1, double position2) { double Pf = (1 + ops.G) / 2; double a = (ops.Mua + ops.Mus) - ops.Mus * Pf; double b = ops.Mus * (1 - Pf); double delta = Math.Sqrt(a * a - b * b); double denom = (delta + a) + (delta - a) * Math.Exp(-2 * delta * slabThickness); if (direction == 1) // downward moving radiance { //d1=-b*Q0*exp(-2*delta*Time)/denom; //d2=b*Q0/denom; // answer=(1/delta)*(d1*exp(delta*x)-d2*exp(-delta*x)); var d1 = (1.0 / delta) * ((delta - a) * Math.Exp(-2 * delta * slabThickness + delta * position2) - (delta + a) * Math.Exp(-delta * position2)) / denom; var d2 = (1.0 / delta) * ((delta - a) * Math.Exp(-2 * delta * slabThickness + delta * position1) - (delta + a) * Math.Exp(-delta * position1)) / denom; return(d1 - d2); } else { // upward moving radiance //d1=Q0*(delta-a)*exp(-2*delta*Time)/denom; //d2=Q0*(delta+a)/denom; // answer=(1/delta)*(d1*exp(delta*x)-d2*exp(-delta*x)); var d1 = (1.0 / delta) * (-b * Math.Exp(-2 * delta * slabThickness + delta * position2) - b * Math.Exp(-delta * position2)) / denom; var d2 = (1.0 / delta) * (-b * Math.Exp(-2 * delta * slabThickness + delta * position1) - b * Math.Exp(-delta * position1)) / denom; return(d1 - d2); } }
private static void EvaluateAndWriteForwardSolver2DResults(ForwardSolverType fST, SpatialDomainType sDT, TimeDomainType tDT, OpticalProperties op, IEnumerable <double> spatialVariable, double[,] temporalVariable) { double[] reflectanceValues; var ReflectanceFunction = Get2DReflectanceFunction(fST, sDT, tDT); MakeDirectoryIfNonExistent(sDT.ToString(), tDT.ToString(), fST.ToString()); var sV = spatialVariable.First(); var tV = temporalVariable.Row(0); reflectanceValues = ReflectanceFunction(op.AsEnumerable(), sV.AsEnumerable(), tV).ToArray(); LocalWriteArrayToBinary(reflectanceValues, @"Output/" + sDT.ToString() + "/" + tDT.ToString() + "/" + fST.ToString() + "/" + "musp" + op.Musp.ToString() + "mua" + op.Mua.ToString(), FileMode.Create); for (int spaceInd = 1; spaceInd < spatialVariable.Count(); spaceInd++) { sV = spatialVariable.ElementAt(spaceInd); tV = temporalVariable.Row(spaceInd); reflectanceValues = ReflectanceFunction(op.AsEnumerable(), sV.AsEnumerable(), tV).ToArray(); LocalWriteArrayToBinary(reflectanceValues, @"Output/" + sDT.ToString() + "/" + tDT.ToString() + "/" + fST.ToString() + "/" + "musp" + op.Musp.ToString() + "mua" + op.Mua.ToString(), FileMode.Append); } }
private string[] GetLegendLabels(PlotDataType datatype) { string solverString = null; OpticalProperties opticalProperties = null; string modelString = null; ForwardSolverType forwardSolver; switch (datatype) { case PlotDataType.Simulated: solverString = "\nSimulated:"; opticalProperties = MeasuredOpticalPropertyVM.GetOpticalProperties(); forwardSolver = MeasuredForwardSolverTypeOptionVM.SelectedValue; break; case PlotDataType.Calculated: solverString = "\nCalculated:"; opticalProperties = ResultOpticalPropertyVM.GetOpticalProperties(); forwardSolver = MeasuredForwardSolverTypeOptionVM.SelectedValue; break; case PlotDataType.Guess: solverString = "\nGuess:"; opticalProperties = InitialGuessOpticalPropertyVM.GetOpticalProperties(); forwardSolver = InverseForwardSolverTypeOptionVM.SelectedValue; break; default: throw new ArgumentOutOfRangeException("datatype"); } var opString = "\rμa=" + opticalProperties.Mua.ToString("F4") + " \rμs'=" + opticalProperties.Musp.ToString("F4"); switch (forwardSolver) { case ForwardSolverType.DistributedGaussianSourceSDA: case ForwardSolverType.DistributedPointSourceSDA: case ForwardSolverType.PointSourceSDA: modelString = "\rModel - SDA"; break; case ForwardSolverType.MonteCarlo: modelString = "\rModel - scaled MC"; break; case ForwardSolverType.Nurbs: modelString = "\rModel - nurbs"; break; case ForwardSolverType.TwoLayerSDA: modelString = "\rModel - 2 layer SDA"; break; } if (_allRangeVMs.Length > 1) { var isWavelengthPlot = _allRangeVMs.Any(vm => vm.AxisType == IndependentVariableAxis.Wavelength); var secondaryRangeVM = isWavelengthPlot ? _allRangeVMs.Where(vm => vm.AxisType != IndependentVariableAxis.Wavelength).First() : _allRangeVMs.Where(vm => vm.AxisType != IndependentVariableAxis.Time && vm.AxisType != IndependentVariableAxis.Ft).First(); string[] secondaryAxesStrings = secondaryRangeVM.Values.Select(value => "\r" + secondaryRangeVM.AxisType.GetInternationalizedString() + " = " + value.ToString()).ToArray(); return secondaryAxesStrings.Select(sas => solverString + modelString + sas + (isWavelengthPlot ? "\r(spectral μa,μs')" : opString)).ToArray(); } return new []{ solverString + modelString + opString }; }
/// <summary> /// CaplessCylinderTissueRegion assumes cylinder axis is parallel with z-axis /// </summary> /// <param name="center">center position</param> /// <param name="radius">radius in x-y plane</param> /// <param name="height">height along z axis</param> /// <param name="op">optical properties of cylinder</param> public CaplessCylinderTissueRegion(Position center, double radius, double height, OpticalProperties op) { TissueRegionType = "CaplessCylinder"; Center = center; Radius = radius; Height = height; RegionOP = op; }
private IEnumerable <double> ROfRho(ForwardSolverType fst, OpticalProperties op, DoubleRange rho) { var ops = op.AsEnumerable(); var rhos = rho.AsEnumerable(); var fs = Factories.SolverFactory.GetForwardSolver(fst); return(fs.ROfRho(ops, rhos)); }
/// <summary> /// constructor for voxel region /// </summary> /// <param name="x">x range of voxel</param> /// <param name="y">y range of voxel</param> /// <param name="z">z range of voxel</param> /// <param name="op">optical properties of voxel</param> public VoxelTissueRegion(DoubleRange x, DoubleRange y, DoubleRange z, OpticalProperties op) { TissueRegionType = "Voxel"; X = x; Y = y; Z = z; RegionOP = op; }
/// <summary> /// CylinderTissueRegion assumes cylinder axis is parallel with z-axis /// </summary> /// <param name="center">center position</param> /// <param name="radius">radius in x-y plane</param> /// <param name="height">height along z axis</param> /// <param name="op">optical properties of cylinder</param> /// <param name="awt">absorption weighting type</param> public CylinderTissueRegion(Position center, double radius, double height, OpticalProperties op, AbsorptionWeightingType awt) { TissueRegionType = "Cylinder"; Center = center; Radius = radius; Height = height; RegionOP = op; }
private IEnumerable <Complex> ROfFxAndFt(ForwardSolverType fst, OpticalProperties op, double fx, DoubleRange ft) { var ops = op.AsEnumerable(); var fxs = fx.AsEnumerable(); var fts = ft.AsEnumerable(); var fs = Factories.SolverFactory.GetForwardSolver(fst); return(fs.ROfFxAndFt(ops, fxs, fts)); }
private IEnumerable <double> ROfFxAndTime(ForwardSolverType fst, OpticalProperties op, double fx, DoubleRange time) { var ops = op.AsEnumerable(); var fxs = fx.AsEnumerable(); var times = time.AsEnumerable(); var fs = Factories.SolverFactory.GetForwardSolver(fst); return(fs.ROfFxAndTime(ops, fxs, times)); }
public void validate_GetScatterLength_returns_correct_values() { var op = new OpticalProperties(0.1, 1.0, 0.9, 1.4); // note mus = 1.0/(1-0.9) = 10 double result = op.GetScatterLength(AbsorptionWeightingType.Analog); Assert.Less(System.Math.Abs(result - 10.1), 1e-6); result = op.GetScatterLength(AbsorptionWeightingType.Discrete); Assert.Less(System.Math.Abs(result - 10.1), 1e-6); result = op.GetScatterLength(AbsorptionWeightingType.Continuous); Assert.Less(System.Math.Abs(result - 10.0), 1e-6); }
/// <summary> /// class specifies ellipsoid tissue region (x-xc)^2/a^2 + (y-yc)^2/b^2 + (z-zc)^2/c^2 = 1 /// where center is (xc,yc,zc) and semi-axis along x-, y-, z- axes are a, b, c, respectively. /// </summary> /// <param name="center">Position (x,y,z) of the center of the ellipsoid</param> /// <param name="radiusX">semi-axis along x-axis</param> /// <param name="radiusY">semi-axis along y-axis</param> /// <param name="radiusZ">semi-axis along z-axis</param> /// <param name="op">OpticalProperties of ellipsoid</param> public EllipsoidTissueRegion(Position center, double radiusX, double radiusY, double radiusZ, OpticalProperties op) { TissueRegionType = "Ellipsoid"; RegionOP = op; Center = center; Dx = radiusX; Dy = radiusY; Dz = radiusZ; }
public void ROfRhoAndT_TimeValueSmallerThenMinimalTimeOfFlight_ReturnsZero() { INurbs fakeNurbsGenerator = new StubNurbsGenerator(); nurbsForwardSolver = new NurbsForwardSolver(fakeNurbsGenerator); OpticalProperties op = new OpticalProperties(0.0, 1.0, 0.8, 1.4); Assert.AreEqual(0.0, nurbsForwardSolver.ROfRhoAndTime(op, 10.0, 0.01), "The returned value should be 0.0"); }
/// <summary> /// Returns the optical properties for a given wavelength /// </summary> /// <param name="wavelengths">Wavelength</param> /// <returns>The optical properties</returns> public OpticalProperties[] GetOpticalProperties(double[] wavelengths) { var opArray = new OpticalProperties[wavelengths.Length]; for (int i = 0; i < wavelengths.Length; i++) { opArray[i] = GetOpticalProperties(wavelengths[i]); } return(opArray); }
public static OpticalProperties[] UnFlattenOpticalProperties(double[] ops) { var nOp = ops.Length / 4; var opArray = new OpticalProperties[nOp]; for (int opi = 0; opi < nOp; opi++) { opArray[opi] = new OpticalProperties(ops[opi * 4], ops[opi * 4 + 1], ops[opi * 4 + 2], ops[opi * 4 + 3]); } return(opArray); }
public OpticalPropertyViewModel(OpticalProperties opticalProperties, string units, string title, bool enableMua, bool enableMusp, bool enableG, bool enableN) { OpticalProperties = opticalProperties; Units = units; Title = title; _enableMua = enableMua; _enableMusp = enableMusp; _enableG = enableG; _enableN = enableN; }
/// <summary> /// Helper method. /// </summary> /// <returns></returns> public void SetOpticalProperties(OpticalProperties op) { OpticalProperties.Mua = op.Mua; OpticalProperties.Musp = op.Musp; OpticalProperties.G = op.G; OpticalProperties.N = op.N; OnPropertyChanged("Mua"); OnPropertyChanged("Musp"); OnPropertyChanged("G"); OnPropertyChanged("N"); }
private IEnumerable <double> ROfRho(ForwardSolverType forwardSolverType, OpticalProperties opticalProperties, DoubleRange rho, double noise) { var ops = opticalProperties.AsEnumerable(); var rhos = rho.AsEnumerable(); var fs = SolverFactory.GetForwardSolver(forwardSolverType); if (noise > 0.0) { return(fs.ROfRho(ops, rhos).AddNoise(noise)); } return(fs.ROfRho(ops, rhos)); }
private object GetTissueInputVM(string tissueType) { // ops to use as the basis for instantiating multi-region tissues based on homogeneous values (for differential comparison) if (_currentHomogeneousOpticalProperties == null) { _currentHomogeneousOpticalProperties = new OpticalProperties(0.01, 1, 0.8, 1.4); } switch (tissueType) { case "SemiInfinite": if (_currentSemiInfiniteTissueInput == null) { _currentSemiInfiniteTissueInput = new SemiInfiniteTissueInput( new SemiInfiniteTissueRegion(_currentHomogeneousOpticalProperties)); } return(new OpticalPropertyViewModel( _currentSemiInfiniteTissueInput.Regions.First().RegionOP, IndependentVariableAxisUnits.InverseMM.GetInternationalizedString(), StringLookup.GetLocalizedString("Heading_OpticalProperties"))); case "MultiLayer": if (_currentMultiLayerTissueInput == null) { _currentMultiLayerTissueInput = new MultiLayerTissueInput(new ITissueRegion[] { new LayerTissueRegion(new DoubleRange(0, 2), _currentHomogeneousOpticalProperties.Clone()), new LayerTissueRegion(new DoubleRange(2, double.PositiveInfinity), _currentHomogeneousOpticalProperties.Clone()) }); } return(new MultiRegionTissueViewModel(_currentMultiLayerTissueInput)); case "SingleEllipsoid": if (_currentSingleEllipsoidTissueInput == null) { _currentSingleEllipsoidTissueInput = new SingleEllipsoidTissueInput( new EllipsoidTissueRegion(new Position(0, 0, 10), 5, 5, 5, new OpticalProperties(0.05, 1.0, 0.8, 1.4)), new ITissueRegion[] { new LayerTissueRegion(new DoubleRange(0, double.PositiveInfinity), _currentHomogeneousOpticalProperties.Clone()) }); } return(new MultiRegionTissueViewModel(_currentSingleEllipsoidTissueInput)); default: throw new ArgumentOutOfRangeException(nameof(tissueType)); } }
public void validate_deserialization_of_OpticalProperties() { Func <double, double, bool> areRoughlyEqual = (a, b) => Math.Abs(a - b) < 0.001; var op = new OpticalProperties(0.011, 1.1, 0.99, 1.44); var jsonSerialized = VtsJsonSerializer.WriteToJson(op); var opDeserialized = VtsJsonSerializer.ReadFromJson <OpticalProperties>(jsonSerialized); Assert.IsTrue(opDeserialized != null); Assert.IsTrue(areRoughlyEqual(opDeserialized.Mua, 0.011)); Assert.IsTrue(areRoughlyEqual(opDeserialized.Musp, 1.1)); Assert.IsTrue(areRoughlyEqual(opDeserialized.G, 0.99)); Assert.IsTrue(areRoughlyEqual(opDeserialized.N, 1.44)); }
/// <summary> /// Method to determine scattering length given the absorption weighting type /// </summary> /// <param name="op">optical properties</param> /// <param name="awt">absorption weighting type</param> /// <returns>scatter length</returns> public static double GetScatterLength(this OpticalProperties op, AbsorptionWeightingType awt) { switch (awt) { default: case AbsorptionWeightingType.Discrete: case AbsorptionWeightingType.Analog: return(op.Mua + op.Mus); case AbsorptionWeightingType.Continuous: return(op.Mus); } }