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 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[]) {
61 GGO(clitkImageCreate, args_info);
64 // Check --like option
66 if (args_info.like_given) {
67 itk::ImageIOBase::Pointer header = clitk::readImageHeader(args_info.like_arg);
68 dim = header->GetNumberOfDimensions();
69 //mPixelTypeName = header->GetComponentTypeAsString(header->GetComponentType());
70 //mNbOfComponents = header->GetNumberOfComponents();
71 args_info.size_given = dim;
72 args_info.size_arg = new int[dim];
73 args_info.spacing_given = dim;
74 args_info.spacing_arg = new float[dim];
75 args_info.origin_given = dim;
76 args_info.origin_arg = new double[dim];
78 for(int i=0; i<dim; i++) {
79 args_info.size_arg[i] = header->GetDimensions(i);
80 args_info.spacing_arg[i] = header->GetSpacing(i);
81 args_info.origin_arg[i]= header->GetOrigin(i);
86 if ((args_info.size_given > 4) || (args_info.size_given <2)) {
87 std::cerr << "ERROR : only 2D/3D/4D image ! Please give 2 or 3 or 4 number to the --size option." << std::endl;
90 dim = args_info.size_given;
93 std::vector<double> origin;
95 for(int i=0; i<dim; i++) origin[i]=0.;
96 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];
102 if (args_info.origin_given != args_info.size_given) {
103 std::cerr << "ERROR : please give the same number of values for --origin and --size." << std::endl;
106 for(int i=0; i<dim; i++) origin[i] = args_info.origin_arg[i];
111 std::vector<float> spacing;
113 if (args_info.spacing_given == 1) {
114 for(int i=0; i<dim; i++) spacing[i] = args_info.spacing_arg[0];
117 if (args_info.spacing_given != args_info.size_given) {
118 std::cerr << "ERROR : please give the same number of values for --size and --spacing." << std::endl;
121 for(int i=0; i<dim; i++) spacing[i] = args_info.spacing_arg[i];
125 typedef float PixelType;
128 typedef itk::Image<PixelType, Dim> ImageType;
129 ImageType::Pointer output = ImageType::New();
130 NewFilledImage<ImageType>(args_info.size_arg, &spacing[0], &origin[0], args_info.value_arg, output);
131 clitk::writeImage<ImageType>(output, args_info.output_arg);
135 typedef itk::Image<PixelType, Dim> ImageType;
136 ImageType::Pointer output = ImageType::New();
137 NewFilledImage<ImageType>(args_info.size_arg, &spacing[0], &origin[0], args_info.value_arg, output);
138 clitk::writeImage<ImageType>(output, args_info.output_arg);
142 typedef itk::Image<PixelType, Dim> ImageType;
143 ImageType::Pointer output = ImageType::New();
144 NewFilledImage<ImageType>(args_info.size_arg, &spacing[0], &origin[0], args_info.value_arg, output);
145 clitk::writeImage<ImageType>(output, args_info.output_arg);
148 // this is the end my friend
152 #endif //define CLITKIMAGEARITHM_CXX