1 // This file is part of libigl, a simple c++ geometry processing library.
2 //
3 // Copyright (C) 2013 Alec Jacobson <alecjacobson@gmail.com>
4 //
5 // This Source Code Form is subject to the terms of the Mozilla Public License
6 // v. 2.0. If a copy of the MPL was not distributed with this file, You can
7 // obtain one at http://mozilla.org/MPL/2.0/.
8 #include "covariance_scatter_matrix.h"
9 #include "arap_linear_block.h"
10 #include "cotmatrix.h"
11 #include "diag.h"
12 #include "sum.h"
13 #include "edges.h"
14 #include "verbose.h"
15 #include "cat.h"
16 #include "PI.h"
17 
covariance_scatter_matrix(const Eigen::MatrixXd & V,const Eigen::MatrixXi & F,const ARAPEnergyType energy,Eigen::SparseMatrix<double> & CSM)18 IGL_INLINE void igl::covariance_scatter_matrix(
19   const Eigen::MatrixXd & V,
20   const Eigen::MatrixXi & F,
21   const ARAPEnergyType energy,
22   Eigen::SparseMatrix<double>& CSM)
23 {
24   using namespace Eigen;
25   // number of mesh vertices
26   int n = V.rows();
27   assert(n > F.maxCoeff());
28   // dimension of mesh
29   int dim = V.cols();
30   // Number of mesh elements
31   int m = F.rows();
32 
33   // number of rotations
34   int nr;
35   switch(energy)
36   {
37     case ARAP_ENERGY_TYPE_SPOKES:
38       nr = n;
39       break;
40     case ARAP_ENERGY_TYPE_SPOKES_AND_RIMS:
41       nr = n;
42       break;
43     case ARAP_ENERGY_TYPE_ELEMENTS:
44       nr = m;
45       break;
46     default:
47       fprintf(
48         stderr,
49         "covariance_scatter_matrix.h: Error: Unsupported arap energy %d\n",
50         energy);
51       return;
52   }
53 
54   SparseMatrix<double> KX,KY,KZ;
55   arap_linear_block(V,F,0,energy,KX);
56   arap_linear_block(V,F,1,energy,KY);
57   SparseMatrix<double> Z(n,nr);
58   if(dim == 2)
59   {
60     CSM = cat(1,cat(2,KX,Z),cat(2,Z,KY)).transpose();
61   }else if(dim == 3)
62   {
63     arap_linear_block(V,F,2,energy,KZ);
64     SparseMatrix<double>ZZ(n,nr*2);
65     CSM =
66       cat(1,cat(1,cat(2,KX,ZZ),cat(2,cat(2,Z,KY),Z)),cat(2,ZZ,KZ)).transpose();
67   }else
68   {
69     fprintf(
70      stderr,
71      "covariance_scatter_matrix.h: Error: Unsupported dimension %d\n",
72      dim);
73     return;
74   }
75 
76 }
77