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
|
/*=========================================================================
*
* Copyright UMC Utrecht and contributors
*
* 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
*
* http://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 itkDeformationFieldRegulizer_hxx
#define itkDeformationFieldRegulizer_hxx
#include "itkDeformationFieldRegulizer.h"
namespace itk
{
/**
* ************************ Constructor *************************
*/
template <class TAnyITKTransform>
DeformationFieldRegulizer<TAnyITKTransform>::DeformationFieldRegulizer()
{
/** Initialize. */
this->m_IntermediaryDeformationFieldTransform = nullptr;
this->m_Initialized = false;
} // end Constructor
/**
* ********* InitializeIntermediaryDeformationField **************
*/
template <class TAnyITKTransform>
void
DeformationFieldRegulizer<TAnyITKTransform>::InitializeDeformationFields()
{
/** Initialize this->m_IntermediaryDeformationFieldTransform. */
this->m_IntermediaryDeformationFieldTransform = IntermediaryDFTransformType::New();
/** Initialize this->m_IntermediaryDeformationField. */
auto intermediaryDeformationField = VectorImageType::New();
intermediaryDeformationField->SetRegions(this->m_DeformationFieldRegion);
intermediaryDeformationField->SetSpacing(this->m_DeformationFieldSpacing);
intermediaryDeformationField->SetOrigin(this->m_DeformationFieldOrigin);
try
{
intermediaryDeformationField->Allocate();
}
catch (itk::ExceptionObject & excp)
{
/** Add information to the exception and throw again. */
excp.SetLocation("DeformationFieldRegulizer - InitializeDeformationFields()");
std::string err_str = excp.GetDescription();
err_str += "\nError occurred while allocating the intermediary deformation field.\n";
excp.SetDescription(err_str);
throw;
}
/** Set everything to zero. */
IteratorType it(intermediaryDeformationField, intermediaryDeformationField->GetLargestPossibleRegion());
VectorPixelType vec;
vec.Fill(ScalarType{});
while (!it.IsAtEnd())
{
it.Set(vec);
++it;
}
/** Set the deformation field in the transform. */
this->m_IntermediaryDeformationFieldTransform->SetCoefficientVectorImage(intermediaryDeformationField);
/** Set to initialized. */
this->m_Initialized = true;
} // end InitializeDeformationFields()
/**
* *********************** TransformPoint ***********************
*/
template <class TAnyITKTransform>
auto
DeformationFieldRegulizer<TAnyITKTransform>::TransformPoint(const InputPointType & inputPoint) const -> OutputPointType
{
/** Get the outputpoint of any ITK Transform and the deformation field. */
OutputPointType oppAnyT, oppDF, opp;
oppAnyT = this->Superclass::TransformPoint(inputPoint);
oppDF = this->m_IntermediaryDeformationFieldTransform->TransformPoint(inputPoint);
/** Add them: don't forget to subtract ipp. */
for (unsigned int i = 0; i < OutputSpaceDimension; ++i)
{
opp[i] = oppAnyT[i] + oppDF[i] - inputPoint[i];
}
/** Return a value. */
return opp;
} // end TransformPoint()
/**
* ******** UpdateIntermediaryDeformationFieldTransform *********
*/
template <class TAnyITKTransform>
void
DeformationFieldRegulizer<TAnyITKTransform>::UpdateIntermediaryDeformationFieldTransform(
typename VectorImageType::Pointer vecImage)
{
/** Set the vecImage (which is allocated elsewhere) and put it in
* IntermediaryDeformationFieldTransform (where it is copied and split up).
*/
this->m_IntermediaryDeformationFieldTransform->SetCoefficientVectorImage(vecImage);
} // end UpdateIntermediaryDeformationFieldTransform()
} // end namespace itk
#endif // end #ifndef itkDeformationFieldRegulizer_hxx
|