Procházet zdrojové kódy

Some version compiles.

Former-commit-id: 10e8eb898e7755f76a81272ce6837a4f8b357a04
Amir Vaxman před 7 roky
rodič
revize
3624dbec2a

+ 10 - 11
include/igl/shapeup.cpp

@@ -14,8 +14,6 @@
 #include <Eigen/Core>
 #include <vector>
 
-
-
 namespace igl
 {
     template <
@@ -104,15 +102,14 @@ namespace igl
         return min_quad_with_fixed_precompute(sudata.Q,VectorXi(),SparseMatrix<double>(),true,sudata.solver_data);
     }
     
-    
-    
+
     template <
     typename Derivedbc,
     typename DerivedP>
     IGL_INLINE bool shapeup_solve(const Eigen::PlainObjectBase<Derivedbc>& bc,
-                                    const Eigen::PlainObjectBase<DerivedP>& P0,
-                                    const ShapeupData & sudata,
-                                    Eigen::PlainObjectBase<DerivedP>& P)
+                                  const Eigen::PlainObjectBase<DerivedP>& P0,
+                                  const ShapeupData & sudata,
+                                  Eigen::PlainObjectBase<DerivedP>& P)
     {
         using namespace Eigen;
         using namespace std;
@@ -150,8 +147,10 @@ namespace igl
 }
 
 
-/*#ifdef IGL_STATIC_LIBRARY
-template bool igl::shapeup_precomputation<Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, 1, 0, -1, 1> >(Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> > const&, int, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, 1, 0, -1, 1> > const&, igl::ARAPData&);
-template bool igl::shapeup_solve<Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<double, -1, -1, 0, -1, -1> >(Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&, igl::ARAPData&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> >&);
 
-#endif*/
+
+#ifdef IGL_STATIC_LIBRARY
+template bool igl::shapeup_precomputation<Eigen::Matrix<double, -1, -1, 0, -1, -1> ,Eigen::Matrix<int, -1, -1, 0, -1, 1> ,Eigen::Matrix<int, -1, -1, 0, -1, -1> ,Eigen::Matrix<int, -1, -1, 0, -1, 1> ,Eigen::Matrix<double, -1, -1, 0, -1, 1> >(const Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> >& P, const Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, 1> >& SC,const Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> >& S, const Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> >& E, const Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, 1> >& b, const Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, 1> >& w, const std::function<bool(const Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> >&, const Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, 1> >&, const Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> >&,  Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> >&)>& local_projection, igl::ShapeupData & sudata);
+
+template bool igl::shapeup_solve<typename Eigen::Matrix<double, -1, -1, 0, -1, -1>, typename Eigen::Matrix<double, -1, -1, 0, -1, -1> >(const Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> >& bc, const Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> >& P0, const igl::ShapeupData & sudata, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> >& P);
+#endif

+ 1 - 1
include/igl/shapeup.h

@@ -99,7 +99,7 @@ namespace igl
     template <
     typename Derivedbc,
     typename DerivedP>
