You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
132 lines
2.3 KiB
132 lines
2.3 KiB
import pybindmagic
|
|
import os
|
|
os.environ["PATH"] = "/home/ugo/anaconda3/bin" + os.pathsep + os.environ["PATH"]
|
|
|
|
#%%
|
|
%%cpp -f generateMesh
|
|
#include <pybind11/eigen.h>
|
|
std::tuple<Eigen::MatrixXd,Eigen::MatrixXi> 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 <pybind11/eigen.h>
|
|
|
|
|
|
std::tuple<Eigen::MatrixXd,Eigen::MatrixXi> 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 <igl/opengl/glfw/Viewer.h>
|
|
#include <pybind11/eigen.h>
|
|
|
|
|
|
void viewMesh(Eigen::Matrix<double, Eigen::Dynamic, 3> V, Eigen::Matrix<int, Eigen::Dynamic, 3> 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)
|
|
|