cellSelector.h 2.05 KB
Newer Older
Pierre Kraemer's avatar
Pierre Kraemer committed
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 29 30 31 32 33 34 35 36 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
#ifndef _CELL_SELECTOR_H_
#define _CELL_SELECTOR_H_

#include <QString>

#include "Topology/generic/dart.h"
#include "Topology/generic/genericmap.h"
#include "Topology/generic/cellmarker.h"

namespace CGoGN
{

namespace SCHNApps
{

class CellSelectorGen
{
public:
	static unsigned int selectorCount;

	CellSelectorGen(const QString& name);
	virtual ~CellSelectorGen()
	{}

	inline const QString& getName() { return m_name; }

	inline const std::vector<Dart>& getSelectedCells() { return m_cells; }

	virtual unsigned int getOrbit() = 0;

//	virtual void select(Dart d) = 0;
//	virtual void unselect(Dart d) = 0;

//	virtual void select(const std::vector<Dart>& d) = 0;
//	virtual void unselect(const std::vector<Dart>& d) = 0;

//	virtual bool isSelected(Dart d) = 0;

private:
	QString m_name;
	std::vector<Dart> m_cells;
};

template <unsigned int ORBIT>
class CellSelector : public CellSelectorGen
{
public:
	CellSelector(GenericMap& m, const QString& name, unsigned int thread = 0) :
		CellSelectorGen(name),
		m_map(m),
		m_cm(m, thread)
	{}

	~CellSelector()
	{}

	inline unsigned int getOrbit() { return ORBIT; }

	inline void select(Dart d)
	{
		unsigned int v = m_map.getEmbedding<ORBIT>(d);
		if(!m_cm.isMarked(v))
		{
			m_cells.push_back(d);
			m_cm.mark(v);
		}
	}

	inline void unselect(Dart d)
	{
		unsigned int v = m_map.getEmbedding<ORBIT>(d);
		if(m_cm.isMarked(v))
		{
			bool found = false;
			unsigned int i;
			for(i = 0; i < m_cells.size() && !found; ++i)
			{
				if(m_map.getEmbedding<ORBIT>(m_cells[i]) == v)
					found = true ;
			}
			if(found)
			{
				m_cm.unmark(m_cells[i-1]);
				m_cells[i-1] = m_cells.back();
				m_cells.pop_back();
			}
		}
	}

	inline void select(const std::vector<Dart>& d)
	{
		for(unsigned int i = 0; i < d.size(); ++i)
			select(d[i]);
	}

	inline void unselect(const std::vector<Dart>& d)
	{
		for(unsigned int i = 0; i < d.size(); ++i)
			unselect(d[i]);
	}

	inline bool isSelected(Dart d)
	{
		return m_cm.isMarked(d);
	}

private:
	GenericMap& m_map;
	CellMarker<ORBIT> m_cm;
};

} // namespace SCHNApps

} // namespace CGoGN

#endif