aimsdata 6.0.0
Neuroimaging data handling
texW.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_TEXW_H
35#define AIMS_IO_TEXW_H
36
38#include <aims/mesh/texture.h>
39#include <aims/io/texheader.h>
42#include <cartobase/exception/file.h>
43#include <memory>
44
45
46namespace aims
47{
48
55 template<class T> class AIMSDATA_API TexWriter
56 {
57 public:
58 TexWriter( const std::string & filename )
59 : _name( filename ), _itemw( 0 ) {}
61
62 void write( const TimeTexture<T> & thing, bool ascii );
64 { delete _itemw; _itemw = iw; }
65
66 private:
67 std::string _name;
68 ItemWriter<T> *_itemw;
69 };
70
71
72 template<class T> AIMSDATA_API
73 inline
75 {
76 w.write( thing );
77 return w;
78 }
79
80
81 template<class T>
82 inline
83 void TexWriter<T>::write( const TimeTexture<T> & thing, bool ascii )
84 {
85 TexHeader hdr( _name, carto::DataTypeCode<T>().dataType(), thing.size(),
86 ascii );
87
88 hdr.copy( thing.header() );
89 hdr.write();
90
91 std::ios::openmode omd = std::ios::app;
92 if ( !ascii )
93 omd |= std::ios::binary;
94 std::ofstream os( hdr.filename().c_str(), omd );
95 if ( !os )
96 throw carto::file_error( hdr.filename() );
97
98 if ( !_itemw )
99 _itemw = new DefaultItemWriter<T>;
100 std::string opmode = ascii ? "ascii" : "binar";
101 ItemWriter<T> *iw = _itemw->writer( opmode );
103 std::unique_ptr<ItemWriter<uint32_t> > sw( sw1.writer( opmode ) );
104
105 typename TimeTexture<T>::const_iterator it, et = thing.end();
106
107 for ( it=thing.begin(); it!=et; ++it )
108 {
109 sw->write( os, it->first );
110 const Texture<T> & tex = it->second;
111 uint32_t nitem = tex.nItem();
112 sw->write( os, nitem );
113 const std::vector<T> & vec = tex.data();
114 iw->write( os, &vec[0], nitem );
115 }
116
117 delete iw;
118 }
119
120}
121
122
123#endif
#define AIMSDATA_API
const std::vector< T > & data() const
Definition texture.h:81
size_t nItem() const
Definition texture.h:70
std::map< int, Texture< T > >::const_iterator const_iterator
Definition texture.h:125
const aims::PythonHeader & header() const
Get the header.
Definition texture.h:143
Default low-levels writers.
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)
virtual void write()
virtual std::string filename() const
void setItemWriter(ItemWriter< T > *iw)
Definition texW.h:63
TexWriter(const std::string &filename)
Definition texW.h:58
void write(const TimeTexture< T > &thing, bool ascii)
Definition texW.h:83
The class for EcatSino data write operation.
GenesisReader< T > & operator>>(GenesisReader< T > &reader, AimsData< T > &thing)
Definition genesisR.h:70
bool write(const T &obj, const std::string &filename, carto::Object options=carto::none(), const std::string *format=0)
Finds the correct format and writes the object, global version.
Definition writer.h:141