29 #include <QGraphicsSceneMouseEvent>
30 #include <QMouseEvent>
31 #include <QPaintEngine>
33 #include "core/common/WTransferFunction.h"
34 #include "WTransferFunctionBackground.h"
35 #include "WTransferFunctionColorPoint.h"
36 #include "WTransferFunctionHistogram.h"
37 #include "WTransferFunctionLine.h"
38 #include "WTransferFunctionPoint.h"
39 #include "WTransferFunctionScene.h"
40 #include "WTransferFunctionWidget.h"
59 const int xMax( 300 );
60 const int yMax( 100 );
63 setMinimumSize( xMax-xMin+20, yMax - yMin + 30 );
64 this->setViewportUpdateMode( QGraphicsView::FullViewportUpdate );
67 scene->setItemIndexMethod( QGraphicsScene::NoIndex );
68 scene->setSceneRect( xMin, yMin, xMax, yMax );
69 this->setScene(
scene );
72 this->setCacheMode( CacheNone );
73 this->setRenderHint( QPainter::Antialiasing );
128 QColor blend(
const QColor&a,
double ta,
const QColor &b,
double tb )
131 ta*a.red()+tb*b.red(),
132 ta*a.green()+tb*b.green(),
133 ta*a.blue()+tb*b.blue() );
145 for(
int i = 0; i < width; ++i )
147 double normalized = ( double )i/(
double )
scene->width();
148 while( acurrent && acurrent->
getRight() && normalized > acurrent->
getRight()->pos().x() )
158 if( !acurrent || !acurrent->
getRight() )
167 double awidth = acurrent->
getRight()->pos().x() - acurrent->pos().x();
170 double at = ( normalized - acurrent->pos().x() )/awidth;
171 double ct = ( normalized -
ccurrent->pos().x() )/cwidth;
173 double alpha = ( double )( acurrent->
getRight()->pos().y() )/
scene->height()*at + ( double )( acurrent->pos().y() )/
scene->height()*( 1.-at );
176 array[ i*4 + 0 ] = rgb.red();
177 array[ i*4 + 1 ] = rgb.green();
178 array[ i*4 + 2 ] = rgb.blue();
179 array[ i*4 + 3 ] = alpha;
187 double scenewidth =
scene->width();
191 for(
int i = 0; i < width; ++i )
193 double normalized = ( double )i/(
double )width * scenewidth;
204 double ct = ( normalized -
ccurrent->pos().x() )/cwidth;
208 array[ i*4 + 2 ] = rgb.red();
209 array[ i*4 + 1 ] = rgb.green();
210 array[ i*4 + 0 ] = rgb.blue();
211 array[ i*4 + 3 ] = 255;
231 const int transferFunctionSize = 100;
232 static unsigned char texturearray[ 4*transferFunctionSize ];
238 QImage image( texturearray, transferFunctionSize, 1, QImage::Format_ARGB32 );
239 QPixmap pixmap( transferFunctionSize, 1 );
240 #if( QT_VERSION >= 0x040700 )
241 pixmap.convertFromImage( image );
246 pixmap = QPixmap::fromImage( image );
255 BaseClass::drawBackground( painter, rect );
286 QRectF viewport(
scene->sceneRect() );
287 scene->invalidate( viewport );
318 if( event->key() == Qt::Key_Backspace
319 || event->key() == Qt::Key_Delete )
377 point->setPos( QPointF( pos.x(), 0 ) );
378 scene->addItem( point );
402 double p = ( point->pos().x() - left->pos().x() )/( right->pos().x() - left->pos().x() );
449 scene->addItem( point );
450 scene->addItem( line );
511 point->
setPos( position );
518 if( event->button() == Qt::RightButton )
520 QPointF position( this->mapToScene( event->pos() ) );
521 if( position.y() < 0 )
534 BaseClass::mousePressEvent( event );
546 if( right->pos().x() > position.x() )
567 if( right->pos().x() > position.x() )
578 WColor toWColor(
const QColor& q )
580 return WColor( q.redF(), q.greenF(), q.blueF(), q.alphaF() );
592 QRectF bb =
scene->sceneRect();
597 double iso = ( cp->pos().x() - bb.x() )/bb.width();
605 double iso = ( p->pos().x() - bb.x() )/bb.width();
606 double alpha = 1.-( ( p->pos().y() - bb.y() )/bb.height() );
A QGraphicsItem that displays a pixmap in the background of the scene.
void setMyPixmap(const QPixmap &pixmap)
Set the background pixmap that will be displayed.
A control point for the color function.
void colorSelected(const QColor &color)
Called by the color dialog every time the user changes the color.
void setLeft(WTransferFunctionColorPoint *left)
Set the item left of us.
WTransferFunctionColorPoint * getRight() const
Returns the item right of this item.
void setRight(WTransferFunctionColorPoint *right)
Set the item right of us.
WTransferFunctionColorPoint * getLeft() const
Returns the item left of the this item.
Display a semi-transparent line graph as the histogram of the current data set.
const std::vector< double > & getData() const
Get histogram data.
Line object for the connection of alpha control points.
void setRight(WTransferFunctionPoint *right)
Sets point to the right.
void setLeft(WTransferFunctionPoint *left)
Sets point to the left.
A control point for the alpha function.
WTransferFunctionPoint * getLeft() const
Get point to the left.
WTransferFunctionLine * getLine() const
The current line if there is one.
WTransferFunctionPoint * getRight() const
Get point to the right.
virtual void setPos(QPointF point)
Overloaded form base class for debugging.
void setLeft(WTransferFunctionPoint *left)
Set point to the left.
void setRight(WTransferFunctionPoint *right)
Set point to the right.
void setLine(WTransferFunctionLine *line)
Set the line pointing to the right.
The scene for our visualization of the transfer function.
A class that stores a 1D transfer function which consists of a linear interpolation of alpha and colo...
void setHistogram(std::vector< double > &data)
Set the histogram going along with the transfer function.
void addColor(double iso, const WColor &color)
Insert a new color point.
void addAlpha(double iso, double alpha)
Insert a new alpha point.
The class managing the widget that wants to receive updates whenever a change occurrs.
virtual void guiUpdate(const WTransferFunction &tf)=0
update the gui