Skip to content

(Image): improve the API of ::fwData::Image

Emilie WERNERT requested to merge 67-improve-the-api-of-fwdata-image into dev

What does this MR do?

Improve the API of ::fwData::Image:

  • Add the pixel format information: GRAY_SCALE, RGB, RGBA, BGR, BGRA
    • Add an iterator for the different formats
    • the format involve the number of components
  • Prevent to use more than 3 dimensions: the size, spacing and origin are defined in a std::array
    • 4D images are no longer allowed
  • The ::fwData::Array is no longer accessible from the image
  • Update Dispatcher to use ::fwTools::Type instead of ::fwTools::DynamicType and deprecate DynamicType.
  • Most of the old API is still supported with deprecated warning:
    • the new getter/setter for size, origin and spacing are temporary post-fixed by 2 (ex: getSize2())
  • Increase the version of Medical Data to serialize the image format (V12, V14AR, V16RD)
  • Update WARNINGS_AS_ERRORS macro to allow deprecated warnings.

Example:

::fwData::Image::sptr img = ::fwData::Image::New();

img->resize({1920, 1080}, ::fwTools::Type::s_UINT8, ::fwData::Image::PixelFormat::GRAY_SCALE);

typedef ::fwData::Image::RGBAIteration RGBAIteration;

auto lock    = img->lock(); // to prevent buffer dumping
auto iter    = img->begin<RGBAIteration>();
const auto iterEnd = img->end<RGBAIteration>();

for (; iter != iterEnd; ++iter)
{
    iter->r = static_cast<std::uint8_t>(rand()%256);
    iter->g = static_cast<std::uint8_t>(rand()%256);
    iter->b = static_cast<std::uint8_t>(rand()%256);
    iter->a = static_cast<std::uint8_t>(rand()%256);
}

How to test it?

Launch the unit tests. Launch the application (at least Tuto06Filter)

Additional tests to run

Check the iterator performances. You can use This sample. For 2D RGBA image 1920*1080.

(ms) buffer for(buff!=buffEnd...) All value iteration RGBA Iteration
Linux Debug 5.93333 12.2667 4.46667
Linux Release 6 6.66667 2.2
macOS Debug 7.06667 50.7333 17.6667
macOS Release 7.13333 7.06667 3.33333

Associated Issues/Merge Requests

Edited by Emilie WERNERT

Merge request reports