File: itkTransformTest.cxx

package info (click to toggle)
insighttoolkit4 4.13.3withdata-dfsg2-4
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 491,256 kB
  • sloc: cpp: 557,600; ansic: 180,546; fortran: 34,788; python: 16,572; sh: 2,187; lisp: 2,070; tcl: 993; java: 362; perl: 200; makefile: 133; csh: 81; pascal: 69; xml: 19; ruby: 10
file content (337 lines) | stat: -rw-r--r-- 11,439 bytes parent folder | download | duplicates (4)
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
/*=========================================================================
 *
 *  Copyright Insight Software Consortium
 *
 *  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.
 *
 *=========================================================================*/

#include <iostream>

#include "itkTransform.h"

namespace itk
{
namespace itkTransformTestHelpers
{

template <
  typename TScalar,
  unsigned int NInputDimensions,
  unsigned int NOutputDimensions>
class TransformTestHelper :
  public Transform< TScalar, NInputDimensions, NOutputDimensions >
{
public:
  typedef TransformTestHelper                                       Self;
  typedef Transform< TScalar, NInputDimensions, NOutputDimensions > Superclass;
  typedef SmartPointer< Self >                                      Pointer;
  typedef SmartPointer< const Self >                                ConstPointer;

  itkNewMacro( Self );
  itkTypeMacro( TransformTestHelper, Transform );

  typedef typename Superclass::JacobianType              JacobianType;
  typedef typename Superclass::ParametersType            ParametersType;
  typedef typename Superclass::InputPointType            InputPointType;
  typedef typename Superclass::OutputPointType           OutputPointType;
  typedef typename Superclass::InputVectorType           InputVectorType;
  typedef typename Superclass::OutputVectorType          OutputVectorType;
  typedef typename Superclass::InputVectorPixelType      InputVectorPixelType;
  typedef typename Superclass::OutputVectorPixelType     OutputVectorPixelType;
  typedef typename Superclass::InputVnlVectorType        InputVnlVectorType;
  typedef typename Superclass::OutputVnlVectorType       OutputVnlVectorType;
  typedef typename Superclass::InputCovariantVectorType  InputCovariantVectorType;
  typedef typename Superclass::OutputCovariantVectorType OutputCovariantVectorType;

  typedef typename Superclass::InputDiffusionTensor3DType  InputDiffusionTensor3DType;
  typedef typename Superclass::OutputDiffusionTensor3DType OutputDiffusionTensor3DType;

  typedef typename Superclass::InputSymmetricSecondRankTensorType
  InputSymmetricSecondRankTensorType;
  typedef typename Superclass::OutputSymmetricSecondRankTensorType
  OutputSymmetricSecondRankTensorType;

  virtual OutputPointType TransformPoint(const InputPointType  & itkNotUsed(inputPoint) ) const ITK_OVERRIDE
  {
    OutputPointType outPoint;
    outPoint.Fill( 22.0 );
    return outPoint;
  }

  using Superclass::TransformVector;
  virtual OutputVectorType TransformVector(const InputVectorType  & itkNotUsed(inputVector) ) const ITK_OVERRIDE
  {
    OutputVectorType outVector;
    outVector.Fill( 12.2 );
    return outVector;
  }

  virtual OutputVnlVectorType TransformVector(const InputVnlVectorType  & itkNotUsed(inputVector) ) const ITK_OVERRIDE
  {
    OutputVnlVectorType outVector( 15.0 );
    return outVector;
  }

  virtual OutputVectorPixelType TransformVector(const InputVectorPixelType  & itkNotUsed(inputVector) ) const ITK_OVERRIDE
  {
    OutputVectorPixelType outVector;
    outVector.Fill( 88.8 );
    return outVector;
  }

  using Superclass::TransformCovariantVector;
  virtual OutputCovariantVectorType TransformCovariantVector(const InputCovariantVectorType  & itkNotUsed(inputVector) ) const ITK_OVERRIDE
  {
    OutputCovariantVectorType outVector;
    outVector.Fill( 8.9 );
    return outVector;
  }

  virtual OutputVectorPixelType TransformCovariantVector(const InputVectorPixelType  & itkNotUsed(inputVector) ) const ITK_OVERRIDE
  {
    OutputVectorPixelType outVector;
    outVector.Fill( 6.9 );
    return outVector;
  }

  using Superclass::TransformDiffusionTensor3D;
  virtual OutputDiffusionTensor3DType TransformDiffusionTensor3D( const InputDiffusionTensor3DType & itkNotUsed( tensor ) ) const ITK_OVERRIDE
  {
    OutputDiffusionTensor3DType outTensor;
    outTensor.Fill( 2.1 );
    return outTensor;
  }

  virtual OutputVectorPixelType TransformDiffusionTensor3D( const InputVectorPixelType & itkNotUsed( tensor ) ) const ITK_OVERRIDE
  {
    OutputVectorPixelType outTensor;
    outTensor.Fill( 29.1 );
    return outTensor;
  }

  using Superclass::TransformSymmetricSecondRankTensor;
  virtual OutputSymmetricSecondRankTensorType TransformSymmetricSecondRankTensor(
    const InputSymmetricSecondRankTensorType & itkNotUsed( tensor ) ) const ITK_OVERRIDE
  {
    OutputSymmetricSecondRankTensorType outTensor;
    outTensor.Fill( 10.0 );
    return outTensor;
  }

  virtual OutputVectorPixelType TransformSymmetricSecondRankTensor(
    const InputVectorPixelType & itkNotUsed( tensor ) ) const ITK_OVERRIDE
  {
    OutputVectorPixelType outTensor;
    outTensor.Fill( 55.9 );
    return outTensor;
  }

  virtual void SetParameters(const ParametersType &) ITK_OVERRIDE
  {
  }

  virtual void SetFixedParameters(const ParametersType &) ITK_OVERRIDE
  {
  }

  virtual void ComputeJacobianWithRespectToParameters(const InputPointType &,
                                                      JacobianType & jacobian) const ITK_OVERRIDE
  {
    jacobian.SetSize(3, 6);
    jacobian.Fill(1);
  }

  virtual void ComputeJacobianWithRespectToPosition(
    const InputPointType &,
    JacobianType & jacobian ) const ITK_OVERRIDE
  {
    jacobian.SetSize(NOutputDimensions, NInputDimensions);
    jacobian.Fill(1);
  }

};

template <
  typename TScalar,
  unsigned int NInputDimensions,
  unsigned int NOutputDimensions>
class TransformTester
{
public:
  typedef TransformTester                                             Self;

