cartobase  5.0.5
voxelvalue.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 CARTOBASE_TYPE_VOXELVALUE_H
35 #define CARTOBASE_TYPE_VOXELVALUE_H
36 
37 //--- cartobase --------------------------------------------------------------
38 #include <cartobase/type/types.h>
40 //--- system -----------------------------------------------------------------
41 //#define CARTO_DEBUG_VOXELVALUE
42 #ifdef CARTO_DEBUG_VOXELVALUE
43  #include <iostream>
44 #endif
45 //----------------------------------------------------------------------------
46 
47 namespace carto {
48 
57  template <typename T, unsigned int C>
58  class VoxelValue
59  {
60  public:
61  //=== TYPES =====================================================
62  typedef T ChannelType;
63 
64  //=== CONSTANTS =====================================================
65  static const unsigned int channelcount = C;
66 
67  //=== CONSTRUCTORS =====================================================
68  VoxelValue();
69  VoxelValue( const VoxelValue<T,C> & other );
70  ~VoxelValue();
71 
72  //=== OPERATORS ========================================================
73  bool operator == ( const VoxelValue<T,C> & ) const;
74  bool operator != ( const VoxelValue<T,C> & ) const;
75  bool operator == ( const T & ) const;
76  bool operator != ( const T & ) const;
77 
78  //=== CONVERSION =======================================================
79  operator bool() const;
80 
81  //=== ACCESSORS ========================================================
82  inline
83  const T & operator[] ( unsigned int i ) const { return _voxel[i]; }
84  inline
85  T & operator[] ( unsigned int i ) { return _voxel[i]; }
86 
87  protected:
88  T _voxel[C];
89  };
90 
91  /***************************************************************************
92  * Old stream operators
93  **************************************************************************/
94 
95  template <typename T, unsigned int C> inline
96  std::ostream& operator << ( std::ostream &out, const VoxelValue<T,C> &aa )
97  {
98  unsigned int i;
99  out << '(';
100  for( i=0; i<C-1; ++i )
101  out << static_cast<int>( aa[i] ) << ',';
102  out << static_cast<int>( aa[C-1] ) << ')';
103  return( out );
104  }
105 
106  template <typename T, unsigned int C> inline
107  std::istream& operator >> ( std::istream &in , VoxelValue<T,C> &aa )
108  {
109  int read;
110  char ch = 0;
111  unsigned int i;
112  VoxelValue<T,C> result;
113 
114  while( in &&
115  ( in.peek() == ' ' || in.peek() == '\t' || in.peek() == '\n' ) )
116  in >> ch;
117  if ( in.peek () == '(' )
118  in >> ch;
119 
120  in >> read >> ch;
121  result[0] = static_cast<T>( read );
122  for( i=1; i<C; ++i )
123  if( ch == ',' ) {
124  in >> read >> ch;
125  result[i] = static_cast<T>( read );
126  }
127 
128  if( ch != 0 && ch != ')' )
129  in.setstate (std::ios::failbit);
130  else if (in.good())
131  aa = result;
132 
133  return in;
134  }
135 
136 }
137 
138 #endif
static const unsigned int channelcount
Definition: voxelvalue.h:65
const T & operator[](unsigned int i) const
Definition: voxelvalue.h:83
std::istream & operator>>(std::istream &in, VoxelValue< T, C > &aa)
Definition: voxelvalue.h:107
Base class for any multichannel data (RGB, RGBA, HSV, ...)
Definition: voxelvalue.h:58
bool operator!=(const VoxelValue< T, C > &) const
Definition: voxelvalue_d.h:90
bool operator==(const VoxelValue< T, C > &) const
Definition: voxelvalue_d.h:77