Example #1
0
        private void OnOpenDICOMDatasetResult(RuntimeFileBrowser.DialogResult result)
        {
            if (!result.cancelled)
            {
                // We'll only allow one dataset at a time in the runtime GUI (for simplicity)
                DespawnAllDatasets();

                bool recursive = true;

                // Read all files
                IEnumerable <string> fileCandidates = Directory.EnumerateFiles(result.path, "*.*", recursive ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly)
                                                      .Where(p => p.EndsWith(".dcm", StringComparison.InvariantCultureIgnoreCase) || p.EndsWith(".dicom", StringComparison.InvariantCultureIgnoreCase) || p.EndsWith(".dicm", StringComparison.InvariantCultureIgnoreCase));

                // Import the dataset
                DICOMImporter importer = new DICOMImporter(fileCandidates, Path.GetFileName(result.path));
                List <DICOMImporter.DICOMSeries> seriesList = importer.LoadDICOMSeries();
                float numVolumesCreated = 0;
                foreach (DICOMImporter.DICOMSeries series in seriesList)
                {
                    VolumeDataset dataset = importer.ImportDICOMSeries(series);
                    // Spawn the object
                    if (dataset != null)
                    {
                        VolumeRenderedObject obj = VolumeObjectFactory.CreateObject(dataset);
                        obj.transform.position = new Vector3(numVolumesCreated, 0, 0);
                        numVolumesCreated++;
                    }
                }
            }
        }
Example #2
0
        static void ShowSequenceImporter()
        {
            string dir = EditorUtility.OpenFolderPanel("Select a folder to load", "", "");

            if (Directory.Exists(dir))
            {
                ImageSequenceImporter importer = new ImageSequenceImporter(dir);

                VolumeDataset dataset = importer.Import();
                if (dataset != null)
                {
                    if (EditorPrefs.GetBool("DownscaleDatasetPrompt"))
                    {
                        if (EditorUtility.DisplayDialog("Optional DownScaling",
                                                        $"Do you want to downscale the dataset? The dataset's dimension is: {dataset.dimX} x {dataset.dimY} x {dataset.dimZ}", "Yes", "No"))
                        {
                            dataset.DownScaleData();
                        }
                    }
                    VolumeObjectFactory.CreateObject(dataset);
                }
            }
            else
            {
                Debug.LogError("Directory doesn't exist: " + dir);
            }
        }
Example #3
0
        private void OnOpenRAWDatasetResult(RuntimeFileBrowser.DialogResult result)
        {
            if (!result.cancelled)
            {
                // We'll only allow one dataset at a time in the runtime GUI (for simplicity)
                DespawnAllDatasets();

                // Did the user try to import an .ini-file? Open the corresponding .raw file instead
                string filePath = result.path;
                if (System.IO.Path.GetExtension(filePath) == ".ini")
                {
                    filePath = filePath.Replace(".ini", ".raw");
                }

                // Parse .ini file
                DatasetIniData initData = DatasetIniReader.ParseIniFile(filePath + ".ini");
                if (initData != null)
                {
                    // Import the dataset
                    RawDatasetImporter importer = new RawDatasetImporter(filePath, initData.dimX, initData.dimY, initData.dimZ, initData.format, initData.endianness, initData.bytesToSkip);
                    VolumeDataset      dataset  = importer.Import();
                    // Spawn the object
                    if (dataset != null)
                    {
                        VolumeObjectFactory.CreateObject(dataset);
                    }
                }
            }
        }
        public static void ImportDataset(string filePath)
        {
            DatasetType datasetType = DatasetImporterUtility.GetDatasetType(filePath);

            switch (datasetType)
            {
            case DatasetType.Raw:
            {
                RAWDatasetImporterEditorWindow wnd = (RAWDatasetImporterEditorWindow)EditorWindow.GetWindow(typeof(RAWDatasetImporterEditorWindow));
                if (wnd != null)
                {
                    wnd.Close();
                }

                wnd = new RAWDatasetImporterEditorWindow(filePath);
                wnd.Show();
                break;
            }

            case DatasetType.DICOM:
            {
                DatasetImporterBase importer = new DICOMImporter(new FileInfo(filePath).Directory.FullName, false);
                VolumeDataset       dataset  = importer.Import();

                if (dataset != null)
                {
                    VolumeRenderedObject obj = VolumeObjectFactory.CreateObject(dataset);
                }
                break;
            }
            }
        }
