/// <summary>
        ///     Gets the dose at a volume for all structures in this constraint by merging their dvhs
        /// </summary>
        /// <param name="pi">the planning item containing the dose to be queried</param>
        /// <returns>the dose value at the volume of this constraint</returns>
        public double GetComplementVolumeAtDose(PlanningItem pi)
        {
            var structures = StructureNames.Select(s => pi.GetStructure(s));
            var volAtDose  = pi.GetComplementVolumeAtDose(structures, ConstraintDose, VolumeType);

            return(volAtDose);
        }
Example #2
0
        /// <summary>
        ///     Gets the dose at a volume for all structures in this constraint by merging their dvhs
        /// </summary>
        /// <param name="pi">the planning item containing the dose to be queried</param>
        /// <returns>the dose value at the volume of this constraint</returns>
        public DoseValue GetDoseAtVolume(PlanningItem pi)
        {
            var structures = StructureNames.Select(s => pi.GetStructure(s));
            var doseAtVol  = pi.GetDoseAtVolume(structures, Volume, VolumeType, ConstraintDose.GetPresentation());

            return(doseAtVol);
        }
Example #3
0
        public void UpdateStructureNames(string structureName)
        {
            if (!StructureNames.Contains(structureName))
            {
                StructureNames.Add(structureName);
            }

            if (!ContouredStructureNames.Contains(structureName))
            {
                ContouredStructureNames.Add(structureName);
            }

            SortStructureNames();
        }
Example #4
0
        public override ConstraintResult Constrain(PlanningItem pi)
        {
            var msg    = string.Empty;
            var passed = GetFailedResultType();

            var structures = StructureNames.Select(s => pi.GetStructure(s));
            var doseAtVol  = pi.GetDoseAtVolume(structures, Volume, VolumeType, ConstraintDose.GetPresentation());

            passed = PassingFunc(doseAtVol);

            var stringUnit = VolumeType == VolumePresentation.AbsoluteCm3 ? "CC" : "%";
            var value      = $"{doseAtVol.GetDose(ConstraintDose.Unit).ToString("F3")} {ConstraintDose.UnitAsString}";

            msg = $"Dose to {Volume} {stringUnit} of {StructureName} is {value}.";
            return(new ConstraintResult(this, passed, msg, value));
        }
        private void ChooseFile(DvhObjectivesViewModel dvhObjectivesViewModel)
        {
            var dialog = new OpenFileDialog
            {
                Title            = "Choose file",
                Filter           = "CSV file (*.csv)|*.csv",
                InitialDirectory = Path.Combine(DvhCheckerDirectoryPath, "templates")
            };

            if (dialog.ShowDialog() == true)
            {
                ProtocolFilePath = dialog.FileName;
            }
            else
            {
                ProtocolFilePath = string.Empty;
                Message          = "\"Choose file\" is canceled";
                return;
            }

            dvhObjectivesViewModel.DvhObjectives = new ObservableCollection <DvhObjective>(DvhObjective.ReadObjectivesFromCsv(ProtocolFilePath));

            var dvhObjectives = dvhObjectivesViewModel.DvhObjectives;

            if (!StructureNames.Contains(StructureNameNone))
            {
                StructureNames.Insert(0, StructureNameNone);
            }
            foreach (var o in dvhObjectives)
            {
                if (StructureNames.Contains(o.StructureName))
                {
                    o.StructureNameTps = o.StructureName;
                    o.InUse            = true;
                }
                else
                {
                    o.StructureNameTps = StructureNameNone;
                }
            }

            if (dvhObjectives.Count > 0)
            {
                dvhObjectivesViewModel.ProtocolId = dvhObjectives[0].ProtocolId;
            }
        }
 /// <summary>
 ///     Returns the structures in the planning item from the structure names property
 /// </summary>
 /// <param name="pi">the planning item to query</param>
 /// <returns>the collection of structures</returns>
 public IEnumerable <Structure> GetStructures(PlanningItem pi)
 {
     return(StructureNames.Select(s => pi.GetStructure(s)));
 }
Example #7
0
 public void SortStructureNames()
 {
     StructureNames          = new ObservableCollection <string>(StructureNames.OrderBy(s => s));
     ContouredStructureNames = new ObservableCollection <string>(ContouredStructureNames.OrderBy(s => s));
 }
        public void RtStructOutputEncoder_SuccessWithValidInputs()
        {
            var labels = VolumeMetadataMapper.MultiLabelMapping(sourceVolume, NumValidLabels);
            var volumesWithMetadata = VolumeMetadataMapper.MapVolumeMetadata(labels, StructureNames, StructureColors, FillHoles, ROIInterpretedTypes);

            var referenceVolume = DicomSeriesHelpers.LoadVolume(DicomFolderContents.Build(
                                                                    Directory.EnumerateFiles(TestDicomVolumeLocation).Select(x => DicomFileAndPath.SafeCreate(x)).ToList()
                                                                    ));

            var outputEncoder = new DicomRTStructOutputEncoder();

            var outputStructureBytes = outputEncoder.EncodeStructures(
                volumesWithMetadata,
                new Dictionary <string, MedicalVolume>()
            {
                { "", referenceVolume }
            },
                "modelX:1",
                "manufacturer",
                "interpreter");

            var dcm = DicomFile.Open(new MemoryStream(outputStructureBytes.Array));

            // Check the output format (should be RT struct)
            Assert.AreEqual(DicomUID.RTStructureSetStorage, dcm.FileMetaInfo.MediaStorageSOPClassUID);

            // Check stuff in StructureSet ROI sequence
            var structSetRois = dcm.Dataset.GetSequence(DicomTag.StructureSetROISequence).Items;
            var iter          = StructureNames.GetEnumerator();

            iter.MoveNext();

            var origReferencedFrameOfReference = referenceVolume.Identifiers.First().FrameOfReference.FrameOfReferenceUid;

            foreach (var roi in structSetRois)
            {
                // Verify that names in the generated DICOM Rt structure are the ones we've supplied
                Assert.AreEqual(iter.Current, roi.GetString(DicomTag.ROIName));
                iter.MoveNext();

                // Verify that this roi references the same frame of reference as the original image
                Assert.AreEqual(roi.GetString(DicomTag.ReferencedFrameOfReferenceUID), origReferencedFrameOfReference);
            }

            // Check stuff in ROI Contour sequence
            var roiContours = dcm.Dataset.GetSequence(DicomTag.ROIContourSequence).Items;
            var iterColors  = 0;

            var sopInstanceUIDs = referenceVolume.Identifiers.Select(x => x.Image.SopCommon.SopInstanceUid);

            foreach (var contourSequence in roiContours)
            {
                // Verify that colors in the generated contour sequence are the ones we've supplied
                var currentColor       = StructureColors[iterColors].Value;
                var currentColorString = string.Format("{0}\\{1}\\{2}", currentColor.R, currentColor.G, currentColor.B);

                Assert.AreEqual(contourSequence.GetString(DicomTag.ROIDisplayColor), currentColorString);
                iterColors++;

                // Verify that all contour types are closed planar
                Assert.IsTrue(contourSequence.GetSequence(DicomTag.ContourSequence).Items.All(
                                  x => x.GetString(DicomTag.ContourGeometricType) == "CLOSED_PLANAR"));

                // Verify that for all contours there exists a SOP Instance UID in the original series
                Assert.IsTrue(contourSequence.GetSequence(DicomTag.ContourSequence).Items.All(
                                  x => sopInstanceUIDs.Contains(x.GetSequence(DicomTag.ContourImageSequence).Items[0].GetString(DicomTag.ReferencedSOPInstanceUID))));
            }
        }