]> Creatis software - clitk.git/blobdiff - tools/clitkImageConvert.cxx
With ITK 5, add itkReadRawBytesAfterSwappingMacro and itkWriteRawBytesAfterSwappingMacro
[clitk.git] / tools / clitkImageConvert.cxx
index b4fceed096e458a8898a1084c54cf1307b7f77a9..e54c736d99ae1d9e433204931ebb0c4f7533c9d3 100644 (file)
@@ -1,21 +1,22 @@
-/*-------------------------------------------------------------------------
-                                                                                
-Program:   clitk
-Language:  C++
-                                                                                
-Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
-l'Image). All rights reserved. See Doc/License.txt or
-http://www.creatis.insa-lyon.fr/Public/Gdcm/License.html for details.
-                                                                                
-This software is distributed WITHOUT ANY WARRANTY; without even
-the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
-PURPOSE.  See the above copyright notices for more information.
-                                                                             
--------------------------------------------------------------------------*/
+/*=========================================================================
+  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 CLITKIMAGECONVERT_CXX
 #define CLITKIMAGECONVERT_CXX
-
 /**
    -------------------------------------------------
    * @file   clitkImageConvert.cxx
@@ -30,7 +31,8 @@ PURPOSE.  See the above copyright notices for more information.
 #include "clitkImageConvertGenericFilter.h"
 
 //-------------------------------------------------------------------=
-int main(int argc, char * argv[]) {
+int main(int argc, char * argv[])
+{
 
   // init command line
   GGO(clitkImageConvert, args_info);
@@ -38,31 +40,45 @@ int main(int argc, char * argv[]) {
 
   // Get list of filenames
   std::vector<std::string> l;
-  for(unsigned int i=0; i<args_info.input_given; i++) {
-    l.push_back(args_info.input_arg[i]);
+  unsigned int nCmdLineInputs = args_info.inputs_num;
+  std::string output;
+  if(args_info.output_given)
+    output = args_info.output_arg;
+  else if(nCmdLineInputs--)
+    output = args_info.inputs[nCmdLineInputs];
+  else {
+    std::cerr << "Error, you should give the --output option or one image filename on the commande line." << std::endl;
+    exit(0);
   }
-  for(unsigned int i=0; i<args_info.inputs_num; i++) {
-    l.push_back(args_info.inputs[i]);
+
+  if(args_info.input_given) {
+    l.push_back(args_info.input_arg);
+  }
+  if(nCmdLineInputs==1) {
+    l.push_back(args_info.inputs[0]);
   }
   if (l.size() < 1) {
-    std::cerr << "Error, you should give at least one --input option or one image filename on the commande line." << std::endl;
+    std::cerr << "Error, you should give the --input option or one image filename on the commande line." << std::endl;
     exit(0);
-  }  
+  }
 
   // Create filter
   clitk::ImageConvertGenericFilter::Pointer filter = clitk::ImageConvertGenericFilter::New();
   filter->SetInputFilenames(l);
   filter->SetIOVerbose(args_info.verbose_flag);
-  filter->SetOutputFilename(args_info.output_arg);
+  filter->SetOutputFilename(output);
+  filter->SetVV(args_info.vv_flag);
+  filter->SetNoNiiMeta(args_info.noniimeta_flag);
+  filter->SetCorrectNegativeSpacingFlag(args_info.correct_flag);
+  filter->EnableWriteCompression(args_info.compression_flag);
   if (args_info.type_given) filter->SetOutputPixelType(args_info.type_arg);
 
   // Go !
-  filter->Update();  
+  CLITK_TRY_CATCH_EXIT(filter->Update());
 
-  // this is the end my friend  
+  // this is the end my friend
   return 0;
 }
 //-------------------------------------------------------------------=
 
 #endif /* end #define CLITKIMAGECONVERT_CXX */
-