Beispiel #1
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);
                    }
                }
            }
        }
Beispiel #2
0
        public static DatasetIniData ParseIniFile(string filePath)
        {
            if (!File.Exists(filePath))
            {
                return(null);
            }

            string[] lines = File.ReadAllLines(filePath);

            DatasetIniData iniData = new DatasetIniData();

            foreach (string line in lines)
            {
                string[] parts = line.Trim(' ').Split(':');
                if (parts.Length != 2)
                {
                    continue;
                }

                string name  = parts[0];
                string value = parts[1];

                if (name == "dimx")
                {
                    Int32.TryParse(value, out iniData.dimX);
                }
                else if (name == "dimy")
                {
                    Int32.TryParse(value, out iniData.dimY);
                }
                else if (name == "dimz")
                {
                    Int32.TryParse(value, out iniData.dimZ);
                }
                else if (name == "skip")
                {
                    Int32.TryParse(value, out iniData.bytesToSkip);
                }
                else if (name == "format")
                {
                    iniData.format = GetFormatByName(value);
                }
                else if (name == "endianness")
                {
                    iniData.endianness = GetEndiannessByName(value);
                }
            }

            return(iniData);
        }
Beispiel #3
0
        public DatasetImporterEditorWindow(string fileToImport)
        {
            // Check file extension
            string extension = Path.GetExtension(fileToImport);

            if (extension == ".dat" || extension == ".raw" || extension == ".vol")
            {
                datasetType = DatasetType.Raw;
            }
            else if (extension == ".ini")
            {
                fileToImport = fileToImport.Substring(0, fileToImport.LastIndexOf("."));
                datasetType  = DatasetType.Raw;
            }
            else if (extension == ".dicom" || extension == ".dcm")
            {
                datasetType = DatasetType.DICOM;
            }
            else
            {
                datasetType = DatasetType.Unknown;
            }

            this.fileToImport = fileToImport;

            // Try parse ini file (if available)
            DatasetIniData initData = DatasetIniReader.ParseIniFile(fileToImport + ".ini");

            if (initData != null)
            {
                dimX        = initData.dimX;
                dimY        = initData.dimY;
                dimZ        = initData.dimZ;
                bytesToSkip = initData.bytesToSkip;
                dataFormat  = initData.format;
                endianness  = initData.endianness;
            }

            this.minSize = new Vector2(300.0f, 200.0f);
        }
        public RAWDatasetImporterEditorWindow(string filePath)
        {
            fileToImport = filePath;

            if (Path.GetExtension(fileToImport) == ".ini")
            {
                fileToImport = fileToImport.Replace(".ini", ".raw");
            }

            // Try parse ini file (if available)
            DatasetIniData initData = DatasetIniReader.ParseIniFile(fileToImport + ".ini");

            if (initData != null)
            {
                dimX        = initData.dimX;
                dimY        = initData.dimY;
                dimZ        = initData.dimZ;
                bytesToSkip = initData.bytesToSkip;
                dataFormat  = initData.format;
                endianness  = initData.endianness;
            }

            this.minSize = new Vector2(300.0f, 200.0f);
        }