Пример #1
0
def coplaner_neighbors(fid, fNormal, tag):
    vertexIds = ModelData.dictFaces[fid].get_vids()
    for i in range(0, 3):
        j = 0
        if i < 2:
            j = i + 1
        face = CarveFunc.get_neighbor_shellface([vertexIds[i], vertexIds[j]], fid)
        if face not in tag and face is not None:
            newVertids = ModelData.dictFaces[face].get_vids()
            Normal = SimpleMath.get_face_normal([ModelData.dictVertices[newVertids[0]], ModelData.dictVertices[newVertids[1]], ModelData.dictVertices[newVertids[2]]])
            if SimpleMath.vector_length_3(Normal) > SimpleMath.Tol and SimpleMath.dot_product_3(fNormal, Normal) > SimpleMath.NeighborAngle:
                tag.append(face)
                #only select the adjacent neighbors
                #coplaner_neighbors(face, Normal, tag)
Пример #2
0
def do_the_work(inputFilePath, isSemantic, debugControl):

    #Init mid files
    if os.path.exists(MIDFILEPATH):
        os.remove(MIDFILEPATH)

    #Init datastructure
    ModelDataFuncs.Init()
    ModelData.strInputFileName, ext = os.path.splitext(inputFilePath)

    #read file
    print ("----Processing file----")
    print (inputFilePath)
    if isSemantic == True:
        if os.path.splitext(inputFilePath)[1] == '.obj':
            print('WARNING: obj format does not contain semantics')
            print('Semantics will be deduced')
            print ("Check and tessellate the file...")
            MyCov = ConvProvider()
            MyCov.convert(inputFilePath, MIDFILEPATH, True)
            #read a tesselated objfile
            if ModelDataFuncs.reader_obj(MIDFILEPATH) == False:
                raise Exception
        else:
            #poly with semantics
            try:
                if not ModelDataFuncs.reader_poly_with_semantics(inputFilePath):
                    return
            except:
                raise ImportError
    else:
        #preprocess (convert and tessellation)
        print ("Check and tessellate the file...")
        MyCov = ConvProvider()
        MyCov.convert(inputFilePath, MIDFILEPATH, True)
        #read a tesselated objfile
        if ModelDataFuncs.reader_obj(MIDFILEPATH) == False:
            raise Exception

    #invert the normal of the input model
    if ModelData.global_INVERT_NORMAL:
        ModelDataFuncs.invert_poly_normal()
    #only for debug
    #tmp = ModelData.centerVertex
    #ModelData.centerVertex = (0.0, 0.0, 0.0)
    #ModelDataFuncs.writer_obj(ModelData.strInputFileName+"_CLS.obj")
    #ModelData.centerVertex = tmp
    #
    if int(debugControl) == 1:
        #Decomposit all the triangles
        DecomposeFunc.model_decompositionEx()

        #Merge all the coplaner dictFaces
        #coplaner_face_merge()
        #ModelDataFuncs.writer_obj(ModelData.strInputFileName+"_DEC.obj")

    elif int(debugControl) == 2:
        #Constrained Tetrahedralization
        if False == TetraFunc.CDT():
            print("Constrained Delauney Tetrahedralization FAILED!")
            return

        #ModelDataFuncs.writer_obj(ModelData.strInputFileName+"_CDT.obj")

        #Heuristic carving
        CarveFunc.heuristic_tet_carving()
        #ModelDataFuncs.writer_obj(ModelData.strInputFileName+"_CARVE.obj")

        #Reconstruct the mesh from tetrahedron
        TetraFunc.extract_mesh_from_tet(isSemantic)
        #Output
        ModelDataFuncs.writer_obj(ModelData.strInputFileName+"_OUTPUT.obj")
        if isSemantic:
            ModelDataFuncs.writer_poly_with_semantics(ModelData.strInputFileName + "_OUTPUT.poly")
    elif int(debugControl) == 3:
        #only deduce the semantics
        TetraFunc.deduce_semantics_of_poly(isSemantic)
        ModelDataFuncs.writer_poly_with_semantics(ModelData.strInputFileName + "_OUTPUT.poly")

    else:
        #Decomposit all the triangles
        DecomposeFunc.model_decompositionEx()

        #Merge all the coplaner dictFaces
        #coplaner_face_merge()
        ModelDataFuncs.writer_obj(ModelData.strInputFileName +"_DEC.obj")

        #Constrained Tetrahedralization
        if False == TetraFunc.CDT():
            print("Constrained Delauney Tetrahedralization FAILED!")
            return
        ModelDataFuncs.writer_obj(ModelData.strInputFileName+"_CDT.obj")

        #Heuristic carving
        CarveFunc.heuristic_tet_carving()
        ModelDataFuncs.writer_obj(ModelData.strInputFileName+"_CARVE.obj")

        #Reconstruct the mesh from tetrahedron
        TetraFunc.extract_mesh_from_tet(isSemantic)
        #Output
        ModelDataFuncs.writer_obj(ModelData.strInputFileName + "_OUTPUT.obj")
        if isSemantic:
            ModelDataFuncs.writer_poly_with_semantics(ModelData.strInputFileName + "_OUTPUT.poly")