/// <summary>
 /// 
 /// </summary>
 /// <param name="sdc"></param>
 /// <returns></returns>
 public StructureDataContract AddStructure(StructureDataContract sdc)
 {
     System.Diagnostics.Trace.Assert(sdc.Id.CompareTo(Guid.Empty) == 0);
     sdc.Id = Guid.NewGuid();
     _cacheStructures.Add(sdc.Id, sdc);
     return sdc;
 }
Ejemplo n.º 2
0
        void StoreStructureSet(DicomDataset ds)
        {
            // store in cached resource
            LocalGeometryResourceManagerClient
                cache1 = new LocalGeometryResourceManagerClient();

            var proxy = ImageResponseClient.CreateProxy();

            string seriesInstanceUID = ds.Get<string>(DicomTag.SeriesInstanceUID);
            string sopInstanceUID = ds.Get<string>(DicomTag.SOPInstanceUID);
            string structureSetLabel = ds.Get<string>(DicomTag.StructureSetLabel);

            DicomSequence referencedForSequence = ds.Get<DicomSequence>(DicomTag.ReferencedFrameOfReferenceSequence);
            string frameOfReferenceUID = referencedForSequence.First().Get<string>(DicomTag.FrameOfReferenceUID);

            DicomSequence ssRoiSequence = ds.Get<DicomSequence>(DicomTag.StructureSetROISequence);
            foreach (var ssRoiItem in ssRoiSequence)
            {
                // process structure set
                StructureDataContract sdc = new StructureDataContract();
                sdc.PatientId = ds.Get<string>(DicomTag.PatientID);
                sdc.SeriesInstanceUID = seriesInstanceUID;
                sdc.SOPInstanceUID = sopInstanceUID;
                sdc.StructureSetLabel = structureSetLabel;
                string roiName = ssRoiItem.Get<string>(DicomTag.ROIName);
                sdc.ROIName = roiName;
                int roiNumber = ssRoiItem.Get<int>(DicomTag.ROINumber);
                // sdc.ROINumber = roiNumber;

                string relatedForUID = ssRoiItem.Get<string>(DicomTag.ReferencedFrameOfReferenceUID);
                sdc.FrameOfReferenceUID = relatedForUID;

                var roiContourSeq = ds.Get<DicomSequence>(DicomTag.ROIContourSequence);
                var roiContourItem = from item in roiContourSeq
                                     where item.Get<int>(DicomTag.ReferencedROINumber) == roiNumber
                                     select item;
                System.Diagnostics.Trace.Assert(roiContourItem.Count() == 1);

                List<Guid> polygonGuidList = new List<Guid>();
                var contourSequence = roiContourItem.First().Get<DicomSequence>(DicomTag.ContourSequence);
                if (contourSequence != null)
                {
                    foreach (var contourItem in contourSequence)
                    {
                        var contourGeometricType = contourItem.Get<string>(DicomTag.ContourGeometricType);
                        // TODO: if it is a point then store differently

                        var numberOfContourPoints = contourItem.Get<int>(DicomTag.NumberOfContourPoints);
                        ContourDataContract pdc = new ContourDataContract();
                        pdc.FrameOfReferenceUID = sdc.FrameOfReferenceUID;
                        pdc.VertexCount = numberOfContourPoints;
                        pdc = cache1.AddPolygon(pdc);
                        polygonGuidList.Add(pdc.Id);

                        // now access vertex buffer

                        var handle = pdc.VertexBuffer.GetHandle();
                        for (int n = 0; n < numberOfContourPoints; n++)
                        {
                            var x = contourItem.Get<double>(DicomTag.ContourData, n * 3 + 0);
                            var y = contourItem.Get<double>(DicomTag.ContourData, n * 3 + 1);
                            var z = contourItem.Get<double>(DicomTag.ContourData, n * 3 + 2);
                            Vector3D vertex = new Vector3D(x, y, z);

                            handle.Write<Vector3D>((ulong)(n * Marshal.SizeOf(vertex)), vertex);
                        }
                        pdc.VertexBuffer.ReleaseHandle();
                    }
                }

                sdc.Contours = polygonGuidList;
                sdc = cache1.AddStructure(sdc);

                // inform of found structure
                proxy.OnStructureStored(sdc.Id);
            }

            proxy.Close();

            cache1.Close();

        }