Rev | Line | |
---|
[136] | 1 | #include <Eigen/Sparse>
|
---|
| 2 | #include <vector>
|
---|
| 3 |
|
---|
| 4 | typedef Eigen::SparseMatrix<double> SpMat; // declares a column-major sparse matrix type of double
|
---|
| 5 | typedef Eigen::Triplet<double> T;
|
---|
| 6 |
|
---|
| 7 | void buildProblem(std::vector<T>& coefficients, Eigen::VectorXd& b, int n);
|
---|
| 8 | void saveAsBitmap(const Eigen::VectorXd& x, int n, const char* filename);
|
---|
| 9 |
|
---|
| 10 | int main(int argc, char** argv)
|
---|
| 11 | {
|
---|
| 12 | int n = 300; // size of the image
|
---|
| 13 | int m = n*n; // number of unknows (=number of pixels)
|
---|
| 14 |
|
---|
| 15 | // Assembly:
|
---|
| 16 | std::vector<T> coefficients; // list of non-zeros coefficients
|
---|
| 17 | Eigen::VectorXd b(m); // the right hand side-vector resulting from the constraints
|
---|
| 18 | buildProblem(coefficients, b, n);
|
---|
| 19 |
|
---|
| 20 | SpMat A(m,m);
|
---|
| 21 | A.setFromTriplets(coefficients.begin(), coefficients.end());
|
---|
| 22 |
|
---|
| 23 | // Solving:
|
---|
| 24 | Eigen::SimplicialCholesky<SpMat> chol(A); // performs a Cholesky factorization of A
|
---|
| 25 | Eigen::VectorXd x = chol.solve(b); // use the factorization to solve for the given right hand side
|
---|
| 26 |
|
---|
| 27 | // Export the result to a file:
|
---|
| 28 | saveAsBitmap(x, n, argv[1]);
|
---|
| 29 |
|
---|
| 30 | return 0;
|
---|
| 31 | }
|
---|
| 32 |
|
---|
Note:
See
TracBrowser
for help on using the repository browser.