  typedef TransformTestHelper<double, NInputDimensions, NOutputDimensions> TransformType;

  typedef typename TransformType::JacobianType              JacobianType;
  typedef typename TransformType::ParametersType            ParametersType;
  typedef typename TransformType::InputPointType            InputPointType;
  typedef typename TransformType::OutputPointType           OutputPointType;
  typedef typename TransformType::InputVectorType           InputVectorType;
  typedef typename TransformType::OutputVectorType          OutputVectorType;
  typedef typename TransformType::InputVectorPixelType      InputVectorPixelType;
  typedef typename TransformType::OutputVectorPixelType     OutputVectorPixelType;
  typedef typename TransformType::InputVnlVectorType        InputVnlVectorType;
  typedef typename TransformType::OutputVnlVectorType       OutputVnlVectorType;
  typedef typename TransformType::InputCovariantVectorType  InputCovariantVectorType;
  typedef typename TransformType::OutputCovariantVectorType OutputCovariantVectorType;

  typedef typename TransformType::InputDiffusionTensor3DType  InputDiffusionTensor3DType;
  typedef typename TransformType::OutputDiffusionTensor3DType OutputDiffusionTensor3DType;

  typedef typename TransformType::InputSymmetricSecondRankTensorType
  InputSymmetricSecondRankTensorType;
  typedef typename TransformType::OutputSymmetricSecondRankTensorType
  OutputSymmetricSecondRankTensorType;

