computeCurvatureDialog.cpp 4.54 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
32
33
34
	const QList<MapHandlerGen*>& maps = m_window->getMapsList();
	foreach(MapHandlerGen* map, maps)
		mapList->addItem(map->getName());
}

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

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

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

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

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

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

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

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

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

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

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

				++k;
			}
		}
99
100

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

107
108
109
110
111
112
113
void ComputeCurvatureDialog::addMapToList(MapHandlerGen* m)
{
	mapList->addItem(m->getName());
}

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

	if(m_selectedMap == m)
119
	{
120
		disconnect(m_selectedMap, SIGNAL(attributeAdded(unsigned int, const QString&)), this, SLOT(addAttributeToList(unsigned int, const QString&)));
121
		m_selectedMap = NULL;
122
123
124
	}
}

125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
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
147
148
149
} // namespace SCHNApps

} // namespace CGoGN