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 LongvolWriter.ih
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 LongvolWriter.h
26 * This file is part of the DGtal library.
30 //////////////////////////////////////////////////////////////////////////////
33 #include "DGtal/io/Color.h"
34 #include <boost/iostreams/filtering_streambuf.hpp>
35 #include <boost/iostreams/copy.hpp>
36 #include <boost/iostreams/filter/zlib.hpp>
37 //////////////////////////////////////////////////////////////////////////////
39 ///////////////////////////////////////////////////////////////////////////////
40 // IMPLEMENTATION of inline methods.
41 ///////////////////////////////////////////////////////////////////////////////
45 template<typename I,typename C>
47 LongvolWriter<I,C>::exportLongvol(const std::string & filename, const I & aImage, const bool compressed,
48 const Functor & aFunctor)
50 DGtal::IOException dgtalio;
53 typename I::Domain domain = aImage.domain();
54 const typename I::Domain::Point &upBound = domain.upperBound();
55 const typename I::Domain::Point &lowBound = domain.lowerBound();
56 typename I::Domain::Point p = I::Domain::Point::diagonal(1);
57 typename I::Domain::Vector size = (upBound - lowBound) + p;
58 typename I::Domain::Vector center = lowBound + ((upBound - lowBound)/2);
59 typename I::Value val;
63 std::stringstream main;
64 out.open(filename.c_str(), std::ios::out | std::ios::binary);
67 out << "Center-X: " << center[0] <<std::endl;
68 out << "Center-Y: " << center[1] <<std::endl;
69 out << "Center-Z: " << center[2] <<std::endl;
70 out << "X: "<< size[0]<<std::endl;
71 out << "Y: "<< size[1]<<std::endl;
72 out << "Z: "<< size[2]<<std::endl;
73 out << "Lvoxel-Size: 4"<<std::endl; //not used in liblongvol but required
74 out << "Alpha-Color: 0"<<std::endl;
75 out << "Lvoxel-Endian: 0"<<std::endl;//not used in liblongvol but required
76 out << "Int-Endian: 0123"<<std::endl;
78 out << "Version: 3"<<std::endl;
80 out << "Version: 2"<<std::endl;
81 out << "."<<std::endl;
84 out.open(filename.c_str(),std::ios_base::binary | std::ios_base::app);
87 for(typename I::Domain::ConstIterator it = domain.begin(), itend=domain.end();
91 val = aImage( (*it) );
92 write_word(main,aFunctor(val));
97 boost::iostreams::filtering_streambuf<boost::iostreams::input> out_compressed;
98 out_compressed.push(boost::iostreams::zlib_compressor());
99 out_compressed.push( main );
100 boost::iostreams::copy(out_compressed, out);
113 std::cout << "LongVol writer IO error on export " << filename << std::endl;