def solve(viewer):
    global Q, B, b, bc, Aeq, Beq, Aieq, Bieq, lx, ux, Z
    params = igl.active_set_params()
    params.max_iter = 8

    igl.active_set(Q, B, b, bc, Aeq, Beq, Aieq, Bieq, lx, ux, params, Z)

    C = igl.eigen.MatrixXd()
    igl.jet(Z, 0, 1, C)
    viewer.data.set_colors(C)
コード例 #2
0
def solve(viewer):
    global Q,B,b,bc,Aeq,Beq,Aieq,Bieq,lx,ux,Z
    params = igl.active_set_params()
    params.max_iter = 8

    igl.active_set(Q,B,b,bc,Aeq,Beq,Aieq,Bieq,lx,ux,params,Z)

    C = igl.eigen.MatrixXd()
    igl.jet(Z,0,1,C)
    viewer.data.set_colors(C)
コード例 #3
0
def key_down(viewer, key, modifier):
    if key < ord('1') or key > ord('8'):
        return False

    viewer.data.lines.resize(0, 9)

    num = key - ord('0')

    # Interpolate
    print("Interpolating " + repr(num * 2) + "-PolyVector field")

    b = igl.eigen.MatrixXi([[4550, 2321, 5413, 5350]]).transpose()

    bc = igl.eigen.MatrixXd(b.size(), num * 3)

    for i in range(0, b.size()):
        t = random_constraints(B1.row(b[i]), B2.row(b[i]), num)
        bc.setRow(i, t)

    # Interpolated PolyVector field
    pvf = igl.eigen.MatrixXd()
    igl.n_polyvector(V, F, b, bc, pvf)

    # Highlight in red the constrained faces
    C = igl.eigen.MatrixXd.Constant(F.rows(), 3, 1)

    for i in range(0, b.size()):
        C.setRow(b[i], igl.eigen.MatrixXd([[1, 0, 0]]))
    viewer.data.set_colors(C)

    for n in range(0, num):
        VF = igl.eigen.MatrixXd.Zero(F.rows(), 3)

        for i in range(0, b.size()):
            VF.setRow(b[i], bc.block(i, n * 3, 1, 3))

        for i in range(0, samples.rows()):
            VF.setRow(samples[i], pvf.block(samples[i], n * 3, 1, 3))

        c = VF.rowwiseNorm()

        C2 = igl.eigen.MatrixXd()
        igl.jet(c, 1, 1 + rand_factor, C2)
        viewer.data.add_edges(B - global_scale * VF, B + global_scale * VF, C2)

    return False
コード例 #4
0
def key_down(viewer, key, modifier):
    if key < ord('1') or key > ord('8'):
        return False

    viewer.data.lines.resize(0,9)

    num = key  - ord('0')

    # Interpolate
    print("Interpolating " + repr(num * 2) + "-PolyVector field")

    b = igl.eigen.MatrixXi([[4550, 2321, 5413, 5350]]).transpose()

    bc = igl.eigen.MatrixXd(b.size(),num*3)

    for i in range(0,b.size()):
        t = random_constraints(B1.row(b[i]),B2.row(b[i]),num)
        bc.setRow(i,t)

    # Interpolated PolyVector field
    pvf = igl.eigen.MatrixXd()
    igl.n_polyvector(V, F, b, bc, pvf)

    # Highlight in red the constrained faces
    C = igl.eigen.MatrixXd.Constant(F.rows(),3,1)

    for i in range(0,b.size()):
        C.setRow(b[i],igl.eigen.MatrixXd([[1, 0, 0]]))
    viewer.data.set_colors(C)

    for n in range(0,num):
        VF = igl.eigen.MatrixXd.Zero(F.rows(),3)

        for i in range(0,b.size()):
            VF.setRow(b[i],bc.block(i,n*3,1,3))

        for i in range(0,samples.rows()):
            VF.setRow(samples[i],pvf.block(samples[i],n*3,1,3))

        c = VF.rowwiseNorm()

        C2 = igl.eigen.MatrixXd()
        igl.jet(c,1,1+rand_factor,C2)
        viewer.data.add_edges(B - global_scale*VF, B + global_scale*VF , C2)

    return False
