public void validate_CircularAngledFromCircle_source()
        {
            Random  rng             = new MathNet.Numerics.Random.MersenneTwister(0); // not really necessary here, as this is now the default
            ITissue tissue          = new MultiLayerTissue();
            var     _profile        = new FlatSourceProfile();
            var     _radiusOnTissue = 10.0;
            var     _radiusInAir    = 0.0;
            var     _circleInAirTranslationFromOrigin = new Position(0, 0, -10);

            var ps = new CircularAngledFromCircleSource(
                _radiusOnTissue,
                _profile,
                _radiusInAir,
                _circleInAirTranslationFromOrigin)
            {
                Rng = rng
            };
            var photon = ps.GetNextPhoton(tissue);

            // make sure initial position is at tissue surface
            Assert.AreEqual(photon.DP.Position.Z, 0.0);
            // make sure initial position is inside radius
            Assert.IsTrue(Math.Sqrt(photon.DP.Position.X * photon.DP.Position.X +
                                    photon.DP.Position.Y * photon.DP.Position.Y) <= _radiusOnTissue);
            // make sure angle is less than 45 degrees
            Assert.IsTrue(photon.DP.Direction.Uz >= 1 / Math.Sqrt(2));
        }
        public void validate_CircularAngledFromPoint_source()
        {
            Random  rng                    = new MathNet.Numerics.Random.MersenneTwister(0); // not really necessary here, as this is now the default
            ITissue tissue                 = new MultiLayerTissue();
            var     profile                = new FlatSourceProfile();
            var     _radius                = 1.0;
            var     _pointLocation         = new Position(0, 0, -1); // put directly above
            var     _translationFromOrigin = new Position(0, 0, 0);

            var ps = new CircularAngledFromPointSource(_radius, profile, _pointLocation, _translationFromOrigin)
            {
                Rng = rng
            };
            var photon = ps.GetNextPhoton(tissue);

            // make sure initial position is at tissue surface
            Assert.AreEqual(photon.DP.Position.Z, 0.0);
            // make sure initial position is inside radius
            Assert.IsTrue(Math.Sqrt(
                              (photon.DP.Position.X - _translationFromOrigin.X) *
                              (photon.DP.Position.X - _translationFromOrigin.X) +
                              (photon.DP.Position.Y - _translationFromOrigin.Y) *
                              (photon.DP.Position.Y - _translationFromOrigin.Y)) <= _radius);
            // make sure angle is less than 45 degrees
            Assert.IsTrue(photon.DP.Direction.Uz >= 1 / Math.Sqrt(2));
        }
        public void validate_LineAngledFromLineSource_general_constructor()
        {
            var tissue = new MultiLayerTissue();
            var source = new LineAngledFromLineSource(
                10.0,                    // tissue line length
                new FlatSourceProfile(),
                1.0,                     // line in air length
                new Position(0, 0, -10), // center of line in air
                0);
            var photon = source.GetNextPhoton(tissue);

            // Position.X will be random between [-5 5] and Y and Z should be 0
            Assert.IsTrue(photon.DP.Position.X < 5);
            Assert.IsTrue(photon.DP.Position.X > -5);
            Assert.AreEqual(photon.DP.Position.Y, 0.0);
            Assert.AreEqual(photon.DP.Position.Z, 0.0);
            // Direction.Ux,Uz will be random but Uy should be 0
            Assert.AreEqual(photon.DP.Direction.Uy, 0.0);
        }
Exemple #4
0
        public void validate_general_constructor_with_flat_profiletype_for_directional_point_source_test()
        {
            Random  rng    = new MathNet.Numerics.Random.MersenneTwister(0); // not really necessary here, as this is now the default
            ITissue tissue = new MultiLayerTissue();                         // todo: remove

            var ps = new DirectionalPointSource(_direction, _translation)
            {
                Rng = rng
            };

            var photon = ps.GetNextPhoton(tissue);

            Assert.Less(Math.Abs(photon.DP.Direction.Ux - _tp[22]), ACCEPTABLE_PRECISION);
            Assert.Less(Math.Abs(photon.DP.Direction.Uy - _tp[23]), ACCEPTABLE_PRECISION);
            Assert.Less(Math.Abs(photon.DP.Direction.Uz - _tp[24]), ACCEPTABLE_PRECISION);

            Assert.Less(Math.Abs(photon.DP.Position.X - _tp[25]), ACCEPTABLE_PRECISION);
            Assert.Less(Math.Abs(photon.DP.Position.Y - _tp[26]), ACCEPTABLE_PRECISION);
            Assert.Less(Math.Abs(photon.DP.Position.Z - _tp[27]), ACCEPTABLE_PRECISION);
        }
