1 // Copyright (C) 2007-2023 CEA, EDF, OPEN CASCADE
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.
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.
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
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #include "SVTK_ImageWriter.h"
22 #include "utilities.h"
26 #include <vtkAlgorithm.h>
27 #include <vtkImageData.h>
28 #include <vtkImageClip.h>
29 #include <vtkJPEGWriter.h>
30 #include <vtkSmartPointer.h>
33 //----------------------------------------------------------------------------
35 ::SVTK_ImageWriter(QSemaphore* theSemaphore,
36 vtkAlgorithm* theAlgorithm,
37 vtkImageData* theImageData,
38 const std::string& theName,
41 mySemaphore(theSemaphore),
42 myAlgorithm(theAlgorithm),
43 myImageData(theImageData),
45 myProgressive(theProgressive),
46 myQuality(theQuality),
47 myConstraint16Flag(true)
50 //----------------------------------------------------------------------------
54 if(SALOME::VerbosityActivated())
55 cout << "SVTK_ImageWriter::~SVTK_ImageWriter - this = " << this << endl;
59 //----------------------------------------------------------------------------
64 vtkJPEGWriter *aWriter = vtkJPEGWriter::New();
65 vtkAlgorithmOutput *anImageData = 0;
66 vtkSmartPointer<vtkImageClip> anImageClip;
68 if(myConstraint16Flag){
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;
79 anImageClip = vtkImageClip::New();
80 anImageClip->Delete();
82 anImageClip->SetInputData(myImageData);
83 anImageClip->SetOutputWholeExtent(uExtent);
84 anImageClip->ClipDataOn();
85 anImageData = anImageClip->GetOutputPort();
88 aWriter->WriteToMemoryOff();
89 aWriter->SetFileName(myName.c_str());
90 aWriter->SetQuality(myQuality);
91 aWriter->SetProgressive(myProgressive);
92 if(myConstraint16Flag)
93 aWriter->SetInputConnection(anImageData);
95 aWriter->SetInputData(myImageData);
99 myImageData->Delete();
101 if(SALOME::VerbosityActivated())
102 cout << "SVTK_ImageWriter::run - this = " << this <<
103 //"; total = "<<mySemaphore->total()<<
104 "; available = " << mySemaphore->available() << endl;
106 mySemaphore->release();