]> SALOME platform Git repositories - modules/visu.git/blob - src/VVTK/VVTK_ImageWriter.cxx
Salome HOME
Join modifications from BR_Dev_For_4_0 tag V4_1_1.
[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->UpdateInformation();
80     myImageData->GetUpdateExtent(uExtent);
81     unsigned int width = uExtent[1] - uExtent[0] + 1;
82     unsigned int height = uExtent[3] - uExtent[2] + 1;
83     width = (width / 16) * 16;
84     height= (height / 16) * 16;
85     uExtent[1] = uExtent[0] + width - 1;
86     uExtent[3] = uExtent[2] + height - 1;
87     //
88     anImageClip = vtkImageClip::New();
89     anImageClip->Delete();
90
91     anImageClip->SetInput(myImageData);
92     anImageClip->SetOutputWholeExtent(uExtent);
93     anImageClip->ClipDataOn();
94     anImageData = anImageClip->GetOutput();
95   }
96   //
97   aWriter->WriteToMemoryOff();
98   aWriter->SetFileName(myName.c_str());
99   aWriter->SetQuality(myQuality);
100   aWriter->SetProgressive(myProgressive);
101   aWriter->SetInput(anImageData);
102   aWriter->Write();
103
104   aWriter->Delete();
105   myImageData->Delete();
106
107   if(MYDEBUG) cout<<"VVTK_ImageWriter::run "<<
108                 "- this = "<<this<<
109                 "; total = "<<mySemaphore->total()<<
110                 "; available = "<<mySemaphore->available()<<endl;
111   *mySemaphore -= 1;
112 }
113