Medical Imaging Interaction Toolkit  2026.06.00
Medical Imaging Interaction Toolkit
QmitkTransferFunctionCanvas Class Referenceabstract

Abstract base class for transfer function editing canvases. More...

#include <QmitkTransferFunctionCanvas.h>

Inheritance diagram for QmitkTransferFunctionCanvas:
Collaboration diagram for QmitkTransferFunctionCanvas:

Public Member Functions

 QmitkTransferFunctionCanvas (QWidget *parent=nullptr, Qt::WindowFlags f={})
 Construct the transfer function canvas. More...
 
mitk::SimpleHistogram * GetHistogram ()
 Get the associated histogram. More...
 
void SetHistogram (mitk::SimpleHistogram *histogram)
 Set the histogram to display as background. More...
 
double GetMin ()
 Get the minimum scalar value of the data range. More...
 
void SetMin (double min)
 Set the minimum scalar value and update the lower display bound. More...
 
double GetMax ()
 Get the maximum scalar value of the data range. More...
 
void SetMax (double max)
 Set the maximum scalar value and update the upper display bound. More...
 
double GetLower ()
 Get the lower display bound. More...
 
void SetLower (double lower)
 Set the lower display bound (visible range start). More...
 
double GetUpper ()
 Get the upper display bound. More...
 
void SetUpper (double upper)
 Set the upper display bound (visible range end). More...
 
void mousePressEvent (QMouseEvent *mouseEvent) override
 Handle mouse press: add or remove function points, select handles. More...
 
void paintEvent (QPaintEvent *e) override
 Default paint event handler. More...
 
virtual void DoubleClickOnHandle (int handle)=0
 Called when a handle is double-clicked (e.g. to open a color dialog). More...
 
void mouseMoveEvent (QMouseEvent *mouseEvent) override
 Handle mouse move: drag the grabbed handle. More...
 
void mouseReleaseEvent (QMouseEvent *mouseEvent) override
 Handle mouse release: trigger repaint. More...
 
void mouseDoubleClickEvent (QMouseEvent *mouseEvent) override
 Handle double-click on a handle. More...
 
void PaintHistogram (QPainter &p)
 Paint the histogram as a background overlay. More...
 
virtual int GetNearHandle (int x, int y, unsigned int maxSquaredDistance=100)=0
 Find a handle near the given canvas position. More...
 
virtual int AddFunctionPoint (double x, double val)=0
 Add a function point at (x, val). More...
 
virtual void RemoveFunctionPoint (double x)=0
 Remove the function point at position x. More...
 
virtual void MoveFunctionPoint (int index, std::pair< double, double > pos)=0
 Move a function point to a new position. More...
 
virtual double GetFunctionX (int index)=0
 Get the x (scalar) value of a function point. More...
 
virtual double GetFunctionY (int index)=0
 Get the y (function) value of a function point. More...
 
virtual int GetFunctionSize ()=0
 Get the number of function points. More...
 
std::pair< int, int > FunctionToCanvas (std::pair< double, double > functionPoint)
 Convert function coordinates to canvas pixel coordinates. More...
 
std::pair< double, double > CanvasToFunction (std::pair< int, int > canvasPoint)
 Convert canvas pixel coordinates to function coordinates. More...
 
void keyPressEvent (QKeyEvent *e) override
 Handle keyboard input for point manipulation (Delete, arrow keys). More...
 
void SetImmediateUpdate (bool state)
 Enable or disable immediate rendering updates during interaction. More...
 
std::pair< double, double > ValidateCoord (std::pair< double, double > x)
 Clamp coordinates to valid histogram range and [0, 1] for y. More...
 
void SetX (float x)
 Set the x coordinate of the currently grabbed handle. More...
 
void SetY (float y)
 Set the y coordinate of the currently grabbed handle. More...
 
void SetQLineEdits (QLineEdit *xEdit, QLineEdit *yEdit)
 Connect QLineEdit widgets for displaying/editing the selected handle coordinates. More...
 

Public Attributes

int m_GrabbedHandle
 Index of the currently grabbed (selected) handle, or -1. More...
 
double m_Lower
 Lower display bound. More...
 
double m_Upper
 Upper display bound. More...
 
double m_Min
 Minimum data range value. More...
 
double m_Max
 Maximum data range value. More...
 
