Download vendor/libigl/tutorial/204_Gradient/main.cpp from AVSim/simulation-package: direct link, hf CLI and curl.
- Browser
- Download file 1.39 kB
-
https://huggingface.co/datasets/AVSim/simulation-package/resolve/main/vendor/libigl/tutorial/204_Gradient/main.cpp
- Command line
-
hf download hf://datasets/AVSim/simulation-package/vendor/libigl/tutorial/204_Gradient/main.cpp
-
curl -L -o main.cpp https://huggingface.co/datasets/AVSim/simulation-package/resolve/main/vendor/libigl/tutorial/204_Gradient/main.cpp
1.39 kB
| int main(int argc, char *argv[]) | |
| { | |
| using namespace Eigen; | |
| using namespace std; | |
| MatrixXd V; | |
| MatrixXi F; | |
| // Load a mesh in OFF format | |
| igl::readOFF(TUTORIAL_SHARED_PATH "/cheburashka.off", V, F); | |
| // Read scalar function values from a file, U: #V by 1 | |
| VectorXd U; | |
| igl::readDMAT(TUTORIAL_SHARED_PATH "/cheburashka-scalar.dmat",U); | |
| // Compute gradient operator: #F*3 by #V | |
| SparseMatrix<double> G; | |
| igl::grad(V,F,G); | |
| // Compute gradient of U | |
| MatrixXd GU = Map<const MatrixXd>((G*U).eval().data(),F.rows(),3); | |
| // Compute gradient magnitude | |
| const VectorXd GU_mag = GU.rowwise().norm(); | |
| igl::opengl::glfw::Viewer viewer; | |
| viewer.data().set_mesh(V, F); | |
| viewer.data().set_data(U); | |
| // Average edge length divided by average gradient (for scaling) | |
| const double max_size = igl::avg_edge_length(V,F) / GU_mag.mean(); | |
| // Draw a black segment in direction of gradient at face barycenters | |
| MatrixXd BC; | |
| igl::barycenter(V,F,BC); | |
| const RowVector3d black(0,0,0); | |
| viewer.data().add_edges(BC,BC+max_size*GU, black); | |
| // Hide wireframe | |
| viewer.data().show_lines = false; | |
| viewer.launch(); | |
| } | |