differentialProperties.cpp 2.67 KB
Newer Older
1
2
3
4
5
6
#include "differentialProperties.h"

#include "mapHandler.h"

#include "Algo/Geometry/normal.h"

7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33


ComputeNormalsDialog::ComputeNormalsDialog(Window* w) : m_window(w)
{
	setupUi(this);
	connect(mapList, SIGNAL(itemSelectionChanged()), this, SLOT(cb_selectedMapChanged()));
}

void ComputeNormalsDialog::cb_selectedMapChanged()
{
	QList<QListWidgetItem*> currentItems = mapList->selectedItems();
	if(!currentItems.empty())
	{
		combo_positionAttribute->clear();
		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;
		cont.getAttributesNames(names);
		for(unsigned int i = 0; i < names.size(); ++i)
			combo_positionAttribute->addItem(QString::fromStdString(names[i]));
	}
}



34
35
bool DifferentialPropertiesPlugin::enable()
{
36
	m_computeNormalsDialog = new ComputeNormalsDialog(m_window);
37
38
39

	computeNormalsAction = new QAction("import", this);
	addMenuAction("Surface;DifferentialProperties;Compute Normals", computeNormalsAction);
40
41
42
43
	connect(computeNormalsAction, SIGNAL(triggered()), this, SLOT(cb_openComputeNormalsDialog()));

	connect(m_computeNormalsDialog, SIGNAL(accepted()), this, SLOT(cb_computeNormals()));

44
45
46
	return true;
}

47
void DifferentialPropertiesPlugin::cb_openComputeNormalsDialog()
48
49
50
51
52
53
54
55
56
57
{
	m_computeNormalsDialog->mapList->clear();
	m_computeNormalsDialog->attributeName->setText("normal");
	const QList<MapHandlerGen*>& maps = m_window->getMapsList();
	foreach(MapHandlerGen* map, maps)
		m_computeNormalsDialog->mapList->addItem(map->getName());

	m_computeNormalsDialog->show();
}

58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
void DifferentialPropertiesPlugin::cb_computeNormals()
{
	QList<QListWidgetItem*> currentItems = m_computeNormalsDialog->mapList->selectedItems();
	if(!currentItems.empty())
	{
		const QString& mapname = currentItems[0]->text();
		MapHandler<PFP>* mh = reinterpret_cast<MapHandler<PFP>*>(m_window->getMap(mapname));
		MAP* map = mh->getMap();
		std::string positionName = m_computeNormalsDialog->combo_positionAttribute->currentText().toUtf8().constData();
		std::string normalName = m_computeNormalsDialog->attributeName->text().toUtf8().constData();
		VertexAttribute<VEC3> position = map->getAttribute<VEC3, VERTEX>(positionName);
		VertexAttribute<VEC3> normal = map->getAttribute<VEC3, VERTEX>(normalName);
		if(!normal.isValid())
			normal = map->addAttribute<VEC3, VERTEX>(normalName);
		Algo::Geometry::computeNormalVertices<PFP>(*map, position, normal);
	}
}

76
77
78
79
80
#ifndef DEBUG
Q_EXPORT_PLUGIN2(DifferentialPropertiesPlugin, DifferentialPropertiesPlugin)
#else
Q_EXPORT_PLUGIN2(DifferentialPropertiesPluginD, DifferentialPropertiesPlugin)
#endif