OpenWalnut  1.5.0dev
Public Types | Public Slots | Public Member Functions | Protected Member Functions | Private Attributes | List of all members
WTransferFunctionWidget Class Reference

A widget that holds a scene to display and modify the transfer function. More...

#include <WTransferFunctionWidget.h>

+ Inheritance diagram for WTransferFunctionWidget:
+ Collaboration diagram for WTransferFunctionWidget:

Public Types

typedef QGraphicsView BaseClass
 type of our base class for easier coding More...
 

Public Slots

void dataChanged ()
 Notification that the data changed, i.e., a control point has been moved or a color changed. More...
 

Public Member Functions

 WTransferFunctionWidget (QWidget *qparent=NULL, WTransferFunctionGuiNotificationClass *parent=NULL)
 Constructor. More...
 
virtual ~WTransferFunctionWidget ()
 Destructor. More...
 
void setHistogram (const std::vector< double > &histogram)
 Called from external to set histogram. More...
 
void forceRedraw ()
 Redraw the widget. More...
 
void setCurrent (WTransferFunctionPoint *current)
 Set the current active point => this should be changed to QGraphicsScene object selection. More...
 
void setCurrentColor (WTransferFunctionColorPoint *ccurrent)
 Similar to setCurrent but for Color control points. More...
 
void sample1DTransferFunction (unsigned char *array, int width)
 Sample the transfer function into a 1D RGBA texture. More...
 
void sample1DTransferFunctionForDisplay (unsigned char *array, int width)
 Sample the transfer function into a 1D RGBA, ABGR, ARGB, ... More...
 
void insertPoint (const QPointF &position)
 Insert a new alpha control point at scene position position. More...
 
void insertPointNormalized (const QPointF &position)
 Same as insertPoint but in normalized coordinates and not in screen space. More...
 
void insertColor (const QPointF &pos, QColor const *const color=0)
 Insert a new color control point at scene position pos (only the x-value is relevant) If a color is provided, it is used. More...
 
void insertColorNormalized (const QPointF &pos, QColor const *const color=0)
 Same as insertColor but in normalized coordinates, i.e., [ 0...1 ] along x. More...
 
void clearTransferFunction ()
 Remove all points from the transfer function widget to be able to insert new points. More...
 

Protected Member Functions

virtual void drawBackground (QPainter *painter, const QRectF &rect)
 Draws the background. More...
 
virtual void keyPressEvent (QKeyEvent *event)
 Interactions implemented so far: right click: insert new object (Ctrl+left click or two-finger tap on OSX) left click on objects: (handled by individual objects) move control points and select object double click on objects: (handled by individual objects) open parameter dialog, e.g., to change the color "Delete" or "Backspace": delete selected itom. More...
 
virtual void mousePressEvent (QMouseEvent *event)
 For a documentation of the implemented actions confer the keyPressEvent documentation. More...
 
WTransferFunctionPointfindPointOnLeft (QPointF position)
 Internal helper function: Find the point to the left of the given point. More...
 
WTransferFunctionColorPointfindCPointOnLeft (QPointF position)
 Internal helper function: Find the point to the left of the given color control point. More...
 
void updateTransferFunction ()
 Updates the transfer function. More...
 
void setMyBackground ()
 Internal helper function to update the QGraphicsPixmapItem that holds a representation of the current color map and displays it as a background of the widget. More...
 

Private Attributes

WTransferFunctionGuiNotificationClassparent
 the class that receives our update notifications More...
 
QGraphicsScenescene
 our scene More...
 
WTransferFunctionPointfirst
 linked list of alpha items More...
 
WTransferFunctionPointlast
 first element More...
 
WTransferFunctionPointcurrent
 last element in list More...
 
WTransferFunctionColorPointcfirst
 currently selected/active element More...
 
WTransferFunctionColorPointclast
 first element More...
 
WTransferFunctionColorPointccurrent
 last element More...
 
WTransferFunctionBackgroundbackground
 currently selected/active color element More...
 
WTransferFunctionHistogramhistogram
 background that displays the color map More...
 
bool initialized
 item responsible for displaying histogram data More...
 

Detailed Description

A widget that holds a scene to display and modify the transfer function.

Currently most data storage is done in this class, which is not a great design. Thus, we should try to split the model and the view a bit more, even though this is not intended by QGraphicsView.

