示例#1
0
        public static List <PETCoincidenceTOF> GenerateCoincList(List <PETSingleEvent> events, string outDir, int index, int window)
        {
            List <PETCoincidenceTOF> result = new List <PETCoincidenceTOF>();

            for (int i = 0; i < events.Count - 1; i++)
            {
                for (int j = i + 1; j < events.Count && (events[j].Timestamp - events[i].Timestamp < window); j++)
                {
                    if (events[j].Timestamp - events[i].Timestamp < window && events[j].Block != events[i].Block)
                    {
                        var coinc = new PETCoincidenceTOF();

                        coinc.Timestamp1 = events[i].Timestamp;
                        coinc.Position1  = events[i].Position;
                        coinc.XMinus1    = events[i].XMinus;
                        coinc.XPlus1     = events[i].XPlus;
                        coinc.YMinus1    = events[i].YMinus;
                        coinc.YPlus1     = events[i].YPlus;
                        coinc.Timestamp2 = events[j].Timestamp;
                        coinc.Position2  = events[j].Position;
                        coinc.XMinus2    = events[j].XMinus;
                        coinc.XPlus2     = events[j].XPlus;
                        coinc.YMinus2    = events[j].YMinus;
                        coinc.YPlus2     = events[j].YPlus;
                        result.Add(coinc);
                        i = j + 1;
                        break;
                    }
                }
            }

            if (result.Count != 0)
            {
                WorkWithFiles.WriteCoincList(string.Format("{1}\\{0}.csv", index++, outDir), result);
            }
            Console.WriteLine("\tFound {0} coincidences", result.Count);
            return(result);
        }
示例#2
0
        public static List <PETSingleEvent> GenerateSinglesNoAtt(List <AnnihilationEvent> eventList, DetectorsConfiguration dc, string outDir, int index)
        {
            List <PETSingleEvent> result = new List <PETSingleEvent>();

            foreach (var ev in eventList)
            {
                Photon ph1 = new Photon(ev)
                {
                    Status = stat.Finished, Energy = 511E3
                },
                         ph2 = new Photon(ev, true)
                {
                    Status = stat.Finished, Energy = 511E3
                };

                PETSingleEvent se        = new PETSingleEvent();
                bool           detection = dc.Detect(ph1, out se);
                if (detection)
                {
                    result.Add(se);
                }

                detection = dc.Detect(ph2, out se);
                if (detection)
                {
                    result.Add(se);
                }
            }

            if (result.Count != 0)
            {
                WorkWithFiles.WriteSingleEventList(string.Format("{1}\\{0}.csv", index++, outDir), result);
            }
            Console.WriteLine("\tRegistered {0} events", result.Count);

            return(result);
        }
        public void Build(string path)
        {
            var sins = new double[numSins][, ];

            for (int i = 0; i < numSins; i++)
            {
                sins[i] = new double[indexer.NumDirs, indexer.NumLines];
            }

            Bitmap   bmp = new Bitmap(1024, 1024);
            Graphics gr  = Graphics.FromImage(bmp);

            gr.TranslateTransform(bmp.Width / 2f, bmp.Height / 2f);

            List <string> fileList = new List <string>();

            if (Directory.Exists(path))
            {
                DirectoryInfo    di    = new DirectoryInfo(path);
                FileSystemInfo[] files = di.GetFileSystemInfos();
                foreach (var file in files)
                {
                    fileList.Add(file.FullName);
                }
            }

            foreach (var file in fileList)
            {
                var clist = WorkWithFiles.ReadCoincList(file);
                foreach (var c in clist)
                {
                    PETDigitalCoincidenceTOF cIJ = new PETDigitalCoincidenceTOF();
                    EventConverter.CalculateDigitalCoincidenceTOF(c, ref cIJ);

                    int Ring1 = indexer.GetRing(c.Position1, cIJ.J1);
                    int Ring2 = indexer.GetRing(c.Position2, cIJ.J2);

                    var sinidx = Ring1 + Ring2;

                    if (sinidx >= numSins)
                    {
                        continue;
                    }

                    int Dir  = indexer.GetDir(c.Position1, c.Position2, cIJ.I1, cIJ.I2);
                    int Line = indexer.GetLine(c.Position1, c.Position2, cIJ.I1, cIJ.I2);

                    //if (isDebug && ++cnt % 1000 == 0)
                    //{
                    // gr.DrawLine(Pens.White, 410 * (float)Math.Cos(Math.PI * Detector1 / 360), 410 * (float)Math.Sin(Math.PI * Detector1 / 360),
                    // 410 * (float)Math.Cos(Math.PI * Detector2 / 360), 410 * (float)Math.Sin(Math.PI * Detector2 / 360));
                    //}
                    if (Line < 0)
                    {
                        continue;
                    }
                    sins[sinidx][Dir, Line]++;
                }
            }

            if (!Directory.Exists(outDir))
            {
                Directory.CreateDirectory(outDir);
            }

            for (int i = 0; i < numSins; i++)
            {
                Sinogram sino    = new Sinogram(sins[i], AnglesDistribution.Uniform(0, Math.PI, indexer.NumDirs));
                Stream   ostream = File.Create(string.Format("{0}\\{1}", outDir, string.Format("{0}.sg", i)));
                //using (StreamWriter w = new StreamWriter(ostream, Encoding.UTF8))
                using (ostream)
                {
                    Sinogram.SaveSinogramToStream(ostream, sino);
                }

                Sinogram.DumpSinogram(sins[i], string.Format("{0}\\{1}.png", outDir, i));
                //if (isDebug)
                // bmp.Save(string.Format("{0}\\lines.png", arg.OutDir));
            }
        }