1 // Copyright (C) 2007-2015 CEA/DEN, EDF R&D, 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"
24 #include <vtkAlgorithm.h>
25 #include <vtkImageData.h>
26 #include <vtkImageClip.h>
27 #include <vtkJPEGWriter.h>
28 #include <vtkSmartPointer.h>
31 static int MYDEBUG = 0;
33 static int MYDEBUG = 0;
37 //----------------------------------------------------------------------------
39 ::SVTK_ImageWriter(QSemaphore* theSemaphore,
40 vtkAlgorithm* theAlgorithm,
41 vtkImageData* theImageData,
42 const std::string& theName,
45 mySemaphore(theSemaphore),
46 myAlgorithm(theAlgorithm),
47 myImageData(theImageData),
49 myProgressive(theProgressive),
50 myQuality(theQuality),
51 myConstraint16Flag(true)
54 //----------------------------------------------------------------------------
58 if(MYDEBUG) cout<<"SVTK_ImageWriter::~SVTK_ImageWriter - this = "<<this<<endl;
62 //----------------------------------------------------------------------------
67 vtkJPEGWriter *aWriter = vtkJPEGWriter::New();
68 vtkAlgorithmOutput *anImageData = 0;
69 vtkSmartPointer<vtkImageClip> anImageClip;
71 if(myConstraint16Flag){
73 myAlgorithm->UpdateInformation();
74 myAlgorithm->GetUpdateExtent(uExtent);
75 unsigned int width = uExtent[1] - uExtent[0] + 1;
76 unsigned int height = uExtent[3] - uExtent[2] + 1;
77 width = (width / 16) * 16;
78 height= (height / 16) * 16;
79 uExtent[1] = uExtent[0] + width - 1;
80 uExtent[3] = uExtent[2] + height - 1;
82 anImageClip = vtkImageClip::New();
83 anImageClip->Delete();
85 anImageClip->SetInputData(myImageData);
86 anImageClip->SetOutputWholeExtent(uExtent);
87 anImageClip->ClipDataOn();
88 anImageData = anImageClip->GetOutputPort();
91 aWriter->WriteToMemoryOff();
92 aWriter->SetFileName(myName.c_str());
93 aWriter->SetQuality(myQuality);
94 aWriter->SetProgressive(myProgressive);
95 if(myConstraint16Flag)
96 aWriter->SetInputConnection(anImageData);
98 aWriter->SetInputData(myImageData);
102 myImageData->Delete();
104 if(MYDEBUG) cout<<"SVTK_ImageWriter::run "<<
106 //"; total = "<<mySemaphore->total()<<
107 "; available = "<<mySemaphore->available()<<endl;
108 mySemaphore->release();