[Insight-developers] question about preprocessor condition in itk::QuadEdgeMesh<>::AddFace method

Arnaud Gelas arnaudgelas at gmail.com
Tue Apr 17 03:59:36 EDT 2012


Hi Alex,

In the AddFace method of itk::QuadEdgeMesh, there is a preprocessor 
condition (#ifndef NDEBUG, see code below).
Is it correct to make these tests only when NDEBUG is undefined? Is it 
the other way around? or should it be tested all the time?

Thanks,
Arnaud

---

template< typename TPixel, unsigned int VDimension, typename TTraits >
typename QuadEdgeMesh< TPixel, VDimension, TTraits >::QEPrimal *
QuadEdgeMesh< TPixel, VDimension, TTraits >
::AddFace(const PointIdList & points)
{
#ifndef NDEBUG
   // Check that there are no duplicate points
   for ( size_t i = 0; i < points.size(); i++ )
     {
     typename PointIdList::const_iterator itr = points.begin();
     typename PointIdList::const_iterator end = points.end();
     PointIdentifier count = NumericTraits< PointIdentifier >::Zero;
     const PointIdentifier pointId = points[i];
     while ( itr != end )
       {
       if ( *itr == pointId )
         {
         ++count;
         }
       ++itr;
       }
     if ( count != 1 )
       {
       itkDebugMacro("Point " << i << " is duplicated");
       return ( (QEPrimal *)NULL );
       }
     }

   // Check that all points exist
   for ( size_t i = 0; i < points.size(); i++ )
     {
     if ( !this->GetPoints()->IndexExists(points[i]) )
       {
       itkDebugMacro("Point " << i << " is missing in the mesh");
       return (QEPrimal *)NULL;
       }
     }
#endif

   // Check if existing edges have no face on the left.
   for ( size_t i = 0; i < points.size(); i++ )
     {
     PointIdentifier pid0 = points[i];
     PointIdentifier pid1 = points[( i + 1 ) % points.size()];

     QEPrimal *edge = this->FindEdge(pid0, pid1);

     if ( edge )
       {
       if ( edge->IsLeftSet() )
         {
         itkDebugMacro("Edge [" << i << " " << ( ( i + 1 ) % points.size() )
<< " has a left face.");
         return (QEPrimal *)NULL;
         }
       }
     }

   return AddFaceWithSecurePointList(points);
}


More information about the Insight-developers mailing list