Пример #1
0
        string GetDicomName(DicomDirectoryRecord r, string infoParent, int count = -1)
        {
            string name = "";

            try
            {
                if (infoParent is null || infoParent.Length == 0)
                {
                    name = r.Get <string>(DicomTag.PatientName, -1);
                }
                else if (infoParent.StartsWith("dicom:patient"))
                {
                    try
                    {
                        name = r.Get <string>(DicomTag.StudyDescription, -1);
                    }
                    catch
                    {
                    }
                    name += " - " + r.Get <string>(DicomTag.StudyDate, -1) + " " + r.Get <string>(DicomTag.StudyTime, -1);
                }
                else if (infoParent.StartsWith("dicom:study"))
                {
                    try
                    {
                        name = r.Get <string>(DicomTag.SeriesNumber, -1);
                    }
                    catch
                    {
                    }
                    name += " - " + r.Get <string>(DicomTag.SeriesDate, -1) + " " + r.Get <string>(DicomTag.SeriesTime, -1);
                }
                else if (infoParent.StartsWith("dicom:series"))
                {
                    name = Path.GetFileName(r.Get <string>(DicomTag.ReferencedFileID, -1));
                }
            }
Пример #2
0
 public string GetDicomTag(DicomDirectoryRecord record, DicomTag tag)
 {
     return(string.Join(",", record.Get <string[]>(tag, new string[] { "" })));
 }
Пример #3
0
    public void ButtonPush(string button)
    {
        if (button == "3D")
        {
            transform.Find("zstack slider").gameObject.SetActive(false);
            var vc = transform.Find("Volume Cube");
            vc.gameObject.SetActive(true);

            if (vc.GetComponent <Renderer>().material.GetTexture("_Volume") == null)
            {
                var    id   = record.Get <string>(DicomTag.SeriesInstanceUID);
                var    path = Path.Combine(Application.persistentDataPath, "Volumes", id);
                byte[] vol;
                Int3   size;

                var startTime = Time.realtimeSinceStartup;

                if (File.Exists(path) && useCache)                 // a cached volume for this series exists
                {
                    vol  = File.ReadAllBytes(path);
                    size = GetSizeForRecord(record);
                }
                else
                {
                    vol = DICOMSeriesToVolume(record, out size);
                    File.WriteAllBytes(path, vol);
                }


                var volumeSizePow2 = MathExtensions.PowerOfTwoGreaterThanOrEqualTo(size);
                var tex3D          = VolumeTextureUtils.BuildTexture(vol, size, volumeSizePow2);

                Debug.Log("created volume in " + (Time.realtimeSinceStartup - startTime) + "s");
                vcRenderer.material.SetTexture("_Volume", tex3D);

                var first         = loadDicomInstance.GetImageForRecord(record, 0);
                var last          = loadDicomInstance.GetImageForRecord(record, -2);
                var sliceLocFirst = first.Dataset.Get <float>(DicomTag.SliceLocation);
                var sliceLocLast  = last.Dataset.Get <float>(DicomTag.SliceLocation);
                var pos           = first.Dataset.Get <string[]>(DicomTag.ImagePositionPatient);
                var spacing       = first.Dataset.Get <float[]>(DicomTag.PixelSpacing);
                var zDepth        = sliceLocLast - sliceLocFirst;
                var xWidth        = spacing[0] * first.Dataset.Get <int>(DicomTag.Rows);
                var yHeight       = spacing[1] * first.Dataset.Get <int>(DicomTag.Columns);
                Debug.Log("volume is " + xWidth + "mm x " + yHeight + "mm x " + zDepth + "mm, and located at " + pos[0] + "," + pos[1]);
                vc.transform.localScale = new Vector3(xWidth / realWorldScale, yHeight / realWorldScale, zDepth / realWorldScale);
            }
            renderer.enabled = false;
            is3D             = true;

            var rootDir = loadDicomInstance.rootDirectoryMap[record];
            if (rootDir.Contains("ChestSeries"))
            {
                rootDir = "ChestSeries";
            }
            else if (rootDir.Contains("HeadNeckChestBody"))
            {
                rootDir = "HeadNeckChestBody";
            }
            var studyFID  = record.LowerLevelDirectoryRecord.Get <string>(DicomTag.ReferencedFileID, 1);
            var seriesFID = record.LowerLevelDirectoryRecord.Get <string>(DicomTag.ReferencedFileID, 2);
            foreach (var s in loadDicomInstance.meshMarkers)
            {
                if (s.Contains(rootDir) && s.Contains(studyFID) && s.Contains(seriesFID))
                {
                    Debug.Log(s + " seems to be a mesh marker for " + gameObject.name);
                    var meshes     = Parabox.STL.pb_Stl_Importer.Import(s);
                    var marker     = Instantiate(meshMarkerPrefab, meshMarkers.transform);
                    var meshFilter = marker.GetComponent <MeshFilter>();
                    meshFilter.mesh = meshes[0];
                    marker.name     = s;
                    if (s.Contains("Sampling Site"))
                    {
                        marker.GetComponent <Renderer>().material.color = Color.green;
                    }
                }
            }
        }
        else if (button == "2D")
        {
            renderer.enabled = true;
            transform.Find("zstack slider").gameObject.SetActive(true);
            transform.Find("Volume Cube").gameObject.SetActive(false);
            is3D = false;
        }
    }