]> SALOME platform Git repositories - modules/gui.git/blob - src/SVTK/SVTK_ImageWriter.cxx
Salome HOME
581111ba6dfd65678fa688634b722e482d2efde5
[modules/gui.git] / src / SVTK / SVTK_ImageWriter.cxx
1 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 #include "SVTK_ImageWriter.h"
21
22 #include <QSemaphore>
23
24 #include <vtkImageData.h>
25 #include <vtkImageClip.h>
26 #include <vtkJPEGWriter.h>
27 #include <vtkSmartPointer.h>
28
29 #ifdef _DEBUG_
30 static int MYDEBUG = 0;
31 #else
32 static int MYDEBUG = 0;
33 #endif
34
35
36 //----------------------------------------------------------------------------
37 SVTK_ImageWriter
38 ::SVTK_ImageWriter(QSemaphore* theSemaphore,
39                    vtkImageData* theImageData,
40                    const std::string& theName,
41                    int theProgressive,
42                    int theQuality):
43   mySemaphore(theSemaphore),
44   myImageData(theImageData),
45   myName(theName),
46   myProgressive(theProgressive),
47   myQuality(theQuality),
48   myConstraint16Flag(true)
49 {}
50
51 //----------------------------------------------------------------------------
52 SVTK_ImageWriter
53 ::~SVTK_ImageWriter()
54 {
55   if(MYDEBUG) cout<<"SVTK_ImageWriter::~SVTK_ImageWriter - this = "<<this<<endl;
56 }
57
58
59 //----------------------------------------------------------------------------
60 void
61 SVTK_ImageWriter
62 ::run()
63 {
64   vtkJPEGWriter *aWriter = vtkJPEGWriter::New();
65   vtkImageData *anImageData = myImageData;
66   vtkSmartPointer<vtkImageClip> anImageClip;
67   //
68   if(myConstraint16Flag){ 
69     int uExtent[6];
70     myImageData->UpdateInformation();
71     myImageData->GetUpdateExtent(uExtent);
72     unsigned int width = uExtent[1] - uExtent[0] + 1;
73     unsigned int height = uExtent[3] - uExtent[2] + 1;
74     width = (width / 16) * 16;
75     height= (height / 16) * 16;
76     uExtent[1] = uExtent[0] + width - 1;
77     uExtent[3] = uExtent[2] + height - 1;
78     //
79     anImageClip = vtkImageClip::New();
80     anImageClip->Delete();
81
82     anImageClip->SetInput(myImageData);
83     anImageClip->SetOutputWholeExtent(uExtent);
84     anImageClip->ClipDataOn();
85     anImageData = anImageClip->GetOutput();
86   }
87   //
88   aWriter->WriteToMemoryOff();
89   aWriter->SetFileName(myName.c_str());
90   aWriter->SetQuality(myQuality);
91   aWriter->SetProgressive(myProgressive);
92   aWriter->SetInput(anImageData);
93   aWriter->Write();
94
95   aWriter->Delete();
96   myImageData->Delete();
97
98   if(MYDEBUG) cout<<"SVTK_ImageWriter::run "<<
99                 "- this = "<<this<<
100                 //"; total = "<<mySemaphore->total()<<
101                 "; available = "<<mySemaphore->available()<<endl;
102   mySemaphore->release();
103 }
104