Commit d19cc06a authored by Pierre Kraemer's avatar Pierre Kraemer

add dialog to compute distances in Surface_Radiance plugin + bug fix in...

add dialog to compute distances in Surface_Radiance plugin + bug fix in bounding box update in Surface_Render plugin
parent 34e88583
......@@ -903,7 +903,7 @@ unsigned int Map2<MAP_IMPL>::volumeDegree(Vol v) const
{
mark.mark(it); // Mark
Dart adj = phi2(it); // Get adjacent face
if ( !this->isBoundaryMarked<2>(adj) && !mark.isMarked(adj) )
if ( !this->template isBoundaryMarked<2>(adj) && !mark.isMarked(adj) )
visitedFaces.push_back(adj);// Add it
it = this->phi1(it);
} while(it != df);
......
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Dialog_ComputeRadianceDistance</class>
<widget class="QDialog" name="Dialog_ComputeRadianceDistance">
<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_ComputeRadianceDistance</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_ComputeRadianceDistance</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 _SURFACE_RADIANCE_DIALOG_COMPUTEDISTANCE_H_
#define _SURFACE_RADIANCE_DIALOG_COMPUTEDISTANCE_H_
#include "ui_dialog_computeRadianceDistance.h"
namespace CGoGN
{
namespace SCHNApps
{
class SCHNApps;
class MapHandlerGen;
class Dialog_ComputeRadianceDistance : public QDialog, public Ui::Dialog_ComputeRadianceDistance
{
Q_OBJECT
public:
Dialog_ComputeRadianceDistance(SCHNApps* s);
private:
SCHNApps* m_schnapps;
MapHandlerGen* m_selectedMap1;
MapHandlerGen* m_selectedMap2;
private 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 // _SURFACE_RADIANCE_DIALOG_COMPUTEDISTANCE_H_
#include "dialog_computeRadianceDistance.h"
#include "surface_radiance.h"
#include "schnapps.h"
#include "mapHandler.h"
namespace CGoGN
{
namespace SCHNApps
{
Dialog_ComputeRadianceDistance::Dialog_ComputeRadianceDistance(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())
{
list_maps_1->addItem(map->getName());
list_maps_2->addItem(map->getName());
}
}
void Dialog_ComputeRadianceDistance::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_ComputeRadianceDistance::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_ComputeRadianceDistance::addMapToList(MapHandlerGen* map)
{
list_maps_1->addItem(map->getName());
list_maps_2->addItem(map->getName());
}
void Dialog_ComputeRadianceDistance::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_ComputeRadianceDistance::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_ComputeRadianceDistance::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
......@@ -519,8 +519,12 @@ void Surface_Radiance_Plugin::computeRadianceDistance(
// for each vertex of map1
unsigned int nbVertices = 0;
unsigned int nbVerticesWithDistanceDeviation = 0;
for (Vertex v : allVerticesOf(*map1))
{
nbVertices++;
const PFP2::VEC3& P = position1[v];
// find closest point on map2
......@@ -553,26 +557,31 @@ void Surface_Radiance_Plugin::computeRadianceDistance(
}
}
minDist = sqrt(minDist);
double l1, l2, l3;
Algo::Geometry::closestPointInTriangle<PFP2>(*map2, closestFace, position2, P, l1, l2, l3);
const PFP2::VEC3& P1 = position2[closestFace.dart];
const PFP2::VEC3& P2 = position2[map2->phi1(closestFace.dart)];
const PFP2::VEC3& P3 = position2[map2->phi_1(closestFace.dart)];
PFP2::VEC3 closestPoint = l1*P1 + l2*P2 + l3*P3;
minDist = sqrt(minDist);
PFP2::VEC3 vect = closestPoint - P;
PFP2::REAL dist = vect.norm();
if (fabs(dist - minDist) > 0.001)
{
std::cout << "l1 -> " << l1 << " / l2 -> " << l2 << " / l3 -> " << l3 << std::endl;
std::cout << "diff -> " << fabs(dist - minDist) << std::endl;
nbVerticesWithDistanceDeviation++;
// std::cout << "l1 -> " << l1 << " / l2 -> " << l2 << " / l3 -> " << l3 << std::endl;
// std::cout << "diff -> " << fabs(dist - minDist) << std::endl;
}
distance1[v] = minDist;
}
std::cout << "nbVertices => " << nbVertices << std::endl;
std::cout << "nbVertices with closest point deviation > 0.001 => " << nbVerticesWithDistanceDeviation << std::endl;
this->pythonRecording("computeRadianceDistance", "", mapName1, positionAttributeName1, distanceAttributeName1,
mapName2, positionAttributeName2, distanceAttributeName2);
......
......@@ -114,7 +114,7 @@ private slots:
// slots called from MapHandler signals
void vboAdded(Utils::VBO* vbo);
void vboRemoved(Utils::VBO* vbo);
void selectedMapBoundingBoxModified();
void boundingBoxModified();
void schnappsClosing();
......
......@@ -153,13 +153,6 @@ void Surface_Render_Plugin::selectedViewChanged(View *prev, View *cur)
void Surface_Render_Plugin::selectedMapChanged(MapHandlerGen *prev, MapHandlerGen *cur)
{
DEBUG_SLOT();
if (prev)
disconnect(prev, SIGNAL(boundingBoxModified()), this, SLOT(selectedMapBoundingBoxModified()));
if (cur)
connect(cur, SIGNAL(boundingBoxModified()), this, SLOT(selectedMapBoundingBoxModified()));
m_dockTab->updateMapParameters();
}
......@@ -168,7 +161,7 @@ void Surface_Render_Plugin::mapAdded(MapHandlerGen *map)
DEBUG_SLOT();
connect(map, SIGNAL(vboAdded(Utils::VBO*)), this, SLOT(vboAdded(Utils::VBO*)));
connect(map, SIGNAL(vboRemoved(Utils::VBO*)), this, SLOT(vboRemoved(Utils::VBO*)));
connect(map, SIGNAL(boundingBoxModified()), this, SLOT(selectedMapBoundingBoxModified()));
connect(map, SIGNAL(boundingBoxModified()), this, SLOT(boundingBoxModified()));
}
void Surface_Render_Plugin::mapRemoved(MapHandlerGen *map)
......@@ -176,7 +169,7 @@ void Surface_Render_Plugin::mapRemoved(MapHandlerGen *map)
DEBUG_SLOT();
disconnect(map, SIGNAL(vboAdded(Utils::VBO*)), this, SLOT(vboAdded(Utils::VBO*)));
disconnect(map, SIGNAL(vboRemoved(Utils::VBO*)), this, SLOT(vboRemoved(Utils::VBO*)));
disconnect(map, SIGNAL(boundingBoxModified()), this, SLOT(selectedMapBoundingBoxModified()));
disconnect(map, SIGNAL(boundingBoxModified()), this, SLOT(boundingBoxModified()));
if(map == m_schnapps->getSelectedMap())
m_dockTab->updateMapParameters();
......@@ -246,22 +239,19 @@ void Surface_Render_Plugin::vboRemoved(Utils::VBO *vbo)
v->updateGL();
}
void Surface_Render_Plugin::selectedMapBoundingBoxModified()
void Surface_Render_Plugin::boundingBoxModified()
{
MapHandlerGen* m = m_schnapps->getSelectedMap();
DEBUG_SLOT();
MapHandlerGen* map = static_cast<MapHandlerGen*>(QObject::sender());
QList<View*> views = m->getLinkedViews();
if (m)
foreach(View* v, views)
{
if (h_viewParameterSet.contains(v))
h_viewParameterSet[v][m].basePSradius = m->getBBdiagSize() / (2 * std::sqrt(m->getNbOrbits(EDGE)));
}
QList<View*> views = map->getLinkedViews();
foreach(View* v, views)
{
if (h_viewParameterSet.contains(v))
h_viewParameterSet[v][map].basePSradius = map->getBBdiagSize() / (2 * std::sqrt(map->getNbOrbits(EDGE)));
}
}
void Surface_Render_Plugin::changePositionVBO(const QString& view, const QString& map, const QString& vbo)
{
DEBUG_SLOT();
......
......@@ -129,6 +129,9 @@ void ControlDock_MapTab::selectedMapChanged()
connect(m_selectedMap, SIGNAL(vboRemoved(Utils::VBO*)), this, SLOT(selectedMapVBORemoved(Utils::VBO*)));
connect(m_selectedMap, SIGNAL(cellSelectorAdded(unsigned int, const QString&)), this, SLOT(selectedMapCellSelectorAdded(unsigned int, const QString&)));
connect(m_selectedMap, SIGNAL(cellSelectorRemoved(unsigned int, const QString&)), this, SLOT(selectedMapCellSelectorRemoved(unsigned int, const QString&)));
for(unsigned int i = 0; i < NB_ORBITS; ++i)
m_selectedSelector[i] = NULL;
}
else
m_selectedMap = NULL;
......
......@@ -118,7 +118,6 @@ void MapHandlerGen::setBBColor(const QString& color)
updateBB();
}
void MapHandlerGen::setBBVertexAttribute(const QString& name)
{
m_bbVertexAttribute = m_map->getAttributeVectorGen(VERTEX, name.toStdString());
......@@ -129,7 +128,6 @@ void MapHandlerGen::setBBVertexAttribute(const QString& name)
m_schnapps->setSelectedMap("NONE");
m_schnapps->setSelectedMap(this->getName());
}
}
AttributeMultiVectorGen* MapHandlerGen::getBBVertexAttribute() const
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment