OpenWalnut
1.5.0dev
|
A widget that holds a scene to display and modify the transfer function. More...
#include <WTransferFunctionWidget.h>
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... | |
WTransferFunctionPoint * | findPointOnLeft (QPointF position) |
Internal helper function: Find the point to the left of the given point. More... | |
WTransferFunctionColorPoint * | findCPointOnLeft (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 | |
WTransferFunctionGuiNotificationClass * | parent |
the class that receives our update notifications More... | |
QGraphicsScene * | scene |
our scene More... | |
WTransferFunctionPoint * | first |
linked list of alpha items More... | |
WTransferFunctionPoint * | last |
first element More... | |
WTransferFunctionPoint * | current |
last element in list More... | |
WTransferFunctionColorPoint * | cfirst |
currently selected/active element More... | |
WTransferFunctionColorPoint * | clast |
first element More... | |
WTransferFunctionColorPoint * | ccurrent |
last element More... | |
WTransferFunctionBackground * | background |
currently selected/active color element More... | |
WTransferFunctionHistogram * | histogram |
background that displays the color map More... | |
bool | initialized |
item responsible for displaying histogram data More... | |
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.
type of our base class for easier coding
Definition at line 75 of file WTransferFunctionWidget.h.
WTransferFunctionWidget::WTransferFunctionWidget | ( | QWidget * | qparent = NULL , |
WTransferFunctionGuiNotificationClass * | parent = NULL |
||
) |
Constructor.
Create a TF widget with a given parent.
qparent | parent widgeet |
parent | a class that receives notifications |
Definition at line 42 of file WTransferFunctionWidget.cpp.
References background, histogram, initialized, scene, and setMyBackground().
|
virtual |
Destructor.
Definition at line 218 of file WTransferFunctionWidget.cpp.
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().
|
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().
|
protectedvirtual |
Draws the background.
painter | the painter to use |
rect | the QRectF to repaint |
Definition at line 253 of file WTransferFunctionWidget.cpp.
|
protected |
Internal helper function: Find the point to the left of the given color control point.
position | a position |
Definition at line 556 of file WTransferFunctionWidget.cpp.
References cfirst, current, and WTransferFunctionPoint::getRight().
Referenced by insertColor().
|
protected |
Internal helper function: Find the point to the left of the given point.
position | in the widget |
Definition at line 538 of file WTransferFunctionWidget.cpp.
References current, first, and WTransferFunctionPoint::getRight().
Referenced by insertPoint().
void WTransferFunctionWidget::forceRedraw | ( | ) |
Redraw the widget.
Definition at line 280 of file WTransferFunctionWidget.cpp.
References initialized, and scene.
Referenced by dataChanged(), mousePressEvent(), and setHistogram().
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.
pos | the clicked position where pos.x = iso and pos.y is ignored |
color | the 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().
void WTransferFunctionWidget::insertColorNormalized | ( | const QPointF & | pos, |
QColor const *const | color = 0 |
||
) |
Same as insertColor but in normalized coordinates, i.e., [ 0...1 ] along x.
pos | the position |
color | the 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().
void WTransferFunctionWidget::insertPoint | ( | const QPointF & | position | ) |
Insert a new alpha control point at scene position position.
position | the 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().
void WTransferFunctionWidget::insertPointNormalized | ( | const QPointF & | position | ) |
Same as insertPoint but in normalized coordinates and not in screen space.
position | same 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().
|
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.
event | the 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().
|
protectedvirtual |
For a documentation of the implemented actions confer the keyPressEvent documentation.
event | the event to handle |
Definition at line 516 of file WTransferFunctionWidget.cpp.
References forceRedraw(), insertColor(), and insertPoint().
void WTransferFunctionWidget::sample1DTransferFunction | ( | unsigned char * | array, |
int | width | ||
) |
Sample the transfer function into a 1D RGBA texture.
array | target byte array of RGBA values |
width | width 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.
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->???)
array | target byte array of RGBA values |
width | width 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().
|
inline |
Set the current active point => this should be changed to QGraphicsScene object selection.
current | the new selection |
Definition at line 108 of file WTransferFunctionWidget.h.
References ccurrent, and current.
Referenced by WTransferFunctionPoint::mousePressEvent().
|
inline |
Similar to setCurrent but for Color control points.
ccurrent | the new seelection |
Definition at line 119 of file WTransferFunctionWidget.h.
References ccurrent, and current.
Referenced by WTransferFunctionColorPoint::mousePressEvent().
void WTransferFunctionWidget::setHistogram | ( | const std::vector< double > & | histogram | ) |
Called from external to set histogram.
histogram | The histogram data |
Definition at line 262 of file WTransferFunctionWidget.cpp.
References forceRedraw(), WTransferFunctionHistogram::getData(), and histogram.
Referenced by WPropertyTransferFunctionWidget::update().
|
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().
|
protected |
Updates the transfer function.
Definition at line 584 of file WTransferFunctionWidget.cpp.
References WTransferFunction::addAlpha(), WTransferFunction::addColor(), cfirst, first, WTransferFunctionColorPoint::getColor(), WTransferFunctionHistogram::getData(), WTransferFunctionColorPoint::getRight(), WTransferFunctionPoint::getRight(), WTransferFunctionGuiNotificationClass::guiUpdate(), histogram, parent, scene, and WTransferFunction::setHistogram().
Referenced by dataChanged().
|
private |
currently selected/active color element
Definition at line 260 of file WTransferFunctionWidget.h.
Referenced by setMyBackground(), and WTransferFunctionWidget().
|
private |
last element
Definition at line 258 of file WTransferFunctionWidget.h.
Referenced by clearTransferFunction(), keyPressEvent(), sample1DTransferFunction(), sample1DTransferFunctionForDisplay(), setCurrent(), and setCurrentColor().
|
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().
|
private |
first element
Definition at line 257 of file WTransferFunctionWidget.h.
Referenced by clearTransferFunction(), insertColor(), and insertPoint().
|
private |
last element in list
Definition at line 253 of file WTransferFunctionWidget.h.
Referenced by clearTransferFunction(), findCPointOnLeft(), findPointOnLeft(), keyPressEvent(), setCurrent(), and setCurrentColor().
|
private |
linked list of alpha items
Definition at line 251 of file WTransferFunctionWidget.h.
Referenced by clearTransferFunction(), findPointOnLeft(), insertPoint(), sample1DTransferFunction(), and updateTransferFunction().
|
private |
background that displays the color map
Definition at line 261 of file WTransferFunctionWidget.h.
Referenced by setHistogram(), updateTransferFunction(), and WTransferFunctionWidget().
|
private |
item responsible for displaying histogram data
Definition at line 263 of file WTransferFunctionWidget.h.
Referenced by dataChanged(), forceRedraw(), and WTransferFunctionWidget().
|
private |
first element
Definition at line 252 of file WTransferFunctionWidget.h.
Referenced by clearTransferFunction().
|
private |
the class that receives our update notifications
Definition at line 245 of file WTransferFunctionWidget.h.
Referenced by updateTransferFunction().
|
private |
our scene
Definition at line 248 of file WTransferFunctionWidget.h.
Referenced by forceRedraw(), insertColor(), insertColorNormalized(), insertPoint(), insertPointNormalized(), sample1DTransferFunction(), sample1DTransferFunctionForDisplay(), updateTransferFunction(), and WTransferFunctionWidget().