aimsdata 6.0.0
Neuroimaging data handling
texR.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/*
35 * Texture reader class
36 */
37#ifndef AIMS_IO_TEXR_H
38#define AIMS_IO_TEXR_H
39
41#include <aims/mesh/texture.h>
42#include <aims/io/texheader.h>
44#include <cartobase/exception/ioexcept.h>
45#include <memory>
46
47
48namespace aims
49{
50
57 template<class T> class AIMSDATA_API TexReader
58 {
59 public:
60 TexReader( const std::string & filename )
61 : _name( filename ), _itemr( 0 ) {}
63
64 void read( TimeTexture<T> & thing, int frame = -1 );
66 { delete _itemr; _itemr = ir; }
67
68 private:
69 std::string _name;
70 ItemReader<T> *_itemr;
71 };
72
73
74 template<class T> AIMSDATA_API
75 inline
77 {
78 r.read( thing );
79 return r;
80 }
81
82
83 template<class T>
84 inline
85 void TexReader<T>::read( TimeTexture<T> & thing, int frame )
86 {
87 if ( frame >= 0 )
88 std::cerr << "Warning : .tex single frame reading not implemented yet -\n"
89 << "reading whole texture" << std::endl;
90
91 TexHeader hdr( _name );
92 size_t offset;
93
94 hdr.read( &offset );
95
96 std::ifstream is( hdr.filename().c_str(),
97 std::ios::in | std::ios::binary );
98 if ( !is )
100 is.unsetf( std::ios::skipws );
101 is.seekg( offset );
102 if ( !is )
104
105 if ( !_itemr )
106 _itemr = new DefaultItemReader<T>;
107 ItemReader<T> *ir( _itemr->reader( hdr.openMode(), hdr.byteSwapping() ) );
109 std::unique_ptr<ItemReader<uint32_t> > sr( sr1.reader( hdr.openMode(), hdr.byteSwapping() ) );
110
111 int nt;
112 hdr.getProperty( "nb_t_pos", nt );
113
114 thing.setHeader( hdr );
115
116 for ( int t=0; t<nt; ++t )
117 {
118 uint32_t time, nitem;
119 sr->read( is, time );
120 sr->read( is, nitem );
121 //cout << "time " << time << ", nitem : " << nitem << endl;
122 std::vector<T> & vec = thing[ time ].data();
123 vec.clear();
124 vec.insert( vec.end(), nitem, T() );
125 ir->read( is, &vec[0], nitem );
126 }
127
128 delete ir;
129 }
130
131}
132
133
134#endif
#define AIMSDATA_API
void setHeader(const aims::PythonHeader &hdr)
Set the header.
Definition texture.h:147
Default low-levels readers.
virtual ItemReader< T > * reader(const std::string &openmode="binar", bool bswap=false) const
Low-level "small item" reader, used by higher-level file readers.
Definition itemR.h:99
virtual void read(std::istream &is, T &item) const
Definition itemR.h:103
virtual void read(size_t *offset=0)
virtual std::string filename() const
virtual std::string openMode() const
Definition texheader.h:101
virtual bool byteSwapping() const
Tex format readers for texture objects.
Definition texR.h:58
void read(TimeTexture< T > &thing, int frame=-1)
Definition texR.h:85
TexReader(const std::string &filename)
Definition texR.h:60
void setItemReader(ItemReader< T > *ir)
Definition texR.h:65
virtual bool getProperty(const std::string &, Object &) const
static void launchErrnoExcept(const std::string &filename="")
The class for EcatSino data write operation.
GenesisReader< T > & operator>>(GenesisReader< T > &reader, AimsData< T > &thing)
Definition genesisR.h:70