public static int Main(string[] args) { gdcm.Global global = gdcm.Global.GetInstance(); if (!global.LoadResourcesFiles()) { System.Console.WriteLine("Could not LoadResourcesFiles"); return(1); } string file1 = args[0]; string file2 = args[1]; Reader reader = new Reader(); reader.SetFileName(file1); bool ret = reader.Read(); if (!ret) { return(1); } string certpath = gdcm.Filename.Join(gdcm.Testing.GetSourceDirectory(), "/Testing/Source/Data/certificate.pem"); gdcm.CryptoFactory fact = gdcm.CryptoFactory.GetFactoryInstance(); gdcm.CryptographicMessageSyntax cms = fact.CreateCMSProvider(); if (!cms.ParseCertificateFile(certpath)) { return(1); } //Anonymizer ano = new Anonymizer(); SmartPtrAno sano = Anonymizer.New(); Anonymizer ano = sano.__ref__(); //SimpleSubjectWatcher watcher = new SimpleSubjectWatcher(ano, "Anonymizer"); MyWatcher watcher = new MyWatcher(ano); ano.SetFile(reader.GetFile()); ano.SetCryptographicMessageSyntax(cms); if (!ano.BasicApplicationLevelConfidentialityProfile()) { return(1); } Writer writer = new Writer(); writer.SetFileName(file2); writer.SetFile(ano.GetFile()); ret = writer.Write(); if (!ret) { return(1); } return(0); }
private void FramesQuery(string PatientId) { gdcm.ERootType typ = gdcm.ERootType.ePatientRootType; gdcm.EQueryLevel poziom = gdcm.EQueryLevel.ePatient; // zobacz inne gdcm.KeyValuePairArrayType klucze = new gdcm.KeyValuePairArrayType(); gdcm.KeyValuePairType klucz1 = new gdcm.KeyValuePairType(new gdcm.Tag(0x0010, 0x0020), PatientId); // NIE WOLNO TU STOSOWAC *; tutaj PatientID="01" klucze.Add(klucz1); // skonstruuj zapytanie gdcm.BaseRootQuery zapytanie = gdcm.CompositeNetworkFunctions.ConstructQuery(typ, poziom, klucze, true); // sprawdź, czy zapytanie spełnia kryteria if (!zapytanie.ValidateQuery()) { MessageBox.Show("Wrong frames query.", "Error"); } // przygotuj katalog na wyniki String odebrane = System.IO.Path.Combine(".", "temporary"); if (!System.IO.Directory.Exists(odebrane)) { System.IO.Directory.CreateDirectory(odebrane); } dane = System.IO.Path.Combine(odebrane, System.IO.Path.GetRandomFileName()); //katalog System.IO.Directory.CreateDirectory(dane); // wykonaj zapytanie - pobierz do katalogu _dane_ bool stan = gdcm.CompositeNetworkFunctions.CMove(ip, port, zapytanie, port, aet, call, dane); // sprawdź stan if (!stan) { MessageBox.Show("PACS server doesn't work.", "Error"); } // skasowanie listy zdjęć Images.Clear(); ImageNames.Clear(); Datas.Clear(); List <string> pliki = new List <string>(System.IO.Directory.EnumerateFiles(dane)); //nazwy plikow foreach (String plik in pliki) { gdcm.Reader dataReader = new gdcm.Reader(); dataReader.SetFileName(plik); if (!dataReader.Read()) { continue; } gdcm.File file = dataReader.GetFile(); gdcm.DataSet dataSet = file.GetDataSet(); string data = dataSet.toString(); gdcm.Global g = gdcm.Global.GetInstance(); gdcm.Dicts dicts = g.GetDicts(); gdcm.Dict dict = dicts.GetPublicDict(); string[] dataArray = dataSet.toString().Split('\n'); Dictionary <string, string> dataValues = new Dictionary <string, string>(); String[] id = plik.Split('\\'); foreach (string s in dataArray) { string[] dataArrayRow = s.Split('\t'); if (dataArrayRow.Length > 1) { string[] tags = dataArrayRow[0].Remove(0, 1).Remove(dataArrayRow[0].Length - 2, 1).Split(','); //Pobranie nazwy Tagu //gdcm.Tag tag = new gdcm.Tag(Convert.ToUInt16(tags[0]),Convert.ToUInt16(tags[1])); //string dictDorTag = dict.GetKeywordFromTag(tag); //if (dictDorTag != null) // dataValues.Add(dictDorTag, dataArrayRow[dataArrayRow.Length - 1]); dataValues.Add(dataArrayRow[0], dataArrayRow[dataArrayRow.Length - 1]); } } // przeczytaj pixele gdcm.PixmapReader reader = new gdcm.PixmapReader(); reader.SetFileName(plik); if (!reader.Read()) { continue; } // przekonwertuj na "znany format" gdcm.Bitmap bmjpeg2000 = PACS.ImageConverter.pxmap2jpeg2000(reader.GetPixmap()); // przekonwertuj na .NET bitmapy System.Drawing.Bitmap[] X = PACS.ImageConverter.gdcmBitmap2Bitmap(bmjpeg2000); // zapisz for (int i = 0; i < X.Length; i++) { String name = ""; if (X.Length > 1) { name = String.Format("{0}_slice{1}.jpg", plik, i); Images.Add(String.Format("{0}_slice{1}", id[id.Length - 1], i), X[i]); ImageNames.Add(String.Format("{0}_slice{1}", id[id.Length - 1], i)); Datas.Add(String.Format("{0}_slice{1}", id[id.Length - 1], i), dataValues); } else { name = String.Format("{0}.jpg", plik); Images.Add(String.Format("{0}", id[id.Length - 1]), X[i]); ImageNames.Add(String.Format("{0}", id[id.Length - 1])); Datas.Add(String.Format("{0}", id[id.Length - 1]), dataValues); } X[i].Save(name); } } }
public static int Main(string[] args) { gdcm.FileMetaInformation.SetSourceApplicationEntityTitle("My ClinicalTrial App"); // http://www.oid-info.com/get/1.3.6.1.4.17434 string THERALYS_ORG_ROOT = "1.3.6.1.4.17434"; gdcm.UIDGenerator.SetRoot(THERALYS_ORG_ROOT); System.Console.WriteLine("Root dir is now: " + gdcm.UIDGenerator.GetRoot()); gdcm.Global global = gdcm.Global.GetInstance(); if (!global.LoadResourcesFiles()) { System.Console.WriteLine("Could not LoadResourcesFiles"); return(1); } if (args.Length != 2) { System.Console.WriteLine("Usage:"); System.Console.WriteLine("ClinicalTrialIdentificationWorkflow input_dir output_dir"); return(1); } string dir1 = args[0]; string dir2 = args[1]; // Check input is valid: if (!gdcm.PosixEmulation.FileIsDirectory(dir1)) { System.Console.WriteLine("Input directory: " + dir1 + " does not exist. Sorry"); return(1); } if (!gdcm.PosixEmulation.FileIsDirectory(dir2)) { System.Console.WriteLine("Output directory: " + dir2 + " does not exist. Sorry"); return(1); } // Recursively search all file within this toplevel directory: Directory d = new Directory(); uint nfiles = d.Load(dir1, true); if (nfiles == 0) { return(1); } // Let's use the pre-shipped certificate of GDCM. string certpath = gdcm.Filename.Join(gdcm.Testing.GetSourceDirectory(), "/Testing/Source/Data/certificate.pem"); gdcm.CryptographicMessageSyntax cms = new gdcm.CryptographicMessageSyntax(); if (!cms.ParseCertificateFile(certpath)) { System.Console.WriteLine("PEM Certificate : " + certpath + " could not be read. Sorry"); return(1); } //Anonymizer ano = new Anonymizer(); // A reference to an actual C++ instance is required here: SmartPtrAno sano = Anonymizer.New(); Anonymizer ano = sano.__ref__(); //SimpleSubjectWatcher watcher = new SimpleSubjectWatcher(ano, "Anonymizer"); MyWatcher watcher = new MyWatcher(ano); // Explicitely specify the Cryptographic Message Syntax to use: ano.SetCryptographicMessageSyntax(cms); // Process all filenames: FilenamesType filenames = d.GetFilenames(); for (uint i = 0; i < nfiles; ++i) { string filename = filenames[(int)i]; string outfilename = filename.Replace(dir1, dir2); System.Console.WriteLine("Filename: " + filename); System.Console.WriteLine("Out Filename: " + outfilename); if (!ProcessOneFile(ano, filename, outfilename)) { System.Console.WriteLine("Could not process filename: " + filename); return(1); } } return(0); }
private void FramesQuery(string PatientId, out string dane, out string name, out Dictionary <string, Dictionary <string, string> > Datas, out string segmentation_name) { gdcm.ERootType typ = gdcm.ERootType.ePatientRootType; gdcm.EQueryLevel poziom = gdcm.EQueryLevel.ePatient; // zobacz inne gdcm.KeyValuePairArrayType klucze = new gdcm.KeyValuePairArrayType(); gdcm.KeyValuePairType klucz1 = new gdcm.KeyValuePairType(new gdcm.Tag(0x0010, 0x0020), PatientId); // NIE WOLNO TU STOSOWAC *; tutaj PatientID="01" klucze.Add(klucz1); // skonstruuj zapytanie gdcm.BaseRootQuery zapytanie = gdcm.CompositeNetworkFunctions.ConstructQuery(typ, poziom, klucze, true); // sprawdź, czy zapytanie spełnia kryteria if (!zapytanie.ValidateQuery()) { MessageBox.Show("Wrong frames query.", "Error"); } // przygotuj katalog na wyniki String odebrane = System.IO.Path.Combine(".", "temporary"); if (!System.IO.Directory.Exists(odebrane)) { System.IO.Directory.CreateDirectory(odebrane); } dane = System.IO.Path.Combine(odebrane, System.IO.Path.GetRandomFileName()); //katalog System.IO.Directory.CreateDirectory(dane); // wykonaj zapytanie - pobierz do katalogu _dane_ bool stan = gdcm.CompositeNetworkFunctions.CMove(ip, port, zapytanie, 10104, aet, call, dane); // sprawdź stan if (!stan) { MessageBox.Show("PACS server doesn't work.", "Error"); } // skasowanie listy zdjęć name = ""; segmentation_name = ""; Datas = new Dictionary <string, Dictionary <string, string> >(); List <string> pliki = new List <string>(System.IO.Directory.EnumerateFiles(dane)); //nazwy plikow //OBRAZ ORYGINALNY gdcm.Reader dataReader = new gdcm.Reader(); dataReader.SetFileName(pliki[0]); if (!dataReader.Read()) { } gdcm.File file = dataReader.GetFile(); gdcm.DataSet dataSet = file.GetDataSet(); string data = dataSet.toString(); gdcm.Global g = gdcm.Global.GetInstance(); gdcm.Dicts dicts = g.GetDicts(); gdcm.Dict dict = dicts.GetPublicDict(); string[] dataArray = dataSet.toString().Split('\n'); Dictionary <string, string> dataValues = new Dictionary <string, string>(); String[] id = pliki[0].Split('\\'); bool first_exp = true; bool first_original = true; foreach (string plik in pliki) { dataValues.Clear(); foreach (string s in dataArray) { string[] dataArrayRow = s.Split('\t'); if (dataArrayRow.Length > 1) { string[] tags = dataArrayRow[0].Remove(0, 1).Remove(dataArrayRow[0].Length - 2, 1).Split(','); //Pobranie nazwy Tagu //gdcm.Tag tag = new gdcm.Tag(Convert.ToUInt16(tags[0]),Convert.ToUInt16(tags[1])); //string dictDorTag = dict.GetKeywordFromTag(tag); //if (dictDorTag != null) // dataValues.Add(dictDorTag, dataArrayRow[dataArrayRow.Length - 1]); dataValues.Add(dataArrayRow[0], dataArrayRow[dataArrayRow.Length - 1]); } } if (dataValues.Count > 0) { if (dataValues["(0020,000d)"].Substring(0, 1) == "E" && first_exp == true) {//OBRAZ SEGMENTACJI gdcm.Reader dataReader2 = new gdcm.Reader(); dataReader2.SetFileName(plik); if (!dataReader2.Read()) { } gdcm.File file2 = dataReader2.GetFile(); // przeczytaj pixele gdcm.PixmapReader reader2 = new gdcm.PixmapReader(); string temp = plik; if (plik.Substring(plik.Length - 4, 4) != ".dcm") { temp = pliki[1] + ".dcm"; } reader2.SetFileName(plik); if (!reader2.Read()) { } segmentation_name = String.Format("{0}", plik.Substring(0, plik.Length - 4)); first_exp = false; } else { if (first_original == true) { // przeczytaj pixele gdcm.PixmapReader reader = new gdcm.PixmapReader(); string temp = plik; if (plik.Substring(plik.Length - 4, 4) != ".dcm") { temp = plik + ".dcm"; } reader.SetFileName(plik); if (!reader.Read()) { } name = String.Format("{0}", plik.Substring(0, plik.Length - 4)); Datas.Add(String.Format("{0}", plik.Substring(0, plik.Length - 4)).Replace("\\", "\\\\"), dataValues); first_original = false; } else { gdcm.Reader dataReader2 = new gdcm.Reader(); dataReader2.SetFileName(plik); if (!dataReader2.Read()) { } gdcm.File file2 = dataReader2.GetFile(); // przeczytaj pixele gdcm.PixmapReader reader2 = new gdcm.PixmapReader(); string temp = plik; if (plik.Substring(plik.Length - 4, 4) != ".dcm") { temp = pliki[1] + ".dcm"; } reader2.SetFileName(plik); if (!reader2.Read()) { } segmentation_name = String.Format("{0}", plik.Substring(0, plik.Length - 4)); first_exp = false; } } } } }