Пример #1
0
def extract_mesh_from_tet(bIsSemantics = False):
    print("----Extract the output mesh----")
    #check
    if len(ModelData.dictTetrahedrons) == 0:
        print("invalid call extract Mesh")
        return

    #deletion and deduce semantics
    for fkey in ModelData.dictFaces:
        if fkey not in ModelData.listShellFaceIDs:
            ModelDataFuncs.pre_remove_face_by_faceids([fkey])

    #clearup
    if ModelDataFuncs.remove_faces() > 0:
        print ("Mesh extracted")
    
    #optimisazation
    if ModelDataFuncs.optimise_illshaped_shellfaces():
        ModelDataFuncs.remove_faces()
    ModelDataFuncs.clean_duplicated_vertices()
    ModelDataFuncs.clean_unreferenced_vertices()
    ModelDataFuncs.restore_normals()

    #deduce semantics
    deduce_semantics_of_poly(bIsSemantics)
Пример #2
0
def carve_tetrahedron(curTetId, faceIDsInCurTet):
    #remove the known TMP face of this tetrahedron and locally keep the adjacent FIX tetrahedron
    for i in faceIDsInCurTet:
        if ModelData.dictFaces[i].get_tag() == ClassFace.TMP:
            #on the shell
            ModelDataFuncs.pre_remove_face_by_faceids([i])
            #update the list of shell faces (TMP face must be on the shell)
            ModelData.listShellFaceIDs.remove(i)
        else:
            #deal with adjacent fixed tetrahedron
            if i not in ModelData.listShellFaceIDs:
                ModelData.listShellFaceIDs.append(i)
                tetList = TetraFunc.find_tetids_by_faceid(i)
                for tetId in tetList:
                    if tetId != curTetId:
                        #keep the tet with fixed or keep shell face
                        keep_tetrahedron(tetId, TetraFunc.get_faceids_from_tetid(tetId))
            else:
                print 'weird!!'
    if len(faceIDsInCurTet) < 4:
        #add the undefined dictFaces as TMP dictFaces
        vertexList = ModelData.dictTetrahedrons[curTetId].get_vids()
        faceList = []
        faceList.append((vertexList[0], vertexList[1], vertexList[2]))
        faceList.append((vertexList[0], vertexList[2], vertexList[3]))
        faceList.append((vertexList[0], vertexList[3], vertexList[1]))
        faceList.append((vertexList[1], vertexList[2], vertexList[3]))
        for f in faceList:
            isDefined = False
            for i in faceIDsInCurTet:
                if ModelData.dictFaces[i].is_equal_geometry(ClassFace.Class_face(f)):
                    isDefined = True
                    break
            if not isDefined :
                #add the tmp face and update the list of shell faces
                ModelData.listShellFaceIDs.append(ModelDataFuncs.add_face(ClassFace.Class_face(f)))
    #remove the tetrahedron
    ModelData.dictTetrahedrons.pop(curTetId)
