mapHandler.hpp 3.86 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

namespace CGoGN
{

namespace SCHNApps
{

template <typename T, unsigned int ORBIT>
AttributeHandler<T, ORBIT> MapHandlerGen::getAttribute(const QString& nameAttr, bool onlyRegistered) const
{
	if(onlyRegistered)
	{
		if(m_attribs[ORBIT].contains(nameAttr))
			return static_cast<AttribMap*>(m_map)->getAttribute<T,ORBIT>(nameAttr.toStdString());
		else
			return AttributeHandler<T, ORBIT>();
	}
	else
		return static_cast<AttribMap*>(m_map)->getAttribute<T,ORBIT>(nameAttr.toStdString());
}

template <typename T, unsigned int ORBIT>
AttributeHandler<T, ORBIT> MapHandlerGen::addAttribute(const QString& nameAttr, bool registerAttr)
{
	AttributeHandler<T,ORBIT> ah = static_cast<AttribMap*>(m_map)->addAttribute<T,ORBIT>(nameAttr.toStdString());
	if(ah.isValid() && registerAttr)
	{
		registerAttribute(ah);
		emit(attributeAdded(ORBIT, nameAttr));
	}
	return ah;
}

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 "";
}

47 48 49 50
template <unsigned int ORBIT>
CellSelector<ORBIT>* MapHandlerGen::getCellSelector(const QString& name) const
{
	if (m_cellSelectors[ORBIT].contains(name))
51
		return static_cast<CellSelector<ORBIT>*>(m_cellSelectors[ORBIT][name]);
52 53 54 55
	else
		return NULL;
}

Pierre Kraemer's avatar
Pierre Kraemer committed
56 57 58 59 60 61 62 63 64 65 66 67 68




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))
		m_render->initPrimitives<PFP>(*(static_cast<typename PFP::MAP*>(m_map)), primitive) ;

69 70
	glPushMatrix();
	glMultMatrixd(m_frame->matrix());
Pierre Kraemer's avatar
Pierre Kraemer committed
71
	m_render->draw(shader, primitive);
72
	glPopMatrix();
Pierre Kraemer's avatar
Pierre Kraemer committed
73 74 75 76 77 78 79 80 81 82
}

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

	glPushMatrix();
	glMultMatrixd(m_frame->matrix());
86
//	QGLViewer::drawAxis();
Pierre Kraemer's avatar
Pierre Kraemer committed
87
	m_bbDrawer->callList();
88
	glPopMatrix();
Pierre Kraemer's avatar
Pierre Kraemer committed
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 134 135 136 137 138 139 140 141 142 143
}

template <typename PFP>
void MapHandler<PFP>::updateBB(const VertexAttribute<typename PFP::VEC3>& position)
{
	m_bb = CGoGN::Algo::Geometry::computeBoundingBox<PFP>(*(static_cast<typename PFP::MAP*>(m_map)), position);
	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();
}

} // namespace SCHNApps

} // namespace CGoGN