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)
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 <QFileDialog>
#include <QFileInfo>
#include "system.h"
#include "mapHandler.h"
#include "Algo/Import/import.h"
bool ImportPlugin::enable()
......@@ -17,11 +21,14 @@ void ImportPlugin::disable()
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();
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 ;
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]);
......@@ -36,10 +43,10 @@ void ImportPlugin::cb_import()
h->updatePrimitives(CGoGN::Algo::Render::GL2::LINES, CGoGN::allDarts) ;
h->updatePrimitives(CGoGN::Algo::Render::GL2::TRIANGLES, CGoGN::allDarts) ;
m_window->addMap(h);
CGoGN::Utils::VBO* positionVBO = h->getVBO(position.name());
positionVBO->updateData(position);
m_window->addMap(h);
}
/**
......
......@@ -18,23 +18,8 @@ typedef PFP::MAP MAP;
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
{
/**
* Essential Qt macros.
*/
Q_OBJECT
Q_INTERFACES(Plugin)
......@@ -47,22 +32,8 @@ public:
~ImportPlugin()
{}
/**
* The plugin's enable method
* 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 bool enable();
virtual void disable();
virtual void redraw(View *view) {}
......@@ -70,12 +41,12 @@ public:
virtual void keyRelease(View* view, int key) {}
virtual void mousePress(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 wheelEvent(View* view, int delta, int x, int y) {}
virtual void viewLinked(View* view) {}
virtual void viewUnlinked(View* view) {}
virtual void currentViewChanged(View* view) {}
public slots:
void cb_import();
......@@ -84,4 +55,4 @@ private:
QAction* importAction;
};
#endif // _FIRSTPLUGIN_H_
#endif
......@@ -2,20 +2,20 @@ cmake_minimum_required(VERSION 2.8)
INCLUDE_DIRECTORIES(
${SCHNApps_ROOT_DIR}/include
${SCHNApps_ROOT_DIR}/Plugins/demo
${SCHNApps_ROOT_DIR}/Plugins/render
${CMAKE_CURRENT_BINARY_DIR}
)
SET( PLUGIN_SRC
${SCHNApps_ROOT_DIR}/Plugins/demo/demo.cpp
${SCHNApps_ROOT_DIR}/Plugins/render/render.cpp
)
SET( PLUGIN_H
${SCHNApps_ROOT_DIR}/Plugins/demo/demo.h
${SCHNApps_ROOT_DIR}/Plugins/render/render.h
)
SET( PLUGIN_FORM
${SCHNApps_ROOT_DIR}/Plugins/demo/demo.ui
${SCHNApps_ROOT_DIR}/Plugins/render/render.ui
)
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_CPP( PLUGIN_MOC ${PLUGIN_H} )
ADD_LIBRARY( DemoPluginD SHARED
ADD_LIBRARY( RenderPluginD SHARED
${PLUGIN_SRC}
${PLUGIN_UI}
${PLUGIN_MOC}
)
TARGET_LINK_LIBRARIES( DemoPluginD
TARGET_LINK_LIBRARIES( RenderPluginD
${CGoGN_LIBS_D}
${COMMON_LIBS}
${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 )
......@@ -58,18 +58,18 @@ ELSE ( ${CMAKE_BUILD_TYPE} STREQUAL Debug )
QT4_WRAP_UI( PLUGIN_UI ${PLUGIN_FORM} )
QT4_WRAP_CPP( PLUGIN_MOC ${PLUGIN_H} )
ADD_LIBRARY( DemoPlugin SHARED
ADD_LIBRARY( RenderPlugin SHARED
${PLUGIN_SRC}
${PLUGIN_UI}
${PLUGIN_MOC}
)
TARGET_LINK_LIBRARIES( DemoPlugin
TARGET_LINK_LIBRARIES( RenderPlugin
${CGoGN_LIBS_R}
${COMMON_LIBS}
${QGLVIEWER_LIBRARIES}
)
ADD_DEPENDENCIES( DemoPlugin SCHNApps )
ADD_DEPENDENCIES( RenderPlugin SCHNApps )
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_
#define _DEMO_PLUGIN_H_
#ifndef _RENDER_PLUGIN_H_
#define _RENDER_PLUGIN_H_
#include "plugin.h"
#include "ui_demo.h"
#include "ui_render.h"
#include "Topology/generic/functor.h"
#include "Topology/generic/parameters.h"
#include "Topology/map/embeddedMap2.h"
#include "Utils/Shaders/shaderFlat.h"
#include "Utils/Shaders/shaderSimpleColor.h"
#include "Utils/pointSprite.h"
struct PFP: public CGoGN::PFP_STANDARD
{
// definition of the map
typedef CGoGN::EmbeddedMap2 MAP;
};
typedef PFP::MAP MAP;
typedef PFP::VEC3 VEC3;
class DemoDockTab : public QWidget, public Ui::DemoWidget
class RenderDockTab : public QWidget, public Ui::RenderWidget
{
public:
DemoDockTab() { setupUi(this); }
RenderDockTab() { setupUi(this); }
};
struct TabParams
{
bool b_showVertices;
bool b_showEdges;
};
TabParams(float vsf, bool rv, bool re, bool rf) :
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.
*/
/**
* Our plugin must inherit from Plugin
*/
class DemoPlugin : public Plugin
class RenderPlugin : public Plugin
{
/**
* Essential Qt macros.
*/
Q_OBJECT
Q_INTERFACES(Plugin)
public:
DemoPlugin()
RenderPlugin()
{
setProvidesRendering(true);
}
~DemoPlugin()
~RenderPlugin()
{}
/**
* The plugin's enable method
* 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 bool enable();
virtual void disable();
virtual void redraw(View *view);
......@@ -87,15 +59,26 @@ public:
virtual void keyRelease(View* view, int key) {}
virtual void mousePress(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 wheelEvent(View* view, int delta, int x, int y) {}
virtual void viewLinked(View* view) {}
virtual void viewUnlinked(View* view) {}
virtual void viewLinked(View* view);
virtual void viewUnlinked(View* view);
virtual void currentViewChanged(View* view);
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);
};
#endif // _FIRSTPLUGIN_H_
#endif
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>DemoWidget</class>
<widget class="QWidget" name="DemoWidget">
<class>RenderWidget</class>
<widget class="QWidget" name="RenderWidget">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>177</width>
<height>211</height>
<height>293</height>
</rect>
</property>
<property name="windowTitle">
......@@ -21,6 +21,16 @@
</property>
</widget>
</item>
<item>
<widget class="QSlider" name="slider_verticesScaleFactor">
<property name="value">
<number>50</number>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="check_renderEdges">
<property name="text">
......@@ -28,6 +38,16 @@
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="check_renderFaces">
<property name="text">
<string>render faces</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
......@@ -36,7 +56,7 @@
<property name="sizeHint" stdset="0">
<size>
<width>156</width>
<height>136</height>
<height>161</height>
</size>
</property>
</spacer>
......
......@@ -56,9 +56,9 @@
<attribute name="toolBarBreak">
<bool>false</bool>
</attribute>
<addaction name="actionManageViews"/>
<addaction name="actionManageCameras"/>
<addaction name="actionManagePlugins"/>
<addaction name="actionManageMaps"/>
</widget>
<action name="actionAboutCGoGN">
<property name="text">
......@@ -84,15 +84,6 @@
<string>Manage plugins</string>
</property>
</action>
<action name="actionManageViews">
<property name="icon">
<iconset resource="../resources/resources.qrc">
<normaloff>:/icons/icons/add_view.png</normaloff>:/icons/icons/add_view.png</iconset>
</property>
<property name="text">
<string>Add view</string>
</property>
</action>
<action name="actionManageCameras">
<property name="icon">
<iconset resource="../resources/resources.qrc">
......@@ -107,6 +98,18 @@
<string>Show/Hide Dock</string>
</property>
</action>
<action name="actionManageMaps">
<property name="icon">
<iconset resource="../resources/resources.qrc">
<normaloff>:/icons/icons/map_plugin.png</normaloff>:/icons/icons/map_plugin.png</iconset>
</property>
<property name="text">
<string>ManageMaps</string>
</property>
<property name="toolTip">
<string>Manage maps</string>
</property>
</action>
</widget>
<resources>
<include location="../resources/resources.qrc"/>
......
......@@ -14,14 +14,14 @@ public:
Camera(const QString& name, Window* window);
~Camera();
const QString& getName() { return m_name; }
const QString& getName() const { return m_name; }
void setName(const QString& name) { m_name = name; }
Window* getWindow() { return m_window; }
Window* getWindow() const { return m_window; }
void setWindow(Window* w) { m_window = w; }
bool isUsed() { return l_views.size() > 0; }
bool isShared() { return l_views.size() > 1; }
bool isUsed() const { return l_views.size() > 0; }
bool isShared() const { return l_views.size() > 1; }
/*********************************************************
* CAMERA DRAWING
......@@ -29,22 +29,22 @@ public:
void draw();
bool getDraw() { return m_draw; }
bool getDraw() const { return m_draw; }
void setDraw(bool b = true) { m_draw = b; }
bool getDrawFarPlane() { return m_drawFarPlane; }
void setDrawFarPlane(bool b = true) { m_drawFarPlane = b; }
bool getDrawFarPlane() const { return m_drawFarPlane; }
void setDrawFarPlane(bool b) { m_drawFarPlane = b; }
double getDrawScale() { return m_drawScale; }
double getDrawScale() const { return m_drawScale; }
void setDrawScale(double s) { m_drawScale = s; }
bool getDrawPath() { return m_drawPath; }
void setDrawPath(bool b = true) { m_drawPath = b; }
bool getDrawPath() const { return m_drawPath; }
void setDrawPath(bool b) { m_drawPath = b; }
bool getDrawPathAxis() { return m_drawPathAxis; }
void setDrawPathAxis(bool b = true) { m_drawPathAxis = b