/usr/include/InsightToolkit/Common/itkImageBase.txx is in libinsighttoolkit3-dev 3.20.1-1.
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 | /*=========================================================================
Program: Insight Segmentation & Registration Toolkit
Module: itkImageBase.txx
Language: C++
Date: $Date$
Version: $Revision$
Copyright (c) Insight Software Consortium. All rights reserved.
See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
Portions of this code are covered under the VTK copyright.
See VTKCopyright.txt or http://www.kitware.com/VTKCopyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notices for more information.
=========================================================================*/
#ifndef __itkImageBase_txx
#define __itkImageBase_txx
#include "itkImageBase.h"
#include "itkFastMutexLock.h"
#include "itkProcessObject.h"
#include "itkSpatialOrientation.h"
#include <string.h>
namespace itk
{
/**
*
*/
template<unsigned int VImageDimension>
ImageBase<VImageDimension>
::ImageBase()
{
memset( m_OffsetTable, 0, (VImageDimension+1)*sizeof(unsigned long) );
m_Spacing.Fill(1.0);
m_Origin.Fill(0.0);
m_Direction.SetIdentity();
m_IndexToPhysicalPoint.SetIdentity();
m_PhysicalPointToIndex.SetIdentity();
}
/**
*
*/
template<unsigned int VImageDimension>
void
ImageBase<VImageDimension>
::Initialize()
{
//
// We don't modify ourselves because the "ReleaseData" methods depend upon
// no modification when initialized. Otherwise BUG: 8490 will
// reoccur.
//
// DO NOT CALL ANY METHODS WHICH MODIFY OURSELVES
// Call the superclass which should initialize the BufferedRegion ivar.
Superclass::Initialize();
// Clear the offset table
memset( m_OffsetTable, 0, (VImageDimension+1)*sizeof(unsigned long) );
// Clear the BufferedRegion ivar
this->InitializeBufferedRegion();
}
/**
*
*/
template<unsigned int VImageDimension>
ImageBase<VImageDimension>
::~ImageBase()
{
}
//----------------------------------------------------------------------------
template<unsigned int VImageDimension>
void
ImageBase<VImageDimension>
::SetSpacing(const SpacingType & spacing )
{
itkDebugMacro("setting Spacing to " << spacing);
if( this->m_Spacing != spacing )
{
this->m_Spacing = spacing;
this->ComputeIndexToPhysicalPointMatrices();
this->Modified();
}
}
//----------------------------------------------------------------------------
template<unsigned int VImageDimension>
void
ImageBase<VImageDimension>
::SetSpacing(const double spacing[VImageDimension] )
{
SpacingType s(spacing);
this->SetSpacing(s);
}
//----------------------------------------------------------------------------
template<unsigned int VImageDimension>
void
ImageBase<VImageDimension>
::SetSpacing(const float spacing[VImageDimension] )
{
Vector<float, VImageDimension> sf(spacing);
SpacingType s;
s.CastFrom( sf );
this->SetSpacing(s);
}
//----------------------------------------------------------------------------
template<unsigned int VImageDimension>
void
ImageBase<VImageDimension>
::SetOrigin(const double origin[VImageDimension] )
{
PointType p(origin);
this->SetOrigin( p );
}
//----------------------------------------------------------------------------
template<unsigned int VImageDimension>
void
ImageBase<VImageDimension>
::SetOrigin(const float origin[VImageDimension] )
{
Point<float, VImageDimension> of(origin);
PointType p;
p.CastFrom( of );
this->SetOrigin( p );
}
//----------------------------------------------------------------------------
template<unsigned int VImageDimension>
void
ImageBase<VImageDimension>
::SetDirection(const DirectionType direction )
{
bool modified = false;
for (unsigned int r = 0; r < VImageDimension; r++)
{
for (unsigned int c = 0; c < VImageDimension; c++)
{
if (m_Direction[r][c] != direction[r][c])
{
m_Direction[r][c] = direction[r][c];
modified = true;
}
}
}
if (modified)
{
this->ComputeIndexToPhysicalPointMatrices();
}
}
//----------------------------------------------------------------------------
template<unsigned int VImageDimension>
void
ImageBase<VImageDimension>
::ComputeIndexToPhysicalPointMatrices()
{
DirectionType scale;
for (unsigned int i=0; i < VImageDimension; i++)
{
if (this->m_Spacing[i] == 0.0)
{
itkExceptionMacro("A spacing of 0 is not allowed: Spacing is " << this->m_Spacing);
}
scale[i][i] = this->m_Spacing[i];
}
if (vnl_determinant(this->m_Direction.GetVnlMatrix()) == 0.0)
{
itkExceptionMacro(<< "Bad direction, determinant is 0. Direction is " << this->m_Direction);
}
this->m_IndexToPhysicalPoint = this->m_Direction * scale;
this->m_PhysicalPointToIndex = m_IndexToPhysicalPoint.GetInverse();
this->Modified();
}
//----------------------------------------------------------------------------
template<unsigned int VImageDimension>
void
ImageBase<VImageDimension>
::ComputeOffsetTable()
{
// vxl_uint_64 num=1;
OffsetValueType num=1;
const SizeType& bufferSize = this->GetBufferedRegion().GetSize();
// m_OffsetTable[0] = (OffsetValueType)num;
m_OffsetTable[0] = num;
for (unsigned int i=0; i < VImageDimension; i++)
{
num *= bufferSize[i];
// m_OffsetTable[i+1] = (OffsetValueType)num;
m_OffsetTable[i+1] = num;
}
// if( num > NumericTraits<SizeValueType>::max() )
// {
// itkExceptionMacro(<< "Requested number of pixels (" << num
// << ") is greater than the largest possible number of pixels (" << NumericTraits<SizeValueType>::max() << ").");
// }
}
//----------------------------------------------------------------------------
template<unsigned int VImageDimension>
void
ImageBase<VImageDimension>
::UpdateOutputInformation()
{
if( this->GetSource() )
{
this->GetSource()->UpdateOutputInformation();
}
else
{
// If we don't have a source, we should set our Image to span our
// buffer (by setting our LargestPossibleRegion to equal our
// BufferedRegion). However, if the buffer is empty, we leave the
// LargestPossibleRegion at its prior value. This allows InPlace
// filters to overwrite their inputs safely (taking ownership of
// the pixel buffers), yet respond to subsequent requests for
// information.
if( this->GetBufferedRegion().GetNumberOfPixels() > 0)
{
this->SetLargestPossibleRegion( this->GetBufferedRegion() );
}
}
// Now we should know what our largest possible region is. If our
// requested region was not set yet, (or has been set to something
// invalid - with no data in it ) then set it to the largest possible
// region.
if ( this->GetRequestedRegion().GetNumberOfPixels() == 0)
{
this->SetRequestedRegionToLargestPossibleRegion();
}
}
template<unsigned int VImageDimension>
void
ImageBase<VImageDimension>
::UpdateOutputData()
{
// If the requested region does not contain any pixels then there is
// no reason to Update the output data. This is needed so that
// filters don't need to update all inputs. This occours in
// ImageBase as oppose to DataObject, but cause this statement
// requires the specific GetNumberOfPixels methods ( as oppose to a
// generic Region::IsEmpty method ).
//
// Also note, the check of the largest possible region is needed so
// that an exception will be thrown in the process object when no
// input has been set. ( This part of the statement could be removed
// if this check happened earlier in the pipeline )
if( this->GetRequestedRegion().GetNumberOfPixels() > 0
|| this->GetLargestPossibleRegion().GetNumberOfPixels() == 0 )
{
this->Superclass::UpdateOutputData();
}
// if ITK_LEGACY_SILENT or ITK_LEGACY_REMOVE is enabled then we don't
// print the waring message
#if !defined(ITK_LEGACY_SILENT) && !defined(ITK_LEGACY_REMOVE)
else
{
// Let us try to give a warning of this change in behavior.
itkWarningMacro(<<"Not executing UpdateOutputData due to zero pixel condition RequestedRegion:"
<< this->GetRequestedRegion() << " BufferedRegion: " << this->GetBufferedRegion());
}
#endif // !ITK_LEGACY_SILENT && !ITK_LEGACY_REMOVE
}
//----------------------------------------------------------------------------
template<unsigned int VImageDimension>
void
ImageBase<VImageDimension>
::SetRequestedRegionToLargestPossibleRegion()
{
this->SetRequestedRegion( this->GetLargestPossibleRegion() );
}
//----------------------------------------------------------------------------
template<unsigned int VImageDimension>
void
ImageBase<VImageDimension>
::CopyInformation(const DataObject *data)
{
// Standard call to the superclass' method
Superclass::CopyInformation(data);
if (data)
{
// Attempt to cast data to an ImageBase
const ImageBase<VImageDimension> *imgData;
try
{
imgData = dynamic_cast<const ImageBase<VImageDimension>*>(data);
}
catch( ... )
{
return;
}
if( imgData )
{
// Copy the meta data for this data type
this->SetLargestPossibleRegion( imgData->GetLargestPossibleRegion() );
this->SetSpacing( imgData->GetSpacing() );
this->SetOrigin( imgData->GetOrigin() );
this->SetDirection(imgData->GetDirection() );
this->SetNumberOfComponentsPerPixel(
imgData->GetNumberOfComponentsPerPixel() );
}
else
{
// pointer could not be cast back down
itkExceptionMacro( << "itk::ImageBase::CopyInformation() cannot cast "
<< typeid(data).name() << " to "
<< typeid(const ImageBase*).name() );
}
}
}
//----------------------------------------------------------------------------
template<unsigned int VImageDimension>
void
ImageBase<VImageDimension>
::Graft(const DataObject *data)
{
typedef ImageBase<VImageDimension> ImageBaseType;
const ImageBaseType * image;
try
{
image = dynamic_cast< const ImageBaseType * >( data );
}
catch( ... )
{
return;
}
if( !image )
{
return;
}
// Copy the meta-information
this->CopyInformation( image );
// Copy the remaining region information. Subclasses are
// responsible for copying the pixel container.
this->SetBufferedRegion( image->GetBufferedRegion() );
this->SetRequestedRegion( image->GetRequestedRegion() );
}
//----------------------------------------------------------------------------
template<unsigned int VImageDimension>
bool
ImageBase<VImageDimension>
::RequestedRegionIsOutsideOfTheBufferedRegion()
{
unsigned int i;
const IndexType &requestedRegionIndex = this->GetRequestedRegion().GetIndex();
const IndexType &bufferedRegionIndex = this->GetBufferedRegion().GetIndex();
const SizeType& requestedRegionSize = this->GetRequestedRegion().GetSize();
const SizeType& bufferedRegionSize = this->GetBufferedRegion().GetSize();
for (i=0; i< VImageDimension; i++)
{
if ( (requestedRegionIndex[i] < bufferedRegionIndex[i]) ||
((requestedRegionIndex[i] + static_cast<OffsetValueType>(requestedRegionSize[i]))
> (bufferedRegionIndex[i] + static_cast<OffsetValueType>(bufferedRegionSize[i]))) )
{
return true;
}
}
return false;
}
//----------------------------------------------------------------------------
template<unsigned int VImageDimension>
bool
ImageBase<VImageDimension>
::VerifyRequestedRegion()
{
bool retval = true;
unsigned int i;
// Is the requested region within the LargestPossibleRegion?
// Note that the test is indeed against the largest possible region
// rather than the buffered region; see DataObject::VerifyRequestedRegion.
const IndexType &requestedRegionIndex = this->GetRequestedRegion().GetIndex();
const IndexType &largestPossibleRegionIndex
= this->GetLargestPossibleRegion().GetIndex();
const SizeType& requestedRegionSize = this->GetRequestedRegion().GetSize();
const SizeType& largestPossibleRegionSize
= this->GetLargestPossibleRegion().GetSize();
for (i=0; i< VImageDimension; i++)
{
if ( (requestedRegionIndex[i] < largestPossibleRegionIndex[i]) ||
((requestedRegionIndex[i] + static_cast<long>(requestedRegionSize[i]))
> (largestPossibleRegionIndex[i]+static_cast<long>(largestPossibleRegionSize[i]))))
{
retval = false;
}
}
return retval;
}
//----------------------------------------------------------------------------
template<unsigned int VImageDimension>
void
ImageBase<VImageDimension>
::SetBufferedRegion(const RegionType ®ion)
{
if (m_BufferedRegion != region)
{
m_BufferedRegion = region;
this->ComputeOffsetTable();
this->Modified();
}
}
//----------------------------------------------------------------------------
template<unsigned int VImageDimension>
void
ImageBase<VImageDimension>
::InitializeBufferedRegion(void)
{
//
// We don't modify ourselves because the "ReleaseData" methods depend upon
// no modification when initialized.
//
// Otherwise BUG: 8490 will reoccur
m_BufferedRegion = RegionType();
this->ComputeOffsetTable();
}
//----------------------------------------------------------------------------
template<unsigned int VImageDimension>
void
ImageBase<VImageDimension>
::SetRequestedRegion(const RegionType ®ion)
{
if (m_RequestedRegion != region)
{
m_RequestedRegion = region;
}
}
//----------------------------------------------------------------------------
template<unsigned int VImageDimension>
void
ImageBase<VImageDimension>
::SetRequestedRegion(DataObject *data)
{
ImageBase *imgData;
imgData = dynamic_cast<ImageBase*>(data);
if (imgData)
{
// only copy the RequestedRegion if the parameter object is an image
this->SetRequestedRegion( imgData->GetRequestedRegion() );
}
}
//----------------------------------------------------------------------------
template<unsigned int VImageDimension>
void
ImageBase<VImageDimension>
::SetLargestPossibleRegion(const RegionType ®ion)
{
if (m_LargestPossibleRegion != region)
{
m_LargestPossibleRegion = region;
this->Modified();
}
}
//----------------------------------------------------------------------------
template<unsigned int VImageDimension>
unsigned int
ImageBase<VImageDimension>
::GetNumberOfComponentsPerPixel() const
{
// Returns the number of components in the image. Note that for most images
// this is 1. Even for Image< RGBPixel< T >, 3 >.
// This is > 1 only for time-series images such as itk::VectorImage.
return 1;
}
//----------------------------------------------------------------------------
template<unsigned int VImageDimension>
void
ImageBase<VImageDimension>
::SetNumberOfComponentsPerPixel( unsigned int )
{ // does nothing (always 1 )
}
/**
*
*/
template<unsigned int VImageDimension>
void
ImageBase<VImageDimension>
::PrintSelf(std::ostream& os, Indent indent) const
{
Superclass::PrintSelf(os,indent);
os << indent << "LargestPossibleRegion: " << std::endl;
this->GetLargestPossibleRegion().PrintSelf(os, indent.GetNextIndent());
os << indent << "BufferedRegion: " << std::endl;
this->GetBufferedRegion().PrintSelf(os, indent.GetNextIndent());
os << indent << "RequestedRegion: " << std::endl;
this->GetRequestedRegion().PrintSelf(os, indent.GetNextIndent());
os << indent << "Spacing: " << this->GetSpacing() << std::endl;
os << indent << "Origin: " << this->GetOrigin() << std::endl;\
os << indent << "Direction: " << std::endl << this->GetDirection() << std::endl;
os << indent << "IndexToPointMatrix: " << std::endl;
os << indent << this->m_IndexToPhysicalPoint << std::endl;
os << indent << "PointToIndexMatrix: " << std::endl;
os << indent << this->m_PhysicalPointToIndex << std::endl;
}
} // end namespace itk
#endif
|