aimsdata 6.0.0
Neuroimaging data handling
texture.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 class
36 */
37#ifndef AIMS_MESH_TEXTURE_H
38#define AIMS_MESH_TEXTURE_H
39
40
41#include <cartobase/smart/rcptr.h>
43#include <aims/vector/vector.h>
44#include <aims/def/general.h>
45#include <aims/data/pheader.h>
46#include <aims/math/dtitensor.h>
47#include <vector>
48#include <map>
49#include <iostream>
50
51
52template < class T = float > class Texture;
53
54template < class T >
55AIMSDATA_API std::ostream& operator << ( std::ostream& out,
56 const Texture< T >& thing );
57
58//
59// Basic texture
60//
61template < class T >
63{
64public:
65 Texture() { }
66 Texture( size_t n ): _data( n ) { }
67 Texture( size_t n, const T & value ): _data( n, value ) { }
68 virtual ~Texture() { }
69
70 size_t nItem() const { return _data.size(); }
72 size_t size() const { return _data.size(); }
73
74 const T& item( int n ) const { return _data[ n ]; }
75 const T & operator [] ( int n ) const { return _data[ n ]; }
76 T & operator [] ( int n ) { return _data[ n ]; }
77 T& item( int n ) { return _data[ n ]; }
78
79 void reserve( size_t size ) { _data.reserve( size ); }
80 void push_back( const T& item ) { _data.push_back( item ); }
81 const std::vector<T> & data() const { return( _data ); }
82 std::vector<T> & data() { return( _data ); }
83
84 void erase() { _data.clear(); }
85 bool operator == ( const Texture<T> & x ) const { return _data == x.data(); }
86
87 friend
88 std::ostream& operator << <>( std::ostream& out,
89 const Texture< T >& thing );
90
91protected:
92
93 std::vector< T > _data;
94};
95
96
97template < class T > inline
98std::ostream& operator << ( std::ostream& out, const Texture< T >& thing )
99{
100 out << "{nItem=" << thing.nItem() << ", data=(";
101 for ( size_t n = 0; n < thing.nItem(); n++ )
102 out << thing.item( n ) << ", ";
103 out << "NULL)}";
104
105 return out;
106}
107
108
109//
110// Mixing surface and time
111//
112
113template < class T = float > class TimeTexture;
114
115template < class T >
116std::ostream& operator << ( std::ostream& out, const TimeTexture< T >& thing );
117
118template < class T >
119class TimeTexture : public virtual carto::RCObject,
120 public std::map< int, Texture< T > >
121{
122 public:
123 typedef typename std::map<int, Texture< T > >::iterator iterator;
124 typedef typename std::map<int, Texture< T > >::const_iterator
126
127 TimeTexture() : std::map< int, Texture< T > >() { }
128 TimeTexture(int ntimes, size_t nitems) :
129 std::map< int, Texture< T > >()
130 {
131 for( int i=0; i<ntimes; ++i )
132 (*this)[i] = Texture<T>( nitems );
133 }
134 TimeTexture( int ntimes, size_t nitems, const T & value ) :
135 std::map< int, Texture< T > >()
136 {
137 for( int i=0; i<ntimes; ++i )
138 (*this)[i] = Texture<T>( nitems, value );
139 }
140 virtual ~TimeTexture() {}
141
143 inline const aims::PythonHeader &header() const { return _header; }
144 inline aims::PythonHeader &header() { return _header; }
145
147 void setHeader( const aims::PythonHeader &hdr ) { _header = hdr; }
148
149 size_t nItem() const { return (*(TimeTexture< T >*)this)[0].nItem(); }
150
151 const T& item( int n ) const
152 { return (*(TimeTexture< T >*)this)[0].item( n ); }
153 T& item( int n ) { return (*this)[0].item( n ); }
154
155 void reserve( size_t size ) { (*this)[0].reserve( size ); }
156 void push_back( const T& item ) { (*this)[0].push_back( item ); }
157
158 void erase();
159
160 bool operator == ( const TimeTexture<T> & x ) const
161 {
162 if( x.nItem() != nItem() ) return false;
163 if( _header != x.header() ) return false;
164 for( int i=0; i<nItem(); ++i )
165 if( item(i) != x.item(i) ) return false;
166 return true;
167 }
168
169 friend
170 std::ostream& operator << <>( std::ostream& out,
171 const TimeTexture< T >& thing );
172
173protected:
174
177};
178
179
180#ifndef DOXYGEN_HIDE_INTERNAL_CLASSES
181
182namespace carto
183{
184
185 template<class T> class DataTypeCode<TimeTexture<T> >
186 {
187 public:
188 static std::string objectType()
189 { return "Texture"; }
190 static std::string dataType()
191 { return DataTypeCode<T>::dataType(); }
192 static std::string name()
193 {
194 return std::string("texture of ") + DataTypeCode< T >::name();
195 }
196 };
197
198}
199
200#endif // DOXYGEN_HIDE_INTERNAL_CLASSES
201
202
203template < class T > inline
205{
206 typename TimeTexture< T >::iterator it;
207 for ( it = this->begin(); it != this->end(); it++ )
208 (it->second).erase();
209 std::map< int, Texture< T > >::erase( this->begin(), this->end() );
210}
211
212
213template < class T > inline
214std::ostream& operator << ( std::ostream& out, const TimeTexture< T >& thing )
215{
216 out << "{";
217
219
220 for ( it = thing.begin(); it != thing.end(); it++ )
221 {
222 out << "{";
223 out << "t=" << (*it).first << ",";
224 out << (*it).second << "},";
225 }
226
227 return out << "NULL}" << std::flush;
228}
229
230
231//
232// Useful typedefs
233//
234
237
238namespace carto {
239
251#define _TMP_ TimeTexture< AimsVector< short, 2 > >
253#undef _TMP_
254
256DECLARE_GENERIC_OBJECT_TYPE( rc_ptr< TimeTexture< uint8_t > > )
257DECLARE_GENERIC_OBJECT_TYPE( rc_ptr< TimeTexture< int16_t > > )
258DECLARE_GENERIC_OBJECT_TYPE( rc_ptr< TimeTexture< uint16_t > > )
259DECLARE_GENERIC_OBJECT_TYPE( rc_ptr< TimeTexture< int32_t > > )
260DECLARE_GENERIC_OBJECT_TYPE( rc_ptr< TimeTexture< uint32_t > > )
261DECLARE_GENERIC_OBJECT_TYPE( rc_ptr< TimeTexture< int64_t > > )
262DECLARE_GENERIC_OBJECT_TYPE( rc_ptr< TimeTexture< uint64_t > > )
263DECLARE_GENERIC_OBJECT_TYPE( rc_ptr< TimeTexture< double > > )
266#define _TMP_ rc_ptr< TimeTexture< AimsVector< short, 2 > > >
268#undef _TMP_
269
270} // namespace carto
271
272#endif
#define AIMSDATA_API
bool operator==(const Texture< T > &x) const
Definition texture.h:85
Texture(size_t n, const T &value)
Definition texture.h:67
const std::vector< T > & data() const
Definition texture.h:81
void erase()
Definition texture.h:84
void reserve(size_t size)
Definition texture.h:79
virtual ~Texture()
Definition texture.h:68
size_t nItem() const
Definition texture.h:70
T & item(int n)
Definition texture.h:77
const T & item(int n) const
Definition texture.h:74
const T & operator[](int n) const
Definition texture.h:75
std::vector< T > _data
Definition texture.h:93
Texture(size_t n)
Definition texture.h:66
std::vector< T > & data()
Definition texture.h:82
size_t size() const
alias for nItem()
Definition texture.h:72
Texture()
Definition texture.h:65
void push_back(const T &item)
Definition texture.h:80
std::map< int, Texture< T > >::iterator iterator
Definition texture.h:123
void reserve(size_t size)
Definition texture.h:155
aims::PythonHeader & header()
Definition texture.h:144
std::map< int, Texture< T > >::const_iterator const_iterator
Definition texture.h:125
void erase()
Definition texture.h:204
TimeTexture(int ntimes, size_t nitems, const T &value)
Definition texture.h:134
aims::PythonHeader _header
Header.
Definition texture.h:176
void push_back(const T &item)
Definition texture.h:156
virtual ~TimeTexture()
Definition texture.h:140
TimeTexture(int ntimes, size_t nitems)
Definition texture.h:128
const T & item(int n) const
Definition texture.h:151
bool operator==(const TimeTexture< T > &x) const
Definition texture.h:160
size_t nItem() const
Definition texture.h:149
void setHeader(const aims::PythonHeader &hdr)
Set the header.
Definition texture.h:147
const aims::PythonHeader & header() const
Get the header.
Definition texture.h:143
T & item(int n)
Definition texture.h:153
Attributed python-like header, stores all needed information about an object, currently used for volu...
Definition pheader.h:52
std::string name()
std::string dataType()
#define _TMP_
Definition data.h:68
STL namespace.
#define DECLARE_GENERIC_OBJECT_TYPE(T)
AIMSDATA_API std::ostream & operator<<(std::ostream &out, const Texture< T > &thing)
Definition texture.h:98
AIMSDATA_API TimeTexture< Point2df > Texture2d
Definition texture.h:236
AIMSDATA_API TimeTexture< float > Texture1d
Definition texture.h:235