Example #1
0
def check_file(fileName):
    model_reader = ls.CformatBIN()

    model = ls.ioModel()
    if model_reader.ImportBIN(model, fileName):
        # Import success
        # read content
        assert (len(model.faces) == len(expected_faces))
        faces = [[f.a, f.b, f.c, f.idEn, f.idMat, f.idRs] for f in model.faces]
        for refFace in expected_faces:
            if not refFace in faces:
                print("Got face ref {0} not found in model" % (refFace))
        for modelFace in faces:
            if not modelFace in expected_faces:
                print("Got face {0} not found in ref model" % (modelFace))
        assert (len(model.vertices) == 42)
        vertices = [(v[0], v[1], v[2]) for v in model.vertices]
        # compute min max for x,y,z
        maxV = list(map(max, zip(*vertices)))
        minV = list(map(min, zip(*vertices)))
        assert (abs(maxV[0] - 20) < 1e-5)
        assert (abs(maxV[1] - 30) < 1e-5)
        assert (abs(maxV[2] - 10) < 1e-5)

        assert (abs(minV[0]) < 1e-5)
        assert (abs(minV[1]) < 1e-5)
        assert (abs(minV[2]) < 1e-5)
        return model
    else:
        print("Test failed with %s" % fileName)
        exit(-1)
Example #2
0
def check_file(fileName):
    model_reader = ls.CformatBIN()

    model = ls.ioModel()
    if model_reader.ImportBIN(model, fileName):
        # Import success
        # read content
        assert(len(model.faces) == len(expected_faces))
        faces = [[f.a, f.b, f.c, f.idEn, f.idMat, f.idRs] for f in model.faces]
        for refFace in expected_faces:
            if not refFace in faces:
                print("Got face ref {0} not found in model" % (refFace))
        for modelFace in faces:
            if not modelFace in expected_faces:
                print("Got face {0} not found in ref model" % (modelFace))
        assert(len(model.vertices) == 42)
        vertices = [(v[0], v[1], v[2]) for v in model.vertices]
        # compute min max for x,y,z
        maxV = map(max, zip(*vertices))
        minV = map(min, zip(*vertices))
        assert(abs(maxV[0] - 20) < 1e-5)
        assert(abs(maxV[1] - 30) < 1e-5)
        assert(abs(maxV[2] - 10) < 1e-5)
        
        assert(abs(minV[0]) < 1e-5)
        assert(abs(minV[1]) < 1e-5)
        assert(abs(minV[2]) < 1e-5)
        return model
    else:
        print("Test failed with %s" % fileName)
        exit(-1)
Example #3
0
def BuildModel(filepath):
    model = ls.ioModel()
    #Add vertices
    for vertex in vertices:
        model.vertices.append(ls.t_pos(vertex[0], vertex[1], vertex[2]))
    #Add faces
    for face in faces:
        newface = ls.ioFace()
        newface.a = face[0]
        newface.b = face[1]
        newface.c = face[2]
        newface.idEn = face[3]
        newface.idMat = face[4]
        newface.idRs = face[5]
        model.faces.append(newface)
    #Save 3D model
    ls.CformatBIN().ExportBIN(filepath, model)
Example #4
0
def BuildModel(filepath):
    model=ls.ioModel()
    #Add vertices
    for vertex in vertices:
        model.vertices.append(ls.t_pos(vertex[0],vertex[1],vertex[2]))
    #Add faces
    for face in faces:
        newface=ls.ioFace()
        newface.a=face[0]
        newface.b=face[1]
        newface.c=face[2]
        newface.idEn=face[3]
        newface.idMat=face[4]
        newface.idRs=face[5]
        model.faces.append(newface)
    #Save 3D model
    ls.CformatBIN().ExportBIN(filepath,model)
Example #5
0
def CreerModele(filepath):
    """
        Création du modèle 3D
    """
    model=ls.ioModel()
    #Ajout des sommets
    for sommet in sommets:
        model.vertices.append(ls.t_pos(sommet[0],sommet[1],sommet[2]))
    #Ajout des faces
    for face in faces:
        newface=ls.ioFace()
        newface.a=face[0]
        newface.b=face[1]
        newface.c=face[2]
        newface.idEn=face[3]
        newface.idMat=face[4]
        newface.idRs=face[5]
        model.faces.append(newface)
    #sauvegarde du modèle
    ls.CformatBIN().ExportBIN(filepath,model)
