1 /*=========================================================================
2 Program: vv http://www.creatis.insa-lyon.fr/rio/vv
5 - University of LYON http://www.universite-lyon.fr/
6 - Léon Bérard cancer center http://oncora1.lyon.fnclcc.fr
7 - CREATIS CNRS laboratory http://www.creatis.insa-lyon.fr
9 This software is distributed WITHOUT ANY WARRANTY; without even
10 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
11 PURPOSE. See the copyright notices for more information.
13 It is distributed under dual licence
15 - BSD See included LICENSE.txt file
16 - CeCILL-B http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
17 ======================================================================-====*/
18 #ifndef CLITKVFRESAMPLE_CXX
19 #define CLITKVFRESAMPLE_CXX
22 #include "clitkVFResample_ggo.h"
24 #include "clitkVFResampleGenericFilter.h"
26 //--------------------------------------------------------------------
27 int main(int argc, char * argv[])
31 GGO(clitkVFResample, args_info);
34 // Read input image header to check image dimension
35 itk::ImageIOBase::Pointer header = clitk::readImageHeader(args_info.input_arg);
36 unsigned int dim = header->GetNumberOfDimensions();
37 std::string pixelTypeName = header->GetComponentTypeAsString(header->GetComponentType());
39 // Print image info if verbose
40 if (args_info.verbose_flag) {
41 std::cout << "Input image <" << args_info.input_arg << "> is ";
42 clitk::printImageHeader(header, std::cout);
43 std::cout << std::endl;
46 // Get input size/spacing
47 std::vector<int> inputSize;
48 std::vector<double> inputSpacing;
49 inputSize.resize(dim);
50 inputSpacing.resize(dim);
51 for(unsigned int i=0; i<dim; i++) {
52 inputSpacing[i] = header->GetSpacing(i);
53 inputSize[i] = header->GetDimensions(i);
57 std::vector<int> outputSize;
58 std::vector<double> outputSpacing;
59 outputSize.resize(dim);
60 outputSpacing.resize(dim);
63 if (!args_info.size_given && !args_info.spacing_given) {
64 std::cerr << "Please indicate output size or spacing." << std::endl;
69 if (args_info.size_given && args_info.spacing_given) {
70 std::cerr << "Please indicate only output size or spacing, not both." << std::endl;
74 // Size is given and not spacing
75 if (args_info.size_given && !args_info.spacing_given) {
76 if (args_info.size_given != dim) {
77 std::cerr << "Input image is " << dim << "D, please give " << dim << " size numbers." << std::endl;
80 for(unsigned int i=0; i<dim; i++) {
81 if ((args_info.size_arg[i] == -1) || (args_info.size_arg[i]==0))
82 outputSize[i] = inputSize[i];
84 outputSize[i] = args_info.size_arg[i];
85 outputSpacing[i] = inputSize[i]*inputSpacing[i]/outputSize[i];
89 // Spacing is given and not size
90 if (!args_info.size_given && args_info.spacing_given) {
91 if (args_info.spacing_given != dim) {
92 if (args_info.spacing_given == 1) {
93 for(unsigned int i=0; i<dim; i++) outputSpacing[i] = args_info.spacing_arg[0];
95 std::cerr << "Input image is " << dim << "D, please give " << dim << " spacing numbers." << std::endl;
99 for(unsigned int i=0; i<dim; i++) {
100 if ((args_info.spacing_arg[i] == -1) || (args_info.spacing_arg[i]==0))
101 outputSpacing[i] = inputSpacing[i];
103 outputSpacing[i] = args_info.spacing_arg[i];
107 for(unsigned int i=0; i<dim; i++)
108 outputSize[i] = (int)lrint(inputSize[i]*inputSpacing[i]/outputSpacing[i]);
111 if (args_info.verbose_flag) {
112 std::cout << "Output image will be : " << std::endl;
114 DDV(outputSpacing,dim);
117 // Get sigma option for Gaussian filter
118 std::vector<double> sigma;
119 sigma.resize(args_info.gauss_given);
120 std::copy(args_info.gauss_arg, args_info.gauss_arg+args_info.gauss_given, sigma.begin());
121 if (args_info.gauss_given) {
122 if (args_info.gauss_given != dim) {
123 if (args_info.gauss_given == 1) {
125 for(unsigned int i=0; i<dim; i++) sigma[i] = args_info.gauss_arg[0];
127 std::cerr << "Input image is " << dim << "D, please give " << dim << " sigma numbers for gaussian filter." << std::endl;
134 clitk::VFResampleGenericFilter::Pointer filter = clitk::VFResampleGenericFilter::New();
135 filter->SetInputFilename(args_info.input_arg);
136 filter->SetOutputSize(outputSize);
137 filter->SetOutputSpacing(outputSpacing);
138 filter->SetInterpolationName(args_info.interp_arg);
139 filter->SetBSplineOrder(args_info.order_arg);
140 filter->SetBLUTSampling(args_info.sampling_arg);
141 if (args_info.gauss_given)
142 filter->SetGaussianSigma(sigma);
143 filter->SetOutputFilename(args_info.output_arg);
148 // this is the end my friend
151 //--------------------------------------------------------------------
153 #endif /* end #define CLITKVFRESAMPLE_CXX */