def sort_facesgroup_by_size(listFaceGroup): listSize = [] for list in listFaceGroup: bbox = ModelDataFuncs.get_bbox_faces(list) listSize.append(SimpleMath.square_dist_point_to_point(bbox[0], bbox[1]), list) listSize.sort() # listFaceGroup = [] for list in listSize: listFaceGroup.append(list[1]) return listFaceGroup
def update_stack(): #init sortedTetIDStack = [] #building a list with all the dictTetrahedrons attached with TMP dictFaces and their volume tmpTetIDs = {} for fkey in ModelData.listShellFaceIDs: #all the facets of a fixed tet are already fix if ModelData.dictFaces[fkey].get_tag() == ClassFace.TMP: #if (375 in ModelData.dictFaces[fkey].get_vids() or 382 in ModelData.dictFaces[fkey].get_vids()) and 371 in ModelData.dictFaces[fkey].get_vids() and 685 in ModelData.dictFaces[fkey].get_vids(): # aaa = 9 tetList = TetraFunc.find_tetids_by_faceid(fkey, 1) tetid = tetList[0] tetShellFaceidList = TetraFunc.get_shell_faceids_from_tetid(tetid) tetFaceidList = TetraFunc.get_faceids_from_tetid(tetid)#all the known face of this tet #degree of freedom DoF = 4 - len(tetFaceidList) #Carving differential CDif = 0 for f in tetFaceidList: if ModelData.dictFaces[f].get_tag() == ClassFace.TMP: CDif = CDif + 1 CDif = CDif - DoF #different configurations of heuristics #no heuristics (speedup) if not globalHeuristic['validity']: sortedTetIDStack.append((tetid,tetShellFaceidList, tetFaceidList)) return sortedTetIDStack #with heuristics (normal) if not tmpTetIDs.has_key(tetid): if globalHeuristic['volume']: tmpTetIDs[tetid] = (tetShellFaceidList, tetFaceidList, ModelData.dictTetrahedrons[tetid].get_tag(), DoF, CDif, ModelData.dictTetrahedrons[tetid].get_volume()) #volume elif globalHeuristic['flatness']: tmpTetIDs[tetid] = (tetShellFaceidList, tetFaceidList, ModelData.dictTetrahedrons[tetid].get_tag(), DoF, CDif, ModelData.dictTetrahedrons[tetid].get_depth(ModelData.dictFaces[fkey].get_vids())/ModelData.dictFaces[fkey].get_area())#flatness elif globalHeuristic['depth']: tmpTetIDs[tetid] = (tetShellFaceidList, tetFaceidList, ModelData.dictTetrahedrons[tetid].get_tag(), DoF, CDif, ModelData.dictTetrahedrons[tetid].get_depth(ModelData.dictFaces[fkey].get_vids()))#depth elif globalHeuristic['distanceToCenter']: #face center to the model center vids = ModelData.dictFaces[fkey].get_vids() midPt = SimpleMath.tuple_plus(ModelData.dictVertices[vids[0]], ModelData.dictVertices[vids[1]]) midPt = SimpleMath.tuple_plus(ModelData.dictVertices[vids[2]], midPt) midPt = SimpleMath.tuple_numproduct(1.0/3.0, midPt) tmpTetIDs[tetid] = (tetShellFaceidList, tetFaceidList, ModelData.dictTetrahedrons[tetid].get_tag(), DoF, CDif, 1.0/SimpleMath.square_dist_point_to_point(midPt, [0.0, 0.0, 0.0]))#reciprocal distanceToCenter #tmpTetIDs[tetid] = (tetShellFaceidList, tetFaceidList, ModelData.dictTetrahedrons[tetid].get_tag(), DoF, CDif, ModelData.dictFaces[fkey].get_area())#face area else: tmpTetIDs[tetid] = (tetShellFaceidList, tetFaceidList, ModelData.dictTetrahedrons[tetid].get_tag(), DoF, CDif)#simplest else: #update the exisiting information if globalHeuristic['volume']: volume = ModelData.dictTetrahedrons[tetid].get_volume() if DoF < tmpTetIDs[tetid][3] or CDif > tmpTetIDs[tetid][4] or volume > tmpTetIDs[tetid][5]: tmpTetIDs[tetid] = (tetShellFaceidList, tetFaceidList, ModelData.dictTetrahedrons[tetid].get_tag(), DoF, CDif, 1.0/volume) #reciprocal volume elif globalHeuristic['flatness']: flatness = ModelData.dictTetrahedrons[tetid].get_depth(ModelData.dictFaces[fkey].get_vids())/ModelData.dictFaces[fkey].get_area() if DoF < tmpTetIDs[tetid][3] or CDif > tmpTetIDs[tetid][4] or flatness < tmpTetIDs[tetid][5]: tmpTetIDs[tetid] = (tetShellFaceidList, tetFaceidList, ModelData.dictTetrahedrons[tetid].get_tag(), DoF, CDif, flatness)#flatness elif globalHeuristic['depth']: depth = ModelData.dictTetrahedrons[tetid].get_depth(ModelData.dictFaces[fkey].get_vids()) if DoF < tmpTetIDs[tetid][3] or CDif > tmpTetIDs[tetid][4] or depth < tmpTetIDs[tetid][5]: tmpTetIDs[tetid] = (tetShellFaceidList, tetFaceidList, ModelData.dictTetrahedrons[tetid].get_tag(), DoF, CDif, depth)#depth elif globalHeuristic['distanceToCenter']: #face center to the model center vids = ModelData.dictFaces[fkey].get_vids() midPt = SimpleMath.tuple_plus(ModelData.dictVertices[vids[0]], ModelData.dictVertices[vids[1]]) midPt = SimpleMath.tuple_plus(ModelData.dictVertices[vids[2]], midPt) midPt = SimpleMath.tuple_numproduct(1.0/3.0, midPt) dist = 1.0/SimpleMath.square_dist_point_to_point(midPt, [0.0, 0.0, 0.0]) if DoF < tmpTetIDs[tetid][3] or CDif > tmpTetIDs[tetid][4] or dist > tmpTetIDs[tetid][5]: tmpTetIDs[tetid] = (tetShellFaceidList, tetFaceidList, ModelData.dictTetrahedrons[tetid].get_tag(), DoF, CDif, dist)#reciprocal distanceToCenter #sort the dict by the value (volume) and number of neigbour dictFaces into a desascending order if not globalHeuristic['volume'] and not globalHeuristic['flatness'] and not globalHeuristic['depth'] and not globalHeuristic['distanceToCenter']: for key in tmpTetIDs: sortedTetIDStack.append((key, tmpTetIDs[key][0], tmpTetIDs[key][1], tmpTetIDs[key][2], tmpTetIDs[key][3], tmpTetIDs[key][4])) else: for key in tmpTetIDs: sortedTetIDStack.append((key, tmpTetIDs[key][0], tmpTetIDs[key][1], tmpTetIDs[key][2], tmpTetIDs[key][3], tmpTetIDs[key][4], tmpTetIDs[key][5])) #sort firstly by fix/tmp, secondly by DoF, thirdly by Cd, lastly by volume sortedTetIDStack = sorted(sortedTetIDStack, key=lambda tet: tet[6], reverse = False)#smaller ratio first #sortedTetIDStack = sorted(sortedTetIDStack, key=lambda tet: tet[5], reverse = True)#large CDif first sortedTetIDStack = sorted(sortedTetIDStack, key=lambda tet: tet[4], reverse = False)#smaller DoF first sortedTetIDStack = sorted(sortedTetIDStack, key=lambda tet: tet[5], reverse = True)#large CDif first sortedTetIDStack = sorted(sortedTetIDStack, key=lambda tet: tet[3], reverse = True)#TMP tetrahedron first, then INF str_out = ("number of candidate tetrahedron: {}").format(len(sortedTetIDStack)) os.sys.stdout.write(str_out + "\r") os.sys.stdout.flush() return sortedTetIDStack