Skip to content

Commit cf862ff

Browse files
alxbilgerfredroy
andauthored
[Projective] Avoid template method specialization in AffineMovementProjectiveConstraint (#6156)
* [Projective] Avoid template method specialization in AffineMovementProjectiveConstraint * Data access by reference Co-authored-by: Frederick Roy <fredroy@users.noreply.github.com> * fix typo --------- Co-authored-by: Frederick Roy <fredroy@users.noreply.github.com>
1 parent 409db6b commit cf862ff

2 files changed

Lines changed: 27 additions & 28 deletions

File tree

Sofa/Component/Constraint/Projective/src/sofa/component/constraint/projective/AffineMovementProjectiveConstraint.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@ class AffineMovementProjectiveConstraint : public core::behavior::ProjectiveCons
6464
typedef Data<VecDeriv> DataVecDeriv;
6565
typedef type::vector<Index> SetIndexArray;
6666
typedef sofa::core::topology::TopologySubsetIndices SetIndex;
67-
typedef type::Quat<SReal> Quat;
68-
typedef type::Vec3 Vec3;
67+
typedef type::Quat<Real> Quat;
68+
typedef type::Vec<3,Real> Vec3;
6969

7070
typedef typename DataTypes::MatrixDeriv MatrixDeriv;
7171
typedef core::objectmodel::Data<MatrixDeriv> DataMatrixDeriv;

Sofa/Component/Constraint/Projective/src/sofa/component/constraint/projective/AffineMovementProjectiveConstraint.inl

Lines changed: 25 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -239,36 +239,35 @@ void AffineMovementProjectiveConstraint<DataTypes>::initializeInitialPositions (
239239
}
240240
}
241241

242-
243-
template <>
244-
void AffineMovementProjectiveConstraint<defaulttype::Rigid3Types>::transform(const SetIndexArray & indices,
245-
defaulttype::Rigid3Types::VecCoord& x0,
246-
defaulttype::Rigid3Types::VecCoord& xf)
247-
{
248-
// Get quaternion and translation values
249-
RotationMatrix rotationMat(0);
250-
const Quat quat = d_quaternion.getValue();
251-
quat.toMatrix(rotationMat);
252-
const Vec3 translation = d_translation.getValue();
253-
254-
// Apply transformation
255-
for (size_t i=0; i < indices.size() ; ++i)
256-
{
257-
// Translation
258-
xf[indices[i]].getCenter() = rotationMat*(x0[indices[i]].getCenter()) + translation;
259-
// Rotation
260-
xf[indices[i]].getOrientation() = (quat)+x0[indices[i]].getOrientation();
261-
}
262-
}
263-
264242
template <class DataTypes>
265243
void AffineMovementProjectiveConstraint<DataTypes>::transform(const SetIndexArray & indices, VecCoord& x0, VecCoord& xf)
266244
{
267-
Vec3 translation = d_translation.getValue();
268-
269-
for (size_t i=0; i < indices.size() ; ++i)
245+
if constexpr (type::isRigidType<DataTypes>)
270246
{
271-
DataTypes::setCPos(xf[indices[i]], (d_rotation.getValue()) * DataTypes::getCPos(x0[indices[i]]) + translation);
247+
// Get quaternion and translation values
248+
RotationMatrix rotationMat(0);
249+
const Quat& quat = d_quaternion.getValue();
250+
quat.toMatrix(rotationMat);
251+
const Vec3& translation = d_translation.getValue();
252+
253+
// Apply transformation
254+
for (size_t i=0; i < indices.size() ; ++i)
255+
{
256+
// Translation
257+
xf[indices[i]].getCenter() = rotationMat*(x0[indices[i]].getCenter()) + translation;
258+
// Rotation
259+
xf[indices[i]].getOrientation() = (quat)+x0[indices[i]].getOrientation();
260+
}
261+
}
262+
else
263+
{
264+
const auto& translation = d_translation.getValue();
265+
const auto& rotation = d_rotation.getValue();
266+
267+
for (size_t i=0; i < indices.size() ; ++i)
268+
{
269+
DataTypes::setCPos(xf[indices[i]], rotation * DataTypes::getCPos(x0[indices[i]]) + translation);
270+
}
272271
}
273272
}
274273

0 commit comments

Comments
 (0)