Commit fef6d895 authored by Lionel Untereiner's avatar Lionel Untereiner

Merge cgogn.u-strasbg.fr:~kraemer/CGoGN

parents fc45ade8 601d62f3
......@@ -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}
)
......
......@@ -6,12 +6,17 @@
#include "ui_surfaceDeformation.h"
#include "Utils/drawer.h"
#include "Container/fakeAttribute.h"
#include "OpenNL/linear_solver.h"
#include "Algo/LinearSolving/basic.h"
using namespace CGoGN;
using namespace SCHNApps;
// namespace CGoGN { namespace Utils { class Drawer; } }
enum SelectionMode
{
......@@ -20,6 +25,8 @@ enum SelectionMode
};
typedef NoNameIOAttribute<Eigen::Matrix3f> Eigen_Matrix3f ;
struct PerMapParameterSet
{
PerMapParameterSet() {}
......@@ -32,6 +39,19 @@ struct PerMapParameterSet
SelectionMode verticesSelectionMode;
std::vector<unsigned int> locked_vertices;
std::vector<unsigned int> handle_vertices;
VertexAttribute<PFP2::VEC3> positionInit;
VertexAttribute<PFP2::VEC3> vertexNormal;
EdgeAttribute<PFP2::REAL> edgeAngle;
EdgeAttribute<PFP2::REAL> edgeWeight;
VertexAttribute<PFP2::REAL> vertexArea;
VertexAttribute<PFP2::VEC3> diffCoord;
VertexAttribute<Eigen_Matrix3f> vertexRotationMatrix;
VertexAttribute<PFP2::VEC3> rotatedDiffCoord;
VertexAttribute<unsigned int> vIndex;
unsigned int nb_vertices;
LinearSolver<PFP2::REAL>* solver;
};
struct ParameterSet
......@@ -116,11 +136,14 @@ public slots:
void cb_selectLockedVertices(bool b);
void cb_selectHandleVertices(bool b);
void matchDiffCoord(View* view, MapHandlerGen* map);
void asRigidAsPossible(View* view, MapHandlerGen* map);
private:
SurfaceDeformationDockTab* m_dockTab;
QHash<View*, ParameterSet*> h_viewParams;
Utils::Drawer* m_drawer;
// Utils::Drawer* m_drawer;
bool b_refreshingUI;
......
......@@ -5,15 +5,15 @@ differentialPropertiesPlugin = schnapps.loadPlugin("DifferentialProperties");
subdivisionPlugin = schnapps.loadPlugin("SubdivideSurface");
surfaceDeformationPlugin = schnapps.loadPlugin("SurfaceDeformation");
obj = importPlugin.importFromFile("/home/kraemer/Media/Data/surface/midRes/egea_remesh_9k.off");
#obj = importPlugin.importFromFile("/home/kraemer/Media/Data/surface/lowRes/iphi_good_9k.off");
v = schnapps.getView("view_0");
#v = schnapps.getView("view_0");
schnapps.linkViewAndPlugin(v.getName(), renderPlugin.getName());
schnapps.linkViewAndPlugin(v.getName(), renderVectorPlugin.getName());
schnapps.linkViewAndPlugin(v.getName(), surfaceDeformationPlugin.getName());
#schnapps.linkViewAndPlugin(v.getName(), renderPlugin.getName());
#schnapps.linkViewAndPlugin(v.getName(), renderVectorPlugin.getName());
#schnapps.linkViewAndPlugin(v.getName(), surfaceDeformationPlugin.getName());
schnapps.linkViewAndMap(v.getName(), obj.getName());
#schnapps.linkViewAndMap(v.getName(), obj.getName());
#differentialPropertiesPlugin.computeNormal(obj.getName());
#differentialPropertiesPlugin.computeCurvature(obj.getName());
#include <QSplashScreen>
#include "window.h"
#include <QFileInfo>
#include "PythonQt/PythonQt.h"
#include "PythonQt/gui/PythonQtScriptingConsole.h"
int main(int argc, char* argv[])
{
QApplication app(argc, argv);
......
......@@ -32,17 +32,12 @@
#define __CHOLESKY_SOLVER__
#include <cassert>
#include "OpenNL/sparse_matrix.h"
#include "CHOLMOD/cholmod.h"
#include <cholmod.h>
template< class MATRIX, class VECTOR >
template <typename CoeffType>
class Solver_CHOLESKY
{
public:
typedef MATRIX Matrix ;
typedef VECTOR Vector ;
typedef typename Vector::CoeffType CoeffType ;
Solver_CHOLESKY() {
N = 0 ;
factorized_ = false ;
......@@ -58,14 +53,14 @@ public:
bool factorized() { return factorized_ ; }
void factorize(const MATRIX &A_in) {
assert(A_in.n() == A_in.m()) ;
assert(A_in.has_symmetric_storage()) ;
void factorize(const Eigen::SparseMatrix<CoeffType>& A_in) {
assert(A_in.rows() == A_in.cols()) ;
// assert(A_in.has_symmetric_storage()) ;
N = A_in.n() ;
int NNZ = A_in.nnz() ;
N = A_in.rows() ;
// Translate sparse matrix into cholmod format
int NNZ = A_in.nonZeros() ;
cholmod_sparse* A = cholmod_allocate_sparse(N, N, NNZ, false, true, -1, CHOLMOD_REAL, &c);
int* colptr = static_cast<int*>(A->p) ;
......@@ -75,12 +70,12 @@ public:
// Convert local Matrix into CHOLMOD Matrix
int count = 0 ;
for(int j = 0; j < N; j++) {
const typename SparseMatrix<CoeffType>::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[j] = count;
for(typename Eigen::SparseMatrix<CoeffType>::InnerIterator it(A_in, j); it; ++it)
{
a[count] = it.value();
rowind[count] = it.row();
++count;
}
}
colptr[N] = NNZ ;
......@@ -94,10 +89,10 @@ public:
cholmod_free_sparse(&A, &c) ;
}
void solve(const VECTOR& b_in, VECTOR& x_out) {
void solve(const Eigen::Matrix<CoeffType, Eigen::Dynamic, 1>& b_in, Eigen::Matrix<CoeffType, Eigen::Dynamic, 1>& 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) ;
......@@ -114,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() {
......
......@@ -37,6 +37,7 @@
#include <cstdlib>
#include <Eigen/Sparse>
#include "cholesky_solver.h"
template <class CoeffType>
......@@ -80,7 +81,7 @@ public:
delete A_ ;
delete x_ ;
delete b_ ;
// delete direct_solver_ ;
delete direct_solver_ ;
}
// __________________ Parameters ________________________
......@@ -188,9 +189,7 @@ private:
Eigen::Matrix<CoeffType, Eigen::Dynamic, 1>* x_ ;
Eigen::Matrix<CoeffType, Eigen::Dynamic, 1>* b_ ;
Eigen::ConjugateGradient<Eigen::SparseMatrix<CoeffType> >* symmetric_solver_;
Eigen::BiCGSTAB<Eigen::SparseMatrix<CoeffType> >* nonsymmetric_solver_;
Eigen::SimplicialLDLT<Eigen::SparseMatrix<CoeffType> >* direct_solver_;
Solver_CHOLESKY<CoeffType>* direct_solver_ ;
} ;
#include "OpenNL/linear_solver.hpp"
......
......@@ -33,9 +33,7 @@ LinearSolver<CoeffType>::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<CoeffType>() ;
}
template <typename CoeffType>
......@@ -138,7 +136,7 @@ void LinearSolver<CoeffType>::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<CoeffType>::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,10 +169,10 @@ void LinearSolver<CoeffType>::end_row() {
template <typename CoeffType>
void LinearSolver<CoeffType>::end_system() {
if(least_squares_ && direct_ && !direct_solver_)
direct_solver_ = new Eigen::SimplicialLDLT<Eigen::SparseMatrix<CoeffType> >(*A_);
if(least_squares_ && direct_ && !direct_solver_->factorized())
direct_solver_->factorize(*A_) ;
transition(IN_SYSTEM, CONSTRUCTED) ;
transition(IN_SYSTEM, CONSTRUCTED) ;
}
template <typename CoeffType>
......@@ -183,44 +181,48 @@ void LinearSolver<CoeffType>::solve() {
if(least_squares_)
{
if(direct_) {
*x_ = direct_solver_->solve(*b_) ;
direct_solver_->solve(*b_, *x_) ;
} else {
symmetric_solver_ = new Eigen::ConjugateGradient<Eigen::SparseMatrix<CoeffType> >(*A_) ;
*x_ = symmetric_solver_->solve(*b_) ;
Eigen::ConjugateGradient<Eigen::MatrixXf > solver(*A_) ;
// int n = x_->rows() ;
// Eigen::Matrix<CoeffType, Eigen::Dynamic, 1> guess(n) ;
// for(int i = 0; i < n; ++i)
// guess[i] = (*x_)[i] ;
// *x_ = solver.solveWithGuess(*b_, guess) ;
*x_ = solver.solve(*b_) ;
}
} else {
nonsymmetric_solver_ = new Eigen::BiCGSTAB<Eigen::SparseMatrix<CoeffType> >(*A_) ;
*x_ = nonsymmetric_solver_->solve(*b_) ;
Eigen::BiCGSTAB<Eigen::MatrixXf > solver(*A_) ;
*x_ = solver.solve(*b_) ;
}
vector_to_variables() ;
transition(CONSTRUCTED, SOLVED) ;
}
template <typename CoeffType>
void LinearSolver<CoeffType>::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 ;
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 <typename CoeffType>
void LinearSolver<CoeffType>::vector_to_variables() {
for(unsigned int i=0; i < nb_variables(); i++) {
Variable<CoeffType>& v = variable(i) ;
Variable<CoeffType>& v = variable(i) ;
if(!v.is_locked()) {
v.set_value((*x_)[v.index()]) ;
}
......@@ -230,7 +232,7 @@ void LinearSolver<CoeffType>::vector_to_variables() {
template <typename CoeffType>
void LinearSolver<CoeffType>::variables_to_vector() {
for(unsigned int i=0; i < nb_variables(); i++) {
Variable<CoeffType>& v = variable(i) ;
Variable<CoeffType>& v = variable(i) ;
if(!v.is_locked()) {
(*x_)[v.index()] = v.value() ;
}
......
# - Try to find SUITESPARSE
# Once done this will define
#
# SUITESPARSE_FOUND - system has SUITESPARSE
# SUITESPARSE_INCLUDE_DIRS - the SUITESPARSE include directory
# SUITESPARSE_LIBRARIES - Link these to use SUITESPARSE
# SUITESPARSE_SPQR_LIBRARY - name of spqr library (necessary due to error in debian package)
# SUITESPARSE_SPQR_LIBRARY_DIR - name of spqr library (necessary due to error in debian package)
# SUITESPARSE_LIBRARY_DIR - Library main directory containing suitesparse libs
# SUITESPARSE_LIBRARY_DIRS - all Library directories containing suitesparse libs
# SUITESPARSE_SPQR_VALID - automatic identification whether or not spqr package is installed correctly
IF (SUITESPARSE_INCLUDE_DIRS)
# Already in cache, be silent
SET(SUITESPARSE_FIND_QUIETLY TRUE)
ENDIF (SUITESPARSE_INCLUDE_DIRS)
if( WIN32 )
# Find cholmod part of the suitesparse library collection
FIND_PATH( CHOLMOD_INCLUDE_DIR cholmod.h
PATHS "C:\\libs\\win32\\SuiteSparse\\Include" )
# Add cholmod include directory to collection include directories
IF ( CHOLMOD_INCLUDE_DIR )
list ( APPEND SUITESPARSE_INCLUDE_DIRS ${CHOLMOD_INCLUDE_DIR} )
ENDIF( CHOLMOD_INCLUDE_DIR )
# find path suitesparse library
FIND_PATH( SUITESPARSE_LIBRARY_DIRS
amd.lib
PATHS "C:\\libs\\win32\\SuiteSparse\\libs" )
# if we found the library, add it to the defined libraries
IF ( SUITESPARSE_LIBRARY_DIRS )
list ( APPEND SUITESPARSE_LIBRARIES optimized;amd;optimized;camd;optimized;ccolamd;optimized;cholmod;optimized;colamd;optimized;metis;optimized;spqr;optimized;umfpack;debug;amdd;debug;camdd;debug;ccolamdd;debug;cholmodd;debug;spqrd;debug;umfpackd;debug;colamdd;debug;metisd;optimized;blas;optimized;libf2c;optimized;lapack;debug;blasd;debug;libf2cd;debug;lapackd )
ENDIF( SUITESPARSE_LIBRARY_DIRS )
else( WIN32 )
IF(APPLE)
FIND_PATH( CHOLMOD_INCLUDE_DIR cholmod.h
PATHS /opt/local/include/ufsparse
/usr/local/include )
FIND_PATH( SUITESPARSE_LIBRARY_DIR
NAMES libcholmod.a
PATHS /opt/local/lib
/usr/local/lib )
ELSE(APPLE)
FIND_PATH( CHOLMOD_INCLUDE_DIR cholmod.h
PATHS /usr/local/include
/usr/include
/usr/include/suitesparse/
${CMAKE_SOURCE_DIR}/MacOS/Libs/cholmod
PATH_SUFFIXES cholmod/ CHOLMOD/ )
FIND_PATH( SUITESPARSE_LIBRARY_DIR
NAMES libcholmod.so
PATHS /usr/lib
/usr/lib64
/usr/local/lib )
ENDIF(APPLE)
# Add cholmod include directory to collection include directories
IF ( CHOLMOD_INCLUDE_DIR )
list ( APPEND SUITESPARSE_INCLUDE_DIRS ${CHOLMOD_INCLUDE_DIR} )
ENDIF( CHOLMOD_INCLUDE_DIR )
# if we found the library, add it to the defined libraries
IF ( SUITESPARSE_LIBRARY_DIR )
list ( APPEND SUITESPARSE_LIBRARIES amd)
list ( APPEND SUITESPARSE_LIBRARIES btf)
list ( APPEND SUITESPARSE_LIBRARIES camd)
list ( APPEND SUITESPARSE_LIBRARIES ccolamd)
list ( APPEND SUITESPARSE_LIBRARIES cholmod)
list ( APPEND SUITESPARSE_LIBRARIES colamd)
# list ( APPEND SUITESPARSE_LIBRARIES csparse)
list ( APPEND SUITESPARSE_LIBRARIES cxsparse)
list ( APPEND SUITESPARSE_LIBRARIES klu)
# list ( APPEND SUITESPARSE_LIBRARIES spqr)
list ( APPEND SUITESPARSE_LIBRARIES umfpack)
IF (APPLE)
list ( APPEND SUITESPARSE_LIBRARIES suitesparseconfig)
ENDIF (APPLE)
# Metis and spqr are optional
FIND_LIBRARY( SUITESPARSE_METIS_LIBRARY
NAMES metis
PATHS ${SUITESPARSE_LIBRARY_DIR} )
IF (SUITESPARSE_METIS_LIBRARY)
list ( APPEND SUITESPARSE_LIBRARIES metis)
ENDIF(SUITESPARSE_METIS_LIBRARY)
if(EXISTS "${CHOLMOD_INCLUDE_DIR}/SuiteSparseQR.hpp")
SET(SUITESPARSE_SPQR_VALID TRUE CACHE BOOL "SuiteSparseSPQR valid")
else()
SET(SUITESPARSE_SPQR_VALID false CACHE BOOL "SuiteSparseSPQR valid")
endif()
if(SUITESPARSE_SPQR_VALID)
FIND_LIBRARY( SUITESPARSE_SPQR_LIBRARY
NAMES spqr
PATHS ${SUITESPARSE_LIBRARY_DIR} )
IF (SUITESPARSE_SPQR_LIBRARY)
list ( APPEND SUITESPARSE_LIBRARIES spqr)
ENDIF (SUITESPARSE_SPQR_LIBRARY)
endif()
ENDIF( SUITESPARSE_LIBRARY_DIR )
endif( WIN32 )
IF (SUITESPARSE_INCLUDE_DIRS AND SUITESPARSE_LIBRARIES)
IF(WIN32)
list (APPEND SUITESPARSE_INCLUDE_DIRS ${CHOLMOD_INCLUDE_DIR}/../../UFconfig )
ENDIF(WIN32)
SET(SUITESPARSE_FOUND TRUE)
MESSAGE(STATUS "Found SuiteSparse")
ELSE (SUITESPARSE_INCLUDE_DIRS AND SUITESPARSE_LIBRARIES)
SET( SUITESPARSE_FOUND FALSE )
ENDIF (SUITESPARSE_INCLUDE_DIRS AND SUITESPARSE_LIBRARIES)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment