运行代码遇到的问题
#include <igl/readOBJ.h>
#include <igl/opengl/glfw/Viewer.h>
#include <igl/exact_geodesic.h>
#include <igl/unproject_onto_mesh.h>
#include <igl/png/readPNG.h>
#include <iostream>
// distance field algorithm
#include "stdafx.h"
#include "geodesic_mesh.h"
#include "geodesic_algorithm_exact.h"
//#include "geodesic_mesh_elements.h"
//#include "appls.h"
//#include "geodesic_algorithm_base.h"
//#include "geodesic_algorithm_exact_elements.h"
//#include "geodesic_constants_and_simple_functions.h"
//#include "geodesic_memory.h"
#include "tutorial_shared_path.h"
extern "C"
int main(int argc, char *argv[])
{
using namespace Eigen;
//using namespace std;
Eigen::MatrixXd V;
Eigen::MatrixXi F;
igl::opengl::glfw::Viewer viewer;
// Load a mesh in OFF format
igl::readOBJ(TUTORIAL_SHARED_PATH "/armadillo.obj", V, F);
char file_name[] = TUTORIAL_SHARED_PATH "/armadillo.obj";
const auto update_distance = [&](const int vid)
{
std::vector<double> points;
std::vector<unsigned> faces;
std::vector<int> realIndex;
int originalVertNum = 0;
bool success = geodesic::read_mesh_from_file(file_name, points, faces, realIndex, originalVertNum);
if (!success)
{
std::cout << "something is wrong with the input file" << std::endl;
return -2;
}
int source_vertex_index = vid;
/*Eigen::VectorXi VS,FS,VT,FT;
// The selected vertex is the source
VS.resize(1);
VS << vid;
// All vertices are the targets
VT.setLinSpaced(V.rows(),0,V.rows()-1);
Eigen::VectorXd d;*/
std::cout << "Computing geodesic distance to vertex " << vid << "..." << std::endl;
// Build Mesh
geodesic::Mesh mesh;
mesh.initialize_mesh_data(points, faces); //create internal mesh data structure including edges
geodesic::GeodesicAlgorithmExact algorithm(&mesh);
// Propagation
algorithm.propagate(source_vertex_index); //cover the whole mesh
// Output Geodesic Distances
Eigen::VectorXd d(mesh.vertices().size());
for (unsigned i = 0; i < mesh.vertices().size(); ++i)
{
double distance = mesh.vertices()[i].geodesic_distance();
d[i] = distance;
}
// Allocate temporary buffers
Eigen::Matrix<unsigned char, Eigen::Dynamic, Eigen::Dynamic> R, G, B, A;
// Read the PNG
igl::png::readPNG(TUTORIAL_SHARED_PATH "/colour.png", R, G, B, A);
// Plot the mesh
viewer.data().clear();
viewer.data().set_mesh(V, F);
viewer.core().align_camera_center(V);
viewer.data().show_texture = true;
// Use the image as a texture
viewer.data().set_texture(R, G, B);
// Set the distances
viewer.data().set_data(d);
};
// Plot a distance when a vertex is picked
viewer.callback_mouse_down =
[&](igl::opengl::glfw::Viewer& viewer, int, int)->bool
{
int fid;
Eigen::Vector3f bc;
// Cast a ray in the view direction starting from the mouse position
double x = viewer.current_mouse_x;
double y = viewer.core().viewport(3) - viewer.current_mouse_y;
if(igl::unproject_onto_mesh(
Eigen::Vector2f(x,y),
viewer.core().view,
viewer.core().proj,
viewer.core().viewport,
V,
F,
fid,
bc))
{
int max;
bc.maxCoeff(&max);
int vid = F(fid,max);
update_distance(vid);
return true;
}
return false;
};
viewer.data().set_mesh(V,F);
viewer.data().show_lines = false;
std::cout << "Click on mesh to define new source.\n" << std::endl;
update_distance(0);
return viewer.launch();
}
更换不同的图片,结果是一样的
正常运行