Exemple #5
0
        public void validate_general_constructor_with_gaussian_profiletype_for_isotropic_line_source_test()
        {
            Random  rng    = new MathNet.Numerics.Random.MersenneTwister(0); // not really necessary here, as this is now the default
            ITissue tissue = new MultiLayerTissue();

            var ps = new IsotropicLineSource(_lengthX, _bdFWHM, _direction, _translation, _angPair)
            {
                Rng = rng
            };

            var photon = ps.GetNextPhoton(tissue);

            Assert.Less(Math.Abs(photon.DP.Direction.Ux - _tp[48]), ACCEPTABLE_PRECISION);
            Assert.Less(Math.Abs(photon.DP.Direction.Uy - _tp[49]), ACCEPTABLE_PRECISION);
            Assert.Less(Math.Abs(photon.DP.Direction.Uz - _tp[50]), ACCEPTABLE_PRECISION);

            Assert.Less(Math.Abs(photon.DP.Position.X - _tp[51]), ACCEPTABLE_PRECISION);
            Assert.Less(Math.Abs(photon.DP.Position.Y - _tp[52]), ACCEPTABLE_PRECISION);
            Assert.Less(Math.Abs(photon.DP.Position.Z - _tp[53]), ACCEPTABLE_PRECISION);
        }
        public void validate_general_constructor_with_gaussian_profiletype_for_directional_rectangular_source_test()
        {
            Random  rng    = new MathNet.Numerics.Random.MersenneTwister(0); // not really necessary here, as this is now the default
            ITissue tissue = new MultiLayerTissue();

            var ps = new DirectionalRectangularSource(_polarAngle, _lengthX, _widthY, _bdFWHM, _direction, _translation, _angPair)
            {
                Rng = rng
            };

            var photon = ps.GetNextPhoton(tissue);

            Assert.Less(Math.Abs(photon.DP.Direction.Ux - _tp[91]), ACCEPTABLE_PRECISION);
            Assert.Less(Math.Abs(photon.DP.Direction.Uy - _tp[92]), ACCEPTABLE_PRECISION);
            Assert.Less(Math.Abs(photon.DP.Direction.Uz - _tp[93]), ACCEPTABLE_PRECISION);

            Assert.Less(Math.Abs(photon.DP.Position.X - _tp[94]), ACCEPTABLE_PRECISION);
            Assert.Less(Math.Abs(photon.DP.Position.Y - _tp[95]), ACCEPTABLE_PRECISION);
            Assert.Less(Math.Abs(photon.DP.Position.Z - _tp[96]), ACCEPTABLE_PRECISION);
        }
        public void validate_general_constructor_with_gaussian_profiletype_for_custom_elliptical_source_test()
        {
            Random  rng    = new MathNet.Numerics.Random.MersenneTwister(0); // not really necessary here, as this is now the default
            ITissue tissue = new MultiLayerTissue();

            var ps = new CustomEllipticalSource(_aParameter, _bParameter, _bdFWHM, _polRange, _aziRange, _direction, _translation, _angPair)
            {
                Rng = rng
            };

            var photon = ps.GetNextPhoton(tissue);

            Assert.Less(Math.Abs(photon.DP.Direction.Ux - _tp[55]), ACCEPTABLE_PRECISION);
            Assert.Less(Math.Abs(photon.DP.Direction.Uy - _tp[56]), ACCEPTABLE_PRECISION);
            Assert.Less(Math.Abs(photon.DP.Direction.Uz - _tp[57]), ACCEPTABLE_PRECISION);

            Assert.Less(Math.Abs(photon.DP.Position.X - _tp[58]), ACCEPTABLE_PRECISION);
            Assert.Less(Math.Abs(photon.DP.Position.Y - _tp[59]), ACCEPTABLE_PRECISION);
            Assert.Less(Math.Abs(photon.DP.Position.Z - _tp[60]), ACCEPTABLE_PRECISION);
        }