コード例 #5
0
igl.readOFF("../../tutorial/shared/decimated-knight.off",V,F)

# Sort barycenters lexicographically
BC = igl.eigen.MatrixXd()
sorted_BC = igl.eigen.MatrixXd()

igl.barycenter(V,F,BC);

I = igl.eigen.MatrixXi()
J = igl.eigen.MatrixXi()

# sorted_BC = BC(I,:)
igl.sortrows(BC,True,sorted_BC,I)

# Get sorted "place" from sorted indices
J.resize(I.rows(),1)
# J(I) = 1:numel(I)

igl.slice_into(igl.coloni(0,I.size()-1),I,J)

# Pseudo-color based on sorted place
C = igl.eigen.MatrixXd()
igl.jet(J.castdouble(),True,C)

# Plot the mesh with pseudocolors
viewer = igl.viewer.Viewer()
viewer.data.set_mesh(V, F)
viewer.data.set_colors(C)
viewer.launch()
コード例 #6
0
Z_in = solver.solve(L_in_b * bc)

# slice into solution
igl.slice_into(Z_in, vin, Z)

# Alternative, short hand
mqwf = igl.min_quad_with_fixed_data()

# Linear term is 0
B = igl.eigen.MatrixXd()
B.setZero(V.rows(), 1)

# Empty constraints
Beq = igl.eigen.MatrixXd()
Aeq = igl.eigen.SparseMatrixd()

# Our cotmatrix is _negative_ definite, so flip sign
igl.min_quad_with_fixed_precompute(-L, b, Aeq, True, mqwf)
igl.min_quad_with_fixed_solve(mqwf, B, bc, Beq, Z)

# Pseudo-color based on solution
C = igl.eigen.MatrixXd()
igl.jet(Z, True, C)

# Plot the mesh with pseudocolors
viewer = igl.viewer.Viewer()
viewer.data.set_mesh(V, F)
viewer.core.show_lines = False
viewer.data.set_colors(C)
viewer.launch()
# Pseudo-color based on solution
global C
C = igl.eigen.MatrixXd()

global C_const
C_const = igl.eigen.MatrixXd()

global toggle
toggle = True

# Use same color axes
min_z = min(Z.minCoeff(), Z_const.minCoeff())
max_z = max(Z.maxCoeff(), Z_const.maxCoeff())

igl.jet(Z, min_z, max_z, C)
igl.jet(Z_const, min_z, max_z, C_const)

# Plot the mesh with pseudocolors
viewer = igl.viewer.Viewer()
viewer.data.set_mesh(V, F)
viewer.core.show_lines = False
viewer.data.set_colors(C)


def key_down(viewer, key, mode):
    if key == ord(' '):
        global toggle
        global C
        global C_const
コード例 #8
0
igl.readOFF("../../tutorial/shared/decimated-knight.off", V, F)

# Sort barycenters lexicographically
BC = igl.eigen.MatrixXd()
sorted_BC = igl.eigen.MatrixXd()

igl.barycenter(V, F, BC)

I = igl.eigen.MatrixXi()
J = igl.eigen.MatrixXi()

# sorted_BC = BC(I,:)
igl.sortrows(BC, True, sorted_BC, I)

# Get sorted "place" from sorted indices
J.resize(I.rows(), 1)
# J(I) = 1:numel(I)

igl.slice_into(igl.coloni(0, I.size() - 1), I, J)

# Pseudo-color based on sorted place
C = igl.eigen.MatrixXd()
igl.jet(J.castdouble(), True, C)

# Plot the mesh with pseudocolors
viewer = igl.viewer.Viewer()
viewer.data.set_mesh(V, F)
viewer.data.set_colors(C)
viewer.launch()
コード例 #9
0
Z_in = solver.solve(L_in_b*bc)

# slice into solution
igl.slice_into(Z_in,vin,Z)

# Alternative, short hand
mqwf = igl.min_quad_with_fixed_data()

# Linear term is 0
B = igl.eigen.MatrixXd()
B.setZero(V.rows(),1);

# Empty constraints
Beq = igl.eigen.MatrixXd()
Aeq = igl.eigen.SparseMatrixd()

