Commit 9f2c7763 authored by Pierre Kraemer's avatar Pierre Kraemer

Merge branch 'develop' into 'develop'

Develop

See merge request !32
parents 679b508c a0619054
......@@ -11,6 +11,7 @@ ADD_SUBDIRECTORY(surface_selection)
ADD_SUBDIRECTORY(surface_deformation)
ADD_SUBDIRECTORY(surface_modelisation)
#ADD_SUBDIRECTORY(surface_tilings)
ADD_SUBDIRECTORY(surface_distance)
ADD_SUBDIRECTORY(volume_import)
#ADD_SUBDIRECTORY(volume_render)
cmake_minimum_required(VERSION 2.8)
SET( PLUGIN_NAME Surface_Distance )
SET( PLUGIN_ROOT_DIR ${SCHNApps_ROOT_DIR}/Plugins/surface_distance )
INCLUDE_DIRECTORIES(
${PLUGIN_ROOT_DIR}/include
${CMAKE_CURRENT_BINARY_DIR}
)
file(
GLOB_RECURSE
PLUGIN_FILES
${PLUGIN_ROOT_DIR}/src/*.cpp
${PLUGIN_ROOT_DIR}/include/*.h
${PLUGIN_ROOT_DIR}/include/*.hpp
)
file(
GLOB_RECURSE
PLUGIN_UI_FILES
${PLUGIN_ROOT_DIR}/forms/*.ui
)
SET(
PLUGIN_QOBJECT_FILES
${PLUGIN_ROOT_DIR}/include/surface_distance.h
${PLUGIN_ROOT_DIR}/include/dialog_computeDistance.h
)
include( ${SCHNApps_ROOT_DIR}/Plugins/plugins_cmake.txt )
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Dialog_ComputeDistance</class>
<widget class="QDialog" name="Dialog_ComputeDistance">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>607</width>
<height>359</height>
</rect>
</property>
<property name="windowTitle">
<string>Compute Distance</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_5">
<item>
<layout class="QHBoxLayout" name="horizontalLayout_8">
<item>
<layout class="QVBoxLayout" name="verticalLayout_3">
<item>
<widget class="QListWidget" name="list_maps_1"/>
</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_1">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QGroupBox" name="groupBox">
<property name="title">
<string>Distance attribute</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLabel" name="label_3">
<property name="text">
<string>Existing attribute :</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="combo_distanceAttribute_1">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_5">
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>New attribute :</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="distanceAttributeName_1"/>
</item>
</layout>
</item>
</layout>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QVBoxLayout" name="verticalLayout_4">
<item>
<widget class="QListWidget" name="list_maps_2"/>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_4">
<item>
<widget class="QLabel" name="label_4">
<property name="text">
<string>Position attribute :</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="combo_positionAttribute_2">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QGroupBox" name="groupBox_2">
<property name="title">
<string>Distance attribute</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<layout class="QHBoxLayout" name="horizontalLayout_6">
<item>
<widget class="QLabel" name="label_5">
<property name="text">
<string>Existing attribute :</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="combo_distanceAttribute_2">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_7">
<item>
<widget class="QLabel" name="label_6">
<property name="text">
<string>New attribute :</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="distanceAttributeName_2"/>
</item>
</layout>
</item>
</layout>
</widget>
</item>
</layout>
</item>
</layout>
</item>
<item>
<widget class="QCheckBox" name="enableVBO">
<property name="text">
<string>Create VBOs</string>
</property>
<property name="checked">
<bool>false</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>Dialog_ComputeDistance</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>Dialog_ComputeDistance</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 _DIALOG_COMPUTEDISTANCE_H_
#define _DIALOG_COMPUTEDISTANCE_H_
#include "ui_dialog_computeDistance.h"
namespace CGoGN
{
namespace SCHNApps
{
class SCHNApps;
class MapHandlerGen;
class Dialog_ComputeDistance : public QDialog, public Ui::Dialog_ComputeDistance
{
Q_OBJECT
public:
Dialog_ComputeDistance(SCHNApps* s);
private:
SCHNApps* m_schnapps;
MapHandlerGen* m_selectedMap1;
MapHandlerGen* m_selectedMap2;
public slots:
void selectedMap1Changed();
void selectedMap2Changed();
void addMapToList(MapHandlerGen* map);
void removeMapFromList(MapHandlerGen* map);
void addAttributeToList1(unsigned int orbit, const QString& nameAttr);
void addAttributeToList2(unsigned int orbit, const QString& nameAttr);
};
} // namespace SCHNApps
} // namespace CGoGN
#endif
#ifndef _SURFACE_DISTANCE_PLUGIN_H_
#define _SURFACE_DISTANCE_PLUGIN_H_
#include "plugin_processing.h"
#include "dialog_computeDistance.h"
namespace CGoGN
{
namespace SCHNApps
{
class Surface_Distance_Plugin : public PluginProcessing
{
Q_OBJECT
Q_INTERFACES(CGoGN::SCHNApps::Plugin)
public:
Surface_Distance_Plugin()
{}
~Surface_Distance_Plugin()
{}
virtual bool enable();
virtual void disable();
private slots:
void openComputeDistanceDialog();
void computeDistanceFromDialog();
void appsFinished();
public slots:
void computeDistance(
const QString& mapName1,
const QString& positionAttributeName1,
const QString& distanceAttributeName1,
const QString& mapName2,
const QString& positionAttributeName2,
const QString& distanceAttributeName2
);
private:
Dialog_ComputeDistance* m_computeDistanceDialog;
QAction* m_computeDistanceAction;
};
} // namespace SCHNApps
} // namespace CGoGN
#endif
#include "dialog_computeDistance.h"
#include "surface_distance.h"
#include "schnapps.h"
#include "mapHandler.h"
namespace CGoGN
{
namespace SCHNApps
{
Dialog_ComputeDistance::Dialog_ComputeDistance(SCHNApps* s) :
m_schnapps(s),
m_selectedMap1(NULL),
m_selectedMap2(NULL)
{
setupUi(this);
distanceAttributeName_1->setText("distance");
distanceAttributeName_2->setText("distance");
connect(m_schnapps, SIGNAL(mapAdded(MapHandlerGen*)), this, SLOT(addMapToList(MapHandlerGen*)));
connect(m_schnapps, SIGNAL(mapRemoved(MapHandlerGen*)), this, SLOT(removeMapFromList(MapHandlerGen*)));
connect(list_maps_1, SIGNAL(itemSelectionChanged()), this, SLOT(selectedMap1Changed()));
connect(list_maps_2, SIGNAL(itemSelectionChanged()), this, SLOT(selectedMap2Changed()));
foreach(MapHandlerGen* map, m_schnapps->getMapSet().values())
{
QListWidgetItem* item1 = new QListWidgetItem(map->getName(), list_maps_1);
QListWidgetItem* item2 = new QListWidgetItem(map->getName(), list_maps_2);
}
}
void Dialog_ComputeDistance::selectedMap1Changed()
{
if(m_selectedMap1)
disconnect(m_selectedMap1, SIGNAL(attributeAdded(unsigned int, const QString&)), this, SLOT(addAttributeToList1(unsigned int, const QString&)));
QList<QListWidgetItem*> currentItems = list_maps_1->selectedItems();
if(!currentItems.empty())
{
combo_positionAttribute_1->clear();
combo_distanceAttribute_1->clear();
const QString& mapname = currentItems[0]->text();
MapHandlerGen* mh = m_schnapps->getMap(mapname);
QString vec3TypeName = QString::fromStdString(nameOfType(PFP2::VEC3()));
QString realTypeName = QString::fromStdString(nameOfType(PFP2::REAL()));
const AttributeSet& attribs = mh->getAttributeSet(VERTEX);
for(AttributeSet::const_iterator i = attribs.constBegin(); i != attribs.constEnd(); ++i)
{
if(i.value() == vec3TypeName)
{
combo_positionAttribute_1->addItem(i.key());
}
if(i.value() == realTypeName)
{
combo_distanceAttribute_1->addItem(i.key());
}
}
m_selectedMap1 = mh;
connect(m_selectedMap1, SIGNAL(attributeAdded(unsigned int, const QString&)), this, SLOT(addAttributeToList1(unsigned int, const QString&)));
}
else
m_selectedMap1 = NULL;
}
void Dialog_ComputeDistance::selectedMap2Changed()
{
if(m_selectedMap2)
disconnect(m_selectedMap2, SIGNAL(attributeAdded(unsigned int, const QString&)), this, SLOT(addAttributeToList2(unsigned int, const QString&)));
QList<QListWidgetItem*> currentItems = list_maps_2->selectedItems();
if(!currentItems.empty())
{
combo_positionAttribute_2->clear();
combo_distanceAttribute_2->clear();
const QString& mapname = currentItems[0]->text();
MapHandlerGen* mh = m_schnapps->getMap(mapname);
QString vec3TypeName = QString::fromStdString(nameOfType(PFP2::VEC3()));
QString realTypeName = QString::fromStdString(nameOfType(PFP2::REAL()));
const AttributeSet& attribs = mh->getAttributeSet(VERTEX);
for(AttributeSet::const_iterator i = attribs.constBegin(); i != attribs.constEnd(); ++i)
{
if(i.value() == vec3TypeName)
{
combo_positionAttribute_2->addItem(i.key());
}
if(i.value() == realTypeName)
{
combo_distanceAttribute_2->addItem(i.key());
}
}
m_selectedMap2 = mh;
connect(m_selectedMap2, SIGNAL(attributeAdded(unsigned int, const QString&)), this, SLOT(addAttributeToList2(unsigned int, const QString&)));
}
else
m_selectedMap2 = NULL;
}
void Dialog_ComputeDistance::addMapToList(MapHandlerGen* map)
{
QListWidgetItem* item1 = new QListWidgetItem(map->getName(), list_maps_1);
QListWidgetItem* item2 = new QListWidgetItem(map->getName(), list_maps_2);
}
void Dialog_ComputeDistance::removeMapFromList(MapHandlerGen* map)
{
QList<QListWidgetItem*> items1 = list_maps_1->findItems(map->getName(), Qt::MatchExactly);
if(!items1.empty())
delete items1[0];
QList<QListWidgetItem*> items2 = list_maps_2->findItems(map->getName(), Qt::MatchExactly);
if(!items2.empty())
delete items2[0];
if(m_selectedMap1 == map)
{
disconnect(m_selectedMap1, SIGNAL(attributeAdded(unsigned int, const QString&)), this, SLOT(addAttributeToList1(unsigned int, const QString&)));
m_selectedMap1 = NULL;
}
if(m_selectedMap2 == map)
{
disconnect(m_selectedMap2, SIGNAL(attributeAdded(unsigned int, const QString&)), this, SLOT(addAttributeToList2(unsigned int, const QString&)));
m_selectedMap2 = NULL;
}
}
void Dialog_ComputeDistance::addAttributeToList1(unsigned int orbit, const QString& nameAttr)
{
if(orbit == VERTEX)
{
QString vec3TypeName = QString::fromStdString(nameOfType(PFP2::VEC3()));
QString realTypeName = QString::fromStdString(nameOfType(PFP2::REAL()));
const QString& typeAttr = m_selectedMap1->getAttributeTypeName(orbit, nameAttr);
if(typeAttr == vec3TypeName)
{
combo_positionAttribute_1->addItem(nameAttr);
}
if(typeAttr == realTypeName)
{
combo_distanceAttribute_1->addItem(nameAttr);
}
}
}
void Dialog_ComputeDistance::addAttributeToList2(unsigned int orbit, const QString& nameAttr)
{
if(orbit == VERTEX)
{
QString vec3TypeName = QString::fromStdString(nameOfType(PFP2::VEC3()));
QString realTypeName = QString::fromStdString(nameOfType(PFP2::REAL()));
const QString& typeAttr = m_selectedMap2->getAttributeTypeName(orbit, nameAttr);
if(typeAttr == vec3TypeName)
{
combo_positionAttribute_2->addItem(nameAttr);
}
if(typeAttr == realTypeName)
{
combo_distanceAttribute_2->addItem(nameAttr);
}
}
}
} // namespace SCHNApps
} // namespace CGoGN
#include "surface_distance.h"
#include "mapHandler.h"
#include "Algo/Geometry/distances.h"
namespace CGoGN
{
namespace SCHNApps
{
bool Surface_Distance_Plugin::enable()
{
// magic line that init static variables of GenericMap in the plugins
GenericMap::copyAllStatics(m_schnapps->getStaticPointers());
m_computeDistanceDialog = new Dialog_ComputeDistance(m_schnapps);
m_computeDistanceAction = new QAction("Compute Distance", this);
m_schnapps->addMenuAction(this, "Surface;Compute Distance", m_computeDistanceAction);
connect(m_computeDistanceAction, SIGNAL(triggered()), this, SLOT(openComputeDistanceDialog()));
connect(m_computeDistanceDialog, SIGNAL(accepted()), this, SLOT(computeDistanceFromDialog()));
connect(m_computeDistanceDialog->button_apply, SIGNAL(clicked()), this, SLOT(computeDistanceFromDialog()));
connect(m_schnapps, SIGNAL(appsFinished()), this, SLOT(appsFinished()));
return true;
}
void Surface_Distance_Plugin::disable()
{
disconnect(m_computeDistanceAction, SIGNAL(triggered()), this, SLOT(openComputeNormalDialog()));
disconnect(m_computeDistanceDialog, SIGNAL(accepted()), this, SLOT(computeDistanceFromDialog()));
disconnect(m_computeDistanceDialog->button_apply, SIGNAL(clicked()), this, SLOT(computeDistanceFromDialog()));
disconnect(m_schnapps, SIGNAL(appsFinished()), this, SLOT(appsFinished()));
}
void Surface_Distance_Plugin::openComputeDistanceDialog()
{
m_computeDistanceDialog->show();
}
void Surface_Distance_Plugin::computeDistanceFromDialog()
{
QList<QListWidgetItem*> currentItems1 = m_computeDistanceDialog->list_maps_1->selectedItems();
QList<QListWidgetItem*> currentItems2 = m_computeDistanceDialog->list_maps_2->selectedItems();
if(!currentItems1.empty() && !currentItems2.empty())
{
const QString& mapName1 = currentItems1[0]->text();
const QString& mapName2 = currentItems2[0]->text();
QString positionName1 = m_computeDistanceDialog->combo_positionAttribute_1->currentText();
QString positionName2 = m_computeDistanceDialog->combo_positionAttribute_2->currentText();
QString distanceName1;
if(m_computeDistanceDialog->distanceAttributeName_1->text().isEmpty())
distanceName1 = m_computeDistanceDialog->combo_distanceAttribute_1->currentText();
else
distanceName1 = m_computeDistanceDialog->distanceAttributeName_1->text();
QString distanceName2;
if(m_computeDistanceDialog->distanceAttributeName_2->text().isEmpty())
distanceName2 = m_computeDistanceDialog->combo_distanceAttribute_2->currentText();
else
distanceName2 = m_computeDistanceDialog->distanceAttributeName_2->text();
// create VBO if asked
if (m_computeDistanceDialog->enableVBO->isChecked())
{
MapHandlerGen* mhg1 = getSCHNApps()->getMap(mapName1);
if (mhg1)
mhg1->createVBO(distanceName1);
MapHandlerGen* mhg2 = getSCHNApps()->getMap(mapName2);
if (mhg2)
mhg2->createVBO(distanceName2);
}
computeDistance(mapName1, positionName1, distanceName1, mapName2, positionName2, distanceName2);
}
}
void Surface_Distance_Plugin::computeDistance(
const QString& mapName1,
const QString& positionAttributeName1,
const QString& distanceAttributeName1,
const QString& mapName2,
const QString& positionAttributeName2,
const QString& distanceAttributeName2)
{
MapHandler<PFP2>* mh1 = static_cast<MapHandler<PFP2>*>(m_schnapps->getMap(mapName1));
if(mh1 == NULL)
return;
MapHandler<PFP2>* mh2 = static_cast<MapHandler<PFP2>*>(m_schnapps->getMap(mapName2));
if(mh2 == NULL)
return;
VertexAttribute<PFP2::VEC3, PFP2::MAP> position1 = mh1->getAttribute<PFP2::VEC3, VERTEX>(positionAttributeName1);
if(!position1.isValid())
return;
VertexAttribute<PFP2::VEC3, PFP2::MAP> position2 = mh2->getAttribute<PFP2::VEC3, VERTEX>(positionAttributeName2);
if(!position2.isValid())
return;
VertexAttribute<PFP2::REAL, PFP2::MAP> distance1 = mh1->getAttribute<PFP2::REAL, VERTEX>(distanceAttributeName1);
if(!distance1.isValid())
distance1 = mh1->addAttribute<PFP2::REAL, VERTEX>(distanceAttributeName1);
VertexAttribute<PFP2::REAL, PFP2::MAP> distance2 = mh2->getAttribute<PFP2::REAL, VERTEX>(distanceAttributeName2);
if(!distance2.isValid())
distance2 = mh2->addAttribute<PFP2::REAL, VERTEX>(distanceAttributeName2);
PFP2::MAP* map1 = mh1->getMap();
PFP2::MAP* map2 = mh2->getMap();
// compute distance between map1 and map2 here
// distance from map1 to map2 can be stored in map1 vertex attribute distance1
// distance from map2 to map1 can be stored in map2 vertex attribute distance2
// Algo::Geometry::computeDistance<PFP2>(map1, position1, distance1, map2, position2);
// Algo::Geometry::computeDistance<PFP2>(map2, position2, distance2, map1, position1);
mh1->notifyAttributeModification(distance1);
mh2->notifyAttributeModification(distance2);
}
void Surface_Distance_Plugin::appsFinished()
{
m_computeDistanceDialog->close();
}
Q_EXPORT_PLUGIN2(Surface_Distance_Plugin, Surface_Distance_Plugin)