Example #5
0
        static void ShowDICOMImporter()
        {
            string dir = EditorUtility.OpenFolderPanel("Select a folder to load", "", "");

            if (Directory.Exists(dir))
            {
                bool recursive = true;

                // Read all files
                IEnumerable <string> fileCandidates = Directory.EnumerateFiles(dir, "*.*", recursive ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly)
                                                      .Where(p => p.EndsWith(".dcm", StringComparison.InvariantCultureIgnoreCase) || p.EndsWith(".dicom", StringComparison.InvariantCultureIgnoreCase) || p.EndsWith(".dicm", StringComparison.InvariantCultureIgnoreCase));

                if (!fileCandidates.Any())
                {
#if UNITY_EDITOR
                    if (UnityEditor.EditorUtility.DisplayDialog("Could not find any DICOM files",
                                                                $"Failed to find any files with DICOM file extension.{Environment.NewLine}Do you want to include files without DICOM file extension?", "Yes", "No"))
                    {
                        fileCandidates = Directory.EnumerateFiles(dir, "*.*", recursive ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly);
                    }
#endif
                }

                if (fileCandidates.Any())
                {
                    DICOMImporter importer = new DICOMImporter(fileCandidates, Path.GetFileName(dir));
                    List <DICOMImporter.DICOMSeries> seriesList = importer.LoadDICOMSeries();
                    float numVolumesCreated = 0;

                    foreach (DICOMImporter.DICOMSeries series in seriesList)
                    {
                        VolumeDataset dataset = importer.ImportDICOMSeries(series);
                        if (dataset != null)
                        {
                            if (EditorPrefs.GetBool("DownscaleDatasetPrompt"))
                            {
                                if (EditorUtility.DisplayDialog("Optional DownScaling",
                                                                $"Do you want to downscale the dataset? The dataset's dimension is: {dataset.dimX} x {dataset.dimY} x {dataset.dimZ}", "Yes", "No"))
                                {
                                    dataset.DownScaleData();
                                }
                            }

                            VolumeRenderedObject obj = VolumeObjectFactory.CreateObject(dataset);
                            obj.transform.position = new Vector3(numVolumesCreated, 0, 0);
                            numVolumesCreated++;
                        }
                    }
                }
                else
                {
                    Debug.LogError("Could not find any DICOM files to import.");
                }
            }
            else
            {
                Debug.LogError("Directory doesn't exist: " + dir);
            }
        }
Example #6
0
 static void SpawnCutoutBox()
 {
     VolumeRenderedObject[] objects = GameObject.FindObjectsOfType <VolumeRenderedObject>();
     if (objects.Length == 1)
     {
         VolumeObjectFactory.SpawnCutoutBox(objects[0]);
     }
 }
Example #7
0
 static void OnMenuItemClick()
 {
     VolumeRenderedObject[] objects = GameObject.FindObjectsOfType <VolumeRenderedObject>();
     if (objects.Length == 1)
     {
         VolumeObjectFactory.SpawnCrossSectionPlane(objects[0]);
     }
     else
     {
         CrossSectionPlaneEditorWindow wnd = new CrossSectionPlaneEditorWindow();
         wnd.Show();
     }
 }
Example #8
0
 private void OnOpenPARDatasetResult(RuntimeFileBrowser.DialogResult result)
 {
     if (!result.cancelled)
     {
         DespawnAllDatasets();
         string             filePath    = result.path;
         ParDatasetImporter parimporter = new ParDatasetImporter(filePath);
         VolumeDataset      dataset     = parimporter.Import(); //overriden somewhere
         if (dataset != null)
         {
             VolumeObjectFactory.CreateObject(dataset);
         }
     }
 }
Example #9
0
        private void OnOpenDICOMDatasetResult(RuntimeFileBrowser.DialogResult result)
        {
            if (!result.cancelled)
            {
                // We'll only allow one dataset at a time in the runtime GUI (for simplicity)
                DespawnAllDatasets();

                // Import the dataset
                DICOMImporter importer = new DICOMImporter(result.path, true);
                VolumeDataset dataset  = importer.Import();
                // Spawn the object
                if (dataset != null)
                {
                    VolumeObjectFactory.CreateObject(dataset);
                }
            }
        }
        private void ImportDataset()
        {
            DatasetImporterBase importer = new RawDatasetImporter(fileToImport, dimX, dimY, dimZ, dataFormat, endianness, bytesToSkip);

            VolumeDataset dataset = importer.Import();

            if (dataset != null)
            {
                VolumeRenderedObject obj = VolumeObjectFactory.CreateObject(dataset);
            }
            else
            {
                Debug.LogError("Failed to import datset");
            }

            this.Close();
        }
Example #11
0
 private void OnGUI()
 {
     VolumeRenderedObject[] spawnedObjects = GameObject.FindObjectsOfType <VolumeRenderedObject>();
     if (spawnedObjects.Length == 0)
     {
         EditorGUILayout.LabelField("Please load a dataset first.");
     }
     else
     {
         foreach (VolumeRenderedObject volobj in spawnedObjects)
         {
             if (GUILayout.Button(volobj.gameObject.name))
             {
                 VolumeObjectFactory.SpawnCrossSectionPlane(volobj);
             }
         }
     }
 }
