[Insight-developers] memcpy & ImageAdaptors

Luis Ibanez ibanez@cs.unc.edu
Thu, 14 Dec 2000 16:07:46 -0500


Hi,

This is a possible way to decide when memcpy
can be used safely to move blocks of data between
images, even if they are masked by an ImageAdaptor.

Currently the iterators get the DataAccessor type of the
Image they are accessing, and from it, they define the
types

-  InternalPixelType
-  PixelType

The first is the type of the "real" image that can potentially
be behind an ImageAdaptor. The second is the type that
the ImageAdaptor present to us.

If we are using two iterators, one for the source and the
other for the destination, we can check for these types
in order to see if it is safe to move data with memcpy.

That could look like:
==========================================
IteratorTypeA  iteratorA(...);
IteratorTypeB  iteratorB(...);

if(   typeid(  IteratorTypeA::InternalPixelType ) == typeid(
IteratorTypeB::InternalPixelType) )
{
     // the underlying images are really of the same type,
    //so memcpy is safe
    memcpy( ...);
}
else
{
    // The images have different type,
   //  so a normal (slower ) loop should be used
   //   to move the data
   while(  ...  )
    {
       iteratorA.Set(   iteratorB.Get()  );
       ++iteratorA;
       ++iteratorB;
      }

}



======================================



Luis