Création d'un compte pour un collaborateur extérieur au laboratoire depuis l'intranet ICube : https://intranet.icube.unistra.fr/fr/labs/member/profile

mapHandler.hpp 4.78 KB
Newer Older
Pierre Kraemer's avatar
Pierre Kraemer committed
1
2
3
4
5
6
7

namespace CGoGN
{

namespace SCHNApps
{

Pierre Kraemer's avatar
Pierre Kraemer committed
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
inline void MapHandlerGen::registerAttribute(const AttributeHandlerGen& ah)
{
	m_attribs[ah.getOrbit()].insert(QString::fromStdString(ah.name()), QString::fromStdString(ah.typeName()));
}

inline QString MapHandlerGen::getAttributeTypeName(unsigned int orbit, const QString& nameAttr) const
{
	if(m_attribs[orbit].contains(nameAttr))
		return m_attribs[orbit][nameAttr];
	else
		return "";
}





template <typename PFP>
Pierre Kraemer's avatar
Pierre Kraemer committed
26
template <typename T, unsigned int ORBIT>
Pierre Kraemer's avatar
Pierre Kraemer committed
27
AttributeHandler<T, ORBIT, typename PFP::MAP::IMPL> MapHandler<PFP>::getAttribute(const QString& nameAttr, bool onlyRegistered) const
Pierre Kraemer's avatar
Pierre Kraemer committed
28
29
30
31
{
	if(onlyRegistered)
	{
		if(m_attribs[ORBIT].contains(nameAttr))
32
			return static_cast<MAP*>(m_map)->template getAttribute<T, ORBIT>(nameAttr.toStdString());
Pierre Kraemer's avatar
Pierre Kraemer committed
33
		else
Pierre Kraemer's avatar
Pierre Kraemer committed
34
			return AttributeHandler<T, ORBIT, MAP_IMPL>();
Pierre Kraemer's avatar
Pierre Kraemer committed
35
36
	}
	else
37
		return static_cast<MAP*>(m_map)->template getAttribute<T, ORBIT>(nameAttr.toStdString());
Pierre Kraemer's avatar
Pierre Kraemer committed
38
39
}

Pierre Kraemer's avatar
Pierre Kraemer committed
40
template <typename PFP>
Pierre Kraemer's avatar
Pierre Kraemer committed
41
template <typename T, unsigned int ORBIT>
Pierre Kraemer's avatar
Pierre Kraemer committed
42
AttributeHandler<T, ORBIT, typename PFP::MAP::IMPL> MapHandler<PFP>::addAttribute(const QString& nameAttr, bool registerAttr)
Pierre Kraemer's avatar
Pierre Kraemer committed
43
{
44
	AttributeHandler<T, ORBIT, MAP_IMPL> ah = static_cast<MAP*>(m_map)->template addAttribute<T, ORBIT>(nameAttr.toStdString());
Pierre Kraemer's avatar
Pierre Kraemer committed
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
	if(ah.isValid() && registerAttr)
	{
		registerAttribute(ah);
		emit(attributeAdded(ORBIT, nameAttr));
	}
	return ah;
}

template <typename PFP>
void MapHandler<PFP>::draw(Utils::GLSLShader* shader, int primitive)
{
	if(!m_render)
		m_render = new Algo::Render::GL2::MapRender();

	if(!m_render->isPrimitiveUpToDate(primitive))
Pierre Kraemer's avatar
Pierre Kraemer committed
60
		m_render->initPrimitives<PFP>(*(static_cast<MAP*>(m_map)), primitive) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
61

62
63
	glPushMatrix();
	glMultMatrixd(m_frame->matrix());
Pierre Kraemer's avatar
Pierre Kraemer committed
64
	m_render->draw(shader, primitive);
65
	glPopMatrix();
Pierre Kraemer's avatar
Pierre Kraemer committed
66
67
68
69
70
71
72
73
74
75
}

template <typename PFP>
void MapHandler<PFP>::drawBB()
{
	if(!m_bbDrawer)
	{
		m_bbDrawer = new Utils::Drawer();
		updateBBDrawer();
	}
76
77
78

	glPushMatrix();
	glMultMatrixd(m_frame->matrix());
79
//	QGLViewer::drawAxis();
Pierre Kraemer's avatar
Pierre Kraemer committed
80
	m_bbDrawer->callList();
81
	glPopMatrix();
Pierre Kraemer's avatar
Pierre Kraemer committed
82
83
84
}

template <typename PFP>
Pierre Kraemer's avatar
Pierre Kraemer committed
85
void MapHandler<PFP>::updateBB(const VertexAttribute<VEC3, MAP_IMPL>& position)
Pierre Kraemer's avatar
Pierre Kraemer committed
86
{
Pierre Kraemer's avatar
Pierre Kraemer committed
87
	m_bb = CGoGN::Algo::Geometry::computeBoundingBox<PFP>(*(static_cast<MAP*>(m_map)), position);
Pierre Kraemer's avatar
Pierre Kraemer committed
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
	m_bbMin = qglviewer::Vec(m_bb.min()[0], m_bb.min()[1], m_bb.min()[2]);
	m_bbMax = qglviewer::Vec(m_bb.max()[0], m_bb.max()[1], m_bb.max()[2]);
	m_bbDiagSize = (m_bbMax - m_bbMin).norm();

	updateBBDrawer();
}

template <typename PFP>
void MapHandler<PFP>::updateBBDrawer()
{
	if(!m_bbDrawer)
		m_bbDrawer = new Utils::Drawer();

	const Geom::Vec3f& bbmin = m_bb.min();
	const Geom::Vec3f& bbmax = m_bb.max();

	m_bbDrawer->newList(GL_COMPILE);
	m_bbDrawer->color3f(0.0f,1.0f,0.0f);
	m_bbDrawer->lineWidth(1.0f);
	m_bbDrawer->begin(GL_LINE_LOOP);
	m_bbDrawer->vertex(bbmin);
	m_bbDrawer->vertex3f(bbmin[0], bbmax[1], bbmin[2]);
	m_bbDrawer->vertex3f(bbmax[0], bbmax[1], bbmin[2]);
	m_bbDrawer->vertex3f(bbmax[0], bbmin[1], bbmin[2]);
	m_bbDrawer->vertex(bbmin);
	m_bbDrawer->end();
	m_bbDrawer->begin(GL_LINE_LOOP);
	m_bbDrawer->vertex(bbmax);
	m_bbDrawer->vertex3f(bbmax[0], bbmin[1], bbmax[2]);
	m_bbDrawer->vertex3f(bbmin[0], bbmin[1], bbmax[2]);
	m_bbDrawer->vertex3f(bbmin[0], bbmax[1], bbmax[2]);
	m_bbDrawer->vertex(bbmax);
	m_bbDrawer->end();
	m_bbDrawer->begin(GL_LINES);
	m_bbDrawer->vertex(bbmin);
	m_bbDrawer->vertex3f(bbmin[0], bbmin[1], bbmax[2]);
	m_bbDrawer->vertex3f(bbmin[0], bbmax[1], bbmin[2]);
	m_bbDrawer->vertex3f(bbmin[0], bbmax[1], bbmax[2]);
	m_bbDrawer->vertex3f(bbmax[0], bbmax[1], bbmin[2]);
	m_bbDrawer->vertex(bbmax);
	m_bbDrawer->vertex3f(bbmax[0], bbmin[1], bbmin[2]);
	m_bbDrawer->vertex3f(bbmax[0], bbmin[1], bbmax[2]);
	m_bbDrawer->end();
	m_bbDrawer->endList();
}

Pierre Kraemer's avatar
Pierre Kraemer committed
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
template <typename PFP>
CellSelectorGen* MapHandler<PFP>::addCellSelector(unsigned int orbit, const QString& name)
{
	if(m_cellSelectors[orbit].contains(name))
		return NULL;

	CellSelectorGen* cs = NULL;
	MAP *m = static_cast<MAP*>(m_map);

	switch(orbit)
	{
		case DART: cs = new CellSelector<MAP, DART>(*m, name); break;
		case VERTEX: cs = new CellSelector<MAP, VERTEX>(*m, name); break;
		case EDGE: cs = new CellSelector<MAP, EDGE>(*m, name); break;
		case FACE: cs = new CellSelector<MAP, FACE>(*m, name); break;
		case VOLUME: cs = new CellSelector<MAP, VOLUME>(*m, name); break;
	}

	if(!cs)
		return NULL;

	m_cellSelectors[orbit].insert(name, cs);
	emit(cellSelectorAdded(orbit, name));

	connect(cs, SIGNAL(selectedCellsChanged()), this, SLOT(selectedCellsChanged()));

	return cs;
}

template <typename PFP>
template <unsigned int ORBIT>
CellSelector<typename PFP::MAP, ORBIT>* MapHandler<PFP>::getCellSelector(const QString& name) const
{
	if (m_cellSelectors[ORBIT].contains(name))
		return static_cast<CellSelector<MAP, ORBIT>*>(m_cellSelectors[ORBIT][name]);
	else
		return NULL;
}

Pierre Kraemer's avatar
Pierre Kraemer committed
173
174
175
} // namespace SCHNApps

} // namespace CGoGN