Example #12
0
        static void ShowDICOMImporter()
        {
            string dir = EditorUtility.OpenFolderPanel("Select a folder to load", "", "");

            if (Directory.Exists(dir))
            {
                DICOMImporter importer = new DICOMImporter(dir, true);
                VolumeDataset dataset  = importer.Import();
                if (dataset != null)
                {
                    VolumeObjectFactory.CreateObject(dataset);
                }
            }
            else
            {
                Debug.LogError("Directory doesn't exist: " + dir);
            }
        }
Example #13
0
        static void ShowDICOMImporter()
        {
            string dir = EditorUtility.OpenFolderPanel("Select a folder to load", "", "");

            if (Directory.Exists(dir))
            {
                bool recursive = true;

                // Read all files
                IEnumerable <string> fileCandidates = Directory.EnumerateFiles(dir, "*.*", recursive ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly)
                                                      .Where(p => p.EndsWith(".dcm", StringComparison.InvariantCultureIgnoreCase) || p.EndsWith(".dicom", StringComparison.InvariantCultureIgnoreCase) || p.EndsWith(".dicm", StringComparison.InvariantCultureIgnoreCase));

                if (!fileCandidates.Any())
                {
#if UNITY_EDITOR
                    if (UnityEditor.EditorUtility.DisplayDialog("Could not find any DICOM files",
                                                                $"Failed to find any files with DICOM file extension.{Environment.NewLine}Do you want to include files without DICOM file extension?", "Yes", "No"))
                    {
                        fileCandidates = Directory.EnumerateFiles(dir, "*.*", recursive ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly);
                    }
#endif
                }

                if (fileCandidates.Any())
                {
                    DICOMImporter importer = new DICOMImporter(fileCandidates, Path.GetFileName(dir));
                    VolumeDataset dataset  = importer.Import();
                    if (dataset != null)
                    {
                        VolumeObjectFactory.CreateObject(dataset);
                    }
                }
                else
                {
                    Debug.LogError("Could not find any DICOM files to import.");
                }
            }
            else
            {
                Debug.LogError("Directory doesn't exist: " + dir);
            }
        }
Example #14
0
        public static void ImportDataset(string filePath)
        {
            DatasetType datasetType = DatasetImporterUtility.GetDatasetType(filePath);

            switch (datasetType)
            {
            case DatasetType.Raw:
            {
                RAWDatasetImporterEditorWindow wnd = (RAWDatasetImporterEditorWindow)EditorWindow.GetWindow(typeof(RAWDatasetImporterEditorWindow));
                if (wnd != null)
                {
                    wnd.Close();
                }

                wnd = new RAWDatasetImporterEditorWindow(filePath);
                wnd.Show();
                break;
            }

            case DatasetType.DICOM:
            {
                string directoryPath = new FileInfo(filePath).Directory.FullName;

                // Find all DICOM files in directory
                IEnumerable <string> fileCandidates = Directory.EnumerateFiles(directoryPath, "*.*", SearchOption.TopDirectoryOnly)
                                                      .Where(p => p.EndsWith(".dcm", StringComparison.InvariantCultureIgnoreCase) || p.EndsWith(".dicom", StringComparison.InvariantCultureIgnoreCase) || p.EndsWith(".dicm", StringComparison.InvariantCultureIgnoreCase));

                DatasetImporterBase importer = new DICOMImporter(fileCandidates, Path.GetFileName(directoryPath));
                VolumeDataset       dataset  = importer.Import();

                if (dataset != null)
                {
                    VolumeRenderedObject obj = VolumeObjectFactory.CreateObject(dataset);
                }
                break;
            }
            }
        }
Example #15
0
        private void OnOpenDICOMDatasetResult(RuntimeFileBrowser.DialogResult result)
        {
            if (!result.cancelled)
            {
                // We'll only allow one dataset at a time in the runtime GUI (for simplicity)
                DespawnAllDatasets();

                bool recursive = true;

                // Read all files
                IEnumerable <string> fileCandidates = Directory.EnumerateFiles(result.path, "*.*", recursive ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly)
                                                      .Where(p => p.EndsWith(".dcm", StringComparison.InvariantCultureIgnoreCase) || p.EndsWith(".dicom", StringComparison.InvariantCultureIgnoreCase) || p.EndsWith(".dicm", StringComparison.InvariantCultureIgnoreCase));

                // Import the dataset
                DICOMImporter importer = new DICOMImporter(fileCandidates, Path.GetFileName(result.path));
                VolumeDataset dataset  = importer.Import();
                // Spawn the object
                if (dataset != null)
                {
                    VolumeObjectFactory.CreateObject(dataset);
                }
            }
        }
