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
|
/*=========================================================================
Program: Insight Segmentation & Registration Toolkit
Module: itkPipelineMonitorImageFilter.h
Language: C++
Date: $Date$
Version: $Revision$
Copyright (c) 2002 Insight 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.
=========================================================================*/
#include "itkInPlaceImageFilter.h"
namespace itk {
// this class is usefull for verifying streaming and requested regions
template <class TImageType>
class PipelineMonitorImageFilter :
public InPlaceImageFilter< TImageType, TImageType>
{
public:
typedef PipelineMonitorImageFilter Self;
typedef InPlaceImageFilter<TImageType, TImageType> Superclass;
typedef SmartPointer<Self> Pointer;
typedef SmartPointer<const Self> ConstPointer;
typedef typename TImageType::PointType PointType;
typedef typename TImageType::DirectionType DirectionType;
typedef typename TImageType::SpacingType SpacingType;
typedef typename TImageType::Pointer InputImagePointer;
typedef typename TImageType::ConstPointer InputImageConstPointer;
typedef typename Superclass::InputImageRegionType ImageRegionType;
typedef std::vector<typename TImageType::RegionType> RegionVectorType;
/** Method for creation through the object factory. */
itkNewMacro(Self);
/** Run-time type information (and related methods). */
itkTypeMacro(PipelineMonitorImageFilter,ImageToImageFilter);
bool VerifyDownStreamFilterExecutedPropagation(void)
{
bool ret = true;
// we expect that the propagation is not going to be called
// extra times
if (m_OutputRequestedRegions.size() != this->GetNumberOfUpdates() ||
m_InputRequestedRegions.size() != this->GetNumberOfUpdates())
{
itkWarningMacro(<<"Down stream filter didn't execute PropagateRequestedRegion well");
ret = false;
}
return ret;
}
bool VerifyInputFilterExecutedStreaming(int expectedNumber)
{
if (expectedNumber == 0)
{
return true;
}
else if (expectedNumber < 0 && static_cast<unsigned int>(- expectedNumber) <= this->GetNumberOfUpdates())
{
return true;
}
else if ( expectedNumber == static_cast<int>(this->GetNumberOfUpdates()) )
{
return true;
}
itkWarningMacro(<<"Streamed pipeline was executed " << this->GetNumberOfUpdates()
<< " times which was not the expected number " << expectedNumber
<< " of times.");
return false;
}
bool VerifyInputFilterMatchedUpdateOutputInformation(void)
{
InputImageConstPointer input = this->GetInput();
if (input->GetSpacing() != m_UpdatedOutputSpacing)
{
itkWarningMacro(<<"The input filter's Spacing does not match UpdateOutputInformation");
return false;
}
if (input->GetOrigin() != m_UpdatedOutputOrigin)
{
itkWarningMacro(<<"The input filter's Origin does not match UpdateOutputInformation");
return false;
}
if (input->GetDirection() != m_UpdatedOutputDirection)
{
itkWarningMacro(<<"The input filter's Direction does not match UpdateOutputInformation");
return false;
}
if(input->GetLargestPossibleRegion() != m_UpdatedOutputLargestPossibleRegion)
{
itkWarningMacro(<<"The input filter's LargestPossibleRegion does not match UpdateOutputInformation");
return false;
}
if(m_UpdatedBufferedRegions.size() && !m_UpdatedOutputLargestPossibleRegion.IsInside(m_UpdatedBufferedRegions.back()))
{
itkWarningMacro(<<"The input filter's BufferedRegion is not contained by LargestPossibleRegion");
return false;
}
return true;
}
bool VerifyInputFilterBufferedRequestedRegions(void)
{
// we expect that the input filter's output image's buffered
// region is going to match it's requested region
bool ret = true;
unsigned int i;
for (i = 0; i < m_UpdatedBufferedRegions.size(); ++i)
{
if (m_UpdatedBufferedRegions[i] != m_UpdatedRequestedRegions[i])
{
itkWarningMacro(<<"The input filter's updated buffered region was not the requested region");
ret = false;
}
}
return ret;
}
bool VerifyInputFilterMatchedRequestedRegions(void)
{
// we expect that the input filter's output image's buffered
// region is going to match it's requested region, which is going
// to match the requested region at the end of propagation
//
bool ret = true;
unsigned int i = m_UpdatedBufferedRegions.size();
unsigned int j = m_InputRequestedRegions.size();
while(i != 0 && j != 0)
{
if (m_UpdatedBufferedRegions[--i] != m_InputRequestedRegions[--j])
{
itkWarningMacro(<<"The input filter's updated buffer region was not the region we requested");
ret = false;
}
}
return ret;
}
bool VerifyInputFilterRequestedLargestRegion(void)
{
if (m_InputRequestedRegions.back() != m_UpdatedOutputLargestPossibleRegion)
{
itkWarningMacro(<<"The input filter didn't set it's output request to the largest region");
return false;
}
return true;
}
bool VerifyAllInputCanStream(int expectedNumber)
{
return VerifyInputFilterExecutedStreaming(expectedNumber) &&
VerifyDownStreamFilterExecutedPropagation() &&
VerifyInputFilterMatchedRequestedRegions() &&
VerifyInputFilterBufferedRequestedRegions() &&
VerifyInputFilterMatchedUpdateOutputInformation();
}
bool VerifyAllIputCanNotStream(void)
{
return VerifyDownStreamFilterExecutedPropagation() &&
VerifyInputFilterRequestedLargestRegion() &&
VerifyInputFilterBufferedRequestedRegions() &&
VerifyInputFilterMatchedUpdateOutputInformation();
}
bool VerifyAllNoUpdate(void)
{
return VerifyDownStreamFilterExecutedPropagation() &&
m_NumberOfUpdates == 0;
}
unsigned int GetNumberOfUpdates(void) const { return m_NumberOfUpdates; }
RegionVectorType GetOutputRequestedRegions(void) const {return m_OutputRequestedRegions;}
RegionVectorType GetInputRequestedRegions(void) const {return m_InputRequestedRegions;}
RegionVectorType GetUpdatedBufferedRegions(void) const {return m_UpdatedBufferedRegions; }
RegionVectorType GetUpdatedRequestedRegions(void) const {return m_UpdatedRequestedRegions; }
void ClearPipelineSavedInformation(void)
{
m_NumberOfUpdates = 0;
m_OutputRequestedRegions.clear();
m_InputRequestedRegions.clear();
m_UpdatedBufferedRegions.clear();
m_UpdatedRequestedRegions.clear();
m_UpdatedOutputOrigin.Fill(-1);
m_UpdatedOutputDirection.Fill(-1);
m_UpdatedOutputSpacing.Fill(-1);
++m_NumberOfClearPipeline;
}
virtual void GenerateOutputInformation(void)
{
ClearPipelineSavedInformation();
Superclass::GenerateOutputInformation();
InputImageConstPointer input = this->GetInput();
m_UpdatedOutputOrigin = input->GetOrigin();
m_UpdatedOutputDirection = input->GetDirection();
m_UpdatedOutputSpacing = input->GetSpacing();
m_UpdatedOutputLargestPossibleRegion = input->GetLargestPossibleRegion();
itkDebugMacro("GenerateOutputInformation called");
}
virtual void PropagateRequestedRegion(DataObject *output)
{
// call the superclass' implementation of this method
Superclass::PropagateRequestedRegion(output);
// record the regions after everything has executed
itkDebugMacro("After PropagateRequestedRegion: " << this->GetInput()->GetRequestedRegion());
this->m_InputRequestedRegions.push_back(this->GetInput()->GetRequestedRegion());
this->m_OutputRequestedRegions.push_back(this->GetOutput()->GetRequestedRegion());
}
virtual void EnlargeOutputRequestedRegion( DataObject *output)
{
// call the superclass' implementation of this method
Superclass::EnlargeOutputRequestedRegion(output);
itkDebugMacro("EnlargeOutputRequestRegion: " << this->GetOutput()->GetRequestedRegion());
}
virtual void GenerateInputRequestedRegion(void)
{
// call the superclass' implementation of this method
Superclass::GenerateInputRequestedRegion();
// this is not very interesting as it's always going to be the
// output requested region
itkDebugMacro("GenerateInputRequestRegion: " << this->GetInput()->GetRequestedRegion());
}
virtual void GenerateData(void)
{
// Get pointers to the input and output
InputImagePointer output = this->GetOutput();
InputImagePointer input =
const_cast< TImageType * >( this->GetInput());
// because this is in place filter this will acutall copy the
// pixel containers
this->AllocateOutputs();
itkDebugMacro("GenerateData Buffered: " << this->GetInput()->GetBufferedRegion() << " Requested:" << this->GetInput()->GetRequestedRegion());
m_UpdatedBufferedRegions.push_back(this->GetInput()->GetBufferedRegion());
m_UpdatedRequestedRegions.push_back(this->GetInput()->GetRequestedRegion());
++m_NumberOfUpdates;
}
protected:
PipelineMonitorImageFilter(void)
{
m_NumberOfClearPipeline = 0;
this->ClearPipelineSavedInformation();
}
~PipelineMonitorImageFilter()
{
}
void PrintSelf(std::ostream &os, Indent indent) const
{
Superclass::PrintSelf(os,indent);
os << indent << "m_NumberOfUpdates: " << m_NumberOfUpdates << std::endl;
os << indent << "m_NumberOfClearPipeline: " << m_NumberOfClearPipeline << std::endl;
os << indent << "m_OutputRequestedRegions:"<< std::endl;
for (typename RegionVectorType::const_iterator i = m_OutputRequestedRegions.begin(); i != m_OutputRequestedRegions.end(); ++i)
i->Print(os, indent.GetNextIndent());
os << indent << "m_InputRequestedRegions:"<< std::endl;
for (typename RegionVectorType::const_iterator i = m_InputRequestedRegions.begin(); i != m_InputRequestedRegions.end(); ++i)
i->Print(os, indent.GetNextIndent());
os << indent << "m_UpdatedBufferedRegions:"<< std::endl;
for (typename RegionVectorType::const_iterator i = m_UpdatedBufferedRegions.begin(); i != m_UpdatedBufferedRegions.end(); ++i)
i->Print(os, indent.GetNextIndent());
os << indent << "m_UpdatedRequestedRegions:"<< std::endl;
for (typename RegionVectorType::const_iterator i = m_UpdatedRequestedRegions.begin(); i != m_UpdatedRequestedRegions.end(); ++i)
i->Print(os, indent.GetNextIndent());
os << indent << "m_UpdatedOutputOrigin:" << std::endl;
os << indent.GetNextIndent() << m_UpdatedOutputOrigin << std::endl;
os << indent << "m_UpdatedOutputDirection:" << std::endl;
os << indent.GetNextIndent() << m_UpdatedOutputDirection << std::endl;
os << indent << "m_UpdatedOutputSpacing:" << std::endl;
os << indent.GetNextIndent() << m_UpdatedOutputSpacing << std::endl;
os << indent << "m_UpdatedOutputLargestPossibleRegion: " << std::endl;
m_UpdatedOutputLargestPossibleRegion.Print(os, indent.GetNextIndent());
}
private:
PipelineMonitorImageFilter(const PipelineMonitorImageFilter &); // not implemented
void operator=(const PipelineMonitorImageFilter &); // not implemented
unsigned int m_NumberOfUpdates;
unsigned int m_NumberOfClearPipeline;
RegionVectorType m_OutputRequestedRegions;
RegionVectorType m_InputRequestedRegions;
RegionVectorType m_UpdatedBufferedRegions;
RegionVectorType m_UpdatedRequestedRegions;
PointType m_UpdatedOutputOrigin;
DirectionType m_UpdatedOutputDirection;
SpacingType m_UpdatedOutputSpacing;
ImageRegionType m_UpdatedOutputLargestPossibleRegion;
};
}
|