Browse Source

Fix LIM solver issues and add some improvments

Former-commit-id: edc680b9751d90b4cd841634f99fc680f4d25c9d
schuellc 9 years ago
parent
commit
11ba159664
5 changed files with 45 additions and 40 deletions
  1. 18 16
      include/igl/lim/lim.cpp
  2. 16 17
      include/igl/lim/lim.h
  3. 7 7
      tutorial/608_LIM/main.cpp
  4. 1 0
      tutorial/CMakeLists.txt
  5. 3 0
      tutorial/cmake/FindLIM.cmake

+ 18 - 16
include/igl/lim/lim.cpp

@@ -8,37 +8,39 @@
 #include "lim.h"
 #include <LIMSolverInterface.h>
 
-IGL_INLINE int igl::lim::lim(
+using namespace igl::lim;
+
+IGL_INLINE State lim(
   Eigen::Matrix<double,Eigen::Dynamic,3>& vertices,
   const Eigen::Matrix<double,Eigen::Dynamic,3>& initialVertices,
   const Eigen::Matrix<int,Eigen::Dynamic,Eigen::Dynamic>& elements,
   const Eigen::SparseMatrix<double>& constraintMatrix,
   const Eigen::Matrix<double,Eigen::Dynamic,1>& constraintTargets,
-  int energyType,
+  Energy energyType,
   double tolerance,
   int maxIteration,
   bool findLocalMinima)
 {
-  return ComputeLIM(
+  return (State)ComputeLIM(
     vertices,
     initialVertices,
     elements,
     constraintMatrix,
     constraintTargets,
-    energyType,
+    (EnergyType)energyType,
     tolerance,
     maxIteration,
     findLocalMinima
     );
 }
 
-IGL_INLINE int igl::lim(
+IGL_INLINE State igl::lim::lim(
   Eigen::Matrix<double,Eigen::Dynamic,3>& vertices,
   const Eigen::Matrix<double,Eigen::Dynamic,3>& initialVertices,
   const Eigen::Matrix<int,Eigen::Dynamic,Eigen::Dynamic>& elements,
   const Eigen::SparseMatrix<double>& constraintMatrix,
   const Eigen::Matrix<double,Eigen::Dynamic,1>& constraintTargets,
-  int energyType,
+  Energy energyType,
   double tolerance,
   int maxIteration,
   bool findLocalMinima,
@@ -48,13 +50,13 @@ IGL_INLINE int igl::lim(
   double beta,
   double eps)
 {
-  return ComputeLIM(
+  return (State)ComputeLIM(
     vertices,
     initialVertices,
     elements,
     constraintMatrix,
     constraintTargets,
-    energyType,
+    (EnergyType)energyType,
     tolerance,
     maxIteration,
     findLocalMinima,
@@ -66,7 +68,7 @@ IGL_INLINE int igl::lim(
     );
 }
 
-IGL_INLINE int igl::lim(
+IGL_INLINE State igl::lim::lim(
   Eigen::Matrix<double,Eigen::Dynamic,3>& vertices,
   const Eigen::Matrix<double,Eigen::Dynamic,3>& initialVertices,
   const Eigen::Matrix<int,Eigen::Dynamic,Eigen::Dynamic>& elements,
@@ -74,12 +76,12 @@ IGL_INLINE int igl::lim(
   const Eigen::Matrix<double,Eigen::Dynamic,1>& gradients,
   const Eigen::SparseMatrix<double>& constraintMatrix,
   const Eigen::Matrix<double,Eigen::Dynamic,1>& constraintTargets,
-  int energyType,
+  Energy energyType,
   double tolerance,
   int maxIteration,
   bool findLocalMinima)
 {
-  return ComputeLIM(
+  return (State)ComputeLIM(
     vertices,
     initialVertices,
     elements,
@@ -87,14 +89,14 @@ IGL_INLINE int igl::lim(
     gradients,
     constraintMatrix,
     constraintTargets,
-    energyType,
+    (EnergyType)energyType,
     tolerance,
     maxIteration,
     findLocalMinima
     );
 }
 
-IGL_INLINE int igl::lim(
+IGL_INLINE State igl::lim::lim(
   Eigen::Matrix<double,Eigen::Dynamic,3>& vertices,
   const Eigen::Matrix<double,Eigen::Dynamic,3>& initialVertices,
   const Eigen::Matrix<int,Eigen::Dynamic,Eigen::Dynamic>& elements,
@@ -102,7 +104,7 @@ IGL_INLINE int igl::lim(
   const Eigen::Matrix<double,Eigen::Dynamic,1>& gradients,
   const Eigen::SparseMatrix<double>& constraintMatrix,
   const Eigen::Matrix<double,Eigen::Dynamic,1>& constraintTargets,
-  int energyType,
+  Energy energyType,
   double tolerance,
   int maxIteration,
   bool findLocalMinima,
@@ -112,7 +114,7 @@ IGL_INLINE int igl::lim(
   double beta,
   double eps)
 {
-  return ComputeLIM(
+  return (State)ComputeLIM(
     vertices,
     initialVertices,
     elements,
@@ -120,7 +122,7 @@ IGL_INLINE int igl::lim(
     gradients,
     constraintMatrix,
     constraintTargets,
-    energyType,
+    (EnergyType)energyType,
     tolerance,
     maxIteration,
     findLocalMinima,

+ 16 - 17
include/igl/lim/lim.h

@@ -15,9 +15,6 @@ namespace igl
 {
   namespace lim
   {
-    // Known issues: energy type should be a readable enum rather than magic
-    // ints.
-    //
     // Computes a locally injective mapping of a triangle or tet-mesh based on
     // a deformation energy subject to some provided linear positional
     // constraints Cv-d.
@@ -39,7 +36,7 @@ namespace igl
     //                     y_2, ..., x_v,y_v])
     //   constraintTargets d: c vector target positions
     //   energyType        type of used energy:
-    //                     0=Dirichlet,1=Laplacian,2=Green,3=ARAP,4=LSCM
+    //                     Dirichlet, Laplacian, Green, ARAP, LSCM, Poisson (only 2D), UniformLaplacian, Identity
     //   tolerance         max squared positional constraints error
     //   maxIteration      max number of iterations
     //   findLocalMinima   iterating until a local minima is found. If not
@@ -61,30 +58,32 @@ namespace igl
     //                   mesh
     //--------------------------------------------------------------------------
     // Return values:
-    //  1 : Optimization deemed successful because either (a) it stagnated
-    //    (very step size) or (b) positional constraints were satisfied. (re:
-    //    https://github.com/libigl/libigl/issues/79 )
-    // -1 : Max iteration reached before tolerance was fulfilled
-    // -2 : not feasible -> has inverted elements (may want to decrease eps?)
+    //  Succeeded : Successful optimization with fulfilled tolerance
+    //  LocalMinima : Convergenged to a local minima / tolerance not fullfilled
+    //  IterationLimit : Max iteration reached before tolerance was fulfilled
+    //  Infeasible : not feasible -> has inverted elements (decrease eps?)
   
-    int lim(
+    enum Energy { Dirichlet = 0, Laplacian=1, Green=2, ARAP=3, LSCM=4, Poisson=5, UniformLaplacian=6, Identity=7 };
+    enum State { Uninitialized = -4, Infeasible = -3, IterationLimit = -2, LocalMinima = -1, Running = 0, Succeeded = 1 };
+
+    State lim(
       Eigen::Matrix<double,Eigen::Dynamic,3>& vertices,
       const Eigen::Matrix<double,Eigen::Dynamic,3>& initialVertices,
       const Eigen::Matrix<int,Eigen::Dynamic,Eigen::Dynamic>& elements,
       const Eigen::SparseMatrix<double>& constraintMatrix,
       const Eigen::Matrix<double,Eigen::Dynamic,1>& constraintTargets,
-      int energyType,
+      Energy energyType,
       double tolerance,
       int maxIteration,
       bool findLocalMinima);
   
-    int lim(
+    State lim(
       Eigen::Matrix<double,Eigen::Dynamic,3>& vertices,
       const Eigen::Matrix<double,Eigen::Dynamic,3>& initialVertices,
       const Eigen::Matrix<int,Eigen::Dynamic,Eigen::Dynamic>& elements,
       const Eigen::SparseMatrix<double>& constraintMatrix,
       const Eigen::Matrix<double,Eigen::Dynamic,1>& constraintTargets,
-      int energyType,
+      Energy energyType,
       double tolerance,
       int maxIteration,
       bool findLocalMinima,
@@ -94,7 +93,7 @@ namespace igl
       double beta,
       double eps);
   
-    int lim(
+    State lim(
       Eigen::Matrix<double,Eigen::Dynamic,3>& vertices,
       const Eigen::Matrix<double,Eigen::Dynamic,3>& initialVertices,
       const Eigen::Matrix<int,Eigen::Dynamic,Eigen::Dynamic>& elements,
@@ -102,12 +101,12 @@ namespace igl
       const Eigen::Matrix<double,Eigen::Dynamic,1>& gradients,
       const Eigen::SparseMatrix<double>& constraintMatrix,
       const Eigen::Matrix<double,Eigen::Dynamic,1>& constraintTargets,
-      int energyType,
+      Energy energyType,
       double tolerance,
       int maxIteration,
       bool findLocalMinima);
   
-    int lim(
+    State lim(
       Eigen::Matrix<double,Eigen::Dynamic,3>& vertices,
       const Eigen::Matrix<double,Eigen::Dynamic,3>& initialVertices,
       const Eigen::Matrix<int,Eigen::Dynamic,Eigen::Dynamic>& elements,
@@ -115,7 +114,7 @@ namespace igl
       const Eigen::Matrix<double,Eigen::Dynamic,1>& gradients,
       const Eigen::SparseMatrix<double>& constraintMatrix,
       const Eigen::Matrix<double,Eigen::Dynamic,1>& constraintTargets,
-      int energyType,
+      Energy energyType,
       double tolerance,
       int maxIteration,
       bool findLocalMinima,

+ 7 - 7
tutorial/608_LIM/main.cpp

@@ -7,6 +7,8 @@
 
 #include "tutorial_shared_path.h"
 
+using namespace igl::lim;
+
 // Mesh
 Eigen::MatrixX3d V0;
 Eigen::MatrixX3d V1;
@@ -15,7 +17,7 @@ Eigen::MatrixXi F;
 Eigen::SparseMatrix<double> C;
 Eigen::VectorXd b;
 
-int energyType;
+Energy energyType;
 bool barriersEnabled;
 
 // This function is called every time a keyboard button is pressed
@@ -28,7 +30,7 @@ bool key_down(igl::viewer::Viewer& viewer,unsigned char key,int modifier)
   if(key >= '0' && key <= '5' || key == 'B')
   {
     // compute locally injective map
-    int energy = key - '1';
+    Energy energy = Energy(key - '1');
 
     V1 = V0;
 
@@ -44,8 +46,7 @@ bool key_down(igl::viewer::Viewer& viewer,unsigned char key,int modifier)
 
     if(key != '0')
     {
-      igl::lim::lim(
-          V1,V0,F,C,b,energyType,1e-8,100,true,true,barriersEnabled,true,-1,-1);
+      lim(V1,V0,F,C,b,energyType,1e-8,100,true,true,barriersEnabled,true,-1,-1);
     }
 
     // set mesh
@@ -62,7 +63,7 @@ int main(int argc, char *argv[])
   using namespace std;
   using namespace Eigen;
 
-  energyType = 0;
+  energyType = Dirichlet;
   barriersEnabled = true;
 
   // load a mesh in OFF format
@@ -102,8 +103,7 @@ int main(int argc, char *argv[])
   b(2*fixedVertices.size()+1) = 0.2;
 
   // compute locally injective map
-  igl::lim::lim(
-    V1,V0,F,C,b,energyType,1e-8,100,true,true,barriersEnabled,true,-1,-1);
+  lim(V1,V0,F,C,b,energyType,1e-8,100,true,true,barriersEnabled,true,-1,-1);
 
   // Show mesh
   igl::viewer::Viewer viewer;

+ 1 - 0
tutorial/CMakeLists.txt

@@ -31,6 +31,7 @@ find_package(MOSEK QUIET)
 find_package(TETGEN QUIET)
 find_package(TINYXML2 QUIET)
 find_package(TRIANGLE QUIET)
+find_package(LIM QUIET)
 
 message(STATUS "CMAKE_CXX_FLAGS: ${CMAKE_CXX_FLAGS}")
 include("CMakeLists.shared")

+ 3 - 0
tutorial/cmake/FindLIM.cmake

@@ -9,6 +9,7 @@ FIND_PATH(LIM_INCLUDE_DIR LIMSolverInterface.h
    /usr/include
    /usr/local/include
    ${PROJECT_SOURCE_DIR}/../libigl/external/lim/
+   ${PROJECT_SOURCE_DIR}/../external/lim/
    ${PROJECT_SOURCE_DIR}/../../external/lim/
    NO_DEFAULT_PATH
 )
@@ -33,6 +34,8 @@ set(
   ${LIM_INCLUDE_DIR}/GreenStrain_LIMSolver3D.cpp
   ${LIM_INCLUDE_DIR}/LSConformal_LIMSolver2D.cpp
   ${LIM_INCLUDE_DIR}/Poisson_LIMSolver2D.cpp
+  ${LIM_INCLUDE_DIR}/Identity_LIMSolver2D.cpp
+  ${LIM_INCLUDE_DIR}/Identity_LIMSolver3D.cpp
   )
 
 SET(LIM_FOUND "NO")