cartobase 6.0.6
voxelvalue_d.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_D_H
35#define CARTOBASE_TYPE_VOXELVALUE_D_H
36
37//--- cartobase --------------------------------------------------------------
40//----------------------------------------------------------------------------
41
42namespace carto {
43
44 //==========================================================================
45 // C O N S T R U C T O R S
46 //==========================================================================
47
48 template <typename T, unsigned int C>
50 {
51 #ifdef CARTO_DEBUG_VOXELVALUE
52 std::cout << "VOXELVALUE:: constructor()" << std::endl;
53 #endif
54 }
55
56 template <typename T, unsigned int C>
58 {
59 #ifdef CARTO_DEBUG_VOXELVALUE
60 std::cout << "VOXELVALUE:: constructor( other )" << std::endl;
61 #endif
62 *this = other;
63 }
64
65 template <typename T, unsigned int C>
67 {
68 #ifdef CARTO_DEBUG_VOXELVALUE
69 std::cout << "VOXELVALUE:: destructor()" << std::endl;
70 #endif
71 }
72
73 //==========================================================================
74 // I N T E R N O P E R A T O R S
75 //==========================================================================
77 template <typename T, unsigned int C> inline
79 {
80 #ifdef CARTO_DEBUG_VOXELVALUE
81 std::cout << "VOXELVALUE:: VV == VV" << std::endl;
82 #endif
83 unsigned int i;
84 for( i=0; i<C; ++i )
85 if( (*this)[ i ] != aa[ i ] )
86 return false;
87 return true;
88 }
89
90 template <typename T, unsigned int C> inline
92 {
93 #ifdef CARTO_DEBUG_VOXELVALUE
94 std::cout << "VOXELVALUE:: VV != VV" << std::endl;
95 #endif
96 return !( (*this) == aa );
97 }
98
99 template <typename T, unsigned int C>
100 bool VoxelValue<T,C>::operator == ( const T &bb ) const
101 {
102 #ifdef CARTO_DEBUG_VOXELVALUE
103 std::cout << "VOXELVALUE:: VV == const" << std::endl;
104 #endif
105 unsigned int i;
106 for( i=0; i<C; ++i )
107 if( (*this)[ i ] != bb )
108 return false;
109 return true;
110 }
112 template <typename T, unsigned int C> inline
113 bool VoxelValue<T,C>::operator != ( const T &bb ) const
114 {
115 #ifdef CARTO_DEBUG_VOXELVALUE
116 std::cout << "VOXELVALUE:: VV != const" << std::endl;
117 #endif
118 return !( (*this) == bb );
119 }
120
121 //=== CONVERSION =======================================================
122 template <typename T, unsigned int C>
124 {
125 #ifdef CARTO_DEBUG_VOXELVALUE
126 std::cout << "VOXELVALUE:: bool()" << std::endl;
127 #endif
128 unsigned int i;
129 for( i=0; i<C; ++i )
130 if( (*this)[ i ] != T(0) )
131 return true;
132 return false;
133 }
134
135 //=== KEY COMPARATOR =======================================================
136 template <typename V>
138 const V &value)
139 {
140 return uint64_t(value);
141 }
142
143 template <typename T, unsigned C>
145 const carto::VoxelValue<T, C> &value)
146 {
147 static_assert((sizeof(T) * C <= 8), "It is not possible to define toUnsignedInt for carto::VoxelValue<C, T>.");
148
149 uint64_t result = 0;
150 for (unsigned int c=0; c<carto::VoxelValue<T, C>::channelcount; ++c) {
151 #ifdef CARTO_DEBUG_VOXELVALUE
152 std::cout << "VOXELVALUE:: KeyComparator<carto::VoxelValue<T, C> >::toUnsignedInt(), "
153 << "value[" << carto::toString(c) << "] = " << carto::toString(value[c])
154 << std::endl;
155 #endif
156 result |= static_cast<uint64_t>(value[c] << (sizeof(T) * 8 * c));
157 }
158
159 #ifdef CARTO_DEBUG_VOXELVALUE
160 std::cout << "VOXELVALUE:: KeyComparator<carto::VoxelValue<T, C> >::toUnsignedInt(), "
161 << "result: " << carto::toString(result)
162 << std::endl;
163 #endif
164 return result;
165 }
166
167 template <typename V>
169 const V & lhs,
170 const V & rhs )
171 {
172 #ifdef CARTO_DEBUG_VOXELVALUE
173 std::cout << "VOXELVALUE:: KeyComparator<V>::less()" << std::endl;
174 #endif
175 return (lhs < rhs);
176 }
177
178 template <typename T, unsigned C>
180 const carto::VoxelValue<T, C> & lhs,
181 const carto::VoxelValue<T, C> & rhs )
182 {
183 #ifdef CARTO_DEBUG_VOXELVALUE
184 std::cout << "VOXELVALUE:: KeyComparator<carto::VoxelValue<T, C> >::less()" << std::endl;
185 #endif
186
189 }
190
191 //=== KEY COMPARATOR LESS FUNCTOR =======================================================
192 template <typename V>
193 constexpr bool KeyComparatorLess<V>::operator ()(const V & lhs, const V & rhs) const
194 {
195 #ifdef CARTO_DEBUG_VOXELVALUE
196 std::cout << "VOXELVALUE:: KeyComparatorLess<V>::operator()" << std::endl;
197 std::cout << "VOXELVALUE:: KeyComparatorLess<V>::operator(), lhs = " << carto::toString(lhs) << std::endl;
198 std::cout << "VOXELVALUE:: KeyComparatorLess<V>::operator(), rhs = " << carto::toString(rhs) << std::endl;
199 #endif
200
201 return carto::KeyComparator<V>::less(lhs, rhs);
202 }
203}
204
205#endif
Base class for any multichannel data (RGB, RGBA, HSV, ...)
Definition voxelvalue.h:60
bool operator==(const VoxelValue< T, C > &) const
bool operator!=(const VoxelValue< T, C > &) const
std::string toString(const T &object)
constexpr bool operator()(const V &lhs, const V &rhs) const
static bool less(const carto::VoxelValue< T, C > &lhs, const carto::VoxelValue< T, C > &rhs)
static uint64_t toUnsignedInt(const carto::VoxelValue< T, C > &value)
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)