]> Creatis software - clitk.git/blob - tools/clitkPadImage.cxx
Rolled back to middle slice on first load
[clitk.git] / tools / clitkPadImage.cxx
1 #include "clitkCommon.h"
2 #include "clitkPadImage_ggo.h"
3 #include "clitkPadImageGenericFilter.h"
4
5 // template <class ImageType, class PadBoundType, unsigned int dim>
6 // int pad_like(typename ImageType::Pointer input, const std::string& likeFile, PadBoundType* padLower, PadBoundType* padUpper)
7 // {
8 //   typedef typename ImageType::SpacingType SpacingType;
9 //   typedef typename ImageType::RegionType RegionType;
10 //   typedef typename ImageType::SizeType SizeType;
11 //   typedef typename ImageType::IndexType IndexType;
12 //   typedef typename ImageType::PointType PointType;
13 //   typedef typename ImageType::PointValueType PointValueType;
14 // 
15 //   typedef itk::ImageFileReader<ImageType> ImageReaderType;
16 //   typename ImageReaderType::Pointer reader = ImageReaderType::New();
17 //   reader->SetFileName(likeFile);
18 //   reader->Update();
19 //   
20 //   typename ImageType::Pointer like_image = reader->GetOutput();
21 // 
22 //   SpacingType spacing = input->GetSpacing(), like_spacing = like_image->GetSpacing(); 
23 //   if (spacing != like_spacing) {
24 //     std::cerr << "Like-image must have same spacing as input: " << spacing << " " << like_spacing << std::endl;
25 //     return ERR_NOT_SAME_SPACING;
26 //   }
27 //   
28 //   SizeType size = input->GetLargestPossibleRegion().GetSize(), like_size = like_image->GetLargestPossibleRegion().GetSize();
29 //   PointType origin = input->GetOrigin(), like_origin = like_image->GetOrigin();
30 //   
31 //   PointType lower_bound, like_lower_bound;
32 //   PointType upper_bound, like_upper_bound;
33 //   PointValueType auxl = 0, auxu = 0;
34 //   for (unsigned int i = 0; i < dim; i++) {
35 //     lower_bound[i] = origin[i];
36 //     like_lower_bound[i] = like_origin[i];
37 //     auxl = itk::Math::Round<PointValueType>(((lower_bound[i] - like_lower_bound[i])/spacing[i]));
38 //     
39 //     upper_bound[i] = (lower_bound[i] + size[i]*spacing[i]);
40 //     like_upper_bound[i] = (like_lower_bound[i] + like_size[i]*spacing[i]);
41 //     auxu = itk::Math::Round<PointValueType>(((like_upper_bound[i] - upper_bound[i])/spacing[i]));
42 // 
43 //     if (auxl < 0 || auxu < 0) {
44 //       std::cerr << "Like-image's bounding box must be larger than input's" << std::endl;
45 //       return ERR_NOT_LIKE_LARGER;
46 //     }
47 // 
48 //     padLower[i] = (PadBoundType)auxl;
49 //     padUpper[i] = (PadBoundType)auxu;
50 //   }
51 //   
52 //   return ERR_SUCCESS;
53 // }
54
55 int main(int argc, char** argv)
56 {
57 /*  const DimType dim = 3;
58   typedef short PixelType;
59   typedef itk::Image<PixelType, dim> ImageType;
60   typedef itk::ImageFileReader<ImageType> ImageReaderType;
61   typedef itk::ImageFileWriter<ImageType> ImageWriterType;
62   typedef itk::ConstantPadImageFilter<ImageType, ImageType> PadFilterType;
63   typedef PadFilterType::SizeValueType PadBoundType;*/
64   
65   GGO(clitkPadImage, args_info);
66
67   // Filter
68   typedef clitk::PadImageGenericFilter FilterType;
69   FilterType::Pointer filter = FilterType::New();
70
71   filter->SetArgsInfo(args_info);
72
73   try { 
74     filter->Update();
75   } catch(std::runtime_error e) {
76     std::cout << e.what() << std::endl;
77   }
78   
79 //   ImageReaderType::Pointer reader = ImageReaderType::New();
80 //   reader->SetFileName(args_info.input_arg);
81 //   reader->Update();
82 //   
83 //   PadBoundType pad_lower[dim], pad_upper[dim];
84 //   ImageType::Pointer input = reader->GetOutput();
85 //   if (args_info.like_given) {
86 //     int err = pad_like<ImageType, PadBoundType, dim>(input, args_info.like_arg, pad_lower, pad_upper);
87 //     if (err) {
88 //       std::cerr << "Error processing like image." << std::endl;
89 //       return err;
90 //     }
91 //   }
92 //   else {
93 //     for (DimType i = 0; i < dim; i++) {
94 //       pad_lower[i] = args_info.lower_arg[i];
95 //       pad_upper[i] = args_info.upper_arg[i];
96 //     }
97 //   }
98 //   
99 //   PadFilterType::Pointer filter = PadFilterType::New();
100 //   filter->SetPadLowerBound(pad_lower);
101 //   filter->SetPadUpperBound(pad_upper);
102 //   filter->SetInput(input);
103 //   filter->SetConstant(args_info.value_arg);
104 //   filter->Update();
105 //   
106 //   ImageType::Pointer output = filter->GetOutput();
107 //   ImageWriterType::Pointer writer = ImageWriterType::New();
108 //   writer->SetInput(output);
109 //   writer->SetFileName(args_info.output_arg);
110 //   writer->Update();
111   
112   return EXIT_SUCCESS;
113 }
114