void TransferFunctionEditor::_onTransferFunctionChanged( UInt8Vector tf )
{
    QGradientStops stops;
    QPolygon redPoints, bluePoints, greenPoints, alphaPoints;
    for( size_t i = 0; i < 256; ++i )
    {
        redPoints << QPoint(i, tf[i*4]);
        greenPoints << QPoint(i, tf[i*4+1]);
        bluePoints << QPoint(i, tf[i*4+2]);
        alphaPoints << QPoint(i, tf[i*4+3]);
        stops << QGradientStop( float(i) / 255.f , QColor( tf[i*4], tf[i*4+1], tf[i*4+2], tf[i*4+3]));
    }

    QPolygonF redPointsF = _convertPoints( _filterPoints( redPoints ),
                                           _redWidget->width(),
                                           _redWidget->height());
    QPolygonF greenPointsF = _convertPoints( _filterPoints( greenPoints ),
                                             _greenWidget->width(),
                                             _greenWidget->height());
    QPolygonF bluePointsF = _convertPoints( _filterPoints( bluePoints ),
                                            _blueWidget->width(),
                                            _blueWidget->height());
    QPolygonF alphaPointsF = _convertPoints( _filterPoints( alphaPoints ),
                                             _alphaWidget->width(),
                                             _alphaWidget->height());

    _redWidget->setPoints( redPointsF );
    _greenWidget->setPoints( greenPointsF );
    _blueWidget->setPoints( bluePointsF );
    _alphaWidget->setPoints( alphaPointsF );
    _pointsUpdated();
}
void TransferFunctionEditor::_load()
{
    const QString filename = QFileDialog::getOpenFileName( this, "Load transfer function",
                                                           QString(),
                                                           TF_FILE_FILTER );
    if( filename.isEmpty( ))
        return;

    QFile file( filename );
    file.open( QIODevice::ReadOnly );
    QDataStream in( &file );

    quint32 header;
    in >> header;
    if( header != TF_FILE_HEADER )
        return;

    quint32 version;
    in >> version;
    if( version != TF_FILE_VERSION )
        return;

    QPolygonF redPoints, greenPoints, bluePoints, alphaPoints;
    QGradientStops gradientStops;
    in >> redPoints
       >> greenPoints
       >> bluePoints
       >> alphaPoints;

    _redWidget->setPoints( redPoints );
    _greenWidget->setPoints( greenPoints );
    _blueWidget->setPoints( bluePoints );
    _alphaWidget->setPoints( alphaPoints );
    _pointsUpdated();
}
Beispiel #3
0
void TransferFunctionEditor::_clear()
{
    QGradientStops stops;

    stops << QGradientStop( 0.00, QColor::fromRgba( 0 ));
    stops << QGradientStop( 1.00, QColor::fromRgba( 0xffffffff ));

    setColorMapStops( stops );
    _gradientRenderer->setGradientStops( stops );
    _pointsUpdated();
}
void TransferFunctionEditor::_clear()
{
    QPolygonF points;
    const double h = _redWidget->height();
    const double w = _redWidget->width();
    points << QPointF( 0.0 * w, h );
    points << QPointF( 1.0 * w, 0.0 );

    _redWidget->setPoints( points );
    _greenWidget->setPoints( points );
    _blueWidget->setPoints( points );
    _alphaWidget->setPoints( points );
    _pointsUpdated();
}
Beispiel #5
0
TransferFunctionEditor::TransferFunctionEditor( livre::Controller& controller, QWidget* tfParentWidget )
    : QWidget( tfParentWidget )
    , _controller( controller )
    , ui( new Ui::TransferFunctionEditor )
    , _isConnected( false )
    , _redWidget( new ColorMapWidget( ColorMapWidget::RED_SHADE, this ))
    , _greenWidget( new ColorMapWidget( ColorMapWidget::GREEN_SHADE, this ))
    , _blueWidget( new ColorMapWidget( ColorMapWidget::BLUE_SHADE, this ))
    , _alphaWidget( new ColorMapWidget( ColorMapWidget::ARGB_SHADE, this ))
    , _gradientRenderer( new GradientRenderer( this ))
{
    ui->setupUi( this );

    // Add the widgets to the layouts to match the exact positions on the TransferFunctionEditor.
    ui->redLayout->addWidget( _redWidget );
    ui->greenLayout->addWidget( _greenWidget );
    ui->blueLayout->addWidget( _blueWidget );
    ui->rgbaLayout->addWidget( _alphaWidget );
    ui->rgbGradientLayout->addWidget( _gradientRenderer );

    connect( _redWidget, SIGNAL( colorsChanged()),
            this, SLOT( _pointsUpdated()));
    connect( _greenWidget, SIGNAL( colorsChanged()),
            this, SLOT( _pointsUpdated()));
    connect( _blueWidget, SIGNAL( colorsChanged()),
            this, SLOT( _pointsUpdated()));
    connect( _alphaWidget, SIGNAL( colorsChanged()),
            this, SLOT( _pointsUpdated()));

    connect( ui->resetButton, SIGNAL( clicked()), this, SLOT( _setDefault()));
    connect( ui->clearButton, SIGNAL( clicked()), this, SLOT( _clear()));
    connect( ui->btnConnect, SIGNAL( pressed()), this, SLOT( _connect( )));
    connect( ui->btnDisconnect, SIGNAL( pressed()), this, SLOT( _disconnect()));

    QTimer::singleShot( 50, this, SLOT( _setDefault()));
}
Beispiel #6
0
void TransferFunctionEditor::_setDefault()
{
    QGradientStops stops;

    stops << QGradientStop( 0.0, QColor::fromRgba( 0x000000ff ));
    stops << QGradientStop( 0.1, QColor::fromRgba( 0x330000ff ));
    stops << QGradientStop( 0.2, QColor::fromRgba( 0x53007dff ));
    stops << QGradientStop( 0.3, QColor::fromRgba( 0x7300ffff ));
    stops << QGradientStop( 0.4, QColor::fromRgba( 0x7f00ff7d ));
    stops << QGradientStop( 0.5, QColor::fromRgba( 0x8500ff00 ));
    stops << QGradientStop( 0.6, QColor::fromRgba( 0x86ffff00 ));
    stops << QGradientStop( 0.7, QColor::fromRgba( 0x8cff7d00 ));
    stops << QGradientStop( 0.8, QColor::fromRgba( 0x99ff0000 ));
    stops << QGradientStop( 0.925, QColor::fromRgba( 0xb3ff007d ));
    stops << QGradientStop( 1.00, QColor::fromRgba( 0xffff7dff ));

    setColorMapStops( stops );
    _gradientRenderer->setGradientStops( stops );
    _pointsUpdated();
}