Public Types | Public Member Functions | Protected Attributes

mitk::SimpleHistogram Class Reference

#include <QmitkTransferFunctionCanvas.h>

List of all members.

Public Types

typedef itk::Image< short, 3 > CTImage
typedef
itk::ImageRegionIterator
< CTImage
CTIteratorType
typedef
itk::ImageRegionIteratorWithIndex
< CTImage
CTIteratorIndexType
typedef itk::Image< unsigned
char, 3 > 
BinImage
typedef
itk::ImageRegionIterator
< BinImage
BinIteratorType
typedef
itk::ImageRegionIteratorWithIndex
< BinImage
BinIteratorIndexType
typedef unsigned long CountType

Public Member Functions

 SimpleHistogram ()
 ~SimpleHistogram ()
int GetMin ()
int GetMax ()
void ComputeFromImage (Image::Pointer source)
float GetRelativeBin (float start, float end)

Protected Attributes

CountTypehistogram
bool valid
int first
int last
int min
int max
CountType highest
double invLogHighest

Detailed Description

Definition at line 38 of file QmitkTransferFunctionCanvas.h.


Member Typedef Documentation

typedef itk::Image<unsigned char, 3> mitk::SimpleHistogram::BinImage

Definition at line 58 of file QmitkTransferFunctionCanvas.h.

typedef itk::ImageRegionIteratorWithIndex< BinImage > mitk::SimpleHistogram::BinIteratorIndexType

Definition at line 60 of file QmitkTransferFunctionCanvas.h.

typedef itk::ImageRegionIterator< BinImage > mitk::SimpleHistogram::BinIteratorType

Definition at line 59 of file QmitkTransferFunctionCanvas.h.

typedef unsigned long mitk::SimpleHistogram::CountType

Definition at line 62 of file QmitkTransferFunctionCanvas.h.

Definition at line 54 of file QmitkTransferFunctionCanvas.h.

typedef itk::ImageRegionIteratorWithIndex< CTImage > mitk::SimpleHistogram::CTIteratorIndexType

Definition at line 56 of file QmitkTransferFunctionCanvas.h.

typedef itk::ImageRegionIterator< CTImage > mitk::SimpleHistogram::CTIteratorType

Definition at line 55 of file QmitkTransferFunctionCanvas.h.


Constructor & Destructor Documentation

mitk::SimpleHistogram::SimpleHistogram (  ) [inline]

Definition at line 42 of file QmitkTransferFunctionCanvas.h.

  {
    valid=false;
    histogram=0;
  }
mitk::SimpleHistogram::~SimpleHistogram (  ) [inline]

Definition at line 48 of file QmitkTransferFunctionCanvas.h.

  {
    if(histogram)
      delete histogram;
  }

Member Function Documentation

void mitk::SimpleHistogram::ComputeFromImage ( Image::Pointer  source )

Definition at line 26 of file QmitkTransferFunctionCanvas.cpp.

References first, highest, histogram, invLogHighest, last, QuadProgPP::log(), max, min, MITK_WARN, QuadProgPP::t(), and valid.

Referenced by mitk::SimpleHistogramCache::operator[]().

