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 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359
|
/*=========================================================================
*
* 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 _itkImageToImageMetricWithFeatures_hxx
#define _itkImageToImageMetricWithFeatures_hxx
#include "itkImageToImageMetricWithFeatures.h"
namespace itk
{
/**
* ********************* Initialize *****************************
*/
template <class TFixedImage, class TMovingImage, class TFixedFeatureImage, class TMovingFeatureImage>
void
ImageToImageMetricWithFeatures<TFixedImage, TMovingImage, TFixedFeatureImage, TMovingFeatureImage>::Initialize()
{
/** Call the superclass. */
this->Superclass::Initialize();
/** Check the fixed stuff. */
for (unsigned int i = 0; i < m_NumberOfFixedFeatureImages; ++i)
{
/** Check if all the fixed feature images are set. */
if (!this->m_FixedFeatureImages[i])
{
itkExceptionMacro("ERROR: fixed feature image " << i << " is not set.");
}
/** Check if all the fixed feature interpolators are set. */
if (!this->m_FixedFeatureInterpolators[i])
{
itkExceptionMacro("ERROR: fixed feature interpolator " << i << " is not set.");
}
/** Connect the feature image to the interpolator. */
this->m_FixedFeatureInterpolators[i]->SetInputImage(this->m_FixedFeatureImages[i]);
}
/** Check the moving stuff. */
for (unsigned int i = 0; i < m_NumberOfMovingFeatureImages; ++i)
{
/** Check if all the moving feature images are set. */
if (!this->m_MovingFeatureImages[i])
{
itkExceptionMacro("ERROR: moving feature image " << i << " is not set.");
}
/** Check if all the moving feature interpolators are set. */
if (!this->m_MovingFeatureInterpolators[i])
{
itkExceptionMacro("ERROR: moving feature interpolator " << i << " is not set.");
}
/** Connect the feature image to the interpolator. */
this->m_MovingFeatureInterpolators[i]->SetInputImage(this->m_MovingFeatureImages[i]);
}
/** Check if the moving feature image interpolators are B-spline interpolators. */
this->CheckForBSplineFeatureInterpolators();
} // end Initialize()
/**
* ********************* SetNumberOfFixedFeatureImages ****************************
*/
template <class TFixedImage, class TMovingImage, class TFixedFeatureImage, class TMovingFeatureImage>
void
ImageToImageMetricWithFeatures<TFixedImage, TMovingImage, TFixedFeatureImage, TMovingFeatureImage>::
SetNumberOfFixedFeatureImages(unsigned int arg)
{
if (this->m_NumberOfFixedFeatureImages != arg)
{
this->m_FixedFeatureImages.resize(arg);
this->m_FixedFeatureInterpolators.resize(arg);
this->m_NumberOfFixedFeatureImages = arg;
this->Modified();
}
} // end SetNumberOfFixedFeatureImages()
/**
* ********************* SetFixedFeatureImage ****************************
*/
template <class TFixedImage, class TMovingImage, class TFixedFeatureImage, class TMovingFeatureImage>
void
ImageToImageMetricWithFeatures<TFixedImage, TMovingImage, TFixedFeatureImage, TMovingFeatureImage>::
SetFixedFeatureImage(unsigned int i, FixedFeatureImageType * im)
{
if (i + 1 > this->m_NumberOfFixedFeatureImages)
{
this->m_FixedFeatureImages.resize(i + 1);
this->m_FixedFeatureImages[i] = im;
this->m_NumberOfFixedFeatureImages = i;
this->Modified();
}
else
{
if (this->m_FixedFeatureImages[i] != im)
{
this->m_FixedFeatureImages[i] = im;
this->Modified();
}
}
} // end SetFixedFeatureImage()
/**
* ********************* GetFixedFeatureImage ****************************
*/
template <class TFixedImage, class TMovingImage, class TFixedFeatureImage, class TMovingFeatureImage>
const typename ImageToImageMetricWithFeatures<TFixedImage, TMovingImage, TFixedFeatureImage, TMovingFeatureImage>::
FixedFeatureImageType *
ImageToImageMetricWithFeatures<TFixedImage, TMovingImage, TFixedFeatureImage, TMovingFeatureImage>::
GetFixedFeatureImage(unsigned int i) const
{
return this->m_FixedFeatureImages[i].GetPointer();
} // end GetFixedFeatureImage()
/**
* ********************* SetFixedFeatureInterpolator ****************************
*/
template <class TFixedImage, class TMovingImage, class TFixedFeatureImage, class TMovingFeatureImage>
void
ImageToImageMetricWithFeatures<TFixedImage, TMovingImage, TFixedFeatureImage, TMovingFeatureImage>::
SetFixedFeatureInterpolator(unsigned int i, FixedFeatureInterpolatorType * interpolator)
{
if (i + 1 > this->m_NumberOfFixedFeatureImages)
{
this->m_FixedFeatureInterpolators.resize(i + 1);
this->m_FixedFeatureInterpolators[i] = interpolator;
this->m_NumberOfFixedFeatureImages = i;
this->Modified();
}
else
{
if (this->m_FixedFeatureInterpolators[i] != interpolator)
{
this->m_FixedFeatureInterpolators[i] = interpolator;
this->Modified();
}
}
} // end SetFixedFeatureInterpolator()
/**
* ********************* GetFixedFeatureInterpolator ****************************
*/
template <class TFixedImage, class TMovingImage, class TFixedFeatureImage, class TMovingFeatureImage>
const typename ImageToImageMetricWithFeatures<TFixedImage, TMovingImage, TFixedFeatureImage, TMovingFeatureImage>::
FixedFeatureInterpolatorType *
ImageToImageMetricWithFeatures<TFixedImage, TMovingImage, TFixedFeatureImage, TMovingFeatureImage>::
GetFixedFeatureInterpolator(unsigned int i) const
{
return this->m_FixedFeatureInterpolators[i].GetPointer();
} // end GetFixedFeatureInterpolator()
/**
* ********************* SetNumberOfMovingFeatureImages ****************************
*/
template <class TFixedImage, class TMovingImage, class TFixedFeatureImage, class TMovingFeatureImage>
void
ImageToImageMetricWithFeatures<TFixedImage, TMovingImage, TFixedFeatureImage, TMovingFeatureImage>::
SetNumberOfMovingFeatureImages(unsigned int arg)
{
if (this->m_NumberOfMovingFeatureImages != arg)
{
this->m_MovingFeatureImages.resize(arg);
this->m_MovingFeatureInterpolators.resize(arg);
this->m_NumberOfMovingFeatureImages = arg;
this->Modified();
}
} // end SetNumberOfMovingFeatureImages()
/**
* ********************* SetMovingFeatureImage ****************************
*/
template <class TFixedImage, class TMovingImage, class TFixedFeatureImage, class TMovingFeatureImage>
void
ImageToImageMetricWithFeatures<TFixedImage, TMovingImage, TFixedFeatureImage, TMovingFeatureImage>::
SetMovingFeatureImage(unsigned int i, MovingFeatureImageType * im)
{
if (i + 1 > this->m_NumberOfMovingFeatureImages)
{
this->m_MovingFeatureImages.resize(i + 1);
this->m_MovingFeatureImages[i] = im;
this->m_NumberOfMovingFeatureImages = i;
this->Modified();
}
else
{
if (this->m_MovingFeatureImages[i] != im)
{
this->m_MovingFeatureImages[i] = im;
this->Modified();
}
}
} // end SetMovingFeatureImage()
/**
* ********************* GetMovingFeatureImage ****************************
*/
template <class TFixedImage, class TMovingImage, class TFixedFeatureImage, class TMovingFeatureImage>
const typename ImageToImageMetricWithFeatures<TFixedImage, TMovingImage, TFixedFeatureImage, TMovingFeatureImage>::
MovingFeatureImageType *
ImageToImageMetricWithFeatures<TFixedImage, TMovingImage, TFixedFeatureImage, TMovingFeatureImage>::
GetMovingFeatureImage(unsigned int i) const
{
return this->m_MovingFeatureImages[i].GetPointer();
} // end GetMovingFeatureImage()
/**
* ********************* SetMovingFeatureInterpolator ****************************
*/
template <class TFixedImage, class TMovingImage, class TFixedFeatureImage, class TMovingFeatureImage>
void
ImageToImageMetricWithFeatures<TFixedImage, TMovingImage, TFixedFeatureImage, TMovingFeatureImage>::
SetMovingFeatureInterpolator(unsigned int i, MovingFeatureInterpolatorType * interpolator)
{
if (i + 1 > this->m_NumberOfMovingFeatureImages)
{
this->m_MovingFeatureInterpolators.resize(i + 1);
this->m_MovingFeatureInterpolators[i] = interpolator;
this->m_NumberOfMovingFeatureImages = i;
this->Modified();
}
else
{
if (this->m_MovingFeatureInterpolators[i] != interpolator)
{
this->m_MovingFeatureInterpolators[i] = interpolator;
this->Modified();
}
}
} // end SetMovingFeatureInterpolator()
/**
* ********************* GetMovingFeatureInterpolator ****************************
*/
template <class TFixedImage, class TMovingImage, class TFixedFeatureImage, class TMovingFeatureImage>
const typename ImageToImageMetricWithFeatures<TFixedImage, TMovingImage, TFixedFeatureImage, TMovingFeatureImage>::
MovingFeatureInterpolatorType *
ImageToImageMetricWithFeatures<TFixedImage, TMovingImage, TFixedFeatureImage, TMovingFeatureImage>::
GetMovingFeatureInterpolator(unsigned int i) const
{
return this->m_MovingFeatureInterpolators[i].GetPointer();
} // end GetMovingFeatureInterpolator()
/**
* ****************** CheckForBSplineFeatureInterpolators **********************
*/
template <class TFixedImage, class TMovingImage, class TFixedFeatureImage, class TMovingFeatureImage>
void
ImageToImageMetricWithFeatures<TFixedImage, TMovingImage, TFixedFeatureImage, TMovingFeatureImage>::
CheckForBSplineFeatureInterpolators()
{
/** Check if the interpolators are of type BSplineInterpolateImageFunction.
* If so, we can make use of its EvaluateDerivatives method.
* Otherwise, an exception is thrown.
*/
this->m_FeatureInterpolatorsIsBSpline.resize(this->m_NumberOfMovingFeatureImages, false);
this->m_MovingFeatureBSplineInterpolators.resize(this->m_NumberOfMovingFeatureImages);
for (unsigned int i = 0; i < this->m_NumberOfMovingFeatureImages; ++i)
{
BSplineInterpolatorType * testPtr =
dynamic_cast<BSplineInterpolatorType *>(this->m_MovingFeatureInterpolators[i].GetPointer());
if (testPtr)
{
this->m_FeatureInterpolatorsIsBSpline[i] = true;
this->m_MovingFeatureBSplineInterpolators[i] = testPtr;
itkDebugMacro("Interpolator " << i << " is B-spline.");
}
else
{
itkDebugMacro("Interpolator " << i << " is NOT B-spline.");
itkExceptionMacro("Interpolator " << i << " is NOT B-spline.");
}
} // end for-loop
} // end CheckForBSplineFeatureInterpolators()
/**
* ********************* PrintSelf ****************************
*/
template <class TFixedImage, class TMovingImage, class TFixedFeatureImage, class TMovingFeatureImage>
void
ImageToImageMetricWithFeatures<TFixedImage, TMovingImage, TFixedFeatureImage, TMovingFeatureImage>::PrintSelf(
std::ostream & os,
Indent indent) const
{
Superclass::PrintSelf(os, indent);
os << indent << "NumberOfFixedFeatureImages: " << this->m_NumberOfFixedFeatureImages << std::endl;
os << indent << "NumberOfMovingFeatureImages: " << this->m_NumberOfMovingFeatureImages << std::endl;
/** Print the feature image pointers. */
for (unsigned int i = 0; i < this->m_NumberOfFixedFeatureImages; ++i)
{
os << indent << "FixedFeatureImages[" << i << "]: " << this->m_FixedFeatureImages[i].GetPointer() << std::endl;
}
for (unsigned int i = 0; i < this->m_NumberOfMovingFeatureImages; ++i)
{
os << indent << "MovingFeatureImages[" << i << "]: " << this->m_MovingFeatureImages[i].GetPointer() << std::endl;
}
/** Print the feature interpolators pointers. */
for (unsigned int i = 0; i < this->m_NumberOfFixedFeatureImages; ++i)
{
os << indent << "FixedFeatureInterpolators[" << i << "]: " << this->m_FixedFeatureInterpolators[i].GetPointer()
<< std::endl;
}
for (unsigned int i = 0; i < this->m_NumberOfMovingFeatureImages; ++i)
{
os << indent << "MovingFeatureInterpolators[" << i << "]: " << this->m_MovingFeatureInterpolators[i].GetPointer()
<< std::endl;
}
} // end PrintSelf()
} // end namespace itk
#endif // end #ifndef _itkImageToImageMetricWithFeatures_hxx
|