/usr/include/InsightToolkit/Review/itkGridImageSource.txx is in libinsighttoolkit3-dev 3.20.1+git20120521-6build1.
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 | /*=========================================================================
Program: Insight Segmentation & Registration Toolkit
Module: itkGridImageSource.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.
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 __itkGridImageSource_txx
#define __itkGridImageSource_txx
#include "itkGaussianKernelFunction.h"
#include "itkGridImageSource.h"
#include "itkImageLinearIteratorWithIndex.h"
#include "itkImageRegionIteratorWithIndex.h"
#include "itkProgressReporter.h"
namespace itk
{
template <class TOutputImage>
GridImageSource<TOutputImage>
::GridImageSource()
{
this->m_Size.Fill( 64 );
this->m_Spacing.Fill( 1.0 );
this->m_Origin.Fill( 0.0 );
this->m_Direction.SetIdentity();
this->m_Sigma.Fill( 0.5 );
this->m_GridSpacing.Fill( 4.0 );
this->m_GridOffset.Fill( 0.0 );
this->m_WhichDimensions.Fill( true );
this->m_Scale = 255.0;
this->m_KernelFunction = dynamic_cast<KernelFunction*>(
GaussianKernelFunction::New().GetPointer() );
}
template <typename TOutputImage>
void
GridImageSource<TOutputImage>
::BeforeThreadedGenerateData()
{
typename ImageType::Pointer output = this->GetOutput( 0 );
this->m_PixelArrays = PixelArrayContainerType::New();
m_PixelArrays->Initialize();
for ( unsigned int i = 0; i < ImageDimension; i++ )
{
if ( this->m_GridOffset[i] > this->m_GridSpacing[i] )
{
this->m_GridOffset[i] = this->m_GridSpacing[i];
}
PixelArrayType pixels = m_PixelArrays->CreateElementAt( i );
pixels.set_size( this->m_Size[i] );
pixels.fill( 1 );
if ( this->m_WhichDimensions[i] )
{
ImageLinearIteratorWithIndex<ImageType> It( output, output->GetRequestedRegion() );
It.SetDirection( i );
/** Add two extra functions in the front and one in the back to ensure coverage */
unsigned int numberOfGaussians = Math::Ceil<unsigned int>(
this->m_Size[i]*this->m_Spacing[i]/this->m_GridSpacing[i] ) + 4u;
for ( It.GoToBegin(); !It.IsAtEndOfLine(); ++It )
{
typename ImageType::IndexType index = It.GetIndex();
typename ImageType::PointType point;
output->TransformIndexToPhysicalPoint( index, point );
RealType val = 0;
for ( unsigned int j = 0; j < numberOfGaussians; j++ )
{
RealType num = point[i] - static_cast<RealType>( j-2 )*this->m_GridSpacing[i]
- this->m_Origin[i] - this->m_GridOffset[i];
val += this->m_KernelFunction->Evaluate( num/this->m_Sigma[i] );
}
pixels[index[i]] = val;
}
pixels = 1.0 - pixels/pixels.max_value();
}
this->m_PixelArrays->SetElement( i, pixels );
}
}
template <typename TOutputImage>
void
GridImageSource<TOutputImage>
::ThreadedGenerateData( const ImageRegionType& outputRegionForThread, int threadId )
{
// Support progress methods/callbacks
ProgressReporter progress( this, threadId, outputRegionForThread.GetNumberOfPixels() );
typename ImageType::Pointer output = this->GetOutput( 0 );
ImageRegionIteratorWithIndex<ImageType> It( output, outputRegionForThread );
for ( It.GoToBegin(); !It.IsAtEnd(); ++It )
{
RealType val = 1.0;
typename ImageType::IndexType index = It.GetIndex();
for ( unsigned int i = 0; i < ImageDimension; i++ )
{
val *= this->m_PixelArrays->GetElement( i )[index[i]];
}
It.Set( this->m_Scale * val );
progress.CompletedPixel();
}
}
template <class TOutputImage>
void
GridImageSource<TOutputImage>
::PrintSelf(std::ostream& os, Indent indent) const
{
Superclass::PrintSelf(os,indent);
os << indent << "Output image information: " << std::endl;
os << indent << " Size = " << this->GetSize() << std::endl;
os << indent << " Spacing = " << this->GetSpacing() << std::endl;
os << indent << " Origin = " << this->GetOrigin() << std::endl;
os << indent << " Direction = " << this->GetDirection() << std::endl;
os << indent << " Scale = " << this->GetScale() << std::endl;
os << indent << "Grid information: " << std::endl;
os << indent << " WhichDimensions = " << this->GetWhichDimensions() << std::endl;
os << indent << " Kernel = " << this->GetKernelFunction() << std::endl;
os << indent << " Sigma = " << this->GetSigma() << std::endl;
os << indent << " Grid spacing = " << this->GetGridSpacing() << std::endl;
os << indent << " Grid offset = " << this->GetGridOffset() << std::endl;
}
//----------------------------------------------------------------------------
template <typename TOutputImage>
void
GridImageSource<TOutputImage>
::GenerateOutputInformation()
{
ImageType *output;
output = this->GetOutput( 0 );
typename ImageType::IndexType index;
index.Fill( 0 );
typename ImageType::RegionType largestPossibleRegion;
largestPossibleRegion.SetSize( this->m_Size );
largestPossibleRegion.SetIndex( index );
output->SetLargestPossibleRegion( largestPossibleRegion );
output->SetSpacing( this->m_Spacing );
output->SetOrigin( this->m_Origin );
output->SetDirection( this->m_Direction );
}
} // end namespace itk
#endif
|