Browse Source

move scaf to triangle folder

Zhongshi 5 years ago
parent
commit
07e2b01a3c

+ 42 - 41
include/igl/scaf.cpp → include/igl/triangle/scaf.cpp

@@ -7,41 +7,41 @@
 // obtain one at http://mozilla.org/MPL/2.0/.
 // obtain one at http://mozilla.org/MPL/2.0/.
 
 
 #include "scaf.h"
 #include "scaf.h"
+#include "triangulate.h"
 
 
 #include <Eigen/Dense>
 #include <Eigen/Dense>
 #include <Eigen/IterativeLinearSolvers>
 #include <Eigen/IterativeLinearSolvers>
 #include <Eigen/Sparse>
 #include <Eigen/Sparse>
 #include <Eigen/SparseCholesky>
 #include <Eigen/SparseCholesky>
 #include <Eigen/SparseQR>
 #include <Eigen/SparseQR>
-#include <igl/PI.h>
-#include <igl/Timer.h>
-#include <igl/boundary_loop.h>
-#include <igl/cat.h>
-#include <igl/doublearea.h>
-#include <igl/flip_avoiding_line_search.h>
-#include <igl/flipped_triangles.h>
-#include <igl/grad.h>
-#include <igl/harmonic.h>
-#include <igl/local_basis.h>
-#include <igl/map_vertices_to_circle.h>
-#include <igl/polar_svd.h>
-#include <igl/slice.h>
-#include <igl/slice_into.h>
-#include <igl/slim.h>
-#include <igl/triangle/triangulate.h>
-#include "mapping_energy_with_jacobians.h"
-
-#include <iostream>
+#include "../PI.h"
+#include "../Timer.h"
+#include "../boundary_loop.h"
+#include "../cat.h"
+#include "../doublearea.h"
+#include "../flip_avoiding_line_search.h"
+#include "../flipped_triangles.h"
+#include "../grad.h"
+#include "../harmonic.h"
+#include "../local_basis.h"
+#include "../map_vertices_to_circle.h"
+#include "../polar_svd.h"
+#include "../slice.h"
+#include "../slice_into.h"
+#include "../slim.h"
+#include "../mapping_energy_with_jacobians.h"
+
 #include <map>
 #include <map>
 #include <algorithm>
 #include <algorithm>
 #include <set>
 #include <set>
 #include <vector>
 #include <vector>
 namespace igl
 namespace igl
 {
 {
-
+namespace triangle
+{
 namespace scaf
 namespace scaf
 {
 {
-IGL_INLINE void update_scaffold(igl::SCAFData &s)
+IGL_INLINE void update_scaffold(igl::triangle::SCAFData &s)
 {
 {
   s.mv_num = s.m_V.rows();
   s.mv_num = s.m_V.rows();
   s.mf_num = s.m_T.rows();
   s.mf_num = s.m_T.rows();
@@ -137,7 +137,7 @@ IGL_INLINE void compute_scaffold_gradient_matrix(SCAFData &s,
        F2.col(2).asDiagonal() * Dz;
        F2.col(2).asDiagonal() * Dz;
 }
 }
 
 
-IGL_INLINE void mesh_improve(igl::SCAFData &s)
+IGL_INLINE void mesh_improve(igl::triangle::SCAFData &s)
 {
 {
   using namespace Eigen;
   using namespace Eigen;
   MatrixXd m_uv = s.w_uv.topRows(s.mv_num);
   MatrixXd m_uv = s.w_uv.topRows(s.mv_num);
@@ -245,7 +245,7 @@ IGL_INLINE void mesh_improve(igl::SCAFData &s)
   s.W_s.resize(s.Dx_s.rows(), s.dim * s.dim);
   s.W_s.resize(s.Dx_s.rows(), s.dim * s.dim);
 }
 }
 
 
-IGL_INLINE void add_new_patch(igl::SCAFData &s, const Eigen::MatrixXd &V_ref,
+IGL_INLINE void add_new_patch(igl::triangle::SCAFData &s, const Eigen::MatrixXd &V_ref,
                    const Eigen::MatrixXi &F_ref,
                    const Eigen::MatrixXi &F_ref,
                    const Eigen::RowVectorXd &center,
                    const Eigen::RowVectorXd &center,
                    const Eigen::MatrixXd &uv_init)
                    const Eigen::MatrixXd &uv_init)
@@ -617,14 +617,15 @@ IGL_INLINE double perform_iteration(SCAFData &s)
          s.mesh_measure;
          s.mesh_measure;
 }
 }
 
 
+}
 }
 }
 }
 }
 
 
