Salome HOME
Fix for Bug IPAL8945
[modules/visu.git] / src / PIPELINE / VISU_img2vti.cxx
1 //  VISU OBJECT : interactive object for VISU entities implementation
2 //
3 //  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 //  This library is free software; you can redistribute it and/or
7 //  modify it under the terms of the GNU Lesser General Public
8 //  License as published by the Free Software Foundation; either
9 //  version 2.1 of the License.
10 //
11 //  This library is distributed in the hope that it will be useful,
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 //  Lesser General Public License for more details.
15 //
16 //  You should have received a copy of the GNU Lesser General Public
17 //  License along with this library; if not, write to the Free Software
18 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 //  See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
21 //
22 //
23 // File:    VISU_img2vti.cxx
24 // Author:  Oleg UVAROV
25 // Module : VISU
26
27 #include <vtkImageData.h>
28 #include <vtkBMPReader.h>
29 #include <vtkPNGReader.h>
30 #include <vtkJPEGReader.h>
31 #include <vtkXMLImageDataWriter.h>
32
33 #ifdef _DEBUG_
34 static int MYDEBUG = 0;
35 #else
36 static int MYDEBUG = 0;
37 #endif
38
39 int main( int argc, char** argv )
40 {
41   if(MYDEBUG) std::cout << "Converting the image to VTI format" << std::endl;
42
43   if( argc != 4 )
44   {
45     std::cout << "Usage : VISU_img2vti ImageFormat InputFileName OutputFileName" << std::endl;
46     return 1;
47   }
48
49   if(MYDEBUG){
50     std::cout << argv[1] << std::endl;
51     std::cout << argv[2] << std::endl;
52     std::cout << argv[3] << std::endl;
53   }
54
55   vtkImageReader2* aReader = NULL;
56   if( !strcmp( argv[1], "BMP" ) || !strcmp( argv[1], "bmp" ) )
57   {
58     if(MYDEBUG) std::cout << "Input image format - BMP" << std::endl;
59     aReader = vtkBMPReader::New();
60   }
61   else if( !strcmp( argv[1], "PNG" ) || !strcmp( argv[1], "png" ) )
62   {
63     if(MYDEBUG) std::cout << "Input image format - PNG" << std::endl;
64     aReader = vtkPNGReader::New();
65   }
66   else if( !strcmp( argv[1], "JPG" ) || !strcmp( argv[1], "jpg" ) )
67   {
68     if(MYDEBUG) std::cout << "Input image format - JPG" << std::endl;
69     aReader = vtkJPEGReader::New();
70   }
71   else
72   {
73     std::cout << "Unknown input image format... Must be BMP, PNG or JPG." << std::endl;
74     return 1;
75   }
76   aReader->SetFileName( argv[2] );
77   aReader->Update();
78
79   vtkXMLImageDataWriter* aWriter = vtkXMLImageDataWriter::New();
80   aWriter->SetInput( aReader->GetOutput() );
81   aWriter->SetFileName( argv[3] );
82   aWriter->Write();
83
84   aWriter->Delete();
85   aReader->Delete();
86
87   return 0;
88 }