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

SCHNApps: added namespaces

parent 417d1506
......@@ -29,24 +29,24 @@ file(
${SCHNApps_ROOT_DIR}/src/view.cpp
${SCHNApps_ROOT_DIR}/src/window.cpp
${SCHNApps_ROOT_DIR}/src/viewButtonArea.cpp
${SCHNApps_ROOT_DIR}/src/camerasDialog.cpp
${SCHNApps_ROOT_DIR}/src/pluginsDialog.cpp
${SCHNApps_ROOT_DIR}/src/mapsDialog.cpp
${SCHNApps_ROOT_DIR}/src/cameraViewDialog.cpp
${SCHNApps_ROOT_DIR}/src/pluginsViewDialog.cpp
${SCHNApps_ROOT_DIR}/src/mapsViewDialog.cpp
${SCHNApps_ROOT_DIR}/src/dialogs/camerasDialog.cpp
${SCHNApps_ROOT_DIR}/src/dialogs/pluginsDialog.cpp
${SCHNApps_ROOT_DIR}/src/dialogs/mapsDialog.cpp
${SCHNApps_ROOT_DIR}/src/dialogs/cameraViewDialog.cpp
${SCHNApps_ROOT_DIR}/src/dialogs/pluginsViewDialog.cpp
${SCHNApps_ROOT_DIR}/src/dialogs/mapsViewDialog.cpp
)
SET(SCHNApps_H_OBJECT_FILES
${SCHNApps_ROOT_DIR}/include/view.h
${SCHNApps_ROOT_DIR}/include/window.h
${SCHNApps_ROOT_DIR}/include/viewButtonArea.h
${SCHNApps_ROOT_DIR}/include/camerasDialog.h
${SCHNApps_ROOT_DIR}/include/pluginsDialog.h
${SCHNApps_ROOT_DIR}/include/mapsDialog.h
${SCHNApps_ROOT_DIR}/include/cameraViewDialog.h
${SCHNApps_ROOT_DIR}/include/pluginsViewDialog.h
${SCHNApps_ROOT_DIR}/include/mapsViewDialog.h
${SCHNApps_ROOT_DIR}/include/dialogs/camerasDialog.h
${SCHNApps_ROOT_DIR}/include/dialogs/pluginsDialog.h
${SCHNApps_ROOT_DIR}/include/dialogs/mapsDialog.h
${SCHNApps_ROOT_DIR}/include/dialogs/cameraViewDialog.h
${SCHNApps_ROOT_DIR}/include/dialogs/pluginsViewDialog.h
${SCHNApps_ROOT_DIR}/include/dialogs/mapsViewDialog.h
)
file(
......
......@@ -24,9 +24,9 @@ IF( ${CMAKE_BUILD_TYPE} STREQUAL Debug )
link_directories( ${CGoGN_ROOT_DIR}/lib/Debug ${CGoGN_ROOT_DIR}/lib/Release )
ENDIF (WIN32)
QT4_WRAP_UI( PLUGIN_UI ${PLUGIN_FORM} )
# QT4_WRAP_UI( PLUGIN_UI ${PLUGIN_FORM} )
QT4_WRAP_CPP( PLUGIN_MOC ${PLUGIN_H} )
ADD_LIBRARY( ImportPluginD SHARED
${PLUGIN_SRC}
${PLUGIN_UI}
......@@ -51,7 +51,7 @@ ELSE ( ${CMAKE_BUILD_TYPE} STREQUAL Debug )
link_directories( ${CGoGN_ROOT_DIR}/lib/Release )
ENDIF (WIN32)
QT4_WRAP_UI( PLUGIN_UI ${PLUGIN_FORM} )
# QT4_WRAP_UI( PLUGIN_UI ${PLUGIN_FORM} )
QT4_WRAP_CPP( PLUGIN_MOC ${PLUGIN_H} )
ADD_LIBRARY( ImportPlugin SHARED
......
#include "import.h"
#include <QFileDialog>
#include <QFileInfo>
#include "system.h"
#include "mapHandler.h"
#include "Algo/Import/import.h"
#include <QFileDialog>
#include <QFileInfo>
bool ImportPlugin::enable()
{
importAction = new QAction("import", this);
......@@ -28,23 +29,36 @@ void ImportPlugin::cb_import()
MapHandler<PFP>* h = new MapHandler<PFP>(fi.baseName(), m_window, m);
std::vector<std::string> attrNames ;
CGoGN::Algo::Import::importMesh<PFP>(*m, fileName.toUtf8().constData(), attrNames);
Algo::Import::importMesh<PFP>(*m, fileName.toUtf8().constData(), attrNames);
// get vertex position attribute
VertexAttribute<VEC3> position = m->getAttribute<VEC3, CGoGN::VERTEX>(attrNames[0]);
CGoGN::VertexAttribute<VEC3> position = m->getAttribute<VEC3, CGoGN::VERTEX>(attrNames[0]);
// create VBO for vertex position attribute
Utils::VBO* positionVBO = h->getVBO(position.name());
positionVBO->updateData(position);
// compute vertex normal attribute
VertexAttribute<VEC3> normal = m->getAttribute<VEC3, CGoGN::VERTEX>("normal");
if(!normal.isValid())
normal = m->addAttribute<VEC3, CGoGN::VERTEX>("normal");
Algo::Geometry::computeNormalVertices<PFP>(*m, position, normal);
// create VBO for vertex normal attribute
CGoGN::Utils::VBO* normalVBO = h->getVBO("normal");
normalVBO->updateData(normal);
CGoGN::Geom::BoundingBox<VEC3> bb = CGoGN::Algo::Geometry::computeBoundingBox<PFP>(*m, position) ;
// compute map bounding box
CGoGN::Geom::BoundingBox<VEC3> bb = CGoGN::Algo::Geometry::computeBoundingBox<PFP>(*m, 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]);
h->setBBmin(min);
h->setBBmax(max);
h->updatePrimitives(CGoGN::Algo::Render::GL2::POINTS, CGoGN::allDarts) ;
h->updatePrimitives(CGoGN::Algo::Render::GL2::LINES, CGoGN::allDarts) ;
h->updatePrimitives(CGoGN::Algo::Render::GL2::TRIANGLES, CGoGN::allDarts) ;
CGoGN::Utils::VBO* positionVBO = h->getVBO(position.name());
positionVBO->updateData(position);
// compute primitive connectivity VBOs
h->updatePrimitives(CGoGN::Algo::Render::GL2::POINTS, CGoGN::allDarts);
h->updatePrimitives(CGoGN::Algo::Render::GL2::LINES, CGoGN::allDarts);
h->updatePrimitives(CGoGN::Algo::Render::GL2::TRIANGLES, CGoGN::allDarts);
m_window->addMap(h);
}
......
......@@ -2,25 +2,29 @@
#define _IMPORT_PLUGIN_H_
#include "plugin.h"
#include "view.h"
#include "Topology/generic/functor.h"
#include "Topology/generic/parameters.h"
#include "Topology/map/embeddedMap2.h"
struct PFP: public CGoGN::PFP_STANDARD
using namespace CGoGN;
using namespace SCHNApps;
struct PFP: public PFP_STANDARD
{
typedef CGoGN::EmbeddedMap2 MAP;
typedef EmbeddedMap2 MAP;
};
typedef PFP::MAP MAP;
typedef PFP::VEC3 VEC3;
class ImportPlugin : public Plugin
{
Q_OBJECT
Q_INTERFACES(Plugin)
Q_INTERFACES(CGoGN::SCHNApps::Plugin)
public:
ImportPlugin()
......
......@@ -14,6 +14,12 @@ bool RenderPlugin::enable()
m_flatShader->setDiffuse(CGoGN::Geom::Vec4f(0.8f, 0.9f, 0.7f, 1.0f));
m_flatShader->setExplode(1.0f);
m_phongShader = new CGoGN::Utils::ShaderPhong() ;
m_phongShader->setAmbiant(CGoGN::Geom::Vec4f(0.2f, 0.2f, 0.2f, 0.1f)) ;
m_phongShader->setDiffuse(CGoGN::Geom::Vec4f(0.8f, 0.9f, 0.7f, 1.0f)) ;
m_phongShader->setSpecular(CGoGN::Geom::Vec4f(0.9f, 0.9f, 0.9f, 1.0f)) ;
m_phongShader->setShininess(80.0f) ;
m_simpleColorShader = new CGoGN::Utils::ShaderSimpleColor();
CGoGN::Geom::Vec4f c(0.1f, 0.1f, 0.1f, 1.0f);
m_simpleColorShader->setColor(c);
......@@ -24,6 +30,7 @@ bool RenderPlugin::enable()
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)));
connect(m_dockTab->group_faceShading, SIGNAL(buttonClicked(QAbstractButton*)), this, SLOT(cb_faceStyleChanged(QAbstractButton*)));
return true;
}
......@@ -31,6 +38,7 @@ bool RenderPlugin::enable()
void RenderPlugin::disable()
{
delete m_flatShader;
delete m_phongShader;
delete m_simpleColorShader;
delete m_pointSprite;
}
......@@ -43,6 +51,7 @@ void RenderPlugin::redraw(View* view)
foreach(MapHandlerGen* m, maps)
{
CGoGN::Utils::VBO* positionVBO = m->getVBO("position");
CGoGN::Utils::VBO* normalVBO = m->getVBO("normal");
if(params->renderVertices)
{
m_pointSprite->setSize(m->getBBdiagSize() / 200.0f * params->verticesScaleFactor);
......@@ -63,8 +72,18 @@ void RenderPlugin::redraw(View* view)
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);
switch(params->faceStyle)
{
case FLAT :
m_flatShader->setAttributePosition(positionVBO);
m->draw(m_flatShader, CGoGN::Algo::Render::GL2::TRIANGLES);
break ;
case PHONG :
m_phongShader->setAttributePosition(positionVBO) ;
m_phongShader->setAttributeNormal(normalVBO) ;
m->draw(m_phongShader, CGoGN::Algo::Render::GL2::TRIANGLES);
break ;
}
glDisable(GL_POLYGON_OFFSET_FILL);
}
}
......@@ -73,9 +92,10 @@ void RenderPlugin::redraw(View* view)
void RenderPlugin::viewLinked(View* view)
{
assert(!h_viewParams.contains(view));
h_viewParams.insert(view, new TabParams(1.0, false, false, true));
h_viewParams.insert(view, new TabParams(1.0, false, false, true, FLAT));
CGoGN::Utils::GLSLShader::registerShader(view, m_flatShader);
CGoGN::Utils::GLSLShader::registerShader(view, m_phongShader);
CGoGN::Utils::GLSLShader::registerShader(view, m_simpleColorShader);
CGoGN::Utils::GLSLShader::registerShader(view, m_pointSprite);
}
......@@ -86,6 +106,7 @@ void RenderPlugin::viewUnlinked(View* view)
h_viewParams.remove(view);
CGoGN::Utils::GLSLShader::unregisterShader(view, m_flatShader);
CGoGN::Utils::GLSLShader::registerShader(view, m_phongShader);
CGoGN::Utils::GLSLShader::unregisterShader(view, m_simpleColorShader);
CGoGN::Utils::GLSLShader::unregisterShader(view, m_pointSprite);
}
......@@ -97,6 +118,8 @@ void RenderPlugin::currentViewChanged(View* view)
m_dockTab->slider_verticesScaleFactor->setSliderPosition(params->verticesScaleFactor * 50.0);
m_dockTab->check_renderEdges->setChecked(params->renderEdges);
m_dockTab->check_renderFaces->setChecked(params->renderFaces);
m_dockTab->radio_flatShading->setChecked(params->faceStyle == FLAT);
m_dockTab->radio_phongShading->setChecked(params->faceStyle == PHONG);
}
void RenderPlugin::cb_renderVerticesChanged(bool b)
......@@ -139,6 +162,19 @@ void RenderPlugin::cb_renderFacesChanged(bool b)
current->updateGL();
}
void RenderPlugin::cb_faceStyleChanged(QAbstractButton* b)
{
View* current = m_window->getCurrentView();
assert(isLinkedToView(current));
TabParams* params = h_viewParams[current];
if(m_dockTab->radio_flatShading->isChecked())
params->faceStyle = FLAT;
else if(m_dockTab->radio_phongShading->isChecked())
params->faceStyle = PHONG;
current->updateGL();
}
/**
* If we want to compile this plugin in debug mode,
* we also define a DEBUG macro at the compilation
......
......@@ -9,10 +9,15 @@
#include "Topology/map/embeddedMap2.h"
#include "Utils/Shaders/shaderFlat.h"
#include "Utils/Shaders/shaderPhong.h"
#include "Utils/Shaders/shaderSimpleColor.h"
#include "Utils/pointSprite.h"
using namespace CGoGN;
using namespace SCHNApps;
class RenderDockTab : public QWidget, public Ui::RenderWidget
{
public:
......@@ -20,26 +25,34 @@ public:
};
enum FaceShadingStyle
{
FLAT = 0,
PHONG = 1
};
struct TabParams
{
TabParams(float vsf, bool rv, bool re, bool rf) :
TabParams(float vsf, bool rv, bool re, bool rf, FaceShadingStyle fstyle) :
verticesScaleFactor(vsf),
renderVertices(rv),
renderEdges(re),
renderFaces(rf)
renderFaces(rf),
faceStyle(fstyle)
{}
float verticesScaleFactor;
bool renderVertices;
bool renderEdges;
bool renderFaces;
FaceShadingStyle faceStyle;
};
class RenderPlugin : public Plugin
{
Q_OBJECT
Q_INTERFACES(Plugin)
Q_INTERFACES(CGoGN::SCHNApps::Plugin)
public:
RenderPlugin()
......@@ -71,14 +84,16 @@ protected:
QHash<View*, TabParams*> h_viewParams;
CGoGN::Utils::ShaderFlat* m_flatShader;
CGoGN::Utils::ShaderSimpleColor* m_simpleColorShader ;
CGoGN::Utils::PointSprite* m_pointSprite ;
CGoGN::Utils::ShaderPhong* m_phongShader;
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);
void cb_faceStyleChanged(QAbstractButton* b);
};
#endif
......@@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>177</width>
<height>293</height>
<width>174</width>
<height>397</height>
</rect>
</property>
<property name="windowTitle">
......@@ -48,6 +48,33 @@
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QRadioButton" name="radio_flatShading">
<property name="text">
<string>Flat</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
<attribute name="buttonGroup">
<string notr="true">group_faceShading</string>
</attribute>
</widget>
</item>
<item>
<widget class="QRadioButton" name="radio_phongShading">
<property name="text">
<string>Phong</string>
</property>
<attribute name="buttonGroup">
<string notr="true">group_faceShading</string>
</attribute>
</widget>
</item>
</layout>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
......@@ -65,4 +92,7 @@
</widget>
<resources/>
<connections/>
<buttongroups>
<buttongroup name="group_faceShading"/>
</buttongroups>
</ui>
......@@ -29,24 +29,24 @@ file(
${SCHNApps_ROOT_DIR}/src/view.cpp
${SCHNApps_ROOT_DIR}/src/window.cpp
${SCHNApps_ROOT_DIR}/src/viewButtonArea.cpp
${SCHNApps_ROOT_DIR}/src/camerasDialog.cpp
${SCHNApps_ROOT_DIR}/src/pluginsDialog.cpp
${SCHNApps_ROOT_DIR}/src/mapsDialog.cpp
${SCHNApps_ROOT_DIR}/src/cameraViewDialog.cpp
${SCHNApps_ROOT_DIR}/src/pluginsViewDialog.cpp
${SCHNApps_ROOT_DIR}/src/mapsViewDialog.cpp
${SCHNApps_ROOT_DIR}/src/dialogs/camerasDialog.cpp
${SCHNApps_ROOT_DIR}/src/dialogs/pluginsDialog.cpp
${SCHNApps_ROOT_DIR}/src/dialogs/mapsDialog.cpp
${SCHNApps_ROOT_DIR}/src/dialogs/cameraViewDialog.cpp
${SCHNApps_ROOT_DIR}/src/dialogs/pluginsViewDialog.cpp
${SCHNApps_ROOT_DIR}/src/dialogs/mapsViewDialog.cpp
)
SET(SCHNApps_H_OBJECT_FILES
${SCHNApps_ROOT_DIR}/include/view.h
${SCHNApps_ROOT_DIR}/include/window.h
${SCHNApps_ROOT_DIR}/include/viewButtonArea.h
${SCHNApps_ROOT_DIR}/include/camerasDialog.h
${SCHNApps_ROOT_DIR}/include/pluginsDialog.h
${SCHNApps_ROOT_DIR}/include/mapsDialog.h
${SCHNApps_ROOT_DIR}/include/cameraViewDialog.h
${SCHNApps_ROOT_DIR}/include/pluginsViewDialog.h
${SCHNApps_ROOT_DIR}/include/mapsViewDialog.h
${SCHNApps_ROOT_DIR}/include/dialogs/camerasDialog.h
${SCHNApps_ROOT_DIR}/include/dialogs/pluginsDialog.h
${SCHNApps_ROOT_DIR}/include/dialogs/mapsDialog.h
${SCHNApps_ROOT_DIR}/include/dialogs/cameraViewDialog.h
${SCHNApps_ROOT_DIR}/include/dialogs/pluginsViewDialog.h
${SCHNApps_ROOT_DIR}/include/dialogs/mapsViewDialog.h
)
file(
......
......@@ -4,6 +4,12 @@
#include "view.h"
#include "QGLViewer/camera.h"
namespace CGoGN
{
namespace SCHNApps
{
class Window;
class Camera : public qglviewer::Camera
......@@ -82,4 +88,8 @@ protected:
int m_snapCount;
};
} // namespace SCHNApps
} // namespace CGoGN
#endif
......@@ -3,6 +3,12 @@
#include "ui_cameraViewDialog.h"
namespace CGoGN
{
namespace SCHNApps
{
class Window;
class Camera;
class View;
......@@ -27,4 +33,8 @@ public slots:
void cb_removeCameraFromList(Camera* c);
};
} // namespace SCHNApps
} // namespace CGoGN
#endif
......@@ -3,6 +3,12 @@
#include "ui_camerasDialog.h"
namespace CGoGN
{
namespace SCHNApps
{
class Window;
class Camera;
......@@ -24,4 +30,8 @@ public slots:
void cb_removeCameraFromList(Camera* c);
};
} // namespace SCHNApps
} // namespace CGoGN
#endif
......@@ -3,6 +3,12 @@
#include "ui_mapsDialog.h"
namespace CGoGN
{
namespace SCHNApps
{
class Window;
class MapHandlerGen;
......@@ -24,4 +30,8 @@ public slots:
void cb_removeMapFromList(MapHandlerGen* m);
};
} // namespace SCHNApps
} // namespace CGoGN
#endif
......@@ -3,6 +3,12 @@
#include "ui_mapsViewDialog.h"
namespace CGoGN
{
namespace SCHNApps
{
class Window;
class View;
class MapHandlerGen;
......@@ -25,4 +31,8 @@ public slots:
void cb_removeMapFromList(MapHandlerGen* m);
};
} // namespace SCHNApps
} // namespace CGoGN
#endif
......@@ -5,6 +5,14 @@
#include "types.h"
namespace CGoGN
{
namespace SCHNApps
{
class Window;
struct PluginInfo
{
PluginInfo(const QString& path, const QString& name) :
......@@ -56,4 +64,8 @@ protected slots:
// void showPluginInfo();
};
} // namespace SCHNApps
} // namespace CGoGN
#endif
......@@ -3,6 +3,12 @@
#include "ui_pluginsViewDialog.h"
namespace CGoGN
{
namespace SCHNApps
{
class Window;
class View;
class Plugin;
......@@ -25,4 +31,8 @@ public slots:
void cb_removePluginFromList(Plugin* p);
};
} // namespace SCHNApps
} // namespace CGoGN
#endif
......@@ -11,10 +11,16 @@
#include "Utils/vbo.h"
#include "Algo/Render/GL2/mapRender.h"
namespace CGoGN
{
namespace SCHNApps
{
class MapHandlerGen
{
public:
MapHandlerGen(const QString& name, Window* window, CGoGN::GenericMap* map);
MapHandlerGen(const QString& name, Window* window, GenericMap* map);
virtual ~MapHandlerGen();
const QString& getName() const { return m_name; }
......@@ -23,7 +29,7 @@ public:
Window* getWindow() const { return m_window; }
void setWindow(Window* w) { m_window = w; }
CGoGN::GenericMap* getGenericMap() { return m_map; }
GenericMap* getGenericMap() { return m_map; }
const qglviewer::Vec& getBBmin() const { return m_bbMin; }
void setBBmin(qglviewer::Vec& v) { m_bbMin = v; }
......@@ -35,13 +41,13 @@ public:
bool isUsed() const { return !l_views.empty(); }
void draw(CGoGN::Utils::GLSLShader* shader, int primitive);
void draw(Utils::GLSLShader* shader, int primitive);
/*********************************************************
* MANAGE VBOs
*********************************************************/
CGoGN::Utils::VBO* getVBO(const std::string& name);
Utils::VBO* getVBO(const std::string& name);
void deleteVBO(const std::string& name);
/*********************************************************
......@@ -56,9 +62,9 @@ public:
protected:
QString m_name;
Window* m_window;
CGoGN::GenericMap* m_map;
GenericMap* m_map;
CGoGN::Algo::Render::GL2::MapRender* m_render;
Algo::Render::GL2::MapRender* m_render;
qglviewer::Vec m_bbMin;
qglviewer::Vec m_bbMax;
......@@ -84,10 +90,14 @@ public:
typename PFP::MAP* getMap() { return reinterpret_cast<typename PFP::MAP*>(m_map); }
void updatePrimitives(int primitive, const CGoGN::FunctorSelect& good)
void updatePrimitives(int primitive, const FunctorSelect& good)
{
m_render->initPrimitives<PFP>(*(reinterpret_cast<typename PFP::MAP*>(m_map)), good, primitive) ;