/// <summary> /// Returns the existing stats for tag popularity, modality frequencies etc. If stats have not been loaded they are loaded /// and primed with the Random <paramref name="r"/> (otherwise <paramref name="r"/> is ignored). /// </summary> /// <param name="r"></param> /// <returns></returns> public static DicomDataGeneratorStats GetInstance(Random r) { lock (InstanceLock) { return(_instance ?? (_instance = new DicomDataGeneratorStats(r))); } }
/// <summary> /// Returns the existing stats for tag popularity, modality frequencies etc. If stats have not been loaded they are loaded /// and primed with the Random <paramref name="r"/> (otherwise <paramref name="r"/> is ignored). /// </summary> /// <param name="r"></param> /// <returns></returns> public static DicomDataGeneratorStats GetInstance(Random r) { lock (InstanceLock) { if (_instance == null) { _instance = new DicomDataGeneratorStats(r); } return(_instance); } }
public Study(DicomDataGenerator parent, Person person, ModalityStats modalityStats, Random r) { /////////////////////// Generate all the Study Values //////////////////// Parent = parent; StudyUID = DicomUID.Generate(); StudyDate = person.GetRandomDateDuringLifetime(r).Date; var stats = DicomDataGeneratorStats.GetInstance(r); //if we know about the frequency of tag values for this modality? if (stats.TagValuesByModalityAndTag.ContainsKey(modalityStats.Modality)) { foreach (KeyValuePair <DicomTag, BucketList <string> > dict in stats.TagValuesByModalityAndTag[modalityStats.Modality]) { //for each tag we know about //if it's a study level one record it here if (dict.Key == DicomTag.StudyDescription) { StudyDescription = dict.Value.GetRandom(); } } } AccessionNumber = stats.GetRandomAccessionNumber(r); StudyTime = stats.GetRandomTimeOfDay(r); ///////////////////// Generate all the Series (will also generate images) ///////////////////// //have a random number of series (based on average and standard deviation for that modality) //but have at least 1 series! int seriesCount = Math.Max(1, (int)modalityStats.SeriesPerStudyNormal.Sample()); Series = new ReadOnlyCollection <Series>(_series); for (int i = 0; i < seriesCount; i++) { _series.Add(new Series(this, person, modalityStats, r)); } }
/// <summary> /// /// </summary> /// <param name="r"></param> /// <param name="outputDir"></param> /// <param name="modalities">List of modalities to generate from e.g. CT,MR. The frequency of images generated is based on /// the popularity of that modality in a clinical PACS. Passing nothing results in all supported modalities being generated</param> public DicomDataGenerator(Random r, DirectoryInfo outputDir, params string[] modalities) : base(r) { OutputDir = outputDir; var stats = DicomDataGeneratorStats.GetInstance(r); if (modalities.Length == 0) { _modalities = stats.ModalityIndexes.Values.ToArray(); } else { foreach (var m in modalities) { if (!stats.ModalityIndexes.ContainsKey(m)) { throw new ArgumentException("Modality '" + m + "' was not supported, supported modalities are:" + string.Join(",", stats.ModalityIndexes.Select(kvp => kvp.Key))); } } _modalities = modalities.Select(m => stats.ModalityIndexes[m]).ToArray(); } }
private ModalityStats GetRandomModality() { return(DicomDataGeneratorStats.GetInstance(r).ModalityFrequency.GetRandom(_modalities)); }