def test2_2():
    """
    This functions builds a planar mesh and checks that the weights of the
    middle vertex are correct. Here is the mesh:
    
        \\
        |\ \ 
        | \  \
        |  \   \_________
        | -0.22 |      /|
        |    \ 0.88  /  |
        |     \ |  /    |
        |_0.66_\|/__0.44|
        |      /|\      |
        |    /  |  \    |
        |  /   0.44  \  |
        |/______|______\|

    
    """
    # create vertices
    x = np.array([0., 1., 2.])
    x = np.repeat(x, 3)
    y = np.array([0., 1., 2.])
    y = np.tile(y ,3)
    y[2] = 3.
    z = np.zeros(9)
    vertices = np.vstack((x, y, z)).T
    
    # create polygons
    polygons = np.array([[0, 3, 4], [0, 4, 1], [1, 4, 2], [2, 4, 5],
                         [3, 6, 4], [4, 6, 7], [4, 7, 8], [4, 8, 5]])
    
    # get edges
    nb_edges = 3 * polygons.shape[0]
    edges = np.zeros((nb_edges, 2))
    # get the polygons edges as tuples
    permutator = np.array([(0,0,1),(1,0,0),(0,1,0)], dtype=int)
    edges[:,0] = np.ravel(polygons)
    edges[:,1] = np.ravel(np.dot(polygons, permutator))
    ind = np.lexsort((edges[:,1], edges[:,0]))
    edges = edges[ind]

    weights_matrix = smooth.compute_weights_matrix(polygons, vertices, edges)

    assert (weights_matrix[4,0] == 0. and
            weights_matrix[4,2] == -0.22222222222222221 and
            weights_matrix[4,6] == 0. and weights_matrix[4,8] == 0.)
    assert (weights_matrix[4,1] == 0.66666666666666663 and
            weights_matrix[4,3] == 4./9. and
            weights_matrix[4,5] == 0.88888888888888884 and
            weights_matrix[4,7] == 4./9.)
def test5_1():
    """
    This functions builds a planar mesh and compute the associated
    weights matrix:
        ________________
        |\      |      /|
        |  \   0.5   /  |
        |    \  |  /    |
        |_0.5__\|/__0.5_|
        |      /|\      |
        |    /  |  \    |
        |  /   0.5   \  |
        |/______|______\|
    
    
    Then, the smoothing parameters are computed according to the given FWHM.
    The function checks that the computed parameters are correct.
    
    """
    # create vertices
    x = np.array([0., 1., 2.])
    x = np.repeat(x, 3)
    y = np.array([0., 1., 2.])
    y = np.tile(y ,3)
    z = np.zeros(9)
    vertices = np.vstack((x, y, z)).T
    
    # create polygons
    polygons = np.array([[0, 3, 4], [0, 4, 1], [1, 4, 2], [2, 4, 5],
                         [3, 6, 4], [4, 6, 7], [4, 7, 8], [4, 8, 5]])
    
    # get edges
    nb_edges = 3 * polygons.shape[0]
    edges = np.zeros((nb_edges, 2))
    # get the polygons edges as tuples
    permutator = np.array([(0,0,1),(1,0,0),(0,1,0)], dtype=int)
    edges[:,0] = np.ravel(polygons)
    edges[:,1] = np.ravel(np.dot(polygons, permutator))
    ind = np.lexsort((edges[:,1], edges[:,0]))
    edges = edges[ind]

    weights_matrix = smooth.compute_weights_matrix(polygons, vertices, edges)
    dt_max = 1/np.amax(np.ravel(weights_matrix.sum(1)))
    dt_max /= 2
    for FWHM in np.arange(1, 20):
        N, dt = smooth.compute_smoothing_parameters(weights_matrix, FWHM)
        assert (FWHM == 4 * np.sqrt(np.log(2) * N * dt))
        N, dt = smooth.compute_smoothing_parameters(weights_matrix,
                                                    FWHM, dt_max)
        assert (FWHM == 4 * np.sqrt(np.log(2) * N * dt))
def test4_1():
    """
    This functions builds a planar mesh and checks that the weights of the
    middle vertex is correct. Here is the mesh (with the non-zero weights):
        ________________
        |\      |      /|
        |  \   0.5   /  |
        |    \  |  /    |
        |_0.5__\|/__0.5_|   sum(wi) = 2
        |      /|\      |
        |    /  |  \    |
        |  /   0.5   \  |
        |/______|______\|
    
    
    It also checks that the Laplace-Beltrami operator is correctly defined
    """
    # create vertices
    x = np.array([0., 1., 2.])
    x = np.repeat(x, 3)
    y = np.array([0., 1., 2.])
    y = np.tile(y ,3)
    z = np.zeros(9)
    vertices = np.vstack((x, y, z)).T
    
    # create polygons
    polygons = np.array([[0, 3, 4], [0, 4, 1], [1, 4, 2], [2, 4, 5],
                         [3, 6, 4], [4, 6, 7], [4, 7, 8], [4, 8, 5]])
    
    # get edges
    nb_edges = 3 * polygons.shape[0]
    edges = np.zeros((nb_edges, 2))
    # get the polygons edges as tuples
    permutator = np.array([(0,0,1),(1,0,0),(0,1,0)], dtype=int)
    edges[:,0] = np.ravel(polygons)
    edges[:,1] = np.ravel(np.dot(polygons, permutator))
    ind = np.lexsort((edges[:,1], edges[:,0]))
    edges = edges[ind]

    weights_matrix = smooth.compute_weights_matrix(polygons, vertices, edges)
    LB_operator = smooth.define_LB_operator(weights_matrix)

    assert (LB_operator[4,0] == 0. and LB_operator[4,2] == 0. and
            LB_operator[4,6] == 0. and LB_operator[4,8] == 0.)
    assert (LB_operator[4,1] == 0.5 and LB_operator[4,3] == 0.5 and
            LB_operator[4,5] == 0.5 and LB_operator[4,7] == 0.5)
    assert (LB_operator[4,4] == -2.)
Пример #4
0
 polygons = t.getData()
 nb_polygons = polygons.shape[0]
 edges = get_edges_from_polygons(polygons, vertices)
 
 ### Get information from input texture
 # /!\ fixme : check that input_tex corresponds to the mesh
 print "  * Getting information from input texture"
 sys.stdout.flush()
 input_tex = tio.Texture(orig_tex_path).read(orig_tex_path)
 activation_data = input_tex.data
 activation_data[np.isnan(activation_data)] = 0
     
 ### Construct the weights matrix
 print "  * Computing the weights matrix"
 sys.stdout.flush()
 weights_matrix = smooth.compute_weights_matrix(polygons, vertices, edges)
     
 ### Define the Laplace-Beltrami operator
 LB_operator = smooth.define_LB_operator(weights_matrix)
     
 ### Compute the number of iterations needed
 N, dt = smooth.compute_smoothing_parameters(weights_matrix, FWHM)
     
 ### Apply smoothing
 print "  * Smoothing...(FWHM = %g)" %FWHM
 sys.stdout.flush()
 smoothed_activation_data = smooth.diffusion_smoothing(
     activation_data, LB_operator, N, dt)
 
 ### Write smoothed data into a new texture file
 print "  * Writing output texture"