renderTopoSurface.cpp 9.36 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),
Pierre Kraemer's avatar
Pierre Kraemer committed
14
	dartsColor("white"),
15
	drawPhi1(true),
Pierre Kraemer's avatar
Pierre Kraemer committed
16
	phi1Color("cyan"),
17
	drawPhi2(true),
Pierre Kraemer's avatar
Pierre Kraemer committed
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
	}
}

void RenderTopoSurfacePlugin::viewLinked(View* view, Plugin* plugin)
{
	if(plugin == this)
	{
		ParameterSet* params = new ParameterSet();
		h_viewParams.insert(view, params);
95

96
		const QList<MapHandlerGen*>& maps = view->getLinkedMaps();
untereiner's avatar
untereiner committed
97
		foreach(MapHandlerGen* mh, maps)
98
			addManagedMap(view, mh);
99 100 101 102 103 104 105 106 107 108 109 110 111

		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)
	{
112 113 114 115
		const QList<MapHandlerGen*>& maps = view->getLinkedMaps();
		foreach(MapHandlerGen* mh, maps)
			removeManagedMap(view, mh);

116
		ParameterSet* params = h_viewParams[view];
117
		delete params;
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134
		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));
135 136 137 138 139 140 141 142 143
	addManagedMap(view, m);
}

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

145 146
void RenderTopoSurfacePlugin::addManagedMap(View* v, MapHandlerGen *m)
{
untereiner's avatar
untereiner committed
147 148 149
	connect(m, SIGNAL(attributeModified(unsigned int, QString)), this, SLOT(attributeModified(unsigned int, QString)));
	connect(m, SIGNAL(connectivityModified()), this, SLOT(connectivityModified()));

150
	ParameterSet* params = h_viewParams[v];
151
	PerMapParameterSet* perMap = new PerMapParameterSet(m);
152

153 154
	registerShader(perMap->m_renderTopo->shader1());
	registerShader(perMap->m_renderTopo->shader2());
155

156
	params->perMap.insert(m->getName(), perMap);
157

158
	if(params->selectedMap == NULL || params->perMap.count() == 1)
159
		changeSelectedMap(v, m);
160 161 162 163
	else
		m_dockTab->refreshUI(params);
}

164
void RenderTopoSurfacePlugin::removeManagedMap(View *v, MapHandlerGen *m)
165
{
untereiner's avatar
untereiner committed
166 167 168
	disconnect(m, SIGNAL(attributeModified(unsigned int, QString)), this, SLOT(attributeModified(unsigned int, QString)));
	disconnect(m, SIGNAL(connectivityModified()), this, SLOT(connectivityModified()));

169
	ParameterSet* params = h_viewParams[v];
170
	PerMapParameterSet* perMap = params->perMap[m->getName()];
171

172 173
	unregisterShader(perMap->m_renderTopo->shader1());
	unregisterShader(perMap->m_renderTopo->shader2());
174

175
	delete perMap;
176 177 178 179 180
	params->perMap.remove(m->getName());

	if(params->selectedMap == m)
	{
		if(!params->perMap.empty())
181
			changeSelectedMap(v, m_window->getMap(params->perMap.begin().key()));
182
		else
183
			changeSelectedMap(v, NULL);
184 185 186 187 188
	}
	else
		m_dockTab->refreshUI(params);
}

189
void RenderTopoSurfacePlugin::changeSelectedMap(View* view, MapHandlerGen* map)
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&)));

203
		m_dockTab->refreshUI(params);
204 205 206
	}
}

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

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

222 223 224 225 226 227 228 229 230 231 232 233 234
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();
	}
}

Pierre Kraemer's avatar
Pierre Kraemer committed
235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250
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();
	}
}

251 252 253 254 255 256 257 258 259 260 261 262 263
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();
	}
}

Pierre Kraemer's avatar
Pierre Kraemer committed
264 265 266 267 268 269 270 271 272 273 274 275 276
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();
	}
}

277 278 279 280 281 282 283 284 285 286 287 288
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
289

Pierre Kraemer's avatar
Pierre Kraemer committed
290 291 292 293 294 295 296 297 298 299 300 301
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
302 303

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

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

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

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

untereiner's avatar
untereiner committed
333
void RenderTopoSurfacePlugin::attributeModified(unsigned int orbit, QString nameAttr)
334
{
335 336 337 338 339 340 341 342 343 344 345 346 347 348
	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();
			}
		}
	}
349 350
}

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

}

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

} // namespace SCHNApps

} // namespace CGoGN