41 #ifndef __usImage3D_h_
42 #define __usImage3D_h_
49 #include <visp3/core/vpDebug.h>
50 #include <visp3/core/vpException.h>
51 #include <visp3/core/vpImage.h>
74 usImage3D(
unsigned int height,
unsigned int width,
unsigned int frameNumber);
83 usImage3D(
unsigned int height,
unsigned int width,
unsigned int frameNumber, Type initialValue);
119 Type *
getData(
unsigned int i,
unsigned int j,
unsigned int k) {
return framPointer[k] + m_width * i + j; }
143 unsigned int getSize()
const {
return m_size; }
169 inline Type
operator()(
unsigned int i,
unsigned int j,
unsigned int k)
const
171 return framPointer[k][m_width * i + j];
181 inline void operator()(
unsigned int i,
unsigned int j,
unsigned int k, Type value)
183 framPointer[k][m_width * i + j] = value;
192 void resize(
unsigned int height,
unsigned int width,
unsigned int numberOfFrames);
211 void init(
unsigned int height,
unsigned int width,
unsigned int numberOfFrames);
213 unsigned int m_width;
214 unsigned int m_height;
215 unsigned int m_numberOfFrames;
242 template <
class Type>
243 inline void usImage3D<Type>::init(
unsigned int height,
unsigned int width,
unsigned int numberOfFrames)
245 if ((width != this->m_width) || (height != this->m_height) || (numberOfFrames != this->m_numberOfFrames)) {
246 if (bitmap != NULL) {
247 vpDEBUG_TRACE(10,
"Destruction bitmap[]");
251 if (framPointer != NULL) {
252 vpDEBUG_TRACE(10,
"Destruction framPointer[]");
253 delete[] framPointer;
260 m_numberOfFrames = numberOfFrames;
262 m_size = m_width * m_height * m_numberOfFrames;
265 bitmap =
new Type[m_size];
267 if (framPointer == NULL)
268 framPointer =
new Type *[numberOfFrames];
270 for (
unsigned int k = 0; k < numberOfFrames; k++)
271 framPointer[k] = bitmap + m_width * m_height * k;
274 if (bitmap == NULL) {
275 vpERROR_TRACE(
"cannot allocate bitmap ");
276 throw(vpException(vpException::memoryAllocationError,
"cannot allocate bitmap "));
280 template <
class Type>
285 template <
class Type>
287 : m_width(0), m_height(0), m_numberOfFrames(0), m_size(0), bitmap(NULL), framPointer(NULL)
289 this->init(height, width, frameNumber);
293 template <
class Type>
295 : m_width(0), m_height(0), m_numberOfFrames(0), m_size(0), bitmap(NULL), framPointer(NULL)
297 this->init(height, width, frameNumber);
301 template <
class Type>
303 : m_width(0), m_height(0), m_numberOfFrames(0), m_size(0), bitmap(NULL), framPointer(NULL)
309 memcpy(bitmap, volume.bitmap, m_size *
sizeof(Type));
319 delete[] framPointer;
326 this->init(other.m_height, other.m_width, other.m_numberOfFrames);
328 memcpy(bitmap, other.bitmap, m_size *
sizeof(Type));
334 bool settingsOk = this->getWidth() == other.
getWidth() && this->getHeight() == other.
getHeight() &&
338 for (
unsigned int i = 0; i < m_size; i++) {
347 template <
class Type> std::ostream &operator<<(std::ostream &out,
const usImage3D<Type> &image)
349 return out <<
"width : " << image.
getWidth() << std::endl
350 <<
"height : " << image.
getHeight() << std::endl
357 if (m_size != numberOfVoxels) {
358 throw(vpException(vpException::fatalError,
"usImage3D::setData() error, bitmap dimensions mismatch."));
360 memcpy(bitmap, data, m_size *
sizeof(Type));
361 }
catch (std::exception e) {
362 std::cout <<
"usImage3D::setData(), error when trying to copy the data :" << std::endl;
363 std::cout << e.what() << std::endl;
370 std::fill_n(bitmap, m_size, value);
371 }
catch (
const std::exception &e) {
372 std::cout << e.what() << std::endl;
378 this->init(height, width, numberOfFrames);
Representation of a physical image volume.
usImage3D(const usImage3D< Type > &image, const bool copy=true)
Type * getData(unsigned int i, unsigned int j, unsigned int k)
unsigned int getNumberOfFrames() const
bool operator==(const usImage3D< Type > &other)
usImage3D(unsigned int height, unsigned int width, unsigned int frameNumber, Type initialValue)
unsigned int getSize() const
void resize(unsigned int height, unsigned int width, unsigned int numberOfFrames)
Type * getConstData() const
void initData(Type value)
void setData(Type *data, int numberOfVoxels)
unsigned int getHeight() const
unsigned int getWidth() const
usImage3D(unsigned int height, unsigned int width, unsigned int frameNumber)
Type operator()(unsigned int i, unsigned int j, unsigned int k) const
void operator()(unsigned int i, unsigned int j, unsigned int k, Type value)
usImage3D< Type > & operator=(const usImage3D< Type > &other)