Public Member Functions | Protected Attributes

QmitkColorTransferFunctionCanvas Class Reference

#include <QmitkColorTransferFunctionCanvas.h>

Inheritance diagram for QmitkColorTransferFunctionCanvas:
Inheritance graph
[legend]
Collaboration diagram for QmitkColorTransferFunctionCanvas:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 QmitkColorTransferFunctionCanvas (QWidget *parent=0, Qt::WindowFlags f=0)
virtual void paintEvent (QPaintEvent *e)
int GetNearHandle (int x, int y, unsigned int maxSquaredDistance=32)
void SetTitle (std::string title)
void SetColorTransferFunction (vtkColorTransferFunction *colorTransferFunction)
void AddFunctionPoint (vtkFloatingPointType x, vtkFloatingPointType)
void RemoveFunctionPoint (vtkFloatingPointType x)
vtkFloatingPointType GetFunctionX (int index)
int GetFunctionSize ()
void DoubleClickOnHandle (int handle)
void MoveFunctionPoint (int index, std::pair< vtkFloatingPointType, vtkFloatingPointType > pos)
void AddRGB (double x, double r, double g, double b)
double GetFunctionMax ()
double GetFunctionMin ()
double GetFunctionRange ()
void RemoveAllFunctionPoints ()
float GetFunctionY (int)

Protected Attributes

vtkColorTransferFunction * m_ColorTransferFunction
std::string m_Title

Detailed Description

Definition at line 26 of file QmitkColorTransferFunctionCanvas.h.


Constructor & Destructor Documentation

QmitkColorTransferFunctionCanvas::QmitkColorTransferFunctionCanvas ( QWidget *  parent = 0,
Qt::WindowFlags  f = 0 
)

Definition at line 24 of file QmitkColorTransferFunctionCanvas.cpp.

                                       :
  QmitkTransferFunctionCanvas(parent, f), m_ColorTransferFunction(0)
{
  // used for drawing a border
  setContentsMargins(1,1,1,1);
}

Member Function Documentation

void QmitkColorTransferFunctionCanvas::AddFunctionPoint ( vtkFloatingPointType  x,
vtkFloatingPointType   
) [inline, virtual]

Implements QmitkTransferFunctionCanvas.

Definition at line 46 of file QmitkColorTransferFunctionCanvas.h.

  {
    m_ColorTransferFunction->AddRGBPoint(x,m_ColorTransferFunction->GetRedValue(x),m_ColorTransferFunction->GetGreenValue(x),m_ColorTransferFunction->GetBlueValue(x));
  };
void QmitkColorTransferFunctionCanvas::AddRGB ( double  x,
double  r,
double  g,
double  b 
)

Definition at line 168 of file QmitkColorTransferFunctionCanvas.cpp.

References m_ColorTransferFunction.

{
  m_ColorTransferFunction->AddRGBPoint(x, r, g, b);
}
void QmitkColorTransferFunctionCanvas::DoubleClickOnHandle ( int  handle ) [virtual]

Implements QmitkTransferFunctionCanvas.

Definition at line 143 of file QmitkColorTransferFunctionCanvas.cpp.

References GetFunctionX(), mitk::RenderingManager::GetInstance(), and m_ColorTransferFunction.

{
  vtkFloatingPointType xVal = GetFunctionX(handle);
  QColor col((int) (m_ColorTransferFunction->GetRedValue(xVal) * 255),
      (int) (m_ColorTransferFunction->GetGreenValue(xVal) * 255),
      (int) (m_ColorTransferFunction->GetBlueValue(xVal) * 255));
  QColor result = QColorDialog::getColor(col);
  if (result.isValid())
  {
    m_ColorTransferFunction->AddRGBPoint(xVal, result.red() / 255.0,
        result.green() / 255.0, result.blue() / 255.0);
    this->update();
    mitk::RenderingManager::GetInstance()->RequestUpdateAll();
  }
}
double QmitkColorTransferFunctionCanvas::GetFunctionMax (  ) [inline]

Definition at line 77 of file QmitkColorTransferFunctionCanvas.h.

  {
    return m_ColorTransferFunction->GetRange()[1];
  }
double QmitkColorTransferFunctionCanvas::GetFunctionMin (  ) [inline]

Definition at line 82 of file QmitkColorTransferFunctionCanvas.h.

  {
    return m_ColorTransferFunction->GetRange()[0];
  }
double QmitkColorTransferFunctionCanvas::GetFunctionRange (  ) [inline]