# Our cotmatrix is _negative_ definite, so flip sign
igl.min_quad_with_fixed_precompute(-L,b,Aeq,True,mqwf)
igl.min_quad_with_fixed_solve(mqwf,B,bc,Beq,Z)

# Pseudo-color based on solution
C = igl.eigen.MatrixXd()
igl.jet(Z,True,C)

# Plot the mesh with pseudocolors
viewer = igl.viewer.Viewer()
viewer.data.set_mesh(V, F)
viewer.core.show_lines = False
viewer.data.set_colors(C)
viewer.launch()
コード例 #10
0
# Pseudo-color based on solution
global C
C = igl.eigen.MatrixXd()

global C_const
C_const = igl.eigen.MatrixXd()

global toggle
toggle = True

# Use same color axes
min_z = min(Z.minCoeff(),Z_const.minCoeff())
max_z = max(Z.maxCoeff(),Z_const.maxCoeff())

igl.jet(      Z,min_z,max_z,C);
igl.jet(Z_const,min_z,max_z,C_const);

# Plot the mesh with pseudocolors
viewer = igl.viewer.Viewer()
viewer.data.set_mesh(V, F)
viewer.core.show_lines = False
viewer.data.set_colors(C)

def key_down(viewer,key,mode):
    if key == ord(' '):
        global toggle
        global C
        global C_const

        if toggle:
コード例 #11
0
G = igl.eigen.SparseMatrixd()
igl.grad(V, F, G)

# Compute gradient of U
GU = (G * U).MapMatrix(F.rows(), 3)

# Compute gradient magnitude
GU_mag = GU.rowwiseNorm()

viewer = igl.viewer.Viewer()
viewer.data.set_mesh(V, F)

# Compute pseudocolor for original function
C = igl.eigen.MatrixXd()

igl.jet(U, True, C)

# Or for gradient magnitude
# igl.jet(GU_mag,True,C)

viewer.data.set_colors(C)

# Average edge length divided by average gradient (for scaling)
max_size = igl.avg_edge_length(V, F) / GU_mag.mean()

# Draw a black segment in direction of gradient at face barycenters
BC = igl.eigen.MatrixXd()
igl.barycenter(V, F, BC)

black = igl.eigen.MatrixXd([[0.0, 0.0, 0.0]])
viewer.data.add_edges(BC, BC + max_size * GU, black)
コード例 #12
0
# Add the igl library to the modules search path
import sys, os
sys.path.insert(0, os.getcwd() + "/../")

import igl

# Load mesh
V = igl.eigen.MatrixXd()
F = igl.eigen.MatrixXi()
igl.readOFF("../../tutorial/shared/bumpy.off",V,F);

# Compute Gaussian curvature
K = igl.eigen.MatrixXd();
igl.gaussian_curvature(V,F,K);

# Compute pseudocolor
C = igl.eigen.MatrixXd();
igl.jet(K,True,C);

# Plot the mesh with pseudocolors
viewer = igl.viewer.Viewer()
viewer.data.set_mesh(V, F)
viewer.data.set_colors(C)
viewer.launch()
コード例 #13
0
ファイル: 204_Gradient.py プロジェクト: ChrisMousas/libigl
G = igl.eigen.SparseMatrixd()
igl.grad(V,F,G)

# Compute gradient of U
GU = (G*U).MapMatrix(F.rows(),3)

# Compute gradient magnitude
GU_mag = GU.rowwiseNorm()

viewer = igl.viewer.Viewer()
viewer.data.set_mesh(V, F)

# Compute pseudocolor for original function
C = igl.eigen.MatrixXd()

igl.jet(U,True,C)

# Or for gradient magnitude
# igl.jet(GU_mag,True,C)

viewer.data.set_colors(C);

# Average edge length divided by average gradient (for scaling)
max_size = igl.avg_edge_length(V,F) / GU_mag.mean()

# Draw a black segment in direction of gradient at face barycenters
BC = igl.eigen.MatrixXd()
igl.barycenter(V,F,BC)

black = igl.eigen.MatrixXd([[0.0,0.0,0.0]])
viewer.data.add_edges(BC,BC+max_size*GU, black)