1 // SALOME VTKViewer : build VTK viewer into Salome desktop
3 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
29 #include "VVTK_ImageWriter.h"
31 #include <qsemaphore.h>
33 #include <vtkImageData.h>
34 #include <vtkImageClip.h>
35 #include <vtkJPEGWriter.h>
36 #include <vtkSmartPointer.h>
39 static int MYDEBUG = 0;
41 static int MYDEBUG = 0;
45 //----------------------------------------------------------------------------
47 ::VVTK_ImageWriter(QSemaphore* theSemaphore,
48 vtkImageData* theImageData,
49 const std::string& theName,
52 mySemaphore(theSemaphore),
53 myImageData(theImageData),
55 myProgressive(theProgressive),
56 myQuality(theQuality),
57 myConstraint16Flag(true)
60 //----------------------------------------------------------------------------
64 if(MYDEBUG) cout<<"VVTK_ImageWriter::~VVTK_ImageWriter - this = "<<this<<endl;
68 //----------------------------------------------------------------------------
73 vtkJPEGWriter *aWriter = vtkJPEGWriter::New();
74 vtkImageData *anImageData = myImageData;
75 vtkSmartPointer<vtkImageClip> anImageClip;
77 if(myConstraint16Flag){
79 myImageData->GetUpdateExtent(uExtent);
80 unsigned int width = uExtent[1] - uExtent[0] + 1;
81 unsigned int height = uExtent[3] - uExtent[2] + 1;
82 width = (width / 16) * 16;
83 height= (height / 16) * 16;
84 uExtent[1] = uExtent[0] + width - 1;
85 uExtent[3] = uExtent[2] + height - 1;
87 anImageClip = vtkImageClip::New();
88 anImageClip->Delete();
90 anImageClip->SetInput(myImageData);
91 anImageClip->SetOutputWholeExtent(uExtent);
92 anImageClip->ClipDataOn();
93 anImageData = anImageClip->GetOutput();
96 aWriter->WriteToMemoryOff();
97 aWriter->SetFileName(myName.c_str());
98 aWriter->SetQuality(myQuality);
99 aWriter->SetProgressive(myProgressive);
100 aWriter->SetInput(anImageData);
104 myImageData->Delete();
106 if(MYDEBUG) cout<<"VVTK_ImageWriter::run "<<
108 "; total = "<<mySemaphore->total()<<
109 "; available = "<<mySemaphore->available()<<endl;