Exemple #8
0
        public void validate_general_constructor_with_flat_profiletype_for_directional_line_source_test()
        {
            Random  rng              = new MathNet.Numerics.Random.MersenneTwister(0); // not really necessary here, as this is now the default
            ITissue tissue           = new MultiLayerTissue();
            var     beamDiameterFWHM = -1.0;                                           // flat profile

            var ps = new DirectionalLineSource(_polarAngle, _lengthX, beamDiameterFWHM, _direction, _translation, _angPair)
            {
                Rng = rng
            };

            var photon = ps.GetNextPhoton(tissue);

            Assert.Less(Math.Abs(photon.DP.Direction.Ux - _tp[30]), ACCEPTABLE_PRECISION);
            Assert.Less(Math.Abs(photon.DP.Direction.Uy - _tp[31]), ACCEPTABLE_PRECISION);
            Assert.Less(Math.Abs(photon.DP.Direction.Uz - _tp[32]), ACCEPTABLE_PRECISION);

            Assert.Less(Math.Abs(photon.DP.Position.X - _tp[33]), ACCEPTABLE_PRECISION);
            Assert.Less(Math.Abs(photon.DP.Position.Y - _tp[34]), ACCEPTABLE_PRECISION);
            Assert.Less(Math.Abs(photon.DP.Position.Z - _tp[35]), ACCEPTABLE_PRECISION);
        }
Exemple #9
0
        public void validate_general_constructor_with_gaussian_profiletype_for_custom_line_source_test()
        {
            Random  rng     = new MathNet.Numerics.Random.MersenneTwister(0); // not really necessary here, as this is now the default
            ITissue tissue  = new MultiLayerTissue();
            var     profile = new GaussianSourceProfile(_bdFWHM);


            var ps = new CustomLineSource(_lengthX, profile, _polRange, _aziRange, _direction, _translation, _angPair)
            {
                Rng = rng
            };

            var photon = ps.GetNextPhoton(tissue);

            Assert.Less(Math.Abs(photon.DP.Direction.Ux - _tp[24]), ACCEPTABLE_PRECISION);
            Assert.Less(Math.Abs(photon.DP.Direction.Uy - _tp[25]), ACCEPTABLE_PRECISION);
            Assert.Less(Math.Abs(photon.DP.Direction.Uz - _tp[26]), ACCEPTABLE_PRECISION);

            Assert.Less(Math.Abs(photon.DP.Position.X - _tp[27]), ACCEPTABLE_PRECISION);
            Assert.Less(Math.Abs(photon.DP.Position.Y - _tp[28]), ACCEPTABLE_PRECISION);
            Assert.Less(Math.Abs(photon.DP.Position.Z - _tp[29]), ACCEPTABLE_PRECISION);
        }
        public void validate_general_constructor_with_flat_profiletype_for_custom_rectangular_source_test()
        {
            read_data();

            Random  rng              = new MathNet.Numerics.Random.MersenneTwister(0); // not really necessary here, as this is now the default
            ITissue tissue           = new MultiLayerTissue();
            var     beamDiameterFWHM = -1.0;                                           // flat beam

            var ps = new CustomRectangularSource(_lengthX, _widthY, beamDiameterFWHM, _polRange, _aziRange, _direction, _translation, _angPair)
            {
                Rng = rng
            };

            var photon = ps.GetNextPhoton(tissue);

            Assert.Less(Math.Abs(photon.DP.Direction.Ux - _tp[73]), ACCEPTABLE_PRECISION);
            Assert.Less(Math.Abs(photon.DP.Direction.Uy - _tp[74]), ACCEPTABLE_PRECISION);
            Assert.Less(Math.Abs(photon.DP.Direction.Uz - _tp[75]), ACCEPTABLE_PRECISION);

            Assert.Less(Math.Abs(photon.DP.Position.X - _tp[76]), ACCEPTABLE_PRECISION);
            Assert.Less(Math.Abs(photon.DP.Position.Y - _tp[77]), ACCEPTABLE_PRECISION);
            Assert.Less(Math.Abs(photon.DP.Position.Z - _tp[78]), ACCEPTABLE_PRECISION);
        }
        public void validate_general_constructor_with_flat_profiletype_for_custom_circular_source_test()
        {
            read_data();

            Random  rng     = new MathNet.Numerics.Random.MersenneTwister(0); // not really necessary here, as this is now the default
            ITissue tissue  = new MultiLayerTissue();
            var     profile = new FlatSourceProfile();


            var ps = new CustomCircularSource(_outRad, _inRad, profile, _polRange, _aziRange, _direction, _translation, _angPair)
            {
                Rng = rng
            };

            var photon = ps.GetNextPhoton(tissue);

            Assert.Less(Math.Abs(photon.DP.Direction.Ux - _tp[25]), ACCEPTABLE_PRECISION);
            Assert.Less(Math.Abs(photon.DP.Direction.Uy - _tp[26]), ACCEPTABLE_PRECISION);
            Assert.Less(Math.Abs(photon.DP.Direction.Uz - _tp[27]), ACCEPTABLE_PRECISION);

            Assert.Less(Math.Abs(photon.DP.Position.X - _tp[28]), ACCEPTABLE_PRECISION);
            Assert.Less(Math.Abs(photon.DP.Position.Y - _tp[29]), ACCEPTABLE_PRECISION);
            Assert.Less(Math.Abs(photon.DP.Position.Z - _tp[30]), ACCEPTABLE_PRECISION);
        }
        public void validate_general_constructor_with_flat_profiletype_for_directional_elliptical_source_test()
        {
            read_data();

            Random  rng     = new MathNet.Numerics.Random.MersenneTwister(0); // not really necessary here, as this is now the default
            ITissue tissue  = new MultiLayerTissue();
            var     profile = new FlatSourceProfile();


            var ps = new DirectionalEllipticalSource(_polarAngle, _aParameter, _bParameter, profile, _direction, _translation, _angPair)
            {
                Rng = rng
            };

            var photon = ps.GetNextPhoton(tissue);

            Assert.Less(Math.Abs(photon.DP.Direction.Ux - _tp[61]), ACCEPTABLE_PRECISION);
            Assert.Less(Math.Abs(photon.DP.Direction.Uy - _tp[62]), ACCEPTABLE_PRECISION);
            Assert.Less(Math.Abs(photon.DP.Direction.Uz - _tp[63]), ACCEPTABLE_PRECISION);

            Assert.Less(Math.Abs(photon.DP.Position.X - _tp[64]), ACCEPTABLE_PRECISION);
            Assert.Less(Math.Abs(photon.DP.Position.Y - _tp[65]), ACCEPTABLE_PRECISION);
            Assert.Less(Math.Abs(photon.DP.Position.Z - _tp[66]), ACCEPTABLE_PRECISION);
        }
