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 PPMWriter.h
26 * This file is part of the DGtal library.
30 //////////////////////////////////////////////////////////////////////////////
33 #include "DGtal/io/Color.h"
34 #include "DGtal/kernel/domains/HyperRectDomain.h"
35 //////////////////////////////////////////////////////////////////////////////
37 ///////////////////////////////////////////////////////////////////////////////
38 // IMPLEMENTATION of inline methods.
39 ///////////////////////////////////////////////////////////////////////////////
44 template<typename I,typename C>
46 PPMWriter<I,C>::exportPPM(const std::string & filename, const I & aImage,
47 const Functor & aFunctor, bool topbotomOrder)
49 BOOST_STATIC_ASSERT(I::Domain::dimension == 2);
52 typename I::Domain domain = aImage.domain();
53 typename I::Domain::Point p = I::Domain::Point::diagonal(1);
54 typename I::Domain::Vector size = (domain.upperBound() - domain.lowerBound()) + p;
56 typename I::Value val;
58 out.open(filename.c_str(), std::ios::out | std::ios::binary);
61 out << "P3"<<std::endl;
62 out << "#DGtal PNM Writer"<<std::endl<<std::endl;
63 out << size[0]<<" "<< size[1]<<std::endl;
64 out << "255" <<std::endl;
68 //We scan the domain instead of the image becaus we cannot
69 //trust the image container Iterator
70 for(typename I::Domain::ConstIterator it = domain.begin(), itend=domain.end();
74 val = aImage( (*it) );
75 col = aFunctor( val );
76 out << (int)col.red()<<" "<<(int)col.green()<<" "<<(int)col.blue()<<" ";
81 typename I::Domain::Point ptUpper= domain.upperBound();
83 for(typename HyperRectDomain<typename I::Domain::Space>::ConstSubRange::ConstReverseIterator itY = domain.subRange(1, ptUpper).rbegin(),
84 itYend=domain.subRange(1, ptUpper).rend(); itY!=itYend; ++itY)
86 typename I::Domain::Point ptUpperY= *itY;
88 for(typename HyperRectDomain<typename I::Domain::Space>::ConstSubRange::ConstIterator it = domain.subRange(0, ptUpperY).begin(),
89 itend=domain.subRange(0, ptUpperY).end();
93 val = aImage( (*it) );
94 col = aFunctor( val );
95 out << (int)col.red()<<" "<<(int)col.green()<<" "<<(int)col.blue()<<" ";
102 ///@todo catch IOerror excpetion
106 template<typename I,typename C>
108 PPMWriter<I,C>::exportPPM3D(const std::string & filename, const I & aImage,
109 const Functor&aFunctor)
111 BOOST_STATIC_ASSERT(I::Domain::dimension == 3);
114 typename I::Domain domain(aImage.lowerBound(), aImage.upperBound());
115 typename I::Domain::Point p = I::Domain::Point::diagonal(1);
116 typename I::Domain::Vector size = (domain.upperBound() - domain.lowerBound()) + p;
118 typename I::Value val;
121 out.open(filename.c_str(), std::ios::out | std::ios::binary);
124 out << "P3-3D"<<std::endl;
125 out << "#DGtal PNM Writer"<<std::endl<<std::endl;
126 out << size[0]<<" "<< size[1]<<" "<< size[2]<<std::endl;
127 out << "255" <<std::endl;
129 //We scan the domain instead of the image becaus we cannot
130 //trust the image container Iterator
131 for(typename I::Domain::ConstIterator it = domain.begin(), itend=domain.end();
136 val = aImage( (*it) );
137 col = aFunctor( val );
138 out << (int)col.red()<<" "<<(int)col.green()<<" "<<(int)col.blue()<<" "; }
142 ///@todo catch IOerror excpetion