Files
igl/tutorial/204_Gradient/main.cpp
T
b0fd49d598 CMake refactor (#1805)
* Start CMake refactoring.

* WIP on instlal().

* Handle install + hunter setup.

* Handle module options + igl_include helper.

* Build all tutorials again.

* Update CMake for unit tests.

* Update triangle lib.

* Update Hunter integration.

* Fix for header-only mode.

* Fix Windows compilation + add GMP/MPFR find_package + set VS folders.

* Fix CGAL build.

* Add copy dll for Windows + improve find gmp/mpfr.

* Update Github Actions.

* Update README.

* Fixes for CMake 3.18

* Fix include option.

* Rename libigl_imgui_front to avoid conflicts.

* Fix when disabling unit tests.

* Build imguizmo with C++11.

* Update CMake option comments.

* Rename nonfree -> restricted.

* Update triangle and tetgen versions.

* Fix compilation issue.

* Update continuous.yml

* remove cork

* finding matlab with default

* mosek module compiles; default detected; osx dylib hack

* Reduce build parallelism.

* Fix find GMP/MPFR on Windows + cleanup CGAL changes.

* Update readme.

Co-authored-by: Alec Jacobson <alecjacobson@adobe.com>
Co-authored-by: Alec Jacobson <alecjacobson@gmail.com>
2022-02-09 18:58:40 -08:00

52 lines
1.4 KiB
C++
Executable File

#include <igl/avg_edge_length.h>
#include <igl/barycenter.h>
#include <igl/grad.h>
#include <igl/jet.h>
#include <igl/readDMAT.h>
#include <igl/readOFF.h>
#include <igl/opengl/glfw/Viewer.h>
#include <iostream>
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();
}