Exemple #1
0
        /// <summary>
        /// Implements Get next photon
        /// </summary>
        /// <param name="tissue">tissue</param>
        /// <returns>photon</returns>
        public Photon GetNextPhoton(ITissue tissue)
        {
            //Source starts at the origin
            Position finalPosition = SourceDefaults.DefaultPosition.Clone();

            // sample angular distribution
            Direction finalDirection = SourceToolbox.GetDirectionForGivenPolarAzimuthalAngleRangeRandom(
                _polarAngleEmissionRange,
                _azimuthalAngleEmissionRange,
                Rng);

            //Find the relevent polar and azimuthal pair for the direction
            _rotationalAnglesOfPrincipalSourceAxis = SourceToolbox.GetPolarAzimuthalPairFromDirection(_direction);

            //Rotation and translation
            SourceToolbox.UpdateDirectionPositionAfterGivenFlags(
                ref finalPosition,
                ref finalDirection,
                _rotationalAnglesOfPrincipalSourceAxis,
                _pointLocation,
                _rotationAndTranslationFlags);

            var photon = new Photon(finalPosition, finalDirection, 1.0, tissue, _initialTissueRegionIndex, Rng);

            return(photon);
        }
Exemple #2
0
 /// <summary>
 /// Returns direction for a given position
 /// </summary>
 /// <param name="position">position</param>
 /// <returns>new direction</returns>
 protected override Direction GetFinalDirection(Position position)
 {
     return(SourceToolbox.GetDirectionForGivenPolarAzimuthalAngleRangeRandom(
                _polarAngleEmissionRange,
                _azimuthalAngleEmissionRange,
                Rng));
 }
        /// <summary>
        /// Implements Get next photon
        /// </summary>
        /// <param name="tissue">tissue</param>
        /// <returns>photon</returns>
        public Photon GetNextPhoton(ITissue tissue)
        {
            // sample angular distribution
            Direction finalDirection = SourceToolbox.GetDirectionForGivenPolarAzimuthalAngleRangeRandom(_polarAngleRangeToDefineSphericalSurface, _azimuthalAngleRangeToDefineSphericalSurface, Rng);

            //Source starts from anywhere in the sphere
            Position finalPosition = GetFinalPositionFromProfileType(finalDirection, _radius, Rng);

            //Lambertian distribution (uniform hemispherical distribution)
            PolarAzimuthalAngles polarAzimuthalPair = SourceToolbox.GetPolarAzimuthalPairForGivenAngleRangeRandom(
                SourceDefaults.DefaultHalfPolarAngleRange.Clone(),
                SourceDefaults.DefaultAzimuthalAngleRange.Clone(),
                Rng);

            //Avoid updating the finalDirection during following rotation
            Position dummyPosition = finalPosition;

            //Rotate polar azimutahl angle by polarAzimuthalPair vector
            SourceToolbox.UpdateDirectionPositionAfterRotatingByGivenAnglePair(polarAzimuthalPair, ref finalDirection, ref dummyPosition);

            //Find the relevent polar and azimuthal pair for the direction
            PolarAzimuthalAngles _rotationalAnglesOfPrincipalSourceAxis = SourceToolbox.GetPolarAzimuthalPairFromDirection(_newDirectionOfPrincipalSourceAxis);

            //Translation and source rotation
            SourceToolbox.UpdateDirectionPositionAfterGivenFlags(
                ref finalPosition,
                ref finalDirection,
                _rotationalAnglesOfPrincipalSourceAxis,
                _translationFromOrigin,
                _rotationAndTranslationFlags);

            var photon = new Photon(finalPosition, finalDirection, 1.0, tissue, _initialTissueRegionIndex, Rng);

            return(photon);
        }
 /// <summary>
 /// Returns Lambertian direction - all fluorescence emission is Lambertian
 /// </summary>
 /// <returns>new direction</returns>
 private static Direction GetFinalDirection(Random rng)
 {
     //Lambertian distribution
     return(SourceToolbox.GetDirectionForGivenPolarAzimuthalAngleRangeRandom(
                SourceDefaults.DefaultFullPolarAngleRange.Clone(),
                SourceDefaults.DefaultAzimuthalAngleRange.Clone(),
                rng));
 }
        public void validate_static_method_getdirectionforgivenpolarazimuthalanglerangerandom()
        {
            Random rng = new MathNet.Numerics.Random.MersenneTwister(0);
            var    dir = SourceToolbox.GetDirectionForGivenPolarAzimuthalAngleRangeRandom(_polRange, _aziRange, rng);

            Assert.Less(Math.Abs(dir.Ux - _tp[34]), ACCEPTABLE_PRECISION);
            Assert.Less(Math.Abs(dir.Uy - _tp[35]), ACCEPTABLE_PRECISION);
            Assert.Less(Math.Abs(dir.Uz - _tp[36]), ACCEPTABLE_PRECISION);
        }
