Public Member Functions | Static Public Member Functions | Public Attributes | Protected Attributes

QmitkTransferFunctionCanvas Class Reference

#include <QmitkTransferFunctionCanvas.h>

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

List of all members.

Public Member Functions

 QmitkTransferFunctionCanvas (QWidget *parent=0, Qt::WindowFlags f=0)
mitk::SimpleHistogramGetHistogram ()
void SetHistogram (mitk::SimpleHistogram *histogram)
vtkFloatingPointType GetMin ()
void SetMin (vtkFloatingPointType min)
vtkFloatingPointType GetMax ()
void SetMax (vtkFloatingPointType max)
vtkFloatingPointType GetLower ()
void SetLower (vtkFloatingPointType lower)
vtkFloatingPointType GetUpper ()
void SetUpper (vtkFloatingPointType upper)
void mousePressEvent (QMouseEvent *mouseEvent)
virtual void paintEvent (QPaintEvent *e)
virtual void DoubleClickOnHandle (int handle)=0
void mouseMoveEvent (QMouseEvent *mouseEvent)
void mouseReleaseEvent (QMouseEvent *mouseEvent)
void mouseDoubleClickEvent (QMouseEvent *mouseEvent)
void PaintHistogram (QPainter &p)
virtual int GetNearHandle (int x, int y, unsigned int maxSquaredDistance=32)=0
virtual void AddFunctionPoint (vtkFloatingPointType x, vtkFloatingPointType val)=0
virtual void RemoveFunctionPoint (vtkFloatingPointType x)=0
virtual void MoveFunctionPoint (int index, std::pair< vtkFloatingPointType, vtkFloatingPointType > pos)=0
virtual vtkFloatingPointType GetFunctionX (int index)=0
virtual float GetFunctionY (int index)=0
virtual int GetFunctionSize ()=0
std::pair< int, int > FunctionToCanvas (std::pair< vtkFloatingPointType, vtkFloatingPointType >)
std::pair
< vtkFloatingPointType,
vtkFloatingPointType > 
CanvasToFunction (std::pair< int, int >)
void keyPressEvent (QKeyEvent *e)
void SetImmediateUpdate (bool state)
void SetX (float x)
void SetY (float y)
void SetQLineEdits (QLineEdit *xEdit, QLineEdit *yEdit)

Static Public Member Functions

static std::pair
< vtkFloatingPointType,
vtkFloatingPointType > 
ValidateCoord (std::pair< vtkFloatingPointType, vtkFloatingPointType > x)

Public Attributes

int m_GrabbedHandle
vtkFloatingPointType m_Lower
vtkFloatingPointType m_Upper
vtkFloatingPointType m_Min
vtkFloatingPointType m_Max
mitk::SimpleHistogramm_Histogram

Protected Attributes

bool m_ImmediateUpdate
float m_Range
bool m_LineEditAvailable
QLineEdit * m_XEdit
QLineEdit * m_YEdit

Detailed Description

Definition at line 204 of file QmitkTransferFunctionCanvas.h.


Constructor & Destructor Documentation

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

Definition at line 141 of file QmitkTransferFunctionCanvas.cpp.

References m_LineEditAvailable.

                     :
  QWidget(parent, f), m_GrabbedHandle(-1), m_Lower(0.0f), m_Upper(1.0f), m_Min(
      0.0f), m_Max(1.0f)
{
  setEnabled(false);
  setFocusPolicy(Qt::ClickFocus);
  m_LineEditAvailable = false;
}

Member Function Documentation

virtual void QmitkTransferFunctionCanvas::AddFunctionPoint ( vtkFloatingPointType  x,
vtkFloatingPointType  val 
) [pure virtual]
std::pair< vtkFloatingPointType, vtkFloatingPointType > QmitkTransferFunctionCanvas::CanvasToFunction ( std::pair< int, int >  canvasPoint )

Definition at line 164 of file QmitkTransferFunctionCanvas.cpp.

References m_Lower, and m_Upper.

Referenced by mouseMoveEvent(), and mousePressEvent().