-    IGL_INLINE void shapeup_solve(const Eigen::PlainObjectBase<Derivedbc>& bc,
+    IGL_INLINE bool shapeup_solve(const Eigen::PlainObjectBase<Derivedbc>& bc,
                                    const Eigen::PlainObjectBase<DerivedP>& P0,
                                     const ShapeupData & sudata,
                                     Eigen::PlainObjectBase<DerivedP>& P);

+ 78 - 0
include/igl/shapeup_local_projections.cpp

@@ -0,0 +1,78 @@
+// This file is part of libigl, a simple c++ geometry processing library.
+//
+// Copyright (C) 2017 Amir Vaxman <avaxman@gmail.com>
+//
+// This Source Code Form is subject to the terms of the Mozilla Public License
+// v. 2.0. If a copy of the MPL was not distributed with this file, You can
+// obtain one at http://mozilla.org/MPL/2.0/.
+
+#include <igl/shapeup_local_projections.h>
+#include <igl/igl_inline.h>
+#include <igl/setdiff.h>
+#include <igl/cat.h>
+#include <Eigen/Core>
+#include <vector>
+
+
+//This file implements several basic local projection functions for the shapeup algorithm in shapeup.h
+
+namespace igl
+{
+    
+    //This projection does nothing but render points into projP. Mostly used for "echoing" the global step
+    IGL_INLINE bool shapeup_identity_projection(const Eigen::MatrixXd& P, const Eigen::VectorXi& SC, const Eigen::MatrixXi& S,  Eigen::MatrixXd& projP){
+        projP.conservativeResize(SC.rows(), 3*SC.maxCoeff());
+        for (int i=0;i<S.rows();i++){
+            Eigen::RowVector3d avgCurrP=Eigen::RowVector3d::Zero();
+            for (int j=0;j<SC(i);j++)
+                avgCurrP+=P.row(S(i,j))/(double)(SC(i));
+            
+            for (int j=0;j<SC(i);j++)
+                projP.block(i,3*j,1,3)=P.row(S(i,j))-avgCurrP;
+        }
+        return true;
+    }
+    
+    
+    //the projection assumes that the sets are vertices of polygons in order
+    IGL_INLINE bool shapeup_regular_face_projection(const Eigen::MatrixXd& P, const Eigen::VectorXi& SC, const Eigen::MatrixXi& S,  Eigen::MatrixXd& projP){
+        projP.conservativeResize(SC.rows(), 3*SC.maxCoeff());
+        for (int currRow=0;currRow<SC.rows();currRow++){
+            //computing average
+            int N=SC(currRow);
+            const Eigen::RowVectorXi SRow=S.row(currRow);
+            Eigen::RowVector3d avgCurrP=Eigen::RowVector3d::Zero();
+            Eigen::MatrixXd targetPolygon(N, 3);
+            Eigen::MatrixXd sourcePolygon(N, 3);
+            for (int j=0;j<N;j++)
+                avgCurrP+=P.row(SRow(j))/(double)(N);
+            
+            for (int j=0;j<N;j++)
+                targetPolygon.row(j)=P.row(SRow(j))-avgCurrP;
+            
+            //creating perfectly regular source polygon
+            for (int j=0;j<N;j++)
+                sourcePolygon.row(j)<<cos(2*M_PI*(double)j/(double(N))), sin(2*M_PI*(double)j/(double(N))),0.0;
+            
+            //finding closest similarity transformation between source and target
+            Eigen::MatrixXd corrMat=sourcePolygon.transpose()*targetPolygon;
+            Eigen::JacobiSVD<Eigen::Matrix3d> svd(corrMat, Eigen::ComputeFullU | Eigen::ComputeFullV);
+            Eigen::MatrixXd R=svd.matrixU()*svd.matrixV().transpose();
+            //getting scale by edge length change average. TODO: by singular values
+            Eigen::VectorXd sourceEdgeLengths(N);
+            Eigen::VectorXd targetEdgeLengths(N);
+            for (int j=0;j<N;j++){
+                sourceEdgeLengths(j)=(sourcePolygon.row((j+1)%N)-sourcePolygon.row(j)).norm();
+                targetEdgeLengths(j)=(targetPolygon.row((j+1)%N)-targetPolygon.row(j)).norm();
+            }
+            double scale=(targetEdgeLengths.cwiseQuotient(sourceEdgeLengths)).mean();
+            
+            for (int j=0;j<N;j++)
+                projP.block(currRow,3*j,1,3)=sourcePolygon.row(j)*R*scale;
+        }
+        
+        return true;
+    }
+    
+}
+

+ 2 - 51
include/igl/shapeup_local_projections.h

@@ -21,59 +21,10 @@ namespace igl
 {
     
     //This projection does nothing but render points into projP. Mostly used for "echoing" the global step
-    bool shapeup_identity_projection(const Eigen::MatrixXd& P, const Eigen::VectorXi& SC, const Eigen::MatrixXi& S,  Eigen::MatrixXd& projP){
-        projP.conservativeResize(SC.rows(), 3*SC.maxCoeff());
-        for (int i=0;i<S.rows();i++){
-            Eigen::RowVector3d avgCurrP=Eigen::RowVector3d::Zero();
-            for (int j=0;j<SC(i);j++)
-                avgCurrP+=P.row(S(i,j))/(double)(SC(i));
-            
-            for (int j=0;j<SC(i);j++)
-                projP.block(i,3*j,1,3)=P.row(S(i,j))-avgCurrP;
-        }
-    }
-    
+    IGL_INLINE bool shapeup_identity_projection(const Eigen::MatrixXd& P, const Eigen::VectorXi& SC, const Eigen::MatrixXi& S,  Eigen::MatrixXd& projP);
     
     //the projection assumes that the sets are vertices of polygons in order
-    IGL_INLINE void shapeup_regular_face_projection(const Eigen::MatrixXd& P, const Eigen::VectorXi& SC, const Eigen::MatrixXi& S,  Eigen::MatrixXd& projP)
-    {
-        projP.conservativeResize(SC.rows(), 3*SC.maxCoeff());
-        for (int currRow=0;currRow<SC.rows();currRow++){
-            //computing average
-            int N=SC(currRow);
-            const Eigen::RowVectorXi SRow=S.row(currRow);
-            Eigen::RowVector3d avgCurrP=Eigen::RowVector3d::Zero();
-            Eigen::MatrixXd targetPolygon(N, 3);
-            Eigen::MatrixXd sourcePolygon(N, 3);
-            for (int j=0;j<N;j++)
-                avgCurrP+=P.row(SRow(j))/(double)(N);
-            
-            for (int j=0;j<N;j++)
-                targetPolygon.row(j)=P.row(SRow(j))-avgCurrP;
-            
-            //creating perfectly regular source polygon
-            for (int j=0;j<N;j++)
-                sourcePolygon.row(j)<<cos(2*M_PI*(double)j/(double(N))), sin(2*M_PI*(double)j/(double(N))),0.0;
-            
-            //finding closest similarity transformation between source and target
-            Eigen::MatrixXd corrMat=sourcePolygon.transpose()*targetPolygon;
-            Eigen::JacobiSVD<Eigen::Matrix3d> svd(corrMat, Eigen::ComputeFullU | Eigen::ComputeFullV);
-            Eigen::MatrixXd R=svd.matrixU()*svd.matrixV().transpose();
-            //getting scale by edge length change average. TODO: by singular values
-            Eigen::VectorXd sourceEdgeLengths(N);
-            Eigen::VectorXd targetEdgeLengths(N);
-            for (int j=0;j<N;j++){
-                sourceEdgeLengths(j)=(sourcePolygon.row((j+1)%N)-sourcePolygon.row(j)).norm();
-                targetEdgeLengths(j)=(targetPolygon.row((j+1)%N)-targetPolygon.row(j)).norm();
-            }
-            double scale=(targetEdgeLengths.cwiseQuotient(sourceEdgeLengths)).mean();
-            
-            for (int j=0;j<N;j++)
-                projP.block(currRow,3*j,1,3)=sourcePolygon.row(j)*R*scale;
-        }
-        
-        
-    }
+    IGL_INLINE bool shapeup_regular_face_projection(const Eigen::MatrixXd& P, const Eigen::VectorXi& SC, const Eigen::MatrixXi& S,  Eigen::MatrixXd& projP);
     
 }
 

+ 5 - 4
tutorial/801_ShapeUp/main.cpp

@@ -111,14 +111,15 @@ int main(int argc, char *argv[])
   E.col(1)<<FQC.col(1),FQC.col(2),FQC.col(3),FQC.col(0);
     
   VectorXi b;
-  VectorXi w(FQC.rows());
-  VectorXd bc;
+  VectorXd w(FQC.rows());
+  MatrixXd bc;
     
   VectorXi array_of_fours=VectorXi::Constant(FQC.rows(),4);
     cout<<"before pre-computation"<<endl;
-    shapeup_precomputation(VQC, array_of_fours,FQC,E,b,w, std::function<bool(const MatrixXd&, const VectorXi&, const MatrixXi&, MatrixXd&)>(igl::shapeup_identity_projection),su_data);
+    std::function<bool(const MatrixXd&, const VectorXi&, const MatrixXi&, MatrixXd&)> localFunction=std::function<bool(const MatrixXd&, const VectorXi&, const MatrixXi&, MatrixXd&)>(igl::shapeup_identity_projection);
+    //shapeup_precomputation(VQC, array_of_fours,FQC,E,b,w, localFunction,su_data);
     cout<<"after pre-computation"<<endl;
-  shapeup_solve(bc,VQC,su_data,VQCregular);
+    shapeup_solve(bc,VQC,su_data,VQCregular);
     cout<<"after computation"<<endl;