Exemple #6
0
        /// <summary>
        /// Implements Get next photon
        /// </summary>
        /// <param name="tissue">tissue</param>
        /// <returns>photon</returns>
        public Photon GetNextPhoton(ITissue tissue)
        {
            double curved = 2 * Math.PI * _fiberRadius * _fiberHeightZ * _curvedSurfaceEfficiency;
            double bottom = Math.PI * _fiberRadius * _fiberRadius * _bottomSurfaceEfficiency;

            Direction finalDirection = SourceToolbox.GetDirectionForGivenPolarAzimuthalAngleRangeRandom(
                        SourceDefaults.DefaultHalfPolarAngleRange.Clone(),
                        SourceDefaults.DefaultAzimuthalAngleRange.Clone(),
                        Rng);
            Position finalPosition = SourceDefaults.DefaultPosition.Clone();

            if (_fiberRadius > 0.0)
            {   
                if (Rng.NextDouble() > bottom / (curved + bottom))   //Consider 
                {   /* Curved surface */
                    // To utilize the final direction given above, we can assume a tube 
                    // parallel to the y-axis. We can rotate it about the x-axis by pi/2 
                    // to compute the new direction.
                    SourceToolbox.UpdateDirectionAfterRotatingAroundXAxis(-0.5 * Math.PI, finalDirection);

                    //Sample tube perimeter first to compute x and y coordinates
                    finalPosition = SourceToolbox.GetPositionAtCirclePerimeter(finalPosition,
                        _fiberRadius, 
                        Rng);

                    //Sample tube height to compute z coordinate
                    finalPosition.Z = _fiberHeightZ * (Rng.NextDouble() - 0.5);
                }
                else
                {   /* Bottom Surface */
                    //Shift finalPosition by _fiberHeightZ / 2
                    finalPosition = new Position(0.0, 0.0, _fiberHeightZ * 0.5);

                    //Sample the bottom face to find  x, y coordinates of the emission
                    finalPosition = SourceToolbox.GetPositionInACircleRandomFlat(finalPosition,
                        0.0,
                        _fiberRadius,
                        Rng);                    
                }
            }
 
            //Find the relevent polar and azimuthal pair for the direction
            PolarAzimuthalAngles _rotationalAnglesOfPrincipalSourceAxis = SourceToolbox.GetPolarAzimuthalPairFromDirection(_newDirectionOfPrincipalSourceAxis);
            
            //Translation and source rotation
            SourceToolbox.UpdateDirectionPositionAfterGivenFlags(
                ref finalPosition,
                ref finalDirection,
                _rotationalAnglesOfPrincipalSourceAxis,
                _translationFromOrigin,                
                _rotationAndTranslationFlags);

            var photon = new Photon(finalPosition, finalDirection, 1.0, tissue, _initialTissueRegionIndex, Rng);

            return photon;
        }
Exemple #7
0
        /// <summary>
        /// Returns direction for a given position
        /// </summary>
        /// <param name="position">position</param>
        /// <returns>new direction</returns>
        protected override Direction GetFinalDirection(Position position)
        {
            var azimuthalAngleEmissionRange = SourceDefaults.DefaultAzimuthalAngleRange.Clone();
            var polarAngleEmissionRange     = SourceDefaults.DefaultFullPolarAngleRange.Clone();

            //Sample angular distribution
            Direction finalDirection = SourceToolbox.GetDirectionForGivenPolarAzimuthalAngleRangeRandom(polarAngleEmissionRange, azimuthalAngleEmissionRange, Rng);

            return(finalDirection);
        }
