[Insight-developers] Removing typeids, removing block-copied code, UseVectorBasedHistogram
kent williams
norman-k-williams at uiowa.edu
Fri Nov 5 10:16:55 EDT 2010
This has to do with bug report
http://public.kitware.com/Bug/view.php?id=7006
I did a find/grep for typeid and eliminated the ones in I/O statements.
One of the things I found was this member function UseVectorBasedHistogram,
which was in 4 different places:
./Code/Algorithms/itkAnchorErodeDilateLine.h: bool
UseVectorBasedHistogram()
./Code/Algorithms/itkAnchorOpenCloseLine.h: bool UseVectorBasedHistogram()
./Code/Review/itkMaskedRankImageFilter.h: bool UseVectorBasedHistogram()
./Code/Review/itkRankImageFilter.h: bool UseVectorBasedHistogram()
This was implemented exactly the same in all classes, but the
RankImageFilter classes returned true only for one-byte types:
bool UseVectorBasedHistogram()
{
// bool, short and char are acceptable for vector based algorithm: they
do
// not require
// too much memory. Other types are not usable with that algorithm
return typeid( InputPixelType ) == typeid( unsigned char )
|| typeid( InputPixelType ) == typeid( signed char )
|| typeid(InputPixelType) == typeid(unsigned short)
|| typeid(InputPixelType) == typeid(signed short)
|| typeid( InputPixelType ) == typeid( bool );
}
I replaced these functions with this template/overloaded function version:
template <class PixelType>
static bool UseVectorBasedHistogram(PixelType &) { return false; }
static bool UseVectorBasedHistogram(unsigned char &) { return true; }
static bool UseVectorBasedHistogram(signed char &) { return true; }
static bool UseVectorBasedHistogram(unsigned short &) { return true; }
static bool UseVectorBasedHistogram(signed short &) { return true; }
static bool UseVectorBasedHistogram(bool &) { return true; }
bool UseVectorBasedHistogram()
{
InputImagePixelType p;
return Self::UseVectorBasedHistogram(p);
}
But there are two problems with this it duplicates identical code in
different files, and I don¹t believe I¹ve done an optimal implementation.
In the first matter, I believe there should be a common class to encapsulate
this information. I¹m not sure what to call such a class or where to put it.
In the second matter, there should be a way with specialization where it¹s
boiled down to a template class w/partial specialization that boils it down
to a boolean constant with no member function necessary. I¹m just not
getting my head around how to do this this morning.
Advice wanted. Thanks!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/mailman/private/insight-developers/attachments/20101105/f3a00838/attachment-0001.htm>
More information about the Insight-developers
mailing list