/// <summary> /// 將檔案從V1版本轉成V2版本 /// </summary> /// <param name="saveobj"></param> /// <returns></returns> public static SaveResultV2 Convert(SaveResultV1 saveobj, DcmInfo info) { SaveResultV2 Result = new SaveResultV2(saveobj.FileName); Result.SaveTime = DateTime.Now; Result.KeyPoints = new List <Nullable <Point> >(); #region 處理塑膠管 Result.KeyPoints.AddRange(SaveResultV1.PointConvert(info.Width, info.Height, saveobj.tube)); //foreach (Point p in saveobj.tube) //{ // Result.KeyPoints.Add(p); //} #endregion #region 處理氣管分岔 foreach (List <Point> LP in saveobj.bifurcation) { Result.KeyPoints.AddRange(SaveResultV1.PointConvert(info.Width, info.Height, LP)); //foreach (Point p in LP) //{ // Result.KeyPoints.Add(p); //} } #endregion //巡迴KetPoint後如果點數沒有等於4+3+3+3=13,就代表點數不完整,則遺棄所有的點 if (Result.KeyPoints.Count != 13) { Result.KeyPoints = new List <Nullable <Point> >(); } return(Result); }
/// <summary> /// 把檔案裡面的字串轉成出版存檔類型 /// </summary> /// <param name="str">Json字串</param> /// <returns></returns> public static SaveResultV1 ConvertSaveFile(string str) { SaveResultV1 Result = new SaveResultV1(); if (!String.IsNullOrEmpty(str)) { JObject obj = JObject.Parse(str); Result.SaveTime = obj["info"]["save_time"].ToString(); Result.FileName = obj["info"]["file_name"].ToString(); #region 讀取Tube List <Point> temptube = new List <Point>(); JArray items = (JArray)obj["labels"]["tube"]["lines"][0]; //默認塑膠氣管只會有一組 foreach (var item in items) { //item是一個Tuple var x = Convert.ToDouble(item[0]); var y = Convert.ToDouble(item[1]); x = (int)Math.Round(x); y = (int)Math.Round(y); Point tempPoint = new Point((int)x, (int)y); temptube.Add(tempPoint); } Result.tube = temptube; #endregion #region 讀取Bifurcation List <List <Point> > tempbifurcation = new List <List <Point> >(); foreach (JArray bifurcations in obj["labels"]["bifurcation"]["lines"]) { //巡迴每個氣管分岔的點位 //默認0為左緣,1為下緣,2為右緣 List <Point> temppoint = new List <Point>(); foreach (var item in bifurcations) { var x = Convert.ToDouble(item[0]); var y = Convert.ToDouble(item[1]); x = (int)Math.Round(x); y = (int)Math.Round(y); Point tempPoint = new Point((int)x, (int)y); temppoint.Add(tempPoint); } tempbifurcation.Add(temppoint); } Result.bifurcation = tempbifurcation; #endregion } else { throw new FormatException("輸入的字串為空字串"); } return(Result); }
/// <summary> /// 從檔案讀取記錄檔 /// </summary> /// <param name="Path">檔案路徑</param> /// <returns></returns> public static SaveResultV1 ReadFile(string Path) { if (Func.CheckFileExist(Path)) { string str = Func.ReadText(Path); SaveResultV1 Log = ConvertSaveFile(str); return(Log); } else { throw new IOException("File Not Fount"); } }
public static SaveResultV2 ReadFromString(string JsonStr, DcmInfo info) { SaveResultV2 item; if (SaveResultV2.IsVersion2(JsonStr)) { item = JsonConvert.DeserializeObject <SaveResultV2>(JsonStr); } else { SaveResultV1 item_old = SaveResultV1.ConvertSaveFile(JsonStr); item = SaveResultV2.Convert(item_old, info); } return(item); }