###################################################################################
#3D mesh manipulation and silhouette detection

#rotation and update of vertices
n11=0.05*np.pi
n22=0.05*np.pi

#3D mesh
MH.scale_mesh(scale1)
MHexam.scale_mesh(scale1)
MH.rotate_mesh(n11, "xy")
MHexam.rotate_mesh(n11, "xy")    
MH.rotate_mesh(n22, "zx")
MHexam.rotate_mesh(n22,"zx")
#Initialisation of edges
MH.unique_edges()
#Identification of edges
MH.silhouette_vertices("Lodox", ViewP)
#projecting alignment points
points_bif3Dproj=pm.project_points_ss(MH.points, l0=ViewP, p0=p0) 
skel_3Dproj=pm.project_points_ss(MH.skel, l0=ViewP, p0=p0)
points_proj=pm.project_points_ss(MH.silvert1, l0=ViewP, p0=p0) 
        
#PLOT 1: Plotting
meshplot_module.plot_big(MH, MHexam, points_proj, points_bif3Dproj, skel_3Dproj, ViewP, proj_type, fnum=1)
#mlab.savefig("figure1.x3d") #exporting as x3d
#mlab.savefig("figure1.png", magnification=2)
mlab.show()

n22 = 0.05 * np.pi

#3D mesh
MH.scale_mesh(scale1)
MHexam.scale_mesh(scale1)
MH.rotate_mesh(n11, "xy")
MHexam.rotate_mesh(n11, "xy")
MH.rotate_mesh(n22, "zx")
MHexam.rotate_mesh(n22, "zx")
#Initialisation of edges
MH.unique_edges()
#Identification of edges
MH.silhouette_vertices("Lodox", ViewP)
#projecting alignment points
points_bif3Dproj = pm.project_points_ss(MH.points, l0=ViewP, p0=p0)
skel_3Dproj = pm.project_points_ss(MH.skel, l0=ViewP, p0=p0)
points_proj = pm.project_points_ss(MH.silvert1, l0=ViewP, p0=p0)

#PLOT 1: Plotting
meshplot_module.plot_big(MH,
                         MHexam,
                         points_proj,
                         points_bif3Dproj,
                         skel_3Dproj,
                         ViewP,
                         proj_type,
                         fnum=1)
#mlab.savefig("figure1.x3d") #exporting as x3d
#mlab.savefig("figure1.png", magnification=2)
mlab.show()
eigenvalues = eigenvalues.reshape((eigenvalues.shape[0], 1))
eigenvalues = eigenvalues * (3 * np.sqrt(MH.V[1:12]))
MH.prin_comp_trans(eigenvalues)
MH.scale_mesh(scale1)
MH.rotate_mesh(n11, "xy")
MH.rotate_mesh(n22, "zx")
#Initialisation of edges
MH.unique_edges()
#Identification of edges
MH.silhouette_vertices("Lodox", ViewP)
#projecting alignment points
points_proj = pm.project_points_ss(MH.silvert1, l0=ViewP, p0=p0)
#PLOT 1: Plotting the projection (deformed statistical model)
meshplot_module.plot_big(MH, [],
                         points_proj, [], [],
                         ViewP,
                         proj_type,
                         plot_type="simple",
                         fnum=1)

#Moving along 2nd mode of variation (Other extreme)
MH.reset_mesh()

#eigenvalues
eigenvalues = np.array([0.0, -1.0, 0., 0., 0., 0., 0., 0., 0., 0., 0.])
#
eigenvalues = eigenvalues.reshape((eigenvalues.shape[0], 1))
eigenvalues = eigenvalues * (3 * np.sqrt(MH.V[1:12]))
MH.prin_comp_trans(eigenvalues)
MH.scale_mesh(scale1)
MH.rotate_mesh(n11, "xy")
MH.rotate_mesh(n22, "zx")
eigenvalues=np.array([0.0, 1.0, 0., 0., 0., 0., 0., 0., 0., 0., 0.])
#
eigenvalues=eigenvalues.reshape((eigenvalues.shape[0], 1))
eigenvalues=eigenvalues*(3*np.sqrt(MH.V[1:12]))
MH.prin_comp_trans(eigenvalues)
MH.scale_mesh(scale1)
MH.rotate_mesh(n11, "xy")
MH.rotate_mesh(n22, "zx")
#Initialisation of edges
MH.unique_edges()
#Identification of edges
MH.silhouette_vertices("Lodox", ViewP)
#projecting alignment points
points_proj=pm.project_points_ss(MH.silvert1, l0=ViewP, p0=p0) 
#PLOT 1: Plotting the projection (deformed statistical model)
meshplot_module.plot_big(MH, [], points_proj, [], [], ViewP, proj_type, 
	plot_type="simple", fnum=1)

#Moving along 2nd mode of variation (Other extreme)
MH.reset_mesh()

#eigenvalues
eigenvalues=np.array([0.0, -1.0, 0., 0., 0., 0., 0., 0., 0., 0., 0.])
#
eigenvalues=eigenvalues.reshape((eigenvalues.shape[0], 1))
eigenvalues=eigenvalues*(3*np.sqrt(MH.V[1:12]))
MH.prin_comp_trans(eigenvalues)
MH.scale_mesh(scale1)
MH.rotate_mesh(n11, "xy")
MH.rotate_mesh(n22, "zx")
#Initialisation of edges
MH.unique_edges()