Medical Imaging Interaction Toolkit  2026.06.00
Medical Imaging Interaction Toolkit
QmitkColorTransferFunctionCanvas Class Reference

Canvas widget for editing a vtkColorTransferFunction. More...

#include <QmitkColorTransferFunctionCanvas.h>

Inheritance diagram for QmitkColorTransferFunctionCanvas:
Collaboration diagram for QmitkColorTransferFunctionCanvas:

Public Member Functions

 QmitkColorTransferFunctionCanvas (QWidget *parent=nullptr, Qt::WindowFlags f={})
 Construct the color transfer function canvas. More...
 
void paintEvent (QPaintEvent *e) override
 Paint the color gradient, handles, title, and min/max labels. More...
 
int GetNearHandle (int x, int y, unsigned int maxSquaredDistance=100) override
 Find a handle near the given canvas position. More...
 
void SetTitle (const QString &title)
 Set the title text displayed on the canvas. More...
 
void SetColorTransferFunction (vtkColorTransferFunction *colorTransferFunction)
 Set the vtkColorTransferFunction to edit. More...
 
int AddFunctionPoint (double x, double val) override
 Add a color function point at position x, preserving the existing color at x. More...
 
void RemoveFunctionPoint (double x) override
 Remove the color function point at position x. More...
 
double GetFunctionX (int index) override
 Get the x (scalar) value of a function point by index. More...
 
int GetFunctionSize () override
 Get the number of points in the color transfer function. More...
 
void DoubleClickOnHandle (int handle) override
 Open a QColorDialog to change the color at the given handle. More...
 
void MoveFunctionPoint (int index, std::pair< double, double > pos) override
 Move a function point to a new position, preserving its color. More...
 
void AddRGB (double x, double r, double g, double b)
 Add an RGB color point to the transfer function. 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 (max - min). More...
 
void RemoveAllFunctionPoints ()
 Reset the function to a default red-to-yellow gradient. More...
 
double GetFunctionY (int) override
 Always returns 0.0 since color transfer functions have no y component. 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

vtkColorTransferFunction * m_ColorTransferFunction
 
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 vtkColorTransferFunction.

Renders a color gradient based on the underlying vtkColorTransferFunction and provides interactive handle manipulation. Users can add, move, remove, and double-click handles to change colors via a QColorDialog.

See also
QmitkTransferFunctionCanvas, QmitkPiecewiseFunctionCanvas, QmitkTransferFunctionWidget

Definition at line 30 of file QmitkColorTransferFunctionCanvas.h.

Constructor & Destructor Documentation

◆ QmitkColorTransferFunctionCanvas()

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

Construct the color transfer function canvas.

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

Member Function Documentation

◆ AddFunctionPoint()

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

Add a color function point at position x, preserving the existing color at x.

Parameters
[in]xThe scalar position for the new point.
[in]valUnused for color transfer functions.
Returns
Index of the added point.

Implements QmitkTransferFunctionCanvas.

Definition at line 79 of file QmitkColorTransferFunctionCanvas.h.

◆ AddRGB()

void QmitkColorTransferFunctionCanvas::AddRGB ( double  x,
double  r,
double  g,
double  b 
)

Add an RGB color point to the transfer function.

Parameters
[in]xThe scalar position.
[in]rRed component [0, 1].
[in]gGreen component [0, 1].
[in]bBlue component [0, 1].

◆ DoubleClickOnHandle()

void QmitkColorTransferFunctionCanvas::DoubleClickOnHandle ( int  handle)
overridevirtual

Open a QColorDialog to change the color at the given handle.

Parameters
[in]handleThe index of the handle to edit.

Implements QmitkTransferFunctionCanvas.

◆ GetFunctionMax()

double QmitkColorTransferFunctionCanvas::GetFunctionMax ( )
inline

Get the maximum scalar value of the function range.

Returns
The maximum value.

Definition at line 142 of file QmitkColorTransferFunctionCanvas.h.

◆ GetFunctionMin()

double QmitkColorTransferFunctionCanvas::GetFunctionMin ( )
inline

Get the minimum scalar value of the function range.

Returns
The minimum value.

Definition at line 148 of file QmitkColorTransferFunctionCanvas.h.

◆ GetFunctionRange()

double QmitkColorTransferFunctionCanvas::GetFunctionRange ( )
inline

Get the span of the function range (max - min).

Returns
The range value.

Definition at line 154 of file QmitkColorTransferFunctionCanvas.h.

◆ GetFunctionSize()

int QmitkColorTransferFunctionCanvas::GetFunctionSize ( )
inlineoverridevirtual

Get the number of points in the color transfer function.

Returns
The point count.

Implements QmitkTransferFunctionCanvas.

Definition at line 114 of file QmitkColorTransferFunctionCanvas.h.

◆ GetFunctionX()

double QmitkColorTransferFunctionCanvas::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 108 of file QmitkColorTransferFunctionCanvas.h.

◆ GetFunctionY()

double QmitkColorTransferFunctionCanvas::GetFunctionY ( int  )
inlineoverridevirtual

Always returns 0.0 since color transfer functions have no y component.

Returns
0.0

Implements QmitkTransferFunctionCanvas.

Definition at line 179 of file QmitkColorTransferFunctionCanvas.h.

◆ GetNearHandle()

int QmitkColorTransferFunctionCanvas::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 (unused for color functions).
[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 QmitkColorTransferFunctionCanvas::MoveFunctionPoint ( int  index,
std::pair< double, double >  pos 
)
overridevirtual

Move a function point to a new position, preserving its color.

Parameters
[in]indexThe index of the point to move.
[in]posThe new (x, y) position. Only x is used for color functions.

Implements QmitkTransferFunctionCanvas.

◆ paintEvent()

void QmitkColorTransferFunctionCanvas::paintEvent ( QPaintEvent *  e)
override

Paint the color gradient, handles, title, and min/max labels.

◆ RemoveAllFunctionPoints()

void QmitkColorTransferFunctionCanvas::RemoveAllFunctionPoints ( )
inline

Reset the function to a default red-to-yellow gradient.

Definition at line 170 of file QmitkColorTransferFunctionCanvas.h.

◆ RemoveFunctionPoint()

void QmitkColorTransferFunctionCanvas::RemoveFunctionPoint ( double  x)
inlineoverridevirtual

Remove the color function point at position x.

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

Implements QmitkTransferFunctionCanvas.

Definition at line 92 of file QmitkColorTransferFunctionCanvas.h.

References QmitkTransferFunctionCanvas::GetFunctionSize().

◆ SetColorTransferFunction()

void QmitkColorTransferFunctionCanvas::SetColorTransferFunction ( vtkColorTransferFunction *  colorTransferFunction)
inline

Set the vtkColorTransferFunction to edit.

Parameters
[in]colorTransferFunctionThe color transfer function. Must not be nullptr.

Definition at line 64 of file QmitkColorTransferFunctionCanvas.h.

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

◆ SetTitle()

void QmitkColorTransferFunctionCanvas::SetTitle ( const QString &  title)

Set the title text displayed on the canvas.

Parameters
[in]titleThe title string.

Member Data Documentation

◆ m_ColorTransferFunction

vtkColorTransferFunction* QmitkColorTransferFunctionCanvas::m_ColorTransferFunction
protected

Definition at line 181 of file QmitkColorTransferFunctionCanvas.h.

◆ m_Title

QString QmitkColorTransferFunctionCanvas::m_Title
protected

Definition at line 182 of file QmitkColorTransferFunctionCanvas.h.


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