/// <summary> /// 解析三维网格数据 /// </summary> /// <param name="reader"></param> /// <returns></returns> private bool ReadGridFile_3D(StreamReader reader, IGridOnwer gridOnwer) { #region //// //读取节点信息 //// /* # X Y Z //// points //// 378 //// 1.0000000000000000 -3.4201999999999999 9.3969299999999993 ////*/ #endregion bool result = true; try { #region 读取节点 string strCurrent = ""; reader.BaseStream.Seek(0, SeekOrigin.Begin); while ((strCurrent = reader.ReadLine()) != null) { if (strCurrent.Trim().ToLower() == "points") // 节点信息 { //如果这一行是关键字,则把当前关键字和其对应的信息交给ParseKeyword处理 int numPoints = int.Parse(reader.ReadLine().Trim()); // 读取点的个数 // nodeReflection = new Dictionary<string, string>(); for (int i = 1; i <= numPoints; i++) { string strTemp = reader.ReadLine(); List <string> strList = SplitStringBySpace(strTemp);//分割字符 bool readSuccess = false; float x = float.Parse(strList[0]); float y = float.Parse(strList[1]); float z = float.Parse(strList[2]); int nodeid = m_numTotalPoints; Node node = new Node(x, y, z, nodeid); readSuccess = gridOnwer.AddNode(node); if (readSuccess) { m_numTotalPoints += 1; // 成功读入一个节点 } else { Debug.WriteLine("Error when parse points"); continue; //读入下一个节点 } } } } #endregion #region 读取单元 //// /*# matnr np p1 p2 p3 p4 //// volumeelements //// 1080 //// 1 4 53 230 137 314 //// 1 4 61 324 198 217*/ reader.BaseStream.Seek(0, SeekOrigin.Begin); while ((strCurrent = reader.ReadLine()) != null) { //k文件用*标识,hypermesh用<<标识 if (strCurrent.Trim().ToLower() == "volumeelements") //如果是单元信息 { int numEle = int.Parse(reader.ReadLine().Trim()); //获取单元的个数 //int flag = 0; for (int i = 1; i <= numEle; i++) { string strTemp = reader.ReadLine(); List <string> strList = SplitStringBySpace(strTemp);//分割字符 bool readSuccess = false; int n1 = int.Parse(strList[2]); int n2 = int.Parse(strList[3]); int n3 = int.Parse(strList[4]); int n4 = int.Parse(strList[5]); int id = m_numTotalEles; TetraElement ele = new TetraElement(n1, n2, n3, n4, id); readSuccess = gridOnwer.AddElement(ele); if (readSuccess) { m_numTotalEles += 1;// 成功读入一个节点 } else { Debug.WriteLine("Error when parse volumeelements"); continue;//读入下一个节点 } } } } gridOnwer.AfterAdd(false); //根据传入的节点和单元信息构造actor #endregion } catch (Exception e) { gridOnwer.AfterAdd(false); Logger.WriteLogMessage("Mesher:ReadGridFile_3D:" + e.Message); result = false; } return(result); }