File: itkGPUAdvancedCombinationTransformCopier.hxx

package info (click to toggle)
elastix 5.2.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 42,480 kB
  • sloc: cpp: 68,403; lisp: 4,118; python: 1,013; xml: 182; sh: 177; makefile: 33
file content (677 lines) | stat: -rw-r--r-- 25,661 bytes parent folder | download
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
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
/*=========================================================================
 *
 *  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 itkGPUAdvancedCombinationTransformCopier_hxx
#define itkGPUAdvancedCombinationTransformCopier_hxx

#include "itkGPUAdvancedCombinationTransformCopier.h"

// elastix CPU transforms
#include "itkAdvancedMatrixOffsetTransformBase.h"
#include "itkAdvancedTranslationTransform.h"
#include "itkAdvancedBSplineDeformableTransform.h"
#include "itkAdvancedRigid2DTransform.h"
#include "itkAdvancedEuler3DTransform.h"
#include "itkAdvancedSimilarity2DTransform.h"
#include "itkAdvancedSimilarity3DTransform.h"

// elastix GPU transforms
#include "itkGPUAdvancedMatrixOffsetTransformBase.h"
#include "itkGPUAdvancedTranslationTransform.h"
#include "itkGPUAdvancedBSplineDeformableTransform.h"
#include "itkGPUAdvancedEuler2DTransform.h"
#include "itkGPUAdvancedEuler3DTransform.h"
#include "itkGPUAdvancedSimilarity2DTransform.h"
#include "itkGPUAdvancedSimilarity3DTransform.h"

// GPU factory include
#include "itkGPUImageFactory.h"

namespace itk
{
//------------------------------------------------------------------------------
template <typename TTypeList,
          typename NDimensions,
          typename TAdvancedCombinationTransform,
          typename TOutputTransformPrecisionType>
GPUAdvancedCombinationTransformCopier<TTypeList,
                                      NDimensions,
                                      TAdvancedCombinationTransform,
                                      TOutputTransformPrecisionType>::GPUAdvancedCombinationTransformCopier()
{
  this->m_InputTransform = nullptr;
  this->m_Output = nullptr;
  this->m_InternalTransformTime = 0;
  this->m_ExplicitMode = true;
}


//------------------------------------------------------------------------------
template <typename TTypeList,
          typename NDimensions,
          typename TAdvancedCombinationTransform,
          typename TOutputTransformPrecisionType>
void
GPUAdvancedCombinationTransformCopier<TTypeList,
                                      NDimensions,
                                      TAdvancedCombinationTransform,
                                      TOutputTransformPrecisionType>::Update()
{
  if (!this->m_InputTransform)
  {
    itkExceptionMacro("ERROR: m_InputTransform not set");
  }

  // Update only if the input AdvancedCombinationTransform has been modified
  const ModifiedTimeType t = this->m_InputTransform->GetMTime();
  if (t <= this->m_InternalTransformTime)
    return; // No need to update

  // Cache the timestamp
  this->m_InternalTransformTime = t;

  // Allocate the output GPU combo transform
  GPUComboTransformPointer comboTransformGPU = GPUComboTransformType::New();
  this->m_Output = comboTransformGPU;

  // Initialize the current transforms
  CPUCurrentTransformConstPointer currentTransformCPU;
  GPUComboTransformPointer        currentTransformGPU = comboTransformGPU;

  // Loop over all sub-transforms
  const SizeValueType numberOfTransforms = this->m_InputTransform->GetNumberOfTransforms();
  for (SizeValueType i = 0; i < numberOfTransforms; ++i)
  {
    // Get the current CPU transform of type itk::Transform
    TransformTypePointer itkCurrentTransform = this->m_InputTransform->GetNthTransform(i);

    // Cast to advanced transform type, no checking needed
    currentTransformCPU = dynamic_cast<const CPUCurrentTransformType *>(itkCurrentTransform.GetPointer());

    // Copy the current CPU transform to the current GPU transform
    const bool copySucceeded = this->CopyToCurrentTransform(currentTransformCPU, currentTransformGPU);
    if (!copySucceeded)
    {
      itkExceptionMacro(
        "ERROR: GPUAdvancedCombinationTransformCopier was unable to copy transform from: " << this->m_InputTransform);
    }

    // skip next step when last transform
    if (i == numberOfTransforms - 1)
    {
      continue;
    }

    // Reset the GPU combo transform
    GPUComboTransformPointer initialNext = GPUComboTransformType::New();
    currentTransformGPU->SetInitialTransform(initialNext);
    currentTransformGPU = initialNext;
  }
}


//------------------------------------------------------------------------------
template <typename TTypeList,
          typename NDimensions,
          typename TAdvancedCombinationTransform,
          typename TOutputTransformPrecisionType>
bool
GPUAdvancedCombinationTransformCopier<
  TTypeList,
  NDimensions,
  TAdvancedCombinationTransform,
  TOutputTransformPrecisionType>::CopyToCurrentTransform(const CPUCurrentTransformConstPointer & fromTransform,
                                                         GPUComboTransformPointer &              toTransform)
{
  if (fromTransform.IsNotNull())
  {
    // For Euler and Similarity transforms we have to use partial
    // template specialization logic.
    const unsigned int                                  InputDimension = SpaceDimension;
    const TransformSpaceDimensionToType<SpaceDimension> idim = {};

    // Try Advanced Euler
    bool eulerCopyResult = false;
    switch (InputDimension)
    {
      case 2:
        eulerCopyResult = this->CopyEuler2DTransform(fromTransform, toTransform, idim);
        break;
      case 3:
        eulerCopyResult = this->CopyEuler3DTransform(fromTransform, toTransform, idim);
        break;
      default:
        break;
    }

    if (eulerCopyResult)
    {
      return eulerCopyResult;
    }

    // Try Advanced Similarity
    bool similarityCopyResult = false;
    switch (InputDimension)
    {
      case 2:
        similarityCopyResult = this->CopySimilarity2DTransform(fromTransform, toTransform, idim);
        break;
      case 3:
        similarityCopyResult = this->CopySimilarity3DTransform(fromTransform, toTransform, idim);
        break;
      default:
        break;
    }

    if (similarityCopyResult)
    {
      return similarityCopyResult;
    }

    // Try Advanced Affine
    using AdvancedAffineTransformType =
      AdvancedMatrixOffsetTransformBase<CPUScalarType, SpaceDimension, SpaceDimension>;
    const typename AdvancedAffineTransformType::ConstPointer affine =
      dynamic_cast<const AdvancedAffineTransformType *>(fromTransform.GetPointer());

    if (affine)
    {
      GPUAdvancedTransformPointer affineTransform;
      if (this->m_ExplicitMode)
      {
        // Create GPU Advanced Affine transform in explicit mode
        using GPUAdvancedAffineTransformType = GPUAdvancedMatrixOffsetTransformBase<GPUScalarType, SpaceDimension>;
        affineTransform = GPUAdvancedAffineTransformType::New();
      }
      else
      {
        // Create GPU Advanced Affine transform in implicit mode
        using GPUAdvancedAffineTransformType =
          AdvancedMatrixOffsetTransformBase<GPUScalarType, SpaceDimension, SpaceDimension>;
        affineTransform = GPUAdvancedAffineTransformType::New();
      }
      this->CastCopyTransformParameters(fromTransform, affineTransform);
      toTransform->SetCurrentTransform(affineTransform);
      return true;
    }

    // Try Advanced Translation
    using AdvancedTranslationTransformType = AdvancedTranslationTransform<CPUScalarType, SpaceDimension>;
    const typename AdvancedTranslationTransformType::ConstPointer translation =
      dynamic_cast<const AdvancedTranslationTransformType *>(fromTransform.GetPointer());

    if (translation)
    {
      GPUAdvancedTransformPointer translationTransform;
      if (this->m_ExplicitMode)
      {
        // Create GPU Advanced Translation transform in explicit mode
        using GPUAdvancedTranslationTransformType = GPUAdvancedTranslationTransform<GPUScalarType, SpaceDimension>;
        translationTransform = GPUAdvancedTranslationTransformType::New();
      }
      else
      {
        // Create GPU Advanced Translation transform in implicit mode
        using GPUAdvancedTranslationTransformType = AdvancedTranslationTransform<GPUScalarType, SpaceDimension>;
        translationTransform = GPUAdvancedTranslationTransformType::New();
      }
      this->CastCopyTransformParameters(fromTransform, translationTransform);
      toTransform->SetCurrentTransform(translationTransform);
      return true;
    }

    // For BSpline we have to check all possible spline orders
    const bool bsplineCopyResult = this->CopyBSplineTransform(fromTransform, toTransform);
    if (bsplineCopyResult)
    {
      return bsplineCopyResult;
    }

    return false;
  }

  return true;
}


//------------------------------------------------------------------------------
template <typename TTypeList,
          typename NDimensions,
          typename TAdvancedCombinationTransform,
          typename TOutputTransformPrecisionType>
void
GPUAdvancedCombinationTransformCopier<
  TTypeList,
  NDimensions,
  TAdvancedCombinationTransform,
  TOutputTransformPrecisionType>::CastCopyTransformParameters(const CPUCurrentTransformConstPointer & fromTransform,
                                                              GPUAdvancedTransformPointer &           toTransform)
{
  const CPUFixedParametersType & fixedParametersFrom = fromTransform->GetFixedParameters();
  const CPUParametersType &      parametersFrom = fromTransform->GetParameters();

  GPUFixedParametersType fixedParametersTo;
  GPUParametersType      parametersTo;

  this->CastCopyFixedParameters(fixedParametersFrom, fixedParametersTo);
  this->CastCopyParameters(parametersFrom, parametersTo);

  toTransform->SetFixedParameters(fixedParametersTo);
  toTransform->SetParameters(parametersTo);
}


//------------------------------------------------------------------------------
template <typename TTypeList,
          typename NDimensions,
          typename TAdvancedCombinationTransform,
          typename TOutputTransformPrecisionType>
void
GPUAdvancedCombinationTransformCopier<TTypeList,
                                      NDimensions,
                                      TAdvancedCombinationTransform,
                                      TOutputTransformPrecisionType>::CastCopyParameters(const CPUParametersType & from,
                                                                                         GPUParametersType &       to)
{
  if (from.GetSize() == 0)
  {
    return;
  }

  to.SetSize(from.GetSize());
  for (SizeValueType i = 0; i < from.GetSize(); ++i)
  {
    to[i] = static_cast<GPUScalarType>(from[i]);
  }
}


//------------------------------------------------------------------------------
template <typename TTypeList,
          typename NDimensions,
          typename TAdvancedCombinationTransform,
          typename TOutputTransformPrecisionType>
void
GPUAdvancedCombinationTransformCopier<
  TTypeList,
  NDimensions,
  TAdvancedCombinationTransform,
  TOutputTransformPrecisionType>::CastCopyFixedParameters(const CPUFixedParametersType & from,
                                                          GPUFixedParametersType &       to)
{
  if (from.GetSize() == 0)
  {
    return;
  }

  to.SetSize(from.GetSize());
  for (SizeValueType i = 0; i < from.GetSize(); ++i)
  {
    to[i] = static_cast<GPUScalarType>(from[i]);
  }
}


//------------------------------------------------------------------------------
template <typename TTypeList,
          typename NDimensions,
          typename TAdvancedCombinationTransform,
          typename TOutputTransformPrecisionType>
bool
GPUAdvancedCombinationTransformCopier<
  TTypeList,
  NDimensions,
  TAdvancedCombinationTransform,
  TOutputTransformPrecisionType>::CopyBSplineTransform(const CPUCurrentTransformConstPointer & fromTransform,
                                                       GPUComboTransformPointer &              toTransform)
{
  using AdvancedBSplineOrder0TransformType = AdvancedBSplineDeformableTransform<CPUScalarType, SpaceDimension, 0>;
  using AdvancedBSplineOrder1TransformType = AdvancedBSplineDeformableTransform<CPUScalarType, SpaceDimension, 1>;
  using AdvancedBSplineOrder2TransformType = AdvancedBSplineDeformableTransform<CPUScalarType, SpaceDimension, 2>;
  using AdvancedBSplineOrder3TransformType = AdvancedBSplineDeformableTransform<CPUScalarType, SpaceDimension, 3>;

  GPUAdvancedTransformPointer bsplineTransform;

  // When creating the GPUAdvancedBSplineDeformableTransform in explicit mode
  // We also have to register GPUImageFactory because
  // GPUAdvancedBSplineDeformableTransform using m_Coefficients as ITK images
  // inside the implementation, therefore we define GPUImageFactory pointer
  using GPUImageFactoryType = itk::GPUImageFactory2<TTypeList, NDimensions>;
  using GPUImageFactoryPointer = typename GPUImageFactoryType::Pointer;

  // Try BSpline Order 3 first
  const typename AdvancedBSplineOrder3TransformType::ConstPointer bsplineOrder3 =
    dynamic_cast<const AdvancedBSplineOrder3TransformType *>(fromTransform.GetPointer());

  if (bsplineOrder3)
  {
    if (this->m_ExplicitMode)
    {
      // Register image factory
      GPUImageFactoryPointer imageFactory = GPUImageFactoryType::New();
      itk::ObjectFactoryBase::RegisterFactory(imageFactory);

      // Create GPU Advanced BSpline transform in explicit mode
      using GPUBSplineTransformType = GPUAdvancedBSplineDeformableTransform<GPUScalarType, SpaceDimension, 3>;
      bsplineTransform = GPUBSplineTransformType::New();

      // UnRegister image factory
      itk::ObjectFactoryBase::UnRegisterFactory(imageFactory);
    }
    else
    {
      // Create GPU Advanced BSpline transform in implicit mode
      using GPUBSplineTransformType = AdvancedBSplineDeformableTransform<GPUScalarType, SpaceDimension, 3>;
      bsplineTransform = GPUBSplineTransformType::New();
    }
    this->CastCopyTransformParameters(fromTransform, bsplineTransform);
    toTransform->SetCurrentTransform(bsplineTransform);
    return true;
  }
  else
  {
    // Try BSpline Order 0
    const typename AdvancedBSplineOrder0TransformType::ConstPointer bsplineOrder0 =
      dynamic_cast<const AdvancedBSplineOrder0TransformType *>(fromTransform.GetPointer());

    if (bsplineOrder0)
    {
      if (this->m_ExplicitMode)
      {
        // Register image factory
        GPUImageFactoryPointer imageFactory = GPUImageFactoryType::New();
        itk::ObjectFactoryBase::RegisterFactory(imageFactory);

        // Create GPU Advanced BSpline transform in explicit mode
        using GPUBSplineTransformType = GPUAdvancedBSplineDeformableTransform<GPUScalarType, SpaceDimension, 0>;
        bsplineTransform = GPUBSplineTransformType::New();

        // UnRegister image factory
        itk::ObjectFactoryBase::UnRegisterFactory(imageFactory);
      }
      else
      {
        // Create GPU Advanced BSpline transform in implicit mode
        using GPUBSplineTransformType = AdvancedBSplineDeformableTransform<GPUScalarType, SpaceDimension, 0>;
        bsplineTransform = GPUBSplineTransformType::New();
      }
      this->CastCopyTransformParameters(fromTransform, bsplineTransform);
      toTransform->SetCurrentTransform(bsplineTransform);
      return true;
    }
    else
    {
      // Try BSpline Order 1
      const typename AdvancedBSplineOrder1TransformType::ConstPointer bsplineOrder1 =
        dynamic_cast<const AdvancedBSplineOrder1TransformType *>(fromTransform.GetPointer());

      if (bsplineOrder1)
      {
        if (this->m_ExplicitMode)
        {
          // Register image factory
          GPUImageFactoryPointer imageFactory = GPUImageFactoryType::New();
          itk::ObjectFactoryBase::RegisterFactory(imageFactory);

          // Create GPU Advanced BSpline transform in explicit mode
          using GPUBSplineTransformType = GPUAdvancedBSplineDeformableTransform<GPUScalarType, SpaceDimension, 1>;
          bsplineTransform = GPUBSplineTransformType::New();

          // UnRegister image factory
          itk::ObjectFactoryBase::UnRegisterFactory(imageFactory);
        }
        else
        {
          // Create GPU Advanced BSpline transform in implicit mode
          using GPUBSplineTransformType = AdvancedBSplineDeformableTransform<GPUScalarType, SpaceDimension, 1>;
          bsplineTransform = GPUBSplineTransformType::New();
        }
        this->CastCopyTransformParameters(fromTransform, bsplineTransform);
        toTransform->SetCurrentTransform(bsplineTransform);
        return true;
      }
      else
      {
        // Try BSpline Order 2
        const typename AdvancedBSplineOrder2TransformType::ConstPointer bsplineOrder2 =
          dynamic_cast<const AdvancedBSplineOrder2TransformType *>(fromTransform.GetPointer());

        if (bsplineOrder2)
        {
          if (this->m_ExplicitMode)
          {
            // Register image factory
            GPUImageFactoryPointer imageFactory = GPUImageFactoryType::New();
            itk::ObjectFactoryBase::RegisterFactory(imageFactory);

            // Create GPU Advanced BSpline transform in explicit mode
            using GPUBSplineTransformType = GPUAdvancedBSplineDeformableTransform<GPUScalarType, SpaceDimension, 2>;
            bsplineTransform = GPUBSplineTransformType::New();

            // UnRegister image factory
            itk::ObjectFactoryBase::UnRegisterFactory(imageFactory);
          }
          else
          {
            // Create GPU Advanced BSpline transform in implicit mode
            using GPUBSplineTransformType = AdvancedBSplineDeformableTransform<GPUScalarType, SpaceDimension, 2>;
            bsplineTransform = GPUBSplineTransformType::New();
          }
          this->CastCopyTransformParameters(fromTransform, bsplineTransform);
          toTransform->SetCurrentTransform(bsplineTransform);
          return true;
        }
      }
    }
  }

  return false;
}


//------------------------------------------------------------------------------
template <typename TTypeList,
          typename NDimensions,
          typename TAdvancedCombinationTransform,
          typename TOutputTransformPrecisionType>
bool
GPUAdvancedCombinationTransformCopier<
  TTypeList,
  NDimensions,
  TAdvancedCombinationTransform,
  TOutputTransformPrecisionType>::CopyEuler2DTransform(const CPUCurrentTransformConstPointer & fromTransform,
                                                       GPUComboTransformPointer &              toTransform,
                                                       TransformSpaceDimensionToType<2>)
{
  using CPUEulerTransformType = AdvancedRigid2DTransform<CPUScalarType>;
  const typename CPUEulerTransformType::ConstPointer euler =
    dynamic_cast<const CPUEulerTransformType *>(fromTransform.GetPointer());

  if (euler)
  {
    GPUAdvancedTransformPointer eulerTransform;
    if (this->m_ExplicitMode)
    {
      // Create GPU Advanced Euler transform in explicit mode
      using GPUEulerTransformType = GPUAdvancedEuler2DTransform<GPUScalarType>;
      eulerTransform = GPUEulerTransformType::New();
    }
    else
    {
      // Create GPU Advanced Euler transform in implicit mode
      using GPUEulerTransformType = AdvancedRigid2DTransform<GPUScalarType>;
      eulerTransform = GPUEulerTransformType::New();
    }

    this->CastCopyTransformParameters(fromTransform, eulerTransform);
    toTransform->SetCurrentTransform(eulerTransform);
    return true;
  }

  return false;
}


//------------------------------------------------------------------------------
template <typename TTypeList,
          typename NDimensions,
          typename TAdvancedCombinationTransform,
          typename TOutputTransformPrecisionType>
bool
GPUAdvancedCombinationTransformCopier<
  TTypeList,
  NDimensions,
  TAdvancedCombinationTransform,
  TOutputTransformPrecisionType>::CopyEuler3DTransform(const CPUCurrentTransformConstPointer & fromTransform,
                                                       GPUComboTransformPointer &              toTransform,
                                                       TransformSpaceDimensionToType<3>)
{
  using CPUEulerTransformType = AdvancedEuler3DTransform<CPUScalarType>;
  const typename CPUEulerTransformType::ConstPointer euler =
    dynamic_cast<const CPUEulerTransformType *>(fromTransform.GetPointer());

  if (euler)
  {
    GPUAdvancedTransformPointer eulerTransform;
    if (this->m_ExplicitMode)
    {
      // Create GPU Advanced Euler transform in explicit mode
      using GPUEulerTransformType = GPUAdvancedEuler3DTransform<GPUScalarType>;
      eulerTransform = GPUEulerTransformType::New();
    }
    else
    {
      // Create GPU Advanced Euler transform in implicit mode
      using GPUEulerTransformType = AdvancedEuler3DTransform<GPUScalarType>;
      eulerTransform = GPUEulerTransformType::New();
    }

    this->CastCopyTransformParameters(fromTransform, eulerTransform);
    toTransform->SetCurrentTransform(eulerTransform);
    return true;
  }

  return false;
}


//------------------------------------------------------------------------------
template <typename TTypeList,
          typename NDimensions,
          typename TAdvancedCombinationTransform,
          typename TOutputTransformPrecisionType>
bool
GPUAdvancedCombinationTransformCopier<
  TTypeList,
  NDimensions,
  TAdvancedCombinationTransform,
  TOutputTransformPrecisionType>::CopySimilarity2DTransform(const CPUCurrentTransformConstPointer & fromTransform,
                                                            GPUComboTransformPointer &              toTransform,
                                                            TransformSpaceDimensionToType<2>)
{
  using CPUSimilarityTransformType = AdvancedSimilarity2DTransform<CPUScalarType>;
  const typename CPUSimilarityTransformType::ConstPointer similarity =
    dynamic_cast<const CPUSimilarityTransformType *>(fromTransform.GetPointer());

  if (similarity)
  {
    GPUAdvancedTransformPointer similarityTransform;
    if (this->m_ExplicitMode)
    {
      // Create GPU Advanced Similarity transform in explicit mode
      using GPUSimilarityTransformType = GPUAdvancedSimilarity2DTransform<GPUScalarType>;
      similarityTransform = GPUSimilarityTransformType::New();
    }
    else
    {
      // Create GPU Advanced Similarity transform in implicit mode
      using GPUSimilarityTransformType = AdvancedSimilarity2DTransform<GPUScalarType>;
      similarityTransform = GPUSimilarityTransformType::New();
    }
    this->CastCopyTransformParameters(fromTransform, similarityTransform);
    toTransform->SetCurrentTransform(similarityTransform);
    return true;
  }

  return false;
}


//------------------------------------------------------------------------------
template <typename TTypeList,
          typename NDimensions,
          typename TAdvancedCombinationTransform,
          typename TOutputTransformPrecisionType>
bool
GPUAdvancedCombinationTransformCopier<
  TTypeList,
  NDimensions,
  TAdvancedCombinationTransform,
  TOutputTransformPrecisionType>::CopySimilarity3DTransform(const CPUCurrentTransformConstPointer & fromTransform,
                                                            GPUComboTransformPointer &              toTransform,
                                                            TransformSpaceDimensionToType<3>)
{
  using CPUSimilarityTransformType = AdvancedSimilarity3DTransform<CPUScalarType>;
  const typename CPUSimilarityTransformType::ConstPointer similarity =
    dynamic_cast<const CPUSimilarityTransformType *>(fromTransform.GetPointer());

  if (similarity)
  {
    GPUAdvancedTransformPointer similarityTransform;
    if (this->m_ExplicitMode)
    {
      // Create GPU Advanced Similarity transform in explicit mode
      using GPUSimilarityTransformType = GPUAdvancedSimilarity3DTransform<GPUScalarType>;
      similarityTransform = GPUSimilarityTransformType::New();
    }
    else
    {
      // Create GPU Advanced Similarity transform in implicit mode
      using GPUSimilarityTransformType = AdvancedSimilarity3DTransform<GPUScalarType>;
      similarityTransform = GPUSimilarityTransformType::New();
    }
    this->CastCopyTransformParameters(fromTransform, similarityTransform);
    toTransform->SetCurrentTransform(similarityTransform);
    return true;
  }

  return false;
}


//------------------------------------------------------------------------------
template <typename TTypeList,
          typename NDimensions,
          typename TAdvancedCombinationTransform,
          typename TOutputTransformPrecisionType>
void
GPUAdvancedCombinationTransformCopier<TTypeList,
                                      NDimensions,
                                      TAdvancedCombinationTransform,
                                      TOutputTransformPrecisionType>::PrintSelf(std::ostream & os, Indent indent) const
{
  Superclass::PrintSelf(os, indent);
  os << indent << "Input Transform: " << this->m_InputTransform << std::endl;
  os << indent << "Output Transform: " << this->m_Output << std::endl;
  os << indent << "Internal Transform Time: " << this->m_InternalTransformTime << std::endl;
  os << indent << "Explicit Mode: " << this->m_ExplicitMode << std::endl;
}


} // end namespace itk

#endif