A.I.M.S


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