Beispiel #1
0
        /// <summary>
        /// method to tally given two consecutive photon data points
        /// </summary>
        /// <param name="previousDP">previous data point</param>
        /// <param name="dp">current data point</param>
        /// <param name="currentRegionIndex">index of region photon current is in</param>
        public void TallySingle(PhotonDataPoint previousDP, PhotonDataPoint dp, int currentRegionIndex)
        {
            var totalTime = dp.TotalTime;
            var ix        = DetectorBinning.WhichBin(dp.Position.X, X.Count - 1, X.Delta, X.Start);
            var iy        = DetectorBinning.WhichBin(dp.Position.Y, Y.Count - 1, Y.Delta, Y.Start);
            var iz        = DetectorBinning.WhichBin(dp.Position.Z, Z.Count - 1, Z.Delta, Z.Start);

            var weight = _absorptionWeightingMethod(previousDP, dp, currentRegionIndex);

            var regionIndex = currentRegionIndex;

            if (weight != 0.0)
            {
                for (int iw = 0; iw < Omega.Count; iw++)
                {
                    double freq = Omega.AsEnumerable().ToArray()[iw];

                    Mean[ix, iy, iz, iw] += (weight / _ops[regionIndex].Mua) *
                                            (Math.Cos(-2 * Math.PI * freq * totalTime) +
                                             Complex.ImaginaryOne * Math.Sin(-2 * Math.PI * freq * totalTime));
                    if (TallySecondMoment)
                    {
                        _tallyForOnePhoton[ix, iy, iz, iw] += (weight / _ops[regionIndex].Mua) *
                                                              (Math.Cos(-2 * Math.PI * freq * totalTime) +
                                                               Complex.ImaginaryOne * Math.Sin(-2 * Math.PI * freq * totalTime));
                    }
                    TallyCount++;
                }
            }
        }
        /// <summary>
        /// method to tally to detector
        /// </summary>
        /// <param name="photon">photon data needed to tally</param>
        public void Tally(Photon photon)
        {
            if (!IsWithinDetectorAperture(photon))
            {
                return;
            }

            var ir        = DetectorBinning.WhichBin(DetectorBinning.GetRho(photon.DP.Position.X, photon.DP.Position.Y), Rho.Count - 1, Rho.Delta, Rho.Start);
            var totalTime = photon.DP.TotalTime;

            for (int iw = 0; iw < Omega.Count; iw++)
            {
                double freq = Omega.AsEnumerable().ToArray()[iw];
                Mean[ir, iw] += photon.DP.Weight * (Math.Cos(-2 * Math.PI * freq * totalTime) +
                                                    Complex.ImaginaryOne * Math.Sin(-2 * Math.PI * freq * totalTime));

                if (TallySecondMoment) // 2nd moment is E[xx*]=E[xreal^2]+E[ximag^2]
                {
                    SecondMoment[ir, iw] +=
                        photon.DP.Weight * (Math.Cos(-2 * Math.PI * freq * totalTime)) *
                        photon.DP.Weight * (Math.Cos(-2 * Math.PI * freq * totalTime)) +
                        photon.DP.Weight * (Math.Sin(-2 * Math.PI * freq * totalTime)) *
                        photon.DP.Weight * (Math.Sin(-2 * Math.PI * freq * totalTime));
                }
            }
            TallyCount++;
        }
Beispiel #3
0
        /// <summary>
        /// method to tally given two consecutive photon data points
        /// </summary>
        /// <param name="previousDP">previous data point</param>
        /// <param name="dp">current data point</param>
        /// <param name="currentRegionIndex">index of region photon current is in</param>
        public void TallySingle(PhotonDataPoint previousDP, PhotonDataPoint dp, int currentRegionIndex)
        {
            var totalTime = dp.TotalTime;
            var ir        = DetectorBinning.WhichBin(DetectorBinning.GetRho(dp.Position.X, dp.Position.Y), Rho.Count - 1, Rho.Delta, Rho.Start);
            var iz        = DetectorBinning.WhichBin(dp.Position.Z, Z.Count - 1, Z.Delta, Z.Start);

            var weight = _absorptionWeightingMethod(previousDP, dp, currentRegionIndex);
            // Note: GetVolumeAbsorptionWeightingMethod in Initialize method determines the *absorbed* weight
            //  so for fluence this weight is divided by Mua

            var regionIndex = currentRegionIndex;

            if (weight != 0.0)
            {
                for (int iw = 0; iw < Omega.Count; iw++)
                {
                    double freq = Omega.AsEnumerable().ToArray()[iw];

                    Mean[ir, iz, iw] += (weight / _ops[regionIndex].Mua) *
                                        (Math.Cos(-2 * Math.PI * freq * totalTime) +
                                         Complex.ImaginaryOne * Math.Sin(-2 * Math.PI * freq * totalTime));
                    if (TallySecondMoment)
                    {
                        _tallyForOnePhoton[ir, iz, iw] += (weight / _ops[regionIndex].Mua) *
                                                          (Math.Cos(-2 * Math.PI * freq * totalTime) +
                                                           Complex.ImaginaryOne * Math.Sin(-2 * Math.PI * freq * totalTime));
                    }
                }
                TallyCount++;
            }
        }
 public override void Pack(BinaryWriter writer)
 {
     writer.Write(ObjectID);
     Velocity.Pack(writer);
     Omega.Pack(writer);
     writer.Write(ObjectInstanceSequence);
     writer.Write(ObjectVectorSequence);
 }
 public override void Unpack(BinaryReader reader)
 {
     base.Unpack(reader);
     ObjectID = reader.ReadUInt32();
     Velocity.Unpack(reader);
     Omega.Unpack(reader);
     ObjectInstanceSequence = reader.ReadUInt16();
     ObjectVectorSequence   = reader.ReadUInt16();
 }
