[Insight-developers] Methods for comparing meta-data with tolerance

Bradley Lowekamp blowekamp at mail.nih.gov
Tue Jun 21 17:03:09 EDT 2011


I need to add tolerant comparison for origin, spacing and direction cosines in a couple places now. I would like to implement these methods in a central location to avoid code duplications.

I just got bit by the following code I wrote in MetaImageIO:

for ( unsigned int i = 0; i < this->GetNumberOfDimensions(); ++i )
        {
        // 4)size/origin/spacing
        if ( headerImageIOReader->GetDimensions(i) != this->GetDimensions(i)
             || headerImageIOReader->GetSpacing(i) != this->GetSpacing(i)
             || headerImageIOReader->GetOrigin(i) != this->GetOrigin(i) )
          {
          errorMessage = "Size, spacing or origin does not match in file: " + m_FileName;
          break;
          }
        // 5)direction cosines
        if ( headerImageIOReader->GetDirection(i) != this->GetDirection(i) )
          {
          errorMessage = "Direction cosines does not match in file: " + m_FileName;
          break;
          }
        }

It's in other IO classes, and there is a proposal to add a similar compare to the ImageToImageFilter.

I like the following methods for tolerant comparison:

abs( f1-f2 ) > numeric_limits<double|float>::epsilon()*(1u<<BITS )*max( f1, 1.0)

Where would be a good location to put such methods for number, points, vectors, and direction matrix?

Brad


========================================================
Bradley Lowekamp  
Lockheed Martin Contractor for
Office of High Performance Computing and Communications
National Library of Medicine 
blowekamp at mail.nih.gov

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/mailman/private/insight-developers/attachments/20110621/a7a90f72/attachment.htm>


More information about the Insight-developers mailing list