Commit 5cb464cc authored by Tobias Neeb's avatar Tobias Neeb
Browse files

[ADD #736] implement and extend methods to be able to use triangular-tf-widgets in the GUI

parent a3cf1c57
......@@ -32,11 +32,13 @@
#include "core/common/WTransferFunction2D.h"
#include "qtgui/controlPanel/transferFunction2D/WTransferFunction2DBackground.h"
#include "qtgui/controlPanel/transferFunction2D/WTransferFunction2DScene.h"
#include "WTransferFunction2DTriangleWidget.h"
#include "core/common/WHistogram2D.h"
#include "core/common/WLogger.h"
#include "WTransferFunction2DGUIWidget.h"
WTransferFunction2DGUIWidget::WTransferFunction2DGUIWidget( QWidget* qparent, WTransferFunction2DGuiNotificationClass* parent ):
BaseClass( qparent ),
parent( parent ),
......@@ -144,6 +146,7 @@ namespace
}
}
void WTransferFunction2DGUIWidget::updateTransferFunction()
{
WTransferFunction2D tf;
......@@ -153,8 +156,8 @@ void WTransferFunction2DGUIWidget::updateTransferFunction()
tf.setHistogram( hist ); // get the data back because we need this for comparison
}
// Serialite the current TF into the 2D TF object in normalized space
for( auto const &w : m_widgets )
// Serialize the current TF into the 2D TF object in normalized space
for( auto const &w : m_box_widgets )
{
double isoX = ( w->mapToScene( w->boundingRect().topLeft() ).x() / 300 );
double isoY = ( w->mapToScene( w->boundingRect().topLeft() ).y() / 300 );
......@@ -163,6 +166,27 @@ void WTransferFunction2DGUIWidget::updateTransferFunction()
QColor col( w->getColor().red(), w->getColor().green(), w->getColor().blue(), w->getColor().alpha() );
tf.addBoxWidget( isoX, isoY, width, height, toWColor( col ) );
}
for( auto const &w : m_triangle_widgets )
{
double isoX = ( w->mapToScene( w->boundingRect().topLeft() ).x() / 300 );
double isoY = ( w->mapToScene( w->boundingRect().topLeft() ).y() / 300 );
double width = ( ( w->getTriangle().right().x() - w->getTriangle().left().x() ) / 300 );
double height = ( ( w->getTriangle().mid().y() - w->getTriangle().left().y() ) / 300 ); //TODO(T. Neeb): Check for lowest point
QColor col( w->getColor().red(), w->getColor().green(), w->getColor().blue(), w->getColor().alpha() );
WTransferFunction2D::PolyPoint points[3] =
{
{
w->getTriangle().left().x(), w->getTriangle().left().y()
},
{
w->getTriangle().mid().x(), w->getTriangle().mid().y()
},
{
w->getTriangle().right().x(), w->getTriangle().right().y()
}
};
tf.addTriangleWidget( points, isoX, isoY, width, height, toWColor( col ) );
}
}
if( parent )
{
......@@ -184,11 +208,37 @@ void WTransferFunction2DGUIWidget::insertBoxWidget( const QPointF &pos, const do
WTransferFunction2DBoxWidget *box( new WTransferFunction2DBoxWidget( this, width, height, *color ) );
box->setPos( pos );
scene->addItem( box );
m_widgets.push_back( box );
m_box_widgets.push_back( box );
this->update();
dataChanged();
}
void WTransferFunction2DGUIWidget::insertTriangleWidgetNormalized( const QPointF &pos = QPointF( 0.0, 0.0 ),
const QColor * const color = new QColor( 255.0, 0.0, 0.0, 10.0 ) )
{
insertTriangleWidget( QPointF( pos.x() * 300., pos.y() * 300. ), color );
}
void WTransferFunction2DGUIWidget::insertTriangleWidget( const QPointF &pos, const QColor *const color )
{
WTransferFunction2DTriangleWidget *newTriangle( new WTransferFunction2DTriangleWidget( this, WTransferFunction2DTriangle(), *color ) );
for( QPointF p : newTriangle->getTriangle().getTriangle() )
{
p.setX( p.x() * 100 );
p.setY( p.y() * 100 );
}
newTriangle->setPos( pos );
newTriangle->getTriangle().updateTrianglePoints();
scene->addItem( newTriangle );
m_triangle_widgets.push_back( newTriangle );
this->update();
dataChanged();
}
void WTransferFunction2DGUIWidget::addTriangleWidget()
{
insertTriangleWidgetNormalized();
}
void WTransferFunction2DGUIWidget::addBoxWidget()
{
......@@ -198,12 +248,19 @@ void WTransferFunction2DGUIWidget::addBoxWidget()
void WTransferFunction2DGUIWidget::cleanTransferFunction()
{
std::vector< WTransferFunction2DBoxWidget* >::iterator it;
for( it = m_widgets.begin(); it != m_widgets.end(); it++ )
std::vector<WTransferFunction2DTriangleWidget *>::iterator dit;
for( it = m_box_widgets.begin(); it != m_box_widgets.end(); it++ )
{
scene->removeItem( *it );
delete( *it );
}
m_widgets.clear();
for( dit = m_triangle_widgets.begin(); dit != m_triangle_widgets.end(); dit++ )
{
scene->removeItem( *dit );
delete ( *dit );
}
m_triangle_widgets.clear();
m_box_widgets.clear();
dataChanged();
}
......@@ -213,22 +270,33 @@ void WTransferFunction2DGUIWidget::showContextMenu( const QPoint &pos )
QAction action1( "Add box widget", this );
QAction action2( "Clean transfer function", this );
connect( &action1, SIGNAL( triggered() ), this,
SLOT( addBoxWidget() ) );
QAction action3( "Add triangle widget", this );
connect( &action1, SIGNAL( triggered() ), this, SLOT( addBoxWidget() ) );
connect( &action3, SIGNAL( triggered() ), this, SLOT( addTriangleWidget() ) );
connect( &action2, SIGNAL( triggered() ), this, SLOT( cleanTransferFunction() ) );
contextMenu.addAction( &action1 );
contextMenu.addAction( &action3 );
contextMenu.addSeparator();
contextMenu.addAction( &action2 );
contextMenu.exec( mapToGlobal( pos ) );
}
void WTransferFunction2DGUIWidget::removeWidget( WTransferFunction2DBoxWidget *widget )
void WTransferFunction2DGUIWidget::removeBoxWidget( WTransferFunction2DBoxWidget *widget )
{
auto it = std::find( m_widgets.begin(), m_widgets.end(), widget );
m_widgets.erase( it );
auto it = std::find( m_box_widgets.begin(), m_box_widgets.end(), widget );
m_box_widgets.erase( it );
scene->removeItem( widget );
delete( widget );
this->dataChanged();
}
void WTransferFunction2DGUIWidget::removeTriangleWidget( WTransferFunction2DTriangleWidget *widget )
{
auto it = std::find( m_triangle_widgets.begin(), m_triangle_widgets.end(), widget );
m_triangle_widgets.erase( it );
scene->removeItem( widget );
delete ( widget );
this->dataChanged();
}
......@@ -30,10 +30,12 @@
#include "QGraphicsView"
#include "core/common/WHistogram2D.h"
#include "WTransferFunction2DBoxWidget.h"
#include "WTransferFunction2DTriangleWidget.h"
#include "WTransferFunction2DBackground.h"
class QGraphicsScene;
class WTransferFunction2DBoxWidget;
class WTransferFunction2DTriangleWidget;
/**
* The class managing the widget that wants to receive updates whenever
......@@ -97,11 +99,18 @@ public:
void setHistogram( const std::shared_ptr< WHistogram2D >& newHistogram );
/**
* Removes the specified widget
* Removes the specified box-widget
*
* \param widget widget which is to be deleted
*/
void removeWidget( WTransferFunction2DBoxWidget *widget );
void removeBoxWidget( WTransferFunction2DBoxWidget *widget );
/**
* Removes the specified triangle-widget
*
* \param widget widget which is to be deleted
*/
void removeTriangleWidget( WTransferFunction2DTriangleWidget *widget );
/**
* Updates the transfer function.
......@@ -118,6 +127,7 @@ public:
*/
void insertBoxWidget( const QPointF& pos, const double width, const double height, const QColor *const color );
/**
* Adds a box widget to the scene and list of widgets from normalized space
*
......@@ -128,6 +138,20 @@ public:
*/
void insertBoxWidgetNormalized( const QPointF& pos, const double width, const double height, const QColor *const color );
/**
* Adds a triangle widget to the scene and list of widgets
* \param pos pos of the widget in normalized space
* \param color color of the widget
*/
void insertTriangleWidget( const QPointF &pos, const QColor *const color );
/**
* Adds a triangle widget to the scene and list of widgets from normalized space
* \param pos pos of the widget in normalized space
* \param color color of the widget
*/
void insertTriangleWidgetNormalized( const QPointF &pos, const QColor * const color );
public slots:
/**
* Removes all transfer function widgets from the scene
......@@ -139,6 +163,11 @@ public slots:
*/
void addBoxWidget();
/**
* adds a basic triangle widget
*/
void addTriangleWidget();
/**
* Notification that the data changed, i.e., a control point has been moved or a color changed.
*/
......@@ -168,7 +197,8 @@ protected:
void setMyBackground();
private:
WTransferFunction2DGuiNotificationClass *parent; /*!< the class that receives our update notifications */
std::vector< WTransferFunction2DBoxWidget* > m_widgets; /*!< List of manipulation widgets */
std::vector< WTransferFunction2DBoxWidget* > m_box_widgets; /*!< List of manipulation box widgets */
std::vector<WTransferFunction2DTriangleWidget* > m_triangle_widgets; /*!< List of manipulation triangle widgets */
QGraphicsScene *scene; /*!< The scene that holds the GraphicItems */
WTransferFunction2DBackground *background; /*!< background that displays the 2D histogram */
std::shared_ptr< WHistogram2D > hist; /*!< 2D histogram which is displayed on the background */
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment