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 GenericReader.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 GenericReader.h
26 * This file is part of the DGtal library.
30 //////////////////////////////////////////////////////////////////////////////
32 //////////////////////////////////////////////////////////////////////////////
34 ///////////////////////////////////////////////////////////////////////////////
35 // IMPLEMENTATION of inline functions.
37 template <typename TContainer, int TDim, typename TValue>
40 DGtal::GenericReader<TContainer, TDim, TValue>::
41 import( const std::string & filename,
42 std::vector<unsigned int> dimSpace
45 DGtal::IOException dgtalio;
46 const std::string extension = filename.substr( filename.find_last_of(".") + 1 );
47 if ( extension != "raw" )
49 trace.error() << "Extension " << extension << " not yet implemented in " << TDim << "D for DGtal GenericReader (only raw images are actually implemented in Nd using any value type)." << std::endl;
54 typename TContainer::Point aPointDim;
55 for ( unsigned int i = 0; i < dimSpace.size(); i++)
57 aPointDim[ i ] = dimSpace[ i ];
59 return RawReader< TContainer >::template importRaw<TValue> ( filename, aPointDim );
65 template <typename TContainer, typename TValue>
68 DGtal::GenericReader<TContainer, 3, TValue>::
69 import( const std::string & filename,
75 DGtal::IOException dgtalio;
76 const std::string extension = filename.substr( filename.find_last_of(".") + 1 );
78 if ( extension == "vol" )
80 return VolReader<TContainer>::importVol( filename );
82 else if ( extension == "longvol" || extension == "lvol" )
84 return LongvolReader<TContainer>::importLongvol( filename );
86 else if ( extension == "pgm3d" || extension == "pgm3D" ||
87 extension == "p3d" || extension == "pgm" )
89 return PGMReader<TContainer>::importPGM3D( filename );
92 else if (std::find(ITK_IO_IMAGE_EXT.begin(), ITK_IO_IMAGE_EXT.end(), extension) != ITK_IO_IMAGE_EXT.end() )
95 return ITKReader<TContainer>::importITK( filename );
99 else if ( extension == "raw" )
101 ASSERT( x != 0 && y != 0 && z != 0 );
102 typename TContainer::Point const pt(x, y, z);
103 return RawReader< TContainer >::template importRaw<TValue>( filename, pt );
107 if ( extension == "h5" )
108 return HDF5Reader<TContainer>::importHDF5_3D( filename, "UInt8Array3D" );
111 trace.error() << "Extension " << extension << " in 3D, not yet implemented in DGtal GenericReader." << std::endl;
117 template <typename TContainer>
120 DGtal::GenericReader<TContainer, 3, DGtal::uint32_t>::
121 import( const std::string & filename,
127 DGtal::IOException dgtalio;
128 const std::string extension = filename.substr( filename.find_last_of(".") + 1 );
130 if ( extension == "longvol" || extension == "lvol" )
132 return LongvolReader<TContainer>::importLongvol( filename );
134 else if ( extension == "raw" )
136 ASSERT( x != 0 && y != 0 && z != 0 );
137 typename TContainer::Point const pt(x, y, z);
138 return RawReader< TContainer >::importRaw32 ( filename, pt );
142 trace.error() << "Extension " << extension << " with DGtal::uint32_t in 3D, not yet implemented in DGtal GenericReader." << std::endl;
148 template <typename TContainer>
151 DGtal::GenericReader<TContainer, 3, DGtal::uint64_t>::
152 import( const std::string & filename)
154 DGtal::IOException dgtalio;
155 const std::string extension = filename.substr( filename.find_last_of(".") + 1 );
157 if ( extension == "longvol" || extension == "lvol" )
159 return LongvolReader<TContainer>::importLongvol( filename );
162 trace.error() << "Extension " << extension << " with DGtal::uint64_t in 3D, not yet implemented in DGtal GenericReader." << std::endl;
168 template <typename TContainer, typename TValue>
171 DGtal::GenericReader<TContainer, 2, TValue>::
172 import( const std::string &filename,
177 DGtal::IOException dgtalio;
178 //Getting image extension
179 const std::string extension = filename.substr( filename.find_last_of(".") + 1 );
181 if ( extension == "pgm" )
183 return PGMReader<TContainer>::importPGM(filename);
185 else if ( extension == "ppm" )
187 return PPMReader<TContainer>::importPPM(filename);
189 else if ( extension == "raw" )
191 ASSERT( x != 0 && y != 0 );
192 typename TContainer::Point const pt (x, y);
193 return RawReader<TContainer>::template importRaw<TValue>( filename, pt );
197 if ( extension == "h5" )
198 return HDF5Reader<TContainer>::importHDF5(filename, "image8bit");
201 if( extension == "tga" || extension == "jpg" || extension == "png" || extension == "jpeg" || extension == "bmp" )
203 STBReader<TContainer> reader;
204 return reader.import( filename );
207 trace.error() << "Extension " << extension<< " in 2D, not yet implemented in DGtal GenericReader." << std::endl;
213 template <typename TContainer>
216 DGtal::GenericReader<TContainer, 2, DGtal::uint32_t>::
217 import( const std::string &filename,
222 DGtal::IOException dgtalio;
223 //Getting image extension
224 const std::string extension = filename.substr( filename.find_last_of(".") + 1 );
226 if ( extension == "ppm" )
228 return PPMReader<TContainer>::importPPM(filename);
230 else if ( extension == "pgm" )
232 return PGMReader<TContainer>::importPGM(filename);
234 else if ( extension == "raw" )
236 ASSERT( x != 0 && y != 0);
237 typename TContainer::Point const pt (x,y);
238 return RawReader<TContainer>::importRaw32( filename, pt );
241 if ( extension == "tga" || extension == "jpg" || extension == "png" || extension == "jpeg" || extension == "bmp" )
243 STBReader<TContainer> reader;
244 return reader.import( filename );
247 trace.error() << "Extension " << extension<< " with DGtal::uint32_t in 2D, not yet implemented in DGtal GenericReader." << std::endl;
255 ///////////////////////////////////////////////////////////////////////////////