surface_subdivision.cpp 3.73 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
#include "surface_subdivision.h"

#include "mapHandler.h"

#include "Algo/Modelisation/subdivision.h"

namespace CGoGN
{

namespace SCHNApps
{

bool Surface_Subdivision_Plugin::enable()
{
	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;
}

29 30 31 32 33 34 35 36
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()));
}

37 38 39 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 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 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133
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;

	VertexAttribute<PFP2::VEC3> position = mh->getAttribute<PFP2::VEC3, VERTEX>(positionAttributeName);
	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;

	VertexAttribute<PFP2::VEC3> position = mh->getAttribute<PFP2::VEC3, VERTEX>(positionAttributeName);
	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;

	VertexAttribute<PFP2::VEC3> position = mh->getAttribute<PFP2::VEC3, VERTEX>(positionAttributeName);
	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();
}

#ifndef DEBUG
Q_EXPORT_PLUGIN2(Surface_Subdivision_Plugin, Surface_Subdivision_Plugin)
#else
Q_EXPORT_PLUGIN2(Surface_Subdivision_PluginD, Surface_Subdivision_Plugin)
#endif

} // namespace SCHNApps

} // namespace CGoGN