import pybindmagic import os os.environ["PATH"] = "/home/ugo/anaconda3/bin" + os.pathsep + os.environ["PATH"] #%% %%cpp -f generateMesh #include std::tuple generateMesh() { // Inline mesh of a cube const Eigen::MatrixXd V = (Eigen::MatrixXd(8,3)<< 0.0,0.0,0.0, 0.0,0.0,1.0, 0.0,1.0,0.0, 0.0,1.0,1.0, 1.0,0.0,0.0, 1.0,0.0,1.0, 1.0,1.0,0.0, 1.0,1.0,1.0).finished(); const Eigen::MatrixXi F = (Eigen::MatrixXi(12,3)<< 1,7,5, 1,3,7, 1,4,3, 1,2,4, 3,8,7, 3,4,8, 5,7,8, 5,8,6, 1,5,6, 1,6,2, 2,6,8, 2,8,4).finished().array()-1; return std::make_tuple(V,F); } #%% V,F = generateMesh() print("Vertices:\n",V) print("Faces:\n",F) #%% %%cpp #include std::tuple generateMesh() { // Inline mesh of a cube const Eigen::MatrixXd V = (Eigen::MatrixXd(8,3)<< 0.0,0.0,0.0, 0.0,0.0,1.0, 0.0,1.0,0.0, 0.0,1.0,1.0, 1.0,0.0,0.0, 1.0,0.0,1.0, 1.0,1.0,0.0, 1.0,1.0,1.0).finished(); const Eigen::MatrixXi F = (Eigen::MatrixXi(12,3)<< 1,7,5, 1,3,7, 1,4,3, 1,2,4, 3,8,7, 3,4,8, 5,7,8, 5,8,6, 1,5,6, 1,6,2, 2,6,8, 2,8,4).finished().array()-1; return std::make_tuple(V,F); } void printMesh(Eigen::MatrixXd V,Eigen::MatrixXi F) { py::print("Vertices:\n", V); py::print("Faces:\n", F); } defs m.def("generateMesh",&generateMesh); m.def("printMesh",&printMesh); #%% printMesh(*generateMesh()) #%% %%cpp -c pathtocmake -f viewMesh #include #include void viewMesh(Eigen::Matrix V, Eigen::Matrix F) { // Plot the mesh igl::opengl::glfw::Viewer viewer; viewer.data().set_mesh(V, F); viewer.data().set_face_based(true); viewer.launch(); } #%% import numpy as np V = np.array([ [0.0,0.0,0.0], [0.0,0.0,1.0], [0.0,1.0,0.0], [0.0,1.0,1.0], [1.0,0.0,0.0], [1.0,0.0,1.0], [1.0,1.0,0.0], [1.0,1.0,1.0]]) F = np.array( [ [1,7,5], [1,3,7], [1,4,3], [1,2,4], [3,8,7], [3,4,8], [5,7,8], [5,8,6], [1,5,6], [1,6,2], [2,6,8], [2,8,4] ], dtype=np.int32)-1 viewMesh(V,F)