Skip to content

Commit 982eb46

Browse files
author
EJShim
committed
added boundary actor
1 parent 80d0ea2 commit 982eb46

File tree

5 files changed

+287
-9
lines changed

5 files changed

+287
-9
lines changed

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
#Mesh Parameterization Python
1+
# Mesh Parameterization Python
22
python code of mesh parameterizaiton tutte, lscm
33

44

5-
#Prerequisites
5+
# Prerequisites
66
- vtk
77
- libigl
88

main.py

+50-7
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,34 @@
11

22
import sys
3+
import os
34
import vtk
45
import igl
56
from vtk.util import numpy_support
67
import numpy as np
78
import math
9+
import random
810
from scipy.sparse import csr_matrix, coo_matrix
911

1012

13+
vtk_out = vtk.vtkOutputWindow()
14+
vtk_out.SetInstance(vtk_out)
15+
16+
17+
#Make Shader
18+
19+
20+
rootPath = os.path.dirname( os.path.abspath( __file__ ))
21+
with open( os.path.join( rootPath, "shaders", "normalmap.glsl"), 'r') as shaderFile:
22+
FragmentShaderText = shaderFile.read()
23+
24+
with open( os.path.join( rootPath, "shaders", "vertexShader.glsl"), 'r') as shaderFile:
25+
VertexShaderText = shaderFile.read()
26+
27+
1128
def tutte(V, F):
1229

1330
#Get Boundary and Edge
1431
L = igl.boundary_loop(F)
15-
E = igl.edges(F)
1632
sizeL = len(L)
1733

1834

@@ -24,6 +40,8 @@ def tutte(V, F):
2440

2541

2642
#Iterate over edge, build some kind of sparse matrix,,
43+
E = igl.edges(F)
44+
2745
I = []
2846
J = []
2947
Val = []
@@ -67,20 +85,43 @@ def tutte(V, F):
6785
# print(A.shape)
6886
U = igl.min_quad_with_fixed(A, B_flat, b, bc, Aeq, Beq, False)
6987

70-
return U[1]
88+
return U[1], bc
7189

7290

7391
def MakeActor(polydata):
74-
mapper = vtk.vtkPolyDataMapper()
92+
mapper = vtk.vtkOpenGLPolyDataMapper()
7593
mapper.SetInputData(polydata)
7694

95+
# mapper.SetVertexShaderCode(VertexShaderText)
96+
# mapper.SetFragmentShaderCode(FragmentShaderText)
97+
polydata.GetPointData().RemoveArray("Normals")
98+
7799

78100
actor = vtk.vtkActor()
79101
actor.SetMapper(mapper)
80102

81103
return actor
82104

83105

106+
def MakeBoundaryActor(boundary):
107+
print(boundary.shape)
108+
boundary3D = np.concatenate( [boundary, np.zeros((len(boundary),1) )], axis=1)
109+
print(boundary3D)
110+
111+
polydata = vtk.vtkPolyData()
112+
points = vtk.vtkPoints()
113+
points.SetData( numpy_support.numpy_to_vtk(boundary3D) )
114+
polydata.SetPoints(points)
115+
116+
mapper = vtk.vtkOpenGLSphereMapper()
117+
mapper.SetRadius(.005)
118+
mapper.SetInputData(polydata)
119+
120+
actor = vtk.vtkActor()
121+
actor.SetMapper(mapper)
122+
123+
return actor
124+
84125

85126
if __name__ == "__main__":
86127
iren = vtk.vtkRenderWindowInteractor()
@@ -103,26 +144,28 @@ def MakeActor(polydata):
103144
reader.Update()
104145
polydata = reader.GetOutput()
105146
actor = MakeActor(polydata)
147+
actor.SetScale(.01, .01, .01)
106148
ren.AddActor(actor)
107-
# polydata.GetPointData().RemoveArray("Normals")
108-
149+
109150

110151
# Get V and F from polydatqa
111152
V = numpy_support.vtk_to_numpy( polydata.GetPoints().GetData())
112153
F = numpy_support.vtk_to_numpy( polydata.GetPolys().GetData() )
113154
F = F.reshape( int(len(F)/4), 4 )
114155
F = F[:, 1:]
115156

116-
U_tutte = tutte(V, F)
157+
U_tutte, boundary = tutte(V, F)
117158
V_tutte = np.concatenate((U_tutte, np.zeros( (len(U_tutte),1) ) ), axis=1) #Make three-dimensional
118159

160+
boundaryActor = MakeBoundaryActor(boundary)
161+
ren.AddActor(boundaryActor)
119162

120163
tutte_points = numpy_support.numpy_to_vtk( V_tutte )
121164
tuttePoly = vtk.vtkPolyData()
122165
tuttePoly.DeepCopy(polydata)
123166
tuttePoly.GetPoints().SetData(tutte_points)
124167
tutteActor = MakeActor(tuttePoly)
125-
tutteActor.SetScale( 100, 100, 100 )
168+
# tutteActor.SetScale( 100, 100, 100 )
126169

127170
ren.AddActor(tutteActor)
128171

shaders/diffusemap.glsl