Beispiel #6
0
        public MaterialObjectNewtow() : base()
        {
            AddChild(Omega);
            AddChild(Eps);

            Omega.AddDiffVect(Eps, false);
            AddDiffPropToParam(pQw, pdQWdt);
            AddDiffPropToParam(pQx, pdQXdt);
            AddDiffPropToParam(pQy, pdQYdt);
            AddDiffPropToParam(pQz, pdQZdt);
        }
Beispiel #7
0
        public MaterialObjectNewton(object x, object y, object z, string name = DEFNAME) : base(x, y, z, name)
        {
            AddChild(Omega);
            AddChild(Eps);

            Omega.AddDiffVect(Eps, false);
            AddDiffPropToParam(pQw, pdQWdt);
            AddDiffPropToParam(pQx, pdQXdt);
            AddDiffPropToParam(pQy, pdQYdt);
            AddDiffPropToParam(pQz, pdQZdt);
        }
    public static void omega_test()

    //****************************************************************************80
    //
    //  Purpose:
    //
    //    OMEGA_TEST tests OMEGA.
    //
    //  Licensing:
    //
    //    This code is distributed under the GNU LGPL license.
    //
    //  Modified:
    //
    //    02 June 2007
    //
    //  Author:
    //
    //    John Burkardt
    //
    {
        int c = 0;
        int n = 0;

        Console.WriteLine("");
        Console.WriteLine("OMEGA_TEST");
        Console.WriteLine("  OMEGA computes the OMEGA function.");
        Console.WriteLine("");
        Console.WriteLine("          N   Exact   OMEGA(N)");
        Console.WriteLine("");

        int n_data = 0;

        for (;;)
        {
            Burkardt.Values.Omega.omega_values(ref n_data, ref n, ref c);

            if (n_data == 0)
            {
                break;
            }

            Console.WriteLine("  "
                              + n.ToString().PadLeft(12) + "  "
                              + c.ToString().PadLeft(10) + "  "
                              + Omega.omega(n).ToString().PadLeft(10) + "");
        }
    }
Beispiel #9
0
    public static void omega_values_test()
    //****************************************************************************80
    //
    //  Purpose:
    //
    //    OMEGA_VALUES_TEST tests OMEGA_VALUES.
    //
    //  Licensing:
    //
    //    This code is distributed under the GNU LGPL license.
    //
    //  Modified:
    //
    //    09 February 2007
    //
    //  Author:
    //
    //    John Burkardt
    //
    {
        int fn = 0;
        int n  = 0;

        Console.WriteLine("");
        Console.WriteLine("OMEGA_VALUES_TEST:");
        Console.WriteLine("  OMEGA_VALUES returns values of");
        Console.WriteLine("  the Omega function.");
        Console.WriteLine("");
        Console.WriteLine("     N           OMEGA(N)");
        Console.WriteLine("");
        int n_data = 0;

        for (;;)
        {
            Omega.omega_values(ref n_data, ref n, ref fn);
            if (n_data == 0)
            {
                break;
            }

            Console.WriteLine("  "
                              + n.ToString().PadLeft(12) + n + "  "
                              + fn.ToString().PadLeft(10) + fn + "");
        }
    }