Definition at line 87 of file QmitkColorTransferFunctionCanvas.h.

  {
    double range;
    if((m_ColorTransferFunction->GetRange()[0])==0)
    {
      range = m_ColorTransferFunction->GetRange()[1];
      return range;
    }
    else
    {
      range = (m_ColorTransferFunction->GetRange()[1])-(m_ColorTransferFunction->GetRange()[0]);
      return range;
    }
  }
int QmitkColorTransferFunctionCanvas::GetFunctionSize (  ) [inline, virtual]

Implements QmitkTransferFunctionCanvas.

Definition at line 67 of file QmitkColorTransferFunctionCanvas.h.

Referenced by GetNearHandle(), and paintEvent().

  {
    return m_ColorTransferFunction->GetSize();
  }
vtkFloatingPointType QmitkColorTransferFunctionCanvas::GetFunctionX ( int  index ) [inline, virtual]

Implements QmitkTransferFunctionCanvas.

Definition at line 62 of file QmitkColorTransferFunctionCanvas.h.

Referenced by DoubleClickOnHandle(), GetNearHandle(), MoveFunctionPoint(), and paintEvent().

  {
    return m_ColorTransferFunction->GetDataPointer()[index*4];
  }
float QmitkColorTransferFunctionCanvas::GetFunctionY ( int   ) [inline, virtual]

Implements QmitkTransferFunctionCanvas.

Definition at line 107 of file QmitkColorTransferFunctionCanvas.h.

  {
    return 0.0;
  }
int QmitkColorTransferFunctionCanvas::GetNearHandle ( int  x,
int  y,
unsigned int  maxSquaredDistance = 32 
) [virtual]

returns index of a near handle or -1 if none is near

Implements QmitkTransferFunctionCanvas.

Definition at line 127 of file QmitkColorTransferFunctionCanvas.cpp.

References QmitkTransferFunctionCanvas::FunctionToCanvas(), GetFunctionSize(), and GetFunctionX().

{
  for (int i = 0; i < this->GetFunctionSize(); i++)
  {
    std::pair<int,int> point = this->FunctionToCanvas(std::make_pair(
        GetFunctionX(i), (vtkFloatingPointType) 0.0));
    if ((unsigned int) ((point.first - x) * (point.first - x))
        < maxSquaredDistance)
    {
      return i;
    }
  }
  return -1;
}
void QmitkColorTransferFunctionCanvas::MoveFunctionPoint ( int  index,
std::pair< vtkFloatingPointType, vtkFloatingPointType >  pos 
) [virtual]

Implements QmitkTransferFunctionCanvas.

Definition at line 159 of file QmitkColorTransferFunctionCanvas.cpp.

References GetFunctionX(), m_ColorTransferFunction, and RemoveFunctionPoint().

{
  vtkFloatingPointType color[3];
  m_ColorTransferFunction->GetColor(GetFunctionX(index), color);
  RemoveFunctionPoint( GetFunctionX(index));
  m_ColorTransferFunction->AddRGBPoint(pos.first, color[0], color[1], color[2]);
}
void QmitkColorTransferFunctionCanvas::paintEvent ( QPaintEvent *  e ) [virtual]

Reimplemented from QmitkTransferFunctionCanvas.

Definition at line 38 of file QmitkColorTransferFunctionCanvas.cpp.

References QmitkTransferFunctionCanvas::FunctionToCanvas(), GetFunctionSize(), GetFunctionX(), m_ColorTransferFunction, QmitkTransferFunctionCanvas::m_GrabbedHandle, QmitkTransferFunctionCanvas::m_LineEditAvailable, QmitkTransferFunctionCanvas::m_Max, QmitkTransferFunctionCanvas::m_Min, m_Title, and QmitkTransferFunctionCanvas::m_XEdit.

