The class adds support for PIC images by providing a proper interface to map the intensity range to the physical one of the display. More...
#include <picimage.h>
Public Member Functions | |
iil4mitkPicImage (unsigned int size=128) | |
The constructor. | |
virtual | ~iil4mitkPicImage () |
The destructor. | |
void | setImage (mitkIpPicDescriptor *pic, int model=INTENSITY) |
Sets the PIC image. | |
mitkIpPicDescriptor * | image () const |
Gets the PIC image. | |
void | setExtrema (const float minimum, const float maximum) |
Sets the range of the intensities which will be displayed. | |
void | setWindow (const float level, const float window) |
Sets the range of the intensities which will be displayed. | |
float | minimum () const |
Gets the minimal intensity which will be displayed. | |
float | maximum () const |
Gets the maximal intensity which will be displayed. | |
float | level () const |
Gets the level of the window which limits the displayed intensities. | |
float | window () const |
Gets the width of the window which limits the displayed intensities. | |
void | setOpacityExtrema (const float minimum, const float maximum) |
Sets the range of opacity values which will be displayed. | |
void | setOpacityWindow (const float level, const float window) |
Sets the range of the opacities which will be displayed. | |
float | minimumOpacity () const |
Gets the minimal opacity which will be displayed. | |
float | maximumOpacity () const |
Gets the maximal opacity which will be displayed. | |
float | levelOpacity () const |
Gets the level of the window which limits the displayed opacities. | |
float | windowOpacity () const |
Gets the width of the window which limits the displayed opacities. | |
void | setColors (const unsigned char *colors) |
Sets the color map which assigns each intensity a color according to the color model. | |
const unsigned char * | colors () const |
Gets the color map. | |
void | setBinary (const bool on) |
Sets the binary flag which forces the data to be converted into a binary image. | |
bool | binary () const |
Checks if the binary flag is set. | |
void | setOutline (const bool on) |
Sets the outline flag which forces the data to be displayed as outline. Only possible with binary data! | |
void | setOutlineWidth (float width) |
Sets the line width used to draw the binary outline. Requires the outline flag to be set via setOutline(true) first. | |
bool | outline () const |
Checks if the outline flag is set. | |
void | setMask (const bool on) |
Sets the mask flag which ensures that only pixels are displayed which are in the intensity window. | |
bool | mask () const |
Checks if the mask flag is set. | |
virtual void | clear () |
Clears the image. | |
virtual void | display (iil4mitkWidget *widget) |
Displays the item. | |
Static Public Member Functions | |
static iil4mitkPicImage * | find (const iil4mitkItem *item) |
Gets the first image of the item tree. | |
Protected Member Functions | |
virtual void | copyImage (unsigned int x, unsigned int y, unsigned int w, unsigned int h, unsigned char *data, unsigned int width, unsigned int height, unsigned int xoffset, unsigned int yoffset) |
Copies a specified region of the image. |
The class adds support for PIC images by providing a proper interface to map the intensity range to the physical one of the display.
Definition at line 11 of file picimage.h.
iil4mitkPicImage::iil4mitkPicImage | ( | unsigned int | size = 128 ) |
The constructor.
Definition at line 6 of file picimage.cpp.
: iil4mitkImage(size), _pic (NULL), _min (0.0), _max (0.0), _colors (NULL), _binary (false), _mask (false), _outline(false), _outlineWidth(1.0) { }
iil4mitkPicImage::~iil4mitkPicImage | ( | ) | [virtual] |
bool iil4mitkPicImage::binary | ( | ) | const |
Checks if the binary flag is set.
Definition at line 142 of file picimage.cpp.
Referenced by copyImage().
{
return _binary;
}
void iil4mitkPicImage::clear | ( | ) | [virtual] |
Clears the image.
Reimplemented from iil4mitkImage.
Definition at line 189 of file picimage.cpp.
{ _pic = NULL; _min = _max = 0.0; _minOpac = _maxOpac = 0.0; _colors = NULL; _binary = false; _mask = false; _outline = false; iil4mitkImage::clear (); }
const unsigned char * iil4mitkPicImage::colors | ( | ) | const |
Gets the color map.
Definition at line 124 of file picimage.cpp.
Referenced by setColors().
{
return _colors;
}
void iil4mitkPicImage::copyImage | ( | unsigned int | x, |
unsigned int | y, | ||
unsigned int | w, | ||
unsigned int | h, | ||
unsigned char * | data, | ||
unsigned int | width, | ||
unsigned int | height, | ||
unsigned int | xoffset, | ||
unsigned int | yoffset | ||
) | [protected, virtual] |
Copies a specified region of the image.
x,y,w,h | the geometry of the region |
data | the image data where the region is copied to |
width,height | the geometry of the image data |
xoffset,yoffset | the image point where the region is copied to |
Reimplemented from iil4mitkImage.
Definition at line 456 of file picimage.cpp.
References iil4mitkItem::alpha(), binary(), BINARY_INTENSITIES, iil4mitkImage::bpe(), LIMIT_INTENSITIES, mask(), MASK_INTENSITIES, iil4mitkImage::model(), iil4mitkImage::RGB, and iil4mitkImage::RGBA.
{ assert (_pic); // assert (_min <= _max); unsigned int slice = _pic->n[0] * _pic->n[1] * (_pic->bpe / 8); float scale = (_max -_min > 0 ? 255.0 / (_max - _min) : 0.0); float bias = _min * scale; float scaleOpac = (_maxOpac -_minOpac > 0 ? 255.0 / (_maxOpac - _minOpac) : 0.0); float biasOpac = _minOpac * scaleOpac; unsigned char *src = (unsigned char *) _pic->data + (y * _pic->n[0] + x) * (_pic->bpe/8); unsigned char *dst = data + (yoffset * width + xoffset) * (bpe () / 8); unsigned char *eol = dst + w * (bpe () / 8); //printf ("updateTexture: start = (%u/%u), end = (%u/%u), length = (%u/%u)\n", x, y, x+w-1, y+h-1, w, h); for (unsigned int i = 0; i < h; i++) { // copy current line if (model () == RGB) { unsigned char* source = (unsigned char *) src; unsigned char* dest = dst; while (dest < eol) { if(_min!=0 || _max!=255) { // level/window mechanism for intensity in HSI space double rgb[3], hsi[3]; rgb[0] = source[0]; rgb[1] = source[1]; rgb[2] = source[2]; RGBtoHSI<double>(rgb,hsi); hsi[2] = hsi[2] * 255.0 * scale - bias; hsi[2] = (hsi[2] > 255.0 ? 255 : (hsi[2] < 0.0 ? 0 : hsi[2])); hsi[2] /= 255.0; HSItoRGB<double>(hsi,rgb); dest[0] = (unsigned char)rgb[0]; dest[1] = (unsigned char)rgb[1]; dest[2] = (unsigned char)rgb[2]; source+=3; dest+=3; } else { *dest = *source; ++source; ++dest; } } } else if (model () == RGBA) { unsigned char* source = (unsigned char *) src; unsigned char* dest = dst; while (dest < eol) { if(_min!=0 || _max!=255 || _minOpac!=0 || _maxOpac!=255) { double rgb[3], alpha, hsi[3]; // level/window mechanism for intensity in HSI space rgb[0] = source[0]; rgb[1] = source[1]; rgb[2] = source[2]; alpha = source[3]; RGBtoHSI<double>(rgb,hsi); hsi[2] = hsi[2] * 255.0 * scale - bias; hsi[2] = (hsi[2] > 255.0 ? 255 : (hsi[2] < 0.0 ? 0 : hsi[2])); hsi[2] /= 255.0; HSItoRGB<double>(hsi,rgb); // level/window mechanism for opacity alpha = alpha * scaleOpac - biasOpac; alpha = (alpha > 255.0 ? 255 : (alpha < 0.0 ? 0 : alpha)); dest[0] = (unsigned char)rgb[0]; dest[1] = (unsigned char)rgb[1]; dest[2] = (unsigned char)rgb[2]; dest[3] = (unsigned char)alpha; source+=4; dest+=4; } else { *dest = *source; ++source; ++dest; } } } else if (mask ()) { mitkIpPicFORALL(MASK_INTENSITIES, _pic); } else if (binary ()) { mitkIpPicFORALL(BINARY_INTENSITIES, _pic); } else { #ifdef USE_MMX if (mitkIpPicDR(_pic->type, _pic->bpe) == mitkIpPicDR(mitkIpPicInt, 16)) { unsigned char* d = dst; unsigned char* s = src; if (w / 16) { extrema (dst, (short *) src, w, (short) _min, (short) _max); } if (w % 16) { mitkIpPicFORALL(LIMIT_INTENSITIES, _pic); dst = d; src = s; } } else { mitkIpPicFORALL(LIMIT_INTENSITIES, _pic); } #else mitkIpPicFORALL(LIMIT_INTENSITIES, _pic); #endif } // go to next line src += _pic->n[0] * (_pic->bpe/8); dst += width * (bpe () / 8); eol = dst + w * (bpe () / 8); } }
void iil4mitkPicImage::display | ( | iil4mitkWidget * | widget ) | [virtual] |
Displays the item.
Reimplemented from iil4mitkImage.
Definition at line 584 of file picimage.cpp.
References iil4mitkItem::alpha(), iil4mitkItem::blue(), GL_LINES, GL_MODELVIEW, glBegin(), glColor4f(), glEnd(), glLineWidth(), glMatrixMode(), glPopMatrix(), glPushMatrix(), glTranslatef(), glVertex3f(), iil4mitkItem::green(), iil4mitkItem::red(), iil4mitkItem::x(), and iil4mitkItem::y().
Referenced by mitk::ImageMapperGL2D::Paint().
{ if (!_outline) { iil4mitkImage::display( widget ); } else { glMatrixMode (GL_MODELVIEW); glPushMatrix (); glColor4f ( red(), green(), blue(), alpha() ); //glColor4f( 1.0, 0.0, 0.0, 1.0 ); glTranslatef( x(), y(), 0.0 ); glLineWidth(_outlineWidth); glBegin( GL_LINES ); int line = _pic->n[0]; float fLine = (float)line; float x=0.0, y=0.0; mitkIpInt1_t *current; mitkIpInt1_t *end = ((mitkIpInt1_t*)_pic->data) + (_pic->n[0]*_pic->n[1]); int ii = 0, nn = _pic->n[0]*_pic->n[1]; for (current = (mitkIpInt1_t*)_pic->data; current<end; current++, ii++) { if (*current != 0) { if (ii >= line && *(current-line) == 0) { glVertex3f( x, y, 0.0 ); glVertex3f( x+1.0, y, 0.0 ); } if (ii <= nn-line && *(current+line) == 0) { glVertex3f( x, y+1.0, 0.0 ); glVertex3f( x+1.0, y+1.0, 0.0 ); } if (ii > 1 && *(current-1) == 0) { glVertex3f( x, y, 0.0 ); glVertex3f( x, y+1.0, 0.0 ); } if (ii < nn-1 && *(current+1) == 0) { glVertex3f( x+1.0, y, 0.0 ); glVertex3f( x+1.0, y+1.0, 0.0 ); } } x += 1.0; if (x >= fLine) { x = 0.0; y += 1.0; } } glEnd (); glLineWidth(1.0f); glPopMatrix (); } }
iil4mitkPicImage * iil4mitkPicImage::find | ( | const iil4mitkItem * | item ) | [static] |
Gets the first image of the item tree.
Reimplemented from iil4mitkImage.
Definition at line 202 of file picimage.cpp.
{ iil4mitkPicImage* result = NULL; if (!item) return NULL; if ( dynamic_cast<const iil4mitkPicImage*>(item)!=NULL ) { result = const_cast<iil4mitkPicImage*>(dynamic_cast<const iil4mitkPicImage*>(item)); } return result; }
mitkIpPicDescriptor * iil4mitkPicImage::image | ( | ) | const |
Gets the PIC image.
Definition at line 26 of file picimage.cpp.
Referenced by mitk::ImageMapperGL2D::Paint().
{
return _pic;
}
float iil4mitkPicImage::level | ( | ) | const |
Gets the level of the window which limits the displayed intensities.
Definition at line 63 of file picimage.cpp.
{
return (_min + _max) / 2.0;
}
float iil4mitkPicImage::levelOpacity | ( | ) | const |
Gets the level of the window which limits the displayed opacities.
Definition at line 106 of file picimage.cpp.
{
return (_minOpac + _maxOpac) / 2.0;
}
bool iil4mitkPicImage::mask | ( | ) | const |
Checks if the mask flag is set.
Definition at line 183 of file picimage.cpp.
Referenced by copyImage().
{
return _mask;
}
float iil4mitkPicImage::maximum | ( | ) | const |
Gets the maximal intensity which will be displayed.
Definition at line 57 of file picimage.cpp.
Referenced by setExtrema(), and setOpacityExtrema().
{
return _max;
}
float iil4mitkPicImage::maximumOpacity | ( | ) | const |
Gets the maximal opacity which will be displayed.
Definition at line 100 of file picimage.cpp.
{
return _maxOpac;
}
float iil4mitkPicImage::minimum | ( | ) | const |
Gets the minimal intensity which will be displayed.
Definition at line 51 of file picimage.cpp.
Referenced by setExtrema(), and setOpacityExtrema().
{
return _min;
}
float iil4mitkPicImage::minimumOpacity | ( | ) | const |
Gets the minimal opacity which will be displayed.
Definition at line 94 of file picimage.cpp.
{
return _minOpac;
}
bool iil4mitkPicImage::outline | ( | ) | const |
Checks if the outline flag is set.
Definition at line 165 of file picimage.cpp.
{
return _outline;
}
void iil4mitkPicImage::setBinary | ( | const bool | on ) |
Sets the binary flag which forces the data to be converted into a binary image.
Definition at line 130 of file picimage.cpp.
References iil4mitkImage::invalidateTextures().
Referenced by mitk::ImageMapperGL2D::ApplyProperties().
{ if (_binary != on) { if (on) { _mask = false; } _binary = on; invalidateTextures (); } }
void iil4mitkPicImage::setColors | ( | const unsigned char * | colors ) |
Sets the color map which assigns each intensity a color according to the color model.
colors | the array of colors using either the RGB format or RGBA format which depends on the color model. |
Definition at line 118 of file picimage.cpp.
References colors().
Referenced by mitk::ImageMapperGL2D::ApplyProperties().
{ _colors = colors; }
void iil4mitkPicImage::setExtrema | ( | const float | minimum, |
const float | maximum | ||
) |
Sets the range of the intensities which will be displayed.
minimum | the minimal intensity |
maximum | the maximal intensity |
Definition at line 32 of file picimage.cpp.
References iil4mitkImage::invalidateTextures(), maximum(), and minimum().
Referenced by mitk::ImageMapperGL2D::ApplyProperties().
{ // assert (minimum < maximum); _min = minimum; _max = maximum; invalidateTextures (); }
void iil4mitkPicImage::setImage | ( | mitkIpPicDescriptor * | pic, |
int | model = INTENSITY |
||
) |
Sets the PIC image.
pic | the PIC image |
model | the color model |
Definition at line 16 of file picimage.cpp.
Referenced by mitk::ImageMapperGL2D::GenerateData().
{ assert (pic); assert (pic->dim >= 2); _pic = pic; iil4mitkImage::setImage (pic->n[0], pic->n[1], model, (unsigned char *) pic->data); }
void iil4mitkPicImage::setMask | ( | const bool | on ) |
Sets the mask flag which ensures that only pixels are displayed which are in the intensity window.
Definition at line 171 of file picimage.cpp.
References iil4mitkImage::invalidateTextures().
{ if (_mask != on) { if (on) { _binary = false; } _mask = on; invalidateTextures (); } }
void iil4mitkPicImage::setOpacityExtrema | ( | const float | minimum, |
const float | maximum | ||
) |
Sets the range of opacity values which will be displayed.
minimum | the minimal opacity |
maximum | the maximal opacity |
Definition at line 75 of file picimage.cpp.
References iil4mitkImage::invalidateTextures(), maximum(), and minimum().
Referenced by mitk::ImageMapperGL2D::ApplyProperties().
{ // assert (minimum < maximum); _minOpac = minimum; _maxOpac = maximum; invalidateTextures (); }
void iil4mitkPicImage::setOpacityWindow | ( | const float | level, |
const float | window | ||
) |
Sets the range of the opacities which will be displayed.
level | the level of the window |
window | the width of the window |
Definition at line 85 of file picimage.cpp.
References iil4mitkImage::invalidateTextures(), and window().
{ // assert (window > 0); _minOpac = level - window / 2.0; _maxOpac = _minOpac + window; invalidateTextures (); }
void iil4mitkPicImage::setOutline | ( | const bool | on ) |
Sets the outline flag which forces the data to be displayed as outline. Only possible with binary data!
Definition at line 148 of file picimage.cpp.
Referenced by mitk::ImageMapperGL2D::ApplyProperties().
{
if (_binary) {
_outline = on;
}
}
void iil4mitkPicImage::setOutlineWidth | ( | float | width ) |
Sets the line width used to draw the binary outline. Requires the outline flag to be set via setOutline(true) first.
Definition at line 156 of file picimage.cpp.
References iil4mitkImage::width().
Referenced by mitk::ImageMapperGL2D::ApplyProperties().
{ if (_binary) { _outlineWidth = width; } }
void iil4mitkPicImage::setWindow | ( | const float | level, |
const float | window | ||
) |
Sets the range of the intensities which will be displayed.
level | the level of the window |
window | the width of the window |
Definition at line 42 of file picimage.cpp.
References iil4mitkImage::invalidateTextures(), and window().
{ // assert (window > 0); _min = level - window / 2.0; _max = _min + window; invalidateTextures (); }
float iil4mitkPicImage::window | ( | ) | const |
Gets the width of the window which limits the displayed intensities.
Definition at line 69 of file picimage.cpp.
Referenced by setOpacityWindow(), and setWindow().
{
return (_max - _min);
}
float iil4mitkPicImage::windowOpacity | ( | ) | const |
Gets the width of the window which limits the displayed opacities.
Definition at line 112 of file picimage.cpp.
{
return (_maxOpac - _minOpac);
}