renderTopoSurface.cpp 9.98 KB
Newer Older
1 2 3 4
#include "renderTopoSurface.h"

#include "mapHandler.h"

untereiner's avatar
untereiner committed
5 6 7 8 9 10 11 12
namespace CGoGN
{

namespace SCHNApps
{

PerMapParameterSet::PerMapParameterSet(MapHandlerGen* m) :
	mh(m),
13
	drawDarts(true),
14
	dartsColor("white"),
15
	drawPhi1(true),
16
	phi1Color("cyan"),
17
	drawPhi2(true),
18
	phi2Color("red"),
untereiner's avatar
untereiner committed
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
	edgesScaleFactor(1.0f),
	facesScaleFactor(1.0f)
{
	m_renderTopo = new Algo::Render::GL2::TopoRender();

	QString positionName;

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

	const AttributeHash& attribs = mh->getAttributesList(VERTEX);
	for(AttributeHash::const_iterator i = attribs.constBegin(); i != attribs.constEnd(); ++i)
	{
		if(i.value() == vec3TypeName)
		{
			if(positionName != "position")	// try to select an attribute named "position"
				positionName = i.key();		// or anything else if not found
		}
	}
	positionAttribute = mh->getAttribute<PFP2::VEC3, VERTEX>(positionName);

	updateRender();
}

PerMapParameterSet::~PerMapParameterSet()
{
	delete m_renderTopo;
}

void PerMapParameterSet::updateRender()
{
49 50
	PFP2::MAP* m = static_cast<MapHandler<PFP2>*>(mh)->getMap();
	m_renderTopo->updateData<PFP2>(*m, positionAttribute, edgesScaleFactor, facesScaleFactor);
untereiner's avatar
untereiner committed
51
}
52

53

54 55
bool RenderTopoSurfacePlugin::enable()
{
untereiner's avatar
untereiner committed
56 57
	m_dockTab = new RenderTopoSurfaceDockTab(m_window, this);
	addTabInDock(m_dockTab, "RenderTopoSurface");
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77

	connect(m_window, SIGNAL(viewAndPluginLinked(View*, Plugin*)), this, SLOT(viewLinked(View*, Plugin*)));
	connect(m_window, SIGNAL(viewAndPluginUnlinked(View*, Plugin*)), this, SLOT(viewUnlinked(View*, Plugin*)));
	connect(m_window, SIGNAL(currentViewChanged(View*)), this, SLOT(currentViewChanged(View*)));

	return true;
}

void RenderTopoSurfacePlugin::disable()
{

}

void RenderTopoSurfacePlugin::redraw(View* view)
{
	ParameterSet* params = h_viewParams[view];

	const QList<MapHandlerGen*>& maps = view->getLinkedMaps();
	foreach(MapHandlerGen* m, maps)
	{
untereiner's avatar
untereiner committed
78 79
		PerMapParameterSet* p = params->perMap[m->getName()];

80 81 82 83 84 85
		if(p->drawDarts)
			p->m_renderTopo->drawDarts();
		if(p->drawPhi1)
			p->m_renderTopo->drawRelation1();
		if(p->drawPhi2)
			p->m_renderTopo->drawRelation2();
86 87 88 89 90 91 92 93 94 95
	}
}

void RenderTopoSurfacePlugin::viewLinked(View* view, Plugin* plugin)
{
	if(plugin == this)
	{
		ParameterSet* params = new ParameterSet();
		h_viewParams.insert(view, params);
		const QList<MapHandlerGen*>& maps = view->getLinkedMaps();
untereiner's avatar
untereiner committed
96
		foreach(MapHandlerGen* mh, maps)
97
		{
98 99
			connect(mh, SIGNAL(attributeModified(unsigned int, QString)), this, SLOT(attributeModified(unsigned int, QString)));
			connect(mh, SIGNAL(connectivityModified()), this, SLOT(connectivityModified()));
untereiner's avatar
untereiner committed
100 101 102 103
			PerMapParameterSet* p = new PerMapParameterSet(mh);
			registerShader(p->m_renderTopo->shader1());
			registerShader(p->m_renderTopo->shader2());
			params->perMap.insert(mh->getName(), p);
104
		}
105
		if(!maps.empty())
106 107 108 109 110 111 112 113 114 115 116 117 118 119
			changeSelectedMap(view, maps[0]);

		connect(view, SIGNAL(mapLinked(MapHandlerGen*)), this, SLOT(mapLinked(MapHandlerGen*)));
		connect(view, SIGNAL(mapUnlinked(MapHandlerGen*)), this, SLOT(mapUnlinked(MapHandlerGen*)));

		if(view->isCurrentView())
			m_dockTab->refreshUI(params);
	}
}

void RenderTopoSurfacePlugin::viewUnlinked(View* view, Plugin* plugin)
{
	if(plugin == this)
	{
120 121 122 123
		ParameterSet* params = h_viewParams[view];
		QHash<QString, PerMapParameterSet*>::const_iterator i = params->perMap.constBegin();
		while (i != params->perMap.constEnd())
		{
124 125
			disconnect(i.value()->mh, SIGNAL(attributeModified(unsigned int, QString)), this, SLOT(attributeModified(unsigned int, QString)));
			disconnect(i.value()->mh, SIGNAL(connectivityModified()), this, SLOT(connectivityModified()));
126 127 128 129 130
			unregisterShader(i.value()->m_renderTopo->shader1());
			unregisterShader(i.value()->m_renderTopo->shader2());
			delete i.value();
			++i;
		}
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148
		h_viewParams.remove(view);

		disconnect(view, SIGNAL(mapLinked(MapHandlerGen*)), this, SLOT(mapLinked(MapHandlerGen*)));
		disconnect(view, SIGNAL(mapUnlinked(MapHandlerGen*)), this, SLOT(mapUnlinked(MapHandlerGen*)));
	}
}

void RenderTopoSurfacePlugin::currentViewChanged(View* view)
{
	if(isLinkedToView(view))
		m_dockTab->refreshUI(h_viewParams[view]);
}

void RenderTopoSurfacePlugin::mapLinked(MapHandlerGen* m)
{
	View* view = static_cast<View*>(QObject::sender());
	assert(isLinkedToView(view));

untereiner's avatar
untereiner committed
149 150 151
	connect(m, SIGNAL(attributeModified(unsigned int, QString)), this, SLOT(attributeModified(unsigned int, QString)));
	connect(m, SIGNAL(connectivityModified()), this, SLOT(connectivityModified()));

152
	ParameterSet* params = h_viewParams[view];
153 154 155 156
	PerMapParameterSet* perMap = new PerMapParameterSet(m);
	registerShader(perMap->m_renderTopo->shader1());
	registerShader(perMap->m_renderTopo->shader2());
	params->perMap.insert(m->getName(), perMap);
157 158 159 160 161 162 163 164 165 166 167
	if(params->selectedMap == NULL || params->perMap.count() == 1)
		changeSelectedMap(view, m);
	else
		m_dockTab->refreshUI(params);
}

void RenderTopoSurfacePlugin::mapUnlinked(MapHandlerGen* m)
{
	View* view = static_cast<View*>(QObject::sender());
	assert(isLinkedToView(view));

untereiner's avatar
untereiner committed
168 169 170
	disconnect(m, SIGNAL(attributeModified(unsigned int, QString)), this, SLOT(attributeModified(unsigned int, QString)));
	disconnect(m, SIGNAL(connectivityModified()), this, SLOT(connectivityModified()));

171
	ParameterSet* params = h_viewParams[view];
172 173 174 175
	PerMapParameterSet* perMap = params->perMap[m->getName()];
	unregisterShader(perMap->m_renderTopo->shader1());
	unregisterShader(perMap->m_renderTopo->shader2());
	delete perMap;
176 177 178 179 180 181 182 183 184 185 186 187 188
	params->perMap.remove(m->getName());

	if(params->selectedMap == m)
	{
		if(!params->perMap.empty())
			changeSelectedMap(view, m_window->getMap(params->perMap.begin().key()));
		else
			changeSelectedMap(view, NULL);
	}
	else
		m_dockTab->refreshUI(params);
}

untereiner's avatar
untereiner committed
189
void RenderTopoSurfacePlugin::changeSelectedMap(View* view, MapHandlerGen* map, bool fromUI)
190 191 192 193 194 195 196 197
{
	ParameterSet* params = h_viewParams[view];

	MapHandlerGen* prev = params->selectedMap;
	params->selectedMap = map;

	if(view->isCurrentView())
	{
198 199 200 201 202
		if(prev)
			disconnect(prev, SIGNAL(attributeAdded(unsigned int, const QString&)), m_dockTab, SLOT(addAttributeToList(unsigned int, const QString&)));
		if(map)
			connect(map, SIGNAL(attributeAdded(unsigned int, const QString&)), m_dockTab, SLOT(addAttributeToList(unsigned int, const QString&)));

untereiner's avatar
untereiner committed
203 204
		if(!fromUI)
			m_dockTab->refreshUI(params);
205 206 207
	}
}

untereiner's avatar
untereiner committed
208
void RenderTopoSurfacePlugin::changePositionAttribute(View* view, MapHandlerGen* map, VertexAttribute<PFP2::VEC3> attribute, bool fromUI)
209 210
{
	ParameterSet* params = h_viewParams[view];
untereiner's avatar
untereiner committed
211 212 213
	PerMapParameterSet* perMap = params->perMap[map->getName()];
	perMap->positionAttribute = attribute;
	perMap->updateRender();
214 215 216

	if(view->isCurrentView())
	{
untereiner's avatar
untereiner committed
217 218
		if(!fromUI)
			m_dockTab->refreshUI(params);
219 220 221 222
		view->updateGL();
	}
}

223 224 225 226 227 228 229 230 231 232 233 234 235
void RenderTopoSurfacePlugin::changeDrawDarts(View* view, MapHandlerGen* map, bool b, bool fromUI)
{
	ParameterSet* params = h_viewParams[view];
	params->perMap[map->getName()]->drawDarts = b;

	if(view->isCurrentView())
	{
		if(!fromUI)
			m_dockTab->refreshUI(params);
		view->updateGL();
	}
}

236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251
void RenderTopoSurfacePlugin::changeDartsColor(View* view, MapHandlerGen* map, QColor c, bool fromUI)
{
	ParameterSet* params = h_viewParams[view];
	PerMapParameterSet* perMap = params->perMap[map->getName()];
	perMap->dartsColor = c;
	perMap->m_renderTopo->setInitialDartsColor(c.redF(), c.greenF(), c.blueF());
	perMap->m_renderTopo->setAllDartsColor(c.redF(), c.greenF(), c.blueF());

	if(view->isCurrentView())
	{
		if(!fromUI)
			m_dockTab->refreshUI(params);
		view->updateGL();
	}
}

252 253 254 255 256 257 258 259 260 261 262 263 264
void RenderTopoSurfacePlugin::changeDrawPhi1(View* view, MapHandlerGen* map, bool b, bool fromUI)
{
	ParameterSet* params = h_viewParams[view];
	params->perMap[map->getName()]->drawPhi1 = b;

	if(view->isCurrentView())
	{
		if(!fromUI)
			m_dockTab->refreshUI(params);
		view->updateGL();
	}
}

265 266 267 268 269 270 271 272 273 274 275 276 277
void RenderTopoSurfacePlugin::changePhi1Color(View* view, MapHandlerGen* map, QColor c, bool fromUI)
{
	ParameterSet* params = h_viewParams[view];
	params->perMap[map->getName()]->phi1Color = c;

	if(view->isCurrentView())
	{
		if(!fromUI)
			m_dockTab->refreshUI(params);
		view->updateGL();
	}
}

278 279 280 281 282 283 284 285 286 287 288 289
void RenderTopoSurfacePlugin::changeDrawPhi2(View* view, MapHandlerGen* map, bool b, bool fromUI)
{
	ParameterSet* params = h_viewParams[view];
	params->perMap[map->getName()]->drawPhi2 = b;

	if(view->isCurrentView())
	{
		if(!fromUI)
			m_dockTab->refreshUI(params);
		view->updateGL();
	}
}
untereiner's avatar
untereiner committed
290

291 292 293 294 295 296 297 298 299 300 301 302
void RenderTopoSurfacePlugin::changePhi2Color(View* view, MapHandlerGen* map, QColor c, bool fromUI)
{
	ParameterSet* params = h_viewParams[view];
	params->perMap[map->getName()]->phi2Color = c;

	if(view->isCurrentView())
	{
		if(!fromUI)
			m_dockTab->refreshUI(params);
		view->updateGL();
	}
}
untereiner's avatar
untereiner committed
303 304

void RenderTopoSurfacePlugin::changeEdgesScaleFactor(View* view, MapHandlerGen* map, int i, bool fromUI)
305 306
{
	ParameterSet* params = h_viewParams[view];
untereiner's avatar
untereiner committed
307
	PerMapParameterSet* perMap = params->perMap[map->getName()];
308
	perMap->edgesScaleFactor = i / 100.0;
untereiner's avatar
untereiner committed
309
	perMap->updateRender();
310 311 312

	if(view->isCurrentView())
	{
untereiner's avatar
untereiner committed
313 314
		if(!fromUI)
			m_dockTab->refreshUI(params);
315 316 317 318
		view->updateGL();
	}
}

untereiner's avatar
untereiner committed
319
void RenderTopoSurfacePlugin::changeFacesScaleFactor(View* view, MapHandlerGen* map, int i, bool fromUI)
320
{
untereiner's avatar
untereiner committed
321 322
	ParameterSet* params = h_viewParams[view];
	PerMapParameterSet* perMap = params->perMap[map->getName()];
323
	perMap->facesScaleFactor = i / 100.0;
untereiner's avatar
untereiner committed
324
	perMap->updateRender();
325

untereiner's avatar
untereiner committed
326
	if(view->isCurrentView())
327
	{
untereiner's avatar
untereiner committed
328 329 330
		if(!fromUI)
			m_dockTab->refreshUI(params);
		view->updateGL();
331 332 333
	}
}

untereiner's avatar
untereiner committed
334
void RenderTopoSurfacePlugin::attributeModified(unsigned int orbit, QString nameAttr)
335
{
336 337 338 339 340 341 342 343 344 345 346 347 348 349
	if(orbit == VERTEX)
	{
		MapHandlerGen* map = static_cast<MapHandlerGen*>(QObject::sender());
		foreach(View* view, l_views)
		{
			ParameterSet* params = h_viewParams[view];
			if(params->perMap.contains(map->getName()))
			{
				PerMapParameterSet* perMap = params->perMap[map->getName()];
				if(nameAttr == QString::fromStdString(perMap->positionAttribute.name()))
					perMap->updateRender();
			}
		}
	}
350 351
}

untereiner's avatar
untereiner committed
352
void RenderTopoSurfacePlugin::connectivityModified()
353 354 355 356 357 358 359 360 361
{

}

#ifndef DEBUG
Q_EXPORT_PLUGIN2(RenderTopoSurfacePlugin, RenderTopoSurfacePlugin)
#else
Q_EXPORT_PLUGIN2(RenderTopoSurfacePluginD, RenderTopoSurfacePlugin)
#endif
untereiner's avatar
untereiner committed
362 363 364 365

} // namespace SCHNApps

} // namespace CGoGN