1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277
|
/*=========================================================================
*
* Copyright NumFOCUS
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0.txt
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*=========================================================================*/
#ifndef itkRigid3DPerspectiveTransform_h
#define itkRigid3DPerspectiveTransform_h
#include "itkMacro.h"
#include "vnl/vnl_quaternion.h"
#include <iostream>
#include "itkTransform.h"
#include "itkVersor.h"
namespace itk
{
/** \brief Rigid3DTramsform of a vector space (e.g. space coordinates)
*
* This transform applies a rotation and translation to the 3D space
* followed by a projection to 2D space along the Z axis.
*
* \ingroup ITKTransform
*/
template <typename TParametersValueType = double>
class ITK_TEMPLATE_EXPORT Rigid3DPerspectiveTransform : public Transform<TParametersValueType, 3, 2>
{
public:
ITK_DISALLOW_COPY_AND_MOVE(Rigid3DPerspectiveTransform);
/** Dimension of the domain space. */
static constexpr unsigned int InputSpaceDimension = 3;
static constexpr unsigned int OutputSpaceDimension = 2;
/** Dimension of parameters. */
static constexpr unsigned int SpaceDimension = 3;
static constexpr unsigned int ParametersDimension = 6;
/** Standard class type aliases. */
using Self = Rigid3DPerspectiveTransform;
using Superclass = Transform<TParametersValueType, Self::InputSpaceDimension, Self::OutputSpaceDimension>;
using Pointer = SmartPointer<Self>;
using ConstPointer = SmartPointer<const Self>;
/** \see LightObject::GetNameOfClass() */
itkOverrideGetNameOfClassMacro(Rigid3DPerspectiveTransform);
/** New macro for creation of through a Smart Pointer. */
itkNewMacro(Self);
/** Scalar type. */
using typename Superclass::ScalarType;
/** Parameters type. */
using typename Superclass::FixedParametersType;
using FixedParametersValueType = typename FixedParametersType::ValueType;
using typename Superclass::ParametersType;
using ParametersValueType = typename ParametersType::ValueType;
/** Jacobian types. */
using typename Superclass::JacobianType;
using typename Superclass::JacobianPositionType;
using typename Superclass::InverseJacobianPositionType;
/** Standard matrix type for this class. */
using MatrixType = Matrix<TParametersValueType, Self::InputSpaceDimension, Self::InputSpaceDimension>;
/** Standard vector type for this class. */
using OffsetType = Vector<TParametersValueType, Self::InputSpaceDimension>;
using OffsetValueType = typename OffsetType::ValueType;
/** Standard vector type for this class. */
using InputVectorType = Vector<TParametersValueType, Self::InputSpaceDimension>;
using OutputVectorType = Vector<TParametersValueType, Self::OutputSpaceDimension>;
/** Standard covariant vector type for this class */
using typename Superclass::InputCovariantVectorType;
using typename Superclass::OutputCovariantVectorType;
/** Standard coordinate point type for this class. */
using InputPointType = Point<TParametersValueType, Self::InputSpaceDimension>;
using OutputPointType = Point<TParametersValueType, Self::OutputSpaceDimension>;
/** Standard vnl_quaternion type. */
using VnlQuaternionType = vnl_quaternion<TParametersValueType>;
/** Standard vnl_vector type for this class. */
using typename Superclass::InputVnlVectorType;
using typename Superclass::OutputVnlVectorType;
/** Versor type. */
using VersorType = Versor<TParametersValueType>;
using AxisType = typename VersorType::VectorType;
using AngleType = typename VersorType::ValueType;
using AxisValueType = typename AxisType::ValueType;
/** Get offset of an Rigid3DPerspectiveTransform
* This method returns the value of the offset of the
* Rigid3DPerspectiveTransform. */
const OffsetType &
GetOffset() const
{
return m_Offset;
}
/** Get rotation from an Rigid3DPerspectiveTransform.
* This method returns the value of the rotation of the
* Rigid3DPerspectiveTransform. */
const VersorType &
GetRotation() const
{
return m_Versor;
}
/** Set/Get the transformation from a container of parameters.
* This is typically used by optimizers.
* There are 6 parameters. The first three represent the
* versor and the last three represents the offset. */
void
SetParameters(const ParametersType & parameters) override;
const ParametersType &
GetParameters() const override;
/** Set the fixed parameters and update internal
* transformation. This transform has no fixed parameters
*/
void
SetFixedParameters(const FixedParametersType &) override
{}
/** This method sets the offset of an Rigid3DPerspectiveTransform to a
* value specified by the user. */
void
SetOffset(const OffsetType & offset)
{
m_Offset = offset;
return;
}
/** This method sets the rotation of an Rigid3DPerspectiveTransform to a
* value specified by the user. */
void
SetRotation(const VersorType & rotation);
/** Set Rotation of the Rigid transform.
* This method sets the rotation of an Rigid3DTransform to a
* value specified by the user using the axis of rotation an
* the angle. */
void
SetRotation(const Vector<TParametersValueType, 3> & axis, double angle);
/** Set the Focal Distance of the projection
* This method sets the focal distance for the perspective
* projection to a value specified by the user. */
void
SetFocalDistance(TParametersValueType focalDistance)
{
m_FocalDistance = focalDistance;
}
/** Return the Focal Distance */
double
GetFocalDistance() const
{
return m_FocalDistance;
}
/** Transform by a Rigid3DPerspectiveTransform. This method
* applies the transform given by self to a
* given point, returning the transformed point. */
OutputPointType
TransformPoint(const InputPointType & point) const override;
/** These vector transforms are not implemented for this transform */
using Superclass::TransformVector;
OutputVectorType
TransformVector(const InputVectorType &) const override
{
itkExceptionMacro("TransformVector(const InputVectorType &) is not implemented for Rigid3DPerspectiveTransform");
}
OutputVnlVectorType
TransformVector(const InputVnlVectorType &) const override
{
itkExceptionMacro(
<< "TransformVector(const InputVnlVectorType &) is not implemented for Rigid3DPerspectiveTransform");
}
using Superclass::TransformCovariantVector;
OutputCovariantVectorType
TransformCovariantVector(const InputCovariantVectorType &) const override
{
itkExceptionMacro("TransformCovariantVector(const InputCovariantVectorType &) is not implemented for "
"Rigid3DPerspectiveTransform");
}
/** Return the rotation matrix */
const MatrixType &
GetRotationMatrix() const
{
return m_RotationMatrix;
}
/** Compute the matrix. */
void
ComputeMatrix();
/** Compute the Jacobian Matrix of the transformation at one point,
* allowing for thread-safety. */
void
ComputeJacobianWithRespectToParameters(const InputPointType & p, JacobianType & jacobian) const override;
void
ComputeJacobianWithRespectToPosition(const InputPointType &, JacobianPositionType &) const override
{
itkExceptionMacro("ComputeJacobianWithRespectToPosition not yet implemented "
"for "
<< this->GetNameOfClass());
}
using Superclass::ComputeJacobianWithRespectToPosition;
/** Set a fixed offset: this allow to center the object to be transformed */
itkGetConstReferenceMacro(FixedOffset, OffsetType);
itkSetMacro(FixedOffset, OffsetType);
/** Set the center of Rotation */
itkSetMacro(CenterOfRotation, InputPointType);
itkGetConstReferenceMacro(CenterOfRotation, InputPointType);
protected:
Rigid3DPerspectiveTransform();
~Rigid3DPerspectiveTransform() override = default;
void
PrintSelf(std::ostream & os, Indent indent) const override;
private:
/** Offset of the transformation. */
OffsetType m_Offset{};
/** Rotation of the transformation. */
VersorType m_Versor{};
/** Set Focal distance of the projection. */
TParametersValueType m_FocalDistance{};
/** Matrix representation of the rotation. */
MatrixType m_RotationMatrix{};
/** Fixed offset */
OffsetType m_FixedOffset{};
/** Center of rotation */
InputPointType m_CenterOfRotation{};
}; // class Rigid3DPerspectiveTransform:
} // namespace itk
#ifndef ITK_MANUAL_INSTANTIATION
# include "itkRigid3DPerspectiveTransform.hxx"
#endif
#endif /* itkRigid3DPerspectiveTransform_h */
|