Exemple #13
0
        public void validate_ReflectedMTOfRhoAndSubregionHistDetector_deserialized_class_is_correct_when_using_WriteReadDetectorToFile()
        {
            string detectorName = "testreflectedmtofrhoandsubregionhist";
            var    tissue       = new MultiLayerTissue(
                new ITissueRegion[]
            {
                new LayerTissueRegion(
                    new DoubleRange(double.NegativeInfinity, 0.0),
                    new OpticalProperties(0.0, 1e-10, 1.0, 1.0)),
                new LayerTissueRegion(
                    new DoubleRange(0.0, 100.0),
                    new OpticalProperties(0.01, 1.0, 0.7, 1.33)),
                new LayerTissueRegion(
                    new DoubleRange(100.0, double.PositiveInfinity),
                    new OpticalProperties(0.0, 1e-10, 1.0, 1.0))
            }
                );
            IDetectorInput detectorInput = new ReflectedMTOfRhoAndSubregionHistDetectorInput()
            {
                Rho               = new DoubleRange(0, 10, 3),
                MTBins            = new DoubleRange(0, 10, 3),
                FractionalMTBins  = new DoubleRange(0, 1, 2),
                TallySecondMoment = true, // tally SecondMoment
                Name              = detectorName,
            };
            var detector = (ReflectedMTOfRhoAndSubregionHistDetector)detectorInput.CreateDetector();

            // need to initialize detector so that NumSubregions gets set
            detector.Initialize(tissue, null);
            // Mean has dimensions [Rho.Count - 1, MTBins.Count - 1]
            detector.Mean = new double[, ] {
                { 1, 2 }, { 3, 4 }
            };
            // FractionalMT has dimensions [Rho.Count - 1, MTBins.Count - 1, NumSubregions, FractionalMTBins.Count + 1]=[2,2,3,3]
            detector.FractionalMT = new double[, , , ] {
                { { { 1, 2, 3 }, { 4, 5, 6 }, { 7, 8, 9 } }, { { 10, 11, 12 }, { 13, 14, 15 }, { 16, 17, 18 } } }, { { { 19, 20, 21 }, { 22, 23, 24 }, { 25, 26, 27 } }, { { 28, 29, 30 }, { 31, 32, 33 }, { 34, 35, 36 } } }
            };

            DetectorIO.WriteDetectorToFile(detector, "");
            var dcloned = (ReflectedMTOfRhoAndSubregionHistDetector)DetectorIO.ReadDetectorFromFile(detectorName, "");

            Assert.AreEqual(dcloned.Name, detectorName);
            Assert.AreEqual(dcloned.Mean[0, 0], 1);
            Assert.AreEqual(dcloned.Mean[0, 1], 2);
            Assert.AreEqual(dcloned.Mean[1, 0], 3);
            Assert.AreEqual(dcloned.Mean[1, 1], 4);

            Assert.AreEqual(dcloned.FractionalMT[0, 0, 0, 0], 1);
            Assert.AreEqual(dcloned.FractionalMT[0, 0, 0, 1], 2);
            Assert.AreEqual(dcloned.FractionalMT[0, 0, 0, 2], 3);
            Assert.AreEqual(dcloned.FractionalMT[0, 0, 1, 0], 4);
            Assert.AreEqual(dcloned.FractionalMT[0, 0, 1, 1], 5);
            Assert.AreEqual(dcloned.FractionalMT[0, 0, 1, 2], 6);
            Assert.AreEqual(dcloned.FractionalMT[0, 0, 2, 0], 7);
            Assert.AreEqual(dcloned.FractionalMT[0, 0, 2, 1], 8);
            Assert.AreEqual(dcloned.FractionalMT[0, 0, 2, 2], 9);
            Assert.AreEqual(dcloned.FractionalMT[0, 1, 0, 0], 10);
            Assert.AreEqual(dcloned.FractionalMT[0, 1, 0, 1], 11);
            Assert.AreEqual(dcloned.FractionalMT[0, 1, 0, 2], 12);
            Assert.AreEqual(dcloned.FractionalMT[0, 1, 1, 0], 13);
            Assert.AreEqual(dcloned.FractionalMT[0, 1, 1, 1], 14);
            Assert.AreEqual(dcloned.FractionalMT[0, 1, 1, 2], 15);
            Assert.AreEqual(dcloned.FractionalMT[0, 1, 2, 0], 16);
            Assert.AreEqual(dcloned.FractionalMT[0, 1, 2, 1], 17);
            Assert.AreEqual(dcloned.FractionalMT[0, 1, 2, 2], 18);
            Assert.AreEqual(dcloned.FractionalMT[1, 0, 0, 0], 19);
            Assert.AreEqual(dcloned.FractionalMT[1, 0, 0, 1], 20);
            Assert.AreEqual(dcloned.FractionalMT[1, 0, 0, 2], 21);
            Assert.AreEqual(dcloned.FractionalMT[1, 0, 1, 0], 22);
            Assert.AreEqual(dcloned.FractionalMT[1, 0, 1, 1], 23);
            Assert.AreEqual(dcloned.FractionalMT[1, 0, 1, 2], 24);
            Assert.AreEqual(dcloned.FractionalMT[1, 0, 2, 0], 25);
            Assert.AreEqual(dcloned.FractionalMT[1, 0, 2, 1], 26);
            Assert.AreEqual(dcloned.FractionalMT[1, 0, 2, 2], 27);
            Assert.AreEqual(dcloned.FractionalMT[1, 1, 0, 0], 28);
            Assert.AreEqual(dcloned.FractionalMT[1, 1, 0, 1], 29);
            Assert.AreEqual(dcloned.FractionalMT[1, 1, 0, 2], 30);
            Assert.AreEqual(dcloned.FractionalMT[1, 1, 1, 0], 31);
            Assert.AreEqual(dcloned.FractionalMT[1, 1, 1, 1], 32);
            Assert.AreEqual(dcloned.FractionalMT[1, 1, 1, 2], 33);
            Assert.AreEqual(dcloned.FractionalMT[1, 1, 2, 0], 34);
            Assert.AreEqual(dcloned.FractionalMT[1, 1, 2, 1], 35);
            Assert.AreEqual(dcloned.FractionalMT[1, 1, 2, 2], 36);
        }