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
|
/*=========================================================================
Program: Insight Segmentation & Registration Toolkit
Module: $RCSfile: itkPointSetToImageFilter.txx,v $
Language: C++
Date: $Date: 2005-07-27 15:21:11 $
Version: $Revision: 1.11 $
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 _itkPointSetToImageFilter_txx
#define _itkPointSetToImageFilter_txx
#include "itkPointSetToImageFilter.h"
#include <itkImageRegionIteratorWithIndex.h>
#include <itkNumericTraits.h>
namespace itk
{
/** Constructor */
template <class TInputPointSet, class TOutputImage>
PointSetToImageFilter<TInputPointSet,TOutputImage>
::PointSetToImageFilter()
{
this->SetNumberOfRequiredInputs(1);
m_Size.Fill(0);
m_Spacing.Fill(1.0);
m_Origin.Fill(0.0);
m_InsideValue = 1;
m_OutsideValue = 0;
}
/** Destructor */
template <class TInputPointSet, class TOutputImage>
PointSetToImageFilter<TInputPointSet,TOutputImage>
::~PointSetToImageFilter()
{
}
/** Set the Input PointSet */
template <class TInputPointSet, class TOutputImage>
void
PointSetToImageFilter<TInputPointSet,TOutputImage>
::SetInput(const InputPointSetType *input)
{
// Process object is not const-correct so the const_cast is required here
this->ProcessObject::SetNthInput(0,
const_cast< InputPointSetType * >( input ) );
}
/** Connect one of the operands */
template <class TInputPointSet, class TOutputImage>
void
PointSetToImageFilter<TInputPointSet,TOutputImage>
::SetInput( unsigned int index, const TInputPointSet * pointset )
{
// Process object is not const-correct so the const_cast is required here
this->ProcessObject::SetNthInput(index,
const_cast< TInputPointSet *>( pointset ) );
}
/** Get the input point-set */
template <class TInputPointSet, class TOutputImage>
const typename PointSetToImageFilter<TInputPointSet,TOutputImage>::InputPointSetType *
PointSetToImageFilter<TInputPointSet,TOutputImage>
::GetInput(void)
{
if (this->GetNumberOfInputs() < 1)
{
return 0;
}
return static_cast<const TInputPointSet * >
(this->ProcessObject::GetInput(0) );
}
/** Get the input point-set */
template <class TInputPointSet, class TOutputImage>
const typename PointSetToImageFilter<TInputPointSet,TOutputImage>::InputPointSetType *
PointSetToImageFilter<TInputPointSet,TOutputImage>
::GetInput(unsigned int idx)
{
return static_cast< const TInputPointSet * >
(this->ProcessObject::GetInput(idx));
}
template <class TInputPointSet, class TOutputImage>
void
PointSetToImageFilter<TInputPointSet,TOutputImage>
::SetSpacing(const float* v)
{
Vector<float, OutputImageDimension> vf(v);
SpacingType spacing;
spacing.CastFrom(vf);
this->SetSpacing(spacing);
}
template <class TInputPointSet, class TOutputImage>
void
PointSetToImageFilter<TInputPointSet,TOutputImage>
::SetSpacing(const double* v)
{
SpacingType spacing(v);
this->SetSpacing(spacing);
}
template <class TInputPointSet, class TOutputImage>
void
PointSetToImageFilter<TInputPointSet,TOutputImage>
::SetOrigin(const float* v)
{
Point<float,OutputImageDimension> pf(v);
PointType origin;
origin.CastFrom(pf);
this->SetOrigin(origin);
}
template <class TInputPointSet, class TOutputImage>
void
PointSetToImageFilter<TInputPointSet,TOutputImage>
::SetOrigin(const double* v)
{
PointType origin(v);
this->SetOrigin(origin);
}
//----------------------------------------------------------------------------
/** Update */
template <class TInputPointSet, class TOutputImage>
void
PointSetToImageFilter<TInputPointSet,TOutputImage>
::GenerateData(void)
{
unsigned int i;
itkDebugMacro(<< "PointSetToImageFilter::Update() called");
// Get the input and output pointers
const InputPointSetType * InputPointSet = this->GetInput();
OutputImagePointer OutputImage = this->GetOutput();
// Generate the image
double origin[InputPointSetDimension];
SizeType size;
typedef typename InputPointSetType::BoundingBoxType BoundingBoxType;
const BoundingBoxType * bb = InputPointSet->GetBoundingBox();
for(i=0;i<InputPointSetDimension;i++)
{
size[i] = (unsigned long)(bb->GetBounds()[2*i+1]-bb->GetBounds()[2*i]);
origin[i]= 0; //bb->GetBounds()[2*i];
}
typename OutputImageType::RegionType region;
// If the size of the output has been explicitly specified, the filter
// will set the output size to the explicit size, otherwise the size from the spatial
// PointSet's bounding box will be used as default.
bool specified = false;
for (i = 0; i < OutputImageDimension; i++)
{
if (m_Size[i] != 0)
{
specified = true;
break;
}
}
if (specified)
{
region.SetSize( m_Size );
}
else
{
region.SetSize( size );
}
OutputImage->SetRegions( region);
// If the spacing has been explicitly specified, the filter
// will set the output spacing to that explicit spacing, otherwise the spacing from
// the point-set is used as default.
specified = false;
for (i = 0; i < OutputImageDimension; i++)
{
if (m_Spacing[i] != 0)
{
specified = true;
break;
}
}
if (specified)
{
OutputImage->SetSpacing(this->m_Spacing); // set spacing
}
specified = false;
for (i = 0; i < OutputImageDimension; i++)
{
if (m_Origin[i] != 0)
{
specified = true;
break;
}
}
if (specified)
{
for (i = 0; i < OutputImageDimension; i++)
{
origin[i] = m_Origin[i]; // set origin
}
}
OutputImage->SetOrigin(origin); // and origin
OutputImage->Allocate(); // allocate the image
OutputImage->FillBuffer(m_OutsideValue);
typedef typename InputPointSetType::PointsContainer::ConstIterator PointIterator;
PointIterator pointItr = InputPointSet->GetPoints()->Begin();
PointIterator pointEnd = InputPointSet->GetPoints()->End();
typename OutputImageType::IndexType index;
while( pointItr != pointEnd )
{
if(OutputImage->TransformPhysicalPointToIndex(pointItr.Value(),index))
{
OutputImage->SetPixel(index,m_InsideValue);
}
pointItr++;
}
itkDebugMacro(<< "PointSetToImageFilter::Update() finished");
} // end update function
template<class TInputPointSet, class TOutputImage>
void
PointSetToImageFilter<TInputPointSet,TOutputImage>
::PrintSelf(std::ostream& os, Indent indent) const
{
Superclass::PrintSelf(os, indent);
os << indent << "Size : " << m_Size << std::endl;
os << indent << "Origin: " << m_Origin << std::endl;
os << indent << "Spacing: " << m_Spacing << std::endl;
os << indent << "Inside Value : "
<< static_cast<typename NumericTraits<ValueType>::PrintType>(m_InsideValue)
<< std::endl;
os << indent << "Outside Value : "
<< static_cast<typename NumericTraits<ValueType>::PrintType>(m_OutsideValue)
<< std::endl;
}
} // end namespace itk
#endif
|