CBICA Toolkit  1.0.0
cbicaITKCommonHolder.h
Go to the documentation of this file.
1 /**
2 \file cbicaITKCommonHolder.h
3 
4 \brief Declaration of the CommonHolder class
5 
6 This class computes the average of a series of 2 or 3 dimension images.
7 
8 https://www.cbica.upenn.edu/sbia/software/ <br>
9 software@cbica.upenn.edu
10 
11 Copyright (c) 2015 University of Pennsylvania. All rights reserved. <br>
12 See COPYING file or https://www.cbica.upenn.edu/sbia/software/license.html
13 
14 */
15 #pragma once
16 
17 #include <iostream>
18 #include <string>
19 #include <vector>
20 
21 #include "itkImageIOBase.h"
22 #include "itkImageIOFactory.h"
23 #include "itkDiffusionTensor3D.h"
24 #include "itkImage.h"
25 #include "itkImageFileReader.h"
26 #include "itkImageFileWriter.h"
27 #include "itkNiftiImageIO.h"
28 
29 #include "cbicaUtilities.h"
30 
31 using namespace itk;
32 
33 /*
34 \namespace cbica
35 \brief Namespace for differentiating functions written for internal use
36 */
37 namespace cbica
38 {
39  /**
40  \class CommonHolder
41 
42  \brief Common data container for all statistical computations of images
43  */
45  {
46  public:
47 
48  /**
49  \brief Default Constructor
50 
51  Use the SetParameters() method if this is used
52  */
53  explicit CommonHolder();
54 
55  /**
56  \brief Actual Constructor
57 
58  ALL scalars are computed. Output is saved using cbica::createTmpDir()
59 
60  \param inputFileName The Input File Name
61  */
62  explicit CommonHolder( const std::string &inputFileName );
63 
64  /**
65  \brief Actual Constructor
66 
67  ALL scalars are computed. Output is saved using cbica::createTmpDir()
68 
69  \param inputFileNames The Input File Names
70  */
71  explicit CommonHolder( const std::vector<std::string> &inputFileNames );
72 
73  /**
74  \brief Actual Constructor
75 
76  ALL scalars are computed.
77 
78  \param inputFileName The Input File Name
79  \param output The output file or directory
80  */
81  explicit CommonHolder( const std::string &inputFileName, const std::string &output );
82 
83  /**
84  \brief Actual Constructor
85 
86  ALL scalars are computed.
87 
88  \param inputFileNames Vector of input file names
89  \param output The output file or directory
90  */
91  explicit CommonHolder( const std::vector<std::string> &inputFileNames, const std::string &output );
92 
93  /**
94  \brief Actual Constructor
95 
96  \param inputFileName The Input File Name
97  \param output The output file or directory
98  \param prefix Prefix for output. Disregarded if output is file
99  */
100  explicit CommonHolder( const std::string &inputFileName, const std::string &output,
101  const std::string &prefix );
102 
103  /**
104  \brief Actual Constructor
105 
106  \param inputFileNames Vector of input file names
107  \param output The output file or directory
108  \param prefix Prefix for output. Disregarded if output is file
109  */
110  explicit CommonHolder( const std::vector<std::string> &inputFileNames, const std::string &output,
111  const std::string &prefix );
112 
113  /**
114  \brief The Destructor
115  */
116  virtual ~CommonHolder();
117 
118  protected:
119  // vector of input file names
120  std::vector<FileNameParts> m_inputFiles_parts;
121  std::vector< std::string > m_inputFiles;
122 
123  // output directory (to write multiple files)
124  std::string m_outputDir;
125 
126  // output files (includes path as prefix)
127  //std::string m_outputFile;
128 
129  // output basenames (include path as prefix)
130  //std::string m_outputBaseName;
131 
132  // output files (includes path as prefix)
133  std::vector<std::string> m_outputFiles;
134 
135  // output basenames (include path as prefix)
136  std::vector<std::string> m_outputBaseNames;
137 
138  // other parameters
139  std::string m_prefix, m_suffix, m_extension;
140 
141  itk::ImageIOBase::IOComponentType m_componentType;
142  itk::ImageIOBase::IOPixelType m_pixelType;
143  std::string m_componentType_asString, m_pixelType_asString;
144 
145  /**
146  \brief Exception handling for input file names
147  */
148  virtual void checkInputs();
149 
150  /**
151  \brief Set parameters after using default constructor
152 
153  \param inputFileNames Vector of input file(s)
154  \param output Output file/dir
155  \param prefix For output
156  */
157  virtual void SetParameters( const std::vector<std::string> &inputFileNames,
158  const std::string &output, const std::string &prefix );
159 
160  /**
161  \brief Main function to call different algorithms
162 
163  All inheriting classes need to implement this method. It should interface with initializeClass().
164  */
165  virtual void runAlgorithm();
166 
167  /**
168  \brief Checks the input and throws exception if there is an issue
169 
170  This verifies the input image file and throws an exception if there is an issue. For variable (but required)
171  inputs, please use checkInputs() function. If the inherited class doesn't have any required parameter other than
172  the input, then checkInputs() can be left as an empty void function. If the output is empty, then
173  cbica::createTmpDir() is invoked and the resultant directory is shown as output in the command line.
174 
175  \param inputFileNames Wrap for m_inputFiles
176  \param output Can have the output file or directory. If file is specified without path, it is written in temp dir created using cbica::createTmpDir()
177  */
178  inline void initializeClass( const std::vector<std::string> &inputFileNames,
179  const std::string &output,
180  const std::string &prefix);
181 
182  };
183 
184 }
Common data container for all statistical computations of images.
Definition: cbicaITKCommonHolder.h:44
Some basic utility functions.