//全タグ取得 public static void GetDicomTagAll(string path, out List <DicomTagItem> items) { items = new List <DicomTagItem>(); if (File.Exists(path)) { using (var dcm = DicomData.Open(path)) { foreach (DicomTag tag in dcm) { var item = new DicomTagItem(); item.Tag = tag.Tag; item.VR = tag.VR; item.DataSize = tag.DataSize; if (tag.DataSize >= 0 && tag.DataSize <= 1024) { item.Value = tag.ToString(); } else { item.Value = ""; } var tagData = DicomTagTbl.GetTagData(tag.Tag); if (tagData != null) { item.EName = tagData.EName; item.JName = tagData.JName; } items.Add(item); } } } }
//サムネイル作成 public static void DicomToThumb(string file, out byte[] thumb) { lock (dicomLock) { using (var dcm = new DicomData(file)) { DicomToThumb(dcm, out thumb); } } }
public static void DicomToThumb(IDicomStream stream, out byte[] thumb) { lock (dicomLock) { using (var dcm = new DicomData(stream)) { DicomToThumb(dcm, out thumb); } } }
private static void DicomToThumb(DicomData dcm, out byte[] thumb) { thumb = null; if (dcm.Images.Load()) { var ctrl = dcm.Images.CreateImageControl(0); if (ctrl != null) { int width = AppUtil.THUMB_SIZE * 2; int height = AppUtil.THUMB_SIZE * 2; if (ctrl.Width > width || ctrl.Height > height) { if (ctrl.Width <= ctrl.Height) { width = width * ctrl.Width / ctrl.Height; } else { height = height * ctrl.Height / ctrl.Width; } ctrl = new ImageControl(ctrl, new Rectangle(0, 0, ctrl.Width, ctrl.Height), width, height, true); } width = AppUtil.THUMB_SIZE; height = AppUtil.THUMB_SIZE; if (ctrl.Width <= ctrl.Height) { width = width * ctrl.Width / ctrl.Height; } else { height = height * ctrl.Height / ctrl.Width; } ctrl = new ImageControl(ctrl, new Rectangle(0, 0, ctrl.Width, ctrl.Height), width, height, false); using (var img = ctrl.CreateImage()) using (var ms = new MemoryStream()) using (var bmp = new Bitmap(AppUtil.THUMB_SIZE, AppUtil.THUMB_SIZE)) using (var g = Graphics.FromImage(bmp)) { g.Clear(Color.FromArgb(0, Color.Black)); g.DrawImage(img, (AppUtil.THUMB_SIZE - img.Width) / 2, (AppUtil.THUMB_SIZE - img.Height) / 2); bmp.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg); thumb = ms.GetBuffer(); } } } }
//SeriesTagの取得 public static void GetSeriesTag(string file, out SeriesTag tag) { tag = new SeriesTag(); using (var dcm = new DicomData(file)) { var dic = DicomTagDictionary.Open(dcm, DcmTag.ToTagArray(DCM.SERIES_TAG)); tag.Modality = dic.GetValue <string>(DcmTag.Modality.Tag, ""); tag.SeriesDescription = dic.GetValue <string>(DcmTag.SeriesDescription.Tag, ""); tag.SeriesNumber = dic.GetValue <long>(DcmTag.SeriesNumber.Tag, 0); tag.NumberOfImages = 1; if (dcm.Images.Load()) { tag.NumberOfFrames = dcm.Images.NumberOfFrame; } } }
//MEGファイルの作成 private static void DicomToMeg(string file, string dicomFile, double scale) { using (var dcm = new DicomData(file)) { if (dcm.Images.Load()) { if (dcm.Images.Bits == 8 || dcm.Images.Bits == 24) { File.Copy(file, dicomFile, true); } else { using (var ms = new MemoryStream()) { MegData.ConvertToFile(dcm, dicomFile, scale); } } } } }
//タグ取得 public static void GetDicomTag(string path, uint[] tags, out List <DicomTagItem> items) { items = new List <DicomTagItem>(); if (File.Exists(path)) { using (var dcm = DicomData.Open(path)) { var dic = DicomAnalyzer.DicomTagDictionary.Open(dcm, tags); foreach (var dicP in dic) { var tag = dicP.Value; var item = new DicomTagItem(); item.Tag = tag.Tag; item.VR = tag.VR; item.DataSize = tag.DataSize; if (tag.Tag != 0x7FE00010) { item.Value = tag.ToString(); } else { item.Value = ""; } var tagData = DicomTagTbl.GetTagData(tag.Tag); if (tagData != null) { item.EName = tagData.EName; item.JName = tagData.JName; } items.Add(item); } } } }
//ImageTagの取得 public static void GetImageTag(string file, out ImageTag tag) { tag = new ImageTag(); using (var dcm = new DicomData(file)) { var dic = DicomTagDictionary.Open(dcm, DcmTag.ToTagArray(DCM.IMAGE_TAG)); tag.InstanceNumber = dic.GetValue <long>(DcmTag.InstanceNumber.Tag, 0); tag.SliceThickness = dic.GetValue <string>(DcmTag.SliceThickness.Tag, ""); tag.ImagePositionPatient = dic.GetValue <string>(DcmTag.ImagePositionPatient.Tag, ""); tag.ImageOrientationPatient = dic.GetValue <string>(DcmTag.ImageOrientationPatient.Tag, ""); tag.SliceLocation = dic.GetValue <string>(DcmTag.SliceLocation.Tag, ""); tag.Rows = dic.GetValue <int>(DcmTag.Rows.Tag, 0); tag.Columns = dic.GetValue <int>(DcmTag.Columns.Tag, 0); tag.PixelSpacing = dic.GetValue <string>(DcmTag.PixelSpacing.Tag, ""); tag.WindowCenter = dic.GetValue <string>(DcmTag.WindowCenter.Tag, ""); tag.WindowWidth = dic.GetValue <string>(DcmTag.WindowWidth.Tag, ""); if (dcm.Images.Load()) { if (dcm.Images.Bits == 8 || dcm.Images.Bits == 24) { tag.WindowCenter = "127"; tag.WindowWidth = "255"; } else { ImageControl ctrl = null; if (dcm.Images.WindowCenters.Length > 0) { tag.WindowCenter = dcm.Images.WindowCenters[0].ToString(); } else { if (ctrl == null) { ctrl = dcm.Images.CreateImageControl(0); } //MinMax if (ctrl != null) { tag.WindowCenter = ctrl.WindowCenter.ToString(); } } if (dcm.Images.WindowWidths.Length > 0) { tag.WindowWidth = dcm.Images.WindowWidths[0].ToString(); } else { if (ctrl == null) { ctrl = dcm.Images.CreateImageControl(0); } //MinMax if (ctrl != null) { tag.WindowWidth = ctrl.WindowWidth.ToString(); } } } tag.NumberOfFrames = dcm.Images.NumberOfFrame; } } }
private DicomData[] LoadFiles(string[] fullfilesPath) { DICOMObject dicom; DicomData[] DicomFile = new DicomData[fullfilesPath.Length]; for (int curImg = 0; curImg < fullfilesPath.Length; curImg++) { progressBar1.Value = curImg; string file = fullfilesPath[curImg]; dicom = DICOMObject.Read(file); DicomFile[curImg].sizeRow = Convert.ToInt32(dicom.FindFirst("00280010").DData); DicomFile[curImg].sizeCol = Convert.ToInt32(dicom.FindFirst("00280011").DData); DicomFile[curImg].fileName = Path.GetFileName(fullfilesPath[curImg]); DicomFile[curImg].fullFilePath = fullfilesPath[curImg]; var pixelData = dicom.FindFirst("7FE00010").DData_; DicomFile[curImg].PixelDataOrig = new dynamic[DicomFile[curImg].sizeRow * DicomFile[curImg].sizeCol]; var typeData = Convert.ToInt16(dicom.FindFirst("00280100").DData); switch (typeData) { case 8: if (pixelData.Count != DicomFile[curImg].sizeRow * DicomFile[curImg].sizeCol) { dynamic[] temp = new dynamic[pixelData.Count]; pixelData.CopyTo(temp, 0); dynamic[] temp2 = new dynamic[DicomFile[curImg].sizeRow * DicomFile[curImg].sizeCol]; temp2 = temp.Skip(1).Take(DicomFile[curImg].sizeRow * DicomFile[curImg].sizeCol).ToArray(); for (int i = 0; i < temp2.Length; i++) { temp2[i] = temp2[i] ?? 0; } temp2.CopyTo(DicomFile[curImg].PixelDataOrig, 0); } else { pixelData.CopyTo(DicomFile[curImg].PixelDataOrig, 0); } break; case 16: var PixelDataArray = new ushort[DicomFile[curImg].sizeRow * DicomFile[curImg].sizeCol * 2]; pixelData.CopyTo(PixelDataArray, 0); int pix = 0; for (int i = 0; i < DicomFile[curImg].sizeRow * DicomFile[curImg].sizeCol * 2; i += 2) { DicomFile[curImg].PixelDataOrig[pix++] = (ushort)(PixelDataArray[i] | PixelDataArray[i + 1] << 8); } break; } var rescaleSlope = (float)Convert.ToDouble(dicom.FindFirst("00281053").DData); var rescaleIntercept = (float)Convert.ToDouble(dicom.FindFirst("00281052").DData); for (int i = 0; i < DicomFile[curImg].PixelDataOrig.Length; i++) { DicomFile[curImg].PixelDataOrig[i] = DicomFile[curImg].PixelDataOrig[i] * rescaleSlope + rescaleIntercept; } } progressBar1.Value = 0; label2.Visible = true; return(DicomFile); }
public PRAnalyzer(DicomData dcm) { var dic = DicomTagDictionary.Open(dcm, 0x81115, //参照シリーズシーケンス 0x700001, //図形シーケンス 0x283110, //ソフトコピーVOI LUTシーケンス 0x700041, //画像水平フリップ 0x700042, //画像回転 0x70005A //表示領域選択シーケンス ); var tag = dic[0x700001]; if (tag == null) { return; } if (dic[0x700041] != null) { Flip = dic[0x700041].ToString() == "Y"; } if (dic[0x700042] != null) { Rotate = dic[0x700042].ToValue(0d); } List <PRDisplayArea> displayareas = new List <PRDisplayArea>(); var displayareatag = dic[0x70005A]; if (displayareatag != null) { foreach (var t in displayareatag) { if (t.Tag != 0xfffee000) { continue; } PRDisplayArea refobj = new PRDisplayArea(); var dic2 = DicomTagDictionary.Open(t, 0x81140, //参照画像シーケンス 0x700052, //表示領域上左手コーナ 0x700053, //表示領域下右手コーナ 0x700100, //提示寸法モード 0x700101 //提示画素間隔 ); var seriesuid = dic2[0x20000E]; if (dic2[0x700052] != null && dic2[0x700053] != null) { refobj.PointLU = new PRPoint(dic2[0x700052].ToArray(new double[] { 0, 0 })); refobj.PointRD = new PRPoint(dic2[0x700053].ToArray(new double[] { 0, 0 })); } else { continue; } if (dic2[0x700100] != null) { refobj.SizeMode = dic2[0x700100].ToString(); } if (dic2[0x700101] != null) { refobj.PixelSpacing = new PRPoint(dic2[0x700101].ToArray(new double[] { 0, 0 })); } List <PRReferenceSOP> referencesop = new List <PRReferenceSOP>(); var imageseq = dic2[0x81140]; if (imageseq != null) { foreach (var t2 in imageseq) { if (t2.Tag != 0xfffee000) { continue; } var dic3 = DicomTagDictionary.Open(t2, 0x81150, 0x81155, 0x81160); var cuid = dic3[0x81150]; var uid = dic3[0x81155]; var frame = dic3[0x81160]; if (cuid != null && uid != null) { PRReferenceSOP refobjsop = new PRReferenceSOP() { SOPClassUID = cuid.ToString(), SOPInstanceUID = uid.ToString() }; if (frame != null) { refobjsop.FrameNumber = frame.ToValue(0); } referencesop.Add(refobjsop); } } } refobj.SopRefs = referencesop.ToArray(); displayareas.Add(refobj); } } DisplayAreas = displayareas.ToArray(); List <PRVoiLut> voiluts = new List <PRVoiLut>(); var voiluttag = dic[0x283110]; if (voiluttag != null) { foreach (var t in voiluttag) { if (t.Tag != 0xfffee000) { continue; } PRVoiLut refobj = new PRVoiLut(); var dic2 = DicomTagDictionary.Open(t, 0x81140, //参照画像シーケンス 0x281050, //ウィンドウ中心 0x281051 //ウィンドウ幅 ); var seriesuid = dic2[0x20000E]; if (dic2[0x281050] != null && dic2[0x281051] != null) { refobj.WindowCenter = dic2[0x281050].ToValue(0d); refobj.WindowWidth = dic2[0x281051].ToValue(0d); } else { continue; } List <PRReferenceSOP> referencesop = new List <PRReferenceSOP>(); var imageseq = dic2[0x81140]; if (imageseq != null) { foreach (var t2 in imageseq) { if (t2.Tag != 0xfffee000) { continue; } var dic3 = DicomTagDictionary.Open(t2, 0x81150, 0x81155, 0x81160); var cuid = dic3[0x81150]; var uid = dic3[0x81155]; var frame = dic3[0x81160]; if (cuid != null && uid != null) { PRReferenceSOP refobjsop = new PRReferenceSOP() { SOPClassUID = cuid.ToString(), SOPInstanceUID = uid.ToString() }; if (frame != null) { refobjsop.FrameNumber = frame.ToValue(0); } referencesop.Add(refobjsop); } } } refobj.SopRefs = referencesop.ToArray(); voiluts.Add(refobj); } } VoiLuts = voiluts.ToArray(); List <PRReference> reference = new List <PRReference>(); var refseriestag = dic[0x81115]; if (refseriestag != null) { foreach (var t in refseriestag) { if (t.Tag != 0xfffee000) { continue; } PRReference refobj = new PRReference(); var dic2 = DicomTagDictionary.Open(t, 0x81140, //参照画像シーケンス 0x20000E //シリーズインスタンスUID ); var seriesuid = dic2[0x20000E]; if (dic2[0x81140] != null) { refobj.SeriesInstanceUID = dic2[0x81140].ToString(); } List <PRReferenceSOP> referencesop = new List <PRReferenceSOP>(); var imageseq = dic2[0x81140]; if (imageseq != null) { foreach (var t2 in imageseq) { if (t2.Tag != 0xfffee000) { continue; } var dic3 = DicomTagDictionary.Open(t2, 0x81150, 0x81155, 0x81160); var cuid = dic3[0x81150]; var uid = dic3[0x81155]; var frame = dic3[0x81160]; if (cuid != null && uid != null) { PRReferenceSOP refobjsop = new PRReferenceSOP() { SOPClassUID = cuid.ToString(), SOPInstanceUID = uid.ToString() }; if (frame != null) { refobjsop.FrameNumber = frame.ToValue(0); } referencesop.Add(refobjsop); } } } if (seriesuid != null) { refobj.SeriesInstanceUID = seriesuid.ToString(); } refobj.SopRefs = referencesop.ToArray(); reference.Add(refobj); } } References = reference.ToArray(); List <PRInfo> infos = new List <PRInfo>(); foreach (var t in tag) { if (t.Tag != 0xfffee000) { continue; } PRInfo info = new PRInfo(); List <PRReferenceSOP> refs = new List <PRReferenceSOP>(); var dic2 = DicomTagDictionary.Open(t, 0x81140, 0x700002, 0x700008, 0x700009); var reftag = dic2[0x81140]; var layertag = dic2[0x700002]; var txtobjtag = dic2[0x700008]; var shapeobjtag = dic2[0x700009]; foreach (var r in reftag) { var dic3 = DicomTagDictionary.Open(r, 0x81150, 0x81155, 0x81160); var cuid = dic3[0x81150]; var uid = dic3[0x81155]; var frame = dic3[0x81160]; if (cuid != null && uid != null) { PRReferenceSOP refobj = new PRReferenceSOP() { SOPClassUID = cuid.ToString(), SOPInstanceUID = uid.ToString() }; if (frame != null) { refobj.FrameNumber = frame.ToValue(0); } refs.Add(refobj); } } info.Reference.SopRefs = refs.ToArray(); info.Layer = layertag.ToString(); List <PRDrawItem> drawitems = new List <PRDrawItem>(); if (txtobjtag != null) { foreach (var r in txtobjtag) { if (r.Tag != 0xfffee000) { continue; } var dic4 = DicomTagDictionary.Open(r, 0x700006, //Text 0x700010, //LU 0x700011, //RD 0x700012, //Format 0x711001, //Type // 0x41051005,//色 0x00700014, //アンカー点 0x00700015 //アンカー点可視 ); PRDrawItem item = new PRDrawItem(); item.Text = dic4[0x700006].ToString(); if (dic4[0x700010] != null && dic4[0x700011] != null) { item.Points.Add(new PRPoint(dic4[0x700010].ToArray(new double[] { 0, 0 }))); item.Points.Add(new PRPoint(dic4[0x700011].ToArray(new double[] { 0, 0 }))); } else { continue; } if (dic4[0x41051005] != null) { StringBuilder sb = new StringBuilder(); var c = dic4[0x41051005].ToArray(new int[] { 255, 0, 0 });//デフォルトカラー if (c.Length == 3) { sb.AppendFormat("#{0:X2}{1:X2}{2:X2}", c[0], c[1], c[2]);//#RGBを構成 item.Color = sb.ToString(); } } if (dic4[0x00700014] != null && dic4[0x00700015] != null) { item.AnchorPoint = new PRPoint(dic4[0x00700014].ToArray(new double[] { 0, 0 })); item.AnchorVisible = dic4[0x00700015].ToString() == "Y"; } if (dic4[0x711001] != null) { item.DrawType = dic4[0x711001].ToString(); } else { item.DrawType = "TEXT"; } if (dic4[0x700012] != null) { item.TextFormat = dic4[0x700012].ToString(); } drawitems.Add(item); } } if (shapeobjtag != null) { foreach (var r in shapeobjtag) { if (r.Tag != 0xfffee000) { continue; } var dic4 = DicomTagDictionary.Open(r, 0x700022, //図形データ 0x700023 //図形タイプ //,0x41051005//色 //,0x41051001//図形タイプ拡張 //,0x41051002//図形文字 ); PRDrawItem item = new PRDrawItem(); if (dic4[0x700022] != null) { var p = dic4[0x700022].ToArray(new double[0]); for (int i = 0; i < p.Length; i += 2) { item.Points.Add(new PRPoint(p, i)); } } else { continue; } if (dic4[0x700023] != null) { item.DrawType = dic4[0x700023].ToString(); } if (dic4[0x41051005] != null) { StringBuilder sb = new StringBuilder(); var c = dic4[0x41051005].ToArray(new int[] { 255, 0, 0 });//デフォルトカラー if (c.Length == 3) { sb.AppendFormat("#{0:X2}{1:X2}{2:X2}", c[0], c[1], c[2]);//#RGBを構成 item.Color = sb.ToString(); } } if (dic4[0x41051001] != null) { item.DrawTypeEx = dic4[0x41051001].ToString(); } if (dic4[0x41051002] != null) { item.Text = dic4[0x41051002].ToString(); } drawitems.Add(item); } } info.DrawItems = drawitems.ToArray(); infos.Add(info); } Infos = infos.ToArray(); }
private static void GetImage(string UserName, string StorageID, string StudyUID, string SeriesUID, string SopUID) { LogUtil.Debug3("CMOVE [{0}][{1}][{2}]", StudyUID, SeriesUID, SopUID); var sto = DbCacheUtil.GetStorage(StorageID); using (var pc = new PacsComm()) { //画像取得 DicomFilesResult ret = pc.CMoveImage(StudyUID, SeriesUID, SopUID); if (!ret.IsSuccess) { LogUtil.Error("CMoveImage"); return; } if (ret.Files.Length == 0) { LogUtil.Error("CMoveImage [File=0]"); return; } LogUtil.Debug1("CMoveImage [File={0}]", ret.Files.Length.ToString()); var seriesList = new Dictionary <string, List <Dictionary <string, string> > >(); int cnt = 0; foreach (DicomFile dcmfile in ret.Files) { var file = dcmfile.FileName.Trim(); if (!File.Exists(file)) { continue; } var tags = new Dictionary <string, string>(); tags.Add("StorageID", sto.StorageID); tags.Add("UserName", UserName); tags.Add("AETitle", ""); tags.Add("File", file); var fi = new FileInfo(file); tags.Add("FileSize", fi.Length.ToString()); //タグ取得 using (var dcm = new DicomData(file)) { var tmpTags = new List <uint>(DcmTag.ToTagArray(AppUtil.IMAGE_TAG)); var dic = DicomTagDictionary.Open(dcm, tmpTags.ToArray()); foreach (DcmTag dcmTag in AppUtil.IMAGE_TAG) { tags.Add(dcmTag.Name, dic.GetString(dcmTag.Tag)); } if (dcm.Images.Load()) { if (dcm.Images.Bits == 8 || dcm.Images.Bits == 24) { tags.SetString("WindowCenter", "127"); tags.SetString("WindowWidth", "255"); } else { ImageControl ctrl = null; if (dcm.Images.WindowCenters.Length > 0) { tags.SetString("WindowCenter", dcm.Images.WindowCenters[0].ToString()); } else { if (ctrl == null) { ctrl = dcm.Images.CreateImageControl(0); } //MinMax if (ctrl != null) { tags.SetString("WindowCenter", ctrl.WindowCenter.ToString()); } } if (dcm.Images.WindowWidths.Length > 0) { tags.SetString("WindowWidth", dcm.Images.WindowWidths[0].ToString()); } else { if (ctrl == null) { ctrl = dcm.Images.CreateImageControl(0); } //MinMax if (ctrl != null) { tags.SetString("WindowWidth", ctrl.WindowWidth.ToString()); } } } } } var studyUid = tags[DcmTag.StudyInstanceUID.Name]; var seriesUid = tags[DcmTag.SeriesInstanceUID.Name]; var sopUid = tags[DcmTag.SOPInstanceUID.Name]; var mod = tags[DcmTag.Modality.Name]; //DICOMチェック if (studyUid == "" || seriesUid == "" || sopUid == "" || mod == "") { LogUtil.Error1("NOT DICOM [{0}]", Path.GetFileName(file)); continue; } //無視するモダリティ if (Array.IndexOf(AppUtil.SkipModality, mod) >= 0) { LogUtil.Debug2("SKIP:{0} [{1}]", mod, Path.GetFileName(file)); continue; } if (!seriesList.ContainsKey(seriesUid)) { seriesList.Add(seriesUid, new List <Dictionary <string, string> >()); } seriesList[seriesUid].Add(tags); cnt++; } //SERIES毎のSOPソート foreach (var series in seriesList.Values) { series.Sort((x, y) => { long n1, n2; if (!long.TryParse(x[DcmTag.SeriesNumber.Name], out n1)) { n1 = long.MaxValue; } if (!long.TryParse(y[DcmTag.SeriesNumber.Name], out n2)) { n2 = long.MaxValue; } return((int)(n1 - n2)); }); } int idx = 0; foreach (var series in seriesList.Values) { if (series.Count == 0) { continue; } LogUtil.Info5("AETitle[{0}] StudyDate[{1}] StudyTime[{2}] Modality[{3}] PatientID[{4}]", series[0]["AETitle"], series[0][DcmTag.StudyDate.Name], series[0][DcmTag.StudyTime.Name], series[0][DcmTag.Modality.Name], series[0][DcmTag.PatientID.Name]); var importList = new List <Dictionary <string, string> >(); foreach (var sop in series) { var studyUid = sop[DcmTag.StudyInstanceUID.Name]; var seriesUid = sop[DcmTag.SeriesInstanceUID.Name]; var sopUid = sop[DcmTag.SOPInstanceUID.Name]; var file = sop["File"]; idx++; LogUtil.Debug3("{0}/{1} [{2}]", idx, cnt, Path.GetFileName(file)); //画像圧縮 using (var imp = new Impersonate(sto.LogonUsername, sto.LogonPassword)) { var dicomFile = Path.Combine(sto.DicomPath, studyUid, seriesUid, sopUid + AppUtil.DicomExt); if (DicomUtil.DicomToComp(file, dicomFile, sop)) { sop.Add("DicomFile", dicomFile); LogUtil.Debug("圧縮 end"); var fi = new FileInfo(dicomFile); sop.Add("CompFileSize", fi.Length.ToString()); } else { LogUtil.Error1("圧縮エラー [{0}]", file); return; } } importList.Add(sop); } //DB登録 if (importList.Count > 0) { if (DbUtil.DicomToDB(importList)) { LogUtil.Debug("DB登録 end"); } else { LogUtil.Error("DB登録エラー"); } } else { LogUtil.Debug("DB登録 なし"); } } //DB更新 DbUtil.UpdateStudy(StudyUID); } }
public static ImageCache GetData(string file, int frameNumber) { ImageCache cache = null; if (AppUtil.ImageCacheMax > 0) { var key = string.Format("{0}:{1}", file, frameNumber); if (dict.ContainsKey(key)) { dict[key].accessDate = new TimeSpan(DateTime.Now.Ticks); cache = dict[key]; } else { lock (dict) { if (dict.ContainsKey(key)) { dict[key].accessDate = new TimeSpan(DateTime.Now.Ticks); cache = dict[key]; } else { cache = new ImageCache(); dict.Add(key, cache); } } } if (cache.IsLoad) { return(cache); } } else { cache = new ImageCache(); } lock (syncImage) { if (cache.IsLoad) { return(cache); } using (var dcm = new DicomData(file)) { if (!dcm.Images.Load()) { return(null); } var ctrl = dcm.Images.CreateImageControl(frameNumber); var data = DicomSplitData.Open(dcm); var lvl = data.CreateTopLevel(0, ctrl); cache.Load(lvl); } return(cache); } }
public static void GetGsps(GSPSKey key, out Dictionary <string, GSPSDataItem> items) { items = null; var tmpItems = new Dictionary <string, GSPSDataItem>(); var tmpSeries = new Dictionary <string, string>(); var delItems = new List <string>(); //マルチフレーム時の調整 //GSPSのImageKey取得 List <ImageKey> gspsImkeys; DbUtil.GetGsps(key, out gspsImkeys); foreach (var gspsImKey in gspsImkeys) { var file = FileUtil.GetDicomFile(gspsImKey); try { using (var dcm = new DicomData(file, DicomTransferSyntax.LittleEndianImplicit)) { var pr = new PRAnalyzer(dcm); var tmpSop = new List <PRReferenceSOP>(); //ReferencedSeriesSequence foreach (var seq in pr.References) { tmpSop.AddRange(seq.SopRefs); //ReferencedImageSequence foreach (var sop in seq.SopRefs) { if (!tmpSeries.ContainsKey(sop.SOPInstanceUID)) { tmpSeries.Add(sop.SOPInstanceUID, seq.SeriesInstanceUID); } var imkey = new ImageKey() { StudyInstanceUID = key.StudyInstanceUID, SeriesInstanceUID = seq.SeriesInstanceUID, SOPInstanceUID = sop.SOPInstanceUID, FrameNumber = sop.FrameNumber, StorageID = gspsImKey.StorageID }; var imkey2 = ConvertUtil.Serialize(imkey); tmpItems.Add(imkey2, new GSPSDataItem()); tmpItems[imkey2].Flip = pr.Flip.ToString().ToLower(); tmpItems[imkey2].Rotate = pr.Rotate.ToString(); } } //SoftcopyVOILUTSequence foreach (var seq in pr.VoiLuts) { if (seq.SopRefs.Length == 0) { seq.SopRefs = tmpSop.ToArray(); } //ReferencedImageSequence foreach (var sop in seq.SopRefs) { var imkey = new ImageKey() { StudyInstanceUID = key.StudyInstanceUID, SeriesInstanceUID = tmpSeries[sop.SOPInstanceUID], SOPInstanceUID = sop.SOPInstanceUID, FrameNumber = sop.FrameNumber, StorageID = gspsImKey.StorageID }; var imkey2 = ConvertUtil.Serialize(imkey); if (!tmpItems.ContainsKey(imkey2)) { tmpItems.Add(imkey2, new GSPSDataItem()); } tmpItems[imkey2].VoiLut = seq.ToString(); } } //GraphicAnnotationSequence foreach (var seq in pr.Infos) { //ReferencedImageSequence foreach (var sop in seq.Reference.SopRefs) { var imkey = new ImageKey() { StudyInstanceUID = key.StudyInstanceUID, SeriesInstanceUID = tmpSeries[sop.SOPInstanceUID], SOPInstanceUID = sop.SOPInstanceUID, FrameNumber = sop.FrameNumber, StorageID = gspsImKey.StorageID }; var imkey2 = ConvertUtil.Serialize(imkey); if (!tmpItems.ContainsKey(imkey2)) { tmpItems.Add(imkey2, new GSPSDataItem()); } tmpItems[imkey2].Info = seq.ToString(); } } //DisplayedAreaSelectionSequence foreach (var seq in pr.DisplayAreas) { if (seq.SopRefs.Length == 0) { seq.SopRefs = tmpSop.ToArray(); } //ReferencedImageSequence foreach (var sop in seq.SopRefs) { var imkey = new ImageKey() { StudyInstanceUID = key.StudyInstanceUID, SeriesInstanceUID = tmpSeries[sop.SOPInstanceUID], SOPInstanceUID = sop.SOPInstanceUID, FrameNumber = sop.FrameNumber, StorageID = gspsImKey.StorageID }; var imkey2 = ConvertUtil.Serialize(imkey); if (!tmpItems.ContainsKey(imkey2)) { tmpItems.Add(imkey2, new GSPSDataItem()); } tmpItems[imkey2].DisplayArea = seq.ToString(); //マルチフレーム時の調整 if (sop.FrameNumber > 0) { var imkey3 = new ImageKey() { StudyInstanceUID = key.StudyInstanceUID, SeriesInstanceUID = tmpSeries[sop.SOPInstanceUID], SOPInstanceUID = sop.SOPInstanceUID, FrameNumber = 0, StorageID = gspsImKey.StorageID }; var imkey4 = ConvertUtil.Serialize(imkey3); if (tmpItems.ContainsKey(imkey4)) { if (tmpItems[imkey2].Flip == "") { tmpItems[imkey2].Flip = tmpItems[imkey4].Flip; } if (tmpItems[imkey2].Rotate == "") { tmpItems[imkey2].Rotate = tmpItems[imkey4].Rotate; } if (!delItems.Contains(imkey4)) { delItems.Add(imkey4); } } } } } } } catch { LogUtil.Error1("PR Error [{0}]", file); throw; } } //マルチフレーム時の調整 if (delItems.Count > 0) { foreach (var delItem in delItems) { tmpItems.Remove(delItem); } } items = tmpItems; }