@@ -63,7 +63,7 @@ void LegacyCorrespondenceFunction ::ComputeCovarianceMatrix() {
6363
6464 if (this ->m_UseMeanEnergy ) {
6565 pinvMat.set_identity ();
66- m_InverseCovMatrix->clear ();
66+ m_InverseCovMatrix->setZero ();
6767 } else {
6868 gramMat = points_minus_mean.transpose () * points_minus_mean;
6969
@@ -83,7 +83,9 @@ void LegacyCorrespondenceFunction ::ComputeCovarianceMatrix() {
8383 const auto lhs = projMat * invLambda;
8484 const auto rhs =
8585 invLambda * projMat.transpose (); // invLambda doesn't need to be transposed since its a diagonal matrix
86- m_InverseCovMatrix->set_size (num_dims, num_dims);
86+ if (m_InverseCovMatrix->rows () != num_dims || m_InverseCovMatrix->cols () != num_dims) {
87+ m_InverseCovMatrix->resize (num_dims, num_dims);
88+ }
8789 Utils::multiply_into (*m_InverseCovMatrix, lhs, rhs);
8890 }
8991 m_PointsUpdate->update (points_minus_mean * pinvMat);
@@ -108,9 +110,8 @@ void LegacyCorrespondenceFunction ::ComputeCovarianceMatrix() {
108110}
109111
110112LegacyCorrespondenceFunction::VectorType LegacyCorrespondenceFunction ::Evaluate (unsigned int idx, unsigned int d,
111- const ParticleSystem* system,
112- double & maxdt,
113- double & energy) const {
113+ const ParticleSystem* system,
114+ double & maxdt, double & energy) const {
114115 // NOTE: This code requires that indices be contiguous, i.e. it won't work if
115116 // you start deleting particles.
116117 const unsigned int DomainsPerShape = m_ShapeMatrix->GetDomainsPerShape ();
@@ -130,10 +131,18 @@ LegacyCorrespondenceFunction::VectorType LegacyCorrespondenceFunction ::Evaluate
130131
131132 vnl_matrix_type tmp1 (3 , 3 , 0.0 );
132133
133- if (this ->m_UseMeanEnergy )
134+ if (this ->m_UseMeanEnergy ) {
134135 tmp1.set_identity ();
135- else
136- tmp1 = m_InverseCovMatrix->extract (3 , 3 , k, k);
136+ } else {
137+ // extract 3x3 submatrix at k,k
138+ Eigen::MatrixXd region = m_InverseCovMatrix->block (k, k, 3 , 3 );
139+ // convert to vnl
140+ for (unsigned int i = 0 ; i < 3 ; i++) {
141+ for (unsigned int j = 0 ; j < 3 ; j++) {
142+ tmp1 (i, j) = region (i, j);
143+ }
144+ }
145+ }
137146
138147 vnl_matrix_type tmp = Xi.transpose () * tmp1;
139148
0 commit comments