Salome HOME
Update copyright information
[modules/visu.git] / src / PIPELINE / VISU_img2vti.cxx
1 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  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.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 //  VISU OBJECT : interactive object for VISU entities implementation
24 // File:    VISU_img2vti.cxx
25 // Author:  Oleg UVAROV
26 // Module : VISU
27 //
28 #include <vtkImageData.h>
29 #include <vtkBMPReader.h>
30 #include <vtkPNGReader.h>
31 #include <vtkJPEGReader.h>
32 #include <vtkXMLImageDataWriter.h>
33
34 #ifdef _DEBUG_
35 static int MYDEBUG = 0;
36 #else
37 static int MYDEBUG = 0;
38 #endif
39
40 int main( int argc, char** argv )
41 {
42   if(MYDEBUG) std::cout << "Converting the image to VTI format" << std::endl;
43
44   if( argc != 4 )
45   {
46     std::cout << "Usage : VISU_img2vti ImageFormat InputFileName OutputFileName" << std::endl;
47     return 1;
48   }
49
50   if(MYDEBUG){
51     std::cout << argv[1] << std::endl;
52     std::cout << argv[2] << std::endl;
53     std::cout << argv[3] << std::endl;
54   }
55
56   vtkImageReader2* aReader = NULL;
57   if( !strcmp( argv[1], "BMP" ) || !strcmp( argv[1], "bmp" ) )
58   {
59     if(MYDEBUG) std::cout << "Input image format - BMP" << std::endl;
60     aReader = vtkBMPReader::New();
61   }
62   else if( !strcmp( argv[1], "PNG" ) || !strcmp( argv[1], "png" ) )
63   {
64     if(MYDEBUG) std::cout << "Input image format - PNG" << std::endl;
65     aReader = vtkPNGReader::New();
66   }
67   else if( !strcmp( argv[1], "JPG" ) || !strcmp( argv[1], "jpg" ) )
68   {
69     if(MYDEBUG) std::cout << "Input image format - JPG" << std::endl;
70     aReader = vtkJPEGReader::New();
71   }
72   else
73   {
74     std::cout << "Unknown input image format... Must be BMP, PNG or JPG." << std::endl;
75     return 1;
76   }
77   aReader->SetFileName( argv[2] );
78   aReader->Update();
79
80   vtkXMLImageDataWriter* aWriter = vtkXMLImageDataWriter::New();
81   aWriter->SetInput( aReader->GetOutput() );
82   aWriter->SetFileName( argv[3] );
83   aWriter->Write();
84
85   aWriter->Delete();
86   aReader->Delete();
87
88   return 0;
89 }