Example #6
0
def CreerModele(filepath):
    """
        Création du modèle 3D
    """
    model = ls.ioModel()
    #Ajout des sommets
    for sommet in sommets:
        model.vertices.append(ls.t_pos(sommet[0], sommet[1], sommet[2]))
    #Ajout des faces
    for face in faces:
        newface = ls.ioFace()
        newface.a = face[0]
        newface.b = face[1]
        newface.c = face[2]
        newface.idEn = face[3]
        newface.idMat = face[4]
        newface.idRs = face[5]
        model.faces.append(newface)
    #sauvegarde du modèle
    ls.CformatBIN().ExportBIN(filepath, model)
Example #7
0
def check_model(filepath):
    model = ls.ioModel()
    assert ls.CformatBIN().ImportBIN(model, filepath), "Cannot import model"
    # Check if vertex in expected vertices
    model_vertices = []
    for vertex in model.vertices:
        model_vertex = [vertex[0], vertex[1], vertex[2]]
        model_vertices.append(model_vertex)
        assert model_vertex in vertices, "wrong vertex"

    # Check if expected vertex in vertices
    for vertex in vertices:
        assert vertex in model_vertices, "missing vertex"

    modelfaces = []
    for face in model.faces:
        new_face = [face.a, face.b, face.c, face.idEn, face.idMat, face.idRs]
        assert new_face in faces, "wrong face"
        modelfaces.append(new_face)
    for face in faces:
        assert face in modelfaces, "missing face"
Example #8
0
def write_input_files(cbinpath, cmbinpath, materials, sources_lst, outfolder):
    """
     Import 3D model
     This model contains the associated material link to the XML file
     XML volume index to octave index
    :param cbinpath:
    :param cmbinpath:
    :param materials:
    :param sources_lst:
    :param outfolder:
    :return: dictionary of loaded data or None if failed
    """
    ret = {}
    idVolumeIndex = {}
    sharedVertices = set()

    modelImport = ls.ioModel()
    if not ls.CformatBIN().ImportBIN(modelImport, cbinpath):
        print("Error can not load %s model !\n" % cbinpath)
        return None

    # Import 3D mesh file builded from tetgen output
    mesh_import = ls.CMBIN().LoadMesh(cmbinpath)
    if not mesh_import:
        print("Error can not load %s mesh model !\n" % cmbinpath)
        return None

    # Write NODES file
    with open(os.path.join(outfolder, "scene_nodes.txt"), "w") as f:
        for node in mesh_import.nodes:
            f.write('{0:>15} {1:>15} {2:>15}'.format(*(node[0], node[1], node[2])) + "\n")

    ret["model"] = modelImport
    ret["mesh"] = mesh_import
    # Write elements file
    with open(os.path.join(outfolder, "scene_elements.txt"), "w") as f:
        for tetra in mesh_import.tetrahedres:
            volindex = idVolumeIndex.get(tetra.idVolume)
            if volindex is None:
                volindex = len(idVolumeIndex) + 1
                idVolumeIndex[tetra.idVolume] = len(idVolumeIndex) + 1
            f.write('{0:>6} {1:>6} {2:>6} {3:>6} {4:>6}'.format(*(
            tetra.vertices[0] + 1, tetra.vertices[1] + 1, tetra.vertices[2] + 1, tetra.vertices[3] + 1,
            volindex)) + "\n")

    # Write tetra face file
    with open(os.path.join(outfolder,"scene_faces.txt"), "w") as f:
        for tetra in mesh_import.tetrahedres:
            process_face(tetra.getFace(0), modelImport, sharedVertices, f)
            process_face(tetra.getFace(1), modelImport, sharedVertices, f)
            process_face(tetra.getFace(2), modelImport, sharedVertices, f)
            process_face(tetra.getFace(3), modelImport, sharedVertices, f)

    # Write boundary material file
    with open(os.path.join(outfolder,"scene_materials_absorption.txt"), "w") as f:
        for xmlid, mat in materials.iteritems():
            f.write('{0:>6} '.format(xmlid))
            # for each frequency band
            for freqAbs in mat["q"]:
                f.write(' {0:>6.2g}'.format(freqAbs))
            # end of line
            f.write("\n")

    # Write boundary material transmission file
    with open(os.path.join(outfolder, "scene_materials_transmission.txt"), "w") as f:
        for xmlid, mat in materials.iteritems():
            f.write('{0:>6} '.format(xmlid))
            # for each frequency band
            for freqTransm in mat["g"]:
                f.write(' {0:>6.2g}'.format(freqTransm))
            # end of line
            f.write("\n")

    # Write source position and power files
    with open(os.path.join(outfolder, "scene_sources.txt"), "w") as f:
        for src in sources_lst:
            f.write('{0:>15} {1:>15} {2:>15} '.format(src.pos[0], src.pos[1], src.pos[2]))
            # for each frequency band
            for spl in src.db:
                f.write(' {0:>6.4g}'.format(spl))
            # end of line
            f.write("\n")

    # Write shared vertices index
    with open(os.path.join(outfolder, "scene_shared_vertices.txt"), "w") as f:
        for ptindex in sharedVertices:
            f.write(str(ptindex) + "\n")

    return ret
