#include #include #include #include #include #include #include #include // Input mesh Eigen::MatrixXd V; Eigen::MatrixXi F; // Face barycenters Eigen::MatrixXd B; // Scale for visualizing the fields double global_scale; // Cross field Eigen::MatrixXd X1,X2; // Bisector field Eigen::MatrixXd BIS1, BIS2; // Combed bisector Eigen::MatrixXd BIS1_combed, BIS2_combed; // Per-corner, integer mismatches Eigen::MatrixXi MMatch; // Field singularities Eigen::VectorXi isSingularity, singularityIndex; // Per corner seams Eigen::MatrixXi Seams; // Combed field Eigen::MatrixXd X1_combed, X2_combed; // Global parametrization (with seams) Eigen::MatrixXd UV_seams; Eigen::MatrixXi FUV_seams; // Global parametrization Eigen::MatrixXd UV; Eigen::MatrixXi FUV; // Create a texture that hides the integer translation in the parametrization void line_texture(Eigen::Matrix &texture_R, Eigen::Matrix &texture_G, Eigen::Matrix &texture_B) { unsigned size = 128; unsigned size2 = size/2; unsigned lineWidth = 3; texture_R.setConstant(size, size, 255); for (unsigned i=0; i'8') return false; viewer.clear_mesh(); viewer.options.show_lines = false; viewer.options.show_texture = false; if (key == '1') { // Cross field viewer.set_mesh(V, F); viewer.add_edges (B, B + global_scale*X1 ,Eigen::RowVector3d(1,0,0)); viewer.add_edges (B, B + global_scale*X2 ,Eigen::RowVector3d(0,0,1)); } if (key == '2') { // Bisector field viewer.set_mesh(V, F); viewer.add_edges (B, B + global_scale*BIS1 ,Eigen::RowVector3d(1,0,0)); viewer.add_edges (B, B + global_scale*BIS2 ,Eigen::RowVector3d(0,0,1)); } if (key == '3') { // Bisector field combed viewer.set_mesh(V, F); viewer.add_edges (B, B + global_scale*BIS1_combed ,Eigen::RowVector3d(1,0,0)); viewer.add_edges (B, B + global_scale*BIS2_combed ,Eigen::RowVector3d(0,0,1)); } if (key == '4') { // Singularities and cuts viewer.set_mesh(V, F); // Plot cuts int l_count = Seams.sum(); Eigen::MatrixXd P1(l_count,3); Eigen::MatrixXd P2(l_count,3); for (unsigned i=0; i 0) viewer.add_points(V.row(i),Eigen::RowVector3d(1,0,0)); else if (singularityIndex(i) > 2) viewer.add_points(V.row(i),Eigen::RowVector3d(0,1,0)); } } if (key == '5') { // Singularities and cuts, original field // Singularities and cuts viewer.set_mesh(V, F); viewer.add_edges (B, B + global_scale*X1_combed ,Eigen::RowVector3d(1,0,0)); viewer.add_edges (B, B + global_scale*X2_combed ,Eigen::RowVector3d(0,0,1)); // Plot cuts int l_count = Seams.sum(); Eigen::MatrixXd P1(l_count,3); Eigen::MatrixXd P2(l_count,3); for (unsigned i=0; i 0) viewer.add_points(V.row(i),Eigen::RowVector3d(1,0,0)); else if (singularityIndex(i) > 2) viewer.add_points(V.row(i),Eigen::RowVector3d(0,1,0)); } } if (key == '6') { // Global parametrization UV viewer.set_mesh(UV, FUV); viewer.set_uv(UV); viewer.options.show_lines = true; } if (key == '7') { // Global parametrization in 3D viewer.set_mesh(V, F); viewer.set_uv(UV,FUV); viewer.options.show_texture = true; } if (key == '8') { // Global parametrization in 3D with seams viewer.set_mesh(V, F); viewer.set_uv(UV_seams,FUV_seams); viewer.options.show_texture = true; } viewer.set_colors(Eigen::RowVector3d(1,1,1)); // Replace the standard texture with an integer shift invariant texture Eigen::Matrix texture_R, texture_G, texture_B; line_texture(texture_R, texture_G, texture_B); viewer.set_texture(texture_R, texture_B, texture_G); return false; } int main(int argc, char *argv[]) { using namespace Eigen; // Load a mesh in OFF format igl::readOFF("../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 VectorXi b(1); b << 0; MatrixXd bc(1,3); bc << 1, 0, 0; // Create a smooth 4-RoSy field VectorXd S; igl::nrosy(V,F,b,bc,VectorXi(),VectorXd(),MatrixXd(),4,0.5,X1,S); // Find the the orthogonal vector MatrixXd B1,B2,B3; igl::local_basis(V,F,B1,B2,B3); X2 = igl::rotate_vectors(X1, VectorXd::Constant(1,M_PI/2), B1, B2); double gradient_size = 50; double iter = 0; double stiffness = 5.0; bool direct_round = 0; // Always work on the bisectors, it is more general igl::compute_frame_field_bisectors(V, F, X1, X2, BIS1, BIS2); // Comb the field, implicitly defining the seams igl::comb_cross_field(V, F, BIS1, BIS2, BIS1_combed, BIS2_combed); // Find the integer mismatches igl::cross_field_missmatch(V, F, BIS1_combed, BIS2_combed, true, MMatch); // Find the singularities igl::find_cross_field_singularities(V, F, MMatch, isSingularity, singularityIndex); // Cut the mes, duplicating all vertices on the seams igl::cut_mesh_from_singularities(V, F, MMatch, isSingularity, singularityIndex, Seams); // Comb the cross-field accordingly igl::comb_frame_field(V, F, X1, X2, BIS1_combed, BIS2_combed, X1_combed, X2_combed); // Global parametrization igl::miq(V, F, X1_combed, X2_combed, BIS1_combed, BIS2_combed, MMatch, isSingularity, singularityIndex, Seams, UV, FUV, gradient_size, stiffness, direct_round, iter, 5, true); // Global parametrization (with seams, only for demonstration) igl::miq(V, F, X1_combed, X2_combed, BIS1_combed, BIS2_combed, MMatch, isSingularity, singularityIndex, Seams, UV_seams, FUV_seams, gradient_size, stiffness, direct_round, iter, 5, false); // Plot the mesh igl::Viewer viewer; // Plot the original mesh with a texture parametrization key_down(viewer,'7',0); // Launch the viewer viewer.callback_key_down = &key_down; viewer.launch(); }