4 #pragma warning(disable:4244) 25 #include "ConstImageBPLinearIterator.h" 26 #include "ImageBPLinearIterator.h" 27 #include "ConstImageBPVolumetricIterator.h" 28 #include "ImageBPVolumetricIterator.h" 36 typedef uchar t_value;
41 class ImageBP :
public SmartObject
58 ImageBP(
const numeric_array<int,3> &dim,
const numeric_array<t_voxsize,3> &vDim);
69 ImageBP(
const ImageBP<N> *);
91 void init(
const numeric_array<int,3> & dim,
const numeric_array<t_voxsize,3> & vDim);
92 void init(
const ImageBP<N> *);
99 int getDimX()
const {
return m_dim.getX();}
100 int getDimY()
const {
return m_dim.getY();}
101 int getDimZ()
const {
return m_dim.getZ();}
102 int getDim(
int i)
const {
return m_dim.get(i); }
103 const numeric_array<int,3> & getDim()
const {
return m_dim; }
108 int getSize()
const {
return this->getDimX()*this->getDimY()*this->getDimZ(); }
113 t_voxsize getVx()
const {
return m_vDim.getX(); }
114 t_voxsize getVy()
const {
return m_vDim.getY(); }
115 t_voxsize getVz()
const {
return m_vDim.getZ(); }
116 t_voxsize getVDim(
int i)
const {
return m_vDim.get(i); }
117 const numeric_array<t_voxsize,3> & getVDim()
const {
return m_vDim; }
128 t_value& operator()(
int i,
int j,
int k) {
return *(this->getPointerOf(i,j,k)); }
129 t_value& operator()(
const numeric_array<int,3> &v) {
return this->operator()(
EXPAND_VECTOR(v)); }
135 INLINE const t_value getValue(
int i,
int j,
int k)
const;
136 const t_value getValue(
const numeric_array<int,3> &v)
const {
return this->getValue(
EXPAND_VECTOR(v)); }
142 INLINE const t_value getUnsafeValue(
int i,
int j,
int k)
const;
143 const t_value getUnsafeValue(
const numeric_array<int,3> &v)
const {
return this->getUnsafeValue(
EXPAND_VECTOR(v)); }
151 t_value* getPointer() {
return m_data;}
153 const t_value* getConstPointer()
const {
return m_data;}
155 inline const t_value* getConstPointerOf(
int i,
int j,
int k)
const;
176 void copy(
const ConstPtr<ImageBP<N> > &im);
181 friend class ConstImageBPVolumetricIterator<N>;
186 typedef t_value TPixel;
187 typedef ConstImageBPLinearIterator<N> ConstLinearIterator;
188 typedef ImageBPLinearIterator<N> LinearIterator;
189 typedef ConstImageBPVolumetricIterator<N> ConstVolumetricIterator;
190 typedef ImageBPVolumetricIterator<N> VolumetricIterator;
199 t_value* getUnsafePointerOf(
int i,
int j,
int k)
const {
return m_data + i + m_dim.getX() * ( j + m_dim.getY()*k); }
200 t_value* getUnsafePointerOf(
const numeric_array<int,3> &v)
const {
return this->getUnsafePointerOf(
EXPAND_VECTOR(v)); }
201 t_value* getUnsafePointerOf(
int n)
const {
return m_data + n;}
203 t_value* getPointerOf(
int i,
int j,
int k)
const 209 return this->getUnsafePointerOf(i,j,k);
211 t_value* getPointerOf(
const numeric_array<int,3> &v)
const {
return this->getPointerOf(
EXPAND_VECTOR(v)); }
213 void setDim(
int x,
int y,
int z)
215 if ((x<0)||(y<0)||(z<0))
217 throw std::invalid_argument(
"Image size < 0");
224 if ((vx<0)||(vy<0)||(vz<0))
226 throw std::invalid_argument(
"Voxel size < 0");
228 m_vDim.set(vx, vy, vz);
231 void setData(t_value* data)
233 if (m_data == data)
return;
234 if (m_data)
delete [] m_data;
241 bool contains(
int i,
int j,
int k)
const 243 return (i >= 0 && j >= 0 && k >= 0 &&
254 numeric_array<int,3> m_dim;
257 numeric_array<t_voxsize,3> m_vDim;
260 numeric_array<t_voxsize,3> m_ori;
307 ImageBP<N>::ImageBP() : SmartObject(), m_data(0)
315 void ImageBP<N>::init()
325 this->init(x, y, z, vx, vy, vz);
333 t_value * data =
new t_value[x*y*z];
334 this->init(data, x, y, z, vx, vy, vz);
341 ImageBP<N>::ImageBP(
const numeric_array<int,3> &dim,
const numeric_array<t_voxsize,3> &vDim) : SmartObject(), m_data(0)
343 this->init(dim, vDim);
349 void ImageBP<N>::init(
const numeric_array<int,3> &dim,
const numeric_array<t_voxsize,3> &vDim)
359 this->init(data, x, y, z, vx, vy, vz);
367 this->setDim(x, y, z);
368 this->setVDim(vx, vy, vz);
375 ImageBP<N>::ImageBP(
const ImageBP<N> *pIm) : SmartObject(), m_data(0)
383 void ImageBP<N>::init(
const ImageBP<N> *pIm)
385 this->init(
param(pIm));
387 (
void*)this->getPointer(),
388 (
void*)pIm->getConstPointer(),
389 pIm->getSize()*
sizeof(t_value));
395 ImageBP<N>::~ImageBP()
404 void ImageBP<N>::reset()
406 memset((
void*)m_data, 0, this->getSize()*
sizeof(t_value));
412 INLINE const t_value* ImageBP<N>::getConstPointerOf(
int i,
int j,
int k)
const 414 return this->getPointerOf(i,j,k);
420 INLINE const t_value ImageBP<N>::getValue(
int i,
int j,
int k)
const 424 return this->getUnsafeValue(i,j,k);
428 throw std::out_of_range(
"Position out of image range");
435 INLINE const t_value ImageBP<N>::getUnsafeValue(
int i,
int j,
int k)
const 437 return *(this->getUnsafePointerOf(i,j,k));
446 throw std::invalid_argument(
"Unallocated image");
449 if (!((this->getDimX() == im->getDimX()) &&
450 (this->getDimY() == im->getDimY()) &&
451 (this->getDimZ() == im->getDimZ()) &&
452 (this->getVx() == im->getVx()) &&
453 (this->getVy() == im->getVy()) &&
454 (this->getVz() == im->getVz())))
456 throw std::invalid_argument(
"Incompatible images");
460 (
void*)this->getPointer(),
461 (
void*)(const_cast<t_value*>(im->getConstPointer())),
462 im->getSize()*
sizeof(t_value));
ImageParameter param(const TImage &im)
Create an ImageParameter structure out of an Image.
Belongs to package Box Do not include directly, include til/Box.h instead.
General macros, definitions and functions.
void copy(const TImage &in, TImage &out)
Copy one image to another.
INLINE bool isAllocated(const TImage &im)
Check whether smart pointer and image are allocated.
boost::enable_if< is_numeric_container< TStorage >, bool >::type contains(const Box< T, D > &box, const TStorage &v)
Check whether a point lies within box.
float t_voxsize
type of voxel size