Example #9
0
def write_input_files(cbinpath, cmbinpath, materials, sources_lst, outfolder):
    """
     Import 3D model
     This model contains the associated material link to the XML file
     XML volume index to octave index
    :param cbinpath:
    :param cmbinpath:
    :param materials:
    :param sources_lst:
    :param outfolder:
    :return: dictionary of loaded data or None if failed
    """
    ret = {}
    idVolumeIndex = {}
    sharedVertices = set()

    modelImport = ls.ioModel()
    if not ls.CformatBIN().ImportBIN(modelImport, cbinpath):
        print("Error can not load %s model !\n" % cbinpath)
        return None

    # Import 3D mesh file builded from tetgen output
    mesh_import = ls.CMBIN().LoadMesh(cmbinpath)
    if not mesh_import:
        print("Error can not load %s mesh model !\n" % cmbinpath)
        return None

    # Write NODES file
    with open(os.path.join(outfolder, "scene_nodes.txt"), "w") as f:
        for node in mesh_import.nodes:
            f.write('{0:>15} {1:>15} {2:>15}'.format(*(node[0], node[1],
                                                       node[2])) + "\n")

    ret["model"] = modelImport
    ret["mesh"] = mesh_import
    # Write elements file
    with open(os.path.join(outfolder, "scene_elements.txt"), "w") as f:
        for tetra in mesh_import.tetrahedres:
            volindex = idVolumeIndex.get(tetra.idVolume)
            if volindex is None:
                volindex = len(idVolumeIndex) + 1
                idVolumeIndex[tetra.idVolume] = len(idVolumeIndex) + 1
            f.write('{0:>6} {1:>6} {2:>6} {3:>6} {4:>6}'.format(
                *(tetra.vertices[0] + 1, tetra.vertices[1] + 1,
                  tetra.vertices[2] + 1, tetra.vertices[3] + 1, volindex)) +
                    "\n")

    # Write tetra face file
    with open(os.path.join(outfolder, "scene_faces.txt"), "w") as f:
        for tetra in mesh_import.tetrahedres:
            process_face(tetra.getFace(0), modelImport, sharedVertices, f)
            process_face(tetra.getFace(1), modelImport, sharedVertices, f)
            process_face(tetra.getFace(2), modelImport, sharedVertices, f)
            process_face(tetra.getFace(3), modelImport, sharedVertices, f)

    # Write boundary material file
    with open(os.path.join(outfolder, "scene_materials_absorption.txt"),
              "w") as f:
        for xmlid, mat in materials.iteritems():
            f.write('{0:>6} '.format(xmlid))
            # for each frequency band
            for freqAbs in mat["q"]:
                f.write(' {0:>6.2g}'.format(freqAbs))
            # end of line
            f.write("\n")

    # Write boundary material transmission file
    with open(os.path.join(outfolder, "scene_materials_transmission.txt"),
              "w") as f:
        for xmlid, mat in materials.iteritems():
            f.write('{0:>6} '.format(xmlid))
            # for each frequency band
            for freqTransm in mat["g"]:
                f.write(' {0:>6.2g}'.format(freqTransm))
            # end of line
            f.write("\n")

    # Write source position and power files
    with open(os.path.join(outfolder, "scene_sources.txt"), "w") as f:
        for src in sources_lst:
            f.write('{0:>15} {1:>15} {2:>15} '.format(src.pos[0], src.pos[1],
                                                      src.pos[2]))
            # for each frequency band
            for spl in src.db:
                f.write(' {0:>6.4g}'.format(spl))
            # end of line
            f.write("\n")

    # Write shared vertices index
    with open(os.path.join(outfolder, "scene_shared_vertices.txt"), "w") as f:
        for ptindex in sharedVertices:
            f.write(str(ptindex) + "\n")

    return ret
Example #10
0
import libsimpa as ls

model=ls.ioModel()
ls.CformatBIN().ImportBIN(model,"modeldebug.cbin")
merger=ls.SurfaceMerging()
merger.LoadGroups(model)
print "Il y a %i groupes de surfaces)" % (merger.GetGroups())
for igroup in range(0,merger.GetGroups()):
    faces=list(merger.GetGroupInformation(igroup))
    print "Groupe %i" % (igroup)
    print faces
    print "\n"