/usr/include/ITK-4.9/itkIndex.h is in libinsighttoolkit4-dev 4.9.0-4ubuntu1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 | /*=========================================================================
*
* Copyright Insight Software Consortium
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0.txt
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*=========================================================================*/
#ifndef itkIndex_h
#define itkIndex_h
#include "itkOffset.h"
#include "itkFixedArray.h"
#include "itkMath.h"
#include <memory>
namespace itk
{
namespace Functor
{
template< unsigned int VIndexDimension >
class IndexLexicographicCompare;
}
/** \class Index
* \brief Represent a n-dimensional index in a n-dimensional image.
*
* Index is a templated class to represent a multi-dimensional index,
* i.e. (i,j,k,...). Index is templated over the dimension of the index.
* ITK assumes the first element of an index is the fastest moving index.
*
* For efficiency sake, Index does not define a default constructor, a
* copy constructor, or an operator=. We rely on the compiler to provide
* efficient bitwise copies.
*
* Index is an "aggregate" class. Its data is public (m_Index)
* allowing for fast and convenient instantiations/assignments.
*
* The following syntax for assigning an index is allowed/suggested:
*
* Index<3> index = {{5, 2, 7}};
*
* The double braces {{ and }} are needed to prevent a compiler warning
* about a partly bracketed initializer.
*
* \remark
* Should there be an itkBoundedIndex to handle bounds checking? Or should
* there be an API to perform bounded increments in the iterator.
*
* \ingroup ImageAccess
* \ingroup ImageObjects
* \ingroup ITKCommon
*
* \wiki
* \wikiexample{SimpleOperations/DistanceBetweenIndices,Distance between two indices}
* \wikiexample{Images/Index,An object which holds the index of a pixel}
* \endwiki
*/
template< unsigned int VIndexDimension = 2 >
class Index
{
public:
/** Standard class typedefs. */
typedef Index Self;
/** Compatible Index and value typedef */
typedef Index< VIndexDimension > IndexType;
typedef ::itk::IndexValueType IndexValueType;
/** Dimension constant */
itkStaticConstMacro(Dimension, unsigned int, VIndexDimension);
/** Get the dimension (size) of the index. */
static unsigned int GetIndexDimension() { return VIndexDimension; }
/** Compatible Size typedef. */
typedef Size< VIndexDimension > SizeType;
/** Compatible Offset and Offset value typedef. */
typedef Offset< VIndexDimension > OffsetType;
typedef ::itk::OffsetValueType OffsetValueType;
/** Lexicographic ordering functor type. */
typedef Functor::IndexLexicographicCompare< VIndexDimension > LexicographicCompare;
/** Add a size to an index. This method models a random access Index. */
const Self
operator+(const SizeType & size) const
{
Self result;
for ( unsigned int i = 0; i < VIndexDimension; i++ )
{ result[i] = m_Index[i] + static_cast< IndexValueType >( size[i] ); }
return result;
}
/** Increment index by a size. This method models a random access Index. */
const Self &
operator+=(const SizeType & size)
{
for ( unsigned int i = 0; i < VIndexDimension; i++ )
{ m_Index[i] += static_cast< IndexValueType >( size[i] ); }
return *this;
}
/** Subtract a size from an index. This method models a random access Index.
*/
const Self
operator-(const SizeType & size) const
{
Self result;
for ( unsigned int i = 0; i < VIndexDimension; i++ )
{ result[i] = m_Index[i] - static_cast< IndexValueType >( size[i] ); }
return result;
}
/** Decrement index by a size. This method models a random access Index. */
const Self &
operator-=(const SizeType & size)
{
for ( unsigned int i = 0; i < VIndexDimension; i++ )
{ m_Index[i] -= static_cast< IndexValueType >( size[i] ); }
return *this;
}
/** Add an offset to an index. */
const Self
operator+(const OffsetType & offset) const
{
Self result;
for ( unsigned int i = 0; i < VIndexDimension; i++ )
{ result[i] = m_Index[i] + offset[i]; }
return result;
}
/** Increment index by an offset. This method models a random access Index. */
const Self &
operator+=(const OffsetType & offset)
{
for ( unsigned int i = 0; i < VIndexDimension; i++ )
{ m_Index[i] += offset[i]; }
return *this;
}
/** Decrement index by an offset. This method models a random access Index. */
const Self &
operator-=(const OffsetType & offset)
{
for ( unsigned int i = 0; i < VIndexDimension; i++ )
{ m_Index[i] -= offset[i]; }
return *this;
}
/** Subtract an offset from an index. */
const Self
operator-(const OffsetType & off) const
{
Self result;
for ( unsigned int i = 0; i < VIndexDimension; i++ )
{ result[i] = m_Index[i] - off.m_Offset[i]; }
return result;
}
/** Subtract two indices. This method models a random access Index. */
const OffsetType
operator-(const Self & vec) const
{
OffsetType result;
for ( unsigned int i = 0; i < VIndexDimension; i++ )
{ result[i] = m_Index[i] - vec.m_Index[i]; }
return result;
}
/** Multiply an index by a size (elementwise product). This method
* models a random access Index. */
const Self
operator*(const SizeType & vec) const
{
Self result;
for ( unsigned int i = 0; i < VIndexDimension; i++ )
{ result[i] = m_Index[i] * static_cast< IndexValueType >( vec.m_Size[i] ); }
return result;
}
/** Compare two indices. */
bool
operator==(const Self & vec) const
{
bool same = true;
for ( unsigned int i = 0; i < VIndexDimension && same; i++ )
{ same = ( m_Index[i] == vec.m_Index[i] ); }
return same;
}
/** Compare two indices. */
bool
operator!=(const Self & vec) const
{
bool same = true;
for ( unsigned int i = 0; i < VIndexDimension && same; i++ )
{ same = ( m_Index[i] == vec.m_Index[i] ); }
return !same;
}
// false positive warnings with GCC 4.9
#if defined( __GNUC__ )
#if ( __GNUC__ == 4 ) && ( __GNUC_MINOR__ == 9 )
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Warray-bounds"
#endif
#endif
/** Access an element of the index. Elements are numbered
* 0, ..., VIndexDimension-1. No bounds checking is performed. */
IndexValueType & operator[](unsigned int dim)
{
return m_Index[dim];
}
#if defined( __GNUC__ )
#if ( __GNUC__ == 4 ) && ( __GNUC_MINOR__ == 9 )
#pragma GCC diagnostic pop
#endif
#endif
/** Access an element of the index. Elements are numbered
* 0, ..., VIndexDimension-1. This version can only be an rvalue.
* No bounds checking is performed. */
IndexValueType operator[](unsigned int dim) const
{ return m_Index[dim]; }
/** Get the index. This provides a read only reference to the index.
* \sa SetIndex() */
const IndexValueType * GetIndex() const { return m_Index; }
/** Set the index.
* Try to prototype this function so that val has to point to a block of
* memory that is the appropriate size.
* \sa GetIndex() */
void SetIndex(const IndexValueType val[VIndexDimension])
{
std::copy(val,
val+VIndexDimension,
m_Index);
}
/** Sets the value of one of the elements in the index.
* This method is mainly intended to facilitate the access to elements
* from Tcl and Python where C++ notation is not very convenient.
* \warning No bound checking is performed
* \sa SetIndex()
* \sa GetElement() */
void SetElement(unsigned long element, IndexValueType val)
{ m_Index[element] = val; }
/** Gets the value of one of the elements in the index.
* This method is mainly intended to facilitate the access to elements
* from Tcl and Python where C++ notation is not very convenient.
* \warning No bound checking is performed
* \sa GetIndex()
* \sa SetElement() */
IndexValueType GetElement(unsigned long element) const
{ return m_Index[element]; }
/** Return a basis vector of the form [0, ..., 0, 1, 0, ... 0] where the "1"
* is positioned in the location specified by the parameter "dim". Valid
* values of "dim" are 0, ..., VIndexDimension-1. */
static Self GetBasisIndex(unsigned int dim);
/** Set one value for the index in all dimensions. Useful for initializing
* an offset to zero. */
void Fill(IndexValueType value)
{ for ( unsigned int i = 0; i < VIndexDimension; ++i ) { m_Index[i] = value; } }
/** Index is an "aggregate" class. Its data is public (m_Index)
* allowing for fast and convenient instantiations/assignments.
*
* The following syntax for assigning an index is allowed/suggested:
* Index<3> index = {5, 2, 7}; */
IndexValueType m_Index[VIndexDimension];
/** Copy values from a FixedArray by rounding each one of the components */
template< typename TCoordRep >
inline void CopyWithRound(const FixedArray< TCoordRep, VIndexDimension > & point)
{
itkForLoopRoundingAndAssignmentMacro(IndexType,
ContinuousIndexType,
IndexValueType,
m_Index,
point,
VIndexDimension);
/* NON TEMPLATE_META_PROGRAMMING_LOOP_UNROLLING data version
* Leaving here for documentation purposes
* for ( unsigned int i = 0; i < VIndexDimension; ++i )
* {
* m_Index[i] = Math::Round< IndexValueType >(point[i]);
* }
*/
}
/** Copy values from a FixedArray by casting each one of the components */
template< typename TCoordRep >
inline void CopyWithCast(const FixedArray< TCoordRep, VIndexDimension > & point)
{
for ( unsigned int i = 0; i < VIndexDimension; ++i )
{
m_Index[i] = static_cast< IndexValueType >( point[i] );
}
}
// force gccxml to find the constructors found before the internal upgrade to
// gcc 4.2
#if defined( ITK_WRAPPING_PARSER )
Index() ITK_DELETE_FUNCTION;
Index(const Self &) ITK_DELETE_FUNCTION;
void operator=(const Self &) ITK_DELETE_FUNCTION;
#endif
};
namespace Functor
{
/** \class IndexLexicographicCompare
* \brief Order Index instances lexicographically.
*
* This is a comparison functor suitable for storing Index instances
* in an STL container. The ordering is total and unique but has
* little geometric meaning.
* \ingroup ITKCommon
*/
template< unsigned int VIndexDimension >
class IndexLexicographicCompare
{
public:
bool operator()(Index< VIndexDimension > const & l,
Index< VIndexDimension > const & r) const
{
for ( unsigned int i = 0; i < VIndexDimension; ++i )
{
if ( l.m_Index[i] < r.m_Index[i] )
{
return true;
}
else if ( l.m_Index[i] > r.m_Index[i] )
{
return false;
}
}
return false;
}
};
}
template< unsigned int VIndexDimension >
Index< VIndexDimension >
Index< VIndexDimension >
::GetBasisIndex(unsigned int dim)
{
Self ind;
memset(ind.m_Index, 0, sizeof( IndexValueType ) * VIndexDimension);
ind.m_Index[dim] = 1;
return ind;
}
template< unsigned int VIndexDimension >
std::ostream & operator<<(std::ostream & os, const Index< VIndexDimension > & ind)
{
os << "[";
for ( unsigned int i = 0; i + 1 < VIndexDimension; ++i )
{
os << ind[i] << ", ";
}
if ( VIndexDimension >= 1 )
{
os << ind[VIndexDimension - 1];
}
os << "]";
return os;
}
} // end namespace itk
#endif
|