]> SALOME platform Git repositories - modules/gui.git/blob - src/SVTK/SVTK_ImageWriter.cxx
Salome HOME
updated copyright message
[modules/gui.git] / src / SVTK / SVTK_ImageWriter.cxx
1 // Copyright (C) 2007-2023  CEA, EDF, 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, or (at your option) any later version.
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 "utilities.h"
23
24 #include <QSemaphore>
25
26 #include <vtkAlgorithm.h>
27 #include <vtkImageData.h>
28 #include <vtkImageClip.h>
29 #include <vtkJPEGWriter.h>
30 #include <vtkSmartPointer.h>
31
32
33 //----------------------------------------------------------------------------
34 SVTK_ImageWriter
35 ::SVTK_ImageWriter(QSemaphore* theSemaphore,
36                    vtkAlgorithm* theAlgorithm,
37                    vtkImageData* theImageData,
38                    const std::string& theName,
39                    int theProgressive,
40                    int theQuality):
41   mySemaphore(theSemaphore),
42   myAlgorithm(theAlgorithm),
43   myImageData(theImageData),
44   myName(theName),
45   myProgressive(theProgressive),
46   myQuality(theQuality),
47   myConstraint16Flag(true)
48 {}
49
50 //----------------------------------------------------------------------------
51 SVTK_ImageWriter
52 ::~SVTK_ImageWriter()
53 {
54   if(SALOME::VerbosityActivated())
55     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   vtkAlgorithmOutput *anImageData = 0;
66   vtkSmartPointer<vtkImageClip> anImageClip;
67   //
68   if(myConstraint16Flag){ 
69     int uExtent[6];
70     myAlgorithm->UpdateInformation();
71     myAlgorithm->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->SetInputData(myImageData);
83     anImageClip->SetOutputWholeExtent(uExtent);
84     anImageClip->ClipDataOn();
85     anImageData = anImageClip->GetOutputPort();
86   }
87   //
88   aWriter->WriteToMemoryOff();
89   aWriter->SetFileName(myName.c_str());
90   aWriter->SetQuality(myQuality);
91   aWriter->SetProgressive(myProgressive);
92   if(myConstraint16Flag)
93     aWriter->SetInputConnection(anImageData);
94   else
95     aWriter->SetInputData(myImageData);
96   aWriter->Write();
97
98   aWriter->Delete();
99   myImageData->Delete();
100
101   if(SALOME::VerbosityActivated())
102     cout << "SVTK_ImageWriter::run - this = " << this <<
103     //"; total = "<<mySemaphore->total()<<
104     "; available = " << mySemaphore->available() << endl;
105     
106   mySemaphore->release();
107 }
108