surface_selection.cpp 20 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
#include "surface_selection.h"

#include "schnapps.h"
#include "view.h"
#include "mapHandler.h"

#include "Algo/Selection/raySelector.h"
#include "Algo/Selection/collector.h"

#include <QKeyEvent>
#include <QMouseEvent>

namespace CGoGN
{

namespace SCHNApps
{

Surface_Selection_Plugin::Surface_Selection_Plugin() :
20 21
	m_selecting(false),
	m_normalAngleThreshold(10)
22 23 24 25
{}

bool Surface_Selection_Plugin::enable()
{
26 27 28
	//	magic line that init static variables of GenericMap in the plugins
		GenericMap::copyAllStatics(m_schnapps->getStaticPointers());

29 30 31
	m_dockTab = new Surface_Selection_DockTab(m_schnapps, this);
	m_schnapps->addPluginDockTab(this, m_dockTab, "Surface_Selection");

32 33 34
	m_pointSprite = new CGoGN::Utils::PointSprite();
	m_selectedVerticesVBO = new Utils::VBO();

Pierre Kraemer's avatar
Pierre Kraemer committed
35 36 37 38 39
	m_selectedEdgesDrawer = new Utils::Drawer();
	m_selectedFacesDrawer = new Utils::Drawer();

	m_selectingCellDrawer = new Utils::Drawer();

40
	m_selectionSphereVBO = new Utils::VBO();
41

42
	registerShader(m_pointSprite);
Pierre Kraemer's avatar
Pierre Kraemer committed
43 44 45
	registerShader(m_selectedEdgesDrawer->getShader());
	registerShader(m_selectedFacesDrawer->getShader());
	registerShader(m_selectingCellDrawer->getShader());
46 47

	connect(m_schnapps, SIGNAL(selectedMapChanged(MapHandlerGen*, MapHandlerGen*)), this, SLOT(selectedMapChanged(MapHandlerGen*, MapHandlerGen*)));
Pierre Kraemer's avatar
Pierre Kraemer committed
48
	connect(m_schnapps, SIGNAL(selectedCellSelectorChanged(CellSelectorGen*)), this, SLOT(updateSelectedCellsRendering()));
49

Pierre Kraemer's avatar
Pierre Kraemer committed
50 51 52 53 54
	MapHandlerGen* cur = m_schnapps->getSelectedMap();
	if(cur)
	{
		connect(cur, SIGNAL(attributeAdded(unsigned int, const QString&)), this, SLOT(selectedMapAttributeAdded(unsigned int, const QString&)));
		connect(cur, SIGNAL(attributeModified(unsigned int, const QString&)), this, SLOT(selectedMapAttributeModified(unsigned int, const QString&)));
55
		connect(cur, SIGNAL(connectivityModified()), this, SLOT(selectedMapConnectivityModified()));
Pierre Kraemer's avatar
Pierre Kraemer committed
56 57
		m_selectionRadius = cur->getBBdiagSize() / 50.0f;
	}
58 59 60 61 62 63 64 65 66

	m_dockTab->updateMapParameters();

	return true;
}

void Surface_Selection_Plugin::disable()
{
	delete m_pointSprite;
67
	delete m_selectedVerticesVBO;
Pierre Kraemer's avatar
Pierre Kraemer committed
68 69 70 71 72

	delete m_selectedEdgesDrawer;
	delete m_selectedFacesDrawer;
	delete m_selectingCellDrawer;

73
	delete m_selectionSphereVBO;
74

Pierre Kraemer's avatar
Pierre Kraemer committed
75
	disconnect(m_schnapps, SIGNAL(selectedViewChanged(View*, View*)), this, SLOT(selectedViewChanged(View*, View*)));
76
	disconnect(m_schnapps, SIGNAL(mapRemoved(MapHandlerGen*)), this, SLOT(mapRemoved(MapHandlerGen*)));
77 78
}

79
void Surface_Selection_Plugin::draw(View *view)
80 81 82
{
}

83 84
void Surface_Selection_Plugin::drawMap(View* view, MapHandlerGen* map)
{
85
	if(map->isSelectedMap())
86
	{
87
		const MapParameters& p = h_parameterSet[map];
88 89 90 91 92 93
		if(p.positionAttribute.isValid())
		{
			unsigned int orbit = m_schnapps->getCurrentOrbit();
			CellSelectorGen* selector = m_schnapps->getSelectedSelector(orbit);
			if(selector)
			{
Pierre Kraemer's avatar
Pierre Kraemer committed
94
				unsigned int nbCells = map->getGenericMap()->getNbCells(orbit);
95
				switch(orbit)
96
				{
97 98
					case VERTEX : {
						m_pointSprite->setAttributePosition(m_selectedVerticesVBO);
Pierre Kraemer's avatar
Pierre Kraemer committed
99
						m_pointSprite->setSize(20 * map->getBBdiagSize() / nbCells);
100 101 102 103
						m_pointSprite->setColor(CGoGN::Geom::Vec4f(1.0f, 0.0f, 0.0f, 1.0f));
						m_pointSprite->setLightPosition(CGoGN::Geom::Vec3f(0.0f, 0.0f, 1.0f));

						m_pointSprite->enableVertexAttribs();
104
						glDrawArrays(GL_POINTS, 0, selector->getNbSelectedCells());
105 106
						m_pointSprite->disableVertexAttribs();

107
						if(m_selecting && m_selectingVertex.valid())
108 109
						{
							std::vector<PFP2::VEC3> selectionPoint;
Pierre Kraemer's avatar
Pierre Kraemer committed
110
							selectionPoint.push_back(p.positionAttribute[m_selectingVertex]);
111 112 113 114 115 116 117 118
							m_selectionSphereVBO->updateData(selectionPoint);

							m_pointSprite->setAttributePosition(m_selectionSphereVBO);
							m_pointSprite->setColor(CGoGN::Geom::Vec4f(0.0f, 0.0f, 1.0f, 0.5f));
							m_pointSprite->setLightPosition(CGoGN::Geom::Vec3f(0.0f, 0.0f, 1.0f));

							switch(p.selectionMethod)
							{
119
								case NormalAngle :
120
								case SingleCell : {
Pierre Kraemer's avatar
Pierre Kraemer committed
121
									m_pointSprite->setSize(30 * map->getBBdiagSize() / nbCells);
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139
									break;
								}
								case WithinSphere : {
									m_pointSprite->setSize(m_selectionRadius);
									break;
								}
							}

							m_pointSprite->enableVertexAttribs();
							glEnable(GL_BLEND);
							glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
							glDrawArrays(GL_POINTS, 0, 1);
							glDisable(GL_BLEND);
							m_pointSprite->disableVertexAttribs();
						}
						break;
					}
					case EDGE : {
Pierre Kraemer's avatar
Pierre Kraemer committed
140
						m_selectedEdgesDrawer->callList();
Pierre Kraemer's avatar
Pierre Kraemer committed
141

142
						if(m_selecting && m_selectingEdge.valid())
Pierre Kraemer's avatar
Pierre Kraemer committed
143 144 145
						{
							switch(p.selectionMethod)
							{
146
								case NormalAngle :
Pierre Kraemer's avatar
Pierre Kraemer committed
147
								case SingleCell : {
Pierre Kraemer's avatar
Pierre Kraemer committed
148 149 150 151 152
									PFP2::MAP* m = static_cast<MapHandler<PFP2>*>(map)->getMap();
									m_selectingCellDrawer->newList(GL_COMPILE_AND_EXECUTE);
									m_selectingCellDrawer->lineWidth(6.0f);
									m_selectingCellDrawer->color3f(0.0f, 0.0f, 1.0f);
									m_selectingCellDrawer->begin(GL_LINES);
153 154
									m_selectingCellDrawer->vertex(p.positionAttribute[m_selectingEdge.dart]);
									m_selectingCellDrawer->vertex(p.positionAttribute[m->phi1(m_selectingEdge.dart)]);
Pierre Kraemer's avatar
Pierre Kraemer committed
155 156
									m_selectingCellDrawer->end();
									m_selectingCellDrawer->endList();
Pierre Kraemer's avatar
Pierre Kraemer committed
157 158 159
									break;
								}
								case WithinSphere : {
160
									std::vector<PFP2::VEC3> selectionPoint;
161
									selectionPoint.push_back(p.positionAttribute[m_selectingEdge.dart]);
162 163 164 165 166 167 168 169 170 171 172 173 174
									m_selectionSphereVBO->updateData(selectionPoint);

									m_pointSprite->setAttributePosition(m_selectionSphereVBO);
									m_pointSprite->setColor(CGoGN::Geom::Vec4f(0.0f, 0.0f, 1.0f, 0.5f));
									m_pointSprite->setLightPosition(CGoGN::Geom::Vec3f(0.0f, 0.0f, 1.0f));
									m_pointSprite->setSize(m_selectionRadius);

									m_pointSprite->enableVertexAttribs();
									glEnable(GL_BLEND);
									glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
									glDrawArrays(GL_POINTS, 0, 1);
									glDisable(GL_BLEND);
									m_pointSprite->disableVertexAttribs();
Pierre Kraemer's avatar
Pierre Kraemer committed
175 176 177 178
									break;
								}
							}
						}
179 180 181
						break;
					}
					case FACE : {
Pierre Kraemer's avatar
Pierre Kraemer committed
182
						m_selectedFacesDrawer->callList();
Pierre Kraemer's avatar
Pierre Kraemer committed
183

184
						if(m_selecting && m_selectingFace.valid())
Pierre Kraemer's avatar
Pierre Kraemer committed
185 186 187
						{
							switch(p.selectionMethod)
							{
188
								case NormalAngle :
Pierre Kraemer's avatar
Pierre Kraemer committed
189
								case SingleCell : {
Pierre Kraemer's avatar
Pierre Kraemer committed
190 191 192 193
									PFP2::MAP* m = static_cast<MapHandler<PFP2>*>(map)->getMap();
									m_selectingCellDrawer->newList(GL_COMPILE_AND_EXECUTE);
									m_selectingCellDrawer->color3f(0.0f, 0.0f, 1.0f);
									m_selectingCellDrawer->begin(GL_TRIANGLES);
194 195 196
									m_selectingCellDrawer->vertex(p.positionAttribute[m_selectingFace.dart]);
									m_selectingCellDrawer->vertex(p.positionAttribute[m->phi1(m_selectingFace.dart)]);
									m_selectingCellDrawer->vertex(p.positionAttribute[m->phi_1(m_selectingFace.dart)]);
Pierre Kraemer's avatar
Pierre Kraemer committed
197 198
									m_selectingCellDrawer->end();
									m_selectingCellDrawer->endList();
Pierre Kraemer's avatar
Pierre Kraemer committed
199 200 201
									break;
								}
								case WithinSphere : {
202
									std::vector<PFP2::VEC3> selectionPoint;
203
									selectionPoint.push_back(p.positionAttribute[m_selectingFace.dart]);
204 205 206 207 208 209 210 211 212 213 214 215 216
									m_selectionSphereVBO->updateData(selectionPoint);

									m_pointSprite->setAttributePosition(m_selectionSphereVBO);
									m_pointSprite->setColor(CGoGN::Geom::Vec4f(0.0f, 0.0f, 1.0f, 0.5f));
									m_pointSprite->setLightPosition(CGoGN::Geom::Vec3f(0.0f, 0.0f, 1.0f));
									m_pointSprite->setSize(m_selectionRadius);

									m_pointSprite->enableVertexAttribs();
									glEnable(GL_BLEND);
									glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
									glDrawArrays(GL_POINTS, 0, 1);
									glDisable(GL_BLEND);
									m_pointSprite->disableVertexAttribs();
Pierre Kraemer's avatar
Pierre Kraemer committed
217 218 219 220
									break;
								}
							}
						}
221 222
						break;
					}
223 224
				}
			}
225
		}
226 227 228
	}
}

229 230 231 232 233 234
void Surface_Selection_Plugin::keyPress(View* view, QKeyEvent* event)
{
	if(event->key() == Qt::Key_Shift)
	{
		view->setMouseTracking(true);
		m_selecting = true;
235
		view->updateGL();
236 237 238 239 240 241 242 243 244
	}
}

void Surface_Selection_Plugin::keyRelease(View* view, QKeyEvent* event)
{
	if(event->key() == Qt::Key_Shift)
	{
		view->setMouseTracking(false);
		m_selecting = false;
245
		view->updateGL();
246 247 248 249 250
	}
}

void Surface_Selection_Plugin::mousePress(View* view, QMouseEvent* event)
{
251
	if(m_selecting && (event->button() == Qt::LeftButton || event->button() == Qt::RightButton))
252 253
	{
		MapHandlerGen* mh = m_schnapps->getSelectedMap();
254
		const MapParameters& p = h_parameterSet[mh];
255 256
		if(p.positionAttribute.isValid())
		{
257 258 259 260 261
			unsigned int orbit = m_schnapps->getCurrentOrbit();
			CellSelectorGen* selector = m_schnapps->getSelectedSelector(orbit);
			if(selector)
			{
				PFP2::MAP* map = static_cast<MapHandler<PFP2>*>(mh)->getMap();
262

263
				switch(orbit)
264
				{
265
					case VERTEX : {
266 267
						CellSelector<PFP2::MAP, VERTEX>* cs = static_cast<CellSelector<PFP2::MAP, VERTEX>*>(selector);
						if(m_selectingVertex.valid())
268
						{
269 270 271 272
							switch(p.selectionMethod)
							{
								case SingleCell : {
									if(event->button() == Qt::LeftButton)
273
										cs->select(m_selectingVertex);
274
									else if(event->button() == Qt::RightButton)
275
										cs->unselect(m_selectingVertex);
276 277 278 279
									break;
								}
								case WithinSphere : {
									Algo::Surface::Selection::Collector_WithinSphere<PFP2> neigh(*map, p.positionAttribute, m_selectionRadius);
Pierre Kraemer's avatar
Pierre Kraemer committed
280
									neigh.collectAll(m_selectingVertex);
281
									if(event->button() == Qt::LeftButton)
282
										cs->select(neigh.getInsideVertices());
283
									else if(event->button() == Qt::RightButton)
284
										cs->unselect(neigh.getInsideVertices());
285 286
									break;
								}
287 288 289
								case NormalAngle : {
									if(p.normalAttribute.isValid())
									{
Pierre Kraemer's avatar
Pierre Kraemer committed
290
										Algo::Surface::Selection::Collector_NormalAngle<PFP2> neigh(*map, p.normalAttribute, m_normalAngleThreshold);
291 292
										neigh.collectAll(m_selectingVertex);
										if(event->button() == Qt::LeftButton)
293
											cs->select(neigh.getInsideVertices());
294
										else if(event->button() == Qt::RightButton)
295
											cs->unselect(neigh.getInsideVertices());
296 297 298
									}
									break;
								}
299
							}
Pierre Kraemer's avatar
Pierre Kraemer committed
300
							updateSelectedCellsRendering();
301
						}
302
						break;
303
					}
304
					case EDGE : {
305 306
						CellSelector<PFP2::MAP, EDGE>* cs = static_cast<CellSelector<PFP2::MAP, EDGE>*>(selector);
						if(m_selectingEdge.valid())
Pierre Kraemer's avatar
Pierre Kraemer committed
307 308 309 310 311
						{
							switch(p.selectionMethod)
							{
								case SingleCell : {
									if(event->button() == Qt::LeftButton)
312
										cs->select(m_selectingEdge);
Pierre Kraemer's avatar
Pierre Kraemer committed
313
									else if(event->button() == Qt::RightButton)
314
										cs->unselect(m_selectingEdge);
Pierre Kraemer's avatar
Pierre Kraemer committed
315 316 317
									break;
								}
								case WithinSphere : {
318 319 320
									Algo::Surface::Selection::Collector_WithinSphere<PFP2> neigh(*map, p.positionAttribute, m_selectionRadius);
									neigh.collectAll(m_selectingEdge);
									if(event->button() == Qt::LeftButton)
321
										cs->select(neigh.getInsideEdges());
322
									else if(event->button() == Qt::RightButton)
323
										cs->unselect(neigh.getInsideEdges());
Pierre Kraemer's avatar
Pierre Kraemer committed
324 325
									break;
								}
326 327 328
								case NormalAngle : {
									if(p.normalAttribute.isValid())
									{
Pierre Kraemer's avatar
Pierre Kraemer committed
329
										Algo::Surface::Selection::Collector_NormalAngle<PFP2> neigh(*map, p.normalAttribute, m_normalAngleThreshold);
330 331
										neigh.collectAll(m_selectingEdge);
										if(event->button() == Qt::LeftButton)
332
											cs->select(neigh.getInsideEdges());
333
										else if(event->button() == Qt::RightButton)
334
											cs->unselect(neigh.getInsideEdges());
335 336 337
									}
									break;
								}
Pierre Kraemer's avatar
Pierre Kraemer committed
338
							}
Pierre Kraemer's avatar
Pierre Kraemer committed
339
							updateSelectedCellsRendering();
Pierre Kraemer's avatar
Pierre Kraemer committed
340
						}
341 342 343
						break;
					}
					case FACE : {
344 345
						CellSelector<PFP2::MAP, FACE>* cs = static_cast<CellSelector<PFP2::MAP, FACE>*>(selector);
						if(m_selectingFace.valid())
Pierre Kraemer's avatar
Pierre Kraemer committed
346 347 348 349 350
						{
							switch(p.selectionMethod)
							{
								case SingleCell : {
									if(event->button() == Qt::LeftButton)
351
										cs->select(m_selectingFace);
Pierre Kraemer's avatar
Pierre Kraemer committed
352
									else if(event->button() == Qt::RightButton)
353
										cs->unselect(m_selectingFace);
Pierre Kraemer's avatar
Pierre Kraemer committed
354 355 356
									break;
								}
								case WithinSphere : {
357 358 359
									Algo::Surface::Selection::Collector_WithinSphere<PFP2> neigh(*map, p.positionAttribute, m_selectionRadius);
									neigh.collectAll(m_selectingFace);
									if(event->button() == Qt::LeftButton)
360
										cs->select(neigh.getInsideFaces());
361
									else if(event->button() == Qt::RightButton)
362
										cs->unselect(neigh.getInsideFaces());
Pierre Kraemer's avatar
Pierre Kraemer committed
363 364
									break;
								}
365 366 367
								case NormalAngle : {
									if(p.normalAttribute.isValid())
									{
Pierre Kraemer's avatar
Pierre Kraemer committed
368
										Algo::Surface::Selection::Collector_NormalAngle<PFP2> neigh(*map, p.normalAttribute, m_normalAngleThreshold);
369 370
										neigh.collectAll(m_selectingFace);
										if(event->button() == Qt::LeftButton)
371
											cs->select(neigh.getInsideFaces());
372
										else if(event->button() == Qt::RightButton)
373
											cs->unselect(neigh.getInsideFaces());
374 375 376
									}
									break;
								}
Pierre Kraemer's avatar
Pierre Kraemer committed
377
							}
Pierre Kraemer's avatar
Pierre Kraemer committed
378
							updateSelectedCellsRendering();
Pierre Kraemer's avatar
Pierre Kraemer committed
379
						}
380
						break;
381 382
					}
				}
383 384 385 386 387 388 389 390 391 392
			}
		}
	}
}

void Surface_Selection_Plugin::mouseMove(View* view, QMouseEvent* event)
{
	if(m_selecting)
	{
		MapHandlerGen* mh = m_schnapps->getSelectedMap();
393
		const MapParameters& p = h_parameterSet[mh];
394 395
		if(p.positionAttribute.isValid())
		{
Pierre Kraemer's avatar
Pierre Kraemer committed
396 397 398 399 400 401 402 403 404 405 406
			unsigned int orbit = m_schnapps->getCurrentOrbit();
			CellSelectorGen* selector = m_schnapps->getSelectedSelector(orbit);
			if(selector)
			{
				QPoint pixel(event->x(), event->y());
				qglviewer::Vec orig;
				qglviewer::Vec dir;
				view->camera()->convertClickToLine(pixel, orig, dir);

				qglviewer::Vec orig_inv = mh->getFrame()->coordinatesOf(orig);
				qglviewer::Vec dir_inv = mh->getFrame()->transformOf(dir);
407

Pierre Kraemer's avatar
Pierre Kraemer committed
408 409
				PFP2::VEC3 rayA(orig_inv.x, orig_inv.y, orig_inv.z);
				PFP2::VEC3 AB(dir_inv.x, dir_inv.y, dir_inv.z);
Pierre Kraemer's avatar
Pierre Kraemer committed
410

Pierre Kraemer's avatar
Pierre Kraemer committed
411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427
				PFP2::MAP* map = static_cast<MapHandler<PFP2>*>(mh)->getMap();

				switch(orbit)
				{
					case VERTEX : {
						Algo::Selection::vertexRaySelection<PFP2>(*map, p.positionAttribute, rayA, AB, m_selectingVertex);
						break;
					}
					case EDGE : {
						Algo::Selection::edgeRaySelection<PFP2>(*map, p.positionAttribute, rayA, AB, m_selectingEdge);
						break;
					}
					case FACE : {
						Algo::Selection::faceRaySelection<PFP2>(*map, p.positionAttribute, rayA, AB, m_selectingFace);
						break;
					}
				}
428 429 430 431 432 433 434 435 436 437 438

				view->updateGL();
			}
		}
	}
}

void Surface_Selection_Plugin::wheelEvent(View* view, QWheelEvent* event)
{
	if(m_selecting)
	{
439 440 441
		MapHandlerGen* mh = m_schnapps->getSelectedMap();
		const MapParameters& p = h_parameterSet[mh];

442
		switch(p.selectionMethod)
443
		{
444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459
			case SingleCell : {
				break;
			}
			case WithinSphere : {
				if(event->delta() > 0)
					m_selectionRadius *= 0.9f;
				else
					m_selectionRadius *= 1.1f;
				view->updateGL();
				break;
			}
			case NormalAngle : {
				if(event->delta() > 0)
					m_normalAngleThreshold *= 0.9f;
				else
					m_normalAngleThreshold *= 1.1f;
Pierre Kraemer's avatar
Pierre Kraemer committed
460
				// view->displayMessage(QString("Angle threshold : ") + m_normalAngleThreshold);
461 462
				break;
			}
463
		}
464 465 466
	}
}

467 468 469 470 471 472 473
void Surface_Selection_Plugin::viewLinked(View *view)
{
	MapHandlerGen* map = m_schnapps->getSelectedMap();
	if(map)
		m_selectionRadius = map->getBBdiagSize() / 50.0f;
}

474 475 476 477 478 479 480




void Surface_Selection_Plugin::selectedMapChanged(MapHandlerGen *prev, MapHandlerGen *cur)
{
	m_dockTab->updateMapParameters();
Pierre Kraemer's avatar
Pierre Kraemer committed
481 482 483 484
	if(prev)
	{
		disconnect(prev, SIGNAL(attributeAdded(unsigned int, const QString&)), this, SLOT(selectedMapAttributeAdded(unsigned int, const QString&)));
		disconnect(prev, SIGNAL(attributeModified(unsigned int, const QString&)), this, SLOT(selectedMapAttributeModified(unsigned int, const QString&)));
485
		disconnect(prev, SIGNAL(connectivityModified()), this, SLOT(selectedMapConnectivityModified()));
Pierre Kraemer's avatar
Pierre Kraemer committed
486
	}
487
	if(cur)
Pierre Kraemer's avatar
Pierre Kraemer committed
488 489 490
	{
		connect(cur, SIGNAL(attributeAdded(unsigned int, const QString&)), this, SLOT(selectedMapAttributeAdded(unsigned int, const QString&)));
		connect(cur, SIGNAL(attributeModified(unsigned int, const QString&)), this, SLOT(selectedMapAttributeModified(unsigned int, const QString&)));
491
		connect(cur, SIGNAL(connectivityModified()), this, SLOT(selectedMapConnectivityModified()));
492
		m_selectionRadius = cur->getBBdiagSize() / 50.0f;
Pierre Kraemer's avatar
Pierre Kraemer committed
493
	}
494 495
}

Pierre Kraemer's avatar
Pierre Kraemer committed
496 497
void Surface_Selection_Plugin::updateSelectedCellsRendering()
{
Pierre Kraemer's avatar
Pierre Kraemer committed
498 499
	MapHandlerGen* map = m_schnapps->getSelectedMap();
	const MapParameters& p = h_parameterSet[map];
Pierre Kraemer's avatar
Pierre Kraemer committed
500 501 502 503 504 505 506
	if(p.positionAttribute.isValid())
	{
		unsigned int orbit = m_schnapps->getCurrentOrbit();
		CellSelectorGen* selector = m_schnapps->getSelectedSelector(orbit);
		switch(orbit)
		{
			case VERTEX : {
507 508
				CellSelector<PFP2::MAP, VERTEX>* cs = static_cast<CellSelector<PFP2::MAP, VERTEX>*>(selector);
				const std::vector<Vertex>& selectedCells = cs->getSelectedCells();
Pierre Kraemer's avatar
Pierre Kraemer committed
509
				std::vector<PFP2::VEC3> selectedPoints;
510 511
				for(std::vector<Vertex>::const_iterator v = selectedCells.begin(); v != selectedCells.end(); ++v)
					selectedPoints.push_back(p.positionAttribute[*v]);
Pierre Kraemer's avatar
Pierre Kraemer committed
512 513 514 515
				m_selectedVerticesVBO->updateData(selectedPoints);
				break;
			}
			case EDGE : {
Pierre Kraemer's avatar
Pierre Kraemer committed
516 517
				PFP2::MAP* m = static_cast<MapHandler<PFP2>*>(map)->getMap();

518 519 520
				CellSelector<PFP2::MAP, EDGE>* cs = static_cast<CellSelector<PFP2::MAP, EDGE>*>(selector);
				const std::vector<Edge>& selectedCells = cs->getSelectedCells();

Pierre Kraemer's avatar
Pierre Kraemer committed
521 522 523 524
				m_selectedEdgesDrawer->newList(GL_COMPILE);
				m_selectedEdgesDrawer->lineWidth(3.0f);
				m_selectedEdgesDrawer->color3f(1.0f, 0.0f, 0.0f);
				m_selectedEdgesDrawer->begin(GL_LINES);
525
				for(std::vector<Edge>::const_iterator e = selectedCells.begin(); e != selectedCells.end(); ++e)
Pierre Kraemer's avatar
Pierre Kraemer committed
526
				{
527 528
					m_selectedEdgesDrawer->vertex(p.positionAttribute[(*e).dart]);
					m_selectedEdgesDrawer->vertex(p.positionAttribute[m->phi1((*e).dart)]);
Pierre Kraemer's avatar
Pierre Kraemer committed
529 530 531
				}
				m_selectedEdgesDrawer->end();
				m_selectedEdgesDrawer->endList();
Pierre Kraemer's avatar
Pierre Kraemer committed
532 533 534
				break;
			}
			case FACE : {
Pierre Kraemer's avatar
Pierre Kraemer committed
535 536
				PFP2::MAP* m = static_cast<MapHandler<PFP2>*>(map)->getMap();

537 538 539
				CellSelector<PFP2::MAP, FACE>* cs = static_cast<CellSelector<PFP2::MAP, FACE>*>(selector);
				const std::vector<Face>& selectedCells = cs->getSelectedCells();

Pierre Kraemer's avatar
Pierre Kraemer committed
540 541 542
				m_selectedFacesDrawer->newList(GL_COMPILE);
				m_selectedFacesDrawer->color3f(1.0f, 0.0f, 0.0f);
				m_selectedFacesDrawer->begin(GL_TRIANGLES);
543
				for(std::vector<Face>::const_iterator f = selectedCells.begin(); f != selectedCells.end(); ++f)
Pierre Kraemer's avatar
Pierre Kraemer committed
544
				{
545 546 547
					m_selectedFacesDrawer->vertex(p.positionAttribute[(*f).dart]);
					m_selectedFacesDrawer->vertex(p.positionAttribute[m->phi1((*f).dart)]);
					m_selectedFacesDrawer->vertex(p.positionAttribute[m->phi_1((*f).dart)]);
Pierre Kraemer's avatar
Pierre Kraemer committed
548 549 550
				}
				m_selectedFacesDrawer->end();
				m_selectedFacesDrawer->endList();
Pierre Kraemer's avatar
Pierre Kraemer committed
551 552 553 554 555 556 557
				break;
			}
		}
	}

	foreach(View* view, l_views)
	{
Pierre Kraemer's avatar
Pierre Kraemer committed
558
		if(view->isLinkedToMap(map))
Pierre Kraemer's avatar
Pierre Kraemer committed
559 560 561 562
			view->updateGL();
	}
}

563 564 565 566




Pierre Kraemer's avatar
Pierre Kraemer committed
567
void Surface_Selection_Plugin::selectedMapAttributeAdded(unsigned int orbit, const QString& name)
568
{
Pierre Kraemer's avatar
Pierre Kraemer committed
569
	if(orbit == VERTEX)
570 571 572
		m_dockTab->addVertexAttribute(name);
}

Pierre Kraemer's avatar
Pierre Kraemer committed
573 574 575 576 577 578 579 580 581 582 583
void Surface_Selection_Plugin::selectedMapAttributeModified(unsigned int orbit, const QString &name)
{
	if(orbit == VERTEX)
	{
		MapHandlerGen* map = static_cast<MapHandlerGen*>(QObject::sender());
		const MapParameters& p = h_parameterSet[map];
		if(p.positionAttribute.isValid() && QString::fromStdString(p.positionAttribute.name()) == name)
			updateSelectedCellsRendering();
	}
}

584 585 586 587 588 589 590 591
void Surface_Selection_Plugin::selectedMapConnectivityModified()
{
	MapHandlerGen* map = static_cast<MapHandlerGen*>(QObject::sender());
	const MapParameters& p = h_parameterSet[map];
	if(p.positionAttribute.isValid())
		updateSelectedCellsRendering();
}

592 593 594 595




596
void Surface_Selection_Plugin::changePositionAttribute(const QString& map, const QString& name)
597 598
{
	MapHandlerGen* m = m_schnapps->getMap(map);
599
	if(m)
600
	{
Pierre Kraemer's avatar
Pierre Kraemer committed
601 602
		MapHandler<PFP2>* mh = static_cast<MapHandler<PFP2>*>(m);
		h_parameterSet[m].positionAttribute = mh->getAttribute<PFP2::VEC3, VERTEX>(name);
603 604 605 606 607
		if(m->isSelectedMap())
			m_dockTab->updateMapParameters();
	}
}

608 609 610 611 612
void Surface_Selection_Plugin::changeNormalAttribute(const QString& map, const QString& name)
{
	MapHandlerGen* m = m_schnapps->getMap(map);
	if(m)
	{
Pierre Kraemer's avatar
Pierre Kraemer committed
613 614
		MapHandler<PFP2>* mh = static_cast<MapHandler<PFP2>*>(m);
		h_parameterSet[m].normalAttribute = mh->getAttribute<PFP2::VEC3, VERTEX>(name);
615 616 617 618 619 620
		if(m->isSelectedMap())
			m_dockTab->updateMapParameters();
	}
}

void Surface_Selection_Plugin::changeSelectionMethod(const QString& map, unsigned int method)
621 622
{
	MapHandlerGen* m = m_schnapps->getMap(map);
623
	if(m)
624 625 626
	{
		h_parameterSet[m].selectionMethod = SelectionMethod(method);
		if(m->isSelectedMap())
627 628
			m_dockTab->updateMapParameters();
	}
629 630 631 632 633 634 635
}

Q_EXPORT_PLUGIN2(Surface_Selection_Plugin, Surface_Selection_Plugin)

} // namespace SCHNApps

} // namespace CGoGN