27 #include <QtCore/QMimeData>
28 #include <QtCore/QUrl>
29 #include <QGraphicsSceneDragDropEvent>
31 #include "core/common/WTransferFunction.h"
32 #include "WTransferFunctionScene.h"
33 #include "WTransferFunctionWidget.h"
39 setBackgroundBrush( QBrush( Qt::lightGray, Qt::CrossPattern ) );
48 if( sceneRect().contains( event->scenePos() ) )
50 if( event->mimeData()->hasColor() )
58 if( event->mimeData()->hasImage() )
66 if( event->mimeData()->hasUrls() )
72 QImage image( event->mimeData()->urls().first().toLocalFile() );
80 BaseClass::dragMoveEvent( event );
85 inline QColor toQColor(
const WColor &color )
88 tmp.setRgbF( color[0],
118 WColor cc = tf.
getColor( nbColors-1 );
123 for(
size_t i = 1; i< nbColors-1; ++i )
143 double alpha = tf.
getAlpha( nbAlphas-1 );
148 for(
size_t i = 1; i< nbAlphas-1; ++i )
160 if( sceneRect().contains( event->scenePos() ) )
162 if( event->mimeData()->hasColor() )
167 QColor color = qvariant_cast<QColor>( event->mimeData()->colorData() );
174 if( event->mimeData()->hasImage() )
176 myImage = qvariant_cast < QImage > ( event->mimeData()->imageData() );
179 if( event->mimeData()->hasUrls() )
182 Q_ASSERT( !urls.empty() );
183 myImage = QImage( urls.first().toLocalFile() );
186 if( !myImage.isNull() )
189 QImage image = myImage;
191 std::vector < unsigned char > data( 4*image.width() );
192 for(
int i = 0; i < image.width( ); ++i )
194 QRgb pixel = image.pixel( i, 0 );
195 data[ 4*i+0 ] = qRed( pixel );
196 data[ 4*i+1 ] = qGreen( pixel );
197 data[ 4*i+2 ] = qBlue( pixel );
198 data[ 4*i+3 ] = qAlpha( pixel );
206 BaseClass::dropEvent( event );
virtual ~WTransferFunctionScene()
Default destructor.
virtual void dragMoveEvent(QGraphicsSceneDragDropEvent *event)
Checks whether the drag is inside the main rectangle of the scene and whether the dragged object is o...
virtual void dropEvent(QGraphicsSceneDragDropEvent *event)
Allows drop of QColor-alike objects and creates new color control points in the scene.
WTransferFunctionScene(QObject *parent=0)
Default constructor.
WTransferFunctionWidget * myparent
storage of the widget as this currently manages the data
A class that stores a 1D transfer function which consists of a linear interpolation of alpha and colo...
double getColorIsovalue(size_t i) const
The isovalue of the color at a given index.
const std::vector< double > & getHistogram() const
Returns the histogram.
size_t numAlphas() const
Get the number of alphas.
double getAlphaIsovalue(size_t i) const
Get the isovalue at a given index in the alpha values.
size_t numColors() const
Get the number of colors.
double getAlpha(size_t i) const
Get alpha at given index.
const WColor & getColor(size_t i) const
Get color at given index.
static WTransferFunction createFromRGBA(unsigned char const *const rgba, size_t size)
Try to estimate a transfer function from an RGBA image.