1 // SALOME VTKViewer : build VTK viewer into Salome desktop
\r
3 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
\r
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
\r
6 // This library is free software; you can redistribute it and/or
\r
7 // modify it under the terms of the GNU Lesser General Public
\r
8 // License as published by the Free Software Foundation; either
\r
9 // version 2.1 of the License.
\r
11 // This library is distributed in the hope that it will be useful,
\r
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
\r
14 // Lesser General Public License for more details.
\r
16 // You should have received a copy of the GNU Lesser General Public
\r
17 // License along with this library; if not, write to the Free Software
\r
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
\r
20 // See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
\r
29 #include "VVTK_ImageWriter.h"
\r
31 #include <qsemaphore.h>
\r
33 #include <vtkImageData.h>
\r
34 #include <vtkImageClip.h>
\r
35 #include <vtkJPEGWriter.h>
\r
36 #include <vtkSmartPointer.h>
\r
39 static int MYDEBUG = 0;
\r
41 static int MYDEBUG = 0;
\r
45 //----------------------------------------------------------------------------
\r
47 ::VVTK_ImageWriter(QSemaphore* theSemaphore,
\r
48 vtkImageData* theImageData,
\r
49 const std::string& theName,
\r
52 mySemaphore(theSemaphore),
\r
53 myImageData(theImageData),
\r
55 myProgressive(theProgressive),
\r
56 myQuality(theQuality),
\r
57 myConstraint16Flag(true)
\r
60 //----------------------------------------------------------------------------
\r
62 ::~VVTK_ImageWriter()
\r
64 if(MYDEBUG) cout<<"VVTK_ImageWriter::~VVTK_ImageWriter - this = "<<this<<endl;
\r
68 //----------------------------------------------------------------------------
\r
73 vtkJPEGWriter *aWriter = vtkJPEGWriter::New();
\r
74 vtkImageData *anImageData = myImageData;
\r
75 vtkSmartPointer<vtkImageClip> anImageClip;
\r
77 if(myConstraint16Flag){
\r
79 myImageData->GetUpdateExtent(uExtent);
\r
80 unsigned int width = uExtent[1] - uExtent[0] + 1;
\r
81 unsigned int height = uExtent[3] - uExtent[2] + 1;
\r
82 width = (width / 16) * 16;
\r
83 height= (height / 16) * 16;
\r
84 uExtent[1] = uExtent[0] + width - 1;
\r
85 uExtent[3] = uExtent[2] + height - 1;
\r
87 anImageClip = vtkImageClip::New();
\r
88 anImageClip->Delete();
\r
90 anImageClip->SetInput(myImageData);
\r
91 anImageClip->SetOutputWholeExtent(uExtent);
\r
92 anImageClip->ClipDataOn();
\r
93 anImageData = anImageClip->GetOutput();
\r
96 aWriter->WriteToMemoryOff();
\r
97 aWriter->SetFileName(myName.c_str());
\r
98 aWriter->SetQuality(myQuality);
\r
99 aWriter->SetProgressive(myProgressive);
\r
100 aWriter->SetInput(anImageData);
\r
104 myImageData->Delete();
\r
106 if(MYDEBUG) cout<<"VVTK_ImageWriter::run "<<
\r
107 "- this = "<<this<<
\r
108 "; total = "<<mySemaphore->total()<<
\r
109 "; available = "<<mySemaphore->available()<<endl;
\r