Commit e6749ae2 authored by Dirk Wilden's avatar Dirk Wilden

+image can be changed in the dialog

+histogram works (basically)

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@5732 383ad7c9-94d9-4d36-a494-682f7c89f535
parent 00526909
//=============================================================================
//
// CLASS QtFunctionPlot - IMPLEMENTATION
//
//=============================================================================
//== INCLUDES =================================================================
#include "QwtFunctionPlot.hh"
#include <iostream>
#include <algorithm>
#include <QPen>
#include <qlineedit.h>
#include <qlabel.h>
#include <qpainter.h>
//== NAMESPACES ===============================================================
namespace ACG {
//== IMPLEMENTATION ==========================================================
void
QwtFunctionPlot::
add_function( std::vector<double>& _x,
std::vector<double>& _y,
const char* _title,
QColor _col )
{
// if color is white -> choose random color
QColor col = _col;
if( col.red() == 255 && col.green() == 255 && col.blue() == 255)
col.setRgb( (int)(30 + double(rand())/double(RAND_MAX)*200),
(int)(30 + double(rand())/double(RAND_MAX)*200),
(int)(30 + double(rand())/double(RAND_MAX)*200));
// create new curve and attach it to plot widget
QwtPlotCurve *curve = new QwtPlotCurve(_title);
curve->setData( &(_x[0]), &(_y[0]), std::min(_x.size(), _y.size()));
curve->setPen( QPen(col));
functions_.push_back(curve);
curve->attach( qwtPlot );
// check legend item
((QwtLegendItem*)legend_->find( curve))->setChecked(true);
// plot_zoomer_->setZoomBase(false);
update_zoom_base();
qwtPlot->replot();
}
// ------------------------------------------------------------------------------
void
QwtFunctionPlot::
function_mode()
{
for(unsigned int i=0; i<functions_.size(); ++i)
{
functions_[i]->setStyle( QwtPlotCurve::Lines );
}
qwtPlot->replot();
}
// ------------------------------------------------------------------------------
void
QwtFunctionPlot::
histogram_mode()
{
for(unsigned int i=0; i<functions_.size(); ++i)
{
functions_[i]->setStyle( QwtPlotCurve::Sticks );
}
qwtPlot->replot();
}
// ------------------------------------------------------------------------------
void
QwtFunctionPlot::
linear_scaling()
{
// qwtPlot->setAxisScaleEngine(1, (QwtScaleEngine*)linear_scale_engine_);
// qwtPlot->replot();
}
// ------------------------------------------------------------------------------
void
QwtFunctionPlot::
logarithmic_scaling()
{
// qwtPlot->setAxisScaleEngine( 1, (QwtScaleEngine*)log10_scale_engine_);
// qwtPlot->replot();
}
// ------------------------------------------------------------------------------
void
QwtFunctionPlot::
update_pens(int _inc)
{
for(unsigned int i=0; i<functions_.size(); ++i)
{
QPen pen = functions_[i]->pen();
pen.setWidth( std::max(1,(int)pen.width() + _inc) );
functions_[i]->setPen( pen);
}
qwtPlot->replot();
}
// ------------------------------------------------------------------------------
void
QwtFunctionPlot::
add_function( std::vector<double>& _y,
const char* _title,
QColor _col )
{
// set up uniform x-vector
std::vector<double> x(_y.size());
for(unsigned int i=0; i<x.size(); ++i)
x[i] = i;
add_function( x, _y, _title, _col);
}
// ------------------------------------------------------------------------------
void
QwtFunctionPlot::
slotLegendChecked(QwtPlotItem* _plot_item, bool _visible)
{
// only draw checked curves
_plot_item->setVisible(_visible);
update_zoom_base();
qwtPlot->replot();
}
// ------------------------------------------------------------------------------
void
QwtFunctionPlot::
update_zoom_base()
{
QwtDoubleRect rect;
for(unsigned int i=0; i<functions_.size(); ++i)
{
if(functions_[i]->isVisible())
rect |= functions_[i]->boundingRect();
}
if( rect.isValid())
{
plot_zoomer_->setZoomBase( rect );
}
}
// ------------------------------------------------------------------------------
void
QwtFunctionPlot::
keyPressEvent ( QKeyEvent* _event )
{
switch( _event->key())
{
case Qt::Key_H:
{
std::cerr << "histogram mode...\n";
histogram_mode();
break;
}
case Qt::Key_F:
{
std::cerr << "function mode...\n";
function_mode();
break;
}
case Qt::Key_Plus:
{
update_pens(1);
break;
}
case Qt::Key_Minus:
{
update_pens(-1);
break;
}
case Qt::Key_1:
{
linear_scaling();
break;
}
case Qt::Key_2:
{
logarithmic_scaling();
break;
}
}
}
//=============================================================================
} // namespace db
//=============================================================================
//=============================================================================
//
// CLASS QwtFunctionPlot
//
//
// Author: David Bommes <bommes@cs.rwth-aachen.de>
//
// Version: $Revision: 1$
// Date: $Date: 200X-XX-XX$
//
//=============================================================================
#ifndef ACG_QWTFUNCTIONPLOT_HH
#define ACG_QWTFUNCTIONPLOT_HH
//== INCLUDES =================================================================
#include <QtGui>
#include <qwt_plot.h>
#include <qwt_plot_curve.h>
#include <qwt_plot_zoomer.h>
#include <qwt_legend.h>
#include <qwt_legend_item.h>
#include <qwt_scale_engine.h>
// qmake users have to includepc
#include <ui_QwtFunctionPlotBase.hh>
// ACGMake users have to include
// #include "QtFunctionPlotBase.hh"
#include <vector>
//== FORWARDDECLARATIONS ======================================================
//== NAMESPACES ===============================================================
namespace ACG
{
//== CLASS DEFINITION =========================================================
class QwtFunctionPlot : public QDialog, public Ui::QwtFunctionPlotBase
{
Q_OBJECT
public:
/// Default constructor
QwtFunctionPlot( QWidget* _parent = 0 ):
QDialog( _parent ),
Ui::QwtFunctionPlotBase()
{
setupUi( this );
legend_ = new QwtLegend();
// make legend checkable
legend_->setItemMode( QwtLegend::CheckableItem );
qwtPlot->insertLegend(legend_);
plot_zoomer_ = new QwtPlotZoomer( qwtPlot->canvas());
// connect for legend handling
connect(qwtPlot, SIGNAL( legendChecked(QwtPlotItem*, bool)),
this, SLOT( slotLegendChecked(QwtPlotItem*, bool)) );
// delete widget on close
setAttribute(Qt::WA_DeleteOnClose, true);
// init scale engine
linear_scale_engine_ = new QwtLinearScaleEngine;
log10_scale_engine_ = new QwtLog10ScaleEngine;
}
/// Destructor
~QwtFunctionPlot() {}
// clear plot
void clear() { functions_.clear(); }
void add_function( std::vector<double>& _x,
std::vector<double>& _y,
const char* _title="",
QColor _col = QColor( 255,255,255 ) );
void add_function( std::vector<double>& _y,
const char* _title="",
QColor _col = QColor( 255,255,255 ) );
// switch into function mode
void function_mode();
// switch into histogram mode
void histogram_mode();
// update pen size
void update_pens(int _inc);
// set scaling
void linear_scaling();
void logarithmic_scaling();
protected slots:
void slotLegendChecked(QwtPlotItem* _plot_item, bool _visible);
virtual void keyPressEvent ( QKeyEvent* _event );
private:
void update_zoom_base();
private:
std::vector< QwtPlotCurve* > functions_;
QwtPlotZoomer* plot_zoomer_;
QwtLegend* legend_;
QwtLinearScaleEngine* linear_scale_engine_;
QwtLog10ScaleEngine* log10_scale_engine_;
};
//=============================================================================
} // namespace ACG
//=============================================================================
#endif // ACG_QWTFUNCTIONPLOT_HH defined
//=============================================================================
<ui version="4.0" >
<class>QwtFunctionPlotBase</class>
<widget class="QWidget" name="QwtFunctionPlotBase" >
<property name="windowModality" >
<enum>Qt::NonModal</enum>
</property>
<property name="geometry" >
<rect>
<x>0</x>
<y>0</y>
<width>474</width>
<height>474</height>
</rect>
</property>
<property name="windowTitle" >
<string>Function Plot</string>
</property>
<layout class="QHBoxLayout" name="horizontalLayout" >
<item>
<widget class="QwtPlot" name="qwtPlot" />
</item>
</layout>
</widget>
<layoutdefault spacing="6" margin="11" />
<pixmapfunction>qPixmapFromMimeSource</pixmapfunction>
<customwidgets>
<customwidget>
<class>QwtPlot</class>
<extends>QFrame</extends>
<header>qwt_plot.h</header>
</customwidget>
</customwidgets>
<resources/>
<connections/>
</ui>
...@@ -43,6 +43,8 @@ ...@@ -43,6 +43,8 @@
#include "OpenFlipper/BasePlugin/PluginFunctions.hh" #include "OpenFlipper/BasePlugin/PluginFunctions.hh"
#include "OpenFlipper/common/GlobalOptions.hh" #include "OpenFlipper/common/GlobalOptions.hh"
#include <math.h>
#define TEXTUREDATA "TextureData" #define TEXTUREDATA "TextureData"
...@@ -302,6 +304,9 @@ void TextureControlPlugin::slotTextureUpdated( QString _textureName , int _ident ...@@ -302,6 +304,9 @@ void TextureControlPlugin::slotTextureUpdated( QString _textureName , int _ident
return; return;
} }
QImage textureImage;
getImage( texData->texture(_textureName).filename(), textureImage);
// ================================================================================ // ================================================================================
// As the current texture is active, update it // As the current texture is active, update it
// ================================================================================ // ================================================================================
...@@ -309,10 +314,12 @@ void TextureControlPlugin::slotTextureUpdated( QString _textureName , int _ident ...@@ -309,10 +314,12 @@ void TextureControlPlugin::slotTextureUpdated( QString _textureName , int _ident
TriMesh* mesh = PluginFunctions::triMesh(obj); TriMesh* mesh = PluginFunctions::triMesh(obj);
doUpdateTexture(texData->texture(_textureName), *mesh); doUpdateTexture(texData->texture(_textureName), *mesh);
PluginFunctions::triMeshObject(obj)->textureNode()->set_repeat(texData->texture(_textureName).parameters.repeat); PluginFunctions::triMeshObject(obj)->textureNode()->set_repeat(texData->texture(_textureName).parameters.repeat);
PluginFunctions::triMeshObject(obj)->textureNode()->set_texture( textureImage );
} else if ( obj->dataType( DATA_POLY_MESH ) ) { } else if ( obj->dataType( DATA_POLY_MESH ) ) {
PolyMesh* mesh = PluginFunctions::polyMesh(obj); PolyMesh* mesh = PluginFunctions::polyMesh(obj);
doUpdateTexture(texData->texture(_textureName), *mesh); doUpdateTexture(texData->texture(_textureName), *mesh);
PluginFunctions::polyMeshObject(obj)->textureNode()->set_repeat(texData->texture(_textureName).parameters.repeat); PluginFunctions::polyMeshObject(obj)->textureNode()->set_repeat(texData->texture(_textureName).parameters.repeat);
PluginFunctions::polyMeshObject(obj)->textureNode()->set_texture( textureImage );
} }
// ================================================================================ // ================================================================================
...@@ -329,6 +336,7 @@ void TextureControlPlugin::slotTextureUpdated( QString _textureName , int _ident ...@@ -329,6 +336,7 @@ void TextureControlPlugin::slotTextureUpdated( QString _textureName , int _ident
template< typename MeshT > template< typename MeshT >
void TextureControlPlugin::doUpdateTexture ( Texture& _texture, MeshT& _mesh ) void TextureControlPlugin::doUpdateTexture ( Texture& _texture, MeshT& _mesh )
{ {
if ( _texture.type == HALFEDGEBASED ) { if ( _texture.type == HALFEDGEBASED ) {
if (_texture.dimension() == 1) { if (_texture.dimension() == 1) {
...@@ -728,6 +736,11 @@ void TextureControlPlugin::pluginsInitialized() { ...@@ -728,6 +736,11 @@ void TextureControlPlugin::pluginsInitialized() {
connect( settingsDialog_, SIGNAL( applyProperties(TextureData*,QString,int) ), connect( settingsDialog_, SIGNAL( applyProperties(TextureData*,QString,int) ),
this, SLOT( applyDialogSettings(TextureData*,QString,int) )); this, SLOT( applyDialogSettings(TextureData*,QString,int) ));
connect( settingsDialog_, SIGNAL( getCoordinates1D(QString,int,std::vector< double >&)),
this, SLOT( getCoordinates1D(QString,int,std::vector< double >&)));
settingsDialog_->installEventFilter( this );
// ================================================================================ // ================================================================================
// Create action group and menu for global textures // Create action group and menu for global textures
// ================================================================================ // ================================================================================
...@@ -887,7 +900,9 @@ void TextureControlPlugin::doSwitchTexture( QString _textureName , int _id ) { ...@@ -887,7 +900,9 @@ void TextureControlPlugin::doSwitchTexture( QString _textureName , int _id ) {
// If texture is flagged dirty, update it ( this jumps to texture updated // If texture is flagged dirty, update it ( this jumps to texture updated
// which will update the visualization ) // which will update the visualization )
// ================================================================================ // ================================================================================
if ( !multiTextureMode && texData->texture( _textureName).dirty ) { if ( !multiTextureMode && texData->texture( _textureName).dirty ) {
// TODO: maybe introduce lock to prevent extra redraws if updating all objects // TODO: maybe introduce lock to prevent extra redraws if updating all objects
emit updateTexture( texData->texture( _textureName ).name() , obj->id() ); emit updateTexture( texData->texture( _textureName ).name() , obj->id() );
return; return;
...@@ -1059,5 +1074,59 @@ void TextureControlPlugin::slotTextureContextMenu( QAction * _action ) { ...@@ -1059,5 +1074,59 @@ void TextureControlPlugin::slotTextureContextMenu( QAction * _action ) {
} }
//compute histogram for the given texture property
void TextureControlPlugin::getCoordinates1D(QString _textureName, int _id, std::vector< double >& _x ){
// Get the new object
BaseObjectData* obj;
if (! PluginFunctions::getObject( _id , obj ) ) {
emit log(LOGERR,"Unable to get Object for id " + QString::number(_id) );
}
// ================================================================================
// Get Texture data for current object
// ================================================================================
TextureData* texData = dynamic_cast< TextureData* > ( obj->objectData(TEXTUREDATA) );
if (texData == 0) {
std::cerr << "Object has no texture data" << std::endl;
return;
}
// ================================================================================
// Check for requested Texture
// ================================================================================
if ( !texData->textureExists(_textureName) ) {
emit log(LOGERR, "Texture not available! " + _textureName );
return;
}
OpenMesh::VPropHandleT< double > coordProp;
_x.clear();
if( obj->dataType( DATA_TRIANGLE_MESH ) ) {
TriMesh* mesh = PluginFunctions::triMesh(obj);
if ( !mesh->get_property_handle(coordProp, _textureName.toStdString() ) ){
std::cerr << "Texture Property not found: " << _textureName.toStdString() << std::endl;
return;
}
for ( TriMesh::VertexIter v_it = mesh->vertices_begin() ; v_it != mesh->vertices_end(); ++v_it)
_x.push_back( mesh->property(coordProp,v_it) );
} else if ( obj->dataType( DATA_POLY_MESH ) ) {
PolyMesh* mesh = PluginFunctions::polyMesh(obj);
if ( !mesh->get_property_handle(coordProp, _textureName.toStdString() ) ){
std::cerr << "Texture Property not found: " << _textureName.toStdString() << std::endl;
return;
}
for ( PolyMesh::VertexIter v_it = mesh->vertices_begin() ; v_it != mesh->vertices_end(); ++v_it)
_x.push_back( mesh->property(coordProp,v_it) );
}
}
Q_EXPORT_PLUGIN2( texturecontrolplugin , TextureControlPlugin ); Q_EXPORT_PLUGIN2( texturecontrolplugin , TextureControlPlugin );
...@@ -53,28 +53,6 @@ ...@@ -53,28 +53,6 @@
#include "textureProperties.hh" #include "textureProperties.hh"
#include "TextureData.hh" #include "TextureData.hh"
/*
struct Texture {
QString name;
QString filename;
uint dimension;
double clamp_min;
double clamp_max;
bool clamp;
bool repeat;
double max_val;
bool center;
bool abs;
bool scale;
uint type;
};*/
class TextureControlPlugin : public QObject, BaseInterface, TextureInterface, MenuInterface, LoggingInterface, LoadSaveInterface,ContextMenuInterface class TextureControlPlugin : public QObject, BaseInterface, TextureInterface, MenuInterface, LoggingInterface, LoadSaveInterface,ContextMenuInterface
{ {
...@@ -87,7 +65,6 @@ class TextureControlPlugin : public QObject, BaseInterface, TextureInterface, Me ...@@ -87,7 +65,6 @@ class TextureControlPlugin : public QObject, BaseInterface, TextureInterface, Me
Q_INTERFACES(ContextMenuInterface) Q_INTERFACES(ContextMenuInterface)
public: public:
enum TextureType { VERTEXBASED = 1 << 0, HALFEDGEBASED = 1 << 1};
signals: signals:
...@@ -125,8 +102,6 @@ class TextureControlPlugin : public QObject, BaseInterface, TextureInterface, Me ...@@ -125,8 +102,6 @@ class TextureControlPlugin : public QObject, BaseInterface, TextureInterface, Me
void slotSwitchTexture( QString _textureName, int _id ); void slotSwitchTexture( QString _textureName, int _id );
void slotSwitchTexture( QString _textureName ); void slotSwitchTexture( QString _textureName );
// LoadSaveInterface // LoadSaveInterface
void fileOpened( int _id ); void fileOpened( int _id );
void addedEmptyObject( int _id ); void addedEmptyObject( int _id );
...@@ -167,6 +142,9 @@ class TextureControlPlugin : public QObject, BaseInterface, TextureInterface, Me ...@@ -167,6 +142,9 @@ class TextureControlPlugin : public QObject, BaseInterface, TextureInterface, Me
private slots: private slots:
void applyDialogSettings(TextureData* _texData, QString _textureName, int _id); void applyDialogSettings(TextureData* _texData, QString _textureName, int _id);
//compute histogram for the given texture property
void getCoordinates1D(QString _textureName, int _id, std::vector< double >& _x );
private: private:
/// Take a scalar value and return a clamped,... depending on texture settings /// Take a scalar value and return a clamped,... depending on texture settings
......
...@@ -148,7 +148,7 @@ int TextureData::addTexture(QString _textureName, QString _filename, uint _dimen ...@@ -148,7 +148,7 @@ int TextureData::addTexture(QString _textureName, QString _filename, uint _dimen
tex.filename( _filename ); tex.filename( _filename );
tex.dimension(_dimension); tex.dimension(_dimension);
tex.enable(); tex.enable();
tex.dirty = false; tex.dirty = true;
tex.type = VERTEXBASED; tex.type = VERTEXBASED;
tex.hidden(false); tex.hidden(false);
// tex.parameters = TexParameters; // tex.parameters = TexParameters;
...@@ -188,7 +188,7 @@ bool TextureData::addMultiTexture( QString _textureName ) { ...@@ -188,7 +188,7 @@ bool TextureData::addMultiTexture( QString _textureName ) {
tex.id( nextInternalID_++ ); tex.id( nextInternalID_++ );
tex.name( _textureName ); tex.name( _textureName );
tex.filename("MultiTexture"); tex.filename("MultiTexture");
tex.dirty = false; tex.dirty = true;
tex.type = MULTITEXTURE; tex.type = MULTITEXTURE;
tex.hidden(false); tex.hidden(false);
......
...@@ -34,12 +34,6 @@ ...@@ -34,12 +34,6 @@
#include "textureProperties.hh" #include "textureProperties.hh"
#ifdef WITH_QWT
#include <qwt_plot_grid.h>
#include <qwt_text.h>
#include <qwt_plot.h>
#endif
#include <float.h> #include <float.h>
#include <QtGui> #include <QtGui>
...@@ -73,33 +67,10 @@ texturePropertiesWidget::texturePropertiesWidget(QWidget *parent) ...@@ -73,33 +67,10 @@ texturePropertiesWidget::texturePropertiesWidget(QWidget *parent)
#ifdef WITH_QWT #ifdef WITH_QWT
QGridLayout* layout = new QGridLayout( originalData); QGridLayout* layout = new QGridLayout( originalData);
originalDataHistogram_ = new QwtPlot(0); functionPlot_ = new ACG::QwtFunctionPlot(0);
layout->addWidget( originalDataHistogram_ , 0,0 );
QwtText axis_title_x("value");
// axis_title_x.setFont(arial);
QwtText axis_title_y("count");
// axis_title_y.setFont(arial);
originalDataHistogram_->setAxisTitle(QwtPlot::xBottom, axis_title_x);
originalDataHistogram_->setAxisTitle(QwtPlot::yLeft, axis_title_y);
originalDataHistogram_->setCanvasBackground(Qt::white);
QwtPlotGrid *grid2 = new QwtPlotGrid; layout->addWidget( functionPlot_ , 0,0 );
grid2->enableYMin(true);
grid2->enableXMin(true);
grid2->setMajPen(QPen(Qt::black, 0, Qt::DotLine));
grid2->setMinPen(QPen(Qt::gray, 0 , Qt::DotLine));
grid2->attach(originalDataHistogram_);