File: itkCommandLineParserTest.cxx

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 (123 lines) | stat: -rw-r--r-- 3,699 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

#include "antsUtilities.h"
#include <algorithm>

#include "itkPICSLAdvancedNormalizationToolKit.h"
#include "itkCommandLineParser.h"

namespace ants
{
// entry point for the library; parameter 'args' is equivalent to 'argv' in (argc,argv) of commandline parameters to
// 'main()'
int
itkCommandLineParserTest(std::vector<std::string> args, std::ostream * out_stream = nullptr)
{
  // put the arguments coming in as 'args' into standard (argc,argv) format;
  // 'args' doesn't have the command name as first, argument, so add it manually;
  // 'args' may have adjacent arguments concatenated into one argument,
  // which the parser should handle
  args.insert(args.begin(), "itkCommandLineParserTest");

  int     argc = args.size();
  char ** argv = new char *[args.size() + 1];
  for (unsigned int i = 0; i < args.size(); ++i)
  {
    // allocate space for the string plus a null character
    argv[i] = new char[args[i].length() + 1];
    std::strncpy(argv[i], args[i].c_str(), args[i].length());
    // place the null character in the end
    argv[i][args[i].length()] = '\0';
  }
  argv[argc] = 0;
  // class to automatically cleanup argv upon destruction
  class Cleanup_argv
  {
  public:
    Cleanup_argv(char ** argv_, int argc_plus_one_)
      : argv(argv_)
      , argc_plus_one(argc_plus_one_)
    {}

    ~Cleanup_argv()
    {
      for (unsigned int i = 0; i < argc_plus_one; ++i)
      {
        delete[] argv[i];
      }
      delete[] argv;
    }

  private:
    char **      argv;
    unsigned int argc_plus_one;
  };
  Cleanup_argv cleanup_argv(argv, argc + 1);

  // antscout->set_stream( out_stream );

  typedef itk::PICSLAdvancedNormalizationToolKit<3> RegistrationType;
  RegistrationType::Pointer                         registration = RegistrationType::New();

  registration->ParseCommandLine(argc, argv);

  typedef itk::CommandLineParser ParserType;
  ParserType::Pointer            parser = ParserType::New();

  typedef ParserType::OptionType OptionType;
  OptionType::Pointer            fileOption = OptionType::New();
  fileOption->SetShortName('f');
  fileOption->SetLongName("file");
  fileOption->SetDescription("The fixed image file used in the image registration algorithm.");

  parser->AddOption(fileOption);

  typedef ParserType::OptionType OptionType;
  OptionType::Pointer            metricOption = OptionType::New();
  metricOption->SetShortName('m');
  metricOption->SetLongName("metric");
  metricOption->SetDescription("The metric used by the image registration algorithm.");

  parser->AddOption(metricOption);

  typedef ParserType::OptionType OptionType;
  OptionType::Pointer            verbosityOption = OptionType::New();
  verbosityOption->SetLongName("verbosity");
  verbosityOption->SetDescription("Mundi vult decipi.  ");

  parser->AddOption(verbosityOption);

  typedef ParserType::OptionType OptionType;
  OptionType::Pointer            dirOption = OptionType::New();
  dirOption->SetLongName("directionality");
  //  dirOption->SetShortName( 'd' );
  dirOption->SetDescription("Mundi vult decipi.  ");

  parser->AddOption(dirOption);

  if (parser->Parse(argc, argv) == EXIT_FAILURE)
  {
    return EXIT_FAILURE;
  }

  if (!parser->GetOption("directionality"))
  {
    std::cout << "N ULL" << std::endl;
  }
  else
  {
    for (unsigned int j = 0; j < 3; j++)
    {
      std::cout << parser->ConvertVector<bool>(parser->GetOption("directionality")->GetValue(0))[j] << " x ";
    }
  }

  parser->PrintMenu(std::cout, 7);

  //  std::cout << std::endl << std::endl << "--------------------------------------------"
  //            << std::endl << std::endl;

  //  parser->Print( std::cout << 7 );

  return 0;
};
} // namespace ants