computeCurvatureDialog.cpp 4.69 KB
Newer Older
Pierre Kraemer's avatar
Pierre Kraemer committed
1 2 3 4 5 6 7 8 9 10 11 12
#include "computeCurvatureDialog.h"

#include "differentialProperties.h"
#include "window.h"
#include "mapHandler.h"

namespace CGoGN
{

namespace SCHNApps
{

13 14 15
ComputeCurvatureDialog::ComputeCurvatureDialog(Window* w) :
	m_window(w),
	m_selectedMap(NULL)
Pierre Kraemer's avatar
Pierre Kraemer committed
16 17 18 19 20 21 22 23
{
	setupUi(this);

	KmaxAttributeName->setText("Kmax");
	kmaxAttributeName->setText("kmax");
	KminAttributeName->setText("Kmin");
	kminAttributeName->setText("kmin");
	KnormalAttributeName->setText("Knormal");
24 25 26 27

	connect(m_window, SIGNAL(mapAdded(MapHandlerGen*)), this, SLOT(addMapToList(MapHandlerGen*)));
	connect(m_window, SIGNAL(mapRemoved(MapHandlerGen*)), this, SLOT(removeMapFromList(MapHandlerGen*)));

28
	connect(mapList, SIGNAL(itemSelectionChanged()), this, SLOT(selectedMapChanged()));
29

Pierre Kraemer's avatar
Pierre Kraemer committed
30 31
	const QList<MapHandlerGen*>& maps = m_window->getMapsList();
	foreach(MapHandlerGen* map, maps)
Pierre Kraemer's avatar
Pierre Kraemer committed
32 33 34 35
	{
		QListWidgetItem* item = new QListWidgetItem(map->getName(), mapList);
		item->setCheckState(Qt::Unchecked);
	}
Pierre Kraemer's avatar
Pierre Kraemer committed
36 37
}

38
void ComputeCurvatureDialog::selectedMapChanged()
Pierre Kraemer's avatar
Pierre Kraemer committed
39
{
40
	if(m_selectedMap)
41
		disconnect(m_selectedMap, SIGNAL(attributeAdded(unsigned int, const QString&)), this, SLOT(addAttributeToList(unsigned int, const QString&)));
42

Pierre Kraemer's avatar
Pierre Kraemer committed
43 44 45 46 47
	QList<QListWidgetItem*> currentItems = mapList->selectedItems();
	if(!currentItems.empty())
	{
		combo_positionAttribute->clear();
		combo_normalAttribute->clear();
48 49 50 51 52
		combo_KmaxAttribute->clear();
		combo_KminAttribute->clear();
		combo_KnormalAttribute->clear();
		combo_kmaxAttribute->clear();
		combo_kminAttribute->clear();
53

Pierre Kraemer's avatar
Pierre Kraemer committed
54 55
		const QString& mapname = currentItems[0]->text();
		MapHandlerGen* mh = m_window->getMap(mapname);
56 57 58 59

		QString vec3TypeName = QString::fromStdString(nameOfType(PFP2::VEC3()));
		QString realTypeName = QString::fromStdString(nameOfType(PFP2::REAL()));

Pierre Kraemer's avatar
Pierre Kraemer committed
60 61
		unsigned int j = 0;
		unsigned int k = 0;
62 63
		const AttributeHash& attribs = mh->getAttributesList(VERTEX);
		for(AttributeHash::const_iterator i = attribs.constBegin(); i != attribs.constEnd(); ++i)
Pierre Kraemer's avatar
Pierre Kraemer committed
64
		{
65
			if(i.value() == vec3TypeName)
Pierre Kraemer's avatar
Pierre Kraemer committed
66
			{
67 68
				combo_positionAttribute->addItem(i.key());
				if(i.key() == "position") // try to select a position attribute named "position"
Pierre Kraemer's avatar
Pierre Kraemer committed
69 70
					combo_positionAttribute->setCurrentIndex(j);

71 72
				combo_normalAttribute->addItem(i.key());
				if(i.key() == "normal") // try to select a normal attribute named "normal"
Pierre Kraemer's avatar
Pierre Kraemer committed
73 74
					combo_normalAttribute->setCurrentIndex(j);

75 76
				combo_KmaxAttribute->addItem(i.key());
				if(i.key() == "Kmax") // try to select a normal attribute named "Kmax"
Pierre Kraemer's avatar
Pierre Kraemer committed
77 78
					combo_KmaxAttribute->setCurrentIndex(j);

79 80
				combo_KminAttribute->addItem(i.key());
				if(i.key() == "Kmin") // try to select a normal attribute named "Kmin"
Pierre Kraemer's avatar
Pierre Kraemer committed
81 82
					combo_KminAttribute->setCurrentIndex(j);

83 84
				combo_KnormalAttribute->addItem(i.key());
				if(i.key() == "Knormal") // try to select a normal attribute named "Knormal"
Pierre Kraemer's avatar
Pierre Kraemer committed
85 86 87 88
					combo_KnormalAttribute->setCurrentIndex(j);

				++j;
			}
89
			else if(i.value() == realTypeName)
Pierre Kraemer's avatar
Pierre Kraemer committed
90
			{
91 92
				combo_kmaxAttribute->addItem(i.key());
				if(i.key() == "kmax") // try to select a normal attribute named "kmax"
Pierre Kraemer's avatar
Pierre Kraemer committed
93 94
					combo_kmaxAttribute->setCurrentIndex(k);

95 96
				combo_kminAttribute->addItem(i.key());
				if(i.key() == "kmin") // try to select a normal attribute named "kmin"
Pierre Kraemer's avatar
Pierre Kraemer committed
97 98 99 100 101
					combo_kminAttribute->setCurrentIndex(k);

				++k;
			}
		}
102 103

		m_selectedMap = mh;
104
		connect(m_selectedMap, SIGNAL(attributeAdded(unsigned int, const QString&)), this, SLOT(addAttributeToList(unsigned int, const QString&)));
Pierre Kraemer's avatar
Pierre Kraemer committed
105
	}
106 107
	else
		m_selectedMap = NULL;
Pierre Kraemer's avatar
Pierre Kraemer committed
108 109
}

110 111
void ComputeCurvatureDialog::addMapToList(MapHandlerGen* m)
{
Pierre Kraemer's avatar
Pierre Kraemer committed
112 113
	QListWidgetItem* item = new QListWidgetItem(m->getName(), mapList);
	item->setCheckState(Qt::Unchecked);
114 115 116 117
}

void ComputeCurvatureDialog::removeMapFromList(MapHandlerGen* m)
{
118 119 120 121 122
	QList<QListWidgetItem*> items = mapList->findItems(m->getName(), Qt::MatchExactly);
	if(!items.empty())
		delete items[0];

	if(m_selectedMap == m)
123
	{
124
		disconnect(m_selectedMap, SIGNAL(attributeAdded(unsigned int, const QString&)), this, SLOT(addAttributeToList(unsigned int, const QString&)));
125
		m_selectedMap = NULL;
126 127 128
	}
}

129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150
void ComputeCurvatureDialog::addAttributeToList(unsigned int orbit, const QString& nameAttr)
{
	QString vec3TypeName = QString::fromStdString(nameOfType(PFP2::VEC3()));
	QString realTypeName = QString::fromStdString(nameOfType(PFP2::REAL()));

	const QString& typeAttr = m_selectedMap->getAttributeTypeName(orbit, nameAttr);

	if(typeAttr == vec3TypeName)
	{
		combo_positionAttribute->addItem(nameAttr);
		combo_normalAttribute->addItem(nameAttr);
		combo_KmaxAttribute->addItem(nameAttr);
		combo_KminAttribute->addItem(nameAttr);
		combo_KnormalAttribute->addItem(nameAttr);
	}
	else if(typeAttr == realTypeName)
	{
		combo_kmaxAttribute->addItem(nameAttr);
		combo_kminAttribute->addItem(nameAttr);
	}
}

Pierre Kraemer's avatar
Pierre Kraemer committed
151 152 153
} // namespace SCHNApps

} // namespace CGoGN