Salome HOME
Join modifications from branch BR_DEBUG_3_2_0b1
[modules/visu.git] / src / VVTK / VVTK_ImageWriter.cxx
1 //  SALOME VTKViewer : build VTK viewer into Salome desktop
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.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 //
23 //
24 //  File   :
25 //  Author :
26 //  Module :
27 //  $Header$
28
29 #include "VVTK_ImageWriter.h"
30
31 #include <qsemaphore.h>
32
33 #include <vtkImageData.h>
34 #include <vtkImageClip.h>
35 #include <vtkJPEGWriter.h>
36 #include <vtkSmartPointer.h>
37
38 #ifdef _DEBUG_
39 static int MYDEBUG = 0;
40 #else
41 static int MYDEBUG = 0;
42 #endif
43
44
45 //----------------------------------------------------------------------------
46 VVTK_ImageWriter
47 ::VVTK_ImageWriter(QSemaphore* theSemaphore,
48                    vtkImageData* theImageData,
49                    const std::string& theName,
50                    int theProgressive,
51                    int theQuality):
52   mySemaphore(theSemaphore),
53   myImageData(theImageData),
54   myName(theName),
55   myProgressive(theProgressive),
56   myQuality(theQuality),
57   myConstraint16Flag(true)
58 {}
59
60 //----------------------------------------------------------------------------
61 VVTK_ImageWriter
62 ::~VVTK_ImageWriter()
63 {
64   if(MYDEBUG) cout<<"VVTK_ImageWriter::~VVTK_ImageWriter - this = "<<this<<endl;
65 }
66
67
68 //----------------------------------------------------------------------------
69 void
70 VVTK_ImageWriter
71 ::run()
72 {
73   vtkJPEGWriter *aWriter = vtkJPEGWriter::New();
74   vtkImageData *anImageData = myImageData;
75   vtkSmartPointer<vtkImageClip> anImageClip;
76   //
77   if(myConstraint16Flag){ 
78     int uExtent[6];
79     myImageData->GetUpdateExtent(uExtent);
80     unsigned int width = uExtent[1] - uExtent[0] + 1;
81     unsigned int height = uExtent[3] - uExtent[2] + 1;
82     width = (width / 16) * 16;
83     height= (height / 16) * 16;
84     uExtent[1] = uExtent[0] + width - 1;
85     uExtent[3] = uExtent[2] + height - 1;
86     //
87     anImageClip = vtkImageClip::New();
88     anImageClip->Delete();
89
90     anImageClip->SetInput(myImageData);
91     anImageClip->SetOutputWholeExtent(uExtent);
92     anImageClip->ClipDataOn();
93     anImageData = anImageClip->GetOutput();
94   }
95   //
96   aWriter->WriteToMemoryOff();
97   aWriter->SetFileName(myName.c_str());
98   aWriter->SetQuality(myQuality);
99   aWriter->SetProgressive(myProgressive);
100   aWriter->SetInput(anImageData);
101   aWriter->Write();
102
103   aWriter->Delete();
104   myImageData->Delete();
105
106   if(MYDEBUG) cout<<"VVTK_ImageWriter::run "<<
107                 "- this = "<<this<<
108                 "; total = "<<mySemaphore->total()<<
109                 "; available = "<<mySemaphore->available()<<endl;
110   *mySemaphore -= 1;
111 }
112