Back to index

salome-gui  6.5.0
SVTK_ImageWriter.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // This library is free software; you can redistribute it and/or
00004 // modify it under the terms of the GNU Lesser General Public
00005 // License as published by the Free Software Foundation; either
00006 // version 2.1 of the License.
00007 //
00008 // This library is distributed in the hope that it will be useful,
00009 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00010 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00011 // Lesser General Public License for more details.
00012 //
00013 // You should have received a copy of the GNU Lesser General Public
00014 // License along with this library; if not, write to the Free Software
00015 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00016 //
00017 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00018 //
00019 
00020 #include "SVTK_ImageWriter.h"
00021 
00022 #include <QSemaphore>
00023 
00024 #include <vtkImageData.h>
00025 #include <vtkImageClip.h>
00026 #include <vtkJPEGWriter.h>
00027 #include <vtkSmartPointer.h>
00028 
00029 #ifdef _DEBUG_
00030 static int MYDEBUG = 0;
00031 #else
00032 static int MYDEBUG = 0;
00033 #endif
00034 
00035 
00036 //----------------------------------------------------------------------------
00037 SVTK_ImageWriter
00038 ::SVTK_ImageWriter(QSemaphore* theSemaphore,
00039                    vtkImageData* theImageData,
00040                    const std::string& theName,
00041                    int theProgressive,
00042                    int theQuality):
00043   mySemaphore(theSemaphore),
00044   myImageData(theImageData),
00045   myName(theName),
00046   myProgressive(theProgressive),
00047   myQuality(theQuality),
00048   myConstraint16Flag(true)
00049 {}
00050 
00051 //----------------------------------------------------------------------------
00052 SVTK_ImageWriter
00053 ::~SVTK_ImageWriter()
00054 {
00055   if(MYDEBUG) cout<<"SVTK_ImageWriter::~SVTK_ImageWriter - this = "<<this<<endl;
00056 }
00057 
00058 
00059 //----------------------------------------------------------------------------
00060 void
00061 SVTK_ImageWriter
00062 ::run()
00063 {
00064   vtkJPEGWriter *aWriter = vtkJPEGWriter::New();
00065   vtkImageData *anImageData = myImageData;
00066   vtkSmartPointer<vtkImageClip> anImageClip;
00067   //
00068   if(myConstraint16Flag){ 
00069     int uExtent[6];
00070     myImageData->UpdateInformation();
00071     myImageData->GetUpdateExtent(uExtent);
00072     unsigned int width = uExtent[1] - uExtent[0] + 1;
00073     unsigned int height = uExtent[3] - uExtent[2] + 1;
00074     width = (width / 16) * 16;
00075     height= (height / 16) * 16;
00076     uExtent[1] = uExtent[0] + width - 1;
00077     uExtent[3] = uExtent[2] + height - 1;
00078     //
00079     anImageClip = vtkImageClip::New();
00080     anImageClip->Delete();
00081 
00082     anImageClip->SetInput(myImageData);
00083     anImageClip->SetOutputWholeExtent(uExtent);
00084     anImageClip->ClipDataOn();
00085     anImageData = anImageClip->GetOutput();
00086   }
00087   //
00088   aWriter->WriteToMemoryOff();
00089   aWriter->SetFileName(myName.c_str());
00090   aWriter->SetQuality(myQuality);
00091   aWriter->SetProgressive(myProgressive);
00092   aWriter->SetInput(anImageData);
00093   aWriter->Write();
00094 
00095   aWriter->Delete();
00096   myImageData->Delete();
00097 
00098   if(MYDEBUG) cout<<"SVTK_ImageWriter::run "<<
00099                 "- this = "<<this<<
00100                 //"; total = "<<mySemaphore->total()<<
00101                 "; available = "<<mySemaphore->available()<<endl;
00102   mySemaphore->release();
00103 }
00104