{
  QPainter painter(this);

  // Render gray background
  QRect contentsRect = this->contentsRect();
  painter.setPen(Qt::gray);
  painter.drawRect(0, 0, contentsRect.width()+1, contentsRect.height()+1);

  if( ! this->isEnabled() )
    return;
 
  if (m_ColorTransferFunction)
  {
    for (int x = contentsRect.x(); x < contentsRect.x() + contentsRect.width(); x++)
    {
      vtkFloatingPointType xVal = m_Min + ((float) x) / contentsRect.width() * (m_Max
          - m_Min);
      QColor col((int) (m_ColorTransferFunction->GetRedValue(xVal) * 255),
          (int) (m_ColorTransferFunction->GetGreenValue(xVal) * 255),
          (int) (m_ColorTransferFunction->GetBlueValue(xVal) * 255));
      painter.setPen(col);
      painter.drawLine(x, 1, x, contentsRect.height());
    }
  }
 
 //paint title
  if (m_Title.size()>0)
  {
    painter.setPen(Qt::black);
    painter.drawText(QPoint(11,21),QString( m_Title.c_str() ));
    painter.setPen(Qt::white);
    painter.drawText(QPoint(10,20),QString( m_Title.c_str() ));
  }
  
  //paint min and max
  QString qs_min = QString::number( m_Min );
  QString qs_max = QString::number( m_Max );
  
  QRect qr_min = painter.fontMetrics().boundingRect( qs_min );
  QRect qr_max = painter.fontMetrics().boundingRect( qs_max );
  
  int y,x;
    
  y=this->contentsRect().height()-qr_min.height()+5; 
  x=10; 
  
  painter.setPen(Qt::black);
  painter.drawText(QPoint(x+1,y+1),qs_min);
  painter.setPen(Qt::white);
  painter.drawText(QPoint(x  ,y  ),qs_min);

  y=this->contentsRect().height()-qr_max.height()+5; 
  x=this->contentsRect().width()-qr_max.width()-6; 

  painter.setPen(Qt::black);
  painter.drawText(QPoint(x,y+1),qs_max);
  painter.setPen(Qt::white);
  painter.drawText(QPoint(x,y  ),qs_max);
  
  if (m_ColorTransferFunction)
  {
    // now paint the handles
    painter.setBrush(Qt::black);
    painter.setPen(Qt::black);
    for (int i = 0; i < this->GetFunctionSize(); i++)
    {
      int handleHeight = (i == m_GrabbedHandle) ? (int) (contentsRect.height() / 1.5)
          : contentsRect.height() / 2;
      int handleWidth = (i == m_GrabbedHandle) ? 6 : 4;
      std::pair<int,int> point = this->FunctionToCanvas(std::make_pair(
          GetFunctionX(i), 0.0f));
      int y = height() / 2;
      painter.drawRoundRect(point.first - handleWidth / 2,
          y - handleHeight / 2, handleWidth, handleHeight, 50, 50);

      if (i == m_GrabbedHandle)
      {
        if (m_LineEditAvailable)
        {
          m_XEdit->setText(QString::number(GetFunctionX(m_GrabbedHandle)));
          //m_YEdit->setText(QString::number(GetFunctionY(m_GrabbedHandle)));
        }
      }
      
    }
  }
}
void QmitkColorTransferFunctionCanvas::RemoveAllFunctionPoints (  ) [inline]

Definition at line 102 of file QmitkColorTransferFunctionCanvas.h.

  {
    m_ColorTransferFunction->AddRGBSegment(this->GetFunctionMin(),1,0,0,this->GetFunctionMax(),1,1,0);
  }
void QmitkColorTransferFunctionCanvas::RemoveFunctionPoint ( vtkFloatingPointType  x ) [inline, virtual]

Implements QmitkTransferFunctionCanvas.

Definition at line 51 of file QmitkColorTransferFunctionCanvas.h.

References QmitkTransferFunctionCanvas::GetFunctionSize().

Referenced by MoveFunctionPoint().

  {
    int old_size = GetFunctionSize();
    m_ColorTransferFunction->RemovePoint(x);
    if (GetFunctionSize() + 1 != old_size)
    {
      std::cout << "old/new size" << old_size << "/" << GetFunctionSize() << std::endl;
      std::cout << "called with x=" << x << std::endl;
    }
  };
void QmitkColorTransferFunctionCanvas::SetColorTransferFunction ( vtkColorTransferFunction *  colorTransferFunction ) [inline]

Definition at line 37 of file QmitkColorTransferFunctionCanvas.h.

References QmitkTransferFunctionCanvas::SetMax(), and QmitkTransferFunctionCanvas::SetMin().

Referenced by QmitkTransferFunctionWidget::OnUpdateCanvas().

  {
    this->m_ColorTransferFunction = colorTransferFunction;
    this->SetMin(colorTransferFunction->GetRange()[0]);
    this->SetMax(colorTransferFunction->GetRange()[1]);
    setEnabled(true);
    update();
  };
void QmitkColorTransferFunctionCanvas::SetTitle ( std::string  title )

Member Data Documentation

vtkColorTransferFunction* QmitkColorTransferFunctionCanvas::m_ColorTransferFunction [protected]

Definition at line 115 of file QmitkColorTransferFunctionCanvas.h.

Referenced by paintEvent(), and SetTitle().


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