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
|
/*=========================================================================
Program: Insight Segmentation & Registration Toolkit
Module: $RCSfile: itkImageToParametricSpaceFilter.txx,v $
Language: C++
Date: $Date: 2005-06-04 19:33:30 $
Version: $Revision: 1.15 $
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 _itkImageToParametricSpaceFilter_txx
#define _itkImageToParametricSpaceFilter_txx
#include "itkImageToParametricSpaceFilter.h"
#include "itkNumericTraits.h"
#include "itkImageIterator.h"
#include "itkProgressReporter.h"
namespace itk
{
/**
*
*/
template <class TInputImage, class TOutputMesh>
ImageToParametricSpaceFilter<TInputImage,TOutputMesh>
::ImageToParametricSpaceFilter()
{
// Modify superclass default values, can be overridden by subclasses
this->SetNumberOfRequiredInputs(PointDimension);
m_ComputeIndices = true;
}
/**
*
*/
template <class TInputImage, class TOutputMesh>
ImageToParametricSpaceFilter<TInputImage,TOutputMesh>
::~ImageToParametricSpaceFilter()
{
}
/**
*
*/
template <class TInputImage, class TOutputMesh>
void
ImageToParametricSpaceFilter<TInputImage,TOutputMesh>
::PrintSelf(std::ostream& os, Indent indent) const
{
Superclass::PrintSelf(os,indent);
os << indent << "ComputeIndices: " << m_ComputeIndices << std::endl;
}
/**
*
*/
template <class TInputImage, class TOutputMesh>
void
ImageToParametricSpaceFilter<TInputImage,TOutputMesh>
::GenerateOutputInformation()
{
OutputMeshPointer mesh = this->GetOutput();
PointsContainerPointer points = mesh->GetPoints();
PointDataContainerPointer pointData;
if( mesh->GetPointData() )
{
pointData = mesh->GetPointData();
}
else
{ // Create
pointData = PointDataContainer::New();
}
InputImageConstPointer image = this->GetInput(0);
const unsigned long numberOfPixels =
image->GetRequestedRegion().GetNumberOfPixels();
points->Reserve( numberOfPixels );
pointData->Reserve( numberOfPixels );
mesh->SetPointData( pointData.GetPointer() );
}
/**
*
*/
template <class TInputImage, class TOutputMesh>
void
ImageToParametricSpaceFilter<TInputImage,TOutputMesh>
::GenerateData(void)
{
OutputMeshPointer mesh = this->GetOutput();
PointsContainerPointer points = mesh->GetPoints();
PointDataContainerPointer pointData = PointDataContainer::New();
InputImageConstPointer image = this->GetInput(0);
InputImageRegionType region = image->GetRequestedRegion();
unsigned long numberOfPixels = region.GetNumberOfPixels();
points->Reserve( numberOfPixels );
pointData->Reserve( numberOfPixels );
mesh->SetPointData( pointData.GetPointer() );
mesh->SetBufferedRegion( mesh->GetRequestedRegion() );
// support progress methods/callbacks
ProgressReporter progress(this, 0, numberOfPixels);
for( unsigned int component=0; component<PointDimension; component++)
{
image = this->GetInput( component );
InputImageIterator it( image, image->GetRequestedRegion() );
PointsContainerIterator point = points->Begin();
it.GoToBegin();
while( !it.IsAtEnd() )
{
(point.Value())[ component ] = it.Get();
it.GetIndex();
++it;
++point;
progress.CompletedPixel();
}
}
if( m_ComputeIndices )
{
PointDataContainerIterator data = pointData->Begin();
image = this->GetInput( 0 );
InputImageIterator it( image, image->GetRequestedRegion() );
it.GoToBegin();
while( !it.IsAtEnd() )
{
// The data at each point is the index
// of the corresponding pixel on the image.
typedef typename OutputMeshType::PixelType MeshPixelType;
MeshPixelType point;
image->TransformIndexToPhysicalPoint( it.GetIndex(), point );
(data.Value()) = point;
++it;
++data;
}
}
}
} // end namespace itk
#endif
|