Beispiel #10
0
        public override int GetHashCode()
        {
            int hash = 1;

            if (X != 0F)
            {
                hash ^= X.GetHashCode();
            }
            if (Y != 0F)
            {
                hash ^= Y.GetHashCode();
            }
            if (Vx != 0F)
            {
                hash ^= Vx.GetHashCode();
            }
            if (Vy != 0F)
            {
                hash ^= Vy.GetHashCode();
            }
            if (Rotation != 0F)
            {
                hash ^= Rotation.GetHashCode();
            }
            if (Omega != 0F)
            {
                hash ^= Omega.GetHashCode();
            }
            if (InitLife != 0F)
            {
                hash ^= InitLife.GetHashCode();
            }
            if (Life != 0F)
            {
                hash ^= Life.GetHashCode();
            }
            if (Scale != 0F)
            {
                hash ^= Scale.GetHashCode();
            }
            if (Alpha != 0F)
            {
                hash ^= Alpha.GetHashCode();
            }
            if (Mass != 0F)
            {
                hash ^= Mass.GetHashCode();
            }
            if (IsDead != false)
            {
                hash ^= IsDead.GetHashCode();
            }
            if (ColorR != 0F)
            {
                hash ^= ColorR.GetHashCode();
            }
            if (ColorG != 0F)
            {
                hash ^= ColorG.GetHashCode();
            }
            if (ColorB != 0F)
            {
                hash ^= ColorB.GetHashCode();
            }
            if (CurrentAnimationFrame != 0)
            {
                hash ^= CurrentAnimationFrame.GetHashCode();
            }
            return(hash);
        }
        public void Update <TMeasurements>(Vector <double> motion, TMeasurements measurements, double motionNoise, double measurementNoise) where TMeasurements : IEnumerable <LandmarkMeasurement>
        {
            // expand information matrix to accomodate new landmarks, if necessary
            var maxIndex = measurements.Max(m => (int?)m.Index);

            if (maxIndex != null)
            {
                var m = 2 * (1 + maxIndex.Value);
                if (m >= Omega.RowCount)
                {
                    var indices = Enumerable.Range(0, Omega.RowCount).ToArray();
                    Omega = Omega.Expand(m + 2, m + 2, indices);
                    Xi    = Xi.Expand(m + 2, 1, indices, new[] { 0 });
                }
            }

            var expandedSize    = Omega.RowCount + 2;
            var expandedIndices = new int[Omega.RowCount];
            var reducedIndices  = new int[Omega.RowCount];

            for (int i = 0; i < expandedIndices.Length; i++)
            {
                if (i < 2)
                {
                    expandedIndices[i] = i;
                }
                else
                {
                    expandedIndices[i] = i + 2;
                }

                reducedIndices[i] = i + 2;
            }

            // expand omega and xi for motion
            Omega = Omega.Expand(expandedSize, expandedSize, expandedIndices);
            Xi    = Xi.Expand(expandedSize, 1, expandedIndices, new[] { 0 });

            // integrate the measurements
            foreach (var measurement in measurements)
            {
                // m is the corrected index of the landmark
                var m = 2 * (2 + measurement.Index);

                // update information matrix based on the measurement
                for (int i = 0; i < 2; i++)
                {
                    Omega[i, i]         += 1.0 / measurementNoise;
                    Omega[m + i, m + i] += 1.0 / measurementNoise;
                    Omega[i, m + i]     += -1.0 / measurementNoise;
                    Omega[m + i, i]     += -1.0 / measurementNoise;
                    Xi[i, 0]            += -measurement.Measurement[i] / measurementNoise;
                    Xi[m + i, 0]        += measurement.Measurement[i] / measurementNoise;
                }
            }

            // update information matrix based on motion
            for (int i = 0; i < 4; i++)
            {
                Omega[i, i] += 1.0 / motionNoise;
                if (i < 2)
                {
                    Omega[i, i + 2] += -1.0 / motionNoise;
                    Omega[i + 2, i] += -1.0 / motionNoise;
                    Xi[i, 0]        += -motion[i] / motionNoise;
                    Xi[i + 2, 0]    += motion[i] / motionNoise;
                }
            }

            // reduce omega and xi
            var omegaPrime = Omega.Take(reducedIndices);
            var xiPrime    = Xi.Take(reducedIndices, new[] { 0 });

            var A = Omega.Take(new[] { 0, 2 }, reducedIndices);
            var B = Omega.Take(new[] { 0, 2 });
            var C = Xi.Take(new[] { 0, 2 }, new[] { 0 });

            var AtBinv = A.TransposeThisAndMultiply(B.Inverse());

            omegaPrime = omegaPrime - (AtBinv * A);
            xiPrime    = xiPrime - (AtBinv * C);

            Omega = omegaPrime;
            Xi    = xiPrime;
        }
Beispiel #12
0
 public override string ToString()
 {
     return($"Omega/Phi/Psi: {Omega.In(Unit.Degree):F1}/{Phi.In(Unit.Degree):F1}/{Psi.In(Unit.Degree):F1}");
 }