aimsdata  4.7.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 
52 template < class T = float > class Texture;
53 
54 template < class T >
55 AIMSDATA_API std::ostream& operator << ( std::ostream& out,
56  const Texture< T >& thing );
57 
58 //
59 // Basic texture
60 //
61 template < class T >
62 class Texture
63 {
64 public:
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(); }
71 
72  const T& item( int n ) const { return _data[ n ]; }
73  const T & operator [] ( int n ) const { return _data[ n ]; }
74  T & operator [] ( int n ) { return _data[ n ]; }
75  T& item( int n ) { return _data[ n ]; }
76 
77  void reserve( size_t size ) { _data.reserve( size ); }
78  void push_back( const T& item ) { _data.push_back( item ); }
79  const std::vector<T> & data() const { return( _data ); }
80  std::vector<T> & data() { return( _data ); }
81 
82  void erase() { _data.clear(); }
83 
84  friend
85  std::ostream& operator << <>( std::ostream& out,
86  const Texture< T >& thing );
87 
88 protected:
89 
90  std::vector< T > _data;
91 };
92 
93 
94 template < class T > inline
95 std::ostream& operator << ( std::ostream& out, const Texture< T >& thing )
96 {
97  out << "{nItem=" << thing.nItem() << ", data=(";
98  for ( size_t n = 0; n < thing.nItem(); n++ )
99  out << thing.item( n ) << ", ";
100  out << "NULL)}";
101 
102  return out;
103 }
104 
105 
106 //
107 // Mixing surface and time
108 //
109 
110 template < class T = float > class TimeTexture;
111 
112 template < class T >
113 std::ostream& operator << ( std::ostream& out, const TimeTexture< T >& thing );
114 
115 template < class T >
116 class TimeTexture : public virtual carto::RCObject,
117  public std::map< int, Texture< T > >
118 {
119  public:
120  typedef typename std::map<int, Texture< T > >::iterator iterator;
121  typedef typename std::map<int, Texture< T > >::const_iterator
123 
124  TimeTexture() : std::map< int, Texture< T > >() { }
125  TimeTexture(int ntimes, size_t nitems) :
126  std::map< int, Texture< T > >()
127  {
128  for( int i=0; i<ntimes; ++i )
129  (*this)[i] = Texture<T>( nitems );
130  }
131  TimeTexture( int ntimes, size_t nitems, const T & value ) :
132  std::map< int, Texture< T > >()
133  {
134  for( int i=0; i<ntimes; ++i )
135  (*this)[i] = Texture<T>( nitems, value );
136  }
137  virtual ~TimeTexture() {}
138 
140  inline const aims::PythonHeader &header() const { return _header; }
141  inline aims::PythonHeader &header() { return _header; }
142 
144  void setHeader( const aims::PythonHeader &hdr ) { _header = hdr; }
145 
146  size_t nItem() const { return (*(TimeTexture< T >*)this)[0].nItem(); }
147 
148  const T& item( int n ) const
149  { return (*(TimeTexture< T >*)this)[0].item( n ); }
150  T& item( int n ) { return (*this)[0].item( n ); }
151 
152  void reserve( size_t size ) { (*this)[0].reserve( size ); }
153  void push_back( const T& item ) { (*this)[0].push_back( item ); }
154 
155  void erase();
156 
157  friend
158  std::ostream& operator << <>( std::ostream& out,
159  const TimeTexture< T >& thing );
160 
161 protected:
162 
165 };
166 
167 
168 #ifndef DOXYGEN_HIDE_INTERNAL_CLASSES
169 
170 namespace carto
171 {
172 
173  template<class T> class DataTypeCode<TimeTexture<T> >
174  {
175  public:
176  static std::string objectType()
177  { return "Texture"; }
178  static std::string dataType()
179  { return DataTypeCode<T>::dataType(); }
180  static std::string name()
181  {
182  return std::string("texture of ") + DataTypeCode< T >::name();
183  }
184  };
185 
186 }
187 
188 #endif // DOXYGEN_HIDE_INTERNAL_CLASSES
189 
190 
191 template < class T > inline
193 {
194  typename TimeTexture< T >::iterator it;
195  for ( it = this->begin(); it != this->end(); it++ )
196  (it->second).erase();
197  std::map< int, Texture< T > >::erase( this->begin(), this->end() );
198 }
199 
200 
201 template < class T > inline
202 std::ostream& operator << ( std::ostream& out, const TimeTexture< T >& thing )
203 {
204  out << "{";
205 
207 
208  for ( it = thing.begin(); it != thing.end(); it++ )
209  {
210  out << "{";
211  out << "t=" << (*it).first << ",";
212  out << (*it).second << "},";
213  }
214 
215  return out << "NULL}" << std::flush;
216 }
217 
218 
219 //
220 // Useful typedefs
221 //
222 
225 
226 namespace carto {
227 
236 #define _TMP_ TimeTexture< AimsVector< short, 2 > >
238 #undef _TMP_
239 
246 DECLARE_GENERIC_OBJECT_TYPE( rc_ptr< Texture1d > )
247 DECLARE_GENERIC_OBJECT_TYPE( rc_ptr< Texture2d > )
248 #define _TMP_ rc_ptr< TimeTexture< AimsVector< short, 2 > > >
250 #undef _TMP_
251 
252 } // namespace carto
253 
254 #endif
#define DECLARE_GENERIC_OBJECT_TYPE(T)
TimeTexture(int ntimes, size_t nitems, const T &value)
Definition: texture.h:131
std::map< int, Texture< T > >::iterator iterator
Definition: texture.h:120
void erase()
Definition: texture.h:82
const T & operator[](int n) const
Definition: texture.h:73
Texture()
Definition: texture.h:65
Attributed python-like header, stores all needed information about an object, currently used for volu...
Definition: pheader.h:51
void push_back(const T &item)
Definition: texture.h:153
size_t nItem() const
Definition: texture.h:70
std::map< int, Texture< T > >::const_iterator const_iterator
Definition: texture.h:122
Texture(size_t n, const T &value)
Definition: texture.h:67
Texture(size_t n)
Definition: texture.h:66
TimeTexture(int ntimes, size_t nitems)
Definition: texture.h:125
aims::PythonHeader _header
Header.
Definition: texture.h:164
#define AIMSDATA_API
const T & item(int n) const
Definition: texture.h:72
STL namespace.
void reserve(size_t size)
Definition: texture.h:152
T & item(int n)
Definition: texture.h:75
static std::string objectType()
Definition: texture.h:176
void reserve(size_t size)
Definition: texture.h:77
virtual ~TimeTexture()
Definition: texture.h:137
size_t nItem() const
Definition: texture.h:146
TimeTexture()
Definition: texture.h:124
const T & item(int n) const
Definition: texture.h:148
std::vector< T > & data()
Definition: texture.h:80
T & item(int n)
Definition: texture.h:150
void erase()
Definition: texture.h:192
const std::vector< T > & data() const
Definition: texture.h:79
virtual ~Texture()
Definition: texture.h:68
AIMSDATA_API TimeTexture< Point2df > Texture2d
Definition: texture.h:224
AIMSDATA_API std::ostream & operator<<(std::ostream &out, const Texture< T > &thing)
Definition: texture.h:95
AIMSDATA_API TimeTexture< float > Texture1d
Definition: texture.h:223
#define _TMP_
Definition: texture.h:248
std::vector< T > _data
Definition: texture.h:90
aims::PythonHeader & header()
Definition: texture.h:141
void setHeader(const aims::PythonHeader &hdr)
Set the header.
Definition: texture.h:144
void push_back(const T &item)
Definition: texture.h:78
const aims::PythonHeader & header() const
Get the header.
Definition: texture.h:140