已知两个蓝色面,使用遍历面的方法求紫色面。算法例子:
1 bool is_NeighborFace(tag_t tagFace1, tag_t tagFace2) 2 { 3 vector<tag_t> vecEdges1; 4 uf_list_p_t list1 = NULL;//定义链表 5 UF_MODL_create_list(&list1); //创建链表 6 UF_MODL_ask_face_edges(tagFace1, &list1); 7 int count1 = 0; 8 UF_MODL_ask_list_count(list1, &count1);//链表计数 9 for (int i = 0; i < count1; i++) 10 { 11 tag_t tagEdge = NULL_TAG; 12 UF_MODL_ask_list_item(list1, i, &tagEdge); //接收链表数据 13 vecEdges1.push_back(tagEdge); 14 } 15 UF_free(list1); //释放链表指针 16 list1 = NULL; 17 18 vector<tag_t> vecEdges2; 19 uf_list_p_t list2 = NULL;//定义链表 20 UF_MODL_create_list(&list2); //创建链表 21 UF_MODL_ask_face_edges(tagFace2, &list2); 22 int count2 = 0; 23 UF_MODL_ask_list_count(list2, &count2);//链表计数 24 for (int i = 0; i < count2; i++) 25 { 26 tag_t tagEdge = NULL_TAG; 27 UF_MODL_ask_list_item(list2, i, &tagEdge); //接收链表数据 28 vecEdges2.push_back(tagEdge); 29 } 30 UF_free(list2); //释放链表指针 31 list2 = NULL; 32 33 for (int i = 0; i < vecEdges1.size(); i++) 34 { 35 for (int j = 0; j < vecEdges2.size(); j++) 36 { 37 if (vecEdges1[i] == vecEdges2[j]) 38 { 39 return true; 40 } 41 } 42 } 43 return false; 44 }
1 int get_NeighborFaces(tag_t tagFace, vector<tag_t> *vecFaces) 2 { 3 vector<tag_t> vecAllFaces; 4 vector<tag_t> vecEdges; 5 //获取面的边【自定义函数】 6 get_face_edges(tagFace, 0, &vecEdges); 7 for (int i = 0; i < vecEdges.size(); i++) 8 { 9 vector<tag_t> vecTempFaces; 10 //获取边的面【自定义函数】 11 get_edge_faces(vecEdges[i], &vecTempFaces); 12 for (int j = 0; j < vecTempFaces.size(); j++) 13 { 14 15 vecAllFaces.push_back(vecTempFaces[j]); 16 } 17 } 18 //排序去重【自定义函数】 19 Setting_Order(vecAllFaces, vecFaces, 3); 20 21 for (vector<tag_t>::iterator itor = (*vecFaces).begin(); itor != (*vecFaces).end(); /*++itor*/) 22 { 23 if (*itor == tagFace) 24 { 25 itor = (*vecFaces).erase(itor); 26 } 27 else 28 { 29 ++itor; 30 } 31 } 32 return 0; 33 }
1 int get_faces_Between_two_faces(tag_t tagFace1, tag_t tagFace2, vector<tag_t> *vecFaces) 2 { 3 //如果输入的两个面相邻则return 4 if (is_NeighborFace(tagFace1, tagFace2)) return 0; 5 6 vector<tag_t> vecT1; 7 vecT1.push_back(tagFace1); 8 int m = 0; 9 bool isNOK = true; 10 while (isNOK) 11 { 12 vector<tag_t> vecTemp; 13 vecTemp.clear(); 14 15 //输入一个面输出与他相邻的面 【自定义函数】 16 get_NeighborFaces(vecT1[m], &vecTemp); 17 18 vector<tag_t> vecT1_temp; 19 vecT1_temp.clear(); 20 for (int i = 0; i < vecTemp.size(); i++) 21 { 22 vecT1_temp.push_back(vecTemp[i]); 23 } 24 //排序去重 【自定义函数】 25 Setting_Order(vecT1_temp, &vecT1, 3); 26 27 for (int i = 0; i < vecT1.size(); i++) 28 { 29 if (vecT1[i] == tagFace2) isNOK = false; 30 } 31 32 m++; 33 } 34 35 vector<tag_t> vecT2; 36 vecT2.push_back(tagFace2); 37 m = 0; 38 isNOK = true; 39 while (isNOK) 40 { 41 vector<tag_t> vecTemp; 42 vecTemp.clear(); 43 //输入一个面输出与他相邻的面 【自定义函数】 44 get_NeighborFaces(vecT2[m], &vecTemp); 45 46 vector<tag_t> vecT2_temp; 47 vecT2_temp.clear(); 48 for (int i = 0; i < vecTemp.size(); i++) 49 { 50 vecT2_temp.push_back(vecTemp[i]); 51 } 52 //排序去重 【自定义函数】 53 Setting_Order(vecT2_temp, &vecT2, 3); 54 55 for (int i = 0; i < vecT2.size(); i++) 56 { 57 if (vecT2[i] == tagFace1) isNOK = false; 58 } 59 60 m++; 61 } 62 63 for (int i = 0; i < vecT1.size(); i++) 64 { 65 for (int j = 0; j < vecT2.size(); j++) 66 { 67 if (vecT1[i] == vecT2[j]) 68 { 69 (*vecFaces).push_back(vecT1[i]); 70 } 71 } 72 } 73 74 for (vector<tag_t>::iterator itor = (*vecFaces).begin(); itor != (*vecFaces).end(); /*++itor*/) 75 { 76 if ((*itor == tagFace1) || (*itor == tagFace2)) 77 { 78 itor = (*vecFaces).erase(itor); 79 } 80 else 81 { 82 ++itor; 83 } 84 } 85 86 return 0; 87 }