Definition at line 69 of file WTransferFunctionWidget.h.

Member Typedef Documentation

◆ BaseClass

type of our base class for easier coding

Definition at line 75 of file WTransferFunctionWidget.h.

Constructor & Destructor Documentation

◆ WTransferFunctionWidget()

WTransferFunctionWidget::WTransferFunctionWidget ( QWidget *  qparent = NULL,
WTransferFunctionGuiNotificationClass parent = NULL 
)

Constructor.

Create a TF widget with a given parent.

Parameters
qparentparent widgeet
parenta class that receives notifications

Definition at line 42 of file WTransferFunctionWidget.cpp.

References background, histogram, initialized, scene, and setMyBackground().

+ Here is the call graph for this function:

◆ ~WTransferFunctionWidget()

WTransferFunctionWidget::~WTransferFunctionWidget ( )
virtual

Destructor.

Definition at line 218 of file WTransferFunctionWidget.cpp.

Member Function Documentation

◆ clearTransferFunction()

void WTransferFunctionWidget::clearTransferFunction ( )

Remove all points from the transfer function widget to be able to insert new points.

Definition at line 291 of file WTransferFunctionWidget.cpp.

References ccurrent, cfirst, clast, current, first, WTransferFunctionPoint::getLine(), WTransferFunctionColorPoint::getRight(), WTransferFunctionPoint::getRight(), and last.

Referenced by WPropertyTransferFunctionWidget::update().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ dataChanged

void WTransferFunctionWidget::dataChanged ( )
slot

Notification that the data changed, i.e., a control point has been moved or a color changed.

Definition at line 269 of file WTransferFunctionWidget.cpp.

References forceRedraw(), initialized, setMyBackground(), and updateTransferFunction().

Referenced by WTransferFunctionColorPoint::colorSelected(), WTransferFunctionColorPoint::dropEvent(), WTransferFunctionColorPoint::itemChange(), WTransferFunctionPoint::itemChange(), and keyPressEvent().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ drawBackground()

void WTransferFunctionWidget::drawBackground ( QPainter *  painter,
const QRectF &  rect 
)
protectedvirtual

Draws the background.

Parameters
painterthe painter to use
rectthe QRectF to repaint

Definition at line 253 of file WTransferFunctionWidget.cpp.

◆ findCPointOnLeft()

WTransferFunctionColorPoint * WTransferFunctionWidget::findCPointOnLeft ( QPointF  position)
protected

Internal helper function: Find the point to the left of the given color control point.

Parameters
positiona position
Returns
a color point left of the given position, i.e., with return.x < x_position

Definition at line 556 of file WTransferFunctionWidget.cpp.

References cfirst, current, and WTransferFunctionPoint::getRight().

Referenced by insertColor().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ findPointOnLeft()

WTransferFunctionPoint * WTransferFunctionWidget::findPointOnLeft ( QPointF  position)
protected

Internal helper function: Find the point to the left of the given point.

Parameters
positionin the widget
Returns
an alpha point left of the given position, i.e., with return.x < x_position

Definition at line 538 of file WTransferFunctionWidget.cpp.

References current, first, and WTransferFunctionPoint::getRight().

Referenced by insertPoint().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ forceRedraw()

void WTransferFunctionWidget::forceRedraw ( )

Redraw the widget.

Definition at line 280 of file WTransferFunctionWidget.cpp.

References initialized, and scene.

Referenced by dataChanged(), mousePressEvent(), and setHistogram().

+ Here is the caller graph for this function:

◆ insertColor()

void WTransferFunctionWidget::insertColor ( const QPointF &  pos,
QColor const *const  color = 0 
)

Insert a new color control point at scene position pos (only the x-value is relevant) If a color is provided, it is used.

Otherwise, a new color is used interpolating the current color map.

Parameters
posthe clicked position where pos.x = iso and pos.y is ignored
colorthe color of the new point. If color = 0, a new color is created by interpolating the neighbors.

Definition at line 374 of file WTransferFunctionWidget.cpp.

References cfirst, clast, WTransferFunctionColorPoint::colorSelected(), findCPointOnLeft(), WTransferFunctionColorPoint::getColor(), WTransferFunctionColorPoint::getRight(), scene, WTransferFunctionColorPoint::setLeft(), and WTransferFunctionColorPoint::setRight().

