/usr/include/ITK-4.9/itkConstNeighborhoodIterator.hxx 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 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 | /*=========================================================================
*
* 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 itkConstNeighborhoodIterator_hxx
#define itkConstNeighborhoodIterator_hxx
#include "itkConstNeighborhoodIterator.h"
namespace itk
{
template< typename TImage, typename TBoundaryCondition >
bool
ConstNeighborhoodIterator< TImage, TBoundaryCondition >
::InBounds() const
{
if ( m_IsInBoundsValid )
{
return m_IsInBounds;
}
bool ans = true;
for ( DimensionValueType i = 0; i < Dimension; i++ )
{
if ( m_Loop[i] < m_InnerBoundsLow[i] || m_Loop[i] >= m_InnerBoundsHigh[i] )
{
m_InBounds[i] = ans = false;
}
else
{
m_InBounds[i] = true;
}
}
m_IsInBounds = ans;
m_IsInBoundsValid = true;
return ans;
}
template< typename TImage, typename TBoundaryCondition >
bool
ConstNeighborhoodIterator< TImage, TBoundaryCondition >
::IndexInBounds(const NeighborIndexType n, OffsetType & internalIndex, OffsetType & offset ) const
{
if ( !m_NeedToUseBoundaryCondition )
{
return true;
}
else if ( this->InBounds() ) // Is this whole neighborhood in bounds?
{
return true;
}
else
{
bool flag = true;
internalIndex = this->ComputeInternalIndex(n);
// Is this pixel in bounds?
for ( DimensionValueType i = 0; i < Dimension; ++i )
{
if ( m_InBounds[i] )
{
offset[i] = 0; // this dimension in bounds
}
else // part of this dimension spills out of bounds
{
// Calculate overlap for this dimension
const OffsetValueType OverlapLow ( m_InnerBoundsLow[i] - m_Loop[i] );
if ( internalIndex[i] < OverlapLow )
{
flag = false;
offset[i] = OverlapLow - internalIndex[i];
}
else
{
const OffsetValueType OverlapHigh ( static_cast< OffsetValueType >( this->GetSize(i) - ( ( m_Loop[i] + 2 ) - m_InnerBoundsHigh[i] ) ) );
if ( OverlapHigh < internalIndex[i] )
{
flag = false;
offset[i] = OverlapHigh - internalIndex[i];
}
else
{
offset[i] = 0;
}
}
}
}
return flag;
}
}
template< class TImage, class TBoundaryCondition >
bool
ConstNeighborhoodIterator< TImage, TBoundaryCondition >
::IndexInBounds(const NeighborIndexType n ) const
{
if ( !m_NeedToUseBoundaryCondition )
{
return true;
}
else if ( this->InBounds() ) // Is this whole neighborhood in bounds?
{
return true;
}
else
{
bool flag = true;
const OffsetType & internalIndex = this->ComputeInternalIndex(n);
// Is this pixel in bounds?
for ( DimensionValueType i = 0; i < Dimension; ++i )
{
if ( ! m_InBounds[i] )
{
// Calculate overlap for this dimension
const OffsetValueType OverlapLow ( m_InnerBoundsLow[i] - m_Loop[i] );
if ( internalIndex[i] < OverlapLow )
{
flag = false;
}
else
{
const OffsetValueType OverlapHigh ( static_cast< OffsetValueType >( this->GetSize(i) - ( ( m_Loop[i] + 2 ) - m_InnerBoundsHigh[i] ) ) );
if ( OverlapHigh < internalIndex[i] )
{
flag = false;
}
}
}
}
return flag;
}
}
template< typename TImage, typename TBoundaryCondition >
typename ConstNeighborhoodIterator< TImage, TBoundaryCondition >::PixelType
ConstNeighborhoodIterator< TImage, TBoundaryCondition >
::GetPixel(NeighborIndexType n, bool & IsInBounds) const
{
// If the region the iterator is walking (padded by the neighborhood size)
// never bumps up against the bounds of the buffered region, then don't
// bother checking any boundary conditions
if ( !m_NeedToUseBoundaryCondition )
{
IsInBounds = true;
return ( m_NeighborhoodAccessorFunctor.Get( this->operator[](n) ) );
}
// Is this whole neighborhood in bounds?
if ( this->InBounds() )
{
IsInBounds = true;
return ( m_NeighborhoodAccessorFunctor.Get( this->operator[](n) ) );
}
else
{
bool flag;
OffsetType offset, internalIndex;
flag = this->IndexInBounds( n, internalIndex, offset );
if ( flag )
{
IsInBounds = true;
return ( m_NeighborhoodAccessorFunctor.Get( this->operator[](n) ) );
}
else
{
IsInBounds = false;
return ( m_NeighborhoodAccessorFunctor.BoundaryCondition( internalIndex, offset, this, this->m_BoundaryCondition ) );
}
}
}
template< typename TImage, typename TBoundaryCondition >
typename ConstNeighborhoodIterator< TImage, TBoundaryCondition >::OffsetType
ConstNeighborhoodIterator< TImage, TBoundaryCondition >
::ComputeInternalIndex(const NeighborIndexType n) const
{
OffsetType ans;
const long D = (long)Dimension;
unsigned long r = (unsigned long)n;
for ( long i = D - 1; i >= 0; --i )
{
ans[i] = static_cast< OffsetValueType >( r / this->GetStride(i) );
r = r % this->GetStride(i);
}
return ans;
}
template< typename TImage, typename TBoundaryCondition >
typename ConstNeighborhoodIterator< TImage, TBoundaryCondition >::RegionType
ConstNeighborhoodIterator< TImage, TBoundaryCondition >
::GetBoundingBoxAsImageRegion() const
{
const IndexValueType zero = NumericTraits< IndexValueType >::ZeroValue();
RegionType ans;
ans.SetIndex( this->GetIndex(zero) );
ans.SetSize( this->GetSize() );
return ans;
}
template< typename TImage, typename TBoundaryCondition >
ConstNeighborhoodIterator< TImage, TBoundaryCondition >
::ConstNeighborhoodIterator() :
m_IsInBounds(false),
m_IsInBoundsValid(false),
m_NeedToUseBoundaryCondition(false)
{
IndexType zeroIndex; zeroIndex.Fill(0);
SizeType zeroSize; zeroSize.Fill(0);
m_Bound.Fill(0);
m_Begin = ITK_NULLPTR;
m_BeginIndex.Fill(0);
m_End = ITK_NULLPTR;
m_EndIndex.Fill(0);
m_Loop.Fill(0);
m_Region.SetIndex(zeroIndex);
m_Region.SetSize(zeroSize);
m_WrapOffset.Fill(0);
for ( DimensionValueType i = 0; i < Dimension; i++ )
{
m_InBounds[i] = false;
}
this->ResetBoundaryCondition();
m_BoundaryCondition = &m_InternalBoundaryCondition;
}
template< typename TImage, typename TBoundaryCondition >
ConstNeighborhoodIterator< TImage, TBoundaryCondition >
::ConstNeighborhoodIterator(const Self & orig):
Neighborhood< InternalPixelType *, Dimension >(orig)
{
m_Bound = orig.m_Bound;
m_Begin = orig.m_Begin;
m_BeginIndex = orig.m_BeginIndex;
m_ConstImage = orig.m_ConstImage;
m_End = orig.m_End;
m_EndIndex = orig.m_EndIndex;
m_Loop = orig.m_Loop;
m_Region = orig.m_Region;
m_WrapOffset = orig.m_WrapOffset;
m_InternalBoundaryCondition = orig.m_InternalBoundaryCondition;
m_NeedToUseBoundaryCondition = orig.m_NeedToUseBoundaryCondition;
for ( DimensionValueType i = 0; i < Dimension; ++i )
{
m_InBounds[i] = orig.m_InBounds[i];
}
m_IsInBoundsValid = orig.m_IsInBoundsValid;
m_IsInBounds = orig.m_IsInBounds;
m_InnerBoundsLow = orig.m_InnerBoundsLow;
m_InnerBoundsHigh = orig.m_InnerBoundsHigh;
// Check to see if the default boundary
// conditions have been overridden.
if ( orig.m_BoundaryCondition ==
static_cast< ImageBoundaryConditionConstPointerType >(
&orig.m_InternalBoundaryCondition ) )
{
this->ResetBoundaryCondition();
}
else
{
m_BoundaryCondition = orig.m_BoundaryCondition;
}
m_NeighborhoodAccessorFunctor = orig.m_NeighborhoodAccessorFunctor;
}
template< typename TImage, typename TBoundaryCondition >
void
ConstNeighborhoodIterator< TImage, TBoundaryCondition >
::SetEndIndex()
{
if ( m_Region.GetNumberOfPixels() > 0 )
{
m_EndIndex = m_Region.GetIndex();
m_EndIndex[Dimension - 1] = m_Region.GetIndex()[Dimension - 1]
+ static_cast< OffsetValueType >( m_Region.GetSize()[Dimension - 1] );
}
else
{
// Region has no pixels, so set the end index to be the begin index
m_EndIndex = m_Region.GetIndex();
}
}
template< typename TImage, typename TBoundaryCondition >
typename ConstNeighborhoodIterator< TImage, TBoundaryCondition >::NeighborhoodType
ConstNeighborhoodIterator< TImage, TBoundaryCondition >
::GetNeighborhood() const
{
OffsetType OverlapLow, OverlapHigh, temp, offset;
const ConstIterator _end = this->End();
NeighborhoodType ans;
typename NeighborhoodType::Iterator ansIt;
ConstIterator thisIt;
ans.SetRadius( this->GetRadius() );
if ( m_NeedToUseBoundaryCondition == false )
{
for ( ansIt = ans.Begin(), thisIt = this->Begin();
thisIt < _end; ++ansIt, ++thisIt )
{
*ansIt = m_NeighborhoodAccessorFunctor.Get(*thisIt);
}
}
else if ( InBounds() )
{
for ( ansIt = ans.Begin(), thisIt = this->Begin();
thisIt < _end; ++ansIt, ++thisIt )
{
*ansIt = m_NeighborhoodAccessorFunctor.Get(*thisIt);
}
}
else
{
// Calculate overlap & initialize index
for ( DimensionValueType i = 0; i < Dimension; i++ )
{
OverlapLow[i] = m_InnerBoundsLow[i] - m_Loop[i];
OverlapHigh[i] =
static_cast< OffsetValueType >( this->GetSize(i) ) - ( ( m_Loop[i] + 2 )
- m_InnerBoundsHigh[i] );
temp[i] = 0;
}
// Iterate through neighborhood
for ( ansIt = ans.Begin(), thisIt = this->Begin();
thisIt < _end; ++ansIt, ++thisIt )
{
bool flag = true;
// Is this pixel in bounds?
for ( DimensionValueType i = 0; i < Dimension; ++i )
{
if ( m_InBounds[i] )
{
offset[i] = 0; // this dimension in bounds
}
else // part of this dimension spills out of bounds
{
if ( temp[i] < OverlapLow[i] )
{
flag = false;
offset[i] = OverlapLow[i] - temp[i];
}
else if ( OverlapHigh[i] < temp[i] )
{
flag = false;
offset[i] = OverlapHigh[i] - temp[i];
}
else { offset[i] = 0; }
}
}
if ( flag )
{
*ansIt = m_NeighborhoodAccessorFunctor.Get(*thisIt);
}
else
{
*ansIt = m_NeighborhoodAccessorFunctor.BoundaryCondition(
temp, offset, this, this->m_BoundaryCondition);
}
m_BoundaryCondition->operator()(temp, offset, this);
for ( DimensionValueType i = 0; i < Dimension; ++i ) // Update index
{
temp[i]++;
if ( temp[i] == static_cast< OffsetValueType >( this->GetSize(i) ) )
{
temp[i] = 0;
}
else
{
break;
}
}
}
}
return ans;
}
template< typename TImage, typename TBoundaryCondition >
void
ConstNeighborhoodIterator< TImage, TBoundaryCondition >
::GoToBegin()
{
this->SetLocation(m_BeginIndex);
}
template< typename TImage, typename TBoundaryCondition >
void
ConstNeighborhoodIterator< TImage, TBoundaryCondition >
::GoToEnd()
{
this->SetLocation(m_EndIndex);
}
template< typename TImage, typename TBoundaryCondition >
void
ConstNeighborhoodIterator< TImage, TBoundaryCondition >
::SetRegion(const RegionType & region)
{
m_Region = region;
const IndexType regionIndex = region.GetIndex();
this->SetBeginIndex( region.GetIndex() );
this->SetLocation( region.GetIndex() );
this->SetBound( region.GetSize() );
this->SetEndIndex();
m_Begin = m_ConstImage->GetBufferPointer() + m_ConstImage->ComputeOffset(regionIndex);
m_End = m_ConstImage->GetBufferPointer() + m_ConstImage->ComputeOffset(m_EndIndex);
// now determine whether boundary conditions are going to be needed
const IndexType bStart = m_ConstImage->GetBufferedRegion().GetIndex();
const SizeType bSize = m_ConstImage->GetBufferedRegion().GetSize();
const IndexType rStart = region.GetIndex();
const SizeType rSize = region.GetSize();
m_NeedToUseBoundaryCondition = false;
for ( DimensionValueType i = 0; i < Dimension; ++i )
{
const OffsetValueType overlapLow = static_cast< OffsetValueType >( ( rStart[i]
- static_cast<OffsetValueType>( this->GetRadius(i) ) ) - bStart[i] );
const OffsetValueType overlapHigh = static_cast< OffsetValueType >( ( bStart[i] + bSize[i] )
- ( rStart[i] + rSize[i] + static_cast<OffsetValueType>( this->GetRadius(i) ) ) );
if ( overlapLow < 0 ) // out of bounds condition, define a region of
{
m_NeedToUseBoundaryCondition = true;
break;
}
if ( overlapHigh < 0 )
{
m_NeedToUseBoundaryCondition = true;
break;
}
}
}
template< typename TImage, typename TBoundaryCondition >
void ConstNeighborhoodIterator< TImage, TBoundaryCondition >
::Initialize(const SizeType & radius, const ImageType *ptr,
const RegionType & region)
{
m_ConstImage = ptr;
this->SetRadius(radius);
SetRegion(region);
m_IsInBoundsValid = false;
m_IsInBounds = false;
}
template< typename TImage, typename TBoundaryCondition >
ConstNeighborhoodIterator< TImage, TBoundaryCondition > &
ConstNeighborhoodIterator< TImage, TBoundaryCondition >
::operator=(const Self & orig)
{
if(this != &orig)
{
Superclass::operator=(orig);
m_Bound = orig.m_Bound;
m_Begin = orig.m_Begin;
m_ConstImage = orig.m_ConstImage;
m_End = orig.m_End;
m_EndIndex = orig.m_EndIndex;
m_Loop = orig.m_Loop;
m_Region = orig.m_Region;
m_BeginIndex = orig.m_BeginIndex;
m_WrapOffset = orig.m_WrapOffset;
m_InternalBoundaryCondition = orig.m_InternalBoundaryCondition;
m_NeedToUseBoundaryCondition = orig.m_NeedToUseBoundaryCondition;
m_InnerBoundsLow = orig.m_InnerBoundsLow;
m_InnerBoundsHigh = orig.m_InnerBoundsHigh;
for ( DimensionValueType i = 0; i < Dimension; ++i )
{
m_InBounds[i] = orig.m_InBounds[i];
}
m_IsInBoundsValid = orig.m_IsInBoundsValid;
m_IsInBounds = orig.m_IsInBounds;
// Check to see if the default boundary conditions
// have been overridden.
if ( orig.m_BoundaryCondition ==
static_cast< ImageBoundaryConditionConstPointerType >(
&orig.m_InternalBoundaryCondition ) )
{
this->ResetBoundaryCondition();
}
else { m_BoundaryCondition = orig.m_BoundaryCondition; }
m_NeighborhoodAccessorFunctor = orig.m_NeighborhoodAccessorFunctor;
}
return *this;
}
template< typename TImage, typename TBoundaryCondition >
ConstNeighborhoodIterator< TImage, TBoundaryCondition > &
ConstNeighborhoodIterator< TImage, TBoundaryCondition >
::operator++()
{
Iterator it;
const Iterator _end = Superclass::End();
// Repositioning neighborhood, previous bounds check on neighborhood
// location is invalid.
m_IsInBoundsValid = false;
// Increment pointers.
for ( it = Superclass::Begin(); it < _end; ++it )
{
( *it )++;
}
// Check loop bounds, wrap & add pointer offsets if needed.
for ( DimensionValueType i = 0; i < Dimension; ++i )
{
m_Loop[i]++;
if ( m_Loop[i] == m_Bound[i] )
{
m_Loop[i] = m_BeginIndex[i];
for ( it = Superclass::Begin(); it < _end; ++it )
{
( *it ) += m_WrapOffset[i];
}
}
else { break; }
}
return *this;
}
template< typename TImage, typename TBoundaryCondition >
ConstNeighborhoodIterator< TImage, TBoundaryCondition > &
ConstNeighborhoodIterator< TImage, TBoundaryCondition >
::operator--()
{
Iterator it;
const Iterator _end = Superclass::End();
// Repositioning neighborhood, previous bounds check on neighborhood
// location is invalid.
m_IsInBoundsValid = false;
// Decrement pointers.
for ( it = Superclass::Begin(); it < _end; ++it )
{
( *it )--;
}
// Check loop bounds, wrap & add pointer offsets if needed.
for ( DimensionValueType i = 0; i < Dimension; ++i )
{
if ( m_Loop[i] == m_BeginIndex[i] )
{
m_Loop[i] = m_Bound[i] - 1;
for ( it = Superclass::Begin(); it < _end; ++it )
{
( *it ) -= m_WrapOffset[i];
}
}
else
{
m_Loop[i]--;
break;
}
}
return *this;
}
template< typename TImage, typename TBoundaryCondition >
void
ConstNeighborhoodIterator< TImage, TBoundaryCondition >
::PrintSelf(std::ostream & os, Indent indent) const
{
DimensionValueType i;
os << indent;
os << "ConstNeighborhoodIterator {this= " << this;
os << ", m_Region = { Start = {";
for ( i = 0; i < Dimension; ++i )
{
os << m_Region.GetIndex()[i] << " ";
}
os << "}, Size = { ";
for ( i = 0; i < Dimension; ++i )
{
os << m_Region.GetSize()[i] << " ";
}
os << "} }";
os << ", m_BeginIndex = { ";
for ( i = 0; i < Dimension; ++i )
{
os << m_BeginIndex[i] << " ";
}
os << "} , m_EndIndex = { ";
for ( i = 0; i < Dimension; ++i )
{
os << m_EndIndex[i] << " ";
}
os << "} , m_Loop = { ";
for ( i = 0; i < Dimension; ++i )
{
os << m_Loop[i] << " ";
}
os << "}, m_Bound = { ";
for ( i = 0; i < Dimension; ++i )
{
os << m_Bound[i] << " ";
}
os << "}, m_IsInBounds = {" << m_IsInBounds;
os << "}, m_IsInBoundsValid = {" << m_IsInBoundsValid;
os << "}, m_WrapOffset = { ";
for ( i = 0; i < Dimension; ++i )
{
os << m_WrapOffset[i] << " ";
}
os << ", m_Begin = " << m_Begin;
os << ", m_End = " << m_End;
os << "}" << std::endl;
os << indent << ", m_InnerBoundsLow = { ";
for ( i = 0; i < Dimension; i++ )
{
os << m_InnerBoundsLow[i] << " ";
}
os << "}, m_InnerBoundsHigh = { ";
for ( i = 0; i < Dimension; i++ )
{
os << m_InnerBoundsHigh[i] << " ";
}
os << "} }" << std::endl;
Superclass::PrintSelf( os, indent.GetNextIndent() );
}
template< typename TImage, typename TBoundaryCondition >
void ConstNeighborhoodIterator< TImage, TBoundaryCondition >
::SetBound(const SizeType & size)
{
SizeType radius = this->GetRadius();
const OffsetValueType *offset = m_ConstImage->GetOffsetTable();
const IndexType imageBRStart = m_ConstImage->GetBufferedRegion().GetIndex();
SizeType imageBRSize = m_ConstImage->GetBufferedRegion().GetSize();
// Set the bounds and the wrapping offsets. Inner bounds are the loop
// indices where the iterator will begin to overlap the edge of the image
// buffered region.
for ( DimensionValueType i = 0; i < Dimension; ++i )
{
m_Bound[i] = m_BeginIndex[i] + static_cast< OffsetValueType >( size[i] );
m_InnerBoundsHigh[i] = static_cast< IndexValueType >( imageBRStart[i]
+ static_cast< OffsetValueType >( imageBRSize[i] )
- static_cast< OffsetValueType >( radius[i] ) );
m_InnerBoundsLow[i] = static_cast< IndexValueType >( imageBRStart[i]
+ static_cast< OffsetValueType >( radius[i] ) );
m_WrapOffset[i] = ( static_cast< OffsetValueType >( imageBRSize[i] )
- ( m_Bound[i] - m_BeginIndex[i] ) ) * offset[i];
}
m_WrapOffset[Dimension - 1] = 0; // last offset is zero because there are no
// higher dimensions
}
template< typename TImage, typename TBoundaryCondition >
void ConstNeighborhoodIterator< TImage, TBoundaryCondition >
::SetPixelPointers(const IndexType & pos)
{
const Iterator _end = Superclass::End();
InternalPixelType * Iit;
ImageType * ptr = const_cast< ImageType * >( m_ConstImage.GetPointer() );
const SizeType size = this->GetSize();
const OffsetValueType *OffsetTable = m_ConstImage->GetOffsetTable();
const SizeType radius = this->GetRadius();
DimensionValueType i;
Iterator Nit;
SizeType loop;
for ( i = 0; i < Dimension; ++i )
{
loop[i] = 0;
}
// Find first "upper-left-corner" pixel address of neighborhood
Iit = ptr->GetBufferPointer() + ptr->ComputeOffset(pos);
for ( i = 0; i < Dimension; ++i )
{
Iit -= radius[i] * OffsetTable[i];
}
// Compute the rest of the pixel addresses
for ( Nit = Superclass::Begin(); Nit != _end; ++Nit )
{
*Nit = Iit;
++Iit;
for ( i = 0; i < Dimension; ++i )
{
loop[i]++;
if ( loop[i] == size[i] )
{
if ( i == Dimension - 1 ) { break; }
Iit += OffsetTable[i + 1] - OffsetTable[i] * static_cast< OffsetValueType >( size[i] );
loop[i] = 0;
}
else { break; }
}
}
}
template< typename TImage, typename TBoundaryCondition >
ConstNeighborhoodIterator< TImage, TBoundaryCondition > &
ConstNeighborhoodIterator< TImage, TBoundaryCondition >
::operator+=(const OffsetType & idx)
{
Iterator it;
const Iterator _end = this->End();
OffsetValueType accumulator = 0;
const OffsetValueType *stride = this->GetImagePointer()->GetOffsetTable();
// Repositioning neighborhood, previous bounds check on neighborhood
// location is invalid.
m_IsInBoundsValid = false;
// Offset from the increment in the lowest dimension
accumulator += idx[0];
// Offsets from the stride lengths in each dimension.
//
// Because the image offset table is based on its buffer size and not its
// requested region size, we don't have to worry about adding in the wrapping
// offsets.
for ( DimensionValueType i = 1; i < Dimension; ++i )
{
accumulator += idx[i] * stride[i];
}
// Increment pointers.
for ( it = this->Begin(); it < _end; ++it )
{
( *it ) += accumulator;
}
// Update loop counter values
m_Loop += idx;
return *this;
}
template< typename TImage, typename TBoundaryCondition >
ConstNeighborhoodIterator< TImage, TBoundaryCondition > &
ConstNeighborhoodIterator< TImage, TBoundaryCondition >
::operator-=(const OffsetType & idx)
{
Iterator it;
const Iterator _end = this->End();
OffsetValueType accumulator = 0;
const OffsetValueType *stride = this->GetImagePointer()->GetOffsetTable();
// Repositioning neighborhood, previous bounds check on neighborhood
// location is invalid.
m_IsInBoundsValid = false;
// Offset from the increment in the lowest dimension
accumulator += idx[0];
// Offsets from the stride lengths in each dimension.
//
// Because the image offset table is based on its buffer size and not its
// requested region size, we don't have to worry about adding in the wrapping
// offsets.
for ( DimensionValueType i = 1; i < Dimension; ++i )
{
accumulator += idx[i] * stride[i];
}
// Increment pointers.
for ( it = this->Begin(); it < _end; ++it )
{
( *it ) -= accumulator;
}
// Update loop counter values
m_Loop -= idx;
return *this;
}
} // namespace itk
#endif
|