{
  //std::cout<<"C2F.first: "<<(canvasPoint.first * (m_Upper - m_Lower) / width() + m_Lower)<<" C2F.second: "<<(1.0 - (vtkFloatingPointType)canvasPoint.second / height())<<std::endl;
  return std::make_pair((canvasPoint.first - contentsRect().x()) * (m_Upper - m_Lower) / contentsRect().width()
      + m_Lower, 1.0 - (vtkFloatingPointType) (canvasPoint.second - contentsRect().y()) / contentsRect().height());
}
virtual void QmitkTransferFunctionCanvas::DoubleClickOnHandle ( int  handle ) [pure virtual]
std::pair< int, int > QmitkTransferFunctionCanvas::FunctionToCanvas ( std::pair< vtkFloatingPointType, vtkFloatingPointType >  functionPoint )

Definition at line 156 of file QmitkTransferFunctionCanvas.cpp.

References m_Lower, and m_Upper.

Referenced by QmitkPiecewiseFunctionCanvas::GetNearHandle(), QmitkColorTransferFunctionCanvas::GetNearHandle(), QmitkPiecewiseFunctionCanvas::paintEvent(), and QmitkColorTransferFunctionCanvas::paintEvent().

{
  //std::cout<<"F2C.first: "<<(int)((functionPoint.first - m_Lower) /  (m_Upper - m_Lower) * width())<<" F2C.second: "<<(int)(height() * (1 - functionPoint.second))<<std::endl;
  return std::make_pair((int) ((functionPoint.first - m_Lower) / (m_Upper
      - m_Lower) * contentsRect().width()) + contentsRect().x(), (int) (contentsRect().height() * (1 - functionPoint.second)) + contentsRect().y());
}
virtual int QmitkTransferFunctionCanvas::GetFunctionSize (  ) [pure virtual]
virtual vtkFloatingPointType QmitkTransferFunctionCanvas::GetFunctionX ( int  index ) [pure virtual]
virtual float QmitkTransferFunctionCanvas::GetFunctionY ( int  index ) [pure virtual]
mitk::SimpleHistogram* QmitkTransferFunctionCanvas::GetHistogram (  ) [inline]

Definition at line 213 of file QmitkTransferFunctionCanvas.h.

  {
    return m_Histogram;
  }
vtkFloatingPointType QmitkTransferFunctionCanvas::GetLower (  ) [inline]

Definition at line 245 of file QmitkTransferFunctionCanvas.h.

  {
    return m_Lower;
  }
vtkFloatingPointType QmitkTransferFunctionCanvas::GetMax (  ) [inline]

Definition at line 234 of file QmitkTransferFunctionCanvas.h.

  {
    return m_Max;
  }
vtkFloatingPointType QmitkTransferFunctionCanvas::GetMin (  ) [inline]

Definition at line 223 of file QmitkTransferFunctionCanvas.h.

  {
    return m_Min;
  }
int QmitkTransferFunctionCanvas::GetNearHandle ( int  x,
int  y,
unsigned int  maxSquaredDistance = 32 
) [pure virtual]

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

Implemented in QmitkColorTransferFunctionCanvas, and QmitkPiecewiseFunctionCanvas.

Definition at line 183 of file QmitkTransferFunctionCanvas.cpp.

Referenced by mouseDoubleClickEvent(), and mousePressEvent().

{
  return -1;
}
vtkFloatingPointType QmitkTransferFunctionCanvas::GetUpper (  ) [inline]

Definition at line 255 of file QmitkTransferFunctionCanvas.h.

  {
    return m_Upper;
  }
void QmitkTransferFunctionCanvas::keyPressEvent ( QKeyEvent *  e )
void QmitkTransferFunctionCanvas::mouseDoubleClickEvent ( QMouseEvent *  mouseEvent )

Definition at line 172 of file QmitkTransferFunctionCanvas.cpp.

References DoubleClickOnHandle(), and GetNearHandle().

{
  int nearHandle = GetNearHandle(mouseEvent->pos().x(), mouseEvent->pos().y());
  if (nearHandle != -1)
  {
    this->DoubleClickOnHandle(nearHandle);
  }
}
void QmitkTransferFunctionCanvas::mouseMoveEvent ( QMouseEvent *  mouseEvent )

Definition at line 223 of file QmitkTransferFunctionCanvas.cpp.

References CanvasToFunction(), GetFunctionSize(), mitk::RenderingManager::GetInstance(), m_GrabbedHandle, m_Max, m_Min, and MoveFunctionPoint().

{
  if (m_GrabbedHandle != -1)
  {
    std::pair<vtkFloatingPointType,vtkFloatingPointType>
        newPos = this->CanvasToFunction(std::make_pair(mouseEvent->x(),
            mouseEvent->y()));

    // X Clamping
    {
      // Check with predecessor
      if( m_GrabbedHandle > 0 )
        if (newPos.first <= this->GetFunctionX(m_GrabbedHandle - 1))
          newPos.first = this->GetFunctionX(m_GrabbedHandle);

      // Check with sucessor
      if( m_GrabbedHandle < this->GetFunctionSize()-1 )
        if (newPos.first >= this->GetFunctionX(m_GrabbedHandle + 1))
          newPos.first = this->GetFunctionX(m_GrabbedHandle);

      // Clamping to histogramm
           if (newPos.first < m_Min) newPos.first = m_Min;
      else if (newPos.first > m_Max) newPos.first = m_Max;
    }

    // Y Clamping
    {
           if (newPos.second < 0.0) newPos.second = 0.0;
      else if (newPos.second > 1.0) newPos.second = 1.0;
    }

    // Move selected point
    this->MoveFunctionPoint(m_GrabbedHandle, newPos);

    /*
    // Search again selected point ??????? should not be required, seems like a legacy workaround/bugfix
    // and no longer required
    m_GrabbedHandle = -1;
    for (int i = 0; i < this->GetFunctionSize(); i++)
    {
      if (this->GetFunctionX(i) == newPos.first)
      {
        m_GrabbedHandle = i;
        break;
      }
    }
    */

    update();

    //if (m_ImmediateUpdate)
      mitk::RenderingManager::GetInstance()->RequestUpdateAll();

  }
}
void QmitkTransferFunctionCanvas::mousePressEvent ( QMouseEvent *  mouseEvent )

Definition at line 190 of file QmitkTransferFunctionCanvas.cpp.

References AddFunctionPoint(), CanvasToFunction(), GetFunctionSize(), GetFunctionX(), mitk::RenderingManager::GetInstance(), GetNearHandle(), m_GrabbedHandle, m_LineEditAvailable, m_XEdit, m_YEdit, and RemoveFunctionPoint().

{

  if (m_LineEditAvailable)
  {
    m_XEdit->clear();
    if(m_YEdit)
      m_YEdit->clear();
  }

  m_GrabbedHandle = GetNearHandle(mouseEvent->pos().x(), mouseEvent->pos().y());

  if ( (mouseEvent->button() & Qt::LeftButton) && m_GrabbedHandle == -1)
  {
    this->AddFunctionPoint(
        this->CanvasToFunction(std::make_pair(mouseEvent->pos().x(),
            mouseEvent->pos().y())).first,
        this->CanvasToFunction(std::make_pair(mouseEvent->x(), mouseEvent->y())).second);
    m_GrabbedHandle = GetNearHandle(mouseEvent->pos().x(),
        mouseEvent->pos().y());
    mitk::RenderingManager::GetInstance()->RequestUpdateAll();
  }
  else if ((mouseEvent->button() & Qt::RightButton) && m_GrabbedHandle != -1 && this->GetFunctionSize() > 1)
  {
     this->RemoveFunctionPoint(this->GetFunctionX(m_GrabbedHandle));
     m_GrabbedHandle = -1;
     mitk::RenderingManager::GetInstance()->RequestUpdateAll();
  }
  update();

  // m_TransferFunction->UpdateVtkFunctions();
}
void QmitkTransferFunctionCanvas::mouseReleaseEvent ( QMouseEvent *  mouseEvent )

Definition at line 279 of file QmitkTransferFunctionCanvas.cpp.

References mitk::RenderingManager::GetInstance().

{
  // m_GrabbedHandle = -1;
  update();
  mitk::RenderingManager::GetInstance()->RequestUpdateAll();
}
virtual void QmitkTransferFunctionCanvas::MoveFunctionPoint ( int  index,
std::pair< vtkFloatingPointType, vtkFloatingPointType >  pos 
) [pure virtual]
void QmitkTransferFunctionCanvas::paintEvent ( QPaintEvent *  e ) [virtual]
void QmitkTransferFunctionCanvas::PaintHistogram ( QPainter &  p )

Definition at line 286 of file QmitkTransferFunctionCanvas.cpp.

References mitk::SimpleHistogram::GetRelativeBin(), m_Histogram, m_Lower, and m_Upper.

Referenced by QmitkPiecewiseFunctionCanvas::paintEvent().

{
  if(m_Histogram)
  {
    p.save();

    p.setPen(Qt::gray);

    int displayWidth = contentsRect().width();
    int displayHeight = contentsRect().height();

    int windowLeft = m_Lower;
    int windowRight = m_Upper;

    double step = (windowRight-windowLeft)/double(displayWidth);

    double pos = windowLeft;

    for (int x = 0; x < displayWidth; x++)
    {
      float left = pos;
      float right = pos + step;

      float height = m_Histogram->GetRelativeBin( left , right );

      if (height >= 0)
        p.drawLine(x, displayHeight*(1-height), x, displayHeight);

      pos += step;
    }

    p.restore();
  }
}
virtual void QmitkTransferFunctionCanvas::RemoveFunctionPoint ( vtkFloatingPointType  x ) [pure virtual]
void QmitkTransferFunctionCanvas::SetHistogram ( mitk::SimpleHistogram histogram ) [inline]

Definition at line 218 of file QmitkTransferFunctionCanvas.h.

Referenced by QmitkTransferFunctionWidget::SetDataNode().

  {
    m_Histogram = histogram;
  }
void QmitkTransferFunctionCanvas::SetImmediateUpdate ( bool  state )

Definition at line 361 of file QmitkTransferFunctionCanvas.cpp.

References m_ImmediateUpdate.

{
  m_ImmediateUpdate = state;
}
void QmitkTransferFunctionCanvas::SetLower ( vtkFloatingPointType  lower ) [inline]

Definition at line 250 of file QmitkTransferFunctionCanvas.h.

  {
    this->m_Lower = lower;
  }
void QmitkTransferFunctionCanvas::SetMax ( vtkFloatingPointType  max ) [inline]
void QmitkTransferFunctionCanvas::SetMin ( vtkFloatingPointType  min ) [inline]
void QmitkTransferFunctionCanvas::SetQLineEdits ( QLineEdit *  xEdit,
QLineEdit *  yEdit 
) [inline]
void QmitkTransferFunctionCanvas::SetUpper ( vtkFloatingPointType  upper ) [inline]

Definition at line 260 of file QmitkTransferFunctionCanvas.h.

  {
    this->m_Upper = upper;
  }
void QmitkTransferFunctionCanvas::SetX ( float  x ) [inline]
void QmitkTransferFunctionCanvas::SetY ( float  y ) [inline]
static std::pair<vtkFloatingPointType,vtkFloatingPointType> QmitkTransferFunctionCanvas::ValidateCoord ( std::pair< vtkFloatingPointType, vtkFloatingPointType >  x ) [inline, static]

Definition at line 297 of file QmitkTransferFunctionCanvas.h.

Referenced by keyPressEvent().

  {
    if( x.first < -2048 ) x.first = -2048;
    if( x.first >  2048 ) x.first =  2048;
    if( x.second < 0 ) x.second = 0;
    if( x.second > 1 ) x.second = 1;
    return x;
  }

Member Data Documentation

Definition at line 291 of file QmitkTransferFunctionCanvas.h.

Referenced by PaintHistogram().

Definition at line 334 of file QmitkTransferFunctionCanvas.h.

Referenced by SetImmediateUpdate().

vtkFloatingPointType QmitkTransferFunctionCanvas::m_Max
vtkFloatingPointType QmitkTransferFunctionCanvas::m_Min

Definition at line 335 of file QmitkTransferFunctionCanvas.h.

QLineEdit* QmitkTransferFunctionCanvas::m_XEdit [protected]
QLineEdit* QmitkTransferFunctionCanvas::m_YEdit [protected]

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