コード例 #1
0
        /// <summary>
        /// Creates a radiotherapy structure from a set of contours, including the given rendering
        /// information (name of the contour, color to render in).
        /// </summary>
        /// <param name="contours">The contours and their rendering information.</param>
        /// <param name="dicomIdentifiers">The Dicom identifiers for the scan to which the contours belong.</param>
        /// <param name="volumeTransform">The Dicom-to-data transformation of the scan to which the contours belong.</param>
        /// <returns></returns>
        public static RadiotherapyStruct ContoursToRadiotherapyStruct(IEnumerable <ContourRenderingInformation> contours,
                                                                      IReadOnlyList <DicomIdentifiers> dicomIdentifiers,
                                                                      VolumeTransform volumeTransform)
        {
            var radiotherapyStruct = RadiotherapyStruct.CreateDefault(dicomIdentifiers);

            int roiNumber     = 0;
            var nameConverter = new DicomPersonNameConverter("InnerEye", "CreateDataset", string.Empty, string.Empty, string.Empty);

            foreach (var contour in contours)
            {
                // ROIs need to start at 1 by DICOM spec
                roiNumber++;
                // Create contours - mapping each contour into the volume.
                var radiotherapyContour = RTStructCreator.CreateRadiotherapyContour(
                    contour.Contour,
                    dicomIdentifiers,
                    volumeTransform,
                    contour.Name,
                    (contour.Color.R, contour.Color.G, contour.Color.B),
                    roiNumber.ToString(),
                    nameConverter,
                    ROIInterpretedType.None
                    );
                radiotherapyStruct.Contours.Add(radiotherapyContour);
            }
            return(radiotherapyStruct);
        }
コード例 #2
0
ファイル: MedIO.cs プロジェクト: microsoft/InnerEye-DICOM-RT
        /// <summary>
        /// Loads a medical volume from a Nifti file. The <see cref="MedicalVolume.Volume"/> property
        /// will be set to the volume in the Nifti file, the RT structures will be empty, empty
        /// Dicom identifiers.
        /// </summary>
        /// <param name="path"></param>
        /// <returns></returns>
        public static MedicalVolume LoadMedicalVolumeFromNifti(string path)
        {
            var volume = LoadNiftiAsShort(path);

            return(new MedicalVolume(
                       volume,
                       new DicomIdentifiers[0],
                       new[] { path },
                       RadiotherapyStruct.CreateDefault(new[] { DicomIdentifiers.CreateEmpty() })));
        }
コード例 #3
0
ファイル: MedIO.cs プロジェクト: microsoft/InnerEye-DICOM-RT
        /// <summary>
        /// Attempt to load a volume from the given SeriesUID for the given DicomFolderContents
        /// </summary>
        /// <param name="dfc">A pre-built description of DICOM contents within a particular folder</param>
        /// <param name="seriesUID">The DICOM seriesUID you wish to construct a volume for</param>
        /// <param name="acceptanceTests">An implementation of IVolumeGeometricAcceptanceTest defining the geometric constraints of your application</param>
        /// <param name="loadStructuresIfExists">True if rt-structures identified in the folder and referencing seriesUID should be loaded</param>
        /// <param name="supportLossyCodecs">If you wish to accept lossy encodings of image pixel data</param>
        /// <returns></returns>
        private static VolumeLoaderResult LoadDicomSeries(
            DicomFolderContents dfc, DicomUID seriesUID, IVolumeGeometricAcceptanceTest acceptanceTests, bool loadStructuresIfExists, bool supportLossyCodecs)
        {
            try
            {
                var dicomSeriesContent = dfc.Series.FirstOrDefault((s) => s.SeriesUID == seriesUID);

                var warnings = new List <string>();
                RadiotherapyStruct rtStruct = null;

                if (dicomSeriesContent != null)
                {
                    var volumeData = DicomSeriesReader.BuildVolume(dicomSeriesContent.Content.Select(x => x.File.Dataset), acceptanceTests, supportLossyCodecs);

                    if (volumeData != null && loadStructuresIfExists)
                    {
                        var rtStructData = dfc.RTStructs.FirstOrDefault(rt => rt.SeriesUID == seriesUID);
                        if (rtStructData != null)
                        {
                            if (rtStructData.Content.Count == 1)
                            {
                                var rtStructAndWarnings = RtStructReader.LoadContours(
                                    rtStructData.Content.First().File.Dataset,
                                    volumeData.Transform.DicomToData,
                                    seriesUID.UID,
                                    null,
                                    false);

                                rtStruct = rtStructAndWarnings.Item1;

                                var warning = rtStructAndWarnings.Item2;

                                if (!string.IsNullOrEmpty(warning))
                                {
                                    warnings.Add(warning);
                                }
                            }
                            else if (rtStructData.Content.Count > 1)
                            {
                                warnings.Add("There is more than 1 RT STRUCT referencing this series - skipping structure set load");
                            }
                        }
                    }
                    var dicomIdentifiers = dicomSeriesContent.Content.Select((v) => DicomIdentifiers.ReadDicomIdentifiers(v.File.Dataset)).ToArray();

                    if (rtStruct == null)
                    {
                        rtStruct = RadiotherapyStruct.CreateDefault(dicomIdentifiers);
                    }

                    var result = new MedicalVolume(
                        volumeData,
                        dicomIdentifiers,
                        dicomSeriesContent.Content.Select((d) => d.Path).ToArray(),
                        rtStruct);

                    return(new VolumeLoaderResult(seriesUID.UID, result, null, warnings));
                }
                throw new Exception("Could not find that series");
            }
            catch (Exception oops)
            {
                return(new VolumeLoaderResult(seriesUID.UID, null, oops, new List <string>()));
            }
        }