Commit 4b478c61 authored by Pierre Kraemer's avatar Pierre Kraemer

convert subdivideSurface Plugin from dockTab to Dialog

parent 0f2569ca
...@@ -14,17 +14,6 @@ SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -fPIC") ...@@ -14,17 +14,6 @@ SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -fPIC")
SET(CGoGN_ROOT_DIR ${CMAKE_SOURCE_DIR}/.. CACHE STRING "CGoGN root dir") SET(CGoGN_ROOT_DIR ${CMAKE_SOURCE_DIR}/.. CACHE STRING "CGoGN root dir")
INCLUDE(${CGoGN_ROOT_DIR}/apps_cmake.txt) INCLUDE(${CGoGN_ROOT_DIR}/apps_cmake.txt)
find_package(Qt4 REQUIRED)
#=======QGLViewer=========#
find_package(QGLViewer REQUIRED)
#=======Python=========#
find_package(PythonLibs REQUIRED)
#======SCHNApps=======# #======SCHNApps=======#
SET(SCHNApps_ROOT_DIR ${CGoGN_ROOT_DIR}/SCHNApps) SET(SCHNApps_ROOT_DIR ${CGoGN_ROOT_DIR}/SCHNApps)
...@@ -38,12 +27,12 @@ ENDIF (NOT WIN32) ...@@ -38,12 +27,12 @@ ENDIF (NOT WIN32)
#======Documentation=======# #======Documentation=======#
find_package(Doxygen) #find_package(Doxygen)
if(DOXYGEN_FOUND) #if(DOXYGEN_FOUND)
configure_file(${CMAKE_SOURCE_DIR}/doc/Doxyfile.in ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile @ONLY) #configure_file(${CMAKE_SOURCE_DIR}/doc/Doxyfile.in ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile @ONLY)
add_custom_target(doc #add_custom_target(doc
${DOXYGEN_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile # ${DOXYGEN_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/Doc # WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/Doc
COMMENT "Generating API documentation with Doxygen" VERBATIM # COMMENT "Generating API documentation with Doxygen" VERBATIM
) #)
endif(DOXYGEN_FOUND) #endif(DOXYGEN_FOUND)
...@@ -55,8 +55,8 @@ private: ...@@ -55,8 +55,8 @@ private:
ComputeNormalDialog* m_computeNormalDialog; ComputeNormalDialog* m_computeNormalDialog;
ComputeCurvatureDialog* m_computeCurvatureDialog; ComputeCurvatureDialog* m_computeCurvatureDialog;
QAction* computeNormalAction; QAction* m_computeNormalAction;
QAction* computeCurvatureAction; QAction* m_computeCurvatureAction;
}; };
#endif #endif
...@@ -11,14 +11,14 @@ bool DifferentialPropertiesPlugin::enable() ...@@ -11,14 +11,14 @@ bool DifferentialPropertiesPlugin::enable()
m_computeNormalDialog = new ComputeNormalDialog(m_window); m_computeNormalDialog = new ComputeNormalDialog(m_window);
m_computeCurvatureDialog = new ComputeCurvatureDialog(m_window); m_computeCurvatureDialog = new ComputeCurvatureDialog(m_window);
computeNormalAction = new QAction("Compute Normal", this); m_computeNormalAction = new QAction("Compute Normal", this);
computeCurvatureAction = new QAction("Compute Curvature", this); m_computeCurvatureAction = new QAction("Compute Curvature", this);
addMenuAction("Surface;Differential Properties;Compute Normal", computeNormalAction); addMenuAction("Surface;Differential Properties;Compute Normal", m_computeNormalAction);
addMenuAction("Surface;Differential Properties;Compute Curvature", computeCurvatureAction); addMenuAction("Surface;Differential Properties;Compute Curvature", m_computeCurvatureAction);
connect(computeNormalAction, SIGNAL(triggered()), this, SLOT(cb_openComputeNormalDialog())); connect(m_computeNormalAction, SIGNAL(triggered()), this, SLOT(cb_openComputeNormalDialog()));
connect(computeCurvatureAction, SIGNAL(triggered()), this, SLOT(cb_openComputeCurvatureDialog())); connect(m_computeCurvatureAction, SIGNAL(triggered()), this, SLOT(cb_openComputeCurvatureDialog()));
connect(m_computeNormalDialog, SIGNAL(accepted()), this, SLOT(cb_computeNormal())); connect(m_computeNormalDialog, SIGNAL(accepted()), this, SLOT(cb_computeNormal()));
connect(m_computeNormalDialog->button_apply, SIGNAL(clicked()), this, SLOT(cb_computeNormal())); connect(m_computeNormalDialog->button_apply, SIGNAL(clicked()), this, SLOT(cb_computeNormal()));
...@@ -56,6 +56,7 @@ void DifferentialPropertiesPlugin::cb_computeNormal() ...@@ -56,6 +56,7 @@ void DifferentialPropertiesPlugin::cb_computeNormal()
normalName = m_computeNormalDialog->combo_normalAttribute->currentText().toUtf8().constData(); normalName = m_computeNormalDialog->combo_normalAttribute->currentText().toUtf8().constData();
else else
normalName = m_computeNormalDialog->normalAttributeName->text().toUtf8().constData(); normalName = m_computeNormalDialog->normalAttributeName->text().toUtf8().constData();
VertexAttribute<PFP2::VEC3> position = map->getAttribute<PFP2::VEC3, VERTEX>(positionName); VertexAttribute<PFP2::VEC3> position = map->getAttribute<PFP2::VEC3, VERTEX>(positionName);
VertexAttribute<PFP2::VEC3> normal = map->getAttribute<PFP2::VEC3, VERTEX>(normalName); VertexAttribute<PFP2::VEC3> normal = map->getAttribute<PFP2::VEC3, VERTEX>(normalName);
if(!normal.isValid()) if(!normal.isValid())
......
...@@ -11,15 +11,13 @@ bool ImportSurfacePlugin::enable() ...@@ -11,15 +11,13 @@ bool ImportSurfacePlugin::enable()
{ {
importAction = new QAction("import", this); importAction = new QAction("import", this);
addMenuAction("Surface;Import", importAction); addMenuAction("Surface;Import", importAction);
connect(importAction, SIGNAL(triggered()), this, SLOT(cb_import())); connect(importAction, SIGNAL(triggered()), this, SLOT(importFromFileDialog()));
return true; return true;
} }
void ImportSurfacePlugin::cb_import() void ImportSurfacePlugin::importFromFile(const QString& fileName)
{ {
QString fileName = QFileDialog::getOpenFileName(m_window, "Import file", m_window->getAppPath(), "Mesh Files (*.ply *.off *.trian)");
QFileInfo fi(fileName); QFileInfo fi(fileName);
if(fi.exists()) if(fi.exists())
{ {
GenericMap* m = m_window->createMap(2); GenericMap* m = m_window->createMap(2);
...@@ -47,6 +45,12 @@ void ImportSurfacePlugin::cb_import() ...@@ -47,6 +45,12 @@ void ImportSurfacePlugin::cb_import()
} }
} }
void ImportSurfacePlugin::importFromFileDialog()
{
QString fileName = QFileDialog::getOpenFileName(m_window, "Import file", m_window->getAppPath(), "Mesh Files (*.ply *.off *.trian)");
importFromFile(fileName);
}
#ifndef DEBUG #ifndef DEBUG
Q_EXPORT_PLUGIN2(ImportSurfacePlugin, ImportSurfacePlugin) Q_EXPORT_PLUGIN2(ImportSurfacePlugin, ImportSurfacePlugin)
#else #else
......
...@@ -42,7 +42,8 @@ public: ...@@ -42,7 +42,8 @@ public:
virtual void mapUnlinked(View* view, MapHandlerGen* m) {} virtual void mapUnlinked(View* view, MapHandlerGen* m) {}
public slots: public slots:
void cb_import(); void importFromFile(const QString& fileName);
void importFromFileDialog();
private: private:
QAction* importAction; QAction* importAction;
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>174</width> <width>174</width>
<height>553</height> <height>547</height>
</rect> </rect>
</property> </property>
<property name="windowTitle"> <property name="windowTitle">
......
...@@ -2,20 +2,22 @@ cmake_minimum_required(VERSION 2.8) ...@@ -2,20 +2,22 @@ cmake_minimum_required(VERSION 2.8)
INCLUDE_DIRECTORIES( INCLUDE_DIRECTORIES(
${SCHNApps_ROOT_DIR}/include ${SCHNApps_ROOT_DIR}/include
${SCHNApps_ROOT_DIR}/Plugins/subdivideSurface ${SCHNApps_ROOT_DIR}/Plugins/subdivideSurface/include
${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_BINARY_DIR}
) )
SET( PLUGIN_SRC SET( PLUGIN_SRC
${SCHNApps_ROOT_DIR}/Plugins/subdivideSurface/subdivideSurface.cpp ${SCHNApps_ROOT_DIR}/Plugins/subdivideSurface/src/subdivideSurface.cpp
${SCHNApps_ROOT_DIR}/Plugins/subdivideSurface/src/subdivideSurfaceDialog.cpp
) )
SET( PLUGIN_H SET( PLUGIN_H
${SCHNApps_ROOT_DIR}/Plugins/subdivideSurface/subdivideSurface.h ${SCHNApps_ROOT_DIR}/Plugins/subdivideSurface/include/subdivideSurface.h
${SCHNApps_ROOT_DIR}/Plugins/subdivideSurface/include/subdivideSurfaceDialog.h
) )
SET( PLUGIN_FORM SET( PLUGIN_FORM
${SCHNApps_ROOT_DIR}/Plugins/subdivideSurface/subdivideSurface.ui ${SCHNApps_ROOT_DIR}/Plugins/subdivideSurface/forms/subdivideSurfaceDialog.ui
) )
IF( ${CMAKE_BUILD_TYPE} STREQUAL Debug ) IF( ${CMAKE_BUILD_TYPE} STREQUAL Debug )
......
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0"> <ui version="4.0">
<class>SubdivideSurfaceWidget</class> <class>SubdivideSurfaceDialog</class>
<widget class="QWidget" name="SubdivideSurfaceWidget"> <widget class="QDialog" name="SubdivideSurfaceDialog">
<property name="geometry"> <property name="geometry">
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>176</width> <width>314</width>
<height>427</height> <height>230</height>
</rect> </rect>
</property> </property>
<property name="windowTitle"> <property name="windowTitle">
<string>Form</string> <string>Subdivide surface</string>
</property> </property>
<layout class="QVBoxLayout" name="verticalLayout"> <layout class="QVBoxLayout" name="verticalLayout">
<item> <item>
...@@ -22,14 +22,14 @@ ...@@ -22,14 +22,14 @@
<item> <item>
<widget class="QLabel" name="label_2"> <widget class="QLabel" name="label_2">
<property name="text"> <property name="text">
<string>Position :</string> <string>Position attribute :</string>
</property> </property>
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QComboBox" name="combo_positionAttribute"> <widget class="QComboBox" name="combo_positionAttribute">
<property name="sizePolicy"> <property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed"> <sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch> <horstretch>0</horstretch>
<verstretch>0</verstretch> <verstretch>0</verstretch>
</sizepolicy> </sizepolicy>
...@@ -39,38 +39,54 @@ ...@@ -39,38 +39,54 @@
</layout> </layout>
</item> </item>
<item> <item>
<widget class="QPushButton" name="button_loopSubdivision"> <layout class="QHBoxLayout" name="horizontalLayout">
<property name="text"> <item>
<string>Loop subdivision</string> <widget class="QRadioButton" name="radio_Loop">
</property> <property name="text">
</widget> <string>Loop</string>
</item> </property>
<item> </widget>
<widget class="QPushButton" name="button_CCSubdivision"> </item>
<property name="text"> <item>
<string>Catmull-Clark subdivision</string> <widget class="QRadioButton" name="radio_CC">
</property> <property name="text">
</widget> <string>Catmull-Clark</string>
</item> </property>
<item> </widget>
<widget class="QPushButton" name="button_trianguleFaces"> </item>
<property name="text"> <item>
<string>Triangule Faces</string> <widget class="QRadioButton" name="radio_trianguleFaces">
</property> <property name="text">
</widget> <string>Triangule faces</string>
</property>
</widget>
</item>
</layout>
</item> </item>
<item> <item>
<spacer name="verticalSpacer"> <layout class="QHBoxLayout" name="horizontalLayout_3">
<property name="orientation"> <item>
<enum>Qt::Vertical</enum> <widget class="QPushButton" name="button_cancel">
</property> <property name="text">
<property name="sizeHint" stdset="0"> <string>Cancel</string>
<size> </property>
<width>156</width> </widget>
<height>161</height> </item>
</size> <item>
</property> <widget class="QPushButton" name="button_apply">
</spacer> <property name="text">
<string>Apply</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="button_ok">
<property name="text">
<string>OK</string>
</property>
</widget>
</item>
</layout>
</item> </item>
</layout> </layout>
</widget> </widget>
......
...@@ -2,20 +2,14 @@ ...@@ -2,20 +2,14 @@
#define _SUBDIVIDESURFACE_PLUGIN_H_ #define _SUBDIVIDESURFACE_PLUGIN_H_
#include "plugin.h" #include "plugin.h"
#include "ui_subdivideSurface.h"
#include "subdivideSurfaceDialog.h"
using namespace CGoGN; using namespace CGoGN;
using namespace SCHNApps; using namespace SCHNApps;
class SubdivideSurfaceDockTab : public QWidget, public Ui::SubdivideSurfaceWidget
{
public:
SubdivideSurfaceDockTab() { setupUi(this); }
};
class SubdivideSurfacePlugin : public Plugin class SubdivideSurfacePlugin : public Plugin
{ {
Q_OBJECT Q_OBJECT
...@@ -49,17 +43,18 @@ public: ...@@ -49,17 +43,18 @@ public:
virtual void mapLinked(View* view, MapHandlerGen* m) {} virtual void mapLinked(View* view, MapHandlerGen* m) {}
virtual void mapUnlinked(View* view, MapHandlerGen* m) {} virtual void mapUnlinked(View* view, MapHandlerGen* m) {}
protected:
SubdivideSurfaceDockTab* m_dockTab;
public slots: public slots:
void cb_addMapToList(MapHandlerGen* m); void cb_openSubdivideSurfaceDialog();
void cb_removeMapFromList(MapHandlerGen* m); void cb_subdivideSurface();
void cb_selectedMapChanged();
void loopSubdivision(PFP2::MAP* map, VertexAttribute<PFP2::VEC3>& position);
void CCSubdivision(PFP2::MAP* map, VertexAttribute<PFP2::VEC3>& position);
void trianguleFaces(PFP2::MAP* map, VertexAttribute<PFP2::VEC3>& position);
private:
SubdivideSurfaceDialog* m_subdivideSurfaceDialog;
void cb_loopSubdivision(); QAction* m_subdivideSurfaceAction;
void cb_CCSubdivision();
void cb_trianguleFaces();
}; };
#endif #endif
#ifndef _SUBDIVIDESURFACE_DIALOG_H_
#define _SUBDIVIDESURFACE_DIALOG_H_
#include "ui_subdivideSurfaceDialog.h"
namespace CGoGN
{
namespace SCHNApps
{
class Window;
class SubdivideSurfaceDialog : public QDialog, public Ui::SubdivideSurfaceDialog
{
Q_OBJECT
public:
SubdivideSurfaceDialog(Window* w);
void init();
public slots:
void cb_selectedMapChanged();
private:
Window* m_window;
};
} // namespace SCHNApps
} // namespace CGoGN
#endif
#include "subdivideSurface.h"
#include "mapHandler.h"
#include "Algo/Modelisation/subdivision.h"
bool SubdivideSurfacePlugin::enable()
{
m_subdivideSurfaceDialog = new SubdivideSurfaceDialog(m_window);
m_subdivideSurfaceAction = new QAction("Subdivide surface", this);
addMenuAction("Surface;Subdivide", m_subdivideSurfaceAction);
connect(m_subdivideSurfaceAction, SIGNAL(triggered()), this, SLOT(cb_openSubdivideSurfaceDialog()));
connect(m_subdivideSurfaceDialog, SIGNAL(accepted()), this, SLOT(cb_subdivideSurface()));
connect(m_subdivideSurfaceDialog->button_apply, SIGNAL(clicked()), this, SLOT(cb_subdivideSurface()));
return true;
}
void SubdivideSurfacePlugin::cb_openSubdivideSurfaceDialog()
{
m_subdivideSurfaceDialog->init();
m_subdivideSurfaceDialog->show();
}
void SubdivideSurfacePlugin::cb_subdivideSurface()
{
QList<QListWidgetItem*> currentItems = m_subdivideSurfaceDialog->mapList->selectedItems();
if(!currentItems.empty())
{
const QString& mapname = currentItems[0]->text();
MapHandler<PFP2>* mh = static_cast<MapHandler<PFP2>*>(m_window->getMap(mapname));
PFP2::MAP* map = mh->getMap();
std::string positionName = m_subdivideSurfaceDialog->combo_positionAttribute->currentText().toUtf8().constData();
VertexAttribute<PFP2::VEC3> position = map->getAttribute<PFP2::VEC3, VERTEX>(positionName);
if(m_subdivideSurfaceDialog->radio_Loop->isChecked())
loopSubdivision(map, position);
else if(m_subdivideSurfaceDialog->radio_CC->isChecked())
CCSubdivision(map, position);
else if(m_subdivideSurfaceDialog->radio_trianguleFaces->isChecked())
trianguleFaces(map, position);
mh->updatePrimitives(Algo::Render::GL2::POINTS);
mh->updatePrimitives(Algo::Render::GL2::LINES);
mh->updatePrimitives(Algo::Render::GL2::TRIANGLES);
mh->updateVBO(position);
QList<View*> views = mh->getLinkedViews();
foreach(View* view, views)
view->updateGL();
}
}
void SubdivideSurfacePlugin::loopSubdivision(PFP2::MAP* map, VertexAttribute<PFP2::VEC3>& position)
{
Algo::Surface::Modelisation::LoopSubdivision<PFP2>(*map, position);
}
void SubdivideSurfacePlugin::CCSubdivision(PFP2::MAP* map, VertexAttribute<PFP2::VEC3>& position)
{
Algo::Surface::Modelisation::CatmullClarkSubdivision<PFP2>(*map, position);
}
void SubdivideSurfacePlugin::trianguleFaces(PFP2::MAP* map, VertexAttribute<PFP2::VEC3>& position)
{
Algo::Surface::Modelisation::trianguleFaces<PFP2>(*map, position);
}
#ifndef DEBUG
Q_EXPORT_PLUGIN2(SubdivideSurfacePlugin, SubdivideSurfacePlugin)
#else
Q_EXPORT_PLUGIN2(SubdivideSurfacePluginD, SubdivideSurfacePlugin)
#endif
#include "subdivideSurfaceDialog.h"
#include "subdivideSurface.h"
#include "window.h"
#include "mapHandler.h"
namespace CGoGN
{
namespace SCHNApps
{
SubdivideSurfaceDialog::SubdivideSurfaceDialog(Window* w) : m_window(w)
{
setupUi(this);
connect(mapList, SIGNAL(itemSelectionChanged()), this, SLOT(cb_selectedMapChanged()));
}
void SubdivideSurfaceDialog::init()
{
mapList->clear();
combo_positionAttribute->clear();
const QList<MapHandlerGen*>& maps = m_window->getMapsList();
foreach(MapHandlerGen* map, maps)
mapList->addItem(map->getName());
}
void SubdivideSurfaceDialog::cb_selectedMapChanged()
{
QList<QListWidgetItem*> currentItems = mapList->selectedItems();
if(!currentItems.empty())
{
combo_positionAttribute->clear();
const QString& mapname = currentItems[0]->text();
MapHandlerGen* mh = m_window->getMap(mapname);
GenericMap* map = mh->getGenericMap();
AttributeContainer& cont = map->getAttributeContainer<VERTEX>();
std::vector<std::string> names;
std::vector<std::string> types;
cont.getAttributesNames(names);
cont.getAttributesTypes(types);
std::string vec3TypeName = nameOfType(PFP2::VEC3());
unsigned int j = 0;
for(unsigned int i = 0; i < names.size(); ++i)
{
if(types[i] == vec3TypeName)
{
combo_positionAttribute->addItem(QString::fromStdString(names[i]));
if(names[i] == "position") // try to select a position attribute named "position"
combo_positionAttribute->setCurrentIndex(j);
++j;
}
}
}
}
} // namespace SCHNApps
} // namespace CGoGN
#include "subdivideSurface.h"
#include "mapHandler.h"
#include "Algo/Modelisation/subdivision.h"
bool SubdivideSurfacePlugin::enable()
{
m_dockTab = new SubdivideSurfaceDockTab();
addTabInDock(m_dockTab, "SubdivideSurface");
connect(m_window, SIGNAL(mapAdded(MapHandlerGen*)), this, SLOT(cb_addMapToList(MapHandlerGen*)));
connect(m_window, SIGNAL(mapRemoved(MapHandlerGen*)), this, SLOT(cb_removeMapFromList(MapHandlerGen*)));