def plot_mesh_nrosy(viewer, V, F, N, PD1, S, b):
    # Clear the mesh
    viewer.data.clear()
    viewer.data.set_mesh(V,F)

    # Expand the representative vectors in the full vector set and plot them as lines
    avg = igl.avg_edge_length(V, F)
    Y = igl.eigen.MatrixXd()
    representative_to_nrosy(V, F, PD1, N, Y)

    B = igl.eigen.MatrixXd()
    igl.barycenter(V,F,B)

    Be = igl.eigen.MatrixXd(B.rows()*N,3)
    for i in range(0,B.rows()):
        for j in range(0,N):
            Be.setRow(i*N+j,B.row(i))

    viewer.data.add_edges(Be,Be+Y*(avg/2),igl.eigen.MatrixXd([[0,0,1]]))

    # Plot the singularities as colored dots (red for negative, blue for positive)
    for i in range(0,S.size()):
        if S[i] < -0.001:
            viewer.data.add_points(V.row(i),igl.eigen.MatrixXd([[1,0,0]]))
        elif S[i] > 0.001:
            viewer.data.add_points(V.row(i),igl.eigen.MatrixXd([[0,1,0]]));

    # 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)
def key_pressed(viewer, key, modifier):
    global V
    global U
    global F
    global L

    if key == ord('r') or key == ord('R'):
        U = V;
    elif key == ord(' '):

        # Recompute just mass matrix on each step
        M = igl.eigen.SparseMatrixd()

        igl.massmatrix(U,F,igl.MASSMATRIX_TYPE_BARYCENTRIC,M);

        # Solve (M-delta*L) U = M*U
        S = (M - 0.001*L)

        solver = igl.eigen.SimplicialLLTsparse(S)

        U = solver.solve(M*U)

        # Compute centroid and subtract (also important for numerics)
        dblA = igl.eigen.MatrixXd()
        igl.doublearea(U,F,dblA)

        print(dblA.sum())

        area = 0.5*dblA.sum()
        BC = igl.eigen.MatrixXd()
        igl.barycenter(U,F,BC)
        centroid = igl.eigen.MatrixXd([[0.0,0.0,0.0]])

        for i in range(0,BC.rows()):
            centroid += 0.5*dblA[i,0]/area*BC.row(i)

        U -= centroid.replicate(U.rows(),1)

        # Normalize to unit surface area (important for numerics)
        U = U / math.sqrt(area)
    else:
        return False

    # Send new positions, update normals, recenter
    viewer.data.set_vertices(U)
    viewer.data.compute_normals()
    viewer.core.align_camera_center(U,F)
    return True
Exemplo n.º 3
0
# Add the igl library to the modules search path
import sys, os
sys.path.insert(0, os.getcwd() + "/../")

import igl

V = igl.eigen.MatrixXd()
F = igl.eigen.MatrixXi()

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()
        viewer.core.show_texture = True

    viewer.data.set_colors(igl.eigen.MatrixXd([[1, 1, 1]]))

    viewer.data.set_texture(texture_R, texture_B, texture_G)

    viewer.core.align_camera_center(viewer.data.V, viewer.data.F)

    return False


# Load a mesh in OFF format
igl.readOFF("../../tutorial/shared/3holes.off", V, F)

# Compute face barycenters
igl.barycenter(V, F, B)

# Compute scale for visualizing fields
global_scale = .5 * igl.avg_edge_length(V, F)

# Contrain one face
b = igl.eigen.MatrixXi([[0]])
bc = igl.eigen.MatrixXd([[1, 0, 0]])

# Create a smooth 4-RoSy field
S = igl.eigen.MatrixXd()

igl.comiso.nrosy(V, F, b, bc, igl.eigen.MatrixXi(), igl.eigen.MatrixXd(),
                 igl.eigen.MatrixXd(), 4, 0.5, X1, S)

# Find the the orthogonal vector
Exemplo n.º 5
0
# Add the igl library to the modules search path
import sys, os
sys.path.insert(0, os.getcwd() + "/../")

import igl

V = igl.eigen.MatrixXd()
F = igl.eigen.MatrixXi()

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()
        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


# Load a mesh in OBJ format
igl.readOBJ("../../tutorial/shared/lilium.obj", V, F)
samples = readSamples("../../tutorial/shared/lilium.samples.0.2")

# Compute local basis for faces
igl.local_basis(V,F,B1,B2,B3)

# Compute face barycenters
igl.barycenter(V, F, B)

# Compute scale for visualizing fields
global_scale = 0.2*igl.avg_edge_length(V, F)

# Make the example deterministic
random.seed(0)

viewer = igl.viewer.Viewer()
viewer.data.set_mesh(V, F)
viewer.callback_key_down = key_down
viewer.core.show_lines = False

key_down(viewer,ord('2'),0)

viewer.launch()
 def test_barycenter(self):
     bc = igl.barycenter(self.v, self.f)
     self.assertEqual(bc.dtype, self.v.dtype)
     self.assertEqual(bc.shape[0], self.f.shape[0])
     self.assertEqual(bc.shape[1], 3)
     self.assertTrue(bc.flags.c_contiguous)
Exemplo n.º 8
0
 def test_barycenter(self):
     bc = igl.barycenter(self.v, self.f)
     self.assertEqual(bc.dtype, self.v.dtype)
     self.assertEqual(bc.shape[0], self.f.shape[0])
     self.assertEqual(bc.shape[1], 3)