Commit cc8996c6 authored by Edwin Carlinet's avatar Edwin Carlinet
Browse files

Add tosgui apps.

parent d0e063ee
......@@ -2,6 +2,7 @@ project(apps)
add_subdirectory(tests)
add_subdirectory(imview)
add_subdirectory(maxtree_comparison)
add_subdirectory(simplification)
add_subdirectory(clattice)
add_subdirectory(tosgui)
include(FindQwt)
FIND_PACKAGE(Qt4 REQUIRED)
FIND_PACKAGE(Qwt REQUIRED)
INCLUDE(${QT_USE_FILE})
include_directories(${QWT_INCLUDE_DIR})
link_libraries(-lfreeimage)
QT4_WRAP_CPP(tosgui_HEADERS_MOC
${CMAKE_HOME_DIRECTORY}/mln/qt/mainwin.hpp
tosapp.hpp
)
add_executable(tosgui tosgui.cpp tosapp.cpp
${tosgui_HEADERS_MOC}
${CMAKE_HOME_DIRECTORY}/mln/qt/qtimage.cpp
${CMAKE_HOME_DIRECTORY}/mln/qt/mainwin.cpp
${CMAKE_HOME_DIRECTORY}/mln/qt/graphics_pixmap_item.cpp
)
target_link_libraries(tosgui
${QWT_LIBRARY}
${QT_QTMAIN_LIBRARY}
${QT_LIBRARIES}
)
#include "tosapp.hpp"
#include <QEvent>
#include <QMouseEvent>
#include <qwt_picker_machine.h>
namespace mln
{
QAttributeBase::QAttributeBase()
{
m_curve = new QwtPlotCurve("Energy");
m_curve->setSamples(m_data);
m_curve->setStyle(QwtPlotCurve::Lines);
m_curve->attach(this);
std::cout << this->canvas() << std::endl;
picker = new QwtPlotPicker(this->canvas());
picker->setStateMachine(new QwtPickerTrackerMachine);
picker->setTrackerMode(QwtPicker::AlwaysOn);
picker->setRubberBand(QwtPicker::VLineRubberBand);
picker->installEventFilter(this);
picker->setEnabled(true);
this->setFocus();
std::cout << picker->isActive() << std::endl;
std::cout << picker->isEnabled() << std::endl;
}
bool
QAttributeBase::eventFilter(QObject* obj, QEvent* event)
{
std::cout << "Event" << std::endl;
if (obj == picker) {
if (event->type() == QEvent::MouseButtonPress)
{
QPoint p = static_cast<QMouseEvent*>(event)->pos();
std::cout << "Selected " << p.x() << "," << p.y() << std::endl;
return false;
}
return false;
}
return QwtPlot::eventFilter(obj, event);
}
}
#ifndef TOSAPP_HPP
# define TOSAPP_HPP
# include <mln/core/image/image2d.hpp>
#include <qwt_plot.h>
#include <qwt_plot_curve.h>
#include <qwt_plot_picker.h>
namespace mln
{
class QAttributeBase : public QwtPlot
{
Q_OBJECT;
public:
QAttributeBase();
signals:
void nodeSelected(const point2d& pt);
public slots:
virtual void plotNode(const point2d& pt) = 0;
protected:
virtual bool eventFilter(QObject* obj, QEvent *ev);
protected:
QwtPlotPicker* picker;
QwtPlotCurve* m_curve;
QVector<QPointF> m_data;
};
template <typename V>
class QAttribute : public QAttributeBase
{
public:
QAttribute(const image2d<V>& attr,
const image2d<unsigned>& parent);
virtual void plotNode(const point2d& pt);
private:
const image2d<V>& m_attr;
const image2d<unsigned>& m_parent;
};
/**************************/
/*** Implementation **/
/**************************/
template <typename V>
QAttribute<V>::QAttribute(const image2d<V>& attr,
const image2d<unsigned>& parent)
: m_attr (attr),
m_parent (parent)
{
}
template <typename V>
void
QAttribute<V>::plotNode(const point2d& p)
{
unsigned x = m_parent.index_of_point(p);
unsigned n = 1;
unsigned q = x;
while (q != m_parent[q]) {
++n;
q = m_parent[q];
}
std::cout << "Add " << n << " nodes." << std::endl;
this->m_data.clear();
this->m_data.resize(n);
while (x != m_parent[x]) {
this->m_data[n-1].setX(n-1);
this->m_data[n-1].setY(m_attr[x]);
std::cout << n-1 << ":" << this->m_data[n-1].y() << std::endl;
--n;
x = m_parent[x];
}
this->m_data[0].setX(0);
this->m_data[0].setY(m_attr[x]);
this->m_curve->setSamples(m_data);
this->replot();
std::cout << this->picker->isActive() << std::endl;
std::cout << this->picker->isEnabled() << std::endl;
}
}
#endif // ! TOSAPP_HPP
#include <QApplication>
#include <QtGui>
#include <mln/core/image/image2d.hpp>
#include <mln/core/neighb2d.hpp>
#include <mln/core/algorithm/transform.hpp>
#include <mln/io/imread.hpp>
#include <mln/morpho/tos/tos.hpp>
#include <mln/qt/mainwin.hpp>
#include <apps/tos/Kinterpolate.hpp>
#include "tosapp.hpp"
int main(int argc, char** argv)
{
using namespace mln;
if (argc != 2)
std::cerr << "Usage: " << argv[0] << " ima.pgm" << std::endl;
QApplication a(argc, argv);
image2d<uint8> ima;
io::imread(argv[1], ima);
auto f = interpolate_median(ima, UInt<9> ());
image2d< UInt<9> > K;
std::vector<unsigned> S;
image2d<unsigned> parent;
std::tie(K, parent, S) = morpho::ToS(f, c4);
auto Kui8 = transform(K, [](const UInt<9>& v) -> uint8 {
return v / 2;
});
qt::MainWindow<uint8> main(Kui8);
main.show();
QAttribute<uint8> wattr(Kui8, parent);
wattr.show();
QObject::connect(&main, SIGNAL(pointSelected(const point2d&)),
&wattr, SLOT(plotNode(const point2d&)));
// QImage image("../../../img/small.pgm");
// QGraphicsPixmapItem item(QPixmap::fromImage(image));
// QGraphicsScene* m_scene = new QGraphicsScene;
// m_scene->addItem(&item);
// QGraphicsView* view = new QGraphicsView(m_scene);
// QMainWindow win;
// win.setCentralWidget(view);
// win.show();
a.exec();
}
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