Referenced by WTransferFunctionScene::dropEvent(), insertColorNormalized(), and mousePressEvent().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ insertColorNormalized()

void WTransferFunctionWidget::insertColorNormalized ( const QPointF &  pos,
QColor const *const  color = 0 
)

Same as insertColor but in normalized coordinates, i.e., [ 0...1 ] along x.

Parameters
posthe position
colorthe new color ( my be 0 and will then be interpolated linearly )

Definition at line 369 of file WTransferFunctionWidget.cpp.

References insertColor(), and scene.

Referenced by WPropertyTransferFunctionWidget::update().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ insertPoint()

void WTransferFunctionWidget::insertPoint ( const QPointF &  position)

Insert a new alpha control point at scene position position.

Parameters
positionthe position of the point with position.x = iso and position.y = alpha in window coordinates.

Definition at line 445 of file WTransferFunctionWidget.cpp.

References cfirst, clast, findPointOnLeft(), first, WTransferFunctionPoint::getLine(), WTransferFunctionPoint::getRight(), scene, WTransferFunctionLine::setLeft(), WTransferFunctionPoint::setLeft(), WTransferFunctionPoint::setLine(), WTransferFunctionPoint::setPos(), WTransferFunctionLine::setRight(), and WTransferFunctionPoint::setRight().

Referenced by insertPointNormalized(), and mousePressEvent().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ insertPointNormalized()

void WTransferFunctionWidget::insertPointNormalized ( const QPointF &  position)

Same as insertPoint but in normalized coordinates and not in screen space.

Parameters
positionsame as in insertPoint, but scaled to [ 0..1 ]x[ 0..1 ]

Definition at line 440 of file WTransferFunctionWidget.cpp.

References insertPoint(), and scene.

Referenced by WPropertyTransferFunctionWidget::update().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ keyPressEvent()

void WTransferFunctionWidget::keyPressEvent ( QKeyEvent *  event)
protectedvirtual

Interactions implemented so far: right click: insert new object (Ctrl+left click or two-finger tap on OSX) left click on objects: (handled by individual objects) move control points and select object double click on objects: (handled by individual objects) open parameter dialog, e.g., to change the color "Delete" or "Backspace": delete selected itom.

Parameters
eventthe event to handle

Definition at line 316 of file WTransferFunctionWidget.cpp.

References ccurrent, current, dataChanged(), WTransferFunctionColorPoint::getLeft(), WTransferFunctionPoint::getLeft(), WTransferFunctionPoint::getLine(), WTransferFunctionColorPoint::getRight(), WTransferFunctionPoint::getRight(), WTransferFunctionColorPoint::setLeft(), WTransferFunctionPoint::setLeft(), WTransferFunctionColorPoint::setRight(), WTransferFunctionLine::setRight(), and WTransferFunctionPoint::setRight().

+ Here is the call graph for this function:

◆ mousePressEvent()

void WTransferFunctionWidget::mousePressEvent ( QMouseEvent *  event)
protectedvirtual

For a documentation of the implemented actions confer the keyPressEvent documentation.

Parameters
eventthe event to handle

Definition at line 516 of file WTransferFunctionWidget.cpp.

References forceRedraw(), insertColor(), and insertPoint().

+ Here is the call graph for this function:

◆ sample1DTransferFunction()

void WTransferFunctionWidget::sample1DTransferFunction ( unsigned char *  array,
int  width 
)

Sample the transfer function into a 1D RGBA texture.

Parameters
arraytarget byte array of RGBA values
widthwidth of array in number of color values

Definition at line 137 of file WTransferFunctionWidget.cpp.

References ccurrent, cfirst, first, WTransferFunctionColorPoint::getColor(), WTransferFunctionColorPoint::getRight(), WTransferFunctionPoint::getRight(), and scene.

+ Here is the call graph for this function:

◆ sample1DTransferFunctionForDisplay()

void WTransferFunctionWidget::sample1DTransferFunctionForDisplay ( unsigned char *  array,
int  width 
)

Sample the transfer function into a 1D RGBA, ABGR, ARGB, ...

inaternal representation needs ARGB, but we do not display alpha component, so set it to 255

whatever... This function should work on the graphics native system, but I did not find the function to get information about the alignment, yet. (X11 Linux, little endian: ABRG. OSX: ARGB, X11 on OSX from Linux host->???)

