Commit 996904c4 authored by Edwin Carlinet's avatar Edwin Carlinet Committed by Edwin Carlinet
Browse files

Start supervised segmentation app based on ToS.

 	* apps/CMakeLists.txt,
	* apps/supervised-gui/CMakeLists.txt,
	* apps/supervised-gui/brush.cpp,
	* apps/supervised-gui/brush.hpp,
	* apps/supervised-gui/supervised-cli.cpp: New.
parent e37f7a51
......@@ -7,3 +7,4 @@ add_subdirectory(simplification)
add_subdirectory(clattice)
add_subdirectory(tosgui)
add_subdirectory(saliency)
add_subdirectory(supervised-gui)
FIND_PACKAGE(Qt4 REQUIRED)
INCLUDE(${QT_USE_FILE})
link_libraries(-lfreeimage)
QT4_WRAP_CPP(supervised-cli_MOC
${CMAKE_HOME_DIRECTORY}/mln/qt/imageviewer.hpp
brush.hpp)
add_executable(supervised-cli supervised-cli.cpp brush.cpp
${supervised-cli_MOC}
${CMAKE_HOME_DIRECTORY}/mln/qt/qtimage.cpp
${CMAKE_HOME_DIRECTORY}/mln/qt/imageviewer.cpp
)
target_link_libraries(supervised-cli ${QT_QTMAIN_LIBRARY} ${QT_LIBRARIES})
#include "brush.hpp"
#include <QtGui>
#include <iostream>
#include <mln/io/imsave.hpp>
inline
void brush(QPixmap* pixmap, const QPointF& position, QColor color, int r)
{
QPainter painter(pixmap);
painter.setBrush(color);
painter.setPen(Qt::NoPen);
QRectF rectangle(position.x() - r, position.y() - r, 2*r, 2*r);
painter.drawEllipse(rectangle);
}
MyBrush::MyBrush(mln::qt::ImageViewer* viewer)
: m_viewer (viewer),
m_scene(viewer->getScene()),
m_pixmap(viewer->getPixmap()),
m_ima(m_pixmap->pixmap()),
m_active(false),
m_radius(5)
{
}
bool
MyBrush::eventFilter(QObject* obj, QEvent* ev)
{
if (m_active and ev->type() == QEvent::GraphicsSceneMouseMove)
{
QGraphicsSceneMouseEvent* event = static_cast<QGraphicsSceneMouseEvent*>(ev);
if (event->buttons() & Qt::LeftButton)
{
brush(&m_ima, m_pixmap->mapFromScene(event->scenePos()), m_color, m_radius);
m_pixmap->setPixmap(m_ima);
}
}
return false;
}
void
MyBrush::setColor1()
{
m_active = true;
m_color = Qt::red;
}
void
MyBrush::setColor2()
{
m_active = true;
m_color = Qt::blue;
}
void
MyBrush::setRadius(int k)
{
m_radius = k;
}
void
MyBrush::run()
{
std::cout << "Running." << std::endl;
m_viewer->notify();
mln::io::imsave(m_viewer->getView(), "/tmp/view.tiff");
}
#ifndef BRUSH_HPP
# define BRUSH_HPP
# include <mln/qt/imageviewer.hpp>
class MyBrush : public QObject
{
Q_OBJECT;
public:
MyBrush(mln::qt::ImageViewer* viewer);
bool eventFilter(QObject* obj, QEvent* ev);
public slots:
void setColor1();
void setColor2();
void setRadius(int k);
void run();
private:
mln::qt::ImageViewer* m_viewer;
QGraphicsScene* m_scene;
QGraphicsPixmapItem* m_pixmap;
QPixmap m_ima;
bool m_active;
QColor m_color;
int m_radius;
};
#endif //!BRUSH_HPP
#include <QApplication>
#include <mln/qt/imageviewer.hpp>
#include <mln/core/image/image2d.hpp>
#include <mln/io/imread.hpp>
#include <QtGui>
#include "brush.hpp"
int main(int argc, char** argv)
{
using namespace mln;
QApplication a(argc, argv);
image2d<rgb8> ima;
io::imread(argv[1], ima);
QMainWindow win;
qt::ImageViewer* viewer = new qt::ImageViewer(ima);
QGraphicsScene* scene = viewer->getScene();
MyBrush brush(viewer);
scene->installEventFilter(&brush);
QToolBar* toolbar = new QToolBar(&win);
QAction* action1 = toolbar->addAction("M1");
QAction* action2 = toolbar->addAction("M2");
QAction* action3 = toolbar->addAction("Rum");
QObject::connect(action1, SIGNAL(triggered()),
&brush, SLOT(setColor1()));
QObject::connect(action2, SIGNAL(triggered()),
&brush, SLOT(setColor2()));
QObject::connect(action3, SIGNAL(triggered()),
&brush, SLOT(run()));
QActionGroup agroup(&win);
agroup.addAction(action1);
agroup.addAction(action2);
action1->setCheckable(true);
action2->setCheckable(true);
win.setCentralWidget(viewer);
win.addToolBar(toolbar);
win.show();
// 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