aimsdata 6.0.0
Neuroimaging data handling
bckMapW.h
Go to the documentation of this file.
1/* This software and supporting documentation are distributed by
2 * Institut Federatif de Recherche 49
3 * CEA/NeuroSpin, Batiment 145,
4 * 91191 Gif-sur-Yvette cedex
5 * France
6 *
7 * This software is governed by the CeCILL-B license under
8 * French law and abiding by the rules of distribution of free software.
9 * You can use, modify and/or redistribute the software under the
10 * terms of the CeCILL-B license as circulated by CEA, CNRS
11 * and INRIA at the following URL "http://www.cecill.info".
12 *
13 * As a counterpart to the access to the source code and rights to copy,
14 * modify and redistribute granted by the license, users are provided only
15 * with a limited warranty and the software's author, the holder of the
16 * economic rights, and the successive licensors have only limited
17 * liability.
18 *
19 * In this respect, the user's attention is drawn to the risks associated
20 * with loading, using, modifying and/or developing or reproducing the
21 * software by the user in light of its specific status of free software,
22 * that may mean that it is complicated to manipulate, and that also
23 * therefore means that it is reserved for developers and experienced
24 * professionals having in-depth computer knowledge. Users are therefore
25 * encouraged to load and test the software's suitability as regards their
26 * requirements in conditions enabling the security of their systems and/or
27 * data to be ensured and, more generally, to use and operate it in the
28 * same conditions as regards security.
29 *
30 * The fact that you are presently reading this means that you have had
31 * knowledge of the CeCILL-B license and that you accept its terms.
32 */
33
34#ifndef AIMS_IO_BCKMAPW_H
35#define AIMS_IO_BCKMAPW_H
36
39#include <aims/io/bckheader.h>
42#include <cartobase/exception/ioexcept.h>
43
44
45namespace aims
46{
47
52 template<class T> class BckMapWriter
53 {
54 public:
55 BckMapWriter( const std::string& name, bool ascii = false )
56 : _name(name), _itemw( 0 ), _binmode( !ascii ) {}
57 ~BckMapWriter() { delete _itemw; }
58
59 void write( const BucketMap<T> & thing );
60 void setMode( bool ascii );
61 bool asciiMode() const { return( !_binmode ); }
63 { delete _itemw; _itemw = iw; }
64
65 private:
66 std::string _name;
67 ItemWriter<T> *_itemw;
68 bool _binmode;
69 };
70
71
72 template <class T>
73 inline
74 void BckMapWriter<T>::setMode( bool ascii )
75 {
76 _binmode = !ascii;
77 }
78
79
80 template<class T> inline
82 {
83 std::string openmode = ( _binmode ? "binar" : "ascii" );
85 BckHeader hdr( _name, dtc.name(), thing.sizeX(),
86 thing.sizeY(), thing.sizeZ(), thing.sizeT(),
87 AIMS_MAGIC_NUMBER, openmode );
88 hdr.copy( thing.header() );
89 hdr.write();
90
91 std::string name = hdr.filename();
92 std::ios::openmode omd = std::ios::app;
93 if( _binmode )
94 omd |= std::ios::binary;
95 std::ofstream os( name.c_str(), omd );
96 if( !os )
98
99 if( !_itemw )
100 _itemw = new DefaultItemWriter<T>;
101 ItemWriter<T> *iw = _itemw->writer( openmode, false );
103 ItemWriter<Point3d> *posw = itemw1.writer( openmode, false );
105 typename BucketMap<T>::const_iterator ib, eb = thing.end();
106 typename BucketMap<T>::Bucket::const_iterator ibi, ebi;
107
108 if( _binmode )
109 sw.write( os, thing.size() );
110 else
111 os << "-dimt " << thing.size() << std::endl;;
112
113 for( ib=thing.begin(); ib!=eb; ++ib )
114 {
115 if( _binmode )
116 {
117 sw.write( os, ib->first );
118 sw.write( os, ib->second.size() );
119 }
120 else
121 {
122 os << "-time " << ib->first << std::endl;
123 os << "-dim " << ib->second.size() << std::endl;
124 }
125 for( ibi=ib->second.begin(), ebi=ib->second.end(); ibi!=ebi; ++ibi )
126 {
127 posw->write( os, ibi->first );
128 iw->write( os, ibi->second );
129 if( !_binmode )
130 os << std::endl;
131 }
132 }
133
134 delete iw;
135 delete posw;
136 }
137
138}
139
140
141template<class T> inline
143 aims::BucketMap<T> & thing )
144{
145 writer.write( thing );
146 return( writer );
147}
148
149
150#endif
151
152
aims::BckMapWriter< T > & operator<<(aims::BckMapWriter< T > &writer, aims::BucketMap< T > &thing)
Definition bckMapW.h:142
Descriptor class for the .bck BUCKET file format header.
Definition bckheader.h:52
std::string filename() const
BucketMap objects can be read / written by BckMapReader / BckMapWriter, these IO classes operate on t...
Definition bckMapW.h:53
void setMode(bool ascii)
Definition bckMapW.h:74
void write(const BucketMap< T > &thing)
Definition bckMapW.h:81
void setItemWriter(ItemWriter< T > *iw)
Definition bckMapW.h:62
bool asciiMode() const
Definition bckMapW.h:61
BckMapWriter(const std::string &name, bool ascii=false)
Definition bckMapW.h:55
An alternate, ordered, representation for buckets (voxels lists).
Definition bucketMap.h:99
float sizeZ() const
returns the Z resolution in mm
Definition bucketMap.h:254
std::map< int, Bucket >::const_iterator const_iterator
Definition bucketMap.h:104
const aims::PythonHeader & header() const
Definition bucketMap.h:155
float sizeT() const
returns the T resolution in s
Definition bucketMap.h:264
float sizeY() const
returns the Y resolution in mm
Definition bucketMap.h:244
float sizeX() const
returns the X resolution in mm
Definition bucketMap.h:234
Default low-levels writers.
virtual void write(std::ostream &os, const T &item) const
virtual ItemWriter< T > * writer(const std::string &openmode="binar", bool bswap=false) const
Low-level "small item" writer, used by higher-level file readers.
Definition itemW.h:51
virtual void write(std::ostream &os, const T &item) const
Definition itemW.h:55
virtual ItemWriter< T > * writer(const std::string &openmode="binar", bool bswap=false) const =0
virtual void copy(const PythonHeader &, bool keepUuid=false)
std::string name()
static void launchErrnoExcept(const std::string &filename="")
#define AIMS_MAGIC_NUMBER
Definition general.h:51
The class for EcatSino data write operation.