Пример #3
0
def CDT():
    print("Start tetrahedralization....")
    curDirBefore = os.getcwd() 
    path = os.path.dirname(os.path.realpath(__file__))
    if sizeof(c_voidp) == 4:
        #win32
        path = os.path.join(path, '..\\tetgendll\\Release')
        os.chdir(path)
        if not os.path.exists("tetgendll.dll"):
            print("DLL missing: " + path + "tetgendll.dll")
        Tetrahedralator = CDLL("tetgendll.dll")
    elif sizeof(c_voidp) == 8:
        #x64
        path = os.path.join(path, '..\\tetgendll\\x64\\Release')
        os.chdir(path)
        if not os.path.exists("tetgendll.dll"):
            print("DLL missing: " + path + "tetgendll.dll")
        Tetrahedralator = CDLL("tetgendll.dll")
    os.chdir(curDirBefore)
    #be careful with the indices
    #record the indices of inserted dictVertices and map the indices in the dictFaces and tetrahedron to the finally added indices
    mapVertTet = {}
    iCount = 0
    cVertices = (c_double * (len(ModelData.dictVertices) * 3))() #the size of dictVertices *3
    for key in ModelData.dictVertices:
        cVertices[3*iCount] = c_double(ModelData.dictVertices[key][0])
        cVertices[3*iCount+1] = c_double(ModelData.dictVertices[key][1])
        cVertices[3*iCount+2] = c_double(ModelData.dictVertices[key][2])
        mapVertTet[iCount] = key
        iCount += 1

    iCount = 0
    cFaces = (c_int * (len(ModelData.dictFaces) * 3))() #the size of dictFaces * 3
    for key in ModelData.dictFaces:
        #be careful with the indices
        cFaces[3*iCount] = c_int(ModelDataFuncs.find_key_from_dict_by_exact_value(mapVertTet, ModelData.dictFaces[key].get_vids()[0]))
        cFaces[3*iCount+1] = c_int(ModelDataFuncs.find_key_from_dict_by_exact_value(mapVertTet, ModelData.dictFaces[key].get_vids()[1]))
        cFaces[3*iCount+2] = c_int(ModelDataFuncs.find_key_from_dict_by_exact_value(mapVertTet, ModelData.dictFaces[key].get_vids()[2]))
        iCount += 1

    numberOfOutputVerts = c_int(0);
    numberOfOutputTriangles = c_int(0);
    numberOfOutputTetrahedrons = c_int(0);

    try:
        Tetrahedralator.simpleTetrahedralize(byref(cVertices), c_int(len(ModelData.dictVertices)), byref(cFaces), c_int(len(ModelData.dictFaces)),
                                         byref(numberOfOutputVerts), byref(numberOfOutputTriangles), byref(numberOfOutputTetrahedrons))
    except ValueError:
        print("CDT failed")
        return False

    #check
    if numberOfOutputTetrahedrons.value == 0:
        print("tetrahedralization failed")
        return False
    #Get the results
    outputVerts = (c_double * (numberOfOutputVerts.value *3))()
    outputConvexhullTris = (c_int * (numberOfOutputTriangles.value *3))()
    outputTetrahedrons = (c_int * (numberOfOutputTetrahedrons.value *4))()

    Tetrahedralator.getResults(pointer(outputVerts), pointer(outputConvexhullTris), pointer(outputTetrahedrons))
   
    #update the ModelData
    #dictVertices
    if numberOfOutputVerts.value > len(ModelData.dictVertices):
        print("{} steiner points inserted (at the back of the original list)").format(numberOfOutputVerts.value - len(ModelData.dictVertices))
        for i in range(len(ModelData.dictVertices) * 3, numberOfOutputVerts.value * 3, 3):
            #be carefull with the indices (start with 0)
            mapVertTet[len(mapVertTet)] = ModelDataFuncs.add_vertex((outputVerts[i], outputVerts[i+1], outputVerts[i+2]))

    #dictTetrahedrons
    for i in range(0, numberOfOutputTetrahedrons.value * 4, 4):
        ModelData.dictTetrahedrons[i/4] = Class_tetrahedron((mapVertTet[outputTetrahedrons[i]], mapVertTet[outputTetrahedrons[i+1]], mapVertTet[outputTetrahedrons[i+2]], mapVertTet[outputTetrahedrons[i+3]]))

    #record the the triangles on the shell
    isFaceDeleted = False
    for i in range(0, numberOfOutputTriangles.value*3, 3):
        tris = (mapVertTet[outputConvexhullTris[i]], mapVertTet[outputConvexhullTris[i+1]], mapVertTet[outputConvexhullTris[i+2]])
        isExt = False
        for f in ModelData.dictFaces:
            if ModelData.dictFaces[f].is_equal_geometry(ClassFace.Class_face(tris)):
                #found the existing face
                isExt = True
                #add to the list of shell face
                ModelData.listShellFaceIDs.append(f)
                break
        if isExt == False:
            #distance mapping in case this geometry is produced by flipping the coplanar triangle
            fId = ModelDataFuncs.find_face_by_mapping(tris)
            if fId:
                ModelData.listShellFaceIDs.append(ModelDataFuncs.add_face(ClassFace.Class_face(tris, ClassFace.FIX, ModelData.dictFaces[fId].get_id(), ModelData.dictFaces[fId].get_type())))
                ModelDataFuncs.pre_remove_face_by_faceids([fId])
                isFaceDeleted = True
            else:
                #add the new face and add the face to the list of shell face
                ModelData.listShellFaceIDs.append(ModelDataFuncs.add_face(ClassFace.Class_face(tris)))
    #remove faces 
    if isFaceDeleted:
        ModelDataFuncs.remove_faces()
    #
    print ("After CDT: " + str(len(ModelData.dictTetrahedrons)) + " tetrahedra and " + str(len(ModelData.dictFaces)) + " dictFaces and " + str(len(ModelData.dictVertices)) + " dictVertices")
    return True