Medical Imaging Interaction Toolkit  2026.06.00
Medical Imaging Interaction Toolkit
QmitkPiecewiseFunctionCanvas Class Reference

Canvas widget for editing a vtkPiecewiseFunction (opacity transfer function). More...

#include <QmitkPiecewiseFunctionCanvas.h>

Inheritance diagram for QmitkPiecewiseFunctionCanvas:
Collaboration diagram for QmitkPiecewiseFunctionCanvas:

Public Member Functions

 QmitkPiecewiseFunctionCanvas (QWidget *parent=nullptr, Qt::WindowFlags f={})
 Construct the piecewise function canvas. More...
 
void paintEvent (QPaintEvent *e) override
 Paint the histogram, function lines, handles, title, and range labels. More...
 
void SetTitle (const QString &title)
 Set the title text displayed on the canvas. More...
 
int GetNearHandle (int x, int y, unsigned int maxSquaredDistance=100) override
 Find a handle near the given canvas position. More...
 
void SetPiecewiseFunction (vtkPiecewiseFunction *piecewiseFunction)
 Set the vtkPiecewiseFunction to edit. More...
 
int AddFunctionPoint (double x, double val) override
 Add a function point at position (x, val). More...
 
void RemoveFunctionPoint (double x) override
 Remove the function point at position x. More...
 
double GetFunctionX (int index) override
 Get the x (scalar) value of a function point by index. More...
 
double GetFunctionY (int index) override
 Get the y (opacity) value of a function point by index. More...
 
int GetFunctionSize () override
 Get the number of points in the piecewise function. More...
 
void DoubleClickOnHandle (int) override
 No-op for piecewise functions (double-click does not change values). More...
 
void MoveFunctionPoint (int index, std::pair< double, double > pos) override
 Move a function point to a new position. More...
 
double GetFunctionMax ()
 Get the maximum scalar value of the function range. More...
 
double GetFunctionMin ()
 Get the minimum scalar value of the function range. More...
 
double GetFunctionRange ()
 Get the span of the function range. More...
 
void RemoveAllFunctionPoints ()
 Reset the function to a default ramp from 0 to 1 with a zero-point at origin. More...
 
void ResetGO ()
 Reset the function to a default gradient opacity configuration. More...
 
- Public Member Functions inherited from QmitkTransferFunctionCanvas
 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...
 
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...
 
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...
 

Protected Attributes

vtkPiecewiseFunction * m_PiecewiseFunction
 
QString m_Title
 
- Protected Attributes inherited from QmitkTransferFunctionCanvas
bool m_ImmediateUpdate
 
float m_Range
 
bool m_LineEditAvailable
 
QLineEdit * m_XEdit
 
QLineEdit * m_YEdit
 

Additional Inherited Members

- Public Attributes inherited from QmitkTransferFunctionCanvas
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...
 

Detailed Description

Canvas widget for editing a vtkPiecewiseFunction (opacity transfer function).

Renders a piecewise linear function as connected line segments with draggable control point handles. Supports adding, removing, and moving function points interactively. A histogram is drawn in the background if one is set.

See also
QmitkTransferFunctionCanvas, QmitkColorTransferFunctionCanvas, QmitkTransferFunctionWidget

Definition at line 30 of file QmitkPiecewiseFunctionCanvas.h.

Constructor & Destructor Documentation

◆ QmitkPiecewiseFunctionCanvas()

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

Construct the piecewise function canvas.

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

Member Function Documentation

◆ AddFunctionPoint()

int QmitkPiecewiseFunctionCanvas::AddFunctionPoint ( double  x,
double  val 
)
inlineoverridevirtual

Add a function point at position (x, val).

Parameters
[in]xThe scalar position.
[in]valThe opacity value [0, 1].
Returns
Index of the added point.

Implements QmitkTransferFunctionCanvas.

Definition at line 80 of file QmitkPiecewiseFunctionCanvas.h.

◆ DoubleClickOnHandle()

void QmitkPiecewiseFunctionCanvas::DoubleClickOnHandle ( int  )
inlineoverridevirtual

No-op for piecewise functions (double-click does not change values).

Implements QmitkTransferFunctionCanvas.

Definition at line 121 of file QmitkPiecewiseFunctionCanvas.h.

◆ GetFunctionMax()

double QmitkPiecewiseFunctionCanvas::GetFunctionMax ( )
inline

Get the maximum scalar value of the function range.

Returns
The maximum value.