  bool RunTests( void )
  {
    std::cout << "Testing itkTransform<" << NInputDimensions << "," << NOutputDimensions << ">" << std::endl;
    typename TransformType::Pointer transform = TransformType::New();

    InputPointType pnt;
    pnt.Fill(2.9);

    transform->TransformPoint(pnt);
    std::cout << "TransformPoint()                              OK" << std::endl;

    InputVectorType vec;
    transform->TransformVector(vec);
    transform->TransformVector(vec,pnt);

    InputVectorPixelType vecpix;
    vecpix.SetSize( NInputDimensions );
    vecpix.Fill(1.7);
    transform->TransformVector(vecpix);
    transform->TransformVector(vecpix,pnt);

    InputVnlVectorType vec_vnl;
    transform->TransformVector(vec_vnl);
    transform->TransformVector(vec_vnl,pnt);
    std::cout << "TransformVector()                             OK" << std::endl;

    InputCovariantVectorType covec;
    transform->TransformCovariantVector(covec);
    transform->TransformCovariantVector(vecpix);
    transform->TransformCovariantVector(covec,pnt);
    transform->TransformCovariantVector(vecpix,pnt);
    std::cout << "TransformCovariantVector()                    OK" << std::endl;

    InputDiffusionTensor3DType difften;
    vecpix.SetSize( 6 );
    vecpix.Fill(1.7);
    transform->TransformDiffusionTensor3D(difften);
    transform->TransformDiffusionTensor3D(difften,pnt);
    transform->TransformDiffusionTensor3D(vecpix);
    transform->TransformDiffusionTensor3D(vecpix,pnt);
    std::cout << "TransformDiffusionTensor3D()                  OK" << std::endl;

    InputSymmetricSecondRankTensorType ssrten;
    vecpix.SetSize(NInputDimensions*NInputDimensions);
    vecpix.Fill(0);
    transform->TransformSymmetricSecondRankTensor(ssrten);
    transform->TransformSymmetricSecondRankTensor(ssrten,pnt);
    transform->TransformSymmetricSecondRankTensor(vecpix);
    transform->TransformSymmetricSecondRankTensor(vecpix,pnt);
    std::cout << "TransformSymmetricSecondRankTensor()          OK" << std::endl;

    typename TransformType::ParametersType parameters(6);
    try
      {
      transform->SetParameters(parameters);
      }
    catch( itk::ExceptionObject & e )
      {
      std::cerr << e << std::endl;
      }

    try
      {
      transform->GetParameters();
      }
    catch( itk::ExceptionObject & e )
      {
      std::cerr << e << std::endl;
      }

    typename TransformType::JacobianType jacobian;
    try
      {
      transform->ComputeJacobianWithRespectToParameters(pnt, jacobian);
      }
    catch( itk::ExceptionObject & e )
      {
      std::cerr << e << std::endl;
      }

    try
      {
      transform->ComputeJacobianWithRespectToPosition(pnt, jacobian);
      }
    catch( itk::ExceptionObject & e )
      {
      std::cerr << e << std::endl;
      }

    try
      {
      transform->ComputeInverseJacobianWithRespectToPosition(pnt, jacobian);
      }
    catch( itk::ExceptionObject & e )
      {
      std::cerr << e << std::endl;
      }

    typename TransformType::DerivativeType update( transform->GetNumberOfParameters() );
    update.Fill(1);
    try
      {
    transform->UpdateTransformParameters( update );
      }
    catch( itk::ExceptionObject & e )
      {
      std::cerr << e << std::endl;
      }

    // Exercise some methods
    transform->Print( std::cout );
    std::cout <<  transform->GetNameOfClass() << std::endl;

    return true;
  }

};


}
}

int itkTransformTest(int, char * [] )
{
  itk::itkTransformTestHelpers::TransformTester<double,3,3> tester33;
  tester33.RunTests();
  std::cout << "passed 3 3" << std::endl;

  itk::itkTransformTestHelpers::TransformTester<double,3,2> tester32;
  tester32.RunTests();
  std::cout << "passed 3 2" << std::endl;

  itk::itkTransformTestHelpers::TransformTester<double,2,3> tester23;
  tester23.RunTests();
  std::cout << "passed 2 3" << std::endl;


  std::cout << "[ PASSED ]" << std::endl;
  return EXIT_SUCCESS;

}