diff --git a/SCHNApps/CMakeLists.txt b/SCHNApps/CMakeLists.txt index 220dd4aff456c28e18524a6f1b5952cc188214ce..203b84a8a1141541c81cefd97e9745f434ba91a8 100644 --- a/SCHNApps/CMakeLists.txt +++ b/SCHNApps/CMakeLists.txt @@ -17,6 +17,7 @@ find_package(GLEW REQUIRED) find_package(Qt4 REQUIRED) find_package(QGLViewer REQUIRED) find_package(PythonLibs 2.7 REQUIRED) +find_package(SuiteSparse REQUIRED) SET( QT_USE_QTOPENGL TRUE ) SET( QT_USE_QTXML TRUE ) @@ -66,6 +67,7 @@ SET (EXT_INCLUDES ${QT_INCLUDE_DIR} ${QGLVIEWER_INCLUDE_DIR} ${PYTHON_INCLUDE_DIRS} + ${SUITESPARSE_INCLUDE_DIRS} ) # define libs for external libs @@ -81,6 +83,7 @@ SET (EXT_LIBS ${QT_LIBRARIES} ${QGLVIEWER_LIBRARIES} ${PYTHON_LIBRARIES} + ${SUITESPARSE_LIBRARIES} ) diff --git a/SCHNApps/bin/init.py b/SCHNApps/bin/init.py index 78779e6b4165bca3c97c508e3f8d47bf1d9b6bdf..0b19f79a31c2685150ea44a26dc636ba1a4bfa1d 100644 --- a/SCHNApps/bin/init.py +++ b/SCHNApps/bin/init.py @@ -5,7 +5,7 @@ differentialPropertiesPlugin = schnapps.loadPlugin("DifferentialProperties"); subdivisionPlugin = schnapps.loadPlugin("SubdivideSurface"); surfaceDeformationPlugin = schnapps.loadPlugin("SurfaceDeformation"); -obj = importPlugin.importFromFile("/home/kraemer/Media/Data/surface/midRes/camel_10k.off"); +obj = importPlugin.importFromFile("/home/kraemer/Media/Data/surface/lowRes/iphi_good_9k.off"); v = schnapps.getView("view_0"); diff --git a/SCHNApps/src/main.cpp b/SCHNApps/src/main.cpp index 18367da8573ced619aac58778820fa2894240a75..b2bb6472c34a1544da1cce78e9caee22e6f775df 100644 --- a/SCHNApps/src/main.cpp +++ b/SCHNApps/src/main.cpp @@ -1,11 +1,9 @@ - #include #include "window.h" #include #include "PythonQt/PythonQt.h" #include "PythonQt/gui/PythonQtScriptingConsole.h" - int main(int argc, char* argv[]) { QApplication app(argc, argv); diff --git a/ThirdParty/include/OpenNL/cholesky_solver.h b/ThirdParty/include/OpenNL/cholesky_solver.h index 3ba0c8bddbaa7606745356b95adb9bddd8014785..8c6219347af01708d83bbf92de817bf8e2593e33 100644 --- a/ThirdParty/include/OpenNL/cholesky_solver.h +++ b/ThirdParty/include/OpenNL/cholesky_solver.h @@ -32,7 +32,7 @@ #define __CHOLESKY_SOLVER__ #include -#include "cholmod.h" +#include template class Solver_CHOLESKY @@ -58,43 +58,41 @@ public: // assert(A_in.has_symmetric_storage()) ; N = A_in.rows() ; -// int NNZ = A_in.nonZeros() ; // Translate sparse matrix into cholmod format -// cholmod_sparse* A = cholmod_allocate_sparse(N, N, NNZ, false, true, -1, CHOLMOD_REAL, &c); + int NNZ = A_in.nonZeros() ; + cholmod_sparse* A = cholmod_allocate_sparse(N, N, NNZ, false, true, -1, CHOLMOD_REAL, &c); -// int* colptr = static_cast(A->p) ; -// int* rowind = static_cast(A->i) ; -// double* a = static_cast(A->x) ; + int* colptr = static_cast(A->p) ; + int* rowind = static_cast(A->i) ; + double* a = static_cast(A->x) ; // Convert local Matrix into CHOLMOD Matrix -// int count = 0 ; -// for(int j = 0; j < N; j++) { -// const typename SparseMatrix::Column& Cj = A_in.column(j) ; -// colptr[j] = count ; -// for(unsigned int ii = 0; ii < Cj.nb_coeffs(); ii++) { -// a[count] = Cj.coeff(ii).a ; -// rowind[count] = Cj.coeff(ii).index ; -// count++ ; -// } -// } -// colptr[N] = NNZ ; - - cholmod_sparse A = Eigen::viewAsCholmod(A_in); + int count = 0 ; + for(int j = 0; j < N; j++) { + colptr[j] = count; + for(typename Eigen::SparseMatrix::InnerIterator it(A_in, j); it; ++it) + { + a[count] = it.value(); + rowind[count] = it.row(); + ++count; + } + } + colptr[N] = NNZ ; // Factorize - L = cholmod_analyze(&A, &c) ; - cholmod_factorize(&A, L, &c) ; + L = cholmod_analyze(A, &c) ; + cholmod_factorize(A, L, &c) ; factorized_ = true ; // Cleanup -// cholmod_free_sparse(&A, &c) ; + cholmod_free_sparse(&A, &c) ; } - void solve(const VECTOR& b_in, VECTOR& x_out) { + void solve(const Eigen::Matrix& b_in, Eigen::Matrix& x_out) { assert(factorized_) ; - assert(L->n == b_in.dimension()) ; - assert(L->n == x_out.dimension()) ; + assert(L->n == b_in.rows()) ; + assert(L->n == x_out.rows()) ; // Translate right-hand side into cholmod format cholmod_dense* b = cholmod_allocate_dense(N, 1, N, CHOLMOD_REAL, &c) ; @@ -111,8 +109,8 @@ public: x_out[i] = cx[i] ; // Cleanup - cholmod_free_dense(&x, &c) ; cholmod_free_dense(&b, &c) ; + cholmod_free_dense(&x, &c) ; } void reset() { diff --git a/ThirdParty/include/OpenNL/linear_solver.h b/ThirdParty/include/OpenNL/linear_solver.h index 1cf12db3811d377e0855e15ea9d90a6779bd7b48..1f719ab5d5ba13317cd3fab2d103fdb2c5b7e7eb 100644 --- a/ThirdParty/include/OpenNL/linear_solver.h +++ b/ThirdParty/include/OpenNL/linear_solver.h @@ -36,10 +36,8 @@ #include #include -//#include "cholesky_solver.h" - -#include #include +#include "cholesky_solver.h" template @@ -83,7 +81,7 @@ public: delete A_ ; delete x_ ; delete b_ ; -// delete direct_solver_ ; + delete direct_solver_ ; } // __________________ Parameters ________________________ @@ -191,13 +189,7 @@ private: Eigen::Matrix* x_ ; Eigen::Matrix* b_ ; -// Solver_CHOLESKY* direct_solver_; - - Eigen::LDLT >* direct_solver_; - -// Eigen::ConjugateGradient >* symmetric_solver_; -// Eigen::BiCGSTAB >* nonsymmetric_solver_; -// Eigen::SimplicialLDLT >* direct_solver_; + Solver_CHOLESKY* direct_solver_ ; } ; #include "OpenNL/linear_solver.hpp" diff --git a/ThirdParty/include/OpenNL/linear_solver.hpp b/ThirdParty/include/OpenNL/linear_solver.hpp index c5110f34040f60807ea75b6f00d72c9b8a26ad18..e56f766feb3bbf11acf7448013a93f4cd8a15fb6 100644 --- a/ThirdParty/include/OpenNL/linear_solver.hpp +++ b/ThirdParty/include/OpenNL/linear_solver.hpp @@ -33,9 +33,7 @@ LinearSolver::LinearSolver(unsigned int nb_variables) { A_ = NULL ; x_ = NULL ; b_ = NULL ; -// symmetric_solver_ = NULL; -// nonsymmetric_solver_ = NULL; - direct_solver_ = NULL; + direct_solver_ = new Solver_CHOLESKY() ; } template @@ -138,7 +136,7 @@ void LinearSolver::end_row() { if(!matrix_already_set_) { for(unsigned int i = 0; i < nf; i++) { for(unsigned int j = 0; j < nf; j++) { - A_->coeffRef(if_[i], if_[j]) += af_[i] * af_[j]; + A_->coeffRef(if_[i], if_[j]) += af_[i] * af_[j] ; } } } @@ -156,11 +154,11 @@ void LinearSolver::end_row() { // Construct the matrix coefficients of the current row if(!matrix_already_set_) { for(unsigned int i = 0; i < nf; i++) { - A_->coeffRef(current_row_, if_[i]) += af_[i]; + A_->coeffRef(current_row_, if_[i]) += af_[i] ; } } // Construct the right-hand side of the current row - (*b_)[current_row_] = bk_ ; + (*b_)[current_row_] = -bk_ ; for(unsigned int i = 0; i < nl; i++) { (*b_)[current_row_] -= al_[i] * xl_[i] ; } @@ -171,13 +169,10 @@ void LinearSolver::end_row() { template void LinearSolver::end_system() { - if(least_squares_ && direct_ && !direct_solver_) - direct_solver_ = new Eigen::LDLT >(*A_); + if(least_squares_ && direct_ && !direct_solver_->factorized()) + direct_solver_->factorize(*A_) ; -// if(least_squares_ && direct_ && !direct_solver_->factorized()) -// direct_solver_->factorize(*A_); - - transition(IN_SYSTEM, CONSTRUCTED) ; + transition(IN_SYSTEM, CONSTRUCTED) ; } template @@ -186,45 +181,48 @@ void LinearSolver::solve() { if(least_squares_) { if(direct_) { - *x_ = direct_solver_->solve(*b_) ; + direct_solver_->solve(*b_, *x_) ; } else { - Eigen::ConjugateGradient > solver(*A_) ; + Eigen::ConjugateGradient solver(*A_) ; +// int n = x_->rows() ; +// Eigen::Matrix guess(n) ; +// for(int i = 0; i < n; ++i) +// guess[i] = (*x_)[i] ; +// *x_ = solver.solveWithGuess(*b_, guess) ; *x_ = solver.solve(*b_) ; } } else { - Eigen::BiCGSTAB > solver(*A_) ; + Eigen::BiCGSTAB solver(*A_) ; *x_ = solver.solve(*b_) ; } + vector_to_variables() ; transition(CONSTRUCTED, SOLVED) ; } template void LinearSolver::reset(bool keep_matrix) { - if(keep_matrix) { - x_->setZero(); - b_->setZero(); - matrix_already_set_ = true ; - } else { - delete A_ ; A_ = NULL ; - delete x_ ; x_ = NULL ; - delete b_ ; b_ = NULL ; -// if(symmetric_solver_) delete symmetric_solver_ ; symmetric_solver_ = NULL ; -// if(nonsymmetric_solver_) delete nonsymmetric_solver_ ; nonsymmetric_solver_ = NULL ; - if(direct_solver_) delete direct_solver_ ; direct_solver_ = NULL ; -// direct_solver_->reset(); - matrix_already_set_ = false ; - for(unsigned int i = 0; i < nb_variables_; ++i) { - variable_[i].unlock() ; - } - } + if(keep_matrix) { + x_->setZero() ; + b_->setZero() ; + matrix_already_set_ = true ; + } else { + delete A_ ; A_ = NULL ; + delete x_ ; x_ = NULL ; + delete b_ ; b_ = NULL ; + direct_solver_->reset(); + matrix_already_set_ = false ; + for(unsigned int i = 0; i < nb_variables_; ++i) { + variable_[i].unlock() ; + } + } state_ = INITIAL ; } template void LinearSolver::vector_to_variables() { for(unsigned int i=0; i < nb_variables(); i++) { - Variable& v = variable(i) ; + Variable& v = variable(i) ; if(!v.is_locked()) { v.set_value((*x_)[v.index()]) ; } @@ -234,7 +232,7 @@ void LinearSolver::vector_to_variables() { template void LinearSolver::variables_to_vector() { for(unsigned int i=0; i < nb_variables(); i++) { - Variable& v = variable(i) ; + Variable& v = variable(i) ; if(!v.is_locked()) { (*x_)[v.index()] = v.value() ; }