{
  valid = false;

  // dummy histogram
  {
    min=0;
    max=1;
    first=0;
    last=1;
  }

   {
    int typInt=0;
    {
      const std::type_info* typ=source->GetPixelType().GetTypeId();
      if     (*typ == typeid(unsigned char )) typInt=0;
      else if(*typ == typeid(signed char   )) typInt=1;
      else if(*typ == typeid(unsigned short)) typInt=2;
      else if(*typ == typeid(signed short  )) typInt=3;
      else
      {
        MITK_WARN << "SimpleHistogram currently only supports un/signed char/short";
        return;
      }
    }


    first=-32768;  last=65535; // support at least full signed and unsigned short range

    if(histogram)
      delete histogram;

    histogram = new CountType[last-first+1];
    memset(histogram,0,sizeof(CountType)*(last-first+1));
    highest = 0;
    max = first - 1;
    min = last + 1;

    unsigned int num=1;
    for(unsigned int r=0;r<source->GetDimension();r++)
      num*=source->GetDimension(r);

   // MITK_INFO << "building histogramm of integer image: 0=" << source->GetDimension(0) << " 1=" << source->GetDimension(1) << " 2=" << source->GetDimension(2) << " 3=" <<  source->GetDimension(3);

    void *src=source->GetData();

    do
    {
      int value;

      switch(typInt)
      {
        case 0: { unsigned char  *t=(unsigned char *)src; value=*t++; src=(void*)t; } break;
        case 1: {   signed char  *t=(  signed char *)src; value=*t++; src=(void*)t; } break;
        case 2: { unsigned short *t=(unsigned short*)src; value=*t++; src=(void*)t; } break;
        case 3: {   signed short *t=(  signed short*)src; value=*t++; src=(void*)t; } break;
      }

      if(value >= first && value <= last)
      {
        if(value < min) min = value;
        if(value > max) max = value;
        CountType tmp = ++histogram[value-first];
        if(tmp > highest) highest = tmp;
      }
    }
    while(--num);

    //MITK_INFO << "histogramm computed: min=" << min << " max=" << max << " highestBin=" << highest << " samples=" << num;
  }

  invLogHighest = 1.0/log(double(highest));
  valid = true;
}
int mitk::SimpleHistogram::GetMax (  ) [inline]

Definition at line 87 of file QmitkTransferFunctionCanvas.h.

References QuadProgPP::max().

Referenced by QmitkTransferFunctionWidget::SetDataNode().

  {
    if(!valid)
      return 1;
      
    return max;
  }
int mitk::SimpleHistogram::GetMin (  ) [inline]

Definition at line 79 of file QmitkTransferFunctionCanvas.h.

References min.

Referenced by QmitkTransferFunctionWidget::SetDataNode().

  {
    if(!valid)
      return 0;
      
    return min;
  }
float mitk::SimpleHistogram::GetRelativeBin ( float  start,
float  end 
)

Definition at line 103 of file QmitkTransferFunctionCanvas.cpp.

References QuadProgPP::log().

Referenced by QmitkTransferFunctionCanvas::PaintHistogram().

{
  if( !valid )
    return 0.0f;

  int iLeft = floorf(left);
  int iRight = ceilf(right);

 /*
  double sum = 0;

  for( int r = 0 ; r < 256 ; r++)
  {
    int pos = left + (right-left) * r/255.0;
    int posInArray = floorf(pos+0.5f) - first;
    sum += float(log(double(histogram[posInArray])));
  }

  sum /= 256.0;
  return float(sum*invLogHighest);
 */

  CountType maximum = 0;

  for( int i = iLeft; i <= iRight ; i++)
  {
    int posInArray = i - first;
    if( histogram[posInArray] > maximum ) maximum = histogram[posInArray];
  }

  return float(log(double(maximum))*invLogHighest);




}

Member Data Documentation

Definition at line 70 of file QmitkTransferFunctionCanvas.h.

Referenced by ComputeFromImage().

Definition at line 74 of file QmitkTransferFunctionCanvas.h.

Referenced by ComputeFromImage().

Definition at line 66 of file QmitkTransferFunctionCanvas.h.

Referenced by ComputeFromImage().

Definition at line 75 of file QmitkTransferFunctionCanvas.h.

Referenced by ComputeFromImage().

int mitk::SimpleHistogram::last [protected]

Definition at line 71 of file QmitkTransferFunctionCanvas.h.

Referenced by ComputeFromImage().

int mitk::SimpleHistogram::max [protected]

Definition at line 73 of file QmitkTransferFunctionCanvas.h.

Referenced by ComputeFromImage().

int mitk::SimpleHistogram::min [protected]

Definition at line 72 of file QmitkTransferFunctionCanvas.h.

Referenced by ComputeFromImage().

bool mitk::SimpleHistogram::valid [protected]

Definition at line 68 of file QmitkTransferFunctionCanvas.h.

Referenced by ComputeFromImage().


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines