2 * This program is free software: you can redistribute it and/or modify
3 * it under the terms of the GNU Lesser General Public License as
4 * published by the Free Software Foundation, either version 3 of the
5 * License, or (at your option) any later version.
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
12 * You should have received a copy of the GNU General Public License
13 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 * @file GenericWriter.ih
19 * @author Bertrand Kerautret (\c kerautre@loria.fr )
20 * LORIA (CNRS, UMR 7503), University of Nancy, France
24 * Implementation of inline methods defined in GenericWriter.h
26 * This file is part of the DGtal library.
30 //////////////////////////////////////////////////////////////////////////////
33 #include "DGtal/io/writers/HDF5Writer.h"
35 #include "DGtal/io/writers/VolWriter.h"
36 #include "DGtal/io/writers/PPMWriter.h"
37 #include "DGtal/io/writers/PGMWriter.h"
38 #include "DGtal/io/writers/RawWriter.h"
40 #include "DGtal/io/writers/MagickWriter.h"
45 //////////////////////////////////////////////////////////////////////////////
48 ///////////////////////////////////////////////////////////////////////////////
49 // Implementation of inline functions //
52 template < typename TContainer, int TDim, typename TValue, typename TFunctor >
55 DGtal::GenericWriter<TContainer, TDim, TValue, TFunctor>::
56 exportFile( const std::string & filename,
57 const TContainer & anImage,
58 const TFunctor & aFunctor
61 DGtal::IOException dgtalio;
62 const std::string extension = filename.substr( filename.find_last_of(".") + 1 );
63 if(extension != "raw")
65 trace.error() << "Extension " << extension << " in " << TDim <<"D, not yet implemented in DGtal GenericWriter (only raw images are actually implemented in Nd using any value type)." << std::endl;
70 return RawWriter<TContainer>::template exportRaw<TValue>( filename, anImage, aFunctor );
76 template < typename TContainer, typename TValue, typename TFunctor >
79 DGtal::GenericWriter<TContainer, 3, TValue, TFunctor>::
80 exportFile( const std::string & filename,
81 const TContainer & anImage,
82 const std::string & datasetName,
83 const TFunctor & aFunctor
86 DGtal::IOException dgtalio;
87 const std::string extension = filename.substr( filename.find_last_of(".") + 1 );
89 // To remove compiler warnings
90 boost::ignore_unused_variable_warning( datasetName );
96 extension == "vol" || extension == "pgm3d" || extension == "pgm3D" || extension == "p3d" || extension == "pgm"
99 trace.error() << "Value type of " << extension << " file extension should be unsigned char."
103 else if ( extension == "raw" )
105 return RawWriter<TContainer>::template exportRaw<TValue>( filename, anImage, aFunctor );
109 trace.error() << "Extension " << extension << " in 3D, not yet implemented in DGtal GenericWriter." << std::endl;
119 template <typename TContainer, typename TFunctor>
122 DGtal::GenericWriter<TContainer, 3, DGtal::uint64_t, TFunctor>::
123 exportFile( const std::string & filename,
124 const TContainer & anImage,
125 const TFunctor & aFunctor
128 DGtal::IOException dgtalio;
129 const std::string extension = filename.substr( filename.find_last_of(".") + 1 );
131 if ( extension == "longvol" )
133 return VolWriter<TContainer, TFunctor>::exportLongvol( filename, anImage , aFunctor );
135 else if ( extension == "raw" )
137 return RawWriter<TContainer>::template exportRaw<DGtal::uint64_t>( filename, anImage, aFunctor );
141 trace.error() << "Extension " << extension<< " with DGtal::uint64_t in 3D, not yet implemented in DGtal GenericWriter." << std::endl;
150 template <typename TContainer, typename TFunctor>
153 DGtal::GenericWriter<TContainer, 3, unsigned char, TFunctor>::
154 exportFile( const std::string & filename,
155 const TContainer & anImage,
156 const std::string & datasetName,
157 const TFunctor & aFunctor
160 DGtal::IOException dgtalio;
161 const std::string extension = filename.substr( filename.find_last_of(".") + 1 );
164 if ( extension == "h5" )
166 return HDF5Writer<TContainer,TFunctor>::exportHDF5_3D( filename, anImage, datasetName, aFunctor );
169 boost::ignore_unused_variable_warning(datasetName);
171 if ( extension == "vol" )
173 return VolWriter<TContainer,TFunctor>::exportVol( filename, anImage, true, aFunctor );
175 else if ( extension == "pgm3d" || extension == "pgm3D" || extension == "p3d" || extension == "pgm" )
177 return PGMWriter<TContainer, TFunctor>::exportPGM3D( filename, anImage, aFunctor );
179 else if( extension == "raw" )
181 return RawWriter< TContainer, TFunctor >::exportRaw8( filename, anImage, aFunctor );
185 trace.error() << "Extension " << extension<< " with unsigned char in 3D, not yet implemented in DGtal GenericWriter." << std::endl;
192 template <typename TContainer, typename TValue, typename TFunctor>
195 DGtal::GenericWriter<TContainer, 2, TValue, TFunctor>::
196 exportFile( const std::string & filename,
197 const TContainer & anImage,
198 const TFunctor & aFunctor
201 DGtal::IOException dgtalio;
202 const std::string extension = filename.substr( filename.find_last_of(".") + 1 );
203 if ( extension == "pgm" || extension == "pbm" )
205 trace.error() << "Value type of " << extension<< " file extension should be unsigned char." << std::endl;
208 else if ( extension == "raw" )
210 return RawWriter< TContainer, TFunctor >::template exportRaw<TValue>( filename, anImage, aFunctor );
214 trace.error() << "Extension " << extension<< " in 2D, not yet implemented in DGtal GenericWriter." << std::endl;
223 template <typename TContainer, typename TFunctor>
226 DGtal::GenericWriter<TContainer, 2, DGtal::Color, TFunctor>::
227 exportFile( const std::string & filename,
228 const TContainer & anImage,
229 const TFunctor & aFunctor
232 DGtal::IOException dgtalio;
233 const std::string extension = filename.substr( filename.find_last_of(".") + 1 );
234 if ( extension == "ppm" )
236 return PPMWriter< TContainer, TFunctor >::exportPPM( filename, anImage, aFunctor );
239 else if ( extension == "gif" || extension == "jpg" || extension == "bmp" || extension == "png" )
241 return MagickWriter< TContainer, TFunctor >::exportMagick( filename, anImage, aFunctor );
246 trace.error() << "Extension " << extension<< " in 2D, not yet implemented in DGtal GenericWriter." << std::endl;
253 template <typename TContainer, typename TValue>
256 DGtal::GenericWriter<TContainer, 2, TValue, DGtal::HueShadeColorMap<TValue> >::
257 exportFile( const std::string & filename,
258 const TContainer & anImage,
259 const DGtal::HueShadeColorMap<TValue> & aFunctor
262 DGtal::IOException dgtalio;
263 const std::string extension = filename.substr( filename.find_last_of(".") + 1 );
264 if ( extension == "ppm" )
266 return PPMWriter<TContainer, DGtal::HueShadeColorMap<TValue> >::exportPPM( filename, anImage, aFunctor );
269 else if ( extension == "gif" || extension == "jpg" || extension == "bmp" || extension == "png" )
271 return MagickWriter< TContainer, DGtal::HueShadeColorMap<TValue> >::exportMagick( filename, anImage, aFunctor );
275 else if ( extension == "raw" )
277 return RawWriter< TContainer, DGtal::HueShadeColorMap<TValue> >::template exportRaw<DGtal::Color>( filename, anImage, aFunctor );
281 trace.error() << "Extension " << extension<< " in 2D, not yet implemented in DGtal GenericWriter with specific HueShadeColorMap functor." << std::endl;
289 template <typename TContainer, typename TFunctor >
292 DGtal::GenericWriter<TContainer, 2, unsigned char, TFunctor>::
293 exportFile( const std::string & filename,
294 const TContainer & anImage,
295 const TFunctor & aFunctor
298 DGtal::IOException dgtalio;
299 //Getting image extension
300 const std::string extension = filename.substr(filename.find_last_of(".") + 1);
301 if ( extension == "pgm" )
303 return PGMWriter<TContainer, TFunctor>::exportPGM( filename, anImage, aFunctor );
305 else if ( extension == "raw" )
307 return RawWriter<TContainer, TFunctor>::exportRaw8( filename, anImage, aFunctor );
311 trace.error() << "Extension " << extension<< " with unsigned char in 2D, not yet implemented in DGtal GenericWriter." << std::endl;
318 template <typename TImageContainer >
321 DGtal::operator >> ( const TImageContainer & aContainer,
322 const std::string & aFilename )
324 return DGtal::GenericWriter<TImageContainer>::exportFile(aFilename, aContainer);
331 ///////////////////////////////////////////////////////////////////////////////