surface_subdivision.cpp 3.79 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14
#include "surface_subdivision.h"

#include "mapHandler.h"

#include "Algo/Modelisation/subdivision.h"

namespace CGoGN
{

namespace SCHNApps
{

bool Surface_Subdivision_Plugin::enable()
{
15 16 17
	//	magic line that init static variables of GenericMap in the plugins
		GenericMap::copyAllStatics(m_schnapps->getStaticPointers());

18 19 20 21 22 23 24 25 26 27 28 29 30 31
	m_subdivisionDialog = new Dialog_Surface_Subdivision(m_schnapps);

	m_subdivisionAction = new QAction("Subdivide surface", this);

	m_schnapps->addMenuAction(this, "Surface;Subdivision", m_subdivisionAction);

	connect(m_subdivisionAction, SIGNAL(triggered()), this, SLOT(openSubdivisionDialog()));

	connect(m_subdivisionDialog, SIGNAL(accepted()), this, SLOT(subdivideFromDialog()));
	connect(m_subdivisionDialog->button_apply, SIGNAL(clicked()), this, SLOT(subdivideFromDialog()));

	return true;
}

32 33 34 35 36 37 38 39
void Surface_Subdivision_Plugin::disable()
{
	disconnect(m_subdivisionAction, SIGNAL(triggered()), this, SLOT(openSubdivisionDialog()));

	disconnect(m_subdivisionDialog, SIGNAL(accepted()), this, SLOT(subdivideFromDialog()));
	disconnect(m_subdivisionDialog->button_apply, SIGNAL(clicked()), this, SLOT(subdivideFromDialog()));
}

40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
void Surface_Subdivision_Plugin::openSubdivisionDialog()
{
	m_subdivisionDialog->show();
}

void Surface_Subdivision_Plugin::subdivideFromDialog()
{
	QList<QListWidgetItem*> currentItems = m_subdivisionDialog->list_maps->selectedItems();
	if(!currentItems.empty())
	{
		const QString& mapName = currentItems[0]->text();
		const QString& positionName = m_subdivisionDialog->combo_positionAttribute->currentText();

		if(m_subdivisionDialog->radio_Loop->isChecked())
			loopSubdivision(mapName, positionName);
		else if(m_subdivisionDialog->radio_CC->isChecked())
			CCSubdivision(mapName, positionName);
		else if(m_subdivisionDialog->radio_trianguleFaces->isChecked())
			trianguleFaces(mapName, positionName);
	}
}

void Surface_Subdivision_Plugin::loopSubdivision(
	const QString& mapName,
	const QString& positionAttributeName)
{
	MapHandler<PFP2>* mh = static_cast<MapHandler<PFP2>*>(m_schnapps->getMap(mapName));
	if(mh == NULL)
		return;

Sylvain Thery's avatar
Sylvain Thery committed
70
	VertexAttribute<PFP2::VEC3, PFP2::MAP> position = mh->getAttribute<PFP2::VEC3, VERTEX>(positionAttributeName);
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
	if(!position.isValid())
		return;

	PFP2::MAP* map = mh->getMap();
	Algo::Surface::Modelisation::LoopSubdivision<PFP2>(*map, position);

	mh->notifyAttributeModification(position);
	mh->notifyConnectivityModification();

	foreach(View* view, mh->getLinkedViews())
		view->updateGL();
}

void Surface_Subdivision_Plugin::CCSubdivision(
	const QString& mapName,
	const QString& positionAttributeName)
{
	MapHandler<PFP2>* mh = static_cast<MapHandler<PFP2>*>(m_schnapps->getMap(mapName));
	if(mh == NULL)
		return;

Sylvain Thery's avatar
Sylvain Thery committed
92
	VertexAttribute<PFP2::VEC3, PFP2::MAP> position = mh->getAttribute<PFP2::VEC3, VERTEX>(positionAttributeName);
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113
	if(!position.isValid())
		return;

	PFP2::MAP* map = mh->getMap();
	Algo::Surface::Modelisation::CatmullClarkSubdivision<PFP2>(*map, position);

	mh->notifyAttributeModification(position);
	mh->notifyConnectivityModification();

	foreach(View* view, mh->getLinkedViews())
		view->updateGL();
}

void Surface_Subdivision_Plugin::trianguleFaces(
	const QString& mapName,
	const QString& positionAttributeName)
{
	MapHandler<PFP2>* mh = static_cast<MapHandler<PFP2>*>(m_schnapps->getMap(mapName));
	if(mh == NULL)
		return;

Sylvain Thery's avatar
Sylvain Thery committed
114
	VertexAttribute<PFP2::VEC3, PFP2::MAP> position = mh->getAttribute<PFP2::VEC3, VERTEX>(positionAttributeName);
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132
	if(!position.isValid())
		return;

	PFP2::MAP* map = mh->getMap();
	Algo::Surface::Modelisation::trianguleFaces<PFP2>(*map, position);

	mh->notifyAttributeModification(position);
	mh->notifyConnectivityModification();

	foreach(View* view, mh->getLinkedViews())
		view->updateGL();
}

Q_EXPORT_PLUGIN2(Surface_Subdivision_Plugin, Surface_Subdivision_Plugin)

} // namespace SCHNApps

} // namespace CGoGN