Example #16
0
        private void ImportDataset()
        {
            DatasetImporterBase importer = null;

            switch (datasetType)
            {
            case DatasetType.Raw:
            {
                importer = new RawDatasetImporter(fileToImport, dimX, dimY, dimZ, dataFormat, bytesToSkip);
                break;
            }

            case DatasetType.DICOM:
            {
                importer = new DICOMImporter(new FileInfo(fileToImport).Directory.FullName, false);
                break;
            }
            }

            VolumeDataset dataset = null;

            if (importer != null)
            {
                dataset = importer.Import();
            }

            if (dataset != null)
            {
                VolumeRenderedObject obj = VolumeObjectFactory.CreateObject(dataset);
            }
            else
            {
                Debug.LogError("Failed to import datset");
            }

            this.Close();
        }
        private void ImportDataset()
        {
            RawDatasetImporter importer = new RawDatasetImporter(fileToImport, dimX, dimY, dimZ, dataFormat, endianness, bytesToSkip);
            VolumeDataset      dataset  = importer.Import();

            if (dataset != null)
            {
                if (EditorPrefs.GetBool("DownscaleDatasetPrompt"))
                {
                    if (EditorUtility.DisplayDialog("Optional DownScaling",
                                                    $"Do you want to downscale the dataset? The dataset's dimension is: {dataset.dimX} x {dataset.dimY} x {dataset.dimZ}", "Yes", "No"))
                    {
                        dataset.DownScaleData();
                    }
                }
                VolumeRenderedObject obj = VolumeObjectFactory.CreateObject(dataset);
            }
            else
            {
                Debug.LogError("Failed to import datset");
            }

            this.Close();
        }
        private void ImportDataset()
        {
            DatasetImporterBase importer = null;

            switch (datasetType)
            {
            case DatasetType.Raw:
            {
                importer = new RawDatasetImporter(fileToImport, dimX, dimY, dimZ, dataFormat, bytesToSkip);
                break;
            }

            case DatasetType.DICOM:
            {
                throw new System.NotImplementedException("TODO: implement support for DICOM files");
            }
            }

            VolumeDataset dataset = null;

            if (importer != null)
            {
                dataset = importer.Import();
            }

            if (dataset != null)
            {
                VolumeRenderedObject obj = VolumeObjectFactory.CreateObject(dataset);
            }
            else
            {
                Debug.LogError("Failed to import datset");
            }

            this.Close();
        }
        public static void ImportDataset(string filePath)
        {
            DatasetType datasetType = DatasetImporterUtility.GetDatasetType(filePath);

            switch (datasetType)
            {
            case DatasetType.Raw:
            {
                RAWDatasetImporterEditorWindow wnd = (RAWDatasetImporterEditorWindow)EditorWindow.GetWindow(typeof(RAWDatasetImporterEditorWindow));
                if (wnd != null)
                {
                    wnd.Close();
                }

                wnd = new RAWDatasetImporterEditorWindow(filePath);
                wnd.Show();
                break;
            }

            case DatasetType.DICOM:
            {
                string directoryPath = new FileInfo(filePath).Directory.FullName;

                // Find all DICOM files in directory
                IEnumerable <string> fileCandidates = Directory.EnumerateFiles(directoryPath, "*.*", SearchOption.TopDirectoryOnly)
                                                      .Where(p => p.EndsWith(".dcm", StringComparison.InvariantCultureIgnoreCase) || p.EndsWith(".dicom", StringComparison.InvariantCultureIgnoreCase) || p.EndsWith(".dicm", StringComparison.InvariantCultureIgnoreCase));

                DICOMImporter importer = new DICOMImporter(fileCandidates, Path.GetFileName(directoryPath));

                List <DICOMImporter.DICOMSeries> seriesList = importer.LoadDICOMSeries();
                foreach (DICOMImporter.DICOMSeries series in seriesList)
                {
                    // Only import the series that contains the selected file
                    if (series.dicomFiles.Any(f => Path.GetFileName(f.filePath) == Path.GetFileName(filePath)))
                    {
                        VolumeDataset dataset = importer.ImportDICOMSeries(series);

                        if (dataset != null)
                        {
                            VolumeRenderedObject obj = VolumeObjectFactory.CreateObject(dataset);
                        }
                    }
                }
                break;
            }

            case DatasetType.PARCHG:
            {
                ParDatasetImporter importer = new ParDatasetImporter(filePath);
                VolumeDataset      dataset  = importer.Import();

                if (dataset != null)
                {
                    VolumeRenderedObject obj = VolumeObjectFactory.CreateObject(dataset);
                }
                else
                {
                    Debug.LogError("Failed to import datset");
                }
                break;
            }
            }
        }