+83
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
//VTK::System::Dec
2+
3+
4+
uniform int PrimitiveIDOffset;
5+
// VC position of this fragment
6+
//VTK::PositionVC::Dec
7+
8+
// optional color passed in from the vertex shader, vertexColor
9+
//VTK::Color::Dec
10+
11+
// optional surface normal declaration
12+
//VTK::Normal::Dec
13+
14+
// extra lighting parameters
15+
//VTK::Light::Dec
16+
17+
// Texture coordinates
18+
//VTK::TCoord::Dec
19+
20+
// picking support
21+
//VTK::Picking::Dec
22+
23+
// Depth Peeling Support
24+
//VTK::DepthPeeling::Dec
25+
26+
// clipping plane vars
27+
//VTK::Clip::Dec
28+
29+
// the output of this shader
30+
//VTK::Output::Dec
31+
32+
// Apple Bug
33+
//VTK::PrimID::Dec
34+
35+
// handle coincident offsets
36+
//VTK::Coincident::Dec
37+
38+
//VTK::ZBuffer::Dec
39+
40+
void main()
41+
{
42+
// VC position of this fragment. This should not branch/return/discard.
43+
//VTK::PositionVC::Impl
44+
45+
// Place any calls that require uniform flow (e.g. dFdx) here.
46+
//VTK::UniformFlow::Impl
47+
48+
// Set gl_FragDepth here (gl_FragCoord.z by default)
49+
//VTK::Depth::Impl
50+
51+
// Early depth peeling abort:
52+
//VTK::DepthPeeling::PreColor
53+
54+
// Apple Bug
55+
//VTK::PrimID::Impl
56+
57+
//VTK::Clip::Impl
58+
59+
//VTK::Color::Impl
60+
61+
// Generate the normal if we are not passed in one
62+
63+
64+
//VTK::TCoord::Impl
65+
66+
67+
gl_FragData[0] = vec4(diffuseColor, 1.0);
68+
if (gl_FragData[0].a <= 0.0)
69+
{
70+
discard;
71+
}
72+
73+
//5cd3b62c
74+
75+
//VTK::DepthPeeling::Impl
76+
77+
//VTK::Picking::Impl
78+
79+
// handle coincident offsets
80+
//VTK::Coincident::Impl
81+
82+
//VTK::ZBuffer::Impl
83+
}

shaders/normalmap.glsl

+84
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
//VTK::System::Dec
2+
3+
4+
uniform int PrimitiveIDOffset;
5+
// VC position of this fragment
6+
//VTK::PositionVC::Dec
7+
8+
// optional color passed in from the vertex shader, vertexColor
9+
//VTK::Color::Dec
10+
11+
// optional surface normal declaration
12+
//VTK::Normal::Dec
13+
14+
// extra lighting parameters
15+
//VTK::Light::Dec
16+
17+
// Texture coordinates
18+
//VTK::TCoord::Dec
19+
20+
// picking support
21+
//VTK::Picking::Dec
22+
23+
// Depth Peeling Support
24+
//VTK::DepthPeeling::Dec
25+
26+
// clipping plane vars
27+
//VTK::Clip::Dec
28+
29+
// the output of this shader
30+
//VTK::Output::Dec
31+
32+
// Apple Bug
33+
//VTK::PrimID::Dec
34+
35+
// handle coincident offsets
36+
//VTK::Coincident::Dec
37+
38+
//VTK::ZBuffer::Dec
39+
40+
41+
void main()
42+
{
43+
// VC position of this fragment. This should not branch/return/discard.
44+
//VTK::PositionVC::Impl
45+
46+
// Place any calls that require uniform flow (e.g. dFdx) here.
47+
//VTK::UniformFlow::Impl
48+
49+
// Set gl_FragDepth here (gl_FragCoord.z by default)
50+
//VTK::Depth::Impl
51+
52+
// Early depth peeling abort:
53+
//VTK::DepthPeeling::PreColor
54+
55+
// Apple Bug
56+
//VTK::PrimID::Impl
57+
58+
59+
//VTK::Clip::Impl
60+
61+
//VTK::Color::Impl
62+
63+
// Generate the normal if we are not passed in one
64+
65+
66+
//VTK::TCoord::Impl
67+
68+
gl_FragData[0] = vec4(normalize(normalVCVSOutput), 1.0);
69+
if (gl_FragData[0].a <= 0.0)
70+
{
71+
discard;
72+
}
73+
74+
//5cd3b62c
75+
76+
//VTK::DepthPeeling::Impl
77+
78+
//VTK::Picking::Impl
79+
80+
// handle coincident offsets
81+
//VTK::Coincident::Impl
82+
83+
//VTK::ZBuffer::Impl
84+
}

shaders/vertexShader.glsl

+68
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
2+
//VTK::System::Dec
3+
4+
/*=========================================================================
5+
6+
Program: Visualization Toolkit
7+
Module: vtkPolyDataVS.glsl
8+
9+
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
10+
All rights reserved.
11+
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
12+
13+
This software is distributed WITHOUT ANY WARRANTY; without even
14+
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15+
PURPOSE. See the above copyright notice for more information.
16+
17+
=========================================================================*/
18+
19+
attribute vec4 vertexMC;
20+
21+
// frag position in VC
22+
//VTK::PositionVC::Dec
23+
24+
// optional normal declaration
25+
//VTK::Normal::Dec
26+
27+
// extra lighting parameters
28+
//VTK::Light::Dec
29+
30+
// Texture coordinates
31+
//VTK::TCoord::Dec
32+
33+
// material property values
34+
//VTK::Color::Dec
35+
36+
// clipping plane vars
37+
//VTK::Clip::Dec
38+
39+
// camera and actor matrix values
40+
//VTK::Camera::Dec
41+
42+
// Apple Bug
43+
//VTK::PrimID::Dec
44+
45+
// picking support
46+
//VTK::Picking::Dec
47+
48+
out vec3 ejNormalMC;
49+
50+
void main()
51+
{
52+
ejNormalMC = normalize(normalMC);
53+
//VTK::Color::Impl
54+
55+
//VTK::Normal::Impl
56+
57+
//VTK::TCoord::Impl
58+
59+
//VTK::Clip::Impl
60+
61+
//VTK::PrimID::Impl
62+
63+
//VTK::PositionVC::Impl
64+
65+
//VTK::Light::Impl
66+
67+
//VTK::Picking::Impl
68+
}

0 commit comments

Comments
 (0)