def buildMeshImage(vertices, faces,
                    encoding=GiftiEncoding.GIFTI_ENCODING_ASCII):
     """ build a GiftiImage from arrays of vertices and faces 
     
     NOTE : this is doing the same as the gifti.GiftiImage_fromTriangles
     function and is only redefined here for demonstration purpose"""
 
     k = GiftiImage_fromarray(vertices)
     k.arrays[0].intentString = "NIFTI_INTENT_POINTSET"
     k.addDataArray_fromarray(faces, GiftiIntentCode.NIFTI_INTENT_TRIANGLE)
     for a in k.arrays:
         a.encoding = encoding
     return k
Exemplo n.º 2
0
    def buildMeshImage(vertices,
                       faces,
                       encoding=GiftiEncoding.GIFTI_ENCODING_ASCII):
        """ build a GiftiImage from arrays of vertices and faces

        NOTE : this is doing the same as the gifti.GiftiImage_fromTriangles
        function and is only redefined here for demonstration purpose"""

        k = GiftiImage_fromarray(vertices)
        k.arrays[0].intentString = "NIFTI_INTENT_POINTSET"
        k.addDataArray_fromarray(faces, GiftiIntentCode.NIFTI_INTENT_TRIANGLE)
        for a in k.arrays:
            a.encoding = encoding
        return k
Exemplo n.º 3
0
def mesh_contour_with_files(input_mesh, input_labels, output_mesh=None,
                            output_labels=None):
    from gifti import loadImage, saveImage, GiftiDataArray, GiftiImage
    from gifti import GiftiImage_fromarray, GiftiImage_fromTriangles
    from gifti import GiftiIntentCode, GiftiEncoding

    labels = loadImage(input_labels).arrays[0].data.astype(int)
    cor, triangles = loadImage(input_mesh).arrays

    contour_cor, contour_tri = mesh_contour(cor.data, triangles.data.astype(int),
                                            labels)
    k = GiftiImage_fromarray(contour_cor)
    k.arrays[0].intentString = "NIFTI_INTENT_POINTSET"
    k.addDataArray_fromarray(contour_tri, GiftiIntentCode.NIFTI_INTENT_TRIANGLE)
    for a in k.arrays:
        a.encoding = GiftiEncoding.GIFTI_ENCODING_ASCII

    if output_mesh is None:
        output_mesh = non_existent_file(add_suffix(input_mesh, '_contour'))
    pyhrf.verbose(1, 'saving to %s' %output_mesh)
    k.save(output_mesh)