Definition at line 134 of file QmitkPiecewiseFunctionCanvas.h.

◆ GetFunctionMin()

double QmitkPiecewiseFunctionCanvas::GetFunctionMin ( )
inline

Get the minimum scalar value of the function range.

Returns
The minimum value.

Definition at line 140 of file QmitkPiecewiseFunctionCanvas.h.

◆ GetFunctionRange()

double QmitkPiecewiseFunctionCanvas::GetFunctionRange ( )
inline

Get the span of the function range.

Returns
The range value (max - min, or max if min is non-negative).

Definition at line 146 of file QmitkPiecewiseFunctionCanvas.h.

◆ GetFunctionSize()

int QmitkPiecewiseFunctionCanvas::GetFunctionSize ( )
inlineoverridevirtual

Get the number of points in the piecewise function.

Returns
The point count.

Implements QmitkTransferFunctionCanvas.

Definition at line 118 of file QmitkPiecewiseFunctionCanvas.h.

◆ GetFunctionX()

double QmitkPiecewiseFunctionCanvas::GetFunctionX ( int  index)
inlineoverridevirtual

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

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

Implements QmitkTransferFunctionCanvas.

Definition at line 102 of file QmitkPiecewiseFunctionCanvas.h.

◆ GetFunctionY()

double QmitkPiecewiseFunctionCanvas::GetFunctionY ( int  index)
inlineoverridevirtual

Get the y (opacity) value of a function point by index.

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

Implements QmitkTransferFunctionCanvas.

Definition at line 109 of file QmitkPiecewiseFunctionCanvas.h.

◆ GetNearHandle()

int QmitkPiecewiseFunctionCanvas::GetNearHandle ( int  x,
int  y,
unsigned int  maxSquaredDistance = 100 
)
overridevirtual

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 to consider a handle "near".
Returns
Index of the nearest handle, or -1 if none is within range.

Implements QmitkTransferFunctionCanvas.

◆ MoveFunctionPoint()

void QmitkPiecewiseFunctionCanvas::MoveFunctionPoint ( int  index,
std::pair< double, double >  pos 
)
overridevirtual

Move a function point to a new position.

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

Implements QmitkTransferFunctionCanvas.

◆ paintEvent()

void QmitkPiecewiseFunctionCanvas::paintEvent ( QPaintEvent *  e)
override

Paint the histogram, function lines, handles, title, and range labels.

◆ RemoveAllFunctionPoints()

void QmitkPiecewiseFunctionCanvas::RemoveAllFunctionPoints ( )
inline

Reset the function to a default ramp from 0 to 1 with a zero-point at origin.

Definition at line 162 of file QmitkPiecewiseFunctionCanvas.h.

◆ RemoveFunctionPoint()

void QmitkPiecewiseFunctionCanvas::RemoveFunctionPoint ( double  x)
inlineoverridevirtual

Remove the function point at position x.

Parameters
[in]xThe scalar position of the point to remove.

Implements QmitkTransferFunctionCanvas.

Definition at line 86 of file QmitkPiecewiseFunctionCanvas.h.

References QmitkTransferFunctionCanvas::GetFunctionSize().

◆ ResetGO()

void QmitkPiecewiseFunctionCanvas::ResetGO ( )
inline

Reset the function to a default gradient opacity configuration.

Definition at line 169 of file QmitkPiecewiseFunctionCanvas.h.

◆ SetPiecewiseFunction()

void QmitkPiecewiseFunctionCanvas::SetPiecewiseFunction ( vtkPiecewiseFunction *  piecewiseFunction)
inline

Set the vtkPiecewiseFunction to edit.

Parameters
[in]piecewiseFunctionThe piecewise function. Must not be nullptr.

Definition at line 64 of file QmitkPiecewiseFunctionCanvas.h.

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

◆ SetTitle()

void QmitkPiecewiseFunctionCanvas::SetTitle ( const QString &  title)

Set the title text displayed on the canvas.

Parameters
[in]titleThe title string.

Member Data Documentation

◆ m_PiecewiseFunction

vtkPiecewiseFunction* QmitkPiecewiseFunctionCanvas::m_PiecewiseFunction
protected

Definition at line 178 of file QmitkPiecewiseFunctionCanvas.h.

◆ m_Title

QString QmitkPiecewiseFunctionCanvas::m_Title
protected

Definition at line 179 of file QmitkPiecewiseFunctionCanvas.h.


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