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://www.centreleonberard.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 CLITKIMAGECREATE_CXX
19 #define CLITKIMAGECREATE_CXX
21 ------------------------------------------------=
22 * @file clitkImageCreate.cxx
23 * @author David Sarrut <David.Sarrut@creatis.insa-lyon.fr>
24 * @date 14 Oct 2008 08:37:53
25 ------------------------------------------------=*/
28 #include "clitkImageCreate_ggo.h"
29 #include "clitkCommon.h"
30 #include "clitkImageCommon.h"
33 template<class ImageType>
34 void NewFilledImage(int * size, float * spacing, double * origin,
35 double value,typename ImageType::Pointer output)
37 static const unsigned int Dim = ImageType::GetImageDimension();
38 typename ImageType::SizeType mSize;
40 for(unsigned int i=0; i<Dim; i++) mSize[i] = size[i];
41 typename ImageType::RegionType mRegion;
42 mRegion.SetSize(mSize);
43 typename ImageType::SpacingType mSpacing;
44 for(unsigned int i=0; i<Dim; i++) mSpacing[i] = spacing[i];
45 output->SetRegions(mRegion);
46 output->SetSpacing(mSpacing);
48 typename ImageType::PointType mOrigin;
49 for(unsigned int i=0; i<Dim; i++) mOrigin[i] = origin[i];
50 output->SetOrigin(mOrigin);
51 typedef typename ImageType::PixelType PixelType;
52 PixelType p = clitk::PixelTypeDownCast<double, PixelType>(value);
53 output->FillBuffer(p);
57 //--------------------------------------------------------------------
58 int main(int argc, char * argv[])
62 GGO(clitkImageCreate, args_info);
65 // Check --like option
67 if (args_info.like_given) {
68 itk::ImageIOBase::Pointer header = clitk::readImageHeader(args_info.like_arg);
69 dim = header->GetNumberOfDimensions();
70 //mPixelTypeName = header->GetComponentTypeAsString(header->GetComponentType());
71 //mNbOfComponents = header->GetNumberOfComponents();
72 args_info.size_given = dim;
73 args_info.size_arg = new int[dim];
74 args_info.spacing_given = dim;
75 args_info.spacing_arg = new float[dim];
76 args_info.origin_given = dim;
77 args_info.origin_arg = new double[dim];
79 for(int i=0; i<dim; i++) {
80 args_info.size_arg[i] = header->GetDimensions(i);
81 args_info.spacing_arg[i] = header->GetSpacing(i);
82 args_info.origin_arg[i]= header->GetOrigin(i);
87 if ((args_info.size_given > 4) || (args_info.size_given <2)) {
88 std::cerr << "ERROR : only 2D/3D/4D image ! Please give 2 or 3 or 4 number to the --size option." << std::endl;
91 dim = args_info.size_given;
94 std::vector<double> origin;
96 for(int i=0; i<dim; i++) origin[i]=0.;
97 if (args_info.origin_given) {
98 if (args_info.origin_given==1)
99 for(int i=0; i<dim; i++) origin[i] = args_info.origin_arg[0];
101 if (args_info.origin_given != args_info.size_given) {
102 std::cerr << "ERROR : please give the same number of values for --origin and --size." << std::endl;
105 for(int i=0; i<dim; i++) origin[i] = args_info.origin_arg[i];
110 std::vector<float> spacing;
112 if (args_info.spacing_given == 1) {
113 for(int i=0; i<dim; i++) spacing[i] = args_info.spacing_arg[0];
115 if (args_info.spacing_given != args_info.size_given) {
116 std::cerr << "ERROR : please give the same number of values for --size and --spacing." << std::endl;
119 for(int i=0; i<dim; i++) spacing[i] = args_info.spacing_arg[i];
123 typedef float PixelType;
126 typedef itk::Image<PixelType, Dim> ImageType;
127 ImageType::Pointer output = ImageType::New();
128 NewFilledImage<ImageType>(args_info.size_arg, &spacing[0], &origin[0], args_info.value_arg, output);
129 clitk::writeImage<ImageType>(output, args_info.output_arg);
133 typedef itk::Image<PixelType, Dim> ImageType;
134 ImageType::Pointer output = ImageType::New();
135 NewFilledImage<ImageType>(args_info.size_arg, &spacing[0], &origin[0], args_info.value_arg, output);
136 clitk::writeImage<ImageType>(output, args_info.output_arg);
140 typedef itk::Image<PixelType, Dim> ImageType;
141 ImageType::Pointer output = ImageType::New();
142 NewFilledImage<ImageType>(args_info.size_arg, &spacing[0], &origin[0], args_info.value_arg, output);
143 clitk::writeImage<ImageType>(output, args_info.output_arg);
146 // this is the end my friend
150 #endif //define CLITKIMAGEARITHM_CXX