-IGL_INLINE void igl::scaf_precompute(
+IGL_INLINE void igl::triangle::scaf_precompute(
     const Eigen::MatrixXd &V,
     const Eigen::MatrixXd &V,
     const Eigen::MatrixXi &F,
     const Eigen::MatrixXi &F,
     const Eigen::MatrixXd &V_init,
     const Eigen::MatrixXd &V_init,
-    igl::SCAFData &data,
+    igl::triangle::SCAFData &data,
     igl::MappingEnergyType slim_energy,
     igl::MappingEnergyType slim_energy,
     Eigen::VectorXi &b,
     Eigen::VectorXi &b,
     Eigen::MatrixXd &bc,
     Eigen::MatrixXd &bc,
@@ -632,7 +633,7 @@ IGL_INLINE void igl::scaf_precompute(
 {
 {
   Eigen::MatrixXd CN;
   Eigen::MatrixXd CN;
   Eigen::MatrixXi FN;
   Eigen::MatrixXi FN;
-  igl::scaf::add_new_patch(data, V, F, Eigen::RowVector2d(0, 0), V_init);
+  igl::triangle::scaf::add_new_patch(data, V, F, Eigen::RowVector2d(0, 0), V_init);
   data.soft_const_p = soft_p;
   data.soft_const_p = soft_p;
   for (int i = 0; i < b.rows(); i++)
   for (int i = 0; i < b.rows(); i++)
     data.soft_cons[b(i)] = bc.row(i);
     data.soft_cons[b(i)] = bc.row(i);
@@ -664,7 +665,7 @@ IGL_INLINE void igl::scaf_precompute(
     s.Dx_m = face_proj(F1) * G;
     s.Dx_m = face_proj(F1) * G;
     s.Dy_m = face_proj(F2) * G;
     s.Dy_m = face_proj(F2) * G;
 
 
-    igl::scaf::compute_scaffold_gradient_matrix(s, s.Dx_s, s.Dy_s);
+    igl::triangle::scaf::compute_scaffold_gradient_matrix(s, s.Dx_s, s.Dy_s);
 
 
     s.Dx_m.makeCompressed();
     s.Dx_m.makeCompressed();
     s.Dy_m.makeCompressed();
     s.Dy_m.makeCompressed();
@@ -682,48 +683,48 @@ IGL_INLINE void igl::scaf_precompute(
   }
   }
 }
 }
 
 
-IGL_INLINE Eigen::MatrixXd igl::scaf_solve(SCAFData &s, int iter_num)
+IGL_INLINE Eigen::MatrixXd igl::triangle::scaf_solve(igl::triangle::SCAFData &s, int iter_num)
 {
 {
   using namespace std;
   using namespace std;
   using namespace Eigen;
   using namespace Eigen;
-  s.energy = igl::scaf::compute_energy(s, s.w_uv, false) / s.mesh_measure;
+  s.energy = igl::triangle::scaf::compute_energy(s, s.w_uv, false) / s.mesh_measure;
 
 
   for (int it = 0; it < iter_num; it++)
   for (int it = 0; it < iter_num; it++)
   {
   {
-    s.total_energy = igl::scaf::compute_energy(s, s.w_uv, true) / s.mesh_measure;
+    s.total_energy = igl::triangle::scaf::compute_energy(s, s.w_uv, true) / s.mesh_measure;
     s.rect_frame_V = Eigen::MatrixXd();
     s.rect_frame_V = Eigen::MatrixXd();
-    igl::scaf::mesh_improve(s);
+    igl::triangle::scaf::mesh_improve(s);
 
 
     double new_weight = s.mesh_measure * s.energy / (s.sf_num * 100);
     double new_weight = s.mesh_measure * s.energy / (s.sf_num * 100);
     s.scaffold_factor = new_weight;
     s.scaffold_factor = new_weight;
-    igl::scaf::update_scaffold(s);
+    igl::triangle::scaf::update_scaffold(s);
 
 
-    s.total_energy = igl::scaf::perform_iteration(s);
+    s.total_energy = igl::triangle::scaf::perform_iteration(s);
 
 
     s.energy =
     s.energy =
-        igl::scaf::compute_energy(s, s.w_uv, false) / s.mesh_measure;
+        igl::triangle::scaf::compute_energy(s, s.w_uv, false) / s.mesh_measure;
   }
   }
 
 
   return s.w_uv.topRows(s.mv_num);
   return s.w_uv.topRows(s.mv_num);
 }
 }
 
 
-IGL_INLINE void igl::scaf_system(SCAFData &s, Eigen::SparseMatrix<double> &L, Eigen::VectorXd &rhs)
+IGL_INLINE void igl::triangle::scaf_system(igl::triangle::SCAFData &s, Eigen::SparseMatrix<double> &L, Eigen::VectorXd &rhs)
 {
 {
-    s.energy = igl::scaf::compute_energy(s, s.w_uv, false) / s.mesh_measure;
+    s.energy = igl::triangle::scaf::compute_energy(s, s.w_uv, false) / s.mesh_measure;
 
 
-    s.total_energy = igl::scaf::compute_energy(s, s.w_uv, true) / s.mesh_measure;
+    s.total_energy = igl::triangle::scaf::compute_energy(s, s.w_uv, true) / s.mesh_measure;
     s.rect_frame_V = Eigen::MatrixXd();
     s.rect_frame_V = Eigen::MatrixXd();
-    igl::scaf::mesh_improve(s);
+    igl::triangle::scaf::mesh_improve(s);
 
 
     double new_weight = s.mesh_measure * s.energy / (s.sf_num * 100);
     double new_weight = s.mesh_measure * s.energy / (s.sf_num * 100);
     s.scaffold_factor = new_weight;
     s.scaffold_factor = new_weight;
-    igl::scaf::update_scaffold(s);
+    igl::triangle::scaf::update_scaffold(s);
 
 
-    igl::scaf::compute_jacobians(s, s.w_uv, true);
+    igl::triangle::scaf::compute_jacobians(s, s.w_uv, true);
     igl::slim_update_weights_and_closest_rotations_with_jacobians(s.Ji_m, s.slim_energy, 0, s.W_m, s.Ri_m);
     igl::slim_update_weights_and_closest_rotations_with_jacobians(s.Ji_m, s.slim_energy, 0, s.W_m, s.Ri_m);
     igl::slim_update_weights_and_closest_rotations_with_jacobians(s.Ji_s, s.scaf_energy, 0, s.W_s, s.Ri_s);
     igl::slim_update_weights_and_closest_rotations_with_jacobians(s.Ji_s, s.scaf_energy, 0, s.W_s, s.Ri_s);
 
 
-    igl::scaf::build_weighted_arap_system(s, L, rhs);
+    igl::triangle::scaf::build_weighted_arap_system(s, L, rhs);
 }
 }
 
 
 #ifdef IGL_STATIC_LIBRARY
 #ifdef IGL_STATIC_LIBRARY

+ 9 - 6
include/igl/scaf.h → include/igl/triangle/scaf.h

@@ -8,12 +8,14 @@
 #ifndef IGL_SCAF_H
 #ifndef IGL_SCAF_H
 #define IGL_SCAF_H
 #define IGL_SCAF_H
 
 
-#include "slim.h"
-#include "igl_inline.h"
-#include "MappingEnergyType.h"
+#include "../slim.h"
+#include "../igl_inline.h"
+#include "../MappingEnergyType.h"
 
 
 namespace igl
 namespace igl
 {
 {
+  namespace triangle
+  {
     // Use a similar interface to igl::slim
     // Use a similar interface to igl::slim
     // Implement ready-to-use 2D version of the algorithm described in 
     // Implement ready-to-use 2D version of the algorithm described in 
     // SCAF: Simplicial Complex Augmentation Framework for Bijective Maps
     // SCAF: Simplicial Complex Augmentation Framework for Bijective Maps
@@ -81,7 +83,7 @@ namespace igl
         const Eigen::MatrixXd &V,
         const Eigen::MatrixXd &V,
         const Eigen::MatrixXi &F,
         const Eigen::MatrixXi &F,
         const Eigen::MatrixXd &V_init,
         const Eigen::MatrixXd &V_init,
-        SCAFData &data,
+        triangle::SCAFData &data,
         MappingEnergyType slim_energy,
         MappingEnergyType slim_energy,
         Eigen::VectorXi& b,
         Eigen::VectorXi& b,
         Eigen::MatrixXd& bc,
         Eigen::MatrixXd& bc,
@@ -90,7 +92,7 @@ namespace igl
     // Run iter_num iterations of SCAF, with precomputed data
     // Run iter_num iterations of SCAF, with precomputed data
     // Outputs:
     // Outputs:
     //    V_o (in SLIMData): #V by dim list of mesh vertex positions
     //    V_o (in SLIMData): #V by dim list of mesh vertex positions
-    IGL_INLINE Eigen::MatrixXd scaf_solve(SCAFData &data, int iter_num);
+    IGL_INLINE Eigen::MatrixXd scaf_solve(triangle::SCAFData &data, int iter_num);
 
 
     // Set up the SCAF system L * uv = rhs, without solving it.
     // Set up the SCAF system L * uv = rhs, without solving it.
     // Inputs:
     // Inputs:
@@ -99,7 +101,7 @@ namespace igl
     //    L:   m by m matrix
     //    L:   m by m matrix
     //    rhs: m by 1 vector
     //    rhs: m by 1 vector
     //         with m = dim * (#V_mesh + #V_scaf - #V_frame)
     //         with m = dim * (#V_mesh + #V_scaf - #V_frame)
-    IGL_INLINE void scaf_system(SCAFData &s, Eigen::SparseMatrix<double> &L, Eigen::VectorXd &rhs);
+    IGL_INLINE void scaf_system(triangle::SCAFData &s, Eigen::SparseMatrix<double> &L, Eigen::VectorXd &rhs);
 
 
     namespace scaf
     namespace scaf
     {
     {
@@ -110,6 +112,7 @@ namespace igl
         //    whole: Include scaffold if true
         //    whole: Include scaffold if true
         IGL_INLINE double compute_energy(SCAFData &s, const Eigen::MatrixXd &w_uv, bool whole);
         IGL_INLINE double compute_energy(SCAFData &s, const Eigen::MatrixXd &w_uv, bool whole);
     }
     }
+  }
 }
 }
 
 
 #ifndef IGL_STATIC_LIBRARY
 #ifndef IGL_STATIC_LIBRARY

+ 8 - 0
tests/CMakeLists.txt

@@ -95,6 +95,14 @@ if(LIBIGL_WITH_PREDICATES)
   target_link_libraries(libigl_tests PUBLIC igl::predicates igl::triangle)
   target_link_libraries(libigl_tests PUBLIC igl::predicates igl::triangle)
 endif()
 endif()
 
 
+if(LIBIGL_WITH_TRIANGLE)
+  file(GLOB TEST_SRC_FILES ./include/igl/triangle/*.cpp)
+  file(GLOB TEST_INC_FILES ./include/igl/triangle/*.h ./include/igl/triangle/*.inl)
+  target_sources(libigl_tests PRIVATE ${TEST_SRC_FILES} ${TEST_INC_FILES})
+
+  target_link_libraries(libigl_tests PUBLIC igl::triangle)
+endif()
+
 file(GLOB TEST_SRC_FILES ./include/igl/*.cpp)
 file(GLOB TEST_SRC_FILES ./include/igl/*.cpp)
 file(GLOB TEST_INC_FILES ./include/igl/*.h ./include/igl/*.inl)
 file(GLOB TEST_INC_FILES ./include/igl/*.h ./include/igl/*.inl)
 target_sources(libigl_tests PRIVATE ${TEST_SRC_FILES} ${TEST_INC_FILES})
 target_sources(libigl_tests PRIVATE ${TEST_SRC_FILES} ${TEST_INC_FILES})

+ 8 - 8
tests/include/igl/scaf.cpp → tests/include/igl/triangle/scaf.cpp

@@ -1,6 +1,6 @@
 #include <test_common.h>
 #include <test_common.h>
 #include <igl/cat.h>
 #include <igl/cat.h>
-#include <igl/scaf.h>
+#include <igl/triangle/scaf.h>
 #include <igl/slice.h>
 #include <igl/slice.h>
 #include <igl/harmonic.h>
 #include <igl/harmonic.h>
 #include <igl/boundary_loop.h>
 #include <igl/boundary_loop.h>
@@ -36,20 +36,20 @@ TEST_CASE("scaf_system: Test scaf_system() vs scaf_solve()", "[igl]")
   Eigen::MatrixXd bc;
   Eigen::MatrixXd bc;
 
 
   // Run one scaf iteration as reference
   // Run one scaf iteration as reference
-  igl::SCAFData s_ref;
+  igl::triangle::SCAFData s_ref;
   {
   {
-      igl::scaf_precompute(V, F, uv_init, s_ref, igl::MappingEnergyType::SYMMETRIC_DIRICHLET, b, bc, 0);
-      igl::scaf_solve(s_ref, 1);
+      igl::triangle::scaf_precompute(V, F, uv_init, s_ref, igl::MappingEnergyType::SYMMETRIC_DIRICHLET, b, bc, 0);
+      igl::triangle::scaf_solve(s_ref, 1);
   }
   }
 
 
   // Obtain SCAF linear system perform iteration manually
   // Obtain SCAF linear system perform iteration manually
-  igl::SCAFData s_test;
+  igl::triangle::SCAFData s_test;
   {
   {
       // Set up system
       // Set up system
-      igl::scaf_precompute(V, F, uv_init, s_test, igl::MappingEnergyType::SYMMETRIC_DIRICHLET, b, bc, 0);
+      igl::triangle::scaf_precompute(V, F, uv_init, s_test, igl::MappingEnergyType::SYMMETRIC_DIRICHLET, b, bc, 0);
       Eigen::SparseMatrix<double> L;
       Eigen::SparseMatrix<double> L;
       Eigen::VectorXd rhs;
       Eigen::VectorXd rhs;
-      igl::scaf_system(s_test, L, rhs);
+      igl::triangle::scaf_system(s_test, L, rhs);
 
 
       // Solve
       // Solve
       Eigen::SimplicialLDLT<Eigen::SparseMatrix<double>> solver;
       Eigen::SimplicialLDLT<Eigen::SparseMatrix<double>> solver;
@@ -69,7 +69,7 @@ TEST_CASE("scaf_system: Test scaf_system() vs scaf_solve()", "[igl]")
       }
       }
 
 
       // Line search
       // Line search
-      auto E = [&s_test](Eigen::MatrixXd &uv) { return igl::scaf::compute_energy(s_test, uv, true); };
+      auto E = [&s_test](Eigen::MatrixXd &uv) { return igl::triangle::scaf::compute_energy(s_test, uv, true); };
       Eigen::MatrixXi w_T;
       Eigen::MatrixXi w_T;
       igl::cat(1, s_test.m_T, s_test.s_T, w_T);
       igl::cat(1, s_test.m_T, s_test.s_T, w_T);
       igl::flip_avoiding_line_search(w_T, s_test.w_uv, uv_target, E, -1);
       igl::flip_avoiding_line_search(w_T, s_test.w_uv, uv_target, E, -1);

+ 4 - 4
tutorial/710_SCAF/main.cpp

@@ -1,4 +1,4 @@
-#include <igl/scaf.h>
+#include <igl/triangle/scaf.h>
 #include <igl/arap.h>
 #include <igl/arap.h>
 #include <igl/boundary_loop.h>
 #include <igl/boundary_loop.h>
 #include <igl/harmonic.h>
 #include <igl/harmonic.h>
@@ -18,7 +18,7 @@ Eigen::MatrixXd V;
 Eigen::MatrixXi F;
 Eigen::MatrixXi F;
 Eigen::MatrixXd V_uv;
 Eigen::MatrixXd V_uv;
 igl::Timer timer;
 igl::Timer timer;
-igl::SCAFData scaf_data;
+igl::triangle::SCAFData scaf_data;
 
 
 bool show_uv = false;
 bool show_uv = false;
 float uv_scale = 0.2f;
 float uv_scale = 0.2f;
@@ -33,7 +33,7 @@ bool key_down(igl::opengl::glfw::Viewer& viewer, unsigned char key, int modifier
   if (key == ' ')
   if (key == ' ')
   {
   {
     timer.start();
     timer.start();
-    igl::scaf_solve(scaf_data, 1);
+    igl::triangle::scaf_solve(scaf_data, 1);
     std::cout << "time = " << timer.getElapsedTime() << std::endl;
     std::cout << "time = " << timer.getElapsedTime() << std::endl;
   }
   }
 
 
@@ -103,7 +103,7 @@ int main(int argc, char *argv[])
   }
   }
 
 
   Eigen::VectorXi b; Eigen::MatrixXd bc;
   Eigen::VectorXi b; Eigen::MatrixXd bc;
-  igl::scaf_precompute(V, F, uv_init, scaf_data, igl::MappingEnergyType::SYMMETRIC_DIRICHLET, b, bc, 0);
+  igl::triangle::scaf_precompute(V, F, uv_init, scaf_data, igl::MappingEnergyType::SYMMETRIC_DIRICHLET, b, bc, 0);
 
 
   // Plot the mesh
   // Plot the mesh
   igl::opengl::glfw::Viewer viewer;
   igl::opengl::glfw::Viewer viewer;

+ 2 - 0
tutorial/CMakeLists.txt

@@ -148,7 +148,9 @@ if(TUTORIALS_CHAPTER7)
   add_subdirectory("707_SweptVolume")
   add_subdirectory("707_SweptVolume")
   add_subdirectory("708_Picking")
   add_subdirectory("708_Picking")
   add_subdirectory("709_SLIM")
   add_subdirectory("709_SLIM")
+  if(LIBIGL_WITH_TRIANGLE)
   add_subdirectory("710_SCAF")
   add_subdirectory("710_SCAF")
+  endif()
   add_subdirectory("711_Subdivision")
   add_subdirectory("711_Subdivision")
   add_subdirectory("712_DataSmoothing")
   add_subdirectory("712_DataSmoothing")
   add_subdirectory("713_ShapeUp")
   add_subdirectory("713_ShapeUp")