File: TestBase.h

package info (click to toggle)
itksnap 3.4.0-2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 10,196 kB
  • ctags: 9,196
  • sloc: cpp: 62,895; sh: 175; makefile: 13
file content (100 lines) | stat: -rw-r--r-- 2,898 bytes parent folder | download | duplicates (3)
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
/*=========================================================================

  Program:   Insight Segmentation & Registration Toolkit
  Module:    $RCSfile: TestBase.h,v $
  Language:  C++
  Date:      $Date: 2009/11/14 16:19:56 $
  Version:   $Revision: 1.2 $
  Copyright (c) 2003 Insight Consortium. All rights reserved.
  See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.

     This software is distributed WITHOUT ANY WARRANTY; without even 
     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
     PURPOSE.  See the above copyright notices for more information.
=========================================================================*/
#ifndef __TestBase_h_
#define __TestBase_h_

#include "CommandLineArgumentParser.h"
#include "ImageIORoutines.h"
#include "itkOrientedImage.h"

/** Exception when needed parameters are omitted */
class TestUsageException : public itk::ExceptionObject {};

class TestBase
{
public:
  // Describe the usage of the test
  virtual void PrintUsage() = 0;

  // Get the ID of the test for command line specification
  virtual const char *GetTestName() = 0;
  
  // Get the ID of the test for command line specification
  virtual const char *GetDescription() = 0;

  // Tack on options to the command line parser
  virtual void ConfigureCommandLineParser(CommandLineArgumentParser &parser) = 0;

  // Pass command line parameters to the test
  virtual void SetCommandLineParameters(
    const CommandLineArgumentParseResult &parameters)
    {
    m_Command = parameters;
    }

  // Create a new test with given command line parameters.  The test
  // either runs succesfully and returns, or throws an exception
  // describing what happened.
  virtual void Run() = 0;

  // Destructor
  virtual ~TestBase() {}

protected:

  // The command line parse result, i.e., parameters of the test
  CommandLineArgumentParseResult m_Command;    
};

template <class TPixel>
class TestBaseOneImage : public TestBase
{
public:
  // Type definitions
  typedef itk::OrientedImage<TPixel,3> ImageType;
  typedef typename ImageType::Pointer ImagePointer;

  // Print how to use this test
  virtual void PrintUsage()
  {
    std::cerr << "  image FILE : Pass image name " << std::endl;
  }

  // Tack on options to the command line parser
  virtual void ConfigureCommandLineParser(CommandLineArgumentParser &parser)
  {
    parser.AddOption("image",1);
  }

  // Run method, loads the passed in message
  virtual void Run()
  {
    // Check if the image option is present
    if(!m_Command.IsOptionPresent("image"))
      throw new TestUsageException();

    // Load the image - will throw an exception if something fails
    LoadImageFromFile(m_Command.GetOptionParameter("image"),m_Image);
  }

  // Destructor
  virtual ~TestBaseOneImage() {}

protected:
  // The loaded image
  ImagePointer m_Image;
};

#endif //__TestBase_h_