From a6ee5ddc4c3847a66cf98093227eccc030c375c6 Mon Sep 17 00:00:00 2001 From: Alec Jacobson Date: Wed, 31 Jan 2018 13:30:52 -0500 Subject: [PATCH 01/20] formatting Former-commit-id: 99c878a48bb879a05ede8787f1b8e7b254b9d4de --- include/igl/slice_cached.h | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/include/igl/slice_cached.h b/include/igl/slice_cached.h index f6fb9020d..98ff9c40a 100644 --- a/include/igl/slice_cached.h +++ b/include/igl/slice_cached.h @@ -14,9 +14,11 @@ namespace igl { - // Act like the matlab X(row_indices,col_indices) operator, where - // row_indices, col_indices are non-negative integer indices. This is a fast version - // of igl::slice that can analyze and store the sparsity structure. It is slower at the // first evaluation (slice_cached_precompute), but faster on the subsequent ones. + // Act like the matlab X(row_indices,col_indices) operator, where row_indices, + // col_indices are non-negative integer indices. This is a fast version of + // igl::slice that can analyze and store the sparsity structure. It is slower + // at the irst evaluation (slice_cached_precompute), but faster on the + // subsequent ones. // // Inputs: // X m by n matrix From 134a7bb8bad7df0d3d38c1f23b67ffdbde62de73 Mon Sep 17 00:00:00 2001 From: Alec Jacobson Date: Thu, 8 Feb 2018 10:40:53 -0500 Subject: [PATCH 02/20] Fix CMake that was overwriting desired options when not found Former-commit-id: 321343d402a590c855040ed89469025155484981 --- shared/cmake/libigl.cmake | 70 +++++++++++++++++++-------------------- 1 file changed, 35 insertions(+), 35 deletions(-) diff --git a/shared/cmake/libigl.cmake b/shared/cmake/libigl.cmake index 718e78a44..f2e5c0cae 100644 --- a/shared/cmake/libigl.cmake +++ b/shared/cmake/libigl.cmake @@ -1,22 +1,34 @@ cmake_minimum_required(VERSION 3.1) +### Find packages to populate default options ### +# +# COMPONENTS should match subsequent calls +find_package(CGAL COMPONENTS Core) # --> CGAL_FOUND +find_package(Boost 1.48 COMPONENTS thread system) # --> BOOST_FOUND +if(CGAL_FOUND AND BOOST_FOUND) + set(CGAL_AND_BOOST_FOUND TRUE) +endif() +find_package(Matlab COMPONENTS MEX_COMPILER MX_LIBRARY ENG_LIBRARY) # --> Matlab_FOUND +find_package(MOSEK) # --> MOSEK_FOUND +find_package(OpenGL) # --> OPENGL_FOUND + ### Available options ### option(LIBIGL_USE_STATIC_LIBRARY "Use libigl as static library" OFF) option(LIBIGL_WITH_ANTTWEAKBAR "Use AntTweakBar" OFF) -option(LIBIGL_WITH_CGAL "Use CGAL" ON) +option(LIBIGL_WITH_CGAL "Use CGAL" "${CGAL_AND_BOOST_FOUND}") option(LIBIGL_WITH_COMISO "Use CoMiso" ON) option(LIBIGL_WITH_CORK "Use Cork" OFF) option(LIBIGL_WITH_EMBREE "Use Embree" OFF) option(LIBIGL_WITH_LIM "Use LIM" ON) -option(LIBIGL_WITH_MATLAB "Use Matlab" ON) -option(LIBIGL_WITH_MOSEK "Use MOSEK" ON) +option(LIBIGL_WITH_MATLAB "Use Matlab" "${Matlab_FOUND}") +option(LIBIGL_WITH_MOSEK "Use MOSEK" "${MOSEK_FOUND}") option(LIBIGL_WITH_NANOGUI "Use Nanogui menu" OFF) -option(LIBIGL_WITH_OPENGL "Use OpenGL" ON) -option(LIBIGL_WITH_OPENGL_GLFW "Use GLFW" ON) +option(LIBIGL_WITH_OPENGL "Use OpenGL" "${OPENGL_FOUND}") +option(LIBIGL_WITH_OPENGL_GLFW "Use GLFW" "${OPENGL_FOUND}") option(LIBIGL_WITH_PNG "Use PNG" ON) option(LIBIGL_WITH_TETGEN "Use Tetgen" ON) option(LIBIGL_WITH_TRIANGLE "Use Triangle" ON) -option(LIBIGL_WITH_VIEWER "Use OpenGL viewer" ON) +option(LIBIGL_WITH_VIEWER "Use OpenGL viewer" "${OPENGL_FOUND}") option(LIBIGL_WITH_XML "Use XML" ON) option(LIBIGL_WITH_PYTHON "Use Python" OFF) @@ -136,19 +148,15 @@ endif() if(LIBIGL_WITH_CGAL) # CGAL Core is needed for # `Exact_predicates_exact_constructions_kernel_with_sqrt` - find_package(CGAL COMPONENTS Core) - if(CGAL_FOUND) - compile_igl_module("cgal") - if(WIN32) - set(Boost_USE_STATIC_LIBS ON) # Favor static Boost libs on Windows - endif() - target_include_directories(igl_cgal ${IGL_SCOPE} "${GMP_INCLUDE_DIR}" "${MPFR_INCLUDE_DIR}") - find_package(Boost 1.48 REQUIRED thread system) - target_include_directories(igl_cgal ${IGL_SCOPE} ${CGAL_INCLUDE_DIRS} ${Boost_INCLUDE_DIRS}) - target_link_libraries(igl_cgal ${IGL_SCOPE} CGAL::CGAL CGAL::CGAL_Core ${Boost_LIBRARIES}) - else() - set(LIBIGL_WITH_CGAL OFF CACHE BOOL "" FORCE) + find_package(CGAL REQUIRED COMPONENTS Core) + compile_igl_module("cgal") + if(WIN32) + set(Boost_USE_STATIC_LIBS ON) # Favor static Boost libs on Windows endif() + target_include_directories(igl_cgal ${IGL_SCOPE} "${GMP_INCLUDE_DIR}" "${MPFR_INCLUDE_DIR}") + find_package(Boost 1.48 REQUIRED thread system) + target_include_directories(igl_cgal ${IGL_SCOPE} ${CGAL_INCLUDE_DIRS} ${Boost_INCLUDE_DIRS}) + target_link_libraries(igl_cgal ${IGL_SCOPE} CGAL::CGAL CGAL::CGAL_Core ${Boost_LIBRARIES}) endif() # Helper function for `igl_copy_cgal_dll()` @@ -249,28 +257,20 @@ endif() ################################################################################ ### Compile the matlab part ### if(LIBIGL_WITH_MATLAB) - find_package(Matlab) - if(MATLAB_FOUND) - compile_igl_module("matlab") - target_link_libraries(igl_matlab ${IGL_SCOPE} ${MATLAB_LIBRARIES}) - target_include_directories(igl_matlab ${IGL_SCOPE} ${MATLAB_INCLUDE_DIR}) - else() - set(LIBIGL_WITH_MATLAB OFF CACHE BOOL "" FORCE) - endif() + find_package(Matlab REQUIRED COMPONENTS MEX_COMPILER MX_LIBRARY ENG_LIBRARY) + compile_igl_module("matlab") + target_link_libraries(igl_matlab ${IGL_SCOPE} ${MATLAB_LIBRARIES}) + target_include_directories(igl_matlab ${IGL_SCOPE} ${MATLAB_INCLUDE_DIR}) endif() ################################################################################ ### Compile the mosek part ### if(LIBIGL_WITH_MOSEK) - find_package(MOSEK) - if(MOSEK_FOUND) - compile_igl_module("mosek") - target_link_libraries(igl_mosek ${IGL_SCOPE} ${MOSEK_LIBRARIES}) - target_include_directories(igl_mosek ${IGL_SCOPE} ${MOSEK_INCLUDE_DIRS}) - target_compile_definitions(igl_mosek ${IGL_SCOPE} -DLIBIGL_WITH_MOSEK) - else() - set(LIBIGL_WITH_MOSEK OFF CACHE BOOL "" FORCE) - endif() + find_package(MOSEK REQUIRED) + compile_igl_module("mosek") + target_link_libraries(igl_mosek ${IGL_SCOPE} ${MOSEK_LIBRARIES}) + target_include_directories(igl_mosek ${IGL_SCOPE} ${MOSEK_INCLUDE_DIRS}) + target_compile_definitions(igl_mosek ${IGL_SCOPE} -DLIBIGL_WITH_MOSEK) endif() ################################################################################ From 3ec82bd5a48333a46e0dd94179bccdf3367d4c2f Mon Sep 17 00:00:00 2001 From: Guillaume Jacquenot Date: Sat, 10 Feb 2018 15:04:08 +0100 Subject: [PATCH 03/20] [curvature] Refactored file principal_curvature.cpp - Added const when possible - Replaced i++ with ++i - Removed using namespace std -> was not coherent with some std::* instructions Former-commit-id: fd40319975b279ac7119128d7511972f4b8cb273 --- include/igl/principal_curvature.cpp | 108 +++++++++++++--------------- 1 file changed, 49 insertions(+), 59 deletions(-) diff --git a/include/igl/principal_curvature.cpp b/include/igl/principal_curvature.cpp index 5054cccac..db8e98ddf 100644 --- a/include/igl/principal_curvature.cpp +++ b/include/igl/principal_curvature.cpp @@ -105,13 +105,12 @@ public: } - IGL_INLINE static Quadric fit(std::vector &VV, bool zeroDetCheck, bool svd) + IGL_INLINE static Quadric fit(const std::vector &VV, bool zeroDetCheck, bool svd) { - using namespace std; assert(VV.size() >= 5); if (VV.size() < 5) { - cerr << "ASSERT FAILED!" << endl; + std::cerr << "ASSERT FAILED!" << std::endl; exit(0); } @@ -179,18 +178,18 @@ public: IGL_INLINE CurvatureCalculator(); IGL_INLINE void init(const Eigen::MatrixXd& V, const Eigen::MatrixXi& F); - IGL_INLINE void finalEigenStuff (int, std::vector, Quadric ); - IGL_INLINE void fitQuadric (Eigen::Vector3d, std::vector ref, const std::vector& , Quadric *); - IGL_INLINE void applyProjOnPlane(Eigen::Vector3d, std::vector, std::vector&); + IGL_INLINE void finalEigenStuff(int, const std::vector&, Quadric&); + IGL_INLINE void fitQuadric(const Eigen::Vector3d&, const std::vector& ref, const std::vector& , Quadric *); + IGL_INLINE void applyProjOnPlane(const Eigen::Vector3d&, const std::vector&, std::vector&); IGL_INLINE void getSphere(const int, const double, std::vector&, int min); IGL_INLINE void getKRing(const int, const double,std::vector&); - IGL_INLINE Eigen::Vector3d project(Eigen::Vector3d, Eigen::Vector3d, Eigen::Vector3d); - IGL_INLINE void computeReferenceFrame(int, Eigen::Vector3d, std::vector&); - IGL_INLINE void getAverageNormal(int, std::vector, Eigen::Vector3d&); - IGL_INLINE void getProjPlane(int, std::vector, Eigen::Vector3d&); - IGL_INLINE void applyMontecarlo(std::vector&,std::vector*); + IGL_INLINE Eigen::Vector3d project(const Eigen::Vector3d&, const Eigen::Vector3d&, const Eigen::Vector3d&); + IGL_INLINE void computeReferenceFrame(int, const Eigen::Vector3d&, std::vector&); + IGL_INLINE void getAverageNormal(int, const std::vector&, Eigen::Vector3d&); + IGL_INLINE void getProjPlane(int, const std::vector&, Eigen::Vector3d&); + IGL_INLINE void applyMontecarlo(const std::vector&,std::vector*); IGL_INLINE void computeCurvature(); - IGL_INLINE void printCurvature(std::string outpath); + IGL_INLINE void printCurvature(const std::string& outpath); IGL_INLINE double getAverageEdge(); IGL_INLINE static int rotateForward (float *v0, float *v1, float *v2) @@ -225,7 +224,7 @@ public: IGL_INLINE static Eigen::Vector3d chooseMax (Eigen::Vector3d n, Eigen::Vector3d abc, float ab) { - int i, max_i; + int max_i; float max_sp; Eigen::Vector3d nt[8]; @@ -234,7 +233,7 @@ public: max_sp = - std::numeric_limits::max(); - for (i = 0; i < 4; i++) + for (int i = 0; i < 4; ++i) { nt[i] = n; if (ab > 0) @@ -290,7 +289,6 @@ public: max_i = i; } } - return nt[max_i]; } @@ -337,7 +335,7 @@ IGL_INLINE void CurvatureCalculator::init(const Eigen::MatrixXd& V, const Eigen: igl::per_vertex_normals(V, F, face_normals, vertex_normals); } -IGL_INLINE void CurvatureCalculator::fitQuadric (Eigen::Vector3d v, std::vector ref, const std::vector& vv, Quadric *q) +IGL_INLINE void CurvatureCalculator::fitQuadric(const Eigen::Vector3d& v, const std::vector& ref, const std::vector& vv, Quadric *q) { std::vector points; points.reserve (vv.size()); @@ -357,14 +355,14 @@ IGL_INLINE void CurvatureCalculator::fitQuadric (Eigen::Vector3d v, std::vector< *q = Quadric::fit (points, zeroDetCheck, svd); } -IGL_INLINE void CurvatureCalculator::finalEigenStuff (int i, std::vector ref, Quadric q) +IGL_INLINE void CurvatureCalculator::finalEigenStuff(int i, const std::vector& ref, Quadric& q) { - double a = q.a(); - double b = q.b(); - double c = q.c(); - double d = q.d(); - double e = q.e(); + const double a = q.a(); + const double b = q.b(); + const double c = q.c(); + const double d = q.d(); + const double e = q.e(); // if (fabs(a) < 10e-8 || fabs(b) < 10e-8) // { @@ -457,7 +455,7 @@ IGL_INLINE void CurvatureCalculator::getKRing(const int start, const double r, s vv.push_back(toVisit); if (distance<(int)r) { - for (unsigned int i=0; ifront(); queue->pop_front(); vv.push_back(toVisit); - for (unsigned int i=0; i cand=extra_candidates->top(); extra_candidates->pop(); vv.push_back(cand.first); - for (unsigned int i=0; i& ref ) +IGL_INLINE void CurvatureCalculator::computeReferenceFrame(int i, const Eigen::Vector3d& normal, std::vector& ref ) { - Eigen::Vector3d longest_v=Eigen::Vector3d::Zero(); - longest_v=Eigen::Vector3d(vertices.row(vertex_to_vertices[i][0])); + Eigen::Vector3d longest_v=Eigen::Vector3d(vertices.row(vertex_to_vertices[i][0])); longest_v=(project(vertices.row(i),longest_v,normal)-Eigen::Vector3d(vertices.row(i))).normalized(); @@ -546,20 +543,20 @@ IGL_INLINE void CurvatureCalculator::computeReferenceFrame(int i, Eigen::Vector3 ref[2]=normal; } -IGL_INLINE void CurvatureCalculator::getAverageNormal(int j, std::vector vv, Eigen::Vector3d& normal) +IGL_INLINE void CurvatureCalculator::getAverageNormal(int j, const std::vector& vv, Eigen::Vector3d& normal) { normal=(vertex_normals.row(j)).normalized(); if (localMode) return; - for (unsigned int i=0; i vv, Eigen::Vector3d& ppn) +IGL_INLINE void CurvatureCalculator::getProjPlane(int j, const std::vector& vv, Eigen::Vector3d& ppn) { int nr; float a, b, c; @@ -605,9 +602,9 @@ IGL_INLINE double CurvatureCalculator::getAverageEdge() double sum = 0; int count = 0; - for (int i = 0; i vin, std::vector &vout) +IGL_INLINE void CurvatureCalculator::applyProjOnPlane(const Eigen::Vector3d& ppn, const std::vector& vin, std::vector &vout) { - for (std::vector::iterator vpi = vin.begin(); vpi != vin.end(); ++vpi) + for (std::vector::const_iterator vpi = vin.begin(); vpi != vin.end(); ++vpi) if (vertex_normals.row(*vpi) * ppn > 0.0f) - vout.push_back (*vpi); + vout.push_back(*vpi); } -IGL_INLINE void CurvatureCalculator::applyMontecarlo(std::vector& vin, std::vector *vout) +IGL_INLINE void CurvatureCalculator::applyMontecarlo(const std::vector& vin, std::vector *vout) { if (montecarloN >= vin.size ()) { @@ -639,24 +636,22 @@ IGL_INLINE void CurvatureCalculator::applyMontecarlo(std::vector& vin, std: } float p = ((float) montecarloN) / (float) vin.size(); - for (std::vector::iterator vpi = vin.begin(); vpi != vin.end(); ++vpi) + for (std::vector::const_iterator vpi = vin.begin(); vpi != vin.end(); ++vpi) { float r; if ((r = ((float)rand () / RAND_MAX)) < p) { - vout->push_back (*vpi); + vout->push_back(*vpi); } } } IGL_INLINE void CurvatureCalculator::computeCurvature() { - using namespace std; - //CHECK che esista la mesh - size_t vertices_count=vertices.rows() ; + const size_t vertices_count=vertices.rows(); - if (vertices_count <=0) + if (vertices_count ==0) return; curvDir=std::vector< std::vector >(vertices_count); @@ -691,10 +686,9 @@ IGL_INLINE void CurvatureCalculator::computeCurvature() return; } - std::vector ref(3); if (vv.size()<6) { - std::cerr << "Could not compute curvature of radius " << scaledRadius << endl; + std::cerr << "Could not compute curvature of radius " << scaledRadius << std::endl; return; } @@ -704,8 +698,7 @@ IGL_INLINE void CurvatureCalculator::computeCurvature() vvtmp.reserve (vv.size ()); applyProjOnPlane (vertex_normals.row(i), vv, vvtmp); if (vvtmp.size() >= 6 && vvtmp.size() ref(3); computeReferenceFrame(i,normal,ref); Quadric q; @@ -748,7 +742,7 @@ IGL_INLINE void CurvatureCalculator::computeCurvature() curvatureComputed=true; } -IGL_INLINE void CurvatureCalculator::printCurvature(std::string outpath) +IGL_INLINE void CurvatureCalculator::printCurvature(const std::string& outpath) { using namespace std; if (!curvatureComputed) @@ -765,7 +759,7 @@ IGL_INLINE void CurvatureCalculator::printCurvature(std::string outpath) int vertices_count=vertices.rows(); of << vertices_count << endl; - for (int i=0; i= 2, fixing it to 2." << endl; + std::cout << "WARNING: igl::principal_curvature needs a radius >= 2, fixing it to 2." << std::endl; } // Preallocate memory @@ -823,10 +815,8 @@ IGL_INLINE void igl::principal_curvature( cc.computeCurvature(); // Copy it back - for (unsigned i=0; i 10e-6) { - cerr << "PRINCIPAL_CURVATURE: Something is wrong with vertex: i" << endl; + std::cerr << "PRINCIPAL_CURVATURE: Something is wrong with vertex: i" << std::endl; PD1.row(i) *= 0; PD2.row(i) *= 0; } @@ -857,4 +847,4 @@ IGL_INLINE void igl::principal_curvature( template void igl::principal_curvature, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix >(Eigen::PlainObjectBase > const&, Eigen::PlainObjectBase > const&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, unsigned int, bool); template void igl::principal_curvature, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix >(Eigen::PlainObjectBase > const&, Eigen::PlainObjectBase > const&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, unsigned int, bool); template void igl::principal_curvature, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix >(Eigen::PlainObjectBase > const&, Eigen::PlainObjectBase > const&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, unsigned int, bool); -#endif +#endif \ No newline at end of file From 4b29c38ed3a4be0f2d417ec1140534a8c8cbcb1f Mon Sep 17 00:00:00 2001 From: Guillaume Jacquenot Date: Sat, 10 Feb 2018 15:12:14 +0100 Subject: [PATCH 04/20] [curvature] Replaced float declarations with double For example, we store norm of Vector3d inside a float. Code is updated to have a coherent floating point handling. The only float that remain are located in applyMontecarlo method, where we use float rand points Former-commit-id: add918886124902062a982ba1510d5209852626d --- include/igl/principal_curvature.cpp | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/include/igl/principal_curvature.cpp b/include/igl/principal_curvature.cpp index db8e98ddf..b98b77752 100644 --- a/include/igl/principal_curvature.cpp +++ b/include/igl/principal_curvature.cpp @@ -192,9 +192,9 @@ public: IGL_INLINE void printCurvature(const std::string& outpath); IGL_INLINE double getAverageEdge(); - IGL_INLINE static int rotateForward (float *v0, float *v1, float *v2) + IGL_INLINE static int rotateForward (double *v0, double *v1, double *v2) { - float t; + double t; if (std::abs(*v2) >= std::abs(*v1) && std::abs(*v2) >= std::abs(*v0)) return 0; @@ -207,9 +207,9 @@ public: return 1 + rotateForward (v0, v1, v2); } - IGL_INLINE static void rotateBackward (int nr, float *v0, float *v1, float *v2) + IGL_INLINE static void rotateBackward (int nr, double *v0, double *v1, double *v2) { - float t; + double t; if (nr == 0) return; @@ -222,16 +222,16 @@ public: rotateBackward (nr - 1, v0, v1, v2); } - IGL_INLINE static Eigen::Vector3d chooseMax (Eigen::Vector3d n, Eigen::Vector3d abc, float ab) + IGL_INLINE static Eigen::Vector3d chooseMax (Eigen::Vector3d n, Eigen::Vector3d abc, double ab) { int max_i; - float max_sp; + double max_sp; Eigen::Vector3d nt[8]; n.normalize (); abc.normalize (); - max_sp = - std::numeric_limits::max(); + max_sp = - std::numeric_limits::max(); for (int i = 0; i < 4; ++i) { @@ -492,7 +492,7 @@ IGL_INLINE void CurvatureCalculator::getSphere(const int start, const double r, if (!visited[neighbor]) { Eigen::Vector3d neigh=vertices.row(neighbor); - float distance=(me-neigh).norm(); + double distance=(me-neigh).norm(); if (distancepush_back(neighbor); else if ((int)vv.size()push(std::pair(neighbor,distance)); visited[neighbor]=true; } @@ -559,9 +559,9 @@ IGL_INLINE void CurvatureCalculator::getAverageNormal(int j, const std::vector& vv, Eigen::Vector3d& ppn) { int nr; - float a, b, c; - float nx, ny, nz; - float abcq; + double a, b, c; + double nx, ny, nz; + double abcq; a = b = c = 0; From 7a569a7b9cc2f9eff9cacc0293605b15aff6c6b9 Mon Sep 17 00:00:00 2001 From: Guillaume Jacquenot Date: Sat, 10 Feb 2018 15:20:55 +0100 Subject: [PATCH 05/20] [curvature] Updated inequality comparison between a double and a float Former-commit-id: fe511f8b6d3126004aadb6b1399be2bbc97ce93c --- include/igl/principal_curvature.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/igl/principal_curvature.cpp b/include/igl/principal_curvature.cpp index b98b77752..b75bdcf3a 100644 --- a/include/igl/principal_curvature.cpp +++ b/include/igl/principal_curvature.cpp @@ -623,7 +623,7 @@ IGL_INLINE double CurvatureCalculator::getAverageEdge() IGL_INLINE void CurvatureCalculator::applyProjOnPlane(const Eigen::Vector3d& ppn, const std::vector& vin, std::vector &vout) { for (std::vector::const_iterator vpi = vin.begin(); vpi != vin.end(); ++vpi) - if (vertex_normals.row(*vpi) * ppn > 0.0f) + if (vertex_normals.row(*vpi) * ppn > 0.0) vout.push_back(*vpi); } From bf527884da03eb5a98509c9c0e4beee22da6f391 Mon Sep 17 00:00:00 2001 From: Guillaume Jacquenot Date: Sat, 10 Feb 2018 16:06:00 +0100 Subject: [PATCH 06/20] [curvature] Updated assert message Former-commit-id: a91e1fe32a2dfb2e7c2aaa88b78b198123658d6b --- include/igl/principal_curvature.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/igl/principal_curvature.cpp b/include/igl/principal_curvature.cpp index b75bdcf3a..d770f4498 100644 --- a/include/igl/principal_curvature.cpp +++ b/include/igl/principal_curvature.cpp @@ -110,7 +110,7 @@ public: assert(VV.size() >= 5); if (VV.size() < 5) { - std::cerr << "ASSERT FAILED!" << std::endl; + std::cerr << "ASSERT FAILED! fit function requires at least 5 points: Only " << VV.size() << " were given." << std::endl; exit(0); } From 47d0ea14bd4a6b17fddf0a8a579be1b36a7aaa93 Mon Sep 17 00:00:00 2001 From: Guillaume Jacquenot Date: Sat, 10 Feb 2018 16:10:56 +0100 Subject: [PATCH 07/20] [curvature] Removed unused parameter svd Former-commit-id: 4a5e3b4c6405daf230708a99f3cb5bfcfdf17f52 --- include/igl/principal_curvature.cpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/include/igl/principal_curvature.cpp b/include/igl/principal_curvature.cpp index d770f4498..2f1cbe434 100644 --- a/include/igl/principal_curvature.cpp +++ b/include/igl/principal_curvature.cpp @@ -105,7 +105,7 @@ public: } - IGL_INLINE static Quadric fit(const std::vector &VV, bool zeroDetCheck, bool svd) + IGL_INLINE static Quadric fit(const std::vector &VV, bool zeroDetCheck) { assert(VV.size() >= 5); if (VV.size() < 5) @@ -159,7 +159,6 @@ public: bool localMode; /* Use local mode */ bool projectionPlaneCheck; /* Check collected vertices on tangent plane */ bool montecarlo; - bool svd; /* Use svd calculation instead of pseudoinverse */ bool zeroDetCheck; /* Check if the determinant is close to zero */ unsigned int montecarloN; @@ -313,7 +312,6 @@ IGL_INLINE CurvatureCalculator::CurvatureCalculator() this->montecarlo=false; this->montecarloN=0; this->kRing=3; - this->svd=true; this->zeroDetCheck=true; this->curvatureComputed=false; this->expStep=true; @@ -352,7 +350,7 @@ IGL_INLINE void CurvatureCalculator::fitQuadric(const Eigen::Vector3d& v, const double z = vTang.dot(ref[2]); points.push_back(Eigen::Vector3d (x,y,z)); } - *q = Quadric::fit (points, zeroDetCheck, svd); + *q = Quadric::fit (points, zeroDetCheck); } IGL_INLINE void CurvatureCalculator::finalEigenStuff(int i, const std::vector& ref, Quadric& q) From a07c4659fcd5b6f2d4b268d6c820a1a5d9387785 Mon Sep 17 00:00:00 2001 From: Guillaume Jacquenot Date: Sat, 10 Feb 2018 16:12:01 +0100 Subject: [PATCH 08/20] [curvature] Removed unused parameter zeroDetCheck Former-commit-id: 3099099321231de8d31d2e15f7272f860b5a153d --- include/igl/principal_curvature.cpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/include/igl/principal_curvature.cpp b/include/igl/principal_curvature.cpp index 2f1cbe434..f26928741 100644 --- a/include/igl/principal_curvature.cpp +++ b/include/igl/principal_curvature.cpp @@ -105,7 +105,7 @@ public: } - IGL_INLINE static Quadric fit(const std::vector &VV, bool zeroDetCheck) + IGL_INLINE static Quadric fit(const std::vector &VV) { assert(VV.size() >= 5); if (VV.size() < 5) @@ -159,7 +159,6 @@ public: bool localMode; /* Use local mode */ bool projectionPlaneCheck; /* Check collected vertices on tangent plane */ bool montecarlo; - bool zeroDetCheck; /* Check if the determinant is close to zero */ unsigned int montecarloN; searchType st; /* Use either a sphere search or a k-ring search */ @@ -312,7 +311,6 @@ IGL_INLINE CurvatureCalculator::CurvatureCalculator() this->montecarlo=false; this->montecarloN=0; this->kRing=3; - this->zeroDetCheck=true; this->curvatureComputed=false; this->expStep=true; } @@ -350,7 +348,7 @@ IGL_INLINE void CurvatureCalculator::fitQuadric(const Eigen::Vector3d& v, const double z = vTang.dot(ref[2]); points.push_back(Eigen::Vector3d (x,y,z)); } - *q = Quadric::fit (points, zeroDetCheck); + *q = Quadric::fit (points); } IGL_INLINE void CurvatureCalculator::finalEigenStuff(int i, const std::vector& ref, Quadric& q) From 938dc618249ebc3010ad93cfd61c73335a574853 Mon Sep 17 00:00:00 2001 From: Guillaume Jacquenot Date: Sat, 10 Feb 2018 16:19:44 +0100 Subject: [PATCH 09/20] [curvature] Added a test before calling fit to avoid exit instruction For the time being, the code exits if data is not valid. exit instruction in fit function is not desirable when using principal_curvature in a program. Ideally, one should raise an exception. If data is not valid, we return a default Quadric object Former-commit-id: 78cc9effc3d19a791c0e751bff0894e84aeb4c61 --- include/igl/principal_curvature.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/include/igl/principal_curvature.cpp b/include/igl/principal_curvature.cpp index f26928741..41c4c6691 100644 --- a/include/igl/principal_curvature.cpp +++ b/include/igl/principal_curvature.cpp @@ -348,7 +348,15 @@ IGL_INLINE void CurvatureCalculator::fitQuadric(const Eigen::Vector3d& v, const double z = vTang.dot(ref[2]); points.push_back(Eigen::Vector3d (x,y,z)); } - *q = Quadric::fit (points); + if (points.size() < 5) + { + std::cerr << "ASSERT FAILED! fit function requires at least 5 points: Only " << points.size() << " were given." << std::endl; + *q = Quadric(0,0,0,0,0); + } + else + { + *q = Quadric::fit (points); + } } IGL_INLINE void CurvatureCalculator::finalEigenStuff(int i, const std::vector& ref, Quadric& q) From a97f5248bf5f3382ab8c9aac1d7857f3da2e8a67 Mon Sep 17 00:00:00 2001 From: Guillaume Jacquenot Date: Wed, 14 Feb 2018 19:34:00 +0100 Subject: [PATCH 10/20] [curvature] Fixed log message in case error Former-commit-id: e44ed49037fce84788dadc1ae78f523334187f9f --- include/igl/principal_curvature.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/igl/principal_curvature.cpp b/include/igl/principal_curvature.cpp index 41c4c6691..5712130a0 100644 --- a/include/igl/principal_curvature.cpp +++ b/include/igl/principal_curvature.cpp @@ -837,7 +837,7 @@ IGL_INLINE void igl::principal_curvature( if (PD1.row(i) * PD2.row(i).transpose() > 10e-6) { - std::cerr << "PRINCIPAL_CURVATURE: Something is wrong with vertex: i" << std::endl; + std::cerr << "PRINCIPAL_CURVATURE: Something is wrong with vertex: " << i << std::endl; PD1.row(i) *= 0; PD2.row(i) *= 0; } @@ -851,4 +851,4 @@ IGL_INLINE void igl::principal_curvature( template void igl::principal_curvature, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix >(Eigen::PlainObjectBase > const&, Eigen::PlainObjectBase > const&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, unsigned int, bool); template void igl::principal_curvature, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix >(Eigen::PlainObjectBase > const&, Eigen::PlainObjectBase > const&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, unsigned int, bool); template void igl::principal_curvature, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix >(Eigen::PlainObjectBase > const&, Eigen::PlainObjectBase > const&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, unsigned int, bool); -#endif \ No newline at end of file +#endif From 56c0101ce54edd5e60ac025375cb2562e77bcab4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9mie=20Dumas?= Date: Sat, 17 Feb 2018 18:38:20 -0500 Subject: [PATCH 11/20] Add CONTRIBUTING.md Former-commit-id: e244f485b189fa42d596ce062782eec1093f1798 --- CONTRIBUTING.md | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 CONTRIBUTING.md diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 000000000..cbfe9b7b0 --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,17 @@ +Before opening an issue on creating a pull request, please check the following: + +## Compilation Issues + +- If you are on Windows, did you select the **x64** version of the Visual Studio compiler? + +- If you have a **CMake issue**, make sure you follow the same approach as the [libigl-example-project](https://github.com/libigl/libigl-example-project) to build libigl with your project, and make sure that you can compile the example project. + +- If you have an issue with a **submodule**, check if your submodules are up to date. If you have a doubt about a submodule, delete its folder and run `git submodule update --init --recursive` in the libigl directory. + +- If you have an issue with a missing **template issue**, check if your code compile with the *header-only* option of libigl activated. Turn **`OFF`** the CMake option `LIBIGL_USE_STATIC_LIBRARY`: either modify your `CMakeCache.txt` via CMake GUI or ccmake, or delete your `CMakeCache.txt` and re-run `cmake -DLIBIGL_USE_STATIC_LIBRARY=OFF ..` in your build folder. + +- Make sure your read the [**FAQ**](https://github.com/libigl/libigl/wiki/FAQ) before asking a new question, and search [**existing issues**](https://github.com/libigl/libigl/issues?q=is%3Aissue+is%3Aclosed) for a problem similar to yours. + +- Make sure you read the informations contained in the libigl [homepage](https://github.com/libigl/libigl) as well as the [tutorials](http://libigl.github.io/libigl/tutorial/tutorial.html). + +- If none of these solve your problem, then please report your issue in the bug tracker! From f337dcc79a9e53f9d502e1e9adad589355728870 Mon Sep 17 00:00:00 2001 From: Daniele Panozzo Date: Sun, 18 Feb 2018 22:17:48 -0500 Subject: [PATCH 12/20] Template fixes in grad.h Former-commit-id: 275d4786c3c7ea082e7fc44ea67136e4a9195eb4 --- include/igl/grad.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/include/igl/grad.cpp b/include/igl/grad.cpp index 93d9ef939..9089e52c8 100644 --- a/include/igl/grad.cpp +++ b/include/igl/grad.cpp @@ -36,10 +36,11 @@ IGL_INLINE void grad_tet(const Eigen::PlainObjectBase&V, F.row(3*m + i) << T(i,1), T(i,3), T(i,2); } // compute volume of each tet - VectorXd vol; igl::volume(V,T,vol); + Eigen::Matrix vol; + igl::volume(V,T,vol); - VectorXd A(F.rows()); - MatrixXd N(F.rows(),3); + Eigen::Matrix A(F.rows()); + Eigen::Matrix N(F.rows(),3); if (!uniform) { // compute tetrahedron face normals igl::per_face_normals(V,F,N); int norm_rows = N.rows(); @@ -149,7 +150,7 @@ IGL_INLINE void grad_tri(const Eigen::PlainObjectBase&V, // get h (by the area of the triangle) double h = sqrt( (dblA)/sin(M_PI / 3.0)); // (h^2*sin(60))/2. = Area => h = sqrt(2*Area/sin_60) - Eigen::Vector3d v1,v2,v3; + Eigen::Matrix v1,v2,v3; v1 << 0,0,0; v2 << h,0,0; v3 << h/2.,(sqrt(3)/2.)*h,0; From 1fce94228169e44bd61097daa3c388d428f7ab93 Mon Sep 17 00:00:00 2001 From: Alec Jacobson Date: Fri, 23 Feb 2018 09:12:41 -0500 Subject: [PATCH 13/20] matlab 2018 uses strange macro, include first Former-commit-id: 01ed8dedbb3d3f21a437ea756bb6ef8a6c80b249 --- include/igl/matlab/mexErrMsgTxt.cpp | 3 --- include/igl/matlab/mexErrMsgTxt.h | 3 +++ 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/include/igl/matlab/mexErrMsgTxt.cpp b/include/igl/matlab/mexErrMsgTxt.cpp index bd405faa9..89dda1fa3 100644 --- a/include/igl/matlab/mexErrMsgTxt.cpp +++ b/include/igl/matlab/mexErrMsgTxt.cpp @@ -7,9 +7,6 @@ // obtain one at http://mozilla.org/MPL/2.0/. #include "mexErrMsgTxt.h" -// Overload mexErrMsgTxt to check an assertion then print text only if -// assertion fails -#include "mex.h" IGL_INLINE void igl::matlab::mexErrMsgTxt(bool assertion, const char * text) { if(!assertion) diff --git a/include/igl/matlab/mexErrMsgTxt.h b/include/igl/matlab/mexErrMsgTxt.h index bdd76e75b..61b838e6e 100644 --- a/include/igl/matlab/mexErrMsgTxt.h +++ b/include/igl/matlab/mexErrMsgTxt.h @@ -8,6 +8,9 @@ #ifndef IGL_MATLAB_MEXERRMSGTXT_H #define IGL_MATLAB_MEXERRMSGTXT_H #include "../igl_inline.h" +// Overload mexErrMsgTxt to check an assertion then print text only if +// assertion fails +#include "mex.h" namespace igl { namespace matlab From bc54d78a76ed9e98c13af8bce4da709d190da94f Mon Sep 17 00:00:00 2001 From: Alec Jacobson Date: Fri, 23 Feb 2018 09:16:49 -0500 Subject: [PATCH 14/20] usage instructions Former-commit-id: 10f5ef44c2c5cc397116dde4de111f727db2fc08 --- tutorial/306_EigenDecomposition/main.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tutorial/306_EigenDecomposition/main.cpp b/tutorial/306_EigenDecomposition/main.cpp index 842d001d4..a2ad06f96 100644 --- a/tutorial/306_EigenDecomposition/main.cpp +++ b/tutorial/306_EigenDecomposition/main.cpp @@ -36,6 +36,7 @@ int main(int argc, char * argv[]) { cout<<"failed."< Date: Fri, 23 Feb 2018 09:17:24 -0500 Subject: [PATCH 15/20] only compile 106 if imgui is selected Former-commit-id: fcc97bc619e417f50162b3fa4c26510a265c3ac9 --- tutorial/CMakeLists.txt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tutorial/CMakeLists.txt b/tutorial/CMakeLists.txt index 3ca47bb50..aa9b7a4b9 100644 --- a/tutorial/CMakeLists.txt +++ b/tutorial/CMakeLists.txt @@ -53,7 +53,9 @@ if(TUTORIALS_CHAPTER1) add_subdirectory("103_Events") add_subdirectory("104_Colors") add_subdirectory("105_Overlays") - add_subdirectory("106_ViewerMenu") + if(LIBIGL_WITH_OPENGL_GLFW_IMGUI) + add_subdirectory("106_ViewerMenu") + endif() add_subdirectory("107_MultipleMeshes") endif() From 8dc1a158355f862107e71d5659acbea07f320ae4 Mon Sep 17 00:00:00 2001 From: Alec Jacobson Date: Fri, 23 Feb 2018 09:18:21 -0500 Subject: [PATCH 16/20] imgui off by default; do not unset user's option if module not found Former-commit-id: bfa424b341cec7f7008c1aae0a3f258fd228dde7 --- shared/cmake/libigl.cmake | 49 +++++++++++++++++---------------------- 1 file changed, 21 insertions(+), 28 deletions(-) diff --git a/shared/cmake/libigl.cmake b/shared/cmake/libigl.cmake index 0af899ca2..ceaf1195b 100644 --- a/shared/cmake/libigl.cmake +++ b/shared/cmake/libigl.cmake @@ -13,24 +13,25 @@ find_package(MOSEK) # --> MOSEK_FOUND find_package(OpenGL) # --> OPENGL_FOUND ### Available options ### -option(LIBIGL_USE_STATIC_LIBRARY "Use libigl as static library" OFF) -option(LIBIGL_WITH_ANTTWEAKBAR "Use AntTweakBar" OFF) -option(LIBIGL_WITH_CGAL "Use CGAL" "${CGAL_AND_BOOST_FOUND}") -option(LIBIGL_WITH_COMISO "Use CoMiso" ON) -option(LIBIGL_WITH_CORK "Use Cork" OFF) -option(LIBIGL_WITH_EMBREE "Use Embree" OFF) -option(LIBIGL_WITH_LIM "Use LIM" ON) -option(LIBIGL_WITH_MATLAB "Use Matlab" "${Matlab_FOUND}") -option(LIBIGL_WITH_MOSEK "Use MOSEK" "${MOSEK_FOUND}") -option(LIBIGL_WITH_NANOGUI "Use Nanogui menu" OFF) -option(LIBIGL_WITH_OPENGL "Use OpenGL" "${OPENGL_FOUND}") -option(LIBIGL_WITH_OPENGL_GLFW "Use GLFW" "${OPENGL_FOUND}") -option(LIBIGL_WITH_PNG "Use PNG" ON) -option(LIBIGL_WITH_TETGEN "Use Tetgen" ON) -option(LIBIGL_WITH_TRIANGLE "Use Triangle" ON) -option(LIBIGL_WITH_VIEWER "Use OpenGL viewer" "${OPENGL_FOUND}") -option(LIBIGL_WITH_XML "Use XML" ON) -option(LIBIGL_WITH_PYTHON "Use Python" OFF) +option(LIBIGL_USE_STATIC_LIBRARY "Use libigl as static library" OFF) +option(LIBIGL_WITH_ANTTWEAKBAR "Use AntTweakBar" OFF) +option(LIBIGL_WITH_CGAL "Use CGAL" "${CGAL_AND_BOOST_FOUND}") +option(LIBIGL_WITH_COMISO "Use CoMiso" ON) +option(LIBIGL_WITH_CORK "Use Cork" OFF) +option(LIBIGL_WITH_EMBREE "Use Embree" OFF) +option(LIBIGL_WITH_LIM "Use LIM" ON) +option(LIBIGL_WITH_MATLAB "Use Matlab" "${Matlab_FOUND}") +option(LIBIGL_WITH_MOSEK "Use MOSEK" "${MOSEK_FOUND}") +option(LIBIGL_WITH_NANOGUI "Use Nanogui menu" OFF) +option(LIBIGL_WITH_OPENGL "Use OpenGL" "${OPENGL_FOUND}") +option(LIBIGL_WITH_OPENGL_GLFW "Use GLFW" "${OPENGL_FOUND}") +option(LIBIGL_WITH_OPENGL_GLFW_IMGUI "Use IMGUI" OFF) +option(LIBIGL_WITH_PNG "Use PNG" ON) +option(LIBIGL_WITH_TETGEN "Use Tetgen" ON) +option(LIBIGL_WITH_TRIANGLE "Use Triangle" ON) +option(LIBIGL_WITH_VIEWER "Use OpenGL viewer" "${OPENGL_FOUND}") +option(LIBIGL_WITH_XML "Use XML" ON) +option(LIBIGL_WITH_PYTHON "Use Python" OFF) if(LIBIGL_WITH_VIEWER AND (NOT LIBIGL_WITH_OPENGL_GLFW OR NOT LIBIGL_WITH_OPENGL) ) message(FATAL_ERROR "LIBIGL_WITH_VIEWER=ON requires LIBIGL_WITH_OPENGL_GLFW=ON and LIBIGL_WITH_OPENGL=ON") @@ -256,8 +257,8 @@ endif() if(LIBIGL_WITH_MATLAB) find_package(Matlab REQUIRED COMPONENTS MEX_COMPILER MX_LIBRARY ENG_LIBRARY) compile_igl_module("matlab") - target_link_libraries(igl_matlab ${IGL_SCOPE} ${MATLAB_LIBRARIES}) - target_include_directories(igl_matlab ${IGL_SCOPE} ${MATLAB_INCLUDE_DIR}) + target_link_libraries(igl_matlab ${IGL_SCOPE} ${Matlab_LIBRARIES}) + target_include_directories(igl_matlab ${IGL_SCOPE} ${Matlab_INCLUDE_DIRS}) endif() ################################################################################ @@ -302,9 +303,6 @@ if(LIBIGL_WITH_OPENGL_GLFW) add_subdirectory(${LIBIGL_EXTERNAL}/glfw glfw) endif() target_link_libraries(igl_opengl_glfw ${IGL_SCOPE} igl_opengl glfw) - else() - message(WARNING "GLFW module could not be compiled") - set(LIBIGL_WITH_OPENGL_GLFW OFF CACHE BOOL "" FORCE) endif() endif() @@ -319,9 +317,6 @@ if(LIBIGL_WITH_OPENGL_GLFW_IMGUI) add_subdirectory(${LIBIGL_EXTERNAL}/imgui imgui) endif() target_link_libraries(igl_opengl_glfw_imgui ${IGL_SCOPE} igl_opengl_glfw imgui) - else() - message(WARNING "ImGui module could not be compiled") - set(LIBIGL_WITH_OPENGL_GLFW_IMGUI OFF CACHE BOOL "" FORCE) endif() endif() @@ -337,8 +332,6 @@ if(LIBIGL_WITH_PNG) endif() compile_igl_module("png" "") target_link_libraries(igl_png ${IGL_SCOPE} igl_stb_image igl_opengl) - else() - set(LIBIGL_WITH_PNG OFF CACHE BOOL "" FORCE) endif() endif() From b77c5ba4a98c109daa46c7547b89de6653a374b7 Mon Sep 17 00:00:00 2001 From: Alec Jacobson Date: Fri, 23 Feb 2018 09:18:49 -0500 Subject: [PATCH 17/20] revert 107; do not rely on imgui Former-commit-id: eb1d95e24613ec14272ac8395830b9dbb1a51315 --- tutorial/107_MultipleMeshes/CMakeLists.txt | 2 +- tutorial/107_MultipleMeshes/main.cpp | 59 +++++----------------- 2 files changed, 14 insertions(+), 47 deletions(-) diff --git a/tutorial/107_MultipleMeshes/CMakeLists.txt b/tutorial/107_MultipleMeshes/CMakeLists.txt index 6db43c41a..f1e58934f 100644 --- a/tutorial/107_MultipleMeshes/CMakeLists.txt +++ b/tutorial/107_MultipleMeshes/CMakeLists.txt @@ -2,4 +2,4 @@ cmake_minimum_required(VERSION 2.8.12) project(107_MultipleMeshes) add_executable(${PROJECT_NAME}_bin main.cpp) -target_link_libraries(${PROJECT_NAME}_bin igl::core igl::opengl igl::opengl_glfw igl::opengl_glfw_imgui tutorials) +target_link_libraries(${PROJECT_NAME}_bin igl::core igl::opengl igl::opengl_glfw tutorials) diff --git a/tutorial/107_MultipleMeshes/main.cpp b/tutorial/107_MultipleMeshes/main.cpp index 864af23a8..5c327566c 100755 --- a/tutorial/107_MultipleMeshes/main.cpp +++ b/tutorial/107_MultipleMeshes/main.cpp @@ -1,68 +1,35 @@ #include "tutorial_shared_path.h" #include -#include -#include #include -#include #include -// Add custom data to a viewer mesh -struct MeshData -{ - std::string name; - Eigen::RowVector3d color; -}; -int last_colored_index = -1; - -// Set colors of each mesh -void update_colors(igl::opengl::glfw::Viewer &viewer) -{ - for (auto &data : viewer.data_list) - { - data.set_colors(data.attr().color); - } - viewer.data_list[viewer.selected_data_index].set_colors(Eigen::RowVector3d(0.9,0.1,0.1)); - last_colored_index = viewer.selected_data_index; -} - int main(int argc, char * argv[]) { igl::opengl::glfw::Viewer viewer; - auto names = {"cube.obj","sphere.obj","xcylinder.obj","ycylinder.obj","zcylinder.obj"}; + const auto names = + {"cube.obj","sphere.obj","xcylinder.obj","ycylinder.obj","zcylinder.obj"}; for(const auto & name : names) { viewer.load_mesh_from_file(std::string(TUTORIAL_SHARED_PATH) + "/" + name); - viewer.data().attr().name = name; - viewer.data().attr().color = Eigen::RowVector3d::Random(); } - // Attach a custom menu - igl::opengl::glfw::imgui::ImGuiMenu menu; - viewer.plugins.push_back(&menu); + // Set colors of each mesh by selecting its index first + viewer.selected_data_index = 0; + viewer.data().set_colors(Eigen::RowVector3d(0.8,0.47,0.22)); + viewer.selected_data_index = 1; + viewer.data().set_colors(Eigen::RowVector3d(0.6,0.01,0.11)); + viewer.selected_data_index = 2; + viewer.data().set_colors(Eigen::RowVector3d(0.37,0.06,0.25)); + viewer.selected_data_index = 3; + viewer.data().set_colors(Eigen::RowVector3d(1,1,1)); - // Customize default menu - menu.draw_viewer_menu_func = [&]() - { - if (ImGui::Combo("Selected Mesh", (int *) &viewer.selected_data_index, - [&](int i) { return viewer.data_list[i].attr().name.c_str(); }, - viewer.data_list.size()) - || last_colored_index != viewer.selected_data_index) - { - update_colors(viewer); - } - }; - - // Color each mesh differently - update_colors(viewer); - - viewer.callback_key_down = + viewer.callback_key_down = [&](igl::opengl::glfw::Viewer &, unsigned int key, int mod) { // Delete - if(key == '3') + if(key == 3) { viewer.erase_mesh(viewer.selected_data_index); - update_colors(viewer); return true; } return false; From 3f85509cc6261bc7cacdbddf06646ce8298b17ae Mon Sep 17 00:00:00 2001 From: Alec Jacobson Date: Fri, 23 Feb 2018 09:19:16 -0500 Subject: [PATCH 18/20] lingering bug: per-vertex attributes handled incorrectly Former-commit-id: b21106046bc6b9a59013ea57db354e0451dfa855 --- include/igl/opengl/MeshGL.cpp | 195 +++++++++++++++-------------- include/igl/opengl/ViewerData.cpp | 23 ++-- include/igl/opengl/glfw/Viewer.cpp | 4 +- 3 files changed, 115 insertions(+), 107 deletions(-) diff --git a/include/igl/opengl/MeshGL.cpp b/include/igl/opengl/MeshGL.cpp index de81a1376..3aee63401 100644 --- a/include/igl/opengl/MeshGL.cpp +++ b/include/igl/opengl/MeshGL.cpp @@ -165,112 +165,117 @@ IGL_INLINE void igl::opengl::MeshGL::init() } is_initialized = true; std::string mesh_vertex_shader_string = - "#version 150\n" - "uniform mat4 model;" - "uniform mat4 view;" - "uniform mat4 proj;" - "in vec3 position;" - "in vec3 normal;" - "out vec3 position_eye;" - "out vec3 normal_eye;" - "in vec4 Ka;" - "in vec4 Kd;" - "in vec4 Ks;" - "in vec2 texcoord;" - "out vec2 texcoordi;" - "out vec4 Kai;" - "out vec4 Kdi;" - "out vec4 Ksi;" +R"(#version 150 + uniform mat4 model; + uniform mat4 view; + uniform mat4 proj; + in vec3 position; + in vec3 normal; + out vec3 position_eye; + out vec3 normal_eye; + in vec4 Ka; + in vec4 Kd; + in vec4 Ks; + in vec2 texcoord; + out vec2 texcoordi; + out vec4 Kai; + out vec4 Kdi; + out vec4 Ksi; - "void main()" - "{" - " position_eye = vec3 (view * model * vec4 (position, 1.0));" - " normal_eye = vec3 (view * model * vec4 (normal, 0.0));" - " normal_eye = normalize(normal_eye);" - " gl_Position = proj * vec4 (position_eye, 1.0);" //proj * view * model * vec4(position, 1.0);" - " Kai = Ka;" - " Kdi = Kd;" - " Ksi = Ks;" - " texcoordi = texcoord;" - "}"; + void main() + { + position_eye = vec3 (view * model * vec4 (position, 1.0)); + normal_eye = vec3 (view * model * vec4 (normal, 0.0)); + normal_eye = normalize(normal_eye); + gl_Position = proj * vec4 (position_eye, 1.0); //proj * view * model * vec4(position, 1.0); + Kai = Ka; + Kdi = Kd; + Ksi = Ks; + texcoordi = texcoord; + } +)"; - std::string mesh_fragment_shader_string = - "#version 150\n" - "uniform mat4 model;" - "uniform mat4 view;" - "uniform mat4 proj;" - "uniform vec4 fixed_color;" - "in vec3 position_eye;" - "in vec3 normal_eye;" - "uniform vec3 light_position_world;" - "vec3 Ls = vec3 (1, 1, 1);" - "vec3 Ld = vec3 (1, 1, 1);" - "vec3 La = vec3 (1, 1, 1);" - "in vec4 Ksi;" - "in vec4 Kdi;" - "in vec4 Kai;" - "in vec2 texcoordi;" - "uniform sampler2D tex;" - "uniform float specular_exponent;" - "uniform float lighting_factor;" - "uniform float texture_factor;" - "out vec4 outColor;" - "void main()" - "{" - "vec3 Ia = La * vec3(Kai);" // ambient intensity + std::string mesh_fragment_shader_string = +R"(#version 150 + uniform mat4 model; + uniform mat4 view; + uniform mat4 proj; + uniform vec4 fixed_color; + in vec3 position_eye; + in vec3 normal_eye; + uniform vec3 light_position_world; + vec3 Ls = vec3 (1, 1, 1); + vec3 Ld = vec3 (1, 1, 1); + vec3 La = vec3 (1, 1, 1); + in vec4 Ksi; + in vec4 Kdi; + in vec4 Kai; + in vec2 texcoordi; + uniform sampler2D tex; + uniform float specular_exponent; + uniform float lighting_factor; + uniform float texture_factor; + out vec4 outColor; + void main() + { + vec3 Ia = La * vec3(Kai); // ambient intensity - "vec3 light_position_eye = vec3 (view * vec4 (light_position_world, 1.0));" - "vec3 vector_to_light_eye = light_position_eye - position_eye;" - "vec3 direction_to_light_eye = normalize (vector_to_light_eye);" - "float dot_prod = dot (direction_to_light_eye, normal_eye);" - "float clamped_dot_prod = max (dot_prod, 0.0);" - "vec3 Id = Ld * vec3(Kdi) * clamped_dot_prod;" // Diffuse intensity + vec3 light_position_eye = vec3 (view * vec4 (light_position_world, 1.0)); + vec3 vector_to_light_eye = light_position_eye - position_eye; + vec3 direction_to_light_eye = normalize (vector_to_light_eye); + float dot_prod = dot (direction_to_light_eye, normal_eye); + float clamped_dot_prod = max (dot_prod, 0.0); + vec3 Id = Ld * vec3(Kdi) * clamped_dot_prod; // Diffuse intensity - "vec3 reflection_eye = reflect (-direction_to_light_eye, normal_eye);" - "vec3 surface_to_viewer_eye = normalize (-position_eye);" - "float dot_prod_specular = dot (reflection_eye, surface_to_viewer_eye);" - "dot_prod_specular = float(abs(dot_prod)==dot_prod) * max (dot_prod_specular, 0.0);" - "float specular_factor = pow (dot_prod_specular, specular_exponent);" - "vec3 Is = Ls * vec3(Ksi) * specular_factor;" // specular intensity - "vec4 color = vec4(lighting_factor * (Is + Id) + Ia + (1.0-lighting_factor) * vec3(Kdi),(Kai.a+Ksi.a+Kdi.a)/3);" - "outColor = mix(vec4(1,1,1,1), texture(tex, texcoordi), texture_factor) * color;" - "if (fixed_color != vec4(0.0)) outColor = fixed_color;" - "}"; + vec3 reflection_eye = reflect (-direction_to_light_eye, normal_eye); + vec3 surface_to_viewer_eye = normalize (-position_eye); + float dot_prod_specular = dot (reflection_eye, surface_to_viewer_eye); + dot_prod_specular = float(abs(dot_prod)==dot_prod) * max (dot_prod_specular, 0.0); + float specular_factor = pow (dot_prod_specular, specular_exponent); + vec3 Is = Ls * vec3(Ksi) * specular_factor; // specular intensity + vec4 color = vec4(lighting_factor * (Is + Id) + Ia + (1.0-lighting_factor) * vec3(Kdi),(Kai.a+Ksi.a+Kdi.a)/3); + outColor = mix(vec4(1,1,1,1), texture(tex, texcoordi), texture_factor) * color; + if (fixed_color != vec4(0.0)) outColor = fixed_color; + } + )"; std::string overlay_vertex_shader_string = - "#version 150\n" - "uniform mat4 model;" - "uniform mat4 view;" - "uniform mat4 proj;" - "in vec3 position;" - "in vec3 color;" - "out vec3 color_frag;" +R"(#version 150 + uniform mat4 model; + uniform mat4 view; + uniform mat4 proj; + in vec3 position; + in vec3 color; + out vec3 color_frag; - "void main()" - "{" - " gl_Position = proj * view * model * vec4 (position, 1.0);" - " color_frag = color;" - "}"; + void main() + { + gl_Position = proj * view * model * vec4 (position, 1.0); + color_frag = color; + } +)"; std::string overlay_fragment_shader_string = - "#version 150\n" - "in vec3 color_frag;" - "out vec4 outColor;" - "void main()" - "{" - " outColor = vec4(color_frag, 1.0);" - "}"; +R"(#version 150 + in vec3 color_frag; + out vec4 outColor; + void main() + { + outColor = vec4(color_frag, 1.0); + } +)"; std::string overlay_point_fragment_shader_string = - "#version 150\n" - "in vec3 color_frag;" - "out vec4 outColor;" - "void main()" - "{" - " if (length(gl_PointCoord - vec2(0.5)) > 0.5)" - " discard;" - " outColor = vec4(color_frag, 1.0);" - "}"; +R"(#version 150 + in vec3 color_frag; + out vec4 outColor; + void main() + { + if (length(gl_PointCoord - vec2(0.5)) > 0.5) + discard; + outColor = vec4(color_frag, 1.0); + } +)"; init_buffers(); create_shader_program( diff --git a/include/igl/opengl/ViewerData.cpp b/include/igl/opengl/ViewerData.cpp index f1c730bb2..9cec330b4 100644 --- a/include/igl/opengl/ViewerData.cpp +++ b/include/igl/opengl/ViewerData.cpp @@ -528,7 +528,9 @@ IGL_INLINE void igl::opengl::ViewerData::updateGL( // Texture coordinates if (meshgl.dirty & MeshGL::DIRTY_UV) + { meshgl.V_uv_vbo = data.V_uv.cast(); + } } else { @@ -541,36 +543,35 @@ IGL_INLINE void igl::opengl::ViewerData::updateGL( if (meshgl.dirty & MeshGL::DIRTY_AMBIENT) { - meshgl.V_ambient_vbo.resize(4,data.F.rows()*3); + meshgl.V_ambient_vbo.resize(data.F.rows()*3,4); for (unsigned i=0; i(); + meshgl.V_ambient_vbo.row(i*3+j) = data.V_material_ambient.row(data.F(i,j)).cast(); } if (meshgl.dirty & MeshGL::DIRTY_DIFFUSE) { - meshgl.V_diffuse_vbo.resize(4,data.F.rows()*3); + meshgl.V_diffuse_vbo.resize(data.F.rows()*3,4); for (unsigned i=0; i(); + meshgl.V_diffuse_vbo.row(i*3+j) = data.V_material_diffuse.row(data.F(i,j)).cast(); } if (meshgl.dirty & MeshGL::DIRTY_SPECULAR) { - meshgl.V_specular_vbo.resize(4,data.F.rows()*3); + meshgl.V_specular_vbo.resize(data.F.rows()*3,4); for (unsigned i=0; i(); + meshgl.V_specular_vbo.row(i*3+j) = data.V_material_specular.row(data.F(i,j)).cast(); } if (meshgl.dirty & MeshGL::DIRTY_NORMAL) { - meshgl.V_normals_vbo.resize(3,data.F.rows()*3); + meshgl.V_normals_vbo.resize(data.F.rows()*3,3); for (unsigned i=0; i() : - data.V_normals.row(data.F(i,j)).transpose().cast(); + data.F_normals.row(i*3+j).cast() : + data.V_normals.row(data.F(i,j)).cast(); if (invert_normals) diff --git a/include/igl/opengl/glfw/Viewer.cpp b/include/igl/opengl/glfw/Viewer.cpp index 9497d2ab7..e202bfa68 100644 --- a/include/igl/opengl/glfw/Viewer.cpp +++ b/include/igl/opengl/glfw/Viewer.cpp @@ -172,8 +172,8 @@ namespace glfw printf("Failed to load OpenGL and its extensions\n"); return(-1); } - printf("OpenGL Version %d.%d loaded\n", GLVersion.major, GLVersion.minor); #if defined(DEBUG) || defined(_DEBUG) + printf("OpenGL Version %d.%d loaded\n", GLVersion.major, GLVersion.minor); int major, minor, rev; major = glfwGetWindowAttrib(window, GLFW_CONTEXT_VERSION_MAJOR); minor = glfwGetWindowAttrib(window, GLFW_CONTEXT_VERSION_MINOR); @@ -413,6 +413,8 @@ namespace glfw data().uniform_colors(Eigen::Vector3d(51.0/255.0,43.0/255.0,33.3/255.0), Eigen::Vector3d(255.0/255.0,228.0/255.0,58.0/255.0), Eigen::Vector3d(255.0/255.0,235.0/255.0,80.0/255.0)); + + // Alec: why? if (data().V_uv.rows() == 0) { data().grid_texture(); From 57a8279606399fa8de600e65b7c0a8d37b85b041 Mon Sep 17 00:00:00 2001 From: Alec Jacobson Date: Fri, 23 Feb 2018 09:36:15 -0500 Subject: [PATCH 19/20] use int for callbacks; use corect backspace code Former-commit-id: b86117ea061aec3f88a85f2e8ec76884191b2d38 --- include/igl/opengl/glfw/Viewer.h | 4 ++-- tutorial/107_MultipleMeshes/main.cpp | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/include/igl/opengl/glfw/Viewer.h b/include/igl/opengl/glfw/Viewer.h index 16e77acbd..55e5c3349 100644 --- a/include/igl/opengl/glfw/Viewer.h +++ b/include/igl/opengl/glfw/Viewer.h @@ -142,8 +142,8 @@ namespace glfw std::function callback_mouse_scroll; std::function callback_key_pressed; // THESE SHOULD BE DEPRECATED: - std::function callback_key_down; - std::function callback_key_up; + std::function callback_key_down; + std::function callback_key_up; // Pointers to per-callback data void* callback_init_data; void* callback_pre_draw_data; diff --git a/tutorial/107_MultipleMeshes/main.cpp b/tutorial/107_MultipleMeshes/main.cpp index 5c327566c..dd4615796 100755 --- a/tutorial/107_MultipleMeshes/main.cpp +++ b/tutorial/107_MultipleMeshes/main.cpp @@ -1,5 +1,6 @@ #include "tutorial_shared_path.h" #include +#include #include #include @@ -26,8 +27,7 @@ int main(int argc, char * argv[]) viewer.callback_key_down = [&](igl::opengl::glfw::Viewer &, unsigned int key, int mod) { - // Delete - if(key == 3) + if(key == GLFW_KEY_BACKSPACE) { viewer.erase_mesh(viewer.selected_data_index); return true; From 5c32bd74788af9a400182b6f4db49bd8ea2f1e18 Mon Sep 17 00:00:00 2001 From: Alec Jacobson Date: Fri, 23 Feb 2018 09:55:07 -0500 Subject: [PATCH 20/20] cleanup Former-commit-id: f50084cacb0f3ec76ef270d0a1bc3e9931ac2719 --- tutorial/206_GeodesicDistance/main.cpp | 95 +++++++++++++------------- 1 file changed, 48 insertions(+), 47 deletions(-) diff --git a/tutorial/206_GeodesicDistance/main.cpp b/tutorial/206_GeodesicDistance/main.cpp index ead43f0f5..1012ee867 100755 --- a/tutorial/206_GeodesicDistance/main.cpp +++ b/tutorial/206_GeodesicDistance/main.cpp @@ -3,71 +3,72 @@ #include #include #include - #include #include "tutorial_shared_path.h" -Eigen::MatrixXd V; -Eigen::MatrixXi F; - -void plotMeshDistance(igl::opengl::glfw::Viewer& viewer, const Eigen::MatrixXd& V, const Eigen::MatrixXi& F, const Eigen::VectorXd& d, const double strip_size ) -{ - // Rescale the function depending on the strip size - Eigen::VectorXd f = (d/strip_size); - - // The function should be 1 on each integer coordinate - f = (f*M_PI).array().sin().abs(); - - // Compute per-vertex colors - Eigen::MatrixXd C; - igl::colormap(igl::COLOR_MAP_TYPE_INFERNO,f,false,C); - - // Plot the mesh - viewer.data().set_mesh(V, F); - viewer.data().set_colors(C); -} int main(int argc, char *argv[]) { using namespace Eigen; using namespace std; - + Eigen::MatrixXd V; + Eigen::MatrixXi F; + igl::opengl::glfw::Viewer viewer; // Load a mesh in OFF format igl::readOBJ(TUTORIAL_SHARED_PATH "/armadillo.obj", V, F); + const auto update_distance = [&](const int vid) + { + Eigen::VectorXi VS,FS,VT,FT; + // The selected vertex is the source + VS.resize(1); + VS << vid; + // All vertices are the targets + VT.setLinSpaced(V.rows(),0,V.rows()-1); + Eigen::VectorXd d; + std::cout<<"Computing geodesic distance to vertex "<bool { - int fid; - Eigen::Vector3f bc; - // Cast a ray in the view direction starting from the mouse position - double x = viewer.current_mouse_x; - double y = viewer.core.viewport(3) - viewer.current_mouse_y; - if(igl::unproject_onto_mesh(Eigen::Vector2f(x,y), viewer.core.view * viewer.core.model, - viewer.core.proj, viewer.core.viewport, V, F, fid, bc)) - { - int max; - bc.maxCoeff(&max); - int vid = F(fid,max); - Eigen::VectorXi VS,FS,VT,FT; - // The selected vertex is the source - VS.resize(1); - VS << vid; - // All vertices are the targets - VT.setLinSpaced(V.rows(),0,V.rows()-1); - Eigen::VectorXd d; - igl::exact_geodesic(V,F,VS,FS,VT,FT,d); - - plotMeshDistance(viewer,V,F,d,0.05); - } - return false; + int fid; + Eigen::Vector3f bc; + // Cast a ray in the view direction starting from the mouse position + double x = viewer.current_mouse_x; + double y = viewer.core.viewport(3) - viewer.current_mouse_y; + if(igl::unproject_onto_mesh( + Eigen::Vector2f(x,y), + viewer.core.view * viewer.core.model, + viewer.core.proj, + viewer.core.viewport, + V, + F, + fid, + bc)) + { + int max; + bc.maxCoeff(&max); + int vid = F(fid,max); + update_distance(vid); + return true; + } + return false; }; viewer.data().set_mesh(V,F); - cout << "Press [space] to smooth." << endl;; - cout << "Press [r] to reset." << endl;; + cout << "Click on mesh to define new source.\n" << std::endl; + update_distance(0); return viewer.launch(); }