9 #include "fwDataTools/config.hpp" 10 #include "fwDataTools/helper/Image.hpp" 11 #include "fwDataTools/helper/ImageGetter.hpp" 13 #include <fwData/Image.hpp> 14 #include <fwData/Integer.hpp> 15 #include <fwData/Point.hpp> 17 #include <fwTools/Dispatcher.hpp> 18 #include <fwTools/DynamicTypeKeyTypeMapping.hpp> 19 #include <fwTools/IntrinsicTypes.hpp> 20 #include <fwTools/NumericRoundCast.hxx> 30 template <
class T>
struct bitwise_or : std::binary_function <T, T, T>
34 T operator() (
const T&
x,
const T& y)
const 55 FWDATATOOLS_API
static bool checkLandmarks( ::fwData::Image::sptr _pImg );
65 FWDATATOOLS_API
static bool checkImageValidity( ::fwData::Image::csptr _pImg );
75 FWDATATOOLS_API
static bool checkImageSliceIndex( ::fwData::Image::sptr _pImg );
83 FWDATATOOLS_API static ::fwData::Point::sptr getImageSliceIndices( ::fwData::Image::sptr _pImg );
93 FWDATATOOLS_API
static bool checkComment( ::fwData::Image::sptr _pImg );
104 FWDATATOOLS_API static ::fwData::Image::sptr initialize( ::fwData::Image::sptr imgSrc,
105 ::fwData::Image::sptr imgToInitialize =
106 ::fwData::Image::sptr());
113 template <
typename INT_INDEX>
114 static bool isPixelNull(::fwData::Image::sptr image, INT_INDEX&
point);
116 FWDATATOOLS_API
static bool isBufNull(const ::fwData::Image::BufferType* buf,
const unsigned int len);
124 template <
typename T,
typename INT_INDEX>
125 static void setPixel(::fwData::Image::sptr image, INT_INDEX& point, T& value);
133 template <
typename T >
134 static void setPixel(::fwData::Image::sptr pImage, ::fwData::Point::sptr point, T& value);
141 template <
typename T >
142 static SPTR( ::fwData::Image::BufferType ) getPixelBufferInImageSpace(::fwData::Image::sptr image, T &value);
152 template <
typename MINMAXTYPE >
153 static void getMinMax(const ::fwData::Image::csptr _img, MINMAXTYPE& _min, MINMAXTYPE& _max);
159 template <
typename VALUE >
166 typedef VALUE ValueType;
167 typedef SPTR ( ::fwData::Image::BufferType ) BufferTypeSptr;
169 Param(ValueType& v) :
174 const ValueType& value;
180 template <
typename IMAGE >
181 void operator()(
Param& param )
183 unsigned char imageTypeSize =
sizeof(IMAGE);
185 IMAGE val = ::fwTools::numericRoundCast<IMAGE>(param.value);
187 ::fwData::Image::BufferType* buf =
reinterpret_cast< ::fwData::Image::BufferType*
> (&val);
189 SPTR( ::fwData::Image::BufferType ) res( new ::fwData::Image::BufferType[imageTypeSize] );
190 std::copy(buf, buf+imageTypeSize, res.get());
198 template <
typename VALUE,
typename INT_INDEX >
205 typedef VALUE ValueType;
206 typedef INT_INDEX PointType;
208 Param(PointType& p, ValueType& v) :
214 ::fwData::Image::sptr image;
215 const ValueType& value;
216 const PointType&
point;
221 template <
typename IMAGE >
222 void operator()(
Param& param )
225 IMAGE* buffer = static_cast < IMAGE* > (imagehelper.
getBuffer());
226 const INT_INDEX& p = param.point;
227 const ::fwData::Image::SizeType& size = param.image->getSize();
228 const int& sx = size[0];
229 const int& sy = size[1];
230 const int& offset = p[0] + sx*p[1] + p[2]*sx*sy;
231 *(buffer+offset) = ::fwTools::numericRoundCast<IMAGE>(param.value);
238 template <
typename T >
241 setPixel(image, point->getCoord(), value);
246 template <
typename T,
typename INT_INDEX>
258 template <
typename T >
271 template <
typename INT_INDEX >
278 typedef INT_INDEX PointType;
280 Param(PointType& p,
bool& b) :
286 ::fwData::Image::sptr image;
287 const PointType&
point;
293 template <
typename IMAGE >
294 void operator()(
Param& param )
297 IMAGE* buffer = static_cast < IMAGE* > (imagehelper.
getBuffer());
298 const INT_INDEX& p = param.point;
299 const std::vector<std::int32_t>& size = param.image->getSize();
300 const int& sx = size[0];
301 const int& sy = size[1];
302 const int& offset = p[0] + sx*p[1] + p[2]*sx*sy;
303 param.isNull = (*(buffer+offset) == 0);
310 template <
typename INT_INDEX>
314 const unsigned char imageTypeSize = image->getPixelType().sizeOf();
315 ::fwData::Image::BufferType* buf =
316 static_cast< ::fwData::Image::BufferType*
> (imageLock.
getPixelBuffer(point[0], point[1], point[2]));
318 return isBufNull(buf, imageTypeSize);
323 template <
typename T >
331 Param(::fwData::Image::csptr _img, T& _min, T& _max) :
338 ::fwData::Image::csptr image;
345 template <
typename IMAGE >
346 void operator()(
Param& param )
349 IMAGE* buffer = static_cast < IMAGE* > (imageLock.
getBuffer());
350 const ::fwData::Image::SizeType& size = param.image->getSize();
351 ::fwData::Image::SizeType::value_type len =
static_cast< ::fwData::Image::SizeType::value_type
>(
352 std::accumulate(size.begin(), size.end(), 1, std::multiplies< ::fwData::Image::SizeType::value_type >()));
356 typedef std::numeric_limits<IMAGE> ImgLimits;
357 IMAGE imin = ImgLimits::max();
358 IMAGE imax = ImgLimits::lowest();
360 IMAGE* bufEnd = buffer + len;
363 for (IMAGE* voxel = buffer; voxel < bufEnd; ++voxel )
365 currentVoxel = *voxel;
367 if ( currentVoxel < imin )
371 else if (currentVoxel > imax)
377 typedef std::numeric_limits<T> TLimits;
378 T minT = TLimits::lowest();
379 T maxT = TLimits::max();
381 min = ( imin < minT ) ? minT : static_cast< T > (imin);
382 max = ( imax > maxT ) ? maxT : static_cast< T > (imax);
390 template <
typename MINMAXTYPE >