Salome HOME
Fix for Bug IPAL8945
[modules/visu.git] / src / VVTK / VVTK_ImageWriter.cxx
1 //  SALOME VTKViewer : build VTK viewer into Salome desktop\r
2 //\r
3 //  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,\r
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS \r
5 // \r
6 //  This library is free software; you can redistribute it and/or \r
7 //  modify it under the terms of the GNU Lesser General Public \r
8 //  License as published by the Free Software Foundation; either \r
9 //  version 2.1 of the License. \r
10 // \r
11 //  This library is distributed in the hope that it will be useful, \r
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of \r
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU \r
14 //  Lesser General Public License for more details. \r
15 // \r
16 //  You should have received a copy of the GNU Lesser General Public \r
17 //  License along with this library; if not, write to the Free Software \r
18 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA \r
19 // \r
20 //  See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org \r
21 //\r
22 //\r
23 //\r
24 //  File   :\r
25 //  Author :\r
26 //  Module :\r
27 //  $Header$\r
28 \r
29 #include "VVTK_ImageWriter.h"\r
30 \r
31 #include <qsemaphore.h>\r
32 \r
33 #include <vtkImageData.h>\r
34 #include <vtkImageClip.h>\r
35 #include <vtkJPEGWriter.h>\r
36 #include <vtkSmartPointer.h>\r
37 \r
38 #ifdef _DEBUG_\r
39 static int MYDEBUG = 0;\r
40 #else\r
41 static int MYDEBUG = 0;\r
42 #endif\r
43 \r
44 \r
45 //----------------------------------------------------------------------------\r
46 VVTK_ImageWriter\r
47 ::VVTK_ImageWriter(QSemaphore* theSemaphore,\r
48                    vtkImageData* theImageData,\r
49                    const std::string& theName,\r
50                    int theProgressive,\r
51                    int theQuality):\r
52   mySemaphore(theSemaphore),\r
53   myImageData(theImageData),\r
54   myName(theName),\r
55   myProgressive(theProgressive),\r
56   myQuality(theQuality),\r
57   myConstraint16Flag(true)\r
58 {}\r
59 \r
60 //----------------------------------------------------------------------------\r
61 VVTK_ImageWriter\r
62 ::~VVTK_ImageWriter()\r
63 {\r
64   if(MYDEBUG) cout<<"VVTK_ImageWriter::~VVTK_ImageWriter - this = "<<this<<endl;\r
65 }\r
66 \r
67 \r
68 //----------------------------------------------------------------------------\r
69 void\r
70 VVTK_ImageWriter\r
71 ::run()\r
72 {\r
73   vtkJPEGWriter *aWriter = vtkJPEGWriter::New();\r
74   vtkImageData *anImageData = myImageData;\r
75   vtkSmartPointer<vtkImageClip> anImageClip;\r
76   //\r
77   if(myConstraint16Flag){ \r
78     int uExtent[6];\r
79     myImageData->GetUpdateExtent(uExtent);\r
80     unsigned int width = uExtent[1] - uExtent[0] + 1;\r
81     unsigned int height = uExtent[3] - uExtent[2] + 1;\r
82     width = (width / 16) * 16;\r
83     height= (height / 16) * 16;\r
84     uExtent[1] = uExtent[0] + width - 1;\r
85     uExtent[3] = uExtent[2] + height - 1;\r
86     //\r
87     anImageClip = vtkImageClip::New();\r
88     anImageClip->Delete();\r
89 \r
90     anImageClip->SetInput(myImageData);\r
91     anImageClip->SetOutputWholeExtent(uExtent);\r
92     anImageClip->ClipDataOn();\r
93     anImageData = anImageClip->GetOutput();\r
94   }\r
95   //\r
96   aWriter->WriteToMemoryOff();\r
97   aWriter->SetFileName(myName.c_str());\r
98   aWriter->SetQuality(myQuality);\r
99   aWriter->SetProgressive(myProgressive);\r
100   aWriter->SetInput(anImageData);\r
101   aWriter->Write();\r
102 \r
103   aWriter->Delete();\r
104   myImageData->Delete();\r
105 \r
106   if(MYDEBUG) cout<<"VVTK_ImageWriter::run "<<\r
107                 "- this = "<<this<<\r
108                 "; total = "<<mySemaphore->total()<<\r
109                 "; available = "<<mySemaphore->available()<<endl;\r
110   *mySemaphore -= 1;\r
111 }\r
112 \r