Commit 7a0cad68 authored by Pierre Kraemer's avatar Pierre Kraemer

SCHNApps : premiers plugins import et rendu !

parent 81df0944
......@@ -39,9 +39,6 @@ file(
)
SET(SCHNApps_H_OBJECT_FILES
${SCHNApps_ROOT_DIR}/include/camera.h
${SCHNApps_ROOT_DIR}/include/mapHandler.h
${SCHNApps_ROOT_DIR}/include/plugin.h
${SCHNApps_ROOT_DIR}/include/splitArea.h
${SCHNApps_ROOT_DIR}/include/view.h
${SCHNApps_ROOT_DIR}/include/window.h
......
cmake_minimum_required(VERSION 2.8)
ADD_SUBDIRECTORY(firstPlugin)
ADD_SUBDIRECTORY(import)
ADD_SUBDIRECTORY(demo)
cmake_minimum_required(VERSION 2.8)
INCLUDE_DIRECTORIES(
${SCHNApps_ROOT_DIR}/include
${SCHNApps_ROOT_DIR}/Plugins/firstPlugin/include
${CMAKE_CURRENT_BINARY_DIR}
)
SET( FIRSTPLUGIN_PLUGIN_SRC
${SCHNApps_ROOT_DIR}/Plugins/firstPlugin/src/firstPlugin.cpp
)
SET( FIRSTPLUGIN_PLUGIN_H
${SCHNApps_ROOT_DIR}/Plugins/firstPlugin/include/firstPlugin.h
)
IF( ${CMAKE_BUILD_TYPE} STREQUAL Debug )
ADD_DEFINITIONS(-DDEBUG)
IF(WIN32)
link_directories( ${CGoGN_ROOT_DIR}/lib/Release )
ELSE (WIN32)
link_directories( ${CGoGN_ROOT_DIR}/lib/Debug ${CGoGN_ROOT_DIR}/lib/Release )
ENDIF (WIN32)
QT4_WRAP_CPP( FIRSTPLUGIN_MOC ${FIRSTPLUGIN_PLUGIN_H} )
ADD_LIBRARY( FirstPluginD SHARED
${FIRSTPLUGIN_PLUGIN_SRC}
${FIRSTPLUGIN_MOC}
)
TARGET_LINK_LIBRARIES( FirstPluginD
${CGoGN_LIBS_D}
${COMMON_LIBS}
${QGLVIEWER_LIBRARIES}
)
ADD_DEPENDENCIES( FirstPluginD SCHNAppsD )
SET_TARGET_PROPERTIES( FirstPluginD PROPERTIES COMPILE_DEFINITIONS "DEBUG" )
ELSE ( ${CMAKE_BUILD_TYPE} STREQUAL Debug )
IF(WIN32)
link_directories( ${CGoGN_ROOT_DIR}/lib/Release )
ELSE (WIN32)
link_directories( ${CGoGN_ROOT_DIR}/lib/Release )
ENDIF (WIN32)
QT4_WRAP_CPP( FIRSTPLUGIN_MOC ${FIRSTPLUGIN_PLUGIN_H} )
ADD_LIBRARY( FirstPlugin SHARED
${FIRSTPLUGIN_PLUGIN_SRC}
${FIRSTPLUGIN_MOC}
)
TARGET_LINK_LIBRARIES( FirstPlugin
${CGoGN_LIBS_R}
${COMMON_LIBS}
${QGLVIEWER_LIBRARIES}
)
ADD_DEPENDENCIES( FirstPlugin SCHNApps )
ENDIF ( ${CMAKE_BUILD_TYPE} STREQUAL Debug )
#ifndef _FIRSTPLUGIN_H_
#define _FIRSTPLUGIN_H_
#include "plugin.h"
/**---CGoGN includes **/
#include "Topology/generic/parameters.h"
#include "Topology/map/embeddedMap2.h"
#include "Algo/Render/GL2/mapRender.h"
#include "Utils/Shaders/shaderFlat.h"
/**---CGoGN includes **/
/**---Definitions specific to CGoGN ---*/
using namespace CGoGN ;
/**
* Struct that contains some informations about the types of the manipulated objects
* Mainly here to be used by the algorithms that are parameterized by it
*/
struct PFP: public PFP_STANDARD
{
// definition of the map
typedef EmbeddedMap2 MAP;
};
typedef PFP::MAP MAP;
typedef PFP::VEC3 VEC3;
/**---Definitions specific to CGoGN ---*/
/**
* 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 FirstPlugin : public Plugin
{
/**
* Essential Qt macros.
*/
Q_OBJECT
Q_INTERFACES(Plugin)
public:
FirstPlugin()
{
setProvidesRendering(true);
}
~FirstPlugin()
{}
/**
* 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 void redraw(View *view);
virtual void keyPress(View* view, int key) {}
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 viewAdded(View* view);
virtual void viewRemoved(View* view) {}
protected:
MAP myMap;
VertexAttribute<VEC3> position;
Algo::Render::GL2::MapRender* m_render ;
Utils::VBO* m_positionVBO ;
Utils::ShaderFlat* m_flatShader ;
};
#endif // _FIRSTPLUGIN_H_
#include "firstPlugin.h"
#include "Algo/Geometry/boundingbox.h"
#include "Algo/Import/import.h"
bool FirstPlugin::enable()
{
m_render = new Algo::Render::GL2::MapRender() ;
m_positionVBO = new Utils::VBO() ;
m_flatShader = new Utils::ShaderFlat() ;
m_flatShader->setAttributePosition(m_positionVBO) ;
m_flatShader->setAmbiant(Geom::Vec4f(0.2f, 0.2f, 0.2f, 0.1f)) ;
m_flatShader->setDiffuse(Geom::Vec4f(0.8f, 0.9f, 0.7f, 1.0f)) ;
m_flatShader->setExplode(1.0f) ;
CGoGN::Utils::GLSLShader::registerShader(NULL, m_flatShader) ;
std::vector<std::string> attrNames ;
CGoGN::Algo::Import::importMesh<PFP>(myMap, "/home/kraemer/Media/Data/surface/lowRes/duck_163.ply", attrNames);
position = myMap.getAttribute<PFP::VEC3, VERTEX>(attrNames[0]) ;
m_render->initPrimitives<PFP>(myMap, allDarts, CGoGN::Algo::Render::GL2::POINTS) ;
m_render->initPrimitives<PFP>(myMap, allDarts, CGoGN::Algo::Render::GL2::LINES) ;
m_render->initPrimitives<PFP>(myMap, allDarts, CGoGN::Algo::Render::GL2::TRIANGLES) ;
m_positionVBO->updateData(position) ;
return true;
}
void FirstPlugin::disable()
{
}
void FirstPlugin::redraw(View* view)
{
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL) ;
glEnable(GL_LIGHTING) ;
m_render->draw(m_flatShader, Algo::Render::GL2::TRIANGLES) ;
}
void FirstPlugin::viewAdded(View* view)
{
CGoGN::Geom::BoundingBox<PFP::VEC3> bb = Algo::Geometry::computeBoundingBox<PFP>(myMap, position) ;
qglviewer::Vec min(bb.min()[0], bb.min()[1], bb.min()[2]);
qglviewer::Vec max(bb.max()[0], bb.max()[1], bb.max()[2]);
view->setSceneBoundingBox(min, max);
}
/**
* 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 complied name of the plugin
// - the main class of our plugin
Q_EXPORT_PLUGIN2(FirstPlugin, FirstPlugin)
#else
Q_EXPORT_PLUGIN2(FirstPluginD, FirstPlugin)
#endif
#ifndef _IMPORTMAP_H_
#define _IMPORTMAP_H_
#include "visualPlugin.h"
#include "Topology/generic/parameters.h"
#include "Topology/map/embeddedMap2.h"
#include "Geometry/vector_gen.h"
#include "Geometry/matrix.h"
#include "Algo/Import/import.h"
#include "Algo/Export/export.h"
#include "Algo/Render/GL2/mapRender.h"
#include "Algo/Render/GL2/topoRender.h"
#include "Utils/Shaders/shaderPhong.h"
#include "Utils/Shaders/shaderFlat.h"
#include "Utils/Shaders/shaderSimpleColor.h"
#include "Utils/Shaders/shaderVectorPerVertex.h"
#include "Utils/pointSprite.h"
#include "Utils/text3d.h"
#include "Utils/vboRender.h"
#include "Utils/Qt/qtInputs.h"
#include "Algo/Geometry/boundingbox.h"
#include "Algo/Geometry/normal.h"
using namespace CGoGN ;
struct PFP: public PFP_STANDARD
{
// definition of the map
typedef EmbeddedMap2 MAP ;
};
class ImportMap : public VisualPlugin{
Q_OBJECT
Q_INTERFACES(Plugin)
public:
ImportMap();
~ImportMap();
void cb_updateMatrix(View* view){}
void cb_redraw(Scene* scene){}
void cb_initGL(Scene* scene){}
bool activate();
void disable();
protected:
bool importMap(QString filename);
protected slots:
void saveMap();
};
#endif
#include "import.h"
#include <QMessageBox>
ImportMap::ImportMap(){}
ImportMap::~ImportMap(){}
bool ImportMap::activate(){
QAction* action= new QAction( m_window);
action->setIcon(QIcon(":icon/map.png"));
QObject::connect(action, SIGNAL(triggered()), this, SLOT(saveMap()));
addMenuAction("Visu;Imorter une Map", action);
addToolbarAction(action);
waitingForScene(0);
return true;
}
void ImportMap::disable(){}
bool ImportMap::importMap(QString filename){
QFileInfo fileInfo(filename);
QString extension= fileInfo.suffix();
PFP::MAP* myMap= new PFP::MAP();
VertexAttribute<PFP::VEC3> position;
VertexAttribute<PFP::VEC3> normal;
if (extension == "map")
{
myMap->loadMapBin(filename.toStdString());
position = myMap->getAttribute<PFP::VEC3, VERTEX>("position") ;
}
else
{
std::vector<std::string> attrNames ;
if(!Algo::Import::importMesh<PFP>(*myMap, filename.toStdString().c_str(), attrNames))
{
return false;
}
position = myMap->getAttribute<PFP::VEC3, VERTEX>(attrNames[0]) ;
std::cout << "import map position ok? " << ((myMap->getAttribute<PFP::VEC3, VERTEX>(attrNames[0]).isValid())?"yes":"no") << std::endl;
std::cout << "import map position ok? " << ((myMap->getAttribute<PFP::VEC3, VERTEX>("position").isValid())?"yes":"no") << std::endl;
}
normal = myMap->getAttribute<PFP::VEC3, VERTEX>("normal") ;
if(!normal.isValid())
normal = myMap->addAttribute<PFP::VEC3, VERTEX>("normal") ;
Algo::Geometry::computeNormalVertices<PFP>(*myMap, position, normal) ;
std::cout << "import map normal ok? " << ((myMap->getAttribute<PFP::VEC3, VERTEX>("normal").isValid())?"yes":"no") << std::endl;
MapHandler* vizuHandler= new MapHandler(myMap);
if(!addReferencedMap(fileInfo.baseName()+"_map", vizuHandler)){
System::Error::showError();
delete vizuHandler;
return false;
}
// myMap->check();
return true;
}
void ImportMap::saveMap(){
QString fileName= QFileDialog::getOpenFileName(m_window, System::app_path+"../files", tr("3D files (*)"));
if(!fileName.isEmpty()){
if(!importMap(fileName)){
QMessageBox msg;
msg.setText(QString::fromUtf8("Une erreur est survenue lors de la création de la carte"));
if(System::Error::code!=System::Error::SUCCESS){
System::Error::showError();
}
}
}
}
#ifndef DEBUG
Q_EXPORT_PLUGIN2(ImportMap, ImportMap)
#else
Q_EXPORT_PLUGIN2(ImportMapD, ImportMap)
#endif
#ifndef _SIMPLEVISU_H_
#define _SIMPLEVISU_H_
#include "visualPlugin.h"
#include "ui_simpleVisu.h"
#include <iostream>
#include "Topology/generic/parameters.h"
#include "Topology/map/embeddedMap2.h"
#include "Geometry/vector_gen.h"
#include "Geometry/matrix.h"
#include "Algo/Import/import.h"
#include "Algo/Export/export.h"
#include "Algo/Render/GL2/mapRender.h"
#include "Algo/Render/GL2/topoRender.h"
#include "Utils/Shaders/shaderPhong.h"
#include "Utils/Shaders/shaderFlat.h"
#include "Utils/Shaders/shaderSimpleColor.h"
#include "Utils/Shaders/shaderVectorPerVertex.h"
#include "Utils/pointSprite.h"
#include "Utils/text3d.h"
#include "Utils/vboRender.h"
#include "Utils/Qt/qtInputs.h"
#include "Algo/Geometry/boundingbox.h"
#include "Algo/Geometry/normal.h"
#include <QHash>
#include <QPair>
using namespace CGoGN ;
struct PFP: public PFP_STANDARD
{
// definition of the map
typedef EmbeddedMap2 MAP ;
};
typedef PFP::MAP MAP ;
typedef PFP::VEC3 VEC3 ;
struct MyContainer{
MAP* map;
QPair<VBOHandler*, VBOHandler*> vbos;
QPair<VertexAttribute<VEC3>, VertexAttribute<VEC3> > attributes;
Algo::Render::GL2::MapRender* render;
bool valid;
MyContainer(MAP* myMap, VBOHandler* vbo1, VBOHandler* vbo2, VertexAttribute<VEC3> a1, VertexAttribute<VEC3> a2, Algo::Render::GL2::MapRender* r) :
map(myMap), vbos(vbo1,vbo2), attributes(a1,a2), render(r),valid(true)
{}
};
class MyWidget : public QWidget, public Ui::Form{
Q_OBJECT
public:
MyWidget(QWidget* parent=0) : QWidget(parent) {this->setupUi(this);}
};
class SimpleVisu : public VisualPlugin{
Q_OBJECT
Q_INTERFACES(Plugin)
public:
SimpleVisu();
~SimpleVisu(){}
// void cb_updateMatrix(View* view);
void cb_redraw(Scene* scene);
void cb_initGL(Scene* scene);
bool activate();
void disable();
void cb_recievedMap(MapHandler* map);
void cb_removingMap(MapHandler* map);
void cb_removingScene(Scene* scene);
protected:
enum renderMode { FLAT, PHONG } ;
Geom::Vec4f colDif ;
Geom::Vec4f colSpec ;
Geom::Vec4f colClear ;
Geom::Vec4f colNormal ;
float shininess ;
Geom::BoundingBox<PFP::VEC3> bb ;
float normalBaseSize ;
float normalScaleFactor ;
float vertexBaseSize ;
float vertexScaleFactor ;
float faceShrinkage ;
int m_renderStyle ;
bool m_drawVertices ;
bool m_drawEdges ;
bool m_drawFaces ;
bool m_drawNormals ;
bool m_drawTopo ;
VertexAttribute<VEC3> m_position ;
VertexAttribute<VEC3> m_normal ;
// Algo::Render::GL2::MapRender* m_render ;
VBOHandler* m_positionVBO ;
VBOHandler* m_normalVBO ;
bool initOK;
Utils::ShaderPhong* m_phongShader ;
Utils::ShaderFlat* m_flatShader ;
Utils::ShaderVectorPerVertex* m_vectorShader ;
Utils::ShaderSimpleColor* m_simpleColorShader ;
Utils::PointSprite* m_pointSprite ;
MyWidget* m_widget;
QHash<Scene*, MyContainer> h_info;
QList<QPair<Scene*,MapHandler*> > l_waitingAssoc;
// void initVBOs(Scene* scene);
public slots:
void slot_drawVertices(bool b) ;
void slot_verticesSize(int i) ;
void slot_drawEdges(bool b) ;
void slot_drawFaces(bool b) ;
void slot_faceLighting(int i) ;
void slot_drawTopo(bool b) ;
void slot_drawNormals(bool b) ;
void slot_normalsSize(int i) ;
};
#endif
This diff is collapsed.
......@@ -39,9 +39,6 @@ file(
)
SET(SCHNApps_H_OBJECT_FILES
${SCHNApps_ROOT_DIR}/include/camera.h
${SCHNApps_ROOT_DIR}/include/mapHandler.h
${SCHNApps_ROOT_DIR}/include/plugin.h
${SCHNApps_ROOT_DIR}/include/splitArea.h
${SCHNApps_ROOT_DIR}/include/view.h
${SCHNApps_ROOT_DIR}/include/window.h
......
......@@ -31,6 +31,8 @@
<property name="title">
<string>File</string>
</property>
<addaction name="actionShow_Hide_Dock"/>
<addaction name="separator"/>
<addaction name="actionQuit"/>
</widget>
<widget class="QMenu" name="menuHelp">
......@@ -100,6 +102,11 @@
<string>Manage cameras</string>
</property>
</action>
<action name="actionShow_Hide_Dock">
<property name="text">
<string>Show/Hide Dock</string>
</property>
</action>
</widget>
<resources>
<include location="../resources/resources.qrc"/>
......
......@@ -8,8 +8,6 @@ class Window;
class Camera : public qglviewer::Camera
{
Q_OBJECT
public:
static unsigned int cameraCount;
......@@ -81,9 +79,6 @@ protected:
double m_drawPathScale;
int m_snapCount;
public slots:
void cb_viewRemoved(View* view);
};
#endif
......@@ -2,26 +2,21 @@
#define _MAPHANDLER_H_
#include <QString>
#include "types.h"
#include "types.h"
#include "view.h"
namespace CGoGN
{
class GenericMap;
namespace Utils
{
class VBO;
}
}
#include "Topology/generic/functor.h"
#include "Utils/vbo.h"
#include "Algo/Render/GL2/mapRender.h"
class MapHandler : public QObject
class MapHandlerGen
{
Q_OBJECT
public:
MapHandler(const QString& name, Window* window, CGoGN::GenericMap* map);
~MapHandler();
MapHandlerGen(const QString& name, Window* window);
virtual ~MapHandlerGen();
virtual void draw(CGoGN::Utils::GLSLShader* shader, int primitive) = 0;
const QString& getName() { return m_name; }
void setName(const QString& name) { m_name = name; }
......@@ -29,13 +24,21 @@ public:
Window* getWindow() { return m_window; }
void setWindow(Window* w) { m_window = w; }
CGoGN::GenericMap* getMap() { return m_map; }
const qglviewer::Vec& getBBmin() const { return m_bbMin; }
void setBBmin(qglviewer::Vec& v) { m_bbMin = v; }
CGoGN::Utils::VBO* addVBO(const QString& name);
void removeVBO(const QString& name);
CGoGN::Utils::VBO* getVBO(const QString& name);
CGoGN::Utils::VBO* findFirstVBOMatching(const QRegExp& regexp);
QList<CGoGN::Utils::VBO*> findVBOsMatching(const QRegExp& regexp);
const qglviewer::Vec& getBBmax() const { return m_bbMax; }
void setBBmax(qglviewer::Vec& v) { m_bbMax = v; }
/*********************************************************
* MANAGE VBOs