#include "Utils/Shaders/shaderColorPerVertex.h" #include "Utils/Shaders/shaderSimpleColor.h" #include "Geometry/bounding_box.h" namespace CGoGN { namespace SCHNApps { 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 unsigned int MapHandler::getNbDarts() { return static_cast(m_map)->getNbDarts(); } template unsigned int MapHandler::getNbOrbits(unsigned int orbit) { return Algo::Topo::getNbOrbits(*static_cast(m_map), orbit); } template template AttributeHandler MapHandler::getAttribute(const QString& nameAttr, bool onlyRegistered) const { if(onlyRegistered) { if(m_attribs[ORBIT].contains(nameAttr)) return static_cast(m_map)->template getAttribute(nameAttr.toStdString()); else return AttributeHandler(); } else return static_cast(m_map)->template getAttribute(nameAttr.toStdString()); } template template AttributeHandler MapHandler::addAttribute(const QString& nameAttr, bool registerAttr) { AttributeHandler ah = static_cast(m_map)->template addAttribute(nameAttr.toStdString()); if(ah.isValid() && registerAttr) { registerAttribute(ah); DEBUG_EMIT("attributeAdded"); emit(attributeAdded(ORBIT, nameAttr)); } return ah; } template void MapHandler::draw(Utils::GLSLShader* shader, int primitive) { if(!m_render) m_render = new Algo::Render::GL2::MapRender(); if(!m_render->isPrimitiveUpToDate(primitive)) m_render->initPrimitives(*(static_cast(m_map)), primitive) ; m_render->draw(shader, primitive); } template void MapHandler::drawBB() { if(!m_bbDrawer) { m_bbDrawer = new Utils::Drawer(); updateBBDrawer(); } // QGLViewer::drawAxis(); m_bbDrawer->callList(); } template void MapHandler::updateBB(const VertexAttribute& position) { m_bb = CGoGN::Algo::Geometry::computeBoundingBox(*(static_cast(m_map)), position); m_bbDiagSize = m_bb.diagSize(); updateBBDrawer(); } template void MapHandler::updateBBDrawer() { if(!m_bbDrawer) m_bbDrawer = new Utils::Drawer(); Geom::Vec3f bbmin = m_bb.min(); Geom::Vec3f bbmax = m_bb.max(); float shift = 0.005f*(bbmax - bbmin).norm(); bbmin -= Geom::Vec3f(shift,shift,shift); bbmax += Geom::Vec3f(shift,shift,shift); 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(); } template CellSelectorGen* MapHandler::addCellSelector(unsigned int orbit, const QString& name) { if(m_cellSelectors[orbit].contains(name)) return NULL; CellSelectorGen* cs = NULL; MAP *m = static_cast(m_map); switch(orbit) { case DART: cs = new CellSelector(*m, name); break; case VERTEX: cs = new CellSelector(*m, name); break; case EDGE: cs = new CellSelector(*m, name); break; case FACE: cs = new CellSelector(*m, name); break; case VOLUME: cs = new CellSelector(*m, name); break; } if(!cs) return NULL; m_cellSelectors[orbit].insert(name, cs); DEBUG_EMIT("cellSelectorAdded"); emit(cellSelectorAdded(orbit, name)); connect(cs, SIGNAL(selectedCellsChanged()), this, SLOT(selectedCellsChanged())); return cs; } template template CellSelector* MapHandler::getCellSelector(const QString& name) const { if (m_cellSelectors[ORBIT].contains(name)) return static_cast*>(m_cellSelectors[ORBIT][name]); else return NULL; } template void MapHandler::createTopoRender(CGoGN::Utils::GLSLShader* sh1) { // std::cout << "MH:createTopo"<< std::endl; if (m_topoRender) return; if (m_map->dimension() == 2) { CGoGN::Utils::ShaderSimpleColor* ssc =static_cast(sh1); m_topoRender = new Algo::Render::GL2::TopoRender(ssc); m_topoRender->setInitialDartsColor(0.25f, 0.25f, 0.25f) ; } else std::cerr << "TOPO3 NOT SUPPORTED"<< std::endl; } template void MapHandler::updateTopoRender(const QString& positionName) { if (m_topoRender==NULL) return; typename PFP::MAP* map = this->getMap(); VertexAttribute position = map->template getAttribute(positionName.toStdString()) ; if(position.isValid()) { m_topoRender->updateData(*map,position,false); } } template void MapHandler::drawTopoRender(int code) { if (m_topoRender == NULL) return; m_topoRender->drawTopo(code); } template void MapHandler::transformedBB(qglviewer::Vec& bbMin, qglviewer::Vec& bbMax) { const Geom::Vec3f& BBmin = m_bb.min(); const Geom::Vec3f& BBMax = m_bb.max(); CGoGN::Geom::BoundingBox bb; qglviewer::Vec v = qglviewer::Vec(BBmin[0], BBmin[1], BBmin[2]); qglviewer::Vec vt = m_frame->inverseCoordinatesOf(v); bb.addPoint(Geom::Vec3f(vt[0], vt[1], vt[2])); v = qglviewer::Vec(BBMax[0], BBmin[1], BBmin[2]); vt = m_frame->inverseCoordinatesOf(v); bb.addPoint(Geom::Vec3f(vt[0], vt[1], vt[2])); v = qglviewer::Vec(BBmin[0], BBMax[1], BBmin[2]); vt = m_frame->inverseCoordinatesOf(v); bb.addPoint(Geom::Vec3f(vt[0], vt[1], vt[2])); v = qglviewer::Vec(BBmin[0], BBmin[1], BBMax[2]); vt = m_frame->inverseCoordinatesOf(v); bb.addPoint(Geom::Vec3f(vt[0], vt[1], vt[2])); v = qglviewer::Vec(BBMax[0], BBMax[1], BBmin[2]); vt = m_frame->inverseCoordinatesOf(v); bb.addPoint(Geom::Vec3f(vt[0], vt[1], vt[2])); v = qglviewer::Vec(BBMax[0], BBmin[1], BBMax[2]); vt = m_frame->inverseCoordinatesOf(v); bb.addPoint(Geom::Vec3f(vt[0], vt[1], vt[2])); v = qglviewer::Vec(BBmin[0], BBMax[1], BBMax[2]); vt = m_frame->inverseCoordinatesOf(v); bb.addPoint(Geom::Vec3f(vt[0], vt[1], vt[2])); v = qglviewer::Vec(BBMax[0], BBMax[1], BBMax[2]); vt = m_frame->inverseCoordinatesOf(v); bb.addPoint(Geom::Vec3f(vt[0], vt[1], vt[2])); bbMin = qglviewer::Vec(bb.min()[0], bb.min()[1], bb.min()[2]); bbMax = qglviewer::Vec(bb.max()[0], bb.max()[1], bb.max()[2]); } } // namespace SCHNApps } // namespace CGoGN