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/LongvolWriter.h"
36#include "DGtal/io/writers/VolWriter.h"
37#include "DGtal/io/writers/PPMWriter.h"
38#include "DGtal/io/writers/PGMWriter.h"
39#include "DGtal/io/writers/RawWriter.h"
40#include "DGtal/io/writers/STBWriter.h"
42#include "DGtal/io/writers/ITKWriter.h"
46//////////////////////////////////////////////////////////////////////////////
49///////////////////////////////////////////////////////////////////////////////
50// Implementation of inline functions //
53template < typename TContainer, int TDim, typename TValue, typename TFunctor >
56DGtal::GenericWriter<TContainer, TDim, TValue, TFunctor>::
57exportFile( const std::string & filename,
58 const TContainer & anImage,
59 const TFunctor & aFunctor
62 DGtal::IOException dgtalio;
63 const std::string extension = filename.substr( filename.find_last_of(".") + 1 );
64 if(extension != "raw")
66 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;
71 return RawWriter<TContainer>::template exportRaw<TValue>( filename, anImage, aFunctor );
77template < typename TContainer, typename TValue, typename TFunctor >
80DGtal::GenericWriter<TContainer, 3, TValue, TFunctor>::
81exportFile( const std::string & filename,
82 const TContainer & anImage,
83 const std::string & datasetName,
84 const TFunctor & aFunctor
87 DGtal::IOException dgtalio;
88 const std::string extension = filename.substr( filename.find_last_of(".") + 1 );
90 // To remove compiler warnings
91 boost::ignore_unused_variable_warning( datasetName );
97 extension == "vol" || extension == "pgm3d" || extension == "pgm3D" || extension == "p3d" || extension == "pgm"
100 trace.error() << "Value type of " << extension << " file extension should be unsigned char."
104 else if ( extension == "raw" )
106 return RawWriter<TContainer>::template exportRaw<TValue>( filename, anImage, aFunctor );
109 else if (std::find(ITK_IO_IMAGE_EXT.begin(), ITK_IO_IMAGE_EXT.end(), extension) != ITK_IO_IMAGE_EXT.end() )
111 return ITKWriter<TContainer, TFunctor>::exportITK( filename, anImage, aFunctor );
116 trace.error() << "Extension " << extension << " in 3D, not yet implemented in DGtal GenericWriter." << std::endl;
126template <typename TContainer, typename TFunctor>
129DGtal::GenericWriter<TContainer, 3, DGtal::uint64_t, TFunctor>::
130exportFile( const std::string & filename,
131 const TContainer & anImage,
132 const TFunctor & aFunctor
135 DGtal::IOException dgtalio;
136 const std::string extension = filename.substr( filename.find_last_of(".") + 1 );
138 if ( extension == "longvol" )
140 return LongvolWriter<TContainer, TFunctor>::exportLongvol( filename, anImage );
142 else if ( extension == "raw" )
144 return RawWriter<TContainer>::template exportRaw<DGtal::uint64_t>( filename, anImage, aFunctor );
147 else if (std::find(ITK_IO_IMAGE_EXT.begin(), ITK_IO_IMAGE_EXT.end(), extension) != ITK_IO_IMAGE_EXT.end() )
149 return ITKWriter<TContainer, TFunctor>::exportITK( filename, anImage, aFunctor );
154 trace.error() << "Extension " << extension<< " with DGtal::uint64_t in 3D, not yet implemented in DGtal GenericWriter." << std::endl;
163template <typename TContainer, typename TFunctor>
166DGtal::GenericWriter<TContainer, 3, unsigned char, TFunctor>::
167exportFile( const std::string & filename,
168 const TContainer & anImage,
169 const std::string & datasetName,
170 const TFunctor & aFunctor
173 DGtal::IOException dgtalio;
174 const std::string extension = filename.substr( filename.find_last_of(".") + 1 );
177 if ( extension == "h5" )
179 return HDF5Writer<TContainer,TFunctor>::exportHDF5_3D( filename, anImage, datasetName, aFunctor );
182 boost::ignore_unused_variable_warning(datasetName);
184 if ( extension == "vol" )
186 return VolWriter<TContainer,TFunctor>::exportVol( filename, anImage, true, aFunctor );
188 else if ( extension == "pgm3d" || extension == "pgm3D" || extension == "p3d" || extension == "pgm" )
190 return PGMWriter<TContainer, TFunctor>::exportPGM3D( filename, anImage, aFunctor );
192 else if( extension == "raw" )
194 return RawWriter< TContainer, TFunctor >::exportRaw8( filename, anImage, aFunctor );
197 else if (std::find(ITK_IO_IMAGE_EXT.begin(), ITK_IO_IMAGE_EXT.end(), extension) != ITK_IO_IMAGE_EXT.end() )
199 return ITKWriter<TContainer, TFunctor>::exportITK( filename, anImage, aFunctor );
204 trace.error() << "Extension " << extension<< " with unsigned char in 3D, not yet implemented in DGtal GenericWriter." << std::endl;
211template <typename TContainer, typename TValue, typename TFunctor>
214DGtal::GenericWriter<TContainer, 2, TValue, TFunctor>::
215exportFile( const std::string & filename,
216 const TContainer & anImage,
217 const TFunctor & aFunctor
220 DGtal::IOException dgtalio;
221 const std::string extension = filename.substr( filename.find_last_of(".") + 1 );
222 if ( extension == "pgm" || extension == "pbm" )
224 trace.error() << "Value type of " << extension<< " file extension should be unsigned char." << std::endl;
227 else if ( extension == "raw" )
229 return RawWriter< TContainer, TFunctor >::template exportRaw<TValue>( filename, anImage, aFunctor );
233 trace.error() << "Extension " << extension<< " in 2D, not yet implemented in DGtal GenericWriter." << std::endl;
241template <typename TContainer, typename TFunctor>
244DGtal::GenericWriter<TContainer, 2, DGtal::Color, TFunctor>::
245exportFile( const std::string & filename,
246 const TContainer & anImage,
247 const TFunctor & aFunctor
250 DGtal::IOException dgtalio;
251 const std::string extension = filename.substr( filename.find_last_of(".") + 1 );
252 if ( extension == "ppm" )
254 return PPMWriter< TContainer, TFunctor >::exportPPM( filename, anImage, aFunctor );
256 else if ( extension == "tga" )
257 return STBWriter< TContainer, TFunctor >::exportTGA( filename, anImage, aFunctor );
258 else if (extension == "bmp")
259 return STBWriter< TContainer, TFunctor >::exportBMP( filename, anImage, aFunctor );
260 else if (extension == "png")
261 return STBWriter< TContainer, TFunctor >::exportPNG( filename, anImage, aFunctor );
262 else if (extension == "jpg")
263 return STBWriter< TContainer, TFunctor >::exportJPG( filename, anImage, aFunctor );
265 else if ( extension == "raw" )
267 return RawWriter< TContainer, TFunctor >::template exportRaw<DGtal::Color>( filename, anImage, aFunctor );
271 trace.error() << "Extension " << extension<< " in 2D, not yet implemented in DGtal GenericWriter." << std::endl;
281template <typename TContainer, typename TFunctor >
284DGtal::GenericWriter<TContainer, 2, unsigned char, TFunctor>::
285exportFile( const std::string & filename,
286 const TContainer & anImage,
287 const TFunctor & aFunctor
290 DGtal::IOException dgtalio;
291 //Getting image extension
292 const std::string extension = filename.substr(filename.find_last_of(".") + 1);
293 if ( extension == "pgm" )
295 return PGMWriter<TContainer, TFunctor>::exportPGM( filename, anImage, aFunctor );
297 else if ( extension == "raw" )
299 return RawWriter<TContainer, TFunctor>::exportRaw8( filename, anImage, aFunctor );
303 trace.error() << "Extension " << extension<< " with unsigned char in 2D, not yet implemented in DGtal GenericWriter." << std::endl;
310template <typename TImageContainer >
313DGtal::operator >> ( const TImageContainer & aContainer,
314 const std::string & aFilename )
316 return DGtal::GenericWriter<TImageContainer>::exportFile(aFilename, aContainer);
323///////////////////////////////////////////////////////////////////////////////