32 template <
typename T >
33 class ImageNC :
public ImageBase
96 void setValue(
const T & value,
int i,
int j,
int k)
98 *(this->getUnsafePointerOf(i,j,k)) = value;
102 *(this->getUnsafePointerOf(p)) = value;
133 if (!((this->
dim()[0] == im.
dim()[0]) &&
134 (this->
dim()[1] == im.
dim()[1]) &&
135 (this->
dim()[2] == im.
dim()[2]) &&
136 (this->
vdim()[0] == im.
vdim()[0]) &&
137 (this->
vdim()[1] == im.
vdim()[1]) &&
140 throw std::invalid_argument(
"Incompatible images");
144 for (
int i = 0; i < this->
dim()[2]; ++i)
147 (
void*)this->getUnsafeSlicePointer(i),
148 (
void*)(const_cast<T*>(im.getUnsafeSlicePointer(i))),
149 im.getSliceSize()*
sizeof(T));
158 return m_data != im.m_data;
163 return m_data == im.m_data;
186 const T* getUnsafeSlicePointer(
int i)
const {
return m_data[i]; }
187 T* getUnsafeSlicePointer(
int i) {
return m_data[i]; }
189 const T* getSlicePointer(
int i)
const 191 if (i < 0 || i >= this->
dim()[2])
193 throw std::out_of_range(
"Slice number out of range");
195 return this->getUnsafeSlicePointer(i);
199 T* getSlicePointer(
int i)
201 if (i < 0 || i >= this->
dim()[2])
203 throw std::out_of_range(
"Slice number out of range");
205 return this->getUnsafeSlicePointer(i);
210 T* getUnsafePointerOf(
int i,
int j,
int k)
const {
return m_data[k] + i + this->
dim()[0] * j; }
213 T* getPointerOf(
int i,
int j,
int k)
const 219 return this->getUnsafePointerOf(i,j,k);
223 void setData(T** data)
225 if (m_data == data)
return;
226 if (m_data) this->deallocateData();
230 void setData(
const std::vector<T*> & slices)
232 if (m_data) this->deallocateData();
233 m_data =
new T*[slices.size()];
235 for (
int i=0; i < slices.size(); ++i)
237 m_data[i] = slices[i];
243 if ( this->
dim()[0]<0 || this->
dim()[1]<0 || this->
dim()[2]<0)
245 throw std::invalid_argument(
"Image size < 0");
247 m_data =
new T*[this->
dim()[2]];
248 for (
int i = 0; i < this->
dim()[2]; ++i)
250 m_data[i] =
new T[this->getSliceSize()];
254 void deallocateData()
256 for (
int i=0; i < this->
dim()[2]; ++i)
268 int getSliceSize()
const {
return this->
dim()[0] * this->
dim()[1]; }
283 template <
typename T >
331 template <
typename T >
339 template <
typename T >
347 template <
typename T >
350 this->
init(x, y, z, vx, vy, vz);
355 template <
typename T >
358 this->_init(x, y, z, vx, vy, vz);
359 this->allocateData();
365 template <
typename T >
368 this->
init(dim, vDim);
373 template <
typename T >
380 template <
typename T >
387 template <
typename T >
394 template <
typename T >
397 this->
init(data, x, y, z, vx, vy, vz);
401 template <
typename T >
409 template <
typename T >
412 this->_init(x, y, z, vx, vy, vz);
414 this->setData(data2);
417 template <
typename T >
420 this->
init(data, x, y, z, vx, vy, vz);
423 template <
typename T >
426 this->_init(x, y, z, vx, vy, vz);
430 template <
typename T >
433 this->
init(slices, x, y, vx, vy, vz);
436 template <
typename T >
439 this->_init(x, y, slices.size(), vx, vy, vz);
440 this->setData(slices);
443 template <
typename T >
449 template <
typename T >
454 for (
int i = 0; i < this->getZ(); ++i)
457 (
void*)this->getUnsafeSlicePointer(i),
458 (
void*)pIm.getUnsafeConstSlicePointer(i),
459 pIm.getSliceSize()*
sizeof(T));
464 template <
typename T >
467 this->deallocateData();
471 template <
typename T >
474 for (
int i=0; i<this->
dim()[2]; ++i)
476 memset((
void*)this->getUnsafeSlicePointer(i), 0, this->getSliceSize()*
sizeof(T));
482 template <
typename T >
485 return *(this->getPointerOf(i,j,k));
498 template <
typename T >
507 throw std::out_of_range(
"Position out of image range");
512 template <
typename T >
515 return *(this->getUnsafePointerOf(i,j,k));
A trait class to assign iterators to image types.
const T getUnsafeValue(const numeric_array< int, 3 > &v) const
INLINE const T getValue(int i, int j, int k) const
void setValue(const T &value, int i, int j, int k)
bool contains(const numeric_array< int, 3 > &p) const
void set_dim(const numeric_array< int, 3 > &dim)
const numeric_array< t_voxsize, 3 > & vdim() const
get voxel size
INLINE T & operator()(int i, int j, int k)
ImageParameter param(const TImage &im)
Create an ImageParameter structure out of an Image.
Collects image information to create similar images.
LinearIterator< ImageNC< T > > Linear
VolumetricIterator< ImageNC< T > > Volumetric
Belongs to package Box Do not include directly, include til/Box.h instead.
General macros, definitions and functions.
bool operator!=(const Self &im) const
Check whether images point on the same buffer.
numeric_array< t_voxsize, 3 > m_vDim
Voxel size.
INLINE const T getUnsafeValue(int i, int j, int k) const
void setValue(const T &value, const numeric_array< int, 3 > &p)
void set_vdim(const numeric_array< t_voxsize, 3 > &vdim)
Set the voxel coordinates.
ConstLinearIterator< ImageNC< T > > ConstLinear
Image class storing data slice-by-slice.
bool operator==(const Self &im) const
Check whether images point on the same buffer.
ConstVolumetricIterator< ImageNC< T > > ConstVolumetric
const numeric_array< int, 3 > & dim() const
get image dimension
Collects common code accross all image classes.
T ** simple2DoublePointer(T *data, int x, int y, int z)
Converts a contiguous memory buffer into a per-slice buffer.
T & operator()(const numeric_array< int, 3 > &v)
void copy(const Self &im)
float t_voxsize
type of voxel size
numeric_array< int, 3 > m_dim
Image dimensions.
const T getValue(const numeric_array< int, 3 > &v) const