Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Registration/ClosestPointRegistrationForceField.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ class SOFA_REGISTRATION_API ClosestPointRegistrationForceField : public core::be
void addForce(const core::MechanicalParams* /*mparams*/,DataVecDeriv& f , const DataVecCoord& x , const DataVecDeriv& v) override;
void addDForce(const core::MechanicalParams* mparams ,DataVecDeriv& df , const DataVecDeriv& dx) override;
SReal getPotentialEnergy(const core::MechanicalParams* ,const DataVecCoord&) const override { return m_potentialEnergy; }
void addKToMatrix( const core::MechanicalParams* mparams,const sofa::core::behavior::MultiMatrixAccessor* matrix) override;
void addKToMatrix(sofa::linearalgebra::BaseMatrix * matrix, SReal kFact, unsigned int & offset) override;

Real getStiffness() const{ return ks.getValue(); }
Real getDamping() const{ return kd.getValue(); }
Expand Down
11 changes: 4 additions & 7 deletions src/Registration/ClosestPointRegistrationForceField.inl
Original file line number Diff line number Diff line change
Expand Up @@ -387,18 +387,15 @@ void ClosestPointRegistrationForceField<DataTypes>::addDForce(const core::Mechan
}

template<class DataTypes>
void ClosestPointRegistrationForceField<DataTypes>::addKToMatrix(const core::MechanicalParams* mparams,const sofa::core::behavior::MultiMatrixAccessor* matrix)
void ClosestPointRegistrationForceField<DataTypes>::addKToMatrix(sofa::linearalgebra::BaseMatrix * matrix, SReal kFact, unsigned int & offset)
{
Real k = (Real)sofa::core::mechanicalparams::kFactorIncludingRayleighDamping(mparams, this->rayleighStiffness.getValue()) * this->ks.getValue();
if(!k) return;
sofa::core::behavior::MultiMatrixAccessor::MatrixRef mref = matrix->getMatrix(this->mstate);
sofa::linearalgebra::BaseMatrix *mat = mref.matrix;
const int offset = (int)mref.offset;
if(!kFact)
return;
const int N = Coord::total_size;
const int nb = this->closestPos.size();
for (int index = 0; index < nb; index++)
for(int i = 0; i < N; i++)
mat->add(offset + N * index + i, offset + N * index + i, -k);
matrix->add(offset + N * index + i, offset + N * index + i, -kFact);
}

template<class DataTypes>
Expand Down
2 changes: 1 addition & 1 deletion src/Registration/IntensityProfileRegistrationForceField.h
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ class IntensityProfileRegistrationForceField : public core::behavior::ForceField
void addForce(const core::MechanicalParams* /*mparams*/,DataVecDeriv& f , const DataVecCoord& x , const DataVecDeriv& v) override;
void addDForce(const core::MechanicalParams* mparams ,DataVecDeriv& df , const DataVecDeriv& dx) override;
SReal getPotentialEnergy(const core::MechanicalParams* ,const DataVecCoord&) const override { return m_potentialEnergy; }
void addKToMatrix( const core::MechanicalParams* mparams,const sofa::core::behavior::MultiMatrixAccessor* matrix) override;
void addKToMatrix(sofa::linearalgebra::BaseMatrix * matrix, SReal kFact, unsigned int &offset) override;

Real getStiffness() const{ return ks.getValue(); }
Real getDamping() const{ return kd.getValue(); }
Expand Down
14 changes: 6 additions & 8 deletions src/Registration/IntensityProfileRegistrationForceField.inl
Original file line number Diff line number Diff line change
Expand Up @@ -438,13 +438,11 @@ void IntensityProfileRegistrationForceField<DataTypes,ImageTypes>::addDForce(con


template<class DataTypes,class ImageTypes>
void IntensityProfileRegistrationForceField<DataTypes,ImageTypes>::addKToMatrix(const core::MechanicalParams* mparams,const sofa::core::behavior::MultiMatrixAccessor* matrix)
void IntensityProfileRegistrationForceField<DataTypes,ImageTypes>::addKToMatrix(sofa::linearalgebra::BaseMatrix * matrix, SReal kFactor, unsigned int &offset)
{
Real k = (Real)sofa::core::mechanicalparams::kFactorIncludingRayleighDamping(mparams, this->rayleighStiffness.getValue()) * this->ks.getValue();
if(!k) return;
sofa::core::behavior::MultiMatrixAccessor::MatrixRef mref = matrix->getMatrix(this->mstate);
sofa::linearalgebra::BaseMatrix *mat = mref.matrix;
const int offset = (int)mref.offset;
if(!kFactor)
return;

const int N = Coord::total_size;
const int nb = this->targetPos.size();

Expand All @@ -453,13 +451,13 @@ void IntensityProfileRegistrationForceField<DataTypes,ImageTypes>::addKToMatrix(
for (int index = 0; index <nb; index++)
for(int i = 0; i < N; i++)
for(int j = 0; j < N; j++)
mat->add(offset + N * index + i, offset + N * index + j, -k*this->dfdx[index][i][j]);
matrix->add(offset + N * index + i, offset + N * index + j, -kFactor*this->dfdx[index][i][j]);
}
else
{
for (int index = 0; index <nb; index++)
for(int i = 0; i < N; i++)
mat->add(offset + N * index + i, offset + N * index + i, -k);
matrix->add(offset + N * index + i, offset + N * index + i, -kFactor);
}

}
Expand Down
Loading