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 VolWriter.h
26 * This file is part of the DGtal library.
30//////////////////////////////////////////////////////////////////////////////
34#include "DGtal/io/Color.h"
35#include <boost/iostreams/filtering_streambuf.hpp>
36#include <boost/iostreams/copy.hpp>
37#include <boost/iostreams/filter/zlib.hpp>
39//////////////////////////////////////////////////////////////////////////////
41///////////////////////////////////////////////////////////////////////////////
42// IMPLEMENTATION of inline methods.
43///////////////////////////////////////////////////////////////////////////////
47 template<typename I,typename F>
48 bool VolWriter<I,F>::exportVol(const std::string & filename,
50 const bool compressed,
51 const Functor & aFunctor)
53 DGtal::IOException dgtalio;
56 typename I::Domain domain = aImage.domain();
57 const typename I::Domain::Point &upBound = domain.upperBound();
58 const typename I::Domain::Point &lowBound = domain.lowerBound();
59 typename I::Domain::Point p = I::Domain::Point::diagonal(1);
60 typename I::Domain::Vector size = (upBound - lowBound) + p;
61 typename I::Domain::Vector center = lowBound + ((upBound - lowBound)/2);
63 typename I::Value val;
67 std::stringstream header;
68 std::stringstream main;
69 out.open(filename.c_str(), std::ios::out | std::ios::binary);
72 header << "Center-X: " << center[0] <<std::endl;
73 header << "Center-Y: " << center[1] <<std::endl;
74 header << "Center-Z: " << center[2] <<std::endl;
75 header << "X: "<< size[0]<<std::endl;
76 header << "Y: "<< size[1]<<std::endl;
77 header << "Z: "<< size[2]<<std::endl;
78 header << "Voxel-Size: 1"<<std::endl;
79 header << "Alpha-Color: 0"<<std::endl;
80 header << "Voxel-Endian: 0"<<std::endl;
81 header << "Int-Endian: 0123"<<std::endl;
83 header << "Version: 3"<<std::endl;
85 header << "Version: 2"<<std::endl;
87 header << "."<<std::endl;
90 for(typename I::Domain::ConstIterator it = domain.begin(), itend=domain.end();
94 val = aImage( (*it) );
95 main.put( aFunctor(val) );
100 boost::iostreams::filtering_streambuf<boost::iostreams::input> out_compressed;
101 out_compressed.push(boost::iostreams::zlib_compressor());
102 out_compressed.push( main );
103 boost::iostreams::copy(out_compressed, header);
104 boost::iostreams::copy(header, out);
109 //We flush the header
112 out.open(filename.c_str(),std::ios_base::binary | std::ios_base::app);
119 trace.error() << "Vol writer IO error on export " << filename << std::endl;