Back to index

salome-gui  6.5.0
SVTK_ImageWriterMgr.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_ImageWriterMgr.h"
00021 #include "SVTK_ImageWriter.h"
00022 
00023 #include <vtkImageData.h>
00024 
00025 #include <QSemaphore>
00026 
00027 #include <limits>
00028 
00029 
00030 #ifdef _DEBUG_
00031 static int MYDEBUG = 0;
00032 #else
00033 static int MYDEBUG = 0;
00034 #endif
00035 
00036 //----------------------------------------------------------------------------
00037 SVTK_ImageWriterMgr
00038 ::SVTK_ImageWriterMgr()
00039 {
00040   int aMax = std::numeric_limits<int>::max() / 2;
00041   mySemaphore = new QSemaphore(aMax);
00042   mySemaphore->acquire( aMax );
00043   if(MYDEBUG) cout<<"SVTK_ImageWriterMgr::SVTK_ImageWriterMgr "<<
00044                 //"- total = "<<mySemaphore->total()<<
00045                 "; available = "<<mySemaphore->available()<<endl;
00046 }
00047 
00048 
00049 //----------------------------------------------------------------------------
00050 SVTK_ImageWriterMgr
00051 ::~SVTK_ImageWriterMgr()
00052 {
00053   Stop();
00054   delete mySemaphore;
00055 }
00056 
00057 
00058 //----------------------------------------------------------------------------
00059 void
00060 SVTK_ImageWriterMgr
00061 ::StartImageWriter(vtkImageData *theImageData,
00062                    const std::string& theName,
00063                    const int theProgressive,
00064                    const int theQuality)
00065 {
00066   SVTK_ImageWriter *anImageWriter = 
00067     new SVTK_ImageWriter(mySemaphore,
00068                          theImageData,
00069                          theName,
00070                          theProgressive,
00071                          theQuality);
00072   myThreads.push_back(anImageWriter);
00073 
00074   anImageWriter->start();
00075 
00076 }
00077 
00078 
00079 //----------------------------------------------------------------------------
00080 void
00081 SVTK_ImageWriterMgr
00082 ::Stop()
00083 {
00084   if(MYDEBUG) cout<<"SVTK_ImageWriterMgr::Stop "<<
00085                 //"- total = "<<mySemaphore->total()<<
00086                 "; available = "<<mySemaphore->available()<<endl;
00087   if(MYDEBUG) cout<<"SVTK_ImageWriterMgr::Stop - *mySemaphore += "<<myThreads.size()<<endl;
00088   mySemaphore->acquire( myThreads.size() );
00089 
00090   for(size_t anId = 0, anEnd = myThreads.size(); anId < anEnd; anId++){
00091     SVTK_ImageWriter* anImageWriter = myThreads[anId];
00092     anImageWriter->wait();
00093     delete anImageWriter;
00094   }
00095   myThreads.clear();
00096 }