/usr/include/ITK-4.5/itkOffset.h is in libinsighttoolkit4-dev 4.5.0-3.
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 | /*=========================================================================
*
* 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 __itkOffset_h
#define __itkOffset_h
#include "itkSize.h"
#include <memory>
namespace itk
{
namespace Functor
{
template< unsigned int VOffsetDimension >
class OffsetLexicographicCompare;
}
/**
* \class Offset
* \brief Represent the offset between two n-dimensional indexes
* in a n-dimensional image.
*
* Offset is a templated class to represent a multi-dimensional offset,
* i.e. (i,j,k,...). Offset is templated over the dimension of the space.
*
* For the sake of efficiency, Offset does not define a default constructor, a
* copy constructor, or an operator=. We rely on the compiler to provide
* efficient bitwise copies.
*
* \sa Index
* \ingroup ImageAccess
* \ingroup ITKCommon
*
* \wiki
* \wikiexample{SimpleOperations/Offset,Add an offset to a pixel index}
* \endwiki
*/
template< unsigned int VOffsetDimension = 2 >
class Offset
{
public:
/** Standard class typedefs. */
typedef Offset Self;
/** Dimension constant */
itkStaticConstMacro(Dimension, unsigned int, VOffsetDimension);
/** Get the dimension (size) of the index. */
static unsigned int GetOffsetDimension() { return VOffsetDimension; }
/** Compatible offset typedefs. */
typedef Offset< VOffsetDimension > OffsetType;
typedef itk::OffsetValueType OffsetValueType;
/** Lexicographic ordering functor type. */
typedef Functor::OffsetLexicographicCompare< VOffsetDimension > LexicographicCompare;
/** Add an offset to an offset. */
const Self
operator+(const Self & offset) const
{
Self result;
for ( unsigned int i = 0; i < VOffsetDimension; i++ )
{ result[i] = m_Offset[i] + offset[i]; }
return result;
}
/** Add a size to an offset. */
const Self
operator+(const Size< VOffsetDimension > & size) const
{
Self result;
for ( unsigned int i = 0; i < VOffsetDimension; i++ )
{ result[i] = m_Offset[i] + size[i]; }
return result;
}
/** Increment index by a size. */
const Self &
operator+=(const Size< VOffsetDimension > & size)
{
for ( unsigned int i = 0; i < VOffsetDimension; i++ )
{ m_Offset[i] += size[i]; }
return *this;
}
/** Decrement index by a size. */
const Self &
operator-=(const Size< VOffsetDimension > & size)
{
for ( unsigned int i = 0; i < VOffsetDimension; i++ )
{ m_Offset[i] -= size[i]; }
return *this;
}
/** Subtract two offsets. */
const Self
operator-(const Self & vec)
{
Self result;
for ( unsigned int i = 0; i < VOffsetDimension; i++ )
{ result[i] = m_Offset[i] - vec.m_Offset[i]; }
return result;
}
/** Increment offset by an offset. */
const Self &
operator+=(const Self & vec)
{
for ( unsigned int i = 0; i < VOffsetDimension; i++ )
{ m_Offset[i] += vec.m_Offset[i]; }
return *this;
}
/** Decrement offset by an offset. */
const Self &
operator-=(const Self & vec)
{
for ( unsigned int i = 0; i < VOffsetDimension; i++ )
{ m_Offset[i] -= vec.m_Offset[i]; }
return *this;
}
/** Compare two offsets. */
bool
operator==(const Self & vec) const
{
bool same = 1;
for ( unsigned int i = 0; i < VOffsetDimension && same; i++ )
{ same = ( m_Offset[i] == vec.m_Offset[i] ); }
return same;
}
/** Compare two offsets. */
bool
operator!=(const Self & vec) const
{
bool same = 1;
for ( unsigned int i = 0; i < VOffsetDimension && same; i++ )
{ same = ( m_Offset[i] == vec.m_Offset[i] ); }
return !same;
}
/** Access an element of the offset. Elements are numbered
* 0, ..., VOffsetDimension-1. No bounds checking is performed. */
OffsetValueType & operator[](unsigned int dim)
{ return m_Offset[dim]; }
/** Access an element of the index. Elements are numbered
* 0, ..., VOffsetDimension-1. This version can only be an rvalue.
* No bounds checking is performed. */
OffsetValueType operator[](unsigned int dim) const
{ return m_Offset[dim]; }
/** Get the index. This provides a read only reference to the index.
* \sa SetOffset() */
const OffsetValueType * GetOffset() const { return m_Offset; }
/** 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 GetOffset() */
void SetOffset(const OffsetValueType val[VOffsetDimension])
{
std::copy(val,
val+VOffsetDimension,
m_Offset);
}
/** 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, ..., VOffsetDimension-1. */
static Self GetBasisOffset(unsigned int dim);
/** Set one value for the offset in all dimensions. Useful for initializing
* an offset to zero. */
void Fill(OffsetValueType value)
{ for ( unsigned int i = 0; i < VOffsetDimension; ++i ) { m_Offset[i] = value; } }
/** Offset is an "aggregate" class. Its data is public (m_Offset)
* allowing for fast and convenient instantiations/assignments.
*
* The following syntax for assigning an index is allowed/suggested:
* Offset<3> index = {5, 2, 7}; */
OffsetValueType m_Offset[VOffsetDimension];
// force gccxml to find the constructors found before the internal upgrade to
// gcc 4.2
#if defined( CABLE_CONFIGURATION )
Offset(); //purposely not implemented
Offset(const Self &); //purposely not implemented
void operator=(const Self &); //purposely not implemented
#endif
};
namespace Functor
{
/** \class OffsetLexicographicCompare
* \brief Order Offset instances lexicographically.
*
* This is a comparison functor suitable for storing Offset instances
* in an STL container. The ordering is total and unique but has
* little geometric meaning.
* \ingroup ITKCommon
*/
template< unsigned int VOffsetDimension >
class OffsetLexicographicCompare
{
public:
bool operator()(Offset< VOffsetDimension > const & l,
Offset< VOffsetDimension > const & r) const
{
for ( unsigned int i = 0; i < VOffsetDimension; ++i )
{
if ( l.m_Offset[i] < r.m_Offset[i] )
{
return true;
}
else if ( l.m_Offset[i] > r.m_Offset[i] )
{
return false;
}
}
return false;
}
};
}
template< unsigned int VOffsetDimension >
Offset< VOffsetDimension >
Offset< VOffsetDimension >
::GetBasisOffset(unsigned int dim)
{
Self ind;
memset(ind.m_Offset, 0, sizeof( OffsetValueType ) * VOffsetDimension);
ind.m_Offset[dim] = 1;
return ind;
}
template< unsigned int VOffsetDimension >
std::ostream & operator<<(std::ostream & os, const Offset< VOffsetDimension > & ind)
{
os << "[";
unsigned int dimlim = VOffsetDimension - 1;
for ( unsigned int i = 0; i < dimlim; ++i )
{
os << ind[i] << ", ";
}
if ( VOffsetDimension >= 1 )
{
os << ind[VOffsetDimension - 1];
}
os << "]";
return os;
}
} // end namespace itk
#endif
|