35 #include "Core/include/DBaseImage.h"
36 #include "Gui/include/DBaseImageViewer.h"
45 template <
class T>
class ImageViewer;
64 Image(
size_t w,
size_t h,
size_t d = 1);
66 Image(
const char *fileName);
74 template <
class T2>
Image(
const Image<T2> &rhs,
bool cloneData =
false);
96 return getDataTypeAsString<T>(dum);
98 typedef typename ImDtTypes<T>::pixelType pixelType;
99 typedef typename ImDtTypes<T>::lineType lineType;
100 typedef typename ImDtTypes<T>::restrictLineType restrictLineType;
101 typedef typename ImDtTypes<T>::sliceType sliceType;
102 typedef typename ImDtTypes<T>::volType volType;
128 inline T
getPixel(
size_t x,
size_t y,
size_t z = 0)
const
130 ASSERT((x < width && y < height && z < depth),
131 "Coords out of image range", T(0));
132 return pixels[z * width * height + y * width + x];
138 ASSERT((offset < pixelCount),
"Offset out of image range", T(0));
139 return pixels[offset];
142 inline T getPixelNoCheck(
size_t offset)
const
144 return pixels[offset];
148 inline RES_T
setPixel(
size_t x,
size_t y,
size_t z,
const T &value)
150 ASSERT((x < width && y < height && z < depth),
151 "Coords out of image range", RES_ERR);
152 pixels[z * width * height + y * width + x] = value;
158 inline RES_T
setPixel(
size_t x,
size_t y,
const T &value)
164 inline RES_T
setPixel(
size_t offset,
const T &value)
166 ASSERT((offset < pixelCount),
"Offset out of image range", RES_ERR);
167 pixels[offset] = value;
172 inline void setPixelNoCheck(
size_t offset,
const T &value)
174 pixels[offset] = value;
184 void toCharArray(
signed char outArray[]);
187 return (
char *) pixels;
219 virtual void clone(
const Image<T> &rhs);
220 template <
class T2>
void clone(
const Image<T2> &rhs);
229 virtual RES_T
setSize(
size_t w,
size_t h,
size_t d = 1,
230 bool doAllocate =
true);
232 virtual RES_T
setSize(
size_t s[3],
bool doAllocate =
true)
234 return setSize(s[0], s[1], s[2], doAllocate);
243 virtual RES_T
setSize(
const vector<UINT> s,
bool doAllocate =
true)
246 return setSize(s[0], s[1], s[2], doAllocate);
248 return setSize(s[0], s[1], 1, doAllocate);
264 void printSelf(ostream &os,
bool displayPixVals,
bool hexaGrid =
false,
265 string indent =
"")
const;
267 virtual void printSelf(ostream &os = std::cout,
string indent =
"")
const
274 printSelf(std::cout,
false,
false, indent);
277 void printSelf(
bool displayPixVals,
bool hexaGrid =
false,
string indent =
"")
279 printSelf(std::cout, displayPixVals, hexaGrid, indent);
287 return s.str().c_str();
296 virtual RES_T load(
const char *fileName);
297 virtual RES_T save(
const char *fileName);
299 #if defined SWIGPYTHON && defined USE_NUMPY
326 #endif // defined SWIGPYTHON && defined USE_NUMPY
331 static T getDataTypeMin()
336 static T getDataTypeMax()
338 return ImDtTypes<T>::max();
341 inline T &operator[](
size_t i)
344 return this->pixels[i];
345 ERR_MSG(
"Offset out of range.");
346 return this->dumPixel;
355 ResImage<T> operator-()
const;
357 ResImage<T>
operator+(
const Image<T> &rhs);
365 ResImage<T> operator-(
const Image<T> &rhs);
367 ResImage<T> operator-(
const T &value);
373 ResImage<T>
operator*(
const Image<T> &rhs);
381 ResImage<T>
operator/(
const Image<T> &rhs);
393 ResImage<T>
operator<(
const Image<T> &rhs);
401 ResImage<T>
operator>(
const Image<T> &rhs);
409 ResImage<T> operator|(
const Image<T> &rhs);
410 ResImage<T> operator|(
const T &value);
411 Image<T> &operator|=(
const Image<T> &rhs);
412 Image<T> &operator|=(
const T &value);
415 ResImage<T>
operator&(
const Image<T> &rhs);
455 RES_T restruct(
void);
457 ImageViewer<T> *viewer;
466 virtual void setName(
const char *_name);
469 virtual void show(
const char *_name = NULL,
bool labelImage =
false);
473 virtual void showLabel(
const char *_name = NULL);
475 virtual void showNormal(
const char *_name = NULL);
481 template <
class T>
class ResImage :
public Image<T>
484 ResImage(
const Image<T> &rhs) : Image<T>(rhs, false)
490 ResImage(
const ResImage<T> &rhs) : Image<T>()
500 template <
class T> Image<T> *createImage(
const T)
502 return new Image<T>();
505 template <
class T> Image<T> *castBaseImage(BaseImage *img,
const T &)
507 ASSERT(strcmp(getDataTypeAsString<T>(), img->getTypeAsString()) == 0,
508 "Bad type for cast", NULL);
509 return reinterpret_cast<Image<T> *
>(img);
516 imOut.getViewer()->drawOverlay(imToDraw);
524 #endif // _DIMAGE_HPP
void fromCharArray(const signed char inArray[])
Copy pixel values from a given char array.
volType getSlices() const
Get an array containing the start offset of each slice.
Definition: DImage.hpp:117
lineType getPixels() const
Get the pixels as a 1D array.
Definition: DImage.hpp:105
virtual RES_T allocate()
Allocate image.
RES_T setPixel(size_t offset, const T &value)
Set the value of the pixel at a given offset.
Definition: DImage.hpp:164
virtual bool isVisible()
Check if the image is visible.
ResImage< T > operator*(const Image< T > &rhs)
Multiply by image.
PyObject * getNumArray(bool c_contigous=false)
getNumArray() -
RES_T setPixel(size_t x, size_t y, const T &value)
Set the value of the pixel at pos x,y.
Definition: DImage.hpp:158
void fromString(string pixVals)
Import pixel values from string.
ResImage< T > operator>(const Image< T > &rhs)
Greater boolean operator (see grt())
ResImage< T > operator~() const
Negate image.
Image< T > & operator+=(const Image< T > &rhs)
Image addition assignment.
ResImage< T > operator<(const Image< T > &rhs)
Lower boolean operator (see low())
virtual void clone(const Image< T > &rhs)
Clone from a given image (set same size and copy content)
virtual void hide()
Hide image.
virtual const char * getTypeAsString()
Get the image type.
Definition: DImage.hpp:93
Image()
Default constructor.
ResImage< T > operator+(const Image< T > &rhs)
Add image.
Image< T > & operator/=(const Image< T > &rhs)
Image division assignment.
Image that uses an existing (1D) data pointer.
Definition: DImage.hpp:49
void toArray(T outArray[])
Copy pixel values to a given array.
vector< int > toIntVector()
Copy pixel values to a given int vector.
virtual void * getVoidPointer(void)
Get pixels as a void pointer.
Definition: DImage.hpp:291
virtual void modified()
Trigger modified event (allows to force display update)
Base Image class.
Definition: DBaseImage.h:49
virtual Image< T > clone(bool cloneData=true)
Create a clone of the image (with same size and content )
Definition: DImage.hpp:222
virtual RES_T setSize(const vector< UINT > s, bool doAllocate=true)
Set the size of image.
Definition: DImage.hpp:243
virtual RES_T deallocate()
Deallocate image.
Image< T > & operator&=(const Image< T > &rhs)
Bitwise and assignement.
size_t getHeight() const
Get image height.
Definition: DBaseImage.h:85
Image< T > & operator>>(vector< T > &vect)
Export image data to a vector.
ResImage< T > operator<=(const Image< T > &rhs)
Lower or equal boolean operator (see lowOrEqu())
Image< T > & operator*=(const Image< T > &rhs)
Image multiplication assignment.
string toString()
Export pixel values to a string.
void drain(Image< T > *im, bool deleteSrc=false)
Replace container. Drain memory from image im to this.
virtual RES_T setSize(size_t w, size_t h, size_t d=1, bool doAllocate=true)
Set the size of image.
virtual RES_T setSize(const BaseImage &rhs, bool doAllocate=true)
Set the size of image.
Definition: DImage.hpp:237
RES_T drawOverlay(const Image< T > &imToDraw, Image< T > &imOut)
Draw overlay.
Definition: DImage.hpp:514
virtual void show(const char *_name=NULL, bool labelImage=false)
Show the default viewer associated with the image.
virtual void showLabel(const char *_name=NULL)
Show the default viewer associated with the image using a color lookup table.
Main Image class.
Definition: DQVtkViewer.hpp:42
ResImage< T > operator&(const Image< T > &rhs)
Bitwise and operator.
void fromIntVector(const vector< int > inVector)
Copy pixel values from a given int vector.
RES_T setPixel(size_t x, size_t y, size_t z, const T &value)
Set the value of the pixel at pos x,y,z (for 3D image)
Definition: DImage.hpp:148
Image< T > & operator-=(const Image< T > &rhs)
Image subtraction assignment.
size_t getDepth() const
Get image depth (Z)
Definition: DBaseImage.h:90
ResImage< T > operator==(const Image< T > &rhs)
Equal boolean operator (see equ()).
SharedImage< T > getSlice(size_t sliceNum) const
Get a 2D slice of a 3D image. It doesn't create an image, but returns a 2D SharedImage using the same...
ResImage< T > operator>=(const Image< T > &rhs)
Greater or equal boolean operator (see grt())
Definition: DImage.hpp:47
ResImage< T > operator/(const Image< T > &rhs)
Divide by image.
void fromIntArray(const int inArray[])
Copy pixel values from a given int array.
virtual void setName(const char *_name)
Set the name of the image.
sliceType getLines() const
Get an array containing the start offset of each line.
Definition: DImage.hpp:111
Definition: DTypes.hpp:88
void printSelf(ostream &os, bool displayPixVals, bool hexaGrid=false, string indent="") const
Print a description of the image.
void fromNumArray(PyObject *array)
fromNumArray() -
Image< T > & operator<<(const Image< T > &rhs)
Copy image.
void toIntArray(int outArray[])
Copy pixel values to a given int array.
virtual const char * getInfoString(const char *indent="") const
Get the description of the image as a string.
Definition: DImage.hpp:283
ResImage< T > operator!=(const Image< T > &rhs)
Diff boolean operator (see equ()).
virtual ImageViewer< T > * getViewer()
Get the image viewer (create one if needed)
void fromArray(const T inArray[])
Copy pixel values from a given array.
virtual RES_T setSize(size_t s[3], bool doAllocate=true)
Set the size of image.
Definition: DImage.hpp:232
T getPixel(size_t offset) const
Return the value of the pixel at a given offset.
Definition: DImage.hpp:136
T getPixel(size_t x, size_t y, size_t z=0) const
Return the value of the pixel at pos x,y(,z)
Definition: DImage.hpp:128
size_t getWidth() const
Get image width.
Definition: DBaseImage.h:80