Skip to content

Commit a68d857

Browse files
committed
BUG: Use proper GenerateOutputInformation method to set vector length
The GernerateOutputInformation method is the correct method to overrride when specify image information and meta-data. Remove extraneous setting of the image's number of components. The filter will now throw an exception if the improper fixed number of components is set for the output image type.
1 parent fee73ed commit a68d857

File tree

2 files changed

+13
-18
lines changed

2 files changed

+13
-18
lines changed

include/itkCoocurrenceTextureFeaturesImageFilter.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ class ITK_TEMPLATE_EXPORT CoocurrenceTextureFeaturesImageFilter:public ImageToIm
227227
virtual void AfterThreadedGenerateData() ITK_OVERRIDE;
228228
virtual void ThreadedGenerateData(const OutputRegionType & outputRegionForThread,
229229
ThreadIdType threadId) ITK_OVERRIDE;
230-
virtual void UpdateOutputInformation() ITK_OVERRIDE;
230+
virtual void GenerateOutputInformation() ITK_OVERRIDE;
231231

232232
private:
233233
typename DigitalisedImageType::Pointer m_DigitalisedInputImageg;

include/itkCoocurrenceTextureFeaturesImageFilter.hxx

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -103,15 +103,6 @@ CoocurrenceTextureFeaturesImageFilter<TInputImage, TOutputImage>
103103

104104
functorF->Update();
105105
m_DigitalisedInputImageg = functorF->GetOutput();
106-
107-
// Support VectorImages by setting number of components on output.
108-
OutputImageType * outputPtr = this->GetOutput();
109-
if ( strcmp(outputPtr->GetNameOfClass(), "VectorImage") == 0 )
110-
{
111-
typedef typename TOutputImage::AccessorFunctorType AccessorFunctorType;
112-
AccessorFunctorType::SetVectorLength( outputPtr, 8 );
113-
}
114-
outputPtr->Allocate();
115106
}
116107

117108
template<typename TInputImage, typename TOutputImage>
@@ -249,16 +240,20 @@ CoocurrenceTextureFeaturesImageFilter<TInputImage, TOutputImage>
249240
template<typename TInputImage, typename TOutputImage>
250241
void
251242
CoocurrenceTextureFeaturesImageFilter<TInputImage, TOutputImage>
252-
::UpdateOutputInformation()
243+
::GenerateOutputInformation()
253244
{
254245
// Call superclass's version
255-
Superclass::UpdateOutputInformation();
256-
257-
if ( strcmp(this->GetOutput()->GetNameOfClass(), "VectorImage") == 0 )
258-
{
259-
typedef typename TOutputImage::AccessorFunctorType AccessorFunctorType;
260-
AccessorFunctorType::SetVectorLength( this->GetOutput(), 8 );
261-
}
246+
Superclass::GenerateOutputInformation();
247+
248+
OutputImageType* output = this->GetOutput();
249+
// If the output image type is a VectorImage the number of
250+
// components will be properly sized if before allocation, if the
251+
// output is a fixed width vector and the wrong number of
252+
// components, then an exception will be thrown.
253+
if ( output->GetNumberOfComponentsPerPixel() != 8 )
254+
{
255+
output->SetNumberOfComponentsPerPixel( 8 );
256+
}
262257
}
263258

264259
template<typename TInputImage, typename TOutputImage>

0 commit comments

Comments
 (0)