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/>.
19 * @author David Coeurjolly (\c david.coeurjolly@liris.cnrs.fr )
20 * Laboratoire d'InfoRmatique en Image et Systèmes d'information - LIRIS (CNRS, UMR 5205), CNRS, France
24 * Implementation of inline methods defined in RawReader.h
26 * This file is part of the DGtal library.
30//////////////////////////////////////////////////////////////////////////////
33//////////////////////////////////////////////////////////////////////////////
35///////////////////////////////////////////////////////////////////////////////
36// Interface - public :
38template <typename T, typename TFunctor>
39template <typename Word>
41DGtal::RawReader<T, TFunctor>::importRaw(const std::string& filename, const Vector& extent, const Functor& aFunctor)
43 BOOST_CONCEPT_ASSERT(( concepts::CUnaryFunctor<TFunctor, Word, Value > )) ;
46 fin = fopen( filename.c_str() , "rb" );
49 trace.error() << "RawReader : can't open "<< filename << std::endl;
51 typename T::Point firstPoint;
52 typename T::Point lastPoint;
54 firstPoint = T::Point::zero;
57 for(unsigned int i=0; i < T::Domain::dimension; i++)
63 typename T::Domain domain(firstPoint, lastPoint);
66 //We scan the Raw file
67 typename T::Domain::ConstIterator it=domain.begin(), itend=domain.end();
71 while ((fin) && (it != itend))
73 raw_reader_read_word(fin, val);
74 image.setValue(*it, aFunctor(val));
83 trace.error() << "RawReader: error while opening file " << filename << std::endl;
84 throw DGtal::IOException();
90template <typename T, typename TFunctor>
92DGtal::RawReader<T, TFunctor>::importRaw8(const std::string& filename, const Vector& extent, const Functor& aFunctor)
94 return importRaw<uint8_t>(filename, extent, aFunctor);
97template <typename T, typename TFunctor>
99DGtal::RawReader<T, TFunctor>::importRaw16(const std::string& filename, const Vector& extent, const Functor& aFunctor)
101 return importRaw<uint16_t>(filename, extent, aFunctor);
104template <typename T, typename TFunctor>
106DGtal::RawReader<T, TFunctor>::importRaw32(const std::string& filename, const Vector& extent, const Functor& aFunctor)
108 return importRaw<uint32_t>(filename, extent, aFunctor);
111template <typename Word>
113DGtal::raw_reader_read_word( FILE* fin, Word& aValue )
116 for ( std::size_t i = 0; i < sizeof( Word ); ++i )
117 reinterpret_cast<unsigned char*>(&aValue)[i] = getc(fin);