renderTopoSurface.cpp 9.8 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
	}
}

untereiner's avatar
untereiner committed
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104
void RenderTopoSurfacePlugin::mousePress(View* view, QMouseEvent* event)
{
//  if (Shift())
//  {
//    ParameterSet* params = h_viewParams[view];

//    m_renderTopo->updateData<PFP>(myMap, position, m_coeff_topo_explod[0], m_coeff_topo_explod[1], m_coeff_topo_explod[2], *m_selNoBoundary)	;

//    Dart d = m_renderTopo->picking<PFP>(myMap, x,  y, *m_selNoBoundary);
//    if (d != Dart::nil())
//    {
//      emit(dartSelected(d);
//    }
//  }
}

105 106 107 108 109 110
void RenderTopoSurfacePlugin::viewLinked(View* view, Plugin* plugin)
{
	if(plugin == this)
	{
		ParameterSet* params = new ParameterSet();
		h_viewParams.insert(view, params);
111

112
		const QList<MapHandlerGen*>& maps = view->getLinkedMaps();
untereiner's avatar
untereiner committed
113
		foreach(MapHandlerGen* mh, maps)
114
			addManagedMap(view, mh);
115 116 117 118 119 120 121 122 123 124 125 126 127

		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)
	{
128 129 130 131
		const QList<MapHandlerGen*>& maps = view->getLinkedMaps();
		foreach(MapHandlerGen* mh, maps)
			removeManagedMap(view, mh);

132
		ParameterSet* params = h_viewParams[view];
133
		delete params;
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150
		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));
151 152 153 154 155 156 157 158 159
	addManagedMap(view, m);
}

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

161 162
void RenderTopoSurfacePlugin::addManagedMap(View* v, MapHandlerGen *m)
{
untereiner's avatar
untereiner committed
163 164 165
	connect(m, SIGNAL(attributeModified(unsigned int, QString)), this, SLOT(attributeModified(unsigned int, QString)));
	connect(m, SIGNAL(connectivityModified()), this, SLOT(connectivityModified()));

166
	ParameterSet* params = h_viewParams[v];
167
	PerMapParameterSet* perMap = new PerMapParameterSet(m);
168

169 170
	registerShader(perMap->m_renderTopo->shader1());
	registerShader(perMap->m_renderTopo->shader2());
171

172
	params->perMap.insert(m->getName(), perMap);
173

174
	if(params->selectedMap == NULL || params->perMap.count() == 1)
175
		changeSelectedMap(v, m);
176 177 178 179
	else
		m_dockTab->refreshUI(params);
}

180
void RenderTopoSurfacePlugin::removeManagedMap(View *v, MapHandlerGen *m)
181
{
untereiner's avatar
untereiner committed
182 183 184
	disconnect(m, SIGNAL(attributeModified(unsigned int, QString)), this, SLOT(attributeModified(unsigned int, QString)));
	disconnect(m, SIGNAL(connectivityModified()), this, SLOT(connectivityModified()));

185
	ParameterSet* params = h_viewParams[v];
186
	PerMapParameterSet* perMap = params->perMap[m->getName()];
187

188 189
	unregisterShader(perMap->m_renderTopo->shader1());
	unregisterShader(perMap->m_renderTopo->shader2());
190

191
	delete perMap;
192 193 194 195 196
	params->perMap.remove(m->getName());

	if(params->selectedMap == m)
	{
		if(!params->perMap.empty())
197
			changeSelectedMap(v, m_window->getMap(params->perMap.begin().key()));
198
		else
199
			changeSelectedMap(v, NULL);
200 201 202 203 204
	}
	else
		m_dockTab->refreshUI(params);
}

205
void RenderTopoSurfacePlugin::changeSelectedMap(View* view, MapHandlerGen* map)
206 207 208 209 210 211 212 213
{
	ParameterSet* params = h_viewParams[view];

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

	if(view->isCurrentView())
	{
214 215 216 217 218
		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&)));

219
		m_dockTab->refreshUI(params);
220 221 222
	}
}

untereiner's avatar
untereiner committed
223
void RenderTopoSurfacePlugin::changePositionAttribute(View* view, MapHandlerGen* map, VertexAttribute<PFP2::VEC3> attribute, bool fromUI)
224 225
{
	ParameterSet* params = h_viewParams[view];
untereiner's avatar
untereiner committed
226 227 228
	PerMapParameterSet* perMap = params->perMap[map->getName()];
	perMap->positionAttribute = attribute;
	perMap->updateRender();
229 230 231

	if(view->isCurrentView())
	{
untereiner's avatar
untereiner committed
232 233
		if(!fromUI)
			m_dockTab->refreshUI(params);
234 235 236 237
		view->updateGL();
	}
}

238 239 240 241 242 243 244 245 246 247 248 249 250
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
251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266
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();
	}
}

267 268 269 270 271 272 273 274 275 276 277 278 279
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
280 281 282 283 284 285 286 287 288 289 290 291 292
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();
	}
}

293 294 295 296 297 298 299 300 301 302 303 304
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
305

Pierre Kraemer's avatar
Pierre Kraemer committed
306 307 308 309 310 311 312 313 314 315 316 317
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
318 319

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

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

untereiner's avatar
untereiner committed
334
void RenderTopoSurfacePlugin::changeFacesScaleFactor(View* view, MapHandlerGen* map, int i, bool fromUI)
335
{
untereiner's avatar
untereiner committed
336 337
	ParameterSet* params = h_viewParams[view];
	PerMapParameterSet* perMap = params->perMap[map->getName()];
338
	perMap->facesScaleFactor = i / 100.0;
untereiner's avatar
untereiner committed
339
	perMap->updateRender();
340

untereiner's avatar
untereiner committed
341
	if(view->isCurrentView())
342
	{
untereiner's avatar
untereiner committed
343 344 345
		if(!fromUI)
			m_dockTab->refreshUI(params);
		view->updateGL();
346 347 348
	}
}

untereiner's avatar
untereiner committed
349
void RenderTopoSurfacePlugin::attributeModified(unsigned int orbit, QString nameAttr)
350
{
351 352 353 354 355 356 357 358 359 360 361 362 363 364
	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();
			}
		}
	}
365 366
}

untereiner's avatar
untereiner committed
367
void RenderTopoSurfacePlugin::connectivityModified()
368 369 370 371 372 373 374 375 376
{

}

#ifndef DEBUG
Q_EXPORT_PLUGIN2(RenderTopoSurfacePlugin, RenderTopoSurfacePlugin)
#else
Q_EXPORT_PLUGIN2(RenderTopoSurfacePluginD, RenderTopoSurfacePlugin)
#endif
untereiner's avatar
untereiner committed
377 378 379 380

} // namespace SCHNApps

} // namespace CGoGN