Skip to content

Commit

Permalink
STYLE: [Versor|VersorRigid3D]TransformOptimizer same
Browse files Browse the repository at this point in the history
Make the two nearly identical classes formatted
as close to the same as possible.  This reveals
that the two classes are nearly identical.

The next patch set will remove the
VersorRigid3D specialization.
  • Loading branch information
hjmjohnson committed Oct 20, 2022
1 parent da1229d commit c461bdd
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,20 @@ namespace itk
* \brief Implement a gradient descent optimizer for the VersorRigid3DTransform
* parameter space.
*
* VersorRigid3DTransformOptimizer is a variant of the gradient descent
* optimizer implemented in RegularStepGradientDescentOptimizer.
* VersorRigid3DTransformOptimizer is a variant of the
* gradient descent optimizer implemented in
* RegularStepGradientDescentOptimizer.
*
* Versors are not in a vector space, for that reason, the classical gradient
* descent algorithm has to be modified in order to be applicable to Versors
* (unit quaternions) that form the group SO(3).
* Versors are not in a vector space, for that reason,
* the classical gradient descent algorithm has to be
* modified in order to be applicable to Versors (unit
* quaternions) that form the group SO(3).
*
* The Versor space has only three degrees of freedom, even though Versors are
* represented using four values.
* The Versor space has only three degrees of freedom,
* even though Versors are represented using four values.
*
* This optimizer assumes that the CostFunction to be optimized has an
* itk::Versor and an itk::Vector as parameters.
* This optimizer assumes that the CostFunction to be
* optimized has an itk::Versor as parameters.
*
* \sa RegularStepGradientDescentOptimizer
* \sa Versor
Expand All @@ -65,9 +67,6 @@ class ITKOptimizers_EXPORT VersorRigid3DTransformOptimizer : public RegularStepG
/** Run-time type information (and related methods). */
itkTypeMacro(VersorRigid3DTransformOptimizer, RegularStepGradientDescentBaseOptimizer);

/** This class is specialized for 3D */
static constexpr unsigned int SpaceDimension = 6;

/** Versor Type */
using VersorType = Versor<double>;
using VectorType = VersorType::VectorType;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ namespace itk
* even though Versors are represented using four values.
*
* This optimizer assumes that the CostFunction to be
* optimized has an itk::Versor as parameter.
* optimized has an itk::Versor as parameters.
*
* \sa RegularStepGradientDescentOptimizer
* \sa Versor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ namespace itk
void
VersorRigid3DTransformOptimizer::StepAlongGradient(double factor, const DerivativeType & transformedGradient)
{
const ParametersType & currentPosition = this->GetCurrentPosition();
const ParametersType & currentPosition = this->GetCurrentPosition();
static constexpr unsigned int NumberOfParameters = 6;

// The parameters are assumed to be the right part of the versor and the
// components of the translation vector.
Expand Down Expand Up @@ -66,16 +67,17 @@ VersorRigid3DTransformOptimizer::StepAlongGradient(double factor, const Derivati
//
VersorType newRotation = currentRotation * gradientRotation;

ParametersType newParameters(SpaceDimension);
ParametersType newParameters(NumberOfParameters);

newParameters[0] = newRotation.GetX();
newParameters[1] = newRotation.GetY();
newParameters[2] = newRotation.GetZ();

// Now do the typical update for a Vector space.
for (unsigned int k = 3; k < 6; ++k)
// Optimize the non-versor parameters as the
// RegularStepGradientDescentOptimizer
for (unsigned int j = 3; j < NumberOfParameters; ++j)
{
newParameters[k] = currentPosition[k] + transformedGradient[k] * factor;
newParameters[j] = currentPosition[j] + transformedGradient[j] * factor;
}

this->SetCurrentPosition(newParameters);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,10 @@ void
VersorTransformOptimizer::StepAlongGradient(double factor, const DerivativeType & transformedGradient)
{
const ParametersType & currentPosition = this->GetCurrentPosition();
unsigned int NumberOfParameters = m_CostFunction->GetNumberOfParameters();
const unsigned int NumberOfParameters = m_CostFunction->GetNumberOfParameters();

// The parameters are assumed to be the right part of the versor
// The parameters are assumed to be the right part of the versor and the
// components of the translation vector.
//
VectorType rightPart;

Expand Down

0 comments on commit c461bdd

Please sign in to comment.