cartobase 6.0.6
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 --------------------------------------------------------------
40//--- system -----------------------------------------------------------------
41#include <functional>
42//#define CARTO_DEBUG_VOXELVALUE
43#ifdef CARTO_DEBUG_VOXELVALUE
44 #include <iostream>
45#endif
46//----------------------------------------------------------------------------
47
48namespace carto {
49
58 template <typename T, unsigned int C>
60 {
61 public:
62 //=== TYPES =====================================================
63 typedef T ChannelType;
64
65 //=== CONSTANTS =====================================================
66 static const unsigned int channelcount = C;
67
68 //=== CONSTRUCTORS =====================================================
69 VoxelValue();
70 VoxelValue( const VoxelValue<T,C> & other );
72
73 //=== OPERATORS ========================================================
74 bool operator == ( const VoxelValue<T,C> & ) const;
75 bool operator != ( const VoxelValue<T,C> & ) const;
76 bool operator == ( const T & ) const;
77 bool operator != ( const T & ) const;
78
79 // Since C++11 this operator is explicitly defaulted to avoid a warning
81
82 //=== CONVERSION =======================================================
83 operator bool() const;
84
85 //=== ACCESSORS ========================================================
86 inline
87 const T & operator[] ( unsigned int i ) const { return _voxel[i]; }
88 inline
89 T & operator[] ( unsigned int i ) { return _voxel[i]; }
90
91 protected:
92 T _voxel[C];
93 };
94
95 //=== KEY COMPARATOR =======================================================
96
104
105 // General definition
106 template <typename V>
108 {
109 static inline uint64_t toUnsignedInt( const V & value);
110
111 static inline bool less( const V & lhs, const V & rhs );
112 };
113
114 // VoxelValue partial specialization
115 template <typename T, unsigned C>
117 {
118 static inline uint64_t toUnsignedInt(const carto::VoxelValue<T, C> & value);
119
120 static inline bool less(const carto::VoxelValue<T, C> & lhs,
121 const carto::VoxelValue<T, C> & rhs);
122 };
123
124
125 //=== KEY FUNCTORS =======================================================
134
135 // KeyComparatorLess functor
136 template <typename V>
137 struct KeyComparatorLess: std::binary_function<V, V, bool>
138 {
139 constexpr bool operator ()(const V & lhs, const V & rhs) const;
140 };
141
142 /***************************************************************************
143 * Old stream operators
144 **************************************************************************/
145
146 template <typename T, unsigned int C> inline
147 std::ostream& operator << ( std::ostream &out, const VoxelValue<T,C> &aa )
148 {
149 unsigned int i;
150 out << '(';
151 for( i=0; i<C-1; ++i )
152 out << static_cast<int>( aa[i] ) << ',';
153 out << static_cast<int>( aa[C-1] ) << ')';
154 return( out );
155 }
156
157 template <typename T, unsigned int C> inline
158 std::istream& operator >> ( std::istream &in , VoxelValue<T,C> &aa )
159 {
160 int read;
161 char ch = 0;
162 unsigned int i;
163 VoxelValue<T,C> result;
164
165 while( in &&
166 ( in.peek() == ' ' || in.peek() == '\t' || in.peek() == '\n' ) )
167 in >> ch;
168 if ( in.peek () == '(' )
169 in >> ch;
170
171 in >> read >> ch;
172 result[0] = static_cast<T>( read );
173 for( i=1; i<C; ++i )
174 if( ch == ',' ) {
175 in >> read >> ch;
176 result[i] = static_cast<T>( read );
177 }
178
179 if( ch != 0 && ch != ')' )
180 in.setstate (std::ios::failbit);
181 else if (in.good())
182 aa = result;
183
184 return in;
185 }
186
187}
188
189#endif
Base class for any multichannel data (RGB, RGBA, HSV, ...)
Definition voxelvalue.h:60
const T & operator[](unsigned int i) const
Definition voxelvalue.h:87
VoxelValue< T, C > & operator=(const VoxelValue< T, C > &)=default
static const unsigned int channelcount
Definition voxelvalue.h:66
bool operator==(const VoxelValue< T, C > &) const
bool operator!=(const VoxelValue< T, C > &) const
std::ostream & operator<<(std::ostream &out, const VoxelValue< T, C > &aa)
Definition voxelvalue.h:147
std::istream & operator>>(std::istream &in, VoxelValue< T, C > &aa)
Definition voxelvalue.h:158
KeyComparatorLess Function object to be used in key comparisons.
Definition voxelvalue.h:138
constexpr bool operator()(const V &lhs, const V &rhs) const
KeyComparator is used to compare keys of types that do not have comparison operator.
Definition voxelvalue.h:108
static uint64_t toUnsignedInt(const V &value)
static bool less(const V &lhs, const V &rhs)