+/*=========================================================================
+ Program: vv http://www.creatis.insa-lyon.fr/rio/vv
+
+ Authors belong to:
+ - University of LYON http://www.universite-lyon.fr/
+ - Léon Bérard cancer center http://www.centreleonberard.fr
+ - CREATIS CNRS laboratory http://www.creatis.insa-lyon.fr
+
+ This software is distributed WITHOUT ANY WARRANTY; without even
+ the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ PURPOSE. See the copyright notices for more information.
+
+ It is distributed under dual licence
+
+ - BSD See included LICENSE.txt file
+ - CeCILL-B http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
+===========================================================================**/
#ifndef CLITKIMAGECREATE_CXX
#define CLITKIMAGECREATE_CXX
/**
template<class ImageType>
void NewFilledImage(int * size, float * spacing, double * origin,
- double value,typename ImageType::Pointer output)
+ double value,typename ImageType::Pointer output)
{
static const unsigned int Dim = ImageType::GetImageDimension();
typename ImageType::SizeType mSize;
//--------------------------------------------------------------------
-int main(int argc, char * argv[]) {
+int main(int argc, char * argv[])
+{
// Init command line
GGO(clitkImageCreate, args_info);
int dim;
if (args_info.like_given) {
itk::ImageIOBase::Pointer header = clitk::readImageHeader(args_info.like_arg);
- dim = header->GetNumberOfDimensions();
- //mPixelTypeName = header->GetComponentTypeAsString(header->GetComponentType());
- //mNbOfComponents = header->GetNumberOfComponents();
- args_info.size_given = dim;
- args_info.size_arg = new int[dim];
- args_info.spacing_given = dim;
- args_info.spacing_arg = new float[dim];
- args_info.origin_given = dim;
- args_info.origin_arg = new double[dim];
-
- for(int i=0; i<dim; i++) {
- args_info.size_arg[i] = header->GetDimensions(i);
- args_info.spacing_arg[i] = header->GetSpacing(i);
- args_info.origin_arg[i]= header->GetOrigin(i);
- }
+ dim = header->GetNumberOfDimensions();
+ //mPixelTypeName = header->GetComponentTypeAsString(header->GetComponentType());
+ //mNbOfComponents = header->GetNumberOfComponents();
+ args_info.size_given = dim;
+ args_info.size_arg = new int[dim];
+ args_info.spacing_given = dim;
+ args_info.spacing_arg = new float[dim];
+ args_info.origin_given = dim;
+ args_info.origin_arg = new double[dim];
+
+ for(int i=0; i<dim; i++) {
+ args_info.size_arg[i] = header->GetDimensions(i);
+ args_info.spacing_arg[i] = header->GetSpacing(i);
+ args_info.origin_arg[i]= header->GetOrigin(i);
+ }
}
// Check dimension
exit(-1);
}
dim = args_info.size_given;
-
- // origin
+
+ // origin
std::vector<double> origin;
origin.resize(dim);
for(int i=0; i<dim; i++) origin[i]=0.;
- if (args_info.origin_given)
- {
- if (args_info.origin_given==1)
- for(int i=0; i<dim; i++) origin[i] = args_info.origin_arg[0];
- else
- {
- if (args_info.origin_given != args_info.size_given) {
- std::cerr << "ERROR : please give the same number of values for --origin and --size." << std::endl;
- exit(-1);
- }
- for(int i=0; i<dim; i++) origin[i] = args_info.origin_arg[i];
- }
+ if (args_info.origin_given) {
+ if (args_info.origin_given==1)
+ for(int i=0; i<dim; i++) origin[i] = args_info.origin_arg[0];
+ else {
+ if (args_info.origin_given != args_info.size_given) {
+ std::cerr << "ERROR : please give the same number of values for --origin and --size." << std::endl;
+ exit(-1);
+ }
+ for(int i=0; i<dim; i++) origin[i] = args_info.origin_arg[i];
}
+ }
- // spacing
+ // spacing
std::vector<float> spacing;
spacing.resize(dim);
if (args_info.spacing_given == 1) {
for(int i=0; i<dim; i++) spacing[i] = args_info.spacing_arg[0];
- }
- else {
+ } else {
if (args_info.spacing_given != args_info.size_given) {
std::cerr << "ERROR : please give the same number of values for --size and --spacing." << std::endl;
exit(-1);
}
for(int i=0; i<dim; i++) spacing[i] = args_info.spacing_arg[i];
}
-
+
// Create new image
typedef float PixelType;
if (dim == 2) {
const int Dim=2;
- typedef itk::Image<PixelType, Dim> ImageType;
+ typedef itk::Image<PixelType, Dim> ImageType;
ImageType::Pointer output = ImageType::New();
NewFilledImage<ImageType>(args_info.size_arg, &spacing[0], &origin[0], args_info.value_arg, output);
clitk::writeImage<ImageType>(output, args_info.output_arg);
}
if (dim == 3) {
const int Dim=3;
- typedef itk::Image<PixelType, Dim> ImageType;
+ typedef itk::Image<PixelType, Dim> ImageType;
ImageType::Pointer output = ImageType::New();
NewFilledImage<ImageType>(args_info.size_arg, &spacing[0], &origin[0], args_info.value_arg, output);
clitk::writeImage<ImageType>(output, args_info.output_arg);
}
if (dim == 4) {
const int Dim=4;
- typedef itk::Image<PixelType, Dim> ImageType;
+ typedef itk::Image<PixelType, Dim> ImageType;
ImageType::Pointer output = ImageType::New();
NewFilledImage<ImageType>(args_info.size_arg, &spacing[0], &origin[0], args_info.value_arg, output);
clitk::writeImage<ImageType>(output, args_info.output_arg);
}
-
- // this is the end my friend
+
+ // this is the end my friend
return 0;
} // end main