mitk::SimpleHistogram * m_Histogram
 The background histogram. More...
 

Protected Attributes

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

Detailed Description

Abstract base class for transfer function editing canvases.

Provides common infrastructure for interactive editing of transfer function control points: mouse-based adding, removing, and dragging of handles, histogram background rendering, coordinate conversion, keyboard navigation, and optional QLineEdit binding for precise coordinate input.

Subclasses must implement the pure virtual methods that define the specific transfer function type (color vs. piecewise).

See also
QmitkColorTransferFunctionCanvas, QmitkPiecewiseFunctionCanvas, QmitkTransferFunctionWidget

Definition at line 37 of file QmitkTransferFunctionCanvas.h.

Constructor & Destructor Documentation

◆ QmitkTransferFunctionCanvas()

QmitkTransferFunctionCanvas::QmitkTransferFunctionCanvas ( QWidget *  parent = nullptr,
Qt::WindowFlags  f = {} 
)

Construct the transfer function canvas.

Parameters
[in]parentThe parent widget.
[in]fWindow flags.

Member Function Documentation

◆ AddFunctionPoint()

virtual int QmitkTransferFunctionCanvas::AddFunctionPoint ( double  x,
double  val 
)
pure virtual

Add a function point at (x, val).

Parameters
[in]xThe scalar position.
[in]valThe function value.
Returns
The index of the added point.

Implemented in QmitkPiecewiseFunctionCanvas, and QmitkColorTransferFunctionCanvas.

◆ CanvasToFunction()

std::pair<double, double> QmitkTransferFunctionCanvas::CanvasToFunction ( std::pair< int, int >  canvasPoint)

Convert canvas pixel coordinates to function coordinates.

Parameters
[in]canvasPointThe (x, y) canvas pixel coordinates.
Returns
The (x, y) function coordinates.

◆ DoubleClickOnHandle()

virtual void QmitkTransferFunctionCanvas::DoubleClickOnHandle ( int  handle)
pure virtual

Called when a handle is double-clicked (e.g. to open a color dialog).

Parameters
[in]handleThe index of the double-clicked handle.

Implemented in QmitkPiecewiseFunctionCanvas, and QmitkColorTransferFunctionCanvas.

◆ FunctionToCanvas()

std::pair<int, int> QmitkTransferFunctionCanvas::FunctionToCanvas ( std::pair< double, double >  functionPoint)

Convert function coordinates to canvas pixel coordinates.

Parameters
[in]functionPointThe (x, y) function coordinates.
Returns
The (x, y) canvas pixel coordinates.

◆ GetFunctionSize()

virtual int QmitkTransferFunctionCanvas::GetFunctionSize ( )
pure virtual

◆ GetFunctionX()

virtual double QmitkTransferFunctionCanvas::GetFunctionX ( int  index)
pure virtual

Get the x (scalar) value of a function point.

Parameters
[in]indexThe point index.
Returns
The x value.

Implemented in QmitkPiecewiseFunctionCanvas, and QmitkColorTransferFunctionCanvas.

◆ GetFunctionY()

virtual double QmitkTransferFunctionCanvas::GetFunctionY ( int  index)
pure virtual

Get the y (function) value of a function point.

Parameters
[in]indexThe point index.
Returns
The y value.

Implemented in QmitkColorTransferFunctionCanvas, and QmitkPiecewiseFunctionCanvas.

◆ GetHistogram()

mitk::SimpleHistogram* QmitkTransferFunctionCanvas::GetHistogram ( )
inline

Get the associated histogram.

Returns
Pointer to the histogram, or nullptr.

Definition at line 53 of file QmitkTransferFunctionCanvas.h.

◆ GetLower()

double QmitkTransferFunctionCanvas::GetLower ( )
inline

Get the lower display bound.

Returns
The lower bound.

Definition at line 97 of file QmitkTransferFunctionCanvas.h.

◆ GetMax()

double QmitkTransferFunctionCanvas::GetMax ( )
inline

Get the maximum scalar value of the data range.

Returns
The maximum value.

Definition at line 81 of file QmitkTransferFunctionCanvas.h.

◆ GetMin()

double QmitkTransferFunctionCanvas::GetMin ( )
inline

Get the minimum scalar value of the data range.

Returns
The minimum value.

Definition at line 65 of file QmitkTransferFunctionCanvas.h.

