protected abstract Direction GetFinalDirection(Position position); // position may or may not be needed private static Position GetFinalPositionFromProfileType(ISourceProfile sourceProfile, double innerRadius, double outerRadius, Random rng) { Position finalPosition = SourceDefaults.DefaultPosition.Clone(); switch (sourceProfile.SourceProfileType) { case SourceProfileType.Flat: // var flatProfile = sourceProfile as FlatSourceProfile; finalPosition = SourceToolbox.GetPositionInACircleRandomFlat( SourceDefaults.DefaultPosition.Clone(), innerRadius, outerRadius, rng); break; case SourceProfileType.Gaussian: var gaussianProfile = sourceProfile as GaussianSourceProfile; finalPosition = SourceToolbox.GetPositionInACircleRandomGaussian( SourceDefaults.DefaultPosition.Clone(), outerRadius, innerRadius, gaussianProfile.BeamDiaFWHM, rng); break; } return(finalPosition); }
public void validate_static_method_getpositioninacirclerandomflat() { Random rng = new MathNet.Numerics.Random.MersenneTwister(0); var pos = SourceToolbox.GetPositionInACircleRandomFlat(_position, _innerRadius, _outerRadius, rng); Assert.Less(Math.Abs(pos.X - _tp[47]), ACCEPTABLE_PRECISION); Assert.Less(Math.Abs(pos.Y - _tp[48]), ACCEPTABLE_PRECISION); Assert.Less(Math.Abs(pos.Z - _tp[49]), ACCEPTABLE_PRECISION); }
/// <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; }
protected abstract Direction GetFinalDirection(Position position); // position may or may not be needed private static Position GetFinalPosition(double beamDiameterFWHM, double innerRadius, double outerRadius, Random rng) { return(beamDiameterFWHM < 0.0 ? SourceToolbox.GetPositionInACircleRandomFlat( SourceDefaults.DefaultPosition.Clone(), innerRadius, outerRadius, rng) : SourceToolbox.GetPositionInACircleRandomGaussian( SourceDefaults.DefaultPosition.Clone(), outerRadius, innerRadius, beamDiameterFWHM, rng)); }
/// <summary> /// Returns direction for a given position /// </summary> /// <param name="position">position</param> /// <returns>new direction</returns> protected override Direction GetFinalDirection(Position position) { // randomly sample length of flat circle in air var positionInAir = SourceToolbox.GetPositionInACircleRandomFlat( _circleInAirTranslationFromOrigin, 0.0, _radiusInAir, Rng); // determine angle from positionInAir to PointLocation on tissue var dist = Math.Sqrt( (positionInAir.X - position.X) * (positionInAir.X - position.X) + (positionInAir.Y - position.Y) * (positionInAir.Y - position.Y) + (positionInAir.Z - position.Z) * (positionInAir.Z - position.Z)); return(new Direction( (position.X - positionInAir.X) / dist, (position.Y - positionInAir.Y) / dist, (position.Z - positionInAir.Z) / dist)); }
/// <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); }