Exemple #8
0
        /// <summary>
        /// Returns direction for a given position
        /// </summary>
        /// <param name="position">position</param>
        /// <returns>new direction</returns>
        protected override Direction GetFinalDirection(Position position)
        {
            if (_lineLength == 0.0)
            {
                return(SourceToolbox.GetDirectionForGivenPolarAzimuthalAngleRangeRandom(
                           new DoubleRange(0.0, Math.Abs(_thetaConvOrDiv)),
                           SourceDefaults.DefaultAzimuthalAngleRange.Clone(),
                           Rng));
            }

            // sign is negative for diverging and positive positive for converging
            var polarAngle = SourceToolbox.UpdatePolarAngleForDirectionalSources(
                0.5 * _lineLength,
                position.X,
                _thetaConvOrDiv);

            return(SourceToolbox.GetDirectionForGiven2DPositionAndGivenPolarAngle(polarAngle, position));
        }
 /// <summary>
 /// Returns direction for a given position
 /// </summary>
 /// <param name="position">position</param>
 /// <returns>new direction</returns>
 protected override Direction GetFinalDirection(Position position)
 {
     if ((_rectLengthX == 0.0) && (_rectWidthY == 0.0))
     {
         return(SourceToolbox.GetDirectionForGivenPolarAzimuthalAngleRangeRandom(
                    new DoubleRange(0.0, Math.Abs(_thetaConvOrDiv)),
                    SourceDefaults.DefaultAzimuthalAngleRange.Clone(),
                    Rng));
     }
     else
     {
         // sign is negative for diverging and positive positive for converging
         var polarAngle = SourceToolbox.UpdatePolarAngleForDirectionalSources(
             _rectLengthX,
             Math.Sqrt(position.X * position.X + position.Y * position.Y),
             _thetaConvOrDiv);
         return(SourceToolbox.GetDirectionForGiven2DPositionAndGivenPolarAngle(polarAngle, position));
     }
 }
        /// <summary>
        /// Implements Get next photon
        /// </summary>
        /// <param name="tissue">tissue</param>
        /// <returns>photon</returns>
        public Photon GetNextPhoton(ITissue tissue)
        {
            //sample angular distribution
            Direction finalDirection = SourceToolbox.GetDirectionForGivenPolarAzimuthalAngleRangeRandom(
                SourceDefaults.DefaultHalfPolarAngleRange.Clone(),
                SourceDefaults.DefaultAzimuthalAngleRange.Clone(),
                Rng);

            //Translate the photon to _tubeRadius length below the origin. Ring lies on yz plane.
            Position finalPosition = new Position(0.0, 0.0, _tubeRadius);

            //Sample a ring that emits photons outside.
            SourceToolbox.UpdateDirectionPositionAfterRotatingAroundXAxis(
                2.0 * Math.PI * Rng.NextDouble(),
                ref finalDirection,
                ref finalPosition);

            //Ring lies on xy plane. z= 0;
            SourceToolbox.UpdateDirectionPositionAfterRotatingAroundYAxis(
                0.5 * Math.PI,
                ref finalDirection,
                ref finalPosition);

            //Sample tube height
            finalPosition.Z = _tubeHeightZ * (2.0 * Rng.NextDouble() - 1.0);

            //Find the relevent polar and azimuthal pair for the direction
            PolarAzimuthalAngles _rotationalAnglesOfPrincipalSourceAxis = SourceToolbox.GetPolarAzimuthalPairFromDirection(_newDirectionOfPrincipalSourceAxis);

            //Translation and source rotation
            SourceToolbox.UpdateDirectionPositionAfterGivenFlags(
                ref finalPosition,
                ref finalDirection,
                _rotationalAnglesOfPrincipalSourceAxis,
                _translationFromOrigin,
                _rotationAndTranslationFlags);

            var photon = new Photon(finalPosition, finalDirection, tissue, _initialTissueRegionIndex, Rng);

            return(photon);
        }
        /// <summary>
        /// Implements Get next photon
        /// </summary>
        /// <param name="tissue">tissue</param>
        /// <returns>photon</returns>
        public Photon GetNextPhoton(ITissue tissue)
        {
            //sample angular distribution
            Direction finalDirection = SourceToolbox.GetDirectionForGivenPolarAzimuthalAngleRangeRandom(
                SourceDefaults.DefaultHalfPolarAngleRange.Clone(),
                SourceDefaults.DefaultAzimuthalAngleRange.Clone(),
                Rng);
            Position finalPosition = SourceDefaults.DefaultPosition.Clone();

            if (_tubeRadius > 0.0)
            {
                // To utilize the final direction given above, we can assume a tube
                // parallel to the y-axis. We can rotate it about the x-axis by pi/2
                // to compute the new direction.
                SourceToolbox.UpdateDirectionAfterRotatingAroundXAxis(0.5 * Math.PI, finalDirection);

                //Sample tube perimeter first to compute x and y coordinates
                finalPosition = SourceToolbox.GetPositionAtCirclePerimeter(finalPosition,
                                                                           _tubeRadius,
                                                                           Rng);

                //Sample tube height to compute z coordinate
                finalPosition.Z = _tubeHeightZ * (Rng.NextDouble() - 0.5);
            }

            //Find the relevent polar and azimuthal pair for the direction
            PolarAzimuthalAngles _rotationalAnglesOfPrincipalSourceAxis = SourceToolbox.GetPolarAzimuthalPairFromDirection(_newDirectionOfPrincipalSourceAxis);

            //Translation and source rotation
            SourceToolbox.UpdateDirectionPositionAfterGivenFlags(
                ref finalPosition,
                ref finalDirection,
                _rotationalAnglesOfPrincipalSourceAxis,
                _translationFromOrigin,
                _rotationAndTranslationFlags);

            var photon = new Photon(finalPosition, finalDirection, 1.0, tissue, _initialTissueRegionIndex, Rng);

            return(photon);
        }
        /// <summary>
        /// Implements Get next photon
        /// </summary>
        /// <param name="tissue">tissue</param>
        /// <returns>photon</returns>
        public Photon GetNextPhoton(ITissue tissue)
        {
            //Sample emitting side
            String cSide = SelectEmittingSurface(
                _cubeLengthX,
                _cubeWidthY,
                _cubeHeightZ,
                Rng);

            //sample angular distribution
            Direction finalDirection = SourceToolbox.GetDirectionForGivenPolarAzimuthalAngleRangeRandom(
                _polarAngleEmissionRange,
                SourceDefaults.DefaultAzimuthalAngleRange.Clone(),
                Rng);

            Position tempPosition  = null;
            Position finalPosition = null;

            switch (cSide)
            {
            case "xpos":
                tempPosition    = GetFinalPosition(_beamDiameterFWHM, _cubeHeightZ, _cubeWidthY, Rng);
                finalPosition.X = 0.5 * _cubeLengthX;
                finalPosition.Y = tempPosition.Y;
                finalPosition.Z = tempPosition.X;
                finalDirection  = SourceToolbox.UpdateDirectionAfterRotatingAroundXAxis(0.5 * Math.PI, finalDirection);
                break;

            case "xneg":
                tempPosition    = GetFinalPosition(_beamDiameterFWHM, _cubeHeightZ, _cubeWidthY, Rng);
                finalPosition.X = -0.5 * _cubeLengthX;
                finalPosition.Y = tempPosition.Y;
                finalPosition.Z = tempPosition.X;
                finalDirection  = SourceToolbox.UpdateDirectionAfterRotatingAroundXAxis(-0.5 * Math.PI, finalDirection);
                break;

            case "ypos":
                tempPosition    = GetFinalPosition(_beamDiameterFWHM, _cubeLengthX, _cubeHeightZ, Rng);
                finalPosition.X = tempPosition.X;
                finalPosition.Y = 0.5 * _cubeWidthY;
                finalPosition.Z = tempPosition.Y;
                finalDirection  = SourceToolbox.UpdateDirectionAfterRotatingAroundYAxis(0.5 * Math.PI, finalDirection);
                break;

            case "yneg":
                tempPosition    = GetFinalPosition(_beamDiameterFWHM, _cubeLengthX, _cubeHeightZ, Rng);
                finalPosition.X = tempPosition.X;
                finalPosition.Y = -0.5 * _cubeWidthY;
                finalPosition.Z = tempPosition.Y;
                finalDirection  = SourceToolbox.UpdateDirectionAfterRotatingAroundYAxis(-0.5 * Math.PI, finalDirection);
                break;

            case "zpos":
                tempPosition    = GetFinalPosition(_beamDiameterFWHM, _cubeLengthX, _cubeWidthY, Rng);
                finalPosition.X = tempPosition.X;
                finalPosition.Y = tempPosition.Y;
                finalPosition.Z = 0.5 * _cubeHeightZ;
                break;

            case "zneg":
                tempPosition    = GetFinalPosition(_beamDiameterFWHM, _cubeLengthX, _cubeWidthY, Rng);
                finalPosition.X = tempPosition.X;
                finalPosition.Y = tempPosition.Y;
                finalPosition.Z = -0.5 * _cubeHeightZ;
                //reverse signs
                finalDirection.Uz = -finalDirection.Uz;
                break;
            }

            //Find the relevent polar and azimuthal pair for the direction
            PolarAzimuthalAngles _rotationalAnglesOfPrincipalSourceAxis = SourceToolbox.GetPolarAzimuthalPairFromDirection(_newDirectionOfPrincipalSourceAxis);

            //Translation and source rotation
            SourceToolbox.UpdateDirectionPositionAfterGivenFlags(
                ref finalPosition,
                ref finalDirection,
                _rotationalAnglesOfPrincipalSourceAxis,
                _translationFromOrigin,
                _rotationAndTranslationFlags);

            var photon = new Photon(finalPosition, finalDirection, tissue, _initialTissueRegionIndex, Rng);

            return(photon);
        }
        /// <summary>
        /// Implements Get next photon
        /// </summary>
        /// <param name="tissue">tissue</param>
        /// <returns>photon</returns>
        public Photon GetNextPhoton(ITissue tissue)
        {
            double curved = 2 * Math.PI * _fiberRadius * _fiberHeightZ * _curvedSurfaceEfficiency;
            double bottom = Math.PI * _fiberRadius * _fiberRadius * _bottomSurfaceEfficiency;

            Direction finalDirection;
            Position  finalPosition;

            if (_fiberRadius > 0.0)
            {
                if (Rng.NextDouble() > bottom / (curved + bottom))
                {
                    //sample angular distribution
                    finalDirection = SourceToolbox.GetDirectionForGivenPolarAzimuthalAngleRangeRandom(
                        SourceDefaults.DefaultHalfPolarAngleRange.Clone(),
                        SourceDefaults.DefaultAzimuthalAngleRange.Clone(),
                        Rng);

                    //Translate the photon to _tubeRadius length below the origin. Ring lies on yz plane.
                    finalPosition = new Position(0.0, 0.0, _fiberRadius);

                    //Sample a ring that emits photons outside.
                    SourceToolbox.UpdateDirectionPositionAfterRotatingAroundXAxis(
                        2.0 * Math.PI * Rng.NextDouble(),
                        ref finalDirection,
                        ref finalPosition);

                    //Ring lies on xy plane. z= 0;
                    SourceToolbox.UpdateDirectionPositionAfterRotatingAroundYAxis(
                        0.5 * Math.PI,
                        ref finalDirection,
                        ref finalPosition);

                    //Sample tube height
                    finalPosition.Z = _fiberHeightZ * (2.0 * Rng.NextDouble() - 1.0);
                }
                else
                {
                    finalPosition = SourceToolbox.GetPositionInACircleRandomFlat(
                        SourceDefaults.DefaultPosition.Clone(),
                        0.0,
                        _fiberRadius,
                        Rng);

                    finalDirection = SourceToolbox.GetDirectionForGivenPolarAzimuthalAngleRangeRandom(
                        SourceDefaults.DefaultHalfPolarAngleRange.Clone(),
                        SourceDefaults.DefaultAzimuthalAngleRange.Clone(),
                        Rng);
                }
            }
            else
            {
                finalPosition = SourceToolbox.GetPositionInALineRandomFlat(
                    SourceDefaults.DefaultPosition.Clone(),
                    _fiberHeightZ,
                    Rng);

                finalDirection = SourceToolbox.GetDirectionForGivenPolarAzimuthalAngleRangeRandom(
                    SourceDefaults.DefaultFullPolarAngleRange.Clone(),
                    SourceDefaults.DefaultAzimuthalAngleRange.Clone(),
                    Rng);

                //Rotate 90degrees around y axis
                SourceToolbox.UpdateDirectionPositionAfterRotatingAroundYAxis(
                    0.5 * Math.PI,
                    ref finalDirection,
                    ref finalPosition);
            }


            //Find the relevent polar and azimuthal pair for the direction
            PolarAzimuthalAngles _rotationalAnglesOfPrincipalSourceAxis = SourceToolbox.GetPolarAzimuthalPairFromDirection(_newDirectionOfPrincipalSourceAxis);

            //Translation and source rotation
            SourceToolbox.UpdateDirectionPositionAfterGivenFlags(
                ref finalPosition,
                ref finalDirection,
                _rotationalAnglesOfPrincipalSourceAxis,
                _translationFromOrigin,
                _rotationAndTranslationFlags);

            var photon = new Photon(finalPosition, finalDirection, tissue, _initialTissueRegionIndex, Rng);

            return(photon);
        }