Parameters
arraytarget byte array of RGBA values
widthwidth of array in number of color values

Definition at line 185 of file WTransferFunctionWidget.cpp.

References ccurrent, cfirst, WTransferFunctionColorPoint::getColor(), WTransferFunctionColorPoint::getRight(), and scene.

Referenced by setMyBackground().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setCurrent()

void WTransferFunctionWidget::setCurrent ( WTransferFunctionPoint current)
inline

Set the current active point => this should be changed to QGraphicsScene object selection.

Parameters
currentthe new selection

Definition at line 108 of file WTransferFunctionWidget.h.

References ccurrent, and current.

Referenced by WTransferFunctionPoint::mousePressEvent().

+ Here is the caller graph for this function:

◆ setCurrentColor()

void WTransferFunctionWidget::setCurrentColor ( WTransferFunctionColorPoint ccurrent)
inline

Similar to setCurrent but for Color control points.

Parameters
ccurrentthe new seelection

Definition at line 119 of file WTransferFunctionWidget.h.

References ccurrent, and current.

Referenced by WTransferFunctionColorPoint::mousePressEvent().

+ Here is the caller graph for this function:

◆ setHistogram()

void WTransferFunctionWidget::setHistogram ( const std::vector< double > &  histogram)

Called from external to set histogram.

Parameters
histogramThe histogram data

Definition at line 262 of file WTransferFunctionWidget.cpp.

References forceRedraw(), WTransferFunctionHistogram::getData(), and histogram.

Referenced by WPropertyTransferFunctionWidget::update().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setMyBackground()

void WTransferFunctionWidget::setMyBackground ( )
protected

Internal helper function to update the QGraphicsPixmapItem that holds a representation of the current color map and displays it as a background of the widget.

This function samples the texture into a QPixmap and updates the QGraphicsPixmapItem.

Definition at line 229 of file WTransferFunctionWidget.cpp.

References background, sample1DTransferFunctionForDisplay(), and WTransferFunctionBackground::setMyPixmap().

Referenced by dataChanged(), and WTransferFunctionWidget().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ updateTransferFunction()

void WTransferFunctionWidget::updateTransferFunction ( )
protected

Member Data Documentation

◆ background

WTransferFunctionBackground* WTransferFunctionWidget::background
private

currently selected/active color element

Definition at line 260 of file WTransferFunctionWidget.h.

Referenced by setMyBackground(), and WTransferFunctionWidget().

◆ ccurrent

WTransferFunctionColorPoint* WTransferFunctionWidget::ccurrent
private

◆ cfirst

WTransferFunctionColorPoint* WTransferFunctionWidget::cfirst
private

currently selected/active element

linked list of color items

Definition at line 256 of file WTransferFunctionWidget.h.

Referenced by clearTransferFunction(), findCPointOnLeft(), insertColor(), insertPoint(), sample1DTransferFunction(), sample1DTransferFunctionForDisplay(), and updateTransferFunction().

◆ clast

WTransferFunctionColorPoint* WTransferFunctionWidget::clast
private

first element

Definition at line 257 of file WTransferFunctionWidget.h.

Referenced by clearTransferFunction(), insertColor(), and insertPoint().

◆ current

WTransferFunctionPoint* WTransferFunctionWidget::current
private

◆ first

WTransferFunctionPoint* WTransferFunctionWidget::first
private

◆ histogram

WTransferFunctionHistogram* WTransferFunctionWidget::histogram
private

background that displays the color map

Definition at line 261 of file WTransferFunctionWidget.h.

Referenced by setHistogram(), updateTransferFunction(), and WTransferFunctionWidget().

◆ initialized

bool WTransferFunctionWidget::initialized
private

item responsible for displaying histogram data

Definition at line 263 of file WTransferFunctionWidget.h.

Referenced by dataChanged(), forceRedraw(), and WTransferFunctionWidget().

◆ last

WTransferFunctionPoint* WTransferFunctionWidget::last
private

first element

Definition at line 252 of file WTransferFunctionWidget.h.

Referenced by clearTransferFunction().

◆ parent

WTransferFunctionGuiNotificationClass* WTransferFunctionWidget::parent
private

the class that receives our update notifications

Definition at line 245 of file WTransferFunctionWidget.h.

Referenced by updateTransferFunction().

◆ scene

QGraphicsScene* WTransferFunctionWidget::scene
private

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