1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 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
22 // SALOME VTKViewer : build VTK viewer into Salome desktop
28 #include "VVTK_ImageWriter.h"
32 #include "utilities.h"
34 #include <vtkImageData.h>
35 #include <vtkImageClip.h>
36 #include <vtkJPEGWriter.h>
37 #include <vtkSmartPointer.h>
40 static int MYDEBUG = 0;
42 static int MYDEBUG = 0;
46 //----------------------------------------------------------------------------
48 ::VVTK_ImageWriter(QSemaphore* theSemaphore,
49 vtkImageData* theImageData,
50 const std::string& theName,
53 mySemaphore(theSemaphore),
54 myImageData(theImageData),
56 myProgressive(theProgressive),
57 myQuality(theQuality),
58 myConstraint16Flag(true)
61 //----------------------------------------------------------------------------
65 if(MYDEBUG) MESSAGE("VVTK_ImageWriter::~VVTK_ImageWriter - this = "<<this);
69 //----------------------------------------------------------------------------
74 vtkJPEGWriter *aWriter = vtkJPEGWriter::New();
75 vtkImageData *anImageData = myImageData;
76 vtkSmartPointer<vtkImageClip> anImageClip;
78 if(myConstraint16Flag){
80 myImageData->UpdateInformation();
81 myImageData->GetUpdateExtent(uExtent);
82 unsigned int width = uExtent[1] - uExtent[0] + 1;
83 unsigned int height = uExtent[3] - uExtent[2] + 1;
84 width = (width / 16) * 16;
85 height= (height / 16) * 16;
86 uExtent[1] = uExtent[0] + width - 1;
87 uExtent[3] = uExtent[2] + height - 1;
89 anImageClip = vtkImageClip::New();
90 anImageClip->Delete();
92 anImageClip->SetInput(myImageData);
93 anImageClip->SetOutputWholeExtent(uExtent);
94 anImageClip->ClipDataOn();
95 anImageData = anImageClip->GetOutput();
98 aWriter->WriteToMemoryOff();
99 aWriter->SetFileName(myName.c_str());
100 aWriter->SetQuality(myQuality);
101 aWriter->SetProgressive(myProgressive);
102 aWriter->SetInput(anImageData);
106 myImageData->Delete();
108 if(MYDEBUG) MESSAGE("VVTK_ImageWriter::run "<<
110 //"; total = "<<mySemaphore->total()<<
111 "; available = "<<mySemaphore->available() );
112 mySemaphore->release();