]> SALOME platform Git repositories - modules/visu.git/blob - src/VVTK/VVTK_ImageWriter.cxx
Salome HOME
Merge from BR_V5_DEV 16Feb09
[modules/visu.git] / src / VVTK / VVTK_ImageWriter.cxx
1 //  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 //  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
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.
10 //
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.
15 //
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
19 //
20 //  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 //  SALOME VTKViewer : build VTK viewer into Salome desktop
23 //  File   :
24 //  Author :
25 //  Module :
26 //  $Header$
27 //
28 #include "VVTK_ImageWriter.h"
29
30 #include <QSemaphore>
31
32 #include "utilities.h"
33
34 #include <vtkImageData.h>
35 #include <vtkImageClip.h>
36 #include <vtkJPEGWriter.h>
37 #include <vtkSmartPointer.h>
38
39 #ifdef _DEBUG_
40 static int MYDEBUG = 0;
41 #else
42 static int MYDEBUG = 0;
43 #endif
44
45
46 //----------------------------------------------------------------------------
47 VVTK_ImageWriter
48 ::VVTK_ImageWriter(QSemaphore* theSemaphore,
49                    vtkImageData* theImageData,
50                    const std::string& theName,
51                    int theProgressive,
52                    int theQuality):
53   mySemaphore(theSemaphore),
54   myImageData(theImageData),
55   myName(theName),
56   myProgressive(theProgressive),
57   myQuality(theQuality),
58   myConstraint16Flag(true)
59 {}
60
61 //----------------------------------------------------------------------------
62 VVTK_ImageWriter
63 ::~VVTK_ImageWriter()
64 {
65   if(MYDEBUG) MESSAGE("VVTK_ImageWriter::~VVTK_ImageWriter - this = "<<this);
66 }
67
68
69 //----------------------------------------------------------------------------
70 void
71 VVTK_ImageWriter
72 ::run()
73 {
74   vtkJPEGWriter *aWriter = vtkJPEGWriter::New();
75   vtkImageData *anImageData = myImageData;
76   vtkSmartPointer<vtkImageClip> anImageClip;
77   //
78   if(myConstraint16Flag){ 
79     int uExtent[6];
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;
88     //
89     anImageClip = vtkImageClip::New();
90     anImageClip->Delete();
91
92     anImageClip->SetInput(myImageData);
93     anImageClip->SetOutputWholeExtent(uExtent);
94     anImageClip->ClipDataOn();
95     anImageData = anImageClip->GetOutput();
96   }
97   //
98   aWriter->WriteToMemoryOff();
99   aWriter->SetFileName(myName.c_str());
100   aWriter->SetQuality(myQuality);
101   aWriter->SetProgressive(myProgressive);
102   aWriter->SetInput(anImageData);
103   aWriter->Write();
104
105   aWriter->Delete();
106   myImageData->Delete();
107
108   if(MYDEBUG) MESSAGE("VVTK_ImageWriter::run "<<
109                 "- this = "<<this<<
110                 //"; total = "<<mySemaphore->total()<<
111                 "; available = "<<mySemaphore->available() );
112   mySemaphore->release();
113 }
114