◆ GetNearHandle()

virtual int QmitkTransferFunctionCanvas::GetNearHandle ( int  x,
int  y,
unsigned int  maxSquaredDistance = 100 
)
pure virtual

Find a handle near the given canvas position.

Parameters
[in]xThe x coordinate in canvas pixels.
[in]yThe y coordinate in canvas pixels.
[in]maxSquaredDistanceMaximum squared pixel distance.
Returns
Index of the nearest handle, or -1.

Implemented in QmitkPiecewiseFunctionCanvas, and QmitkColorTransferFunctionCanvas.

◆ GetUpper()

double QmitkTransferFunctionCanvas::GetUpper ( )
inline

Get the upper display bound.

Returns
The upper bound.

Definition at line 109 of file QmitkTransferFunctionCanvas.h.

◆ keyPressEvent()

void QmitkTransferFunctionCanvas::keyPressEvent ( QKeyEvent *  e)
override

Handle keyboard input for point manipulation (Delete, arrow keys).

◆ mouseDoubleClickEvent()

void QmitkTransferFunctionCanvas::mouseDoubleClickEvent ( QMouseEvent *  mouseEvent)
override

Handle double-click on a handle.

◆ mouseMoveEvent()

void QmitkTransferFunctionCanvas::mouseMoveEvent ( QMouseEvent *  mouseEvent)
override

Handle mouse move: drag the grabbed handle.

◆ mousePressEvent()

void QmitkTransferFunctionCanvas::mousePressEvent ( QMouseEvent *  mouseEvent)
override

Handle mouse press: add or remove function points, select handles.

◆ mouseReleaseEvent()

void QmitkTransferFunctionCanvas::mouseReleaseEvent ( QMouseEvent *  mouseEvent)
override

Handle mouse release: trigger repaint.

◆ MoveFunctionPoint()

virtual void QmitkTransferFunctionCanvas::MoveFunctionPoint ( int  index,
std::pair< double, double >  pos 
)
pure virtual

Move a function point to a new position.

Parameters
[in]indexThe index of the point.
[in]posThe new (x, y) position.

Implemented in QmitkPiecewiseFunctionCanvas, and QmitkColorTransferFunctionCanvas.

◆ paintEvent()

void QmitkTransferFunctionCanvas::paintEvent ( QPaintEvent *  e)
override

Default paint event handler.

◆ PaintHistogram()

void QmitkTransferFunctionCanvas::PaintHistogram ( QPainter &  p)

Paint the histogram as a background overlay.

Parameters
[in,out]pThe QPainter to draw with.

◆ RemoveFunctionPoint()

virtual void QmitkTransferFunctionCanvas::RemoveFunctionPoint ( double  x)
pure virtual

Remove the function point at position x.

Parameters
[in]xThe scalar position to remove.

Implemented in QmitkPiecewiseFunctionCanvas, and QmitkColorTransferFunctionCanvas.

◆ SetHistogram()

void QmitkTransferFunctionCanvas::SetHistogram ( mitk::SimpleHistogram *  histogram)
inline

Set the histogram to display as background.

Parameters
[in]histogramThe histogram. May be nullptr.

Definition at line 59 of file QmitkTransferFunctionCanvas.h.

◆ SetImmediateUpdate()

void QmitkTransferFunctionCanvas::SetImmediateUpdate ( bool  state)

Enable or disable immediate rendering updates during interaction.

Parameters
[in]stateTrue to enable immediate updates.

◆ SetLower()

void QmitkTransferFunctionCanvas::SetLower ( double  lower)
inline

Set the lower display bound (visible range start).

Parameters
[in]lowerThe lower bound.

Definition at line 103 of file QmitkTransferFunctionCanvas.h.

◆ SetMax()

void QmitkTransferFunctionCanvas::SetMax ( double  max)
inline

Set the maximum scalar value and update the upper display bound.

Parameters
[in]maxThe maximum value.

Definition at line 87 of file QmitkTransferFunctionCanvas.h.

Referenced by QmitkColorTransferFunctionCanvas::SetColorTransferFunction(), and QmitkPiecewiseFunctionCanvas::SetPiecewiseFunction().

◆ SetMin()

void QmitkTransferFunctionCanvas::SetMin ( double  min)
inline

Set the minimum scalar value and update the lower display bound.

Parameters
[in]minThe minimum value.

Definition at line 71 of file QmitkTransferFunctionCanvas.h.

Referenced by QmitkColorTransferFunctionCanvas::SetColorTransferFunction(), and QmitkPiecewiseFunctionCanvas::SetPiecewiseFunction().

◆ SetQLineEdits()

void QmitkTransferFunctionCanvas::SetQLineEdits ( QLineEdit *  xEdit,
QLineEdit *  yEdit 
)
inline

Connect QLineEdit widgets for displaying/editing the selected handle coordinates.

Parameters
[in]xEditThe line edit for the x coordinate.
[in]yEditThe line edit for the y coordinate. May be nullptr.

Definition at line 280 of file QmitkTransferFunctionCanvas.h.

◆ SetUpper()

void QmitkTransferFunctionCanvas::SetUpper ( double  upper)
inline

Set the upper display bound (visible range end).

Parameters
[in]upperThe upper bound.

Definition at line 115 of file QmitkTransferFunctionCanvas.h.

◆ SetX()

void QmitkTransferFunctionCanvas::SetX ( float  x)
inline

Set the x coordinate of the currently grabbed handle.

Parameters
[in]xThe new x value.

Definition at line 251 of file QmitkTransferFunctionCanvas.h.

References mitk::RenderingManager::GetInstance(), and mitk::RenderingManager::RequestUpdateAll().

◆ SetY()

void QmitkTransferFunctionCanvas::SetY ( float  y)
inline

Set the y coordinate of the currently grabbed handle.

Parameters
[in]yThe new y value.

Definition at line 265 of file QmitkTransferFunctionCanvas.h.

References mitk::RenderingManager::GetInstance(), and mitk::RenderingManager::RequestUpdateAll().

◆ ValidateCoord()

std::pair<double, double> QmitkTransferFunctionCanvas::ValidateCoord ( std::pair< double, double >  x)
inline

Clamp coordinates to valid histogram range and [0, 1] for y.

Parameters
[in]xThe (x, y) coordinates to validate.
Returns
The clamped coordinates.

Definition at line 232 of file QmitkTransferFunctionCanvas.h.

References mitk::SimpleHistogram::GetMax(), and mitk::SimpleHistogram::GetMin().

Member Data Documentation

◆ m_GrabbedHandle

int QmitkTransferFunctionCanvas::m_GrabbedHandle

Index of the currently grabbed (selected) handle, or -1.

Definition at line 195 of file QmitkTransferFunctionCanvas.h.

◆ m_Histogram

mitk::SimpleHistogram* QmitkTransferFunctionCanvas::m_Histogram

The background histogram.

Definition at line 216 of file QmitkTransferFunctionCanvas.h.

◆ m_ImmediateUpdate

bool QmitkTransferFunctionCanvas::m_ImmediateUpdate
protected

Definition at line 288 of file QmitkTransferFunctionCanvas.h.

◆ m_LineEditAvailable

bool QmitkTransferFunctionCanvas::m_LineEditAvailable
protected

Definition at line 291 of file QmitkTransferFunctionCanvas.h.

◆ m_Lower

double QmitkTransferFunctionCanvas::m_Lower

Lower display bound.

Definition at line 197 of file QmitkTransferFunctionCanvas.h.

◆ m_Max

double QmitkTransferFunctionCanvas::m_Max

Maximum data range value.

Definition at line 200 of file QmitkTransferFunctionCanvas.h.

◆ m_Min

double QmitkTransferFunctionCanvas::m_Min

Minimum data range value.

Definition at line 199 of file QmitkTransferFunctionCanvas.h.

◆ m_Range

float QmitkTransferFunctionCanvas::m_Range
protected

Definition at line 289 of file QmitkTransferFunctionCanvas.h.

◆ m_Upper

double QmitkTransferFunctionCanvas::m_Upper

Upper display bound.

Definition at line 198 of file QmitkTransferFunctionCanvas.h.

◆ m_XEdit

QLineEdit* QmitkTransferFunctionCanvas::m_XEdit
protected

Definition at line 292 of file QmitkTransferFunctionCanvas.h.

◆ m_YEdit

QLineEdit* QmitkTransferFunctionCanvas::m_YEdit
protected

Definition at line 293 of file QmitkTransferFunctionCanvas.h.


The documentation for this class was generated from the following file: