import pybindmagic #%% %%cpp -f hello_world void hello_world() { py::print("Hello World..."); } #%% hello_world() #%% %%cpp -f callothercell -f callthiscell void hello_world(); void callthiscell() { py::print("In this cell"); } void callothercell() { py::print("From Other Cell:"); hello_world(); } #%% callthiscell() callothercell() #try to update the first cell an run callothercell() again #%% %%cpp -f transitiv void callothercell(); void transitiv() { py::print("Cell A:"); callothercell(); } #%% transitiv() #%% %%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); } #%% import JV9NK 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)