File: antsUtilities.h

package info (click to toggle)
ants 2.5.4%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 11,672 kB
  • sloc: cpp: 85,685; sh: 15,850; perl: 863; xml: 115; python: 111; makefile: 68
file content (750 lines) | stat: -rw-r--r-- 21,425 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
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
/**
 * There were several functions that had been copied and
 * pasted over and over again in this library.  This
 * header files is contains a common definitoin for
 * those file.
 * \author Hans J. Johnson
 */
#ifndef antsUtilities_h
#define antsUtilities_h

// #include "antscout.hxx"
#include "antsAllocImage.h"
#include <string>
#include <vector>
#include <algorithm>

#include <cstdlib>
#include <cerrno>
#include <cmath>
#include <iostream>

#include "itkVector.h"
#include "itkBinaryThresholdImageFilter.h"
#include "itkBinaryBallStructuringElement.h"
#include "itkBinaryDilateImageFilter.h"
#include "itkBinaryErodeImageFilter.h"
#include "itkBinaryMorphologicalClosingImageFilter.h"
#include "itkBinaryMorphologicalOpeningImageFilter.h"

#include "itkGrayscaleDilateImageFilter.h"
#include "itkGrayscaleErodeImageFilter.h"
#include "itkGrayscaleMorphologicalClosingImageFilter.h"
#include "itkGrayscaleMorphologicalOpeningImageFilter.h"

#include "itkMath.h"

// We need to ensure that only one of these exists!
namespace ants
{
// extern boost::iostreams::stream<ants_Sink> std::cout;

template <typename TImage>
bool
IsInside(typename TImage::Pointer input, typename TImage::IndexType index)
{
  /** FIXME - should use StartIndex - */
  typedef TImage ImageType;
  enum
  {
    ImageDimension = ImageType::ImageDimension
  };
  bool isinside = true;
  for (unsigned int i = 0; i < ImageDimension; i++)
  {
    float shifted = index[i];
    if (shifted < 0 || shifted > input->GetLargestPossibleRegion().GetSize()[i] - 1)
    {
      isinside = false;
    }
  }
  return isinside;
}

// ##########################################################################
// ##########################################################################
// ##########################################################################
// ##########################################################################
// ##########################################################################
// ##########################################################################
// ##########################################################################
// Templates
template <typename TImage>
typename TImage::Pointer
Morphological(typename TImage::Pointer input, float rad, unsigned int option, float dilateval)
{
  typedef TImage ImageType;
  enum
  {
    ImageDimension = TImage::ImageDimension
  };
  typedef typename TImage::PixelType PixelType;

  if (option == 0)
  {
    //    std::cout << " binary eroding the image " << std::endl;
  }
  else if (option == 1)
  {
    //    std::cout << " binary dilating the image " << std::endl;
  }
  else if (option == 2)
  {
    //    std::cout << " binary opening the image " << std::endl;
  }
  else if (option == 3)
  {
    //    std::cout << " binary closing the image " << std::endl;
  }
  else if (option == 4)
  {
    //    std::cout << " grayscale eroding the image " << std::endl;
  }
  else if (option == 5)
  {
    //    std::cout << " grayscale dilating the image " << std::endl;
  }
  else if (option == 6)
  {
    //    std::cout << " grayscale opening the image " << std::endl;
  }
  else if (option == 7)
  {
    //    std::cout << " grayscale closing the image " << std::endl;
  }

  typedef itk::BinaryBallStructuringElement<PixelType, ImageDimension> StructuringElementType;

  typedef itk::BinaryErodeImageFilter<TImage, TImage, StructuringElementType> ErodeFilterType;

  typedef itk::BinaryDilateImageFilter<TImage, TImage, StructuringElementType> DilateFilterType;

  typedef itk::BinaryMorphologicalClosingImageFilter<TImage, TImage, StructuringElementType> ClosingFilterType;

  typedef itk::BinaryMorphologicalOpeningImageFilter<TImage, TImage, StructuringElementType> OpeningFilterType;

  typename ErodeFilterType::Pointer   binaryErode = ErodeFilterType::New();
  typename DilateFilterType::Pointer  binaryDilate = DilateFilterType::New();
  typename OpeningFilterType::Pointer binaryOpen = OpeningFilterType::New();
  typename ClosingFilterType::Pointer binaryClose = ClosingFilterType::New();

  StructuringElementType structuringElement;

  structuringElement.SetRadius(static_cast<unsigned long>(rad)); // 3x3x3 structuring element

  structuringElement.CreateStructuringElement();

  binaryErode->SetKernel(structuringElement);
  binaryDilate->SetKernel(structuringElement);
  binaryOpen->SetKernel(structuringElement);
  binaryClose->SetKernel(structuringElement);

  typedef itk::GrayscaleErodeImageFilter<TImage, TImage, StructuringElementType> GrayscaleErodeFilterType;

  typedef itk::GrayscaleDilateImageFilter<TImage, TImage, StructuringElementType> GrayscaleDilateFilterType;

  typedef itk::GrayscaleMorphologicalClosingImageFilter<TImage, TImage, StructuringElementType>
    GrayscaleClosingFilterType;

  typedef itk::GrayscaleMorphologicalOpeningImageFilter<TImage, TImage, StructuringElementType>
    GrayscaleOpeningFilterType;

  typename GrayscaleErodeFilterType::Pointer   grayscaleErode = GrayscaleErodeFilterType::New();
  typename GrayscaleDilateFilterType::Pointer  grayscaleDilate = GrayscaleDilateFilterType::New();
  typename GrayscaleOpeningFilterType::Pointer grayscaleOpen = GrayscaleOpeningFilterType::New();
  typename GrayscaleClosingFilterType::Pointer grayscaleClose = GrayscaleClosingFilterType::New();
  grayscaleErode->SetKernel(structuringElement);
  grayscaleDilate->SetKernel(structuringElement);
  grayscaleOpen->SetKernel(structuringElement);
  grayscaleClose->SetKernel(structuringElement);

  //  It is necessary to define what could be considered objects on the binary
  //  images. This is specified with the methods \code{SetErodeValue()} and
  //  \code{SetDilateValue()}. The value passed to these methods will be
  //  considered the value over which the dilation and erosion rules will apply
  binaryErode->SetErodeValue(static_cast<PixelType>(dilateval));
  binaryDilate->SetDilateValue(static_cast<PixelType>(dilateval));
  binaryOpen->SetForegroundValue(static_cast<PixelType>(dilateval));
  binaryClose->SetForegroundValue(static_cast<PixelType>(dilateval));

  typename TImage::Pointer temp;
  if (option == 1)
  {
    //    std::cout << " Binary Dilate " << rad << std::endl;
    binaryDilate->SetInput(input);
    binaryDilate->Update();
    temp = binaryDilate->GetOutput();
  }
  else if (option == 0)
  {
    //    std::cout << " Binary Erode " << rad << std::endl;
    binaryErode->SetInput(input);
    binaryErode->Update();
    temp = binaryErode->GetOutput();
  }
  else if (option == 2)
  {
    //    std::cout << " Binary Open " << rad << std::endl;
    binaryOpen->SetInput(input);
    binaryOpen->Update();
    temp = binaryOpen->GetOutput();
  }
  else if (option == 3)
  {
    //    std::cout << " Binary Close " << rad << std::endl;
    binaryClose->SetInput(input);
    binaryClose->Update();
    temp = binaryClose->GetOutput();
  }
  else if (option == 4)
  {
    //    std::cout << " Grayscale Erode " << rad << std::endl;
    grayscaleErode->SetInput(input);
    grayscaleErode->Update();
    temp = grayscaleErode->GetOutput();
  }
  else if (option == 5)
  {
    //    std::cout << " Grayscale Dilate " << rad << std::endl;
    grayscaleDilate->SetInput(input);
    grayscaleDilate->Update();
    temp = grayscaleDilate->GetOutput();
  }
  else if (option == 6)
  {
    //    std::cout << " Grayscale Open " << rad << std::endl;
    grayscaleOpen->SetInput(input);
    grayscaleOpen->Update();
    temp = grayscaleOpen->GetOutput();
  }
  else if (option == 7)
  {
    //    std::cout << " Grayscale Close " << rad << std::endl;
    grayscaleClose->SetInput(input);
    grayscaleClose->Update();
    temp = grayscaleClose->GetOutput();
  }

  if (option == 0)
  {
    // FIXME - replace with threshold filter?
    typedef itk::ImageRegionIteratorWithIndex<ImageType> ImageIteratorType;
    ImageIteratorType                                    o_iter(temp, temp->GetLargestPossibleRegion());
    o_iter.GoToBegin();
    while (!o_iter.IsAtEnd())
    {
      if (o_iter.Get() > static_cast<typename ImageType::PixelType>(0.5) &&
          input->GetPixel(o_iter.GetIndex()) > static_cast<typename ImageType::PixelType>(0.5))
      {
        o_iter.Set(1);
      }
      else
      {
        o_iter.Set(0);
      }
      ++o_iter;
    }
  }

  return temp;
}

#if 0
// TODO:  I am pretty sure that this can be completely
// replaced by the Morphological template above
// with option = true, flase, and
template <typename TImage>
typename TImage::Pointer  MorphologicalBinary( typename TImage::Pointer input, float rad, bool option)
{
  typedef TImage ImageType;
  enum { ImageDimension = TImage::ImageDimension };
  typedef typename TImage::PixelType PixelType;

  if( !option )
    {
//    std::cout << " eroding the image " << std::endl;
    }
  else
    {
//    std::cout << " dilating the image " << std::endl;
    }
  typedef itk::BinaryBallStructuringElement<
      PixelType,
      ImageDimension>             StructuringElementType;

  typedef itk::BinaryErodeImageFilter<
      TImage,
      TImage,
      StructuringElementType>  ErodeFilterType;

  typedef itk::BinaryDilateImageFilter<
      TImage,
      TImage,
      StructuringElementType>  DilateFilterType;

  typename ErodeFilterType::Pointer  binaryErode  = ErodeFilterType::New();
  typename DilateFilterType::Pointer binaryDilate = DilateFilterType::New();

  StructuringElementType structuringElement;

  structuringElement.SetRadius( (unsigned long) rad );  // 3x3x3 structuring element

  structuringElement.CreateStructuringElement();

  binaryErode->SetKernel(  structuringElement );
  binaryDilate->SetKernel( structuringElement );

  //  It is necessary to define what could be considered objects on the binary
  //  images. This is specified with the methods \code{SetErodeValue()} and
  //  \code{SetDilateValue()}. The value passed to these methods will be
  //  considered the value over which the dilation and erosion rules will apply
  binaryErode->SetErodeValue( 1 );
  binaryDilate->SetDilateValue( 1 );

  typename TImage::Pointer temp;
  if( option )
    {
    binaryDilate->SetInput( input );
    binaryDilate->Update();
    temp = binaryDilate->GetOutput();
    }
  else
    {
    binaryErode->SetInput( input );  // binaryDilate->GetOutput() );
    binaryErode->Update();
    temp = binaryErode->GetOutput();

    typedef itk::ImageRegionIteratorWithIndex<ImageType> ImageIteratorType;
    ImageIteratorType o_iter( temp, temp->GetLargestPossibleRegion() );
    o_iter.GoToBegin();
    while( !o_iter.IsAtEnd() )
      {
      if( o_iter.Get() > 0.5 && input->GetPixel(o_iter.GetIndex() ) > 0.5 )
        {
        o_iter.Set(1);
        }
      else
        {
        o_iter.Set(0);
        }
      ++o_iter;
      }
    }

  return temp;
}

#endif

template <typename TImage>
typename TImage::Pointer
BinaryThreshold(typename TImage::PixelType low,
                typename TImage::PixelType high,
                typename TImage::PixelType replaceval,
                typename TImage::Pointer   input)
{
  typedef typename TImage::PixelType PixelType;
  // Begin Threshold Image
  typedef itk::BinaryThresholdImageFilter<TImage, TImage> InputThresholderType;
  typename InputThresholderType::Pointer                  inputThresholder = InputThresholderType::New();

  inputThresholder->SetInput(input);
  inputThresholder->SetInsideValue(replaceval);
  int outval = 0;
  if (itk::Math::FloatAlmostEqual(static_cast<float>(replaceval), -1.0f))
  {
    outval = 1;
  }
  inputThresholder->SetOutsideValue(outval);

  if (high < low)
  {
    high = 255;
  }
  inputThresholder->SetLowerThreshold(static_cast<PixelType>(low));
  inputThresholder->SetUpperThreshold(static_cast<PixelType>(high));
  inputThresholder->Update();

  return inputThresholder->GetOutput();
}

template <typename TPixel, unsigned int VDim>
class VectorPixelCompare
{
public:
  bool
  operator()(const itk::Vector<TPixel, VDim> & v1, const itk::Vector<TPixel, VDim> & v2) const
  {
    // Ordering of vectors based on 1st component, then second, etc.
    for (size_t i = 0; i < VDim; i++)
    {
      if (v1[i] < v2[i])
      {
        return true;
      }
      else if (v1[i] > v2[i])
      {
        return false;
      }
    }
    return false;
  }
};

template <typename ImageType, typename AffineTransform>
void
GetAffineTransformFromImage(const typename ImageType::Pointer & img, typename AffineTransform::Pointer & aff)
{
  typedef typename ImageType::DirectionType         DirectionType;
  typedef typename ImageType::PointType             PointType;
  typedef typename AffineTransform::TranslationType VectorType;

  DirectionType direction = img->GetDirection();

  VectorType translation;
  // translation.Fill(0);
  for (unsigned int i = 0; i < ImageType::GetImageDimension(); i++)
  {
    translation[i] = img->GetOrigin()[i];
  }

  aff->SetMatrix(direction);
  // aff->SetCenter(pt);
  PointType pt;
  pt.Fill(0);
  aff->SetOffset(translation);
  aff->SetCenter(pt);

  //  std::cout << "aff from image:" << aff << std::endl;
}

template <typename WarperType, typename ImageType>
void
GetLargestSizeAfterWarp(typename WarperType::Pointer &  warper,
                        typename ImageType::Pointer &   img,
                        typename ImageType::SizeType &  largest_size,
                        typename ImageType::PointType & origin_warped)
{
  typedef typename ImageType::PointType PointType;

  const int ImageDimension = ImageType::GetImageDimension();
  // typedef typename ImageType::PointType PointType;
  typedef typename std::vector<PointType> PointList;

  typedef typename ImageType::IndexType IndexType;

  // PointList pts_orig;
  PointList pts_warped;

  typename ImageType::SizeType imgsz;
  imgsz = img->GetLargestPossibleRegion().GetSize();

  typename ImageType::SpacingType spacing;
  spacing = img->GetSpacing();

  pts_warped.clear();
  if (ImageDimension == 3)
  {
    for (int i = 0; i < 8; i++)
    {
      IndexType ind;

      switch (i)
      {
        case 0:
        {
          ind[0] = 0;
          ind[1] = 0;
          ind[2] = 0;
        }
        break;
        case 1:
        {
          ind[0] = imgsz[0] - 1;
          ind[1] = 0;
          ind[2] = 0;
        }
        break;
        case 2:
        {
          ind[0] = 0;
          ind[1] = imgsz[1] - 1;
          ind[2] = 0;
        }
        break;
        case 3:
        {
          ind[0] = imgsz[0] - 1;
          ind[1] = imgsz[1] - 1;
          ind[2] = 0;
        }
        break;
        case 4:
        {
          ind[0] = 0;
          ind[1] = 0;
          ind[2] = imgsz[2] - 1;
        }
        break;
        case 5:
        {
          ind[0] = imgsz[0] - 1;
          ind[1] = 0;
          ind[2] = imgsz[2] - 1;
        }
        break;
        case 6:
        {
          ind[0] = 0;
          ind[1] = imgsz[1] - 1;
          ind[2] = imgsz[2] - 1;
        }
        break;
        case 7:
        {
          ind[0] = imgsz[0] - 1;
          ind[1] = imgsz[1] - 1;
          ind[2] = imgsz[2] - 1;
        }
        break;
      }
      PointType pt_orig, pt_warped;
      img->TransformIndexToPhysicalPoint(ind, pt_orig);
      if (warper->MultiInverseAffineOnlySinglePoint(pt_orig, pt_warped) == false)
      {
        //    std::cout << "ERROR: outside of numeric boundary with affine transform." << std::endl;
        throw std::exception();
      }
      pts_warped.push_back(pt_warped);
      //    std::cout << '[' << i << ']' << ind << ',' << pt_orig << "->" << pt_warped << std::endl;
    }
  }
  else if (ImageDimension == 2)
  {
    for (int i = 0; i < 4; i++)
    {
      IndexType ind;

      switch (i)
      {
        case 0:
        {
          ind[0] = 0;
          ind[1] = 0;
        }
        break;
        case 1:
        {
          ind[0] = imgsz[0] - 1;
          ind[1] = 0;
        }
        break;
        case 2:
        {
          ind[0] = 0;
          ind[1] = imgsz[1] - 1;
        }
        break;
        case 3:
        {
          ind[0] = imgsz[0] - 1;
          ind[1] = imgsz[1] - 1;
        }
        break;
      }
      PointType pt_orig, pt_warped;
      img->TransformIndexToPhysicalPoint(ind, pt_orig);
      if (warper->MultiInverseAffineOnlySinglePoint(pt_orig, pt_warped) == false)
      {
        //    std::cout << "ERROR: outside of numeric boundary with affine transform." << std::endl;
        throw std::exception();
      }
      pts_warped.push_back(pt_warped);
      //    std::cout << '[' << i << ']' << ind << ',' << pt_orig << "->" << pt_warped << std::endl;
    }
  }
  else
  {
    //    std::cout << "could not determine the dimension after warping for non 2D/3D volumes" << std::endl;
    throw std::exception();
  }

  PointType pt_min, pt_max;
  pt_min = pts_warped[0];
  pt_max = pts_warped[0];
  for (unsigned int k = 0; k < pts_warped.size(); k++)
  {
    for (int i = 0; i < ImageDimension; i++)
    {
      pt_min[i] = (pt_min[i] < pts_warped[k][i]) ? (pt_min[i]) : (pts_warped[k][i]);
      pt_max[i] = (pt_max[i] > pts_warped[k][i]) ? (pt_max[i]) : (pts_warped[k][i]);
    }
  }
  for (int i = 0; i < ImageDimension; i++)
  {
    largest_size[i] = static_cast<int>((ceil((pt_max[i] - pt_min[i]) / spacing[i]) + 1));
  }

  origin_warped = pt_min;
  //  std::cout << "origin_warped: " << origin_warped << std::endl;
  //  std::cout << "pt_min: " << pt_min << " pt_max:" << pt_max << " largest_size:" << largest_size << std::endl;
}

template <typename TImageIn, typename TImageOut>
typename TImageOut::Pointer
arCastImage(typename TImageIn::Pointer Rimage)
{
  typedef itk::CastImageFilter<TImageIn, TImageOut> CastFilterType;
  typename CastFilterType::Pointer                  caster = CastFilterType::New();
  caster->SetInput(Rimage);
  caster->Update();
  return caster->GetOutput();
}


template <typename TValue>
TValue
Convert(std::string optionString)
{
  TValue             value;
  std::istringstream iss(optionString);
  iss >> value;
  return value;
}

template <typename TValue>
std::vector<TValue>
ConvertVector(std::string optionString)
{
  std::vector<TValue>    values;
  std::string::size_type crosspos = optionString.find('x', 0);

  if (crosspos == std::string::npos)
  {
    values.push_back(Convert<TValue>(optionString));
  }
  else
  {
    std::string element = optionString.substr(0, crosspos);

    TValue             value;
    std::istringstream iss(element);
    iss >> value;
    values.push_back(value);
    while (crosspos != std::string::npos)
    {
      std::string::size_type crossposfrom = crosspos;
      crosspos = optionString.find('x', crossposfrom + 1);
      if (crosspos == std::string::npos)
      {
        element = optionString.substr(crossposfrom + 1, optionString.length());
      }
      else
      {
        element = optionString.substr(crossposfrom + 1, crosspos - (crossposfrom + 1));
      }

      std::istringstream iss2(element);
      iss2 >> value;
      values.push_back(value);
    }
  }
  return values;
}

// void ANTsStringReplace( std::string &s, const std::string &search, const std::string &replace )
// {
//   for( size_t pos = 0; ; pos += replace.length() )
//  	  {
//     pos = s.find( search, pos );
//     if( pos == std::string::npos ) break;
//
//     s.erase( pos, search.length() );
//     s.insert( pos, replace );
//     }
//  }


} // namespace ants

// ##########################################################################
// TODO: KENT:  This block feels like it could be better encapsulated as a c++ class
//
typedef enum
{
  INVALID_FILE = 1,
  AFFINE_FILE,
  DEFORMATION_FILE,
  IMAGE_AFFINE_HEADER,
  IDENTITY_TRANSFORM
} TRAN_FILE_TYPE;

// TODO: This should be a class.
using TRAN_OPT = struct TRAN_OPT_STRUCT
{
  //    char *filename;
  std::string    filename;
  TRAN_FILE_TYPE file_type;
  bool           do_affine_inv;
  //    void SetValue(char *filename, TRAN_FILE_TYPE file_type, bool do_affine_inv){
  //        this.filename = filename;
  //        this.file_type = file_type;
  //        this.do_affine_inv = do_affine_inv;
  //    };
  double weight; // for average
};

typedef std::vector<TRAN_OPT> TRAN_OPT_QUEUE;

using MLINTERP_OPT = struct MLINTERP_OPT_STRUCT
{
  bool                physical_units;
  std::vector<double> sigma;
};

using MISC_OPT = struct MISC_OPT_STRUCT
{
  bool   use_NN_interpolator;
  bool   use_MultiLabel_interpolator;
  bool   use_BSpline_interpolator;
  bool   use_TightestBoundingBox;
  char * reference_image_filename;
  bool   use_RotationHeader;

  MLINTERP_OPT opt_ML;
};

extern TRAN_FILE_TYPE
CheckFileType(const char * const str);

extern TRAN_FILE_TYPE
CheckFileType(const std::string & str);

extern void
SetAffineInvFlag(TRAN_OPT & opt, bool & set_current_affine_inv);

extern void
DisplayOptQueue(const TRAN_OPT_QUEUE & opt_queue);

extern void
DisplayOpt(const TRAN_OPT & opt);

// ##########################################################################

extern bool
get_a_double_number(const char * const str, double & v);

// TODO: KENT:  These two functions have cross-platform-equivalent versions from kwSys and could be replaced.
extern void
FilePartsWithgz(const std::string & filename, std::string & path, std::string & name, std::string & ext);

extern bool
CheckFileExistence(const char * const str);

extern std::string
GetPreferredTransformFileType();

extern void
ConvertToLowerCase(std::string & str);

#endif // __antsUtilities_h__