Commit 27d50543 authored by Pierre Kraemer's avatar Pierre Kraemer

SCHNApps: la ca commence a etre pas mal..

parent 05d5b401
cmake_minimum_required(VERSION 2.8) cmake_minimum_required(VERSION 2.8)
ADD_SUBDIRECTORY(import) ADD_SUBDIRECTORY(import)
ADD_SUBDIRECTORY(demo) ADD_SUBDIRECTORY(render)
#include "demo.h"
#include "mapHandler.h"
#include "Algo/Import/import.h"
bool DemoPlugin::enable()
{
addTabInDock(new DemoDockTab(), "demoTab");
m_flatShader = new CGoGN::Utils::ShaderFlat() ;
m_flatShader->setAmbiant(CGoGN::Geom::Vec4f(0.2f, 0.2f, 0.2f, 0.1f)) ;
m_flatShader->setDiffuse(CGoGN::Geom::Vec4f(0.8f, 0.9f, 0.7f, 1.0f)) ;
m_flatShader->setExplode(1.0f) ;
CGoGN::Utils::GLSLShader::registerShader(NULL, m_flatShader) ;
return true;
}
void DemoPlugin::disable()
{
delete m_flatShader;
}
void DemoPlugin::redraw(View* view)
{
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL) ;
glEnable(GL_LIGHTING) ;
QList<MapHandlerGen*> maps = view->getLinkedMaps();
foreach(MapHandlerGen* m, maps)
{
CGoGN::Utils::VBO* positionVBO = m->getVBO("position");
m_flatShader->setAttributePosition(positionVBO);
m->draw(m_flatShader, CGoGN::Algo::Render::GL2::TRIANGLES) ;
}
}
/**
* If we want to compile this plugin in debug mode,
* we also define a DEBUG macro at the compilation
*/
#ifndef DEBUG
// essential Qt function:
// arguments are
// - the compiled name of the plugin
// - the main class of our plugin
Q_EXPORT_PLUGIN2(DemoPlugin, DemoPlugin)
#else
Q_EXPORT_PLUGIN2(DemoPluginD, DemoPlugin)
#endif
#include "import.h" #include "import.h"
#include <QFileDialog>
#include <QFileInfo>
#include "system.h"
#include "mapHandler.h" #include "mapHandler.h"
#include "Algo/Import/import.h" #include "Algo/Import/import.h"
bool ImportPlugin::enable() bool ImportPlugin::enable()
...@@ -17,11 +21,14 @@ void ImportPlugin::disable() ...@@ -17,11 +21,14 @@ void ImportPlugin::disable()
void ImportPlugin::cb_import() void ImportPlugin::cb_import()
{ {
QString fileName = QFileDialog::getOpenFileName(m_window, "Import file", m_window->getAppPath(), "Mesh Files (*.ply *.off)");
QFileInfo fi(fileName);
MAP* m = new MAP(); MAP* m = new MAP();
MapHandler<PFP>* h = new MapHandler<PFP>("duck", m_window, m); MapHandler<PFP>* h = new MapHandler<PFP>(fi.baseName(), m_window, m);
std::vector<std::string> attrNames ; std::vector<std::string> attrNames ;
CGoGN::Algo::Import::importMesh<PFP>(*m, "/home/kraemer/Media/Data/surface/lowRes/duck_163.ply", attrNames); CGoGN::Algo::Import::importMesh<PFP>(*m, fileName.toUtf8().constData(), attrNames);
CGoGN::VertexAttribute<PFP::VEC3> position = m->getAttribute<PFP::VEC3, CGoGN::VERTEX>(attrNames[0]); CGoGN::VertexAttribute<PFP::VEC3> position = m->getAttribute<PFP::VEC3, CGoGN::VERTEX>(attrNames[0]);
...@@ -36,10 +43,10 @@ void ImportPlugin::cb_import() ...@@ -36,10 +43,10 @@ void ImportPlugin::cb_import()
h->updatePrimitives(CGoGN::Algo::Render::GL2::LINES, CGoGN::allDarts) ; h->updatePrimitives(CGoGN::Algo::Render::GL2::LINES, CGoGN::allDarts) ;
h->updatePrimitives(CGoGN::Algo::Render::GL2::TRIANGLES, CGoGN::allDarts) ; h->updatePrimitives(CGoGN::Algo::Render::GL2::TRIANGLES, CGoGN::allDarts) ;
m_window->addMap(h);
CGoGN::Utils::VBO* positionVBO = h->getVBO(position.name()); CGoGN::Utils::VBO* positionVBO = h->getVBO(position.name());
positionVBO->updateData(position); positionVBO->updateData(position);
m_window->addMap(h);
} }
/** /**
......
...@@ -18,23 +18,8 @@ typedef PFP::MAP MAP; ...@@ -18,23 +18,8 @@ typedef PFP::MAP MAP;
typedef PFP::VEC3 VEC3; typedef PFP::VEC3 VEC3;
/**
* This class is a basic minimal plugin.
* All the methods in this class are overloaded methods.
* In order to create a valid plugin, all the method in this
* needs to be declared (they are actually overloaded methods
* from VisualPlugin), even if your plugin doesn't make any
* drawing.
*/
/**
* Our plugin must inherit from Plugin
*/
class ImportPlugin : public Plugin class ImportPlugin : public Plugin
{ {
/**
* Essential Qt macros.
*/
Q_OBJECT Q_OBJECT
Q_INTERFACES(Plugin) Q_INTERFACES(Plugin)
...@@ -47,22 +32,8 @@ public: ...@@ -47,22 +32,8 @@ public:
~ImportPlugin() ~ImportPlugin()
{} {}
/** virtual bool enable();
* The plugin's enable method virtual void disable();
* Each time the main application loads this plugin,
* it call this method. Writing this method is
* the occasion to initialize the plugin and check certain
* conditions.
* If this methods return 'false', the plugin load will be aborted.
*/
bool enable();
/**
* The plugin's disable method
* Each time the main application will unload the plugin
* it will call this method.
*/
void disable();
virtual void redraw(View *view) {} virtual void redraw(View *view) {}
...@@ -70,12 +41,12 @@ public: ...@@ -70,12 +41,12 @@ public:
virtual void keyRelease(View* view, int key) {} virtual void keyRelease(View* view, int key) {}
virtual void mousePress(View* view, int button, int x, int y) {} virtual void mousePress(View* view, int button, int x, int y) {}
virtual void mouseRelease(View* view, int button, int x, int y) {} virtual void mouseRelease(View* view, int button, int x, int y) {}
// virtual void mouseClick(View* view, int button, int x, int y) {}
virtual void mouseMove(View* view, int buttons, int x, int y) {} virtual void mouseMove(View* view, int buttons, int x, int y) {}
virtual void wheelEvent(View* view, int delta, int x, int y) {} virtual void wheelEvent(View* view, int delta, int x, int y) {}
virtual void viewLinked(View* view) {} virtual void viewLinked(View* view) {}
virtual void viewUnlinked(View* view) {} virtual void viewUnlinked(View* view) {}
virtual void currentViewChanged(View* view) {}
public slots: public slots:
void cb_import(); void cb_import();
...@@ -84,4 +55,4 @@ private: ...@@ -84,4 +55,4 @@ private:
QAction* importAction; QAction* importAction;
}; };
#endif // _FIRSTPLUGIN_H_ #endif
...@@ -2,20 +2,20 @@ cmake_minimum_required(VERSION 2.8) ...@@ -2,20 +2,20 @@ cmake_minimum_required(VERSION 2.8)
INCLUDE_DIRECTORIES( INCLUDE_DIRECTORIES(
${SCHNApps_ROOT_DIR}/include ${SCHNApps_ROOT_DIR}/include
${SCHNApps_ROOT_DIR}/Plugins/demo ${SCHNApps_ROOT_DIR}/Plugins/render
${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_BINARY_DIR}
) )
SET( PLUGIN_SRC SET( PLUGIN_SRC
${SCHNApps_ROOT_DIR}/Plugins/demo/demo.cpp ${SCHNApps_ROOT_DIR}/Plugins/render/render.cpp
) )
SET( PLUGIN_H SET( PLUGIN_H
${SCHNApps_ROOT_DIR}/Plugins/demo/demo.h ${SCHNApps_ROOT_DIR}/Plugins/render/render.h
) )
SET( PLUGIN_FORM SET( PLUGIN_FORM
${SCHNApps_ROOT_DIR}/Plugins/demo/demo.ui ${SCHNApps_ROOT_DIR}/Plugins/render/render.ui
) )
IF( ${CMAKE_BUILD_TYPE} STREQUAL Debug ) IF( ${CMAKE_BUILD_TYPE} STREQUAL Debug )
...@@ -31,21 +31,21 @@ IF( ${CMAKE_BUILD_TYPE} STREQUAL Debug ) ...@@ -31,21 +31,21 @@ IF( ${CMAKE_BUILD_TYPE} STREQUAL Debug )
QT4_WRAP_UI( PLUGIN_UI ${PLUGIN_FORM} ) QT4_WRAP_UI( PLUGIN_UI ${PLUGIN_FORM} )
QT4_WRAP_CPP( PLUGIN_MOC ${PLUGIN_H} ) QT4_WRAP_CPP( PLUGIN_MOC ${PLUGIN_H} )
ADD_LIBRARY( DemoPluginD SHARED ADD_LIBRARY( RenderPluginD SHARED
${PLUGIN_SRC} ${PLUGIN_SRC}
${PLUGIN_UI} ${PLUGIN_UI}
${PLUGIN_MOC} ${PLUGIN_MOC}
) )
TARGET_LINK_LIBRARIES( DemoPluginD TARGET_LINK_LIBRARIES( RenderPluginD
${CGoGN_LIBS_D} ${CGoGN_LIBS_D}
${COMMON_LIBS} ${COMMON_LIBS}
${QGLVIEWER_LIBRARIES} ${QGLVIEWER_LIBRARIES}
) )
ADD_DEPENDENCIES( DemoPluginD SCHNAppsD ) ADD_DEPENDENCIES( RenderPluginD SCHNAppsD )
SET_TARGET_PROPERTIES( DemoPluginD PROPERTIES COMPILE_DEFINITIONS "DEBUG" ) SET_TARGET_PROPERTIES( RenderPluginD PROPERTIES COMPILE_DEFINITIONS "DEBUG" )
ELSE ( ${CMAKE_BUILD_TYPE} STREQUAL Debug ) ELSE ( ${CMAKE_BUILD_TYPE} STREQUAL Debug )
...@@ -58,18 +58,18 @@ ELSE ( ${CMAKE_BUILD_TYPE} STREQUAL Debug ) ...@@ -58,18 +58,18 @@ ELSE ( ${CMAKE_BUILD_TYPE} STREQUAL Debug )
QT4_WRAP_UI( PLUGIN_UI ${PLUGIN_FORM} ) QT4_WRAP_UI( PLUGIN_UI ${PLUGIN_FORM} )
QT4_WRAP_CPP( PLUGIN_MOC ${PLUGIN_H} ) QT4_WRAP_CPP( PLUGIN_MOC ${PLUGIN_H} )
ADD_LIBRARY( DemoPlugin SHARED ADD_LIBRARY( RenderPlugin SHARED
${PLUGIN_SRC} ${PLUGIN_SRC}
${PLUGIN_UI} ${PLUGIN_UI}
${PLUGIN_MOC} ${PLUGIN_MOC}
) )
TARGET_LINK_LIBRARIES( DemoPlugin TARGET_LINK_LIBRARIES( RenderPlugin
${CGoGN_LIBS_R} ${CGoGN_LIBS_R}
${COMMON_LIBS} ${COMMON_LIBS}
${QGLVIEWER_LIBRARIES} ${QGLVIEWER_LIBRARIES}
) )
ADD_DEPENDENCIES( DemoPlugin SCHNApps ) ADD_DEPENDENCIES( RenderPlugin SCHNApps )
ENDIF ( ${CMAKE_BUILD_TYPE} STREQUAL Debug ) ENDIF ( ${CMAKE_BUILD_TYPE} STREQUAL Debug )
#include "render.h"
#include "mapHandler.h"
#include "Algo/Import/import.h"
bool RenderPlugin::enable()
{
m_dockTab = new RenderDockTab();
addTabInDock(m_dockTab, "Render");
m_flatShader = new CGoGN::Utils::ShaderFlat();
m_flatShader->setAmbiant(CGoGN::Geom::Vec4f(0.2f, 0.2f, 0.2f, 0.1f));
m_flatShader->setDiffuse(CGoGN::Geom::Vec4f(0.8f, 0.9f, 0.7f, 1.0f));
m_flatShader->setExplode(1.0f);
m_simpleColorShader = new CGoGN::Utils::ShaderSimpleColor();
CGoGN::Geom::Vec4f c(0.1f, 0.1f, 0.1f, 1.0f);
m_simpleColorShader->setColor(c);
m_pointSprite = new CGoGN::Utils::PointSprite();
connect(m_dockTab->check_renderVertices, SIGNAL(toggled(bool)), this, SLOT(cb_renderVerticesChanged(bool)));
connect(m_dockTab->slider_verticesScaleFactor, SIGNAL(valueChanged(int)), this, SLOT(cb_verticesScaleFactorChanged(int)));
connect(m_dockTab->check_renderEdges, SIGNAL(toggled(bool)), this, SLOT(cb_renderEdgesChanged(bool)));
connect(m_dockTab->check_renderFaces, SIGNAL(toggled(bool)), this, SLOT(cb_renderFacesChanged(bool)));
return true;
}
void RenderPlugin::disable()
{
delete m_flatShader;
delete m_simpleColorShader;
delete m_pointSprite;
}
void RenderPlugin::redraw(View* view)
{
TabParams* params = h_viewParams[view];
const QList<MapHandlerGen*>& maps = view->getLinkedMaps();
foreach(MapHandlerGen* m, maps)
{
CGoGN::Utils::VBO* positionVBO = m->getVBO("position");
if(params->renderVertices)
{
m_pointSprite->setSize(m->getBBdiagSize() / 100.0f * params->verticesScaleFactor);
m_pointSprite->setAttributePosition(positionVBO);
m_pointSprite->predraw(CGoGN::Geom::Vec3f(0.0f, 0.0f, 1.0f));
m->draw(m_pointSprite, CGoGN::Algo::Render::GL2::POINTS);
m_pointSprite->postdraw();
}
if(params->renderEdges)
{
glLineWidth(1.0f);
m_simpleColorShader->setAttributePosition(positionVBO);
m->draw(m_simpleColorShader, CGoGN::Algo::Render::GL2::LINES);
}
if(params->renderFaces)
{
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
glEnable(GL_LIGHTING);
glEnable(GL_POLYGON_OFFSET_FILL);
glPolygonOffset(1.0f, 1.0f);
m_flatShader->setAttributePosition(positionVBO);
m->draw(m_flatShader, CGoGN::Algo::Render::GL2::TRIANGLES);
glDisable(GL_POLYGON_OFFSET_FILL);
}
}
}
void RenderPlugin::viewLinked(View* view)
{
assert(!h_viewParams.contains(view));
h_viewParams.insert(view, new TabParams(1.0, false, false, true));
CGoGN::Utils::GLSLShader::registerShader(view, m_flatShader);
CGoGN::Utils::GLSLShader::registerShader(view, m_simpleColorShader);
CGoGN::Utils::GLSLShader::registerShader(view, m_pointSprite);
}
void RenderPlugin::viewUnlinked(View* view)
{
assert(h_viewParams.contains(view));
h_viewParams.remove(view);
CGoGN::Utils::GLSLShader::unregisterShader(view, m_flatShader);
CGoGN::Utils::GLSLShader::unregisterShader(view, m_simpleColorShader);
CGoGN::Utils::GLSLShader::unregisterShader(view, m_pointSprite);
}
void RenderPlugin::currentViewChanged(View* view)
{
TabParams* params = h_viewParams[view];
m_dockTab->check_renderVertices->setChecked(params->renderVertices);
m_dockTab->slider_verticesScaleFactor->setSliderPosition(params->verticesScaleFactor * 50.0);
m_dockTab->check_renderEdges->setChecked(params->renderEdges);
m_dockTab->check_renderFaces->setChecked(params->renderFaces);
}
void RenderPlugin::cb_renderVerticesChanged(bool b)
{
View* current = m_window->getCurrentView();
assert(isLinkedToView(current));
TabParams* params = h_viewParams[current];
params->renderVertices = b;
current->updateGL();
}
void RenderPlugin::cb_verticesScaleFactorChanged(int i)
{
View* current = m_window->getCurrentView();
assert(isLinkedToView(current));
TabParams* params = h_viewParams[current];
params->verticesScaleFactor = i / 50.0;
current->updateGL();
}
void RenderPlugin::cb_renderEdgesChanged(bool b)
{
View* current = m_window->getCurrentView();
assert(isLinkedToView(current));
TabParams* params = h_viewParams[current];
params->renderEdges = b;
current->updateGL();
}
void RenderPlugin::cb_renderFacesChanged(bool b)
{
View* current = m_window->getCurrentView();
assert(isLinkedToView(current));
TabParams* params = h_viewParams[current];
params->renderFaces = b;
current->updateGL();
}
/**
* If we want to compile this plugin in debug mode,
* we also define a DEBUG macro at the compilation
*/
#ifndef DEBUG
// essential Qt function:
// arguments are
// - the compiled name of the plugin
// - the main class of our plugin
Q_EXPORT_PLUGIN2(RenderPlugin, RenderPlugin)
#else
Q_EXPORT_PLUGIN2(RenderPluginD, RenderPlugin)
#endif
#ifndef _DEMO_PLUGIN_H_ #ifndef _RENDER_PLUGIN_H_
#define _DEMO_PLUGIN_H_ #define _RENDER_PLUGIN_H_
#include "plugin.h" #include "plugin.h"
#include "ui_demo.h" #include "ui_render.h"
#include "Topology/generic/functor.h" #include "Topology/generic/functor.h"
#include "Topology/generic/parameters.h" #include "Topology/generic/parameters.h"
#include "Topology/map/embeddedMap2.h" #include "Topology/map/embeddedMap2.h"
#include "Utils/Shaders/shaderFlat.h" #include "Utils/Shaders/shaderFlat.h"
#include "Utils/Shaders/shaderSimpleColor.h"
#include "Utils/pointSprite.h"
struct PFP: public CGoGN::PFP_STANDARD class RenderDockTab : public QWidget, public Ui::RenderWidget
{
// definition of the map
typedef CGoGN::EmbeddedMap2 MAP;
};
typedef PFP::MAP MAP;
typedef PFP::VEC3 VEC3;
class DemoDockTab : public QWidget, public Ui::DemoWidget
{ {
public: public:
DemoDockTab() { setupUi(this); } RenderDockTab() { setupUi(this); }
}; };
struct TabParams struct TabParams
{ {
bool b_showVertices; TabParams(float vsf, bool rv, bool re, bool rf) :
bool b_showEdges; verticesScaleFactor(vsf),
}; renderVertices(rv),
renderEdges(re),
renderFaces(rf)
{}
float verticesScaleFactor;
bool renderVertices;
bool renderEdges;
bool renderFaces;
};
/**
* This class is a basic minimal plugin.
* All the methods in this class are overloaded methods.
* In order to create a valid plugin, all the method in this
* needs to be declared (they are actually overloaded methods
* from VisualPlugin), even if your plugin doesn't make any
* drawing.
*/
/** class RenderPlugin : public Plugin
* Our plugin must inherit from Plugin
*/
class DemoPlugin : public Plugin
{ {
/**
* Essential Qt macros.
*/
Q_OBJECT Q_OBJECT
Q_INTERFACES(Plugin) Q_INTERFACES(Plugin)
public: public:
DemoPlugin() RenderPlugin()
{ {
setProvidesRendering(true); setProvidesRendering(true);
} }
~DemoPlugin() ~RenderPlugin()
{} {}
/** virtual bool enable();
* The plugin's enable method virtual void disable();
* Each time the main application loads this plugin,
* it call this method. Writing this method is
* the occasion to initialize the plugin and check certain
* conditions.
* If this methods return 'false', the plugin load will be aborted.
*/
bool enable();
/**
* The plugin's disable method
* Each time the main application will unload the plugin
* it will call this method.
*/
void disable();
virtual void redraw(View *view); virtual void redraw(View *view);
...@@ -87,15 +59,26 @@ public: ...@@ -87,15 +59,26 @@ public:
virtual void keyRelease(View* view, int key) {} virtual void keyRelease(View* view, int key) {}
virtual void mousePress(View* view, int button, int x, int y) {} virtual void mousePress(View* view, int button, int x, int y) {}
virtual void mouseRelease(View* view, int button, int x, int y) {} virtual void mouseRelease(View* view, int button, int x, int y) {}
// virtual void mouseClick(View* view, int button, int x, int y) {}
virtual void mouseMove(View* view, int buttons, int x, int y) {} virtual void mouseMove(View* view, int buttons, int x, int y) {}
virtual void wheelEvent(View* view, int delta, int x, int y) {} virtual void wheelEvent(View* view, int delta, int x, int y) {}
virtual void viewLinked(View* view) {} virtual void viewLinked(View* view);
virtual void viewUnlinked(View* view) {} virtual void viewUnlinked(View* view);
virtual void currentViewChanged(View* view);
protected: protected:
CGoGN::Utils::ShaderFlat* m_flatShader ; RenderDockTab* m_dockTab;
QHash<View*, TabParams*> h_viewParams;
CGoGN::Utils::ShaderFlat* m_flatShader;
CGoGN::Utils::ShaderSimpleColor* m_simpleColorShader ;
CGoGN::Utils::PointSprite* m_pointSprite ;
public slots:
void cb_renderVerticesChanged(bool b);
void cb_verticesScaleFactorChanged(int i);
void cb_renderEdgesChanged(bool b);
void cb_renderFacesChanged(bool b);
}; };