computeCurvatureDialog.cpp 3.9 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(refreshUI()));
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::refreshUI()
Pierre Kraemer's avatar
Pierre Kraemer committed
36
{
37
38
39
	if(m_selectedMap)
		disconnect(m_selectedMap, SIGNAL(attributeAdded()), this, SLOT(refreshUI()));

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();
Pierre Kraemer's avatar
Pierre Kraemer committed
50
51
52
53
54
55
56
57
58
		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);
Pierre Kraemer's avatar
Pierre Kraemer committed
59
60
		std::string vec3TypeName = nameOfType(PFP2::VEC3());
		std::string realTypeName = nameOfType(PFP2::REAL());
Pierre Kraemer's avatar
Pierre Kraemer committed
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
		unsigned int j = 0;
		unsigned int k = 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 a position attribute named "position"
					combo_positionAttribute->setCurrentIndex(j);

				combo_normalAttribute->addItem(QString::fromStdString(names[i]));
				if(names[i] == "normal") // try to select a normal attribute named "normal"
					combo_normalAttribute->setCurrentIndex(j);

				combo_KmaxAttribute->addItem(QString::fromStdString(names[i]));
				if(names[i] == "Kmax") // try to select a normal attribute named "Kmax"
					combo_KmaxAttribute->setCurrentIndex(j);

				combo_KminAttribute->addItem(QString::fromStdString(names[i]));
				if(names[i] == "Kmin") // try to select a normal attribute named "Kmin"
					combo_KminAttribute->setCurrentIndex(j);

				combo_KnormalAttribute->addItem(QString::fromStdString(names[i]));
				if(names[i] == "Knormal") // try to select a normal attribute named "Knormal"
					combo_KnormalAttribute->setCurrentIndex(j);

				++j;
			}
			else if(types[i] == realTypeName)
			{
				combo_kmaxAttribute->addItem(QString::fromStdString(names[i]));
				if(names[i] == "kmax") // try to select a normal attribute named "kmax"
					combo_kmaxAttribute->setCurrentIndex(k);

				combo_kminAttribute->addItem(QString::fromStdString(names[i]));
				if(names[i] == "kmin") // try to select a normal attribute named "kmin"
					combo_kminAttribute->setCurrentIndex(k);

				++k;
			}
		}
102
103
104

		m_selectedMap = mh;
		connect(m_selectedMap, SIGNAL(attributeAdded()), this, SLOT(refreshUI()));
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
112
113
114
115
116
void ComputeCurvatureDialog::addMapToList(MapHandlerGen* m)
{
	mapList->addItem(m->getName());
}

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

	if(m_selectedMap == m)
122
	{
123
124
		disconnect(m_selectedMap, SIGNAL(attributeAdded()), this, SLOT(refreshUI()));
		m_selectedMap = NULL;
125
126
127
	}
}

Pierre Kraemer's avatar
Pierre Kraemer committed
128
129
130
} // namespace SCHNApps

} // namespace CGoGN