Commit c96106aa authored by Lionel Untereiner's avatar Lionel Untereiner

Merge branch 'master' of cgogn.u-strasbg.fr:~cgogn/CGoGN

parents 5b6cc5a6 5600a6e5
cmake_minimum_required(VERSION 2.8)
ADD_SUBDIRECTORY(import)
ADD_SUBDIRECTORY(importSurface)
ADD_SUBDIRECTORY(differentialProperties)
ADD_SUBDIRECTORY(render)
ADD_SUBDIRECTORY(renderVector)
ADD_SUBDIRECTORY(subdivideSurface)
cmake_minimum_required(VERSION 2.8)
INCLUDE_DIRECTORIES(
${SCHNApps_ROOT_DIR}/include
${SCHNApps_ROOT_DIR}/Plugins/differentialProperties/include
${CMAKE_CURRENT_BINARY_DIR}
)
SET( PLUGIN_SRC
${SCHNApps_ROOT_DIR}/Plugins/differentialProperties/src/differentialProperties.cpp
${SCHNApps_ROOT_DIR}/Plugins/differentialProperties/src/computeNormalsDialog.cpp
)
SET( PLUGIN_H
${SCHNApps_ROOT_DIR}/Plugins/differentialProperties/include/differentialProperties.h
${SCHNApps_ROOT_DIR}/Plugins/differentialProperties/include/computeNormalsDialog.h
)
SET( PLUGIN_FORM
${SCHNApps_ROOT_DIR}/Plugins/differentialProperties/forms/computeNormalsDialog.ui
)
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_UI( PLUGIN_UI ${PLUGIN_FORM} )
QT4_WRAP_CPP( PLUGIN_MOC ${PLUGIN_H} )
ADD_LIBRARY( DifferentialPropertiesPluginD SHARED
${PLUGIN_SRC}
${PLUGIN_UI}
${PLUGIN_MOC}
)
TARGET_LINK_LIBRARIES( DifferentialPropertiesPluginD
${CGoGN_LIBS_D}
${COMMON_LIBS}
${QGLVIEWER_LIBRARIES}
)
ADD_DEPENDENCIES( DifferentialPropertiesPluginD SCHNAppsD )
SET_TARGET_PROPERTIES( DifferentialPropertiesPluginD 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_UI( PLUGIN_UI ${PLUGIN_FORM} )
QT4_WRAP_CPP( PLUGIN_MOC ${PLUGIN_H} )
ADD_LIBRARY( DifferentialPropertiesPlugin SHARED
${PLUGIN_SRC}
${PLUGIN_UI}
${PLUGIN_MOC}
)
TARGET_LINK_LIBRARIES( DifferentialPropertiesPlugin
${CGoGN_LIBS_R}
${COMMON_LIBS}
${QGLVIEWER_LIBRARIES}
)
ADD_DEPENDENCIES( DifferentialPropertiesPlugin SCHNApps )
ENDIF ( ${CMAKE_BUILD_TYPE} STREQUAL Debug )
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>ComputeNormalsDialog</class>
<widget class="QDialog" name="ComputeNormalsDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>287</width>
<height>228</height>
</rect>
</property>
<property name="windowTitle">
<string>Compute Normals</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QListWidget" name="mapList"/>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QLabel" name="label_2">
<property name="text">
<string>Position attribute :</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="combo_positionAttribute">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>Normal attribute name :</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="attributeName"/>
</item>
</layout>
</item>
<item>
<widget class="QCheckBox" name="check_createVBO">
<property name="text">
<string>create VBO</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<widget class="QPushButton" name="button_cancel">
<property name="text">
<string>Cancel</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="button_apply">
<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>
</layout>
</widget>
<resources/>
<connections>
<connection>
<sender>button_ok</sender>
<signal>clicked()</signal>
<receiver>ComputeNormalsDialog</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>232</x>
<y>283</y>
</hint>
<hint type="destinationlabel">
<x>140</x>
<y>156</y>
</hint>
</hints>
</connection>
<connection>
<sender>button_cancel</sender>
<signal>clicked()</signal>
<receiver>ComputeNormalsDialog</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>52</x>
<y>283</y>
</hint>
<hint type="destinationlabel">
<x>140</x>
<y>156</y>
</hint>
</hints>
</connection>
</connections>
</ui>
#ifndef _COMPUTENORMALS_DIALOG_H_
#define _COMPUTENORMALS_DIALOG_H_
#include "ui_computeNormalsDialog.h"
namespace CGoGN
{
namespace SCHNApps
{
class Window;
class ComputeNormalsDialog : public QDialog, public Ui::ComputeNormalsDialog
{
Q_OBJECT
public:
ComputeNormalsDialog(Window* w);
void init();
public slots:
void cb_selectedMapChanged();
private:
Window* m_window;
};
} // namespace SCHNApps
} // namespace CGoGN
#endif
#ifndef _DIFFERENTIALPROPERTIES_PLUGIN_H_
#define _DIFFERENTIALPROPERTIES_PLUGIN_H_
#include "plugin.h"
#include "computeNormalsDialog.h"
#include "Topology/generic/functor.h"
#include "Topology/generic/parameters.h"
#include "Topology/map/embeddedMap2.h"
#include "Topology/generic/attributeHandler.h"
using namespace CGoGN;
using namespace SCHNApps;
struct PFP: public PFP_STANDARD
{
typedef EmbeddedMap2 MAP;
};
typedef PFP::MAP MAP;
typedef PFP::VEC3 VEC3;
class DifferentialPropertiesPlugin : public Plugin
{
Q_OBJECT
Q_INTERFACES(CGoGN::SCHNApps::Plugin)
public:
DifferentialPropertiesPlugin()
{
setProvidesRendering(false);
}
~DifferentialPropertiesPlugin()
{}
virtual bool enable();
virtual 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 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) {}
virtual void mapLinked(View* view, MapHandlerGen* m) {}
virtual void mapUnlinked(View* view, MapHandlerGen* m) {}
public slots:
void cb_openComputeNormalsDialog();
void cb_computeNormals();
private:
ComputeNormalsDialog* m_computeNormalsDialog;
QAction* computeNormalsAction;
QAction* computeCurvatureAction;
};
#endif
#include "computeNormalsDialog.h"
#include "differentialProperties.h"
#include "window.h"
#include "mapHandler.h"
namespace CGoGN
{
namespace SCHNApps
{
ComputeNormalsDialog::ComputeNormalsDialog(Window* w) : m_window(w)
{
setupUi(this);
connect(mapList, SIGNAL(itemSelectionChanged()), this, SLOT(cb_selectedMapChanged()));
}
void ComputeNormalsDialog::init()
{
mapList->clear();
combo_positionAttribute->clear();
attributeName->setText("normal");
const QList<MapHandlerGen*>& maps = m_window->getMapsList();
foreach(MapHandlerGen* map, maps)
mapList->addItem(map->getName());
}
void ComputeNormalsDialog::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 = VEC3::CGoGNnameOfType();
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 an attribute named "position"
combo_positionAttribute->setCurrentIndex(j);
++j;
}
}
}
}
} // namespace SCHNApps
} // namespace CGoGN
#include "differentialProperties.h"
#include "mapHandler.h"
#include "Algo/Geometry/normal.h"
bool DifferentialPropertiesPlugin::enable()
{
m_computeNormalsDialog = new ComputeNormalsDialog(m_window);
computeNormalsAction = new QAction("Compute Normals", this);
computeCurvatureAction = new QAction("Compute Curvature", this);
addMenuAction("Surface;Differential Properties;Compute Normals", computeNormalsAction);
addMenuAction("Surface;Differential Properties;Compute Curvature", computeCurvatureAction);
connect(computeNormalsAction, SIGNAL(triggered()), this, SLOT(cb_openComputeNormalsDialog()));
connect(computeCurvatureAction, SIGNAL(triggered()), this, SLOT(cb_openComputeNormalsDialog()));
connect(m_computeNormalsDialog, SIGNAL(accepted()), this, SLOT(cb_computeNormals()));
connect(m_computeNormalsDialog->button_apply, SIGNAL(clicked()), this, SLOT(cb_computeNormals()));
return true;
}
void DifferentialPropertiesPlugin::cb_openComputeNormalsDialog()
{
m_computeNormalsDialog->init();
m_computeNormalsDialog->show();
}
void DifferentialPropertiesPlugin::cb_computeNormals()
{
QList<QListWidgetItem*> currentItems = m_computeNormalsDialog->mapList->selectedItems();
if(!currentItems.empty())
{
const QString& mapname = currentItems[0]->text();
MapHandler<PFP>* mh = reinterpret_cast<MapHandler<PFP>*>(m_window->getMap(mapname));
MAP* map = mh->getMap();
std::string positionName = m_computeNormalsDialog->combo_positionAttribute->currentText().toUtf8().constData();
std::string normalName = m_computeNormalsDialog->attributeName->text().toUtf8().constData();
VertexAttribute<VEC3> position = map->getAttribute<VEC3, VERTEX>(positionName);
VertexAttribute<VEC3> normal = map->getAttribute<VEC3, VERTEX>(normalName);
if(!normal.isValid())
normal = map->addAttribute<VEC3, VERTEX>(normalName);
Algo::Geometry::computeNormalVertices<PFP>(*map, position, normal);
if(m_computeNormalsDialog->check_createVBO->checkState() == Qt::Checked)
mh->createVBO(normal);
QList<View*> views = m_window->getViewsList();
foreach(View* view, views)
{
if(view->isLinkedToMap(mh))
view->updateGL();
}
}
}
#ifndef DEBUG
Q_EXPORT_PLUGIN2(DifferentialPropertiesPlugin, DifferentialPropertiesPlugin)
#else
Q_EXPORT_PLUGIN2(DifferentialPropertiesPluginD, DifferentialPropertiesPlugin)
#endif
#include "import.h"
#include "system.h"
#include "mapHandler.h"
#include "Algo/Import/import.h"
#include <QFileDialog>
#include <QFileInfo>
bool ImportPlugin::enable()
{
importAction = new QAction("import", this);
addMenuAction("Import;import", importAction);
connect(importAction, SIGNAL(triggered()), this, SLOT(cb_import()));
return true;
}
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>(fi.baseName(), m_window, m);
std::vector<std::string> attrNames ;
Algo::Import::importMesh<PFP>(*m, fileName.toUtf8().constData(), attrNames);
// get vertex position attribute
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);
// 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);
// 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);
}
/**
* 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(ImportPlugin, ImportPlugin)
#else
Q_EXPORT_PLUGIN2(ImportPluginD, ImportPlugin)
#endif
......@@ -2,16 +2,16 @@ cmake_minimum_required(VERSION 2.8)
INCLUDE_DIRECTORIES(
${SCHNApps_ROOT_DIR}/include
${SCHNApps_ROOT_DIR}/Plugins/import
${SCHNApps_ROOT_DIR}/Plugins/importSurface
${CMAKE_CURRENT_BINARY_DIR}
)
SET( PLUGIN_SRC
${SCHNApps_ROOT_DIR}/Plugins/import/import.cpp
${SCHNApps_ROOT_DIR}/Plugins/importSurface/importSurface.cpp
)
SET( PLUGIN_H
${SCHNApps_ROOT_DIR}/Plugins/import/import.h
${SCHNApps_ROOT_DIR}/Plugins/importSurface/importSurface.h
)
IF( ${CMAKE_BUILD_TYPE} STREQUAL Debug )
......@@ -27,21 +27,21 @@ IF( ${CMAKE_BUILD_TYPE} STREQUAL Debug )
# QT4_WRAP_UI( PLUGIN_UI ${PLUGIN_FORM} )
QT4_WRAP_CPP( PLUGIN_MOC ${PLUGIN_H} )
ADD_LIBRARY( ImportPluginD SHARED
ADD_LIBRARY( ImportSurfacePluginD SHARED
${PLUGIN_SRC}
${PLUGIN_UI}
${PLUGIN_MOC}
)
TARGET_LINK_LIBRARIES( ImportPluginD
TARGET_LINK_LIBRARIES( ImportSurfacePluginD
${CGoGN_LIBS_D}
${COMMON_LIBS}
${QGLVIEWER_LIBRARIES}
)
ADD_DEPENDENCIES( ImportPluginD SCHNAppsD )
ADD_DEPENDENCIES( ImportSurfacePluginD SCHNAppsD )
SET_TARGET_PROPERTIES( ImportPluginD PROPERTIES COMPILE_DEFINITIONS "DEBUG" )
SET_TARGET_PROPERTIES( ImportSurfacePluginD PROPERTIES COMPILE_DEFINITIONS "DEBUG" )
ELSE ( ${CMAKE_BUILD_TYPE} STREQUAL Debug )
......@@ -54,18 +54,18 @@ ELSE ( ${CMAKE_BUILD_TYPE} STREQUAL Debug )
# QT4_WRAP_UI( PLUGIN_UI ${PLUGIN_FORM} )
QT4_WRAP_CPP( PLUGIN_MOC ${PLUGIN_H} )
ADD_LIBRARY( ImportPlugin SHARED
ADD_LIBRARY( ImportSurfacePlugin SHARED
${PLUGIN_SRC}
${PLUGIN_UI}
${PLUGIN_MOC}
)
TARGET_LINK_LIBRARIES( ImportPlugin
TARGET_LINK_LIBRARIES( ImportSurfacePlugin
${CGoGN_LIBS_R}
${COMMON_LIBS}
${QGLVIEWER_LIBRARIES}
)
ADD_DEPENDENCIES( ImportPlugin SCHNApps )
ADD_DEPENDENCIES( ImportSurfacePlugin SCHNApps )
ENDIF ( ${CMAKE_BUILD_TYPE} STREQUAL Debug )
#include "importSurface.h"
#include "mapHandler.h"
#include "Algo/Import/import.h"
#include <QFileDialog>
#include <QFileInfo>
bool ImportSurfacePlugin::enable()
{
importAction = new QAction("import", this);
addMenuAction("Surface;Import", importAction);
connect(importAction, SIGNAL(triggered()), this, SLOT(cb_import()));
return true;
}
void ImportSurfacePlugin::cb_import()
{
QString fileName = QFileDialog::getOpenFileName(m_window, "Import file", m_window->getAppPath(), "Mesh Files (*.ply *.off)");
QFileInfo fi(fileName);
if(fi.exists())
{
MAP* m = new MAP();
MapHandler<PFP>* h = new MapHandler<PFP>(fi.baseName(), m_window, m);
std::vector<std::string> attrNames ;
Algo::Import::importMesh<PFP>(*m, fileName.toUtf8().constData(), attrNames);
// get vertex position attribute
VertexAttribute<VEC3> position = m->getAttribute<VEC3, CGoGN::VERTEX>(attrNames[0]);
// create VBO for vertex position attribute
h->createVBO(position);
// compute map bounding box