/******************************************************************************* * CGoGN: Combinatorial and Geometric modeling with Generic N-dimensional Maps * * version 0.1 * * Copyright (C) 2009, IGG Team, LSIIT, University of Strasbourg * * * * This library is free software; you can redistribute it and/or modify it * * under the terms of the GNU Lesser General Public License as published by the * * Free Software Foundation; either version 2.1 of the License, or (at your * * option) any later version. * * * * This library is distributed in the hope that it will be useful, but WITHOUT * * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License * * for more details. * * * * You should have received a copy of the GNU Lesser General Public License * * along with this library; if not, write to the Free Software Foundation, * * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * * * Web site: https://iggservis.u-strasbg.fr/CGoGN/ * * Contact information: cgogn@unistra.fr * * * *******************************************************************************/ #include "viewer.h" #include "env_generator.h" #include #include "glm/gtc/type_ptr.hpp" #include "Algo/Export/export.h" SocialAgents::SocialAgents(unsigned int config, unsigned int minSize, unsigned int nbAgent, unsigned int nbObst,bool resolution, unsigned int iterations) : #ifdef EXPORTING_OBJ m_objAgent(mapAgent), #endif m_renderStyle(0), nbIterations(0), maxIterations(iterations), nbGeneratedPov(0), frames(0), nextUpdate(0), simulator(config, minSize, nbAgent, nbObst, resolution), render_anim(false), drawEnvLines(true), drawEnvFaces(true), drawEnvTopo(false), drawObstacles(false), drawMovingObstacles(true), drawAgents(true), drawAgentsNeighborDist(false), drawAgentsObstacleDist(false), drawAgentsPredictionTri(false), drawAgentsPath(false), drawObstPredictionTri(false), drawObstPath(false), draw_dart(false), target_Agent(false), draw_posX(false), draw_elipse(false), display_times(false) { timer = new QTimer(this) ; switch (config){ case 0 :name<<"cercle_";break; case 1 :name<<"corridor_";break; case 2 :name<<"corridorSnake_";break; case 3 :name<<"ville_";break; case 5 :name<<"strasbourg_";break; default : break; } filename<setChecked(render_anim); dock.check_drawEnvLines->setChecked(drawEnvLines) ; dock.check_drawEnvFaces->setChecked(drawEnvFaces) ; dock.check_drawAgents->setChecked(drawAgents) ; dock.check_drawMovingObstacles->setChecked(drawMovingObstacles) ; setCallBack(dock.check_timer, SIGNAL(toggled(bool)), SLOT(slot_timer(bool))) ; setCallBack(dock.check_drawEnvLines, SIGNAL(toggled(bool)), SLOT(slot_drawEnvLines(bool))) ; setCallBack(dock.check_drawEnvFaces, SIGNAL(toggled(bool)), SLOT(slot_drawEnvFaces(bool))) ; setCallBack(dock.check_drawEnvTopo, SIGNAL(toggled(bool)), SLOT(slot_drawEnvTopo(bool))) ; setCallBack(dock.check_drawObstacles, SIGNAL(toggled(bool)), SLOT(slot_drawObstacles(bool))) ; setCallBack(dock.check_drawMovingObstacles, SIGNAL(toggled(bool)), SLOT(slot_drawMovingObstacles(bool))) ; setCallBack(dock.check_drawAgents, SIGNAL(toggled(bool)), SLOT(slot_drawAgents(bool))) ; setCallBack(dock.check_drawAgentsPredictionTri, SIGNAL(toggled(bool)), SLOT(slot_drawAgentsPredictionTri(bool))) ; setCallBack(dock.check_drawObstPredictionTri, SIGNAL(toggled(bool)), SLOT(slot_drawObstPredictionTri(bool))) ; setCallBack(dock.check_drawAgentsNeighborDist, SIGNAL(toggled(bool)), SLOT(slot_drawAgentsNeighborDist(bool))) ; setCallBack(dock.check_drawAgentsObstacleDist, SIGNAL(toggled(bool)), SLOT(slot_drawAgentsObstacleDist(bool))) ; setCallBack(dock.check_drawAgentsPath, SIGNAL(toggled(bool)), SLOT(slot_drawAgentsPath(bool))) ; setCallBack(dock.check_drawObstPath, SIGNAL(toggled(bool)), SLOT(slot_drawObstPath(bool))) ; setCallBack(dock.check_dart, SIGNAL(toggled(bool)), SLOT(slot_dart(bool))) ; setCallBack(dock.check_slide, SIGNAL(valueChanged(int)), SLOT(slot_slide(int))) ; setCallBack(dock.check_pos, SIGNAL(toggled(bool)), SLOT(slot_posX(bool))) ; setCallBack(dock.check_x_val, SIGNAL(valueChanged(int)), SLOT(slot_slide2(int))) ; setCallBack(dock.check_y_val, SIGNAL(valueChanged(int)), SLOT(slot_slide3(int))) ; setCallBack(dock.check_elipse, SIGNAL(toggled(bool)), SLOT(slot_elipse(bool))) ; setCallBack(dock.checkAgent, SIGNAL(toggled(bool)), SLOT(slot_Agent(bool))) ; setCallBack(dock.AgentSelect, SIGNAL(valueChanged(int)), SLOT(slot_AgentSlider(int))) ; dock.check_x_val->setRange(-100000, 100000) ; dock.check_y_val->setRange(-100000, 100000) ; } void SocialAgents::cb_initGL() { std::cout << "initGL" << std::endl; colClear = Geom::Vec4f(0.7f, 0.7f, 0.7f, 0.5f) ; colDif = Geom::Vec4f(0.3f, 0.3f, 0.3f, 1.0f) ; colSpec = Geom::Vec4f(0.9f, 0.9f, 0.9f, 1.0f) ; colNormal = Geom::Vec4f(1.0f, 0.0f, 0.0f, 1.0f) ; bb = Algo::Geometry::computeBoundingBox(simulator.envMap_.map, simulator.envMap_.position) ; if(simulator.config==5) { Geom::BoundingBox bbBuilding = Algo::Geometry::computeBoundingBox(simulator.envMap_.mapScenary, simulator.envMap_.positionScenary) ; bb.addPoint(bbBuilding.min()); bb.addPoint(bbBuilding.max()); } VEC3 gPosObj = bb.center() ; float tailleX = bb.size(0) ; float tailleY = bb.size(1) ; float tailleZ = bb.size(2) ; float gWidthObj = std::max(std::max(tailleX, tailleY), tailleZ) ; if(simulator.config<6) gWidthObj /= 5.0f; setParamObject(gWidthObj, gPosObj.data()) ; std::cout << "Bb " << bb << std::endl; // choose to use GL version 2 Utils::GLSLShader::setCurrentOGLVersion(2); // create the render m_render = new Algo::Render::GL2::MapRender(); #ifdef ONERING m_renderWithin = new Algo::Render::GL2::MapRender(); #endif m_renderTopo = new Algo::Render::GL2::TopoRender(); m_ds = new Utils::Drawer(); if(simulator.config==5) m_renderPedway = new Algo::Render::GL2::MapRender(); // create VBO for position m_positionVBO = new Utils::VBO(); m_normalVBO = new Utils::VBO() ; // using simple shader with color m_simpleColorShader = new Utils::ShaderSimpleColor(); m_simpleColorShader->setAttributePosition(m_positionVBO); m_simpleColorShader->setColor(Geom::Vec4f(0.,1.,0.,0.)); m_positionVBO->updateData(simulator.envMap_.position) ; m_normalVBO->updateData(simulator.envMap_.normal) ; if(simulator.config==5) { m_render_scenary = new Algo::Render::GL2::MapRender(); m_positionVBO_scenary = new Utils::VBO(); m_normalVBO_scenary = new Utils::VBO() ; m_positionVBO_scenary->updateData(simulator.envMap_.positionScenary) ; m_normalVBO_scenary->updateData(simulator.envMap_.normalScenary) ; #ifdef EXPORTING m_flatShader_scenary = new ShaderCustom(); #else m_flatShader_scenary = new Utils::ShaderFlat(); #endif m_flatShader_scenary->setAttributePosition(m_positionVBO_scenary); m_flatShader_scenary->setAmbiant(colClear) ; m_flatShader_scenary->setDiffuse(colDif) ; registerShader(m_flatShader_scenary); } m_agentsVBO = new Utils::VBO(); m_agentsVBO->setDataSize(3); m_agentsVBO->allocate(simulator.agents_.size()); PFP::VEC3* data = static_cast(m_agentsVBO->lockPtr()); for (unsigned int i=0; i< simulator.agents_.size(); ++i) { VEC3 p = simulator.agents_[i]->getPosition(); data[i] = p; } m_agentsVBO->releasePtr(); m_sprite = new Utils::PointSprite(); m_sprite->setAttributePosition(m_agentsVBO); m_sprite->setSize(Agent::radius_); // m_sprite->setSize((50.0f/gWidthObj) * Agent::radius_ ); registerShader(m_simpleColorShader); registerShader(m_sprite); qglviewer::Camera* cam = getQGLWidget()->camera(); cam->setSceneRadius(10000); initRendering(); } void SocialAgents::initRendering() { // dCD = new Utils::Drawer(); // registerShader(dCD->getShader()); if(simulator.config==5) { m_render_scenary->initPrimitives(simulator.envMap_.mapScenary, Algo::Render::GL2::LINES,false) ; m_render_scenary->initPrimitives(simulator.envMap_.mapScenary, Algo::Render::GL2::TRIANGLES,false) ; MapBrowserSelector mbs(simulator.envMap_.map,SelectorCellMarked(simulator.envMap_.pedWayMark)); simulator.envMap_.map.setBrowser(&mbs); m_render->initPrimitives(simulator.envMap_.map, Algo::Render::GL2::TRIANGLES,false) ; m_renderPedway->initPrimitives(simulator.envMap_.map, Algo::Render::GL2::TRIANGLES,false) ; simulator.envMap_.map.setBrowser(NULL); m_render->initPrimitives(simulator.envMap_.map, Algo::Render::GL2::LINES,false) ; m_renderPedway->initPrimitives(simulator.envMap_.map, Algo::Render::GL2::LINES,false) ; } else { m_render->initPrimitives(simulator.envMap_.map, Algo::Render::GL2::LINES,false) ; m_render->initPrimitives(simulator.envMap_.map, Algo::Render::GL2::TRIANGLES,false) ; #ifdef ONERING m_renderWithin->initPrimitives(simulator.envMap_.map, Algo::Render::GL2::TRIANGLES,false) ; #endif } m_renderTopo->updateData(simulator.envMap_.map, simulator.envMap_.position, 0.9, 0.9); for(unsigned int i=0 ; i < simulator.movingObstacles_.size() ; ++i) { m_obst_render.push_back(new Algo::Render::GL2::MapRender()); Utils::ShaderFlat * shader = new Utils::ShaderFlat(); shader->setAmbiant(Geom::Vec4f(1.,1.,0.,0.)) ; shader->setDiffuse(Geom::Vec4f(1.,1.,0.,0.)); Utils::VBO * vbo = new Utils::VBO(); vbo->setDataSize(3); vbo->allocate(simulator.movingObstacles_[i]->nbVertices); shader->setAttributePosition(vbo); m_obst_VBO.push_back(vbo); m_obstShader.push_back(shader); registerShader(shader); simulator.movingObstacles_[i]->initGL(); #ifdef EXPORTING_BOXES registerShader(simulator.movingObstacles_[i]->m_shader); #endif } updateObstacleVBO(); #ifdef EXPORTING #if 0 m_Ground_VBO = new Utils::VBO(); m_Ground_VBO->setDataSize(3); m_Ground_VBO->allocate(4); PFP::VEC3* data = static_cast(m_Ground_VBO->lockPtr()); data[0] = VEC3(bb.min()[0], bb.min()[1], 0); data[1] = VEC3(bb.max()[0], bb.min()[1], 0); data[2] = VEC3(bb.max()[0], bb.max()[1], 0); data[3] = VEC3(bb.min()[0], bb.max()[1], 0); m_Ground_VBO->releasePtr(); #else m_Ground_VBO = new Utils::VBO(); m_Ground_VBO->setDataSize(3); m_Ground_VBO->allocate(4*N_THETA*N_PHI); PFP::VEC3* data = static_cast(m_Ground_VBO->lockPtr()); for( unsigned int i=0, n=0; ireleasePtr(); #endif m_Ground_Shader = new Utils::ShaderFlat(); m_Ground_Shader->setAmbiant (Geom::Vec4f(0.6f, 0.8f, 0.6f, 1.0f)); m_Ground_Shader->setDiffuse (Geom::Vec4f(0.0f, 0.0f, 0.0f, 1.0f)); m_Ground_Shader->setAttributePosition(m_Ground_VBO); registerShader(m_Ground_Shader); if( !m_DeferedShader.loadShaders("./shaders/Defered.vert", "./shaders/Defered.frag") ) std::cout << __FUNCTION__ << ": pas glop!" << std::endl; if( !m_DeferedShader2.loadShaders("./shaders/Defered2.vert", "./shaders/Defered2.frag") ) std::cout << __FUNCTION__ << ": pas glop!" << std::endl; #endif for(unsigned int i = 0 ; i < simulator.movingMeshes_.size() ; ++i) { simulator.movingMeshes_[i]->initGL(); #ifdef EXPORTING2 registerShader(simulator.movingMeshes_[i]->m_shaderTex); #else registerShader(simulator.movingMeshes_[i]->m_simpleColorShader); #endif } simulator.envMap_.initGL(); #ifdef EXPORTING3 for(unsigned int j = 0 ; j < simulator.envMap_.m_shaderTex_Export.size() ; ++j) registerShader(simulator.envMap_.m_shaderTex_Export[j]); #endif #ifdef EXPORTING_OBJ std::vector attrNames ; // m_objAgent.import("./meshRessources/scenario3/mexicain_occ.obj",attrNames); m_objAgent.import("./meshRessources/Mexicainlowres2.obj",attrNames); // m_objAgent.import("./meshRessources/Mexicainhighres.obj",attrNames); positionAgent = mapAgent.getAttribute(attrNames[0]) ; // Geom::BoundingBox bb ; // bb = Algo::Geometry::computeBoundingBox(map, position) ; // std::cout << "bb agent " << bb << std::endl; TraversorV tV(mapAgent); for(Dart d = tV.begin() ; d != tV.end() ; d = tV.next()) { positionAgent[d] /= 12.0f; positionAgent[d] *= Agent::radius_; } m_texcoordVBOAgent = new Utils::VBO(); m_positionVBOAgent = new Utils::VBO(); m_normalVBOAgent = new Utils::VBO(); m_textureAgent = new Utils::Texture<2,Geom::Vec3uc>(GL_UNSIGNED_BYTE); // if (m_textureAgent->load("./meshRessources/sombrero2lowres_grp.png")) if (m_textureAgent->load("./meshRessources/sombrero2_grp.png")) // if (m_textureAgent->load("./meshRessources/scenario3/mexicain_occ.png")) m_textureAgent->update(); else std::cout << "problem : loading texture" << std::endl; m_textureAgent->setWrapping(GL_CLAMP_TO_EDGE); // m_shaderTexAgent = new ShaderCustomTex(); m_shaderTexAgent = new ShaderPhongTexCust(); m_shaderTexAgent->setAttributePosition(m_positionVBOAgent); m_shaderTexAgent->setAttributeTexCoord(m_texcoordVBOAgent); m_shaderTexAgent->setTextureUnit(GL_TEXTURE0); m_shaderTexAgent->setTexture(m_textureAgent); m_shaderTexAgent->setAttributeNormal(m_normalVBOAgent); m_shaderTexAgent->setShininess(0.1f); m_shaderTexAgent->setAmbient(0.5f); m_shaderTexAgent->setSpecular(Geom::Vec4f(0.05)); glEnable(GL_TEXTURE_2D); if (!m_objAgent.hasNormals()) { normalAgent = mapAgent.getAttribute("normal") ; if(!normalAgent.isValid()) normalAgent = mapAgent.addAttribute("normal") ; Algo::Surface::Geometry::computeNormalVertices(mapAgent, m_objAgent.m_positions, normalAgent) ; m_objAgent.setNormalAttribute(normalAgent); } mapAgent.setBrowser(NULL); m_nbIndicesAgent = m_objAgent.createSimpleVBO_PTN(m_positionVBOAgent,m_texcoordVBOAgent,m_normalVBOAgent); registerShader(m_shaderTexAgent); #endif #ifdef EXPORTING_AGENT for (unsigned int i=0; i< simulator.agents_.size(); ++i) { simulator.agents_[i]->initGL(); // //#ifdef EXPORTING_OBJ // registerShader(simulator.agents_[i]->m_shaderTex); //#endif registerShader(simulator.agents_[i]->m_ghost_shader); } #endif // bb = Algo::Geometry::computeBoundingBox(simulator.envMap_.m_map_Export, simulator.envMap_.position_Export) ; // // VEC3 gPosObj = bb.center() ; // float tailleX = bb.size(0) ; // float tailleY = bb.size(1) ; // float tailleZ = bb.size(2) ; // float gWidthObj = std::max(std::max(tailleX, tailleY), tailleZ);///10.0f ; // setParamObject(gWidthObj, gPosObj.data()) ; } void SocialAgents::updateObstacleVBO() { for(unsigned int i=0 ; i < simulator.movingObstacles_.size() ; ++i) { Utils::VBO * vbo = m_obst_VBO[i]; PFP::VEC3* data = static_cast(vbo->lockPtr()); for (unsigned int j=0; j< simulator.movingObstacles_[i]->nbVertices; ++j) { VEC3 p = simulator.movingObstacles_[i]->getDilatedPosition(j); data[j] = p; } vbo->releasePtr(); } } void SocialAgents::updateObstaclePredTriVBO() { // CGoGNout<<"update"<(vbo->lockPtr()); for(unsigned int j =0; jnbVertices; j++ ) { VEC3 p = simulator.movingObstacles_[i]->getDilatedPosition(j); data[j*4+0] = p; data[j*4+3] = p; p = simulator.envMap_.position[simulator.movingObstacles_[i]->parts_[j]->d]; data[j*4+1] = p; p = simulator.envMap_.position[simulator.envMap_.map.phi1(simulator.movingObstacles_[i]->parts_[j]->d)]; data[j*4+2] = p; } vbo->releasePtr(); } } void SocialAgents::updateAgentPredTriVBO() { for(unsigned int i=0 ; i < simulator.agents_.size() ; ++i) { Utils::VBO * vbo = m_triAgent_VBO[i]; PFP::VEC3* data = static_cast(vbo->lockPtr()); VEC3 p = simulator.agents_[i]->getPosition(); data[0] = p; p = simulator.envMap_.position[simulator.agents_[i]->part_.d]; data[1] = p; p = simulator.envMap_.position[simulator.envMap_.map.phi1(simulator.agents_[i]->part_.d)]; data[2] = p; vbo->releasePtr(); } } void SocialAgents::updateVBOprimitives(int upType) { #ifdef ONERING CellMarker cmF(simulator.envMap_.map); for(unsigned int i = 0 ; i < simulator.movingObstacles_.size() ; ++i) { MovingObstacle * mo =simulator.movingObstacles_[i]; for (std::vector >::iterator it = mo->general_belonging.begin(); it != mo->general_belonging.end(); ++it) { if(!cmF.isMarked((*it).first)) { cmF.mark((*it).first); } } } MapBrowserSelector mbs1(simulator.envMap_.map,SelectorCellMarked(cmF)); simulator.envMap_.map.setBrowser(&mbs1); if(upType & Algo::Render::GL2::TRIANGLES) m_render->initPrimitives(simulator.envMap_.map, Algo::Render::GL2::TRIANGLES, false) ; simulator.envMap_.map.setBrowser(NULL); CellMarker cmF2(simulator.envMap_.map); for(unsigned int i = 0 ; i < simulator.movingObstacles_.size() ; ++i) { MovingObstacle * mo =simulator.movingObstacles_[i]; int n =mo->nbParticles; for (int i = 0; i< n-1;i++) { for (std::vector::iterator it = mo->neighbor_cells[i].begin(); it != mo->neighbor_cells[i].end(); ++it) { if(!cmF.isMarked(*it)&& !cmF2.isMarked(*it)) { cmF2.mark(*it); } } } } MapBrowserSelector mbs2(simulator.envMap_.map,SelectorCellMarked(cmF2)); simulator.envMap_.map.setBrowser(&mbs2); if(upType & Algo::Render::GL2::TRIANGLES) m_renderWithin->initPrimitives(simulator.envMap_.map, Algo::Render::GL2::TRIANGLES, false) ; simulator.envMap_.map.setBrowser(NULL); #else if(upType & Algo::Render::GL2::TRIANGLES) m_render->initPrimitives(simulator.envMap_.map, Algo::Render::GL2::TRIANGLES, false) ; #endif if(upType & Algo::Render::GL2::LINES) m_render->initPrimitives(simulator.envMap_.map, Algo::Render::GL2::LINES,false) ; if(upType & Algo::Render::GL2::POINTS) m_render->initPrimitives(simulator.envMap_.map, Algo::Render::GL2::POINTS) ; } //----------------------------------- // An ellipse has two foci placed at // F1 and F2. The ellipse is the set // of points M for whom MF1 + MF2 = s //static void drawEllipse(VEC3 F1, VEC3 F2, float s, int N) //{ // float a,b=0; // VEC3 O,u,v; // O = 0.5f*(F1+F2); // u = F1-F2; // float c = (F1-F2).norm(); // if(c==0) // { // u[0] = 1.0; // u[1] = 0.0; // v[0] = 0.0; // v[1] = 1.0; // a=s/2; // b=s/2; // } // else // c>0 // { // u = (1.0f/c) * u; // v.zero(); // v[0] = u[1]; // v[1] = -u[0]; // // c = 0.5 * c; // a = s/2.0; // if(a= c // b = sqrt( a*a - c*c ); // } // glBegin(GL_LINE_LOOP); // VEC3 M; // float dtheta = 2 * M_PI / N; // float theta; // for(theta=0; theta<2*M_PI; theta+=dtheta) // { // M = O + a*cos(theta)*u + b*sin(theta)*v; // glColor3f(0,0,1); // glVertex2f(M[0],M[1]); // } // glEnd(); //} //----------------------------------- void SocialAgents::moveCameraTo(VEC3 newPos) { float& x = trans_x(); float& y = trans_y(); float& z = trans_z(); x = newPos[0]; y = newPos[1]; z = newPos[2]; // transfoTranslate(newPos[0],newPos[1],newPos[2]); // float * quat = curquat(); // // float theta = M_PI/2.0f; // float qx = 1 * sin(theta/2.0f); // float qy = 0 * sin(theta/2.0f); // float qz = 0 * sin(theta/2.0f); // float qw = cos(theta/2.0f); // // quat[0] = qx; // quat[1] = qy; // quat[2] = qz; // quat[3] = qw; updateGLMatrices(); } void SocialAgents::cb_redraw() { pushTransfoMatrix(); #ifdef EXPORTING Utils::FBO fbo( width(), height() ); int deferedColorAttachment = fbo.createAttachColorTexture( GL_RGB ); int deferedNormalAttachment = fbo.createAttachColorTexture( GL_RGB ); fbo.createAttachDepthTexture(); fbo.bind(); fbo.enableAllColorAttachments(); #endif glClearColor( 0.8f, 0.8f, 1.0f, 1.0f ); glClear( GL_COLOR_BUFFER_BIT ); // glEnable(GL_CULL_FACE); glEnable(GL_MULTISAMPLE); glEnable(GL_LINE_SMOOTH); glHint(GL_LINE_SMOOTH_HINT, GL_NICEST); glEnable(GL_POINT_SMOOTH); glHint(GL_POINT_SMOOTH_HINT, GL_NICEST); glPolygonMode(GL_FRONT_AND_BACK, GL_FILL) ; glEnable(GL_LIGHTING); glEnable( GL_MULTISAMPLE ); simulator.envMap_.draw(); dock.check_slide->setRange(0, simulator.envMap_.map.end().index) ; if (drawAgents) { if(drawAgentsPath) { for (unsigned int i=0; i< simulator.agents_.size(); ++i) { Agent * ag = simulator.agents_[i]; m_ds->newList(GL_COMPILE_AND_EXECUTE); m_ds->begin(GL_LINE_STRIP); VEC3 col = Utils::color_map_BCGYR(float(ag->agentNo)/float(simulator.agents_.size())); m_ds->color3f(col[0],col[1],col[2]); m_ds->vertex(ag->getPosition()); for(unsigned int i = 0 ; i < ag->goals_.size() ; i++) { m_ds->vertex(ag->goals_[(ag->curGoal_+i)%(ag->goals_.size())]); } m_ds->end(); m_ds->endList(); } } #ifdef EXPORTING_OBJ for (unsigned int i=0; i< simulator.agents_.size(); ++i) { m_nbIndicesAgent = m_objAgent.createSimpleVBO_PTN(m_positionVBOAgent,m_texcoordVBOAgent,m_normalVBOAgent); glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); m_shaderTexAgent->setTransformation(simulator.agents_[i]->m_transfo); m_shaderTexAgent->activeTexture(); m_shaderTexAgent->enableVertexAttribs(); glDrawArrays(GL_TRIANGLES, 0, m_nbIndicesAgent); m_shaderTexAgent->disableVertexAttribs(); } #else //test thomas P // glDisable(GL_LIGHTING); // for (unsigned int i=0; i< simulator.agents_.size(); ++i) // { // VEC3 pos =simulator.agents_[i]->part_.getPosition(); // m_ds->newList(GL_COMPILE_AND_EXECUTE); // m_ds->lineWidth(5.0f); // m_ds->pointSize(10.0f); // m_ds->begin(GL_POINTS); // // fait varier la couleur du plus pres au plus loin // // m_ds->color3f(simulator.agents_[i]->color1 , simulator.agents_[i]->color2, simulator.agents_[i]->color3); // // m_ds->vertex(pos); // // m_ds->end(); // m_ds->endList(); // } // /// save PFP::VEC3* data = static_cast(m_agentsVBO->lockPtr()); for (unsigned int i=0; i< simulator.agents_.size(); ++i) { VEC3 p = simulator.agents_[i]->getPosition(); data[i] = p; } m_agentsVBO->releasePtr(); m_sprite->predraw(Geom::Vec3f(1.0f, 0.0f ,0.0f)); m_sprite->enableVertexAttribs(); glDrawArrays(GL_POINTS, 0, simulator.agents_.size()); m_sprite->disableVertexAttribs(); m_sprite->postdraw(); #endif #ifdef EXPORTING_AGENT for (unsigned int i=0; i< simulator.agents_.size(); ++i) { simulator.agents_[i]->draw(); } #endif if(target_Agent) { glDisable(GL_LIGHTING); VEC3 pos =simulator.agents_[agentSlider]->part_.getPosition(); m_ds->newList(GL_COMPILE_AND_EXECUTE); m_ds->lineWidth(5.0f); m_ds->pointSize(10.0f); m_ds->begin(GL_POINTS); // fait varier la couleur du plus pres au plus loin m_ds->color3f(0.0f , 1.0f, 0.9f); m_ds->vertex(pos); m_ds->vertex(pos+VEC3(0,0,50)); m_ds->vertex(pos+VEC3(0,10,50)); m_ds->end(); m_ds->endList(); } } if (draw_posX) { glDisable(GL_LIGHTING); VEC3 pos =VEC3 (posXSlider,posYSlider,0); m_ds->newList(GL_COMPILE_AND_EXECUTE); m_ds->lineWidth(5.0f); m_ds->pointSize(10.0f); m_ds->begin(GL_POINTS); // fait varier la couleur du plus pres au plus loin m_ds->color3f(0.0f , 1.0f, 0.9f); m_ds->vertex(pos); m_ds->vertex(pos+VEC3(0,0,50)); m_ds->vertex(pos+VEC3(0,10,50)); m_ds->end(); m_ds->endList(); } if (drawMovingObstacles) { #ifdef SHADOWSHELL updateObstacleVBO(); #endif for(unsigned int i = 0 ; i < simulator.movingObstacles_.size() ; ++i) { #ifdef SHADOWSHELL if(false){ Utils::ShaderFlat* moShader = m_obstShader[i]; // moShader->setAmbiant(Geom::Vec4f(0.43137254902,0.76862745098,0.8862745098,0.)); moShader->setAmbiant(Geom::Vec4f(0,0,0,0.)); moShader->setDiffuse(Geom::Vec4f(0.,0.,0.,0.)); moShader->enableVertexAttribs(); glDrawArrays(GL_POLYGON, 0, simulator.movingObstacles_[i]->nbVertices); moShader->disableVertexAttribs(); } #endif simulator.movingObstacles_[i]->draw(drawObstPath, drawObstacles); #ifdef DRAW_REGISTRATION MovingObstacle * mo =simulator.movingObstacles_[i]; if (drawEnvTopo) { unsigned int n = mo->nbVertices; if(nnbParticles) { for (std::vector::iterator it = mo->belonging_cells[n].begin(); it != mo->belonging_cells[n].end(); ++it) { drawCell((*it),5.0f,0,1.0f,0.5f); } for (std::vector::iterator it = mo->neighbor_cells[n].begin(); it != mo->neighbor_cells[n].end(); ++it) { drawCell((*it),5.0f,1.0f,0,0.5f); } } } #endif } // Commente par Arash #ifdef AFFICHE_MESH for (std::vector::iterator it = simulator.movingMeshes_.begin() ; it != simulator.movingMeshes_.end() ; ++it) (*it)->draw(); #endif } #ifndef SPATIAL_HASHING if (drawAgentsPredictionTri) { updateAgentPredTriVBO(); for(unsigned int i = 0 ; i < simulator.agents_.size() ; ++i) { Utils::ShaderSimpleColor* agShader = m_triAgent_Shader[i]; agShader->enableVertexAttribs(); glDrawArrays(GL_LINE_LOOP, 0, 3); agShader->disableVertexAttribs(); } } if (drawObstPredictionTri) { updateObstaclePredTriVBO(); for(unsigned int i = 0 ; i < m_triObst_Shader.size() ; ++i) { Utils::ShaderSimpleColor* moShader = m_triObst_Shader[i]; MovingObstacle * mo =simulator.movingObstacles_[i]; moShader->enableVertexAttribs(); glDrawArrays(GL_LINE_LOOP, 0, 4*mo->nbVertices); moShader->disableVertexAttribs(); } } #endif //draw the environment if (drawEnvLines) { m_simpleColorShader->setColor(Geom::Vec4f(0.5,0.5,0.5,0.)); m_render->draw(m_simpleColorShader, Algo::Render::GL2::LINES); } if (drawEnvTopo) { m_renderTopo->drawTopo(); if (draw_dart && dartSlider < (simulator.envMap_.map.end().index)) m_renderTopo->overdrawDart(dartSlider,10.0f,0.5f,1.0f,0.5f); if(drawObstacles) { CGoGN::CellMarkerStore m(simulator.envMap_.map) ; for (Dart d = simulator.envMap_.map.begin(); d != simulator.envMap_.map.end(); simulator.envMap_.map.next(d)) { if (!m.isMarked(d)) { m.mark(d) ; if(simulator.envMap_.obstvect[d].size()!=0) { drawCell(d,5.0f,0,1.0f,0.5f); } } } } } if (drawEnvFaces) { glEnable(GL_POLYGON_OFFSET_FILL) ; glPolygonOffset(1.0f, -0.5f) ; switch(m_renderStyle) { case SIMPLE: #ifdef ONERING m_simpleColorShader->setColor(Geom::Vec4f(0.9,0.9,0.9,0.)); #else m_simpleColorShader->setColor(Geom::Vec4f(0.9,0.9,0.9,0.)); #endif m_render->draw(m_simpleColorShader, Algo::Render::GL2::TRIANGLES); #ifdef ONERING // m_simpleColorShader->setColor(Geom::Vec4f(1.0,0.8,0.7,0.)); m_simpleColorShader->setColor(Geom::Vec4f(0.7,0.7,0.75,0.)); m_renderWithin->draw(m_simpleColorShader, Algo::Render::GL2::TRIANGLES); #endif break; } glDisable(GL_POLYGON_OFFSET_FILL) ; } ++frames ; struct timespec realTime ; clock_gettime(CLOCK_MONOTONIC, &realTime) ; elapsedTime += timespec_delta(startTime,realTime).tv_nsec ; clock_gettime(CLOCK_MONOTONIC, &startTime) ; float refresh = 1; if(display_times) { CGoGNout <= nextUpdate) { // Sortie des stats pour analyse externe // std::cout << elapsedTime << ";" << frames << ";" << sim.nbUpdates << ";" // << sim.totalNeighbors << ";" << sim.nearNeighbors << ";" << sim.nbSorts << ";" // << sim.nbRefineCandidate << ";" << sim.nbCoarsenCandidate << std::endl ; // Affichage des stats dans la barre d'état std::ostringstream oss ; oss << "Elapsed time : " << elapsedTime/(1000000000.0f*refresh); oss << " | " << ((float)frames)/refresh << " fps" ; oss << " | Iterations " << nbIterations ; oss << " | Neighbors " << simulator.totalNeighbors << " [" << (simulator.nbUpdates == 0 ? 0 : simulator.totalNeighbors / simulator.nbUpdates) << "]" ; oss << " | Near Neighbors " << simulator.nearNeighbors << " [" << (simulator.nbUpdates == 0 ? 0 : simulator.nearNeighbors / simulator.nbUpdates) << "]" ; oss << " | Sorts " << simulator.nbSorts << " [" << (simulator.nbUpdates == 0 ? 0 : 100 * simulator.nbSorts / simulator.nbUpdates) << "%]" ; oss << " | To Refine " << simulator.nbRefineCandidate ; oss << " | To Coarsen " << simulator.nbCoarsenCandidate ; if(simulator.detect_agent_collision) { oss << " | agents morts : "<( "u_FrameBufferColor", &samplerId ); samplerId = 1; m_DeferedShader.setuniformi<1>( "u_FrameBufferDepth", &samplerId ); samplerId = 2; m_DeferedShader.setuniformi<1>( "u_FrameBufferNormal", &samplerId ); glBegin( GL_QUADS ); glTexCoord2i( 0, 0 ); glVertex2i( -1, -1 ); glTexCoord2i( 1, 0 ); glVertex2i( 1, -1 ); glTexCoord2i( 1, 1 ); glVertex2i( 1, 1 ); glTexCoord2i( 0, 1 ); glVertex2i( -1, 1 ); glEnd(); m_DeferedShader.unbind(); fbo2.unbind(); glActiveTexture( GL_TEXTURE1 ); glEnable( GL_TEXTURE_2D ); glBindTexture( GL_TEXTURE_2D, *fbo2.getColorTexId(deferedEdgesAttachment) ); m_DeferedShader2.bind(); samplerId = 0; m_DeferedShader2.setuniformi<1>( "u_FrameBufferColor", &samplerId ); samplerId = 1; m_DeferedShader2.setuniformi<1>( "u_FrameBufferEdgeDepth", &samplerId ); samplerId = 2; m_DeferedShader2.setuniformi<1>( "u_FrameBufferNormal", &samplerId ); glBegin( GL_QUADS ); glTexCoord2i( 0, 0 ); glVertex2i( -1, -1 ); glTexCoord2i( 1, 0 ); glVertex2i( 1, -1 ); glTexCoord2i( 1, 1 ); glVertex2i( 1, 1 ); glTexCoord2i( 0, 1 ); glVertex2i( -1, 1 ); glEnd(); m_DeferedShader2.unbind(); #endif popTransfoMatrix(); //--------------->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> // qglviewer::Vec lookfrom, lookat, upvector; // qglviewer::Camera* cam = getQGLWidget()->camera(); // cerr << "---------------------------------------------" << endl; // cerr << cam->position()[0] << " " << cam->position()[1] << " " << cam->position()[2] << endl; // cerr << cam->viewDirection()[0] << " " << cam->viewDirection()[1] << " " << cam->viewDirection()[2] << endl; // cerr << cam->upVector()[0] << " " << cam->upVector()[1] << " " << cam->upVector()[2] << endl; } void SocialAgents::drawCell(Dart d, float width, float r, float g, float b) { Dart dd = d; do{ m_renderTopo->overdrawDart(dd,width,r,g,b); dd=simulator.envMap_.map.phi1(dd); }while(dd!=d); } //------------------------------------------------------------ void SocialAgents::setCameraDebug() { qglviewer::Vec lookfrom, lookat, upvector; qglviewer::Camera* cam = getQGLWidget()->camera(); lookfrom.setValue(-52.2146,-1045.85,557.488); lookat.setValue(-47.8132,-957.687,510.494); upvector.setValue(-0.000967862, 0.47043, 0.882437); /* lookfrom.setValue(0,0,1000); lookat.setValue(0,0,0); upvector.setValue(0.5,0.5,0.0); */ /* lookfrom.setValue(0,-1000,0); lookat.setValue(0,0,0); upvector.setValue(0.5,0.0,0.5); */ cam->setPosition(lookfrom); cam->lookAt(lookat); cam->setUpVector(upvector); } //------------------------------------------------------------ void SocialAgents::animate() { // if(simulator.nbSteps_ % simulator.nbStepsPerUnit_ == 0 && (simulator.nbSteps_ / simulator.nbStepsPerUnit_) % 10 == 0) // std::cout << round(simulator.globalTime_) << " " << simulator.envMap_.mapMemoryCost() << std::endl; // if (simulator.nbSteps_ % simulator.nbStepsPerUnit_ == 0 && (simulator.nbSteps_ / simulator.nbStepsPerUnit_) % 10 == 0) std::cout // << round(simulator.globalTime_) << " " << simulator.envMap_.mapMemoryCost() << std::endl ; // // CityGenerator::animateCity(&simulator.envMap_) ; // if (CityGenerator::animateCity(&simulator.envMap_)) simulator.addPathToCorner() ; // simulator.addPathsToAgents() ; // // // std::cout << "t : " << nbIterations << std::endl ; // // // timeval startTime ; // gettimeofday(&startTime, NULL) ; // timeval endTime ; // long seconds, nseconds ; nbIterations++ ; // setCameraDebug(); if(cif_exists) { qglviewer::Vec lookfrom, lookat, upvector; qglviewer::Camera* cam = getQGLWidget()->camera(); if(nbIterations=cif_begin)&&(nbIterationssetPosition(lookfrom); cam->lookAt(lookat); cam->setUpVector(upvector,true); } if (maxIterations > 0 && nbIterations > maxIterations) { // std::cout << "t : " << simulator.globalTime_ << std::endl ; timer->stop() ; if (filename != NULL) { if (percent) filename<<"_percent"; std::stringstream datas; datas<<"stats/"<9000) nb_max=2; // else nb_max=10000; clock_gettime(CLOCK_MONOTONIC, &begTime) ; for(int n =1; nupdateData(simulator.envMap_.position); if (drawEnvFaces) updateVBOprimitives(Algo::Render::GL2::TRIANGLES); if (drawEnvLines) updateVBOprimitives(Algo::Render::GL2::LINES); if(drawEnvTopo) m_renderTopo->updateData(simulator.envMap_.map, simulator.envMap_.position, 0.9, 0.9); // gettimeofday(&endTime, NULL) ; // seconds = endTime.tv_sec - startTime.tv_sec ; // nseconds = endTime.tv_usec - startTime.tv_usec ; // // elapsedTime += (seconds + nseconds / 1000000.0) ; // // if (sim.globalTime_ - int(sim.globalTime_) == 0.0f && int(sim.globalTime_) % 1500 == 0) // { // std::cout << "end " << elapsedTime << std::endl ; // timer->stop() ; // } // // if (simulator.reachedGoal()) // { // std::cout << "end " << elapsedTime << std::endl ; // timer->stop() ; // } #ifndef SPATIAL_HASHING if (render_anim) { if(nbIterations%2==0) { // getQGLWidget()->resize(800,600); getQGLWidget()->resize(1580,930); getQGLWidget()->setSnapshotQuality(100); updateGL() ; std::ostringstream tmpNb ; unsigned int counter = getQGLWidget()->snapshotCounter(); tmpNb << std::setfill('0') << std::setw(5) << counter ; getQGLWidget()->setSnapshotCounter(++counter); // QString filename("./export/meshCercleBA" ); // QString filename("./export/meshCorridorBA" ); // QString filename("./export/oneRing" ); QString filename("./export/scenario5." ); filename.append((tmpNb.str()).c_str()); filename.append(".png"); // getQGLWidget()->setSnapshotFileName(filename); // getQGLWidget()->setSnapshotFormat(QString("PNG")); QImage image = getQGLWidget()->grabFrameBuffer (); if( !image.save( filename, "PNG" ) ) { QMessageBox::warning( this, "Save Image", "Error saving image." ); } if (nbIterations >= 20000) { std::cout << "enough .png generated" << std::endl ; exit(0) ; } if(nbIterations % 1000 == 0) std::cout << "image " << nbIterations << std::endl; } // std::ostringstream oss ; // std::ostringstream tmpNb ; // tmpNb << std::setfill('0') << std::setw(5) << nbGeneratedPov ; //// oss << "./DeCirkelMesh/meshCercle" << tmpNb.str() << ".pov" ; // oss << "./DeCorridorMesh/meshCorrida" << tmpNb.str() << ".pov" ; // std::string chaine = oss.str() ; //// VEC3 agPos = sim.agents_[0]->meanPos_ ; //// agPos[2] = agPos[1] ; //// agPos[1] = 0.0f ; //// VEC3 camPos(agPos) ; //// VEC3 camLook(agPos) ; // //// camPos = camPos //// + VEC3(-10 - 0.05 * nbGenerated, 30 + 0.05 * nbGenerated, //// log(1.0f + nbGenerated / 700.0f)) ; // ////travelling city nbMaxAgent 15000, nbSquare 40 (45?) //// VEC3 camPos(-800, 10, -800) ; //// camPos = camPos //// + VEC3(-10 - 0.3 * nbGenerated, 30 + 0.3 * nbGenerated, //// 400.0f * log(1.0f + nbGenerated / 700.0f)) ; //// VEC3 camLook(0, 0, 0) ; //// camLook = camLook //// + VEC3(-10 - 0.1 * nbGenerated, 30 + 0.1 * nbGenerated, //// 400.0f * log(1.0f + nbGenerated / 700.0f)) ; // ////travelling horizontal //// VEC3 camPos(0, 5, -200) ; //// camPos = camPos + VEC3(-10 - 0.15 * nbGenerated, 0, 0) ; //// VEC3 camLook = camPos ; //// camLook[0] += 0.15 * nbGenerated ; //// camLook[2] += 100 ; //// camLook[1] = 0 ; // ////vertical view //// VEC3 camPos(0, 300, 0) ; //// Geom::BoundingBox bb = simulator.getAgentsBB() ; //// VEC3 seeEveryone = bb.max() - bb.min() ; //// if (seeEveryone[0] > 200) //// camPos[1] += seeEveryone[0] ; //// else //// camPos[1] += 200 ; //// VEC3 camLook(0) ; // ////video intro //// VEC3 camPos(-20, 10, 75) ; //// VEC3 camLook(-25, 0, 0) ; // ////mall //// VEC3 camPos(-500, 500, -400) ; //// VEC3 camLook(100, 100, 0) ; // ////openStreetMap //// VEC3 camPos(500, 75, 400) ; //// VEC3 camLook(-250, 0, 650) ; // ////pathDyn //// VEC3 camPos(-700, 700, -1800) ; //// VEC3 camLook(200, 0, 0) ; // ////corridor side //// VEC3 camPos(-700, 100, 0) ; //// VEC3 camLook(200, 0, 0) ; // ////corridor top //// VEC3 camPos(0, 300, 0) ; //// VEC3 camLook(0, 0, 0) ; // ////corridor take2 //// VEC3 camPos(-350, 200, 0) ; //// VEC3 camLook(0, 0, 0) ; // ////openStreetMap mapRoad & mapBuildings //// VEC3 camPos(-200, 100, 500) ; //// VEC3 camLook(1000, 0, 0) ; // ////openStreetMap sphere //// VEC3 camPos(-200, 100, 500) ; //// VEC3 camLook(100, 0, 0) ; // //// //diligences / Cercle //// VEC3 camPos(0, 300, 750) ; //// VEC3 camLook(0, 0, 0) ; // // //corridor // VEC3 camPos(0, 300, 750) ; // VEC3 camLook(0, 0, 0) ; // // //// if(nbIterations%2==0) //// { //// exportScenePov(simulator.envMap_.map,simulator.envMap_.position,chaine,camPos,camLook,VEC3(0.0f,0,0),0,0,0); //// // exportScenePov(sim.envMap_.map,sim.envMap_.position,chaine,VEC3(43,762,65),VEC3(0,762,0),VEC3(1.0f,0,0),0,0,0); //// // exportScenePov(sim.envMap_.map,sim.envMap_.position,chaine,VEC3(43,762,65+(1500.0f*float(nbGenerated)/400.0f)),VEC3(0,762,0),VEC3(1.0f,0,0),0,0,0); //// nbGeneratedPov++; //// } //// //// if (nbIterations >= 20000) //// { //// std::cout << "enough .pov generated" << std::endl ; //// exit(0) ; //// } } #endif updateGL() ; } #ifndef SPATIAL_HASHING void SocialAgents::exportInfoFace(std::ofstream& out, Dart d) { //get corner Dart dd = d ; VEC3 cornerLeftBottom = simulator.envMap_.position[d] ; do { VEC3 p = simulator.envMap_.position[dd] ; if (cornerLeftBottom[0] > p[0]) cornerLeftBottom[0] = p[0] ; if (cornerLeftBottom[1] > p[1]) cornerLeftBottom[1] = p[1] ; if (cornerLeftBottom[2] > p[2]) cornerLeftBottom[2] = p[2] ; dd = simulator.envMap_.map.phi1(dd) ; } while (dd != d) ; //draw text if (!simulator.envMap_.buildingMark.isMarked(d)) { out << "object {" << std::endl ; out << "polygon { 4 , <0,0,0>, <11,0,0>, <11,0,6>, <0,0,6> }" << std::endl ; out << "texture { pigment{ color rgb<0,1,1> } finish { ambient 1 diffuse 0 } }" << std::endl; out << "translate < " << cornerLeftBottom[0]+5 << "," << cornerLeftBottom[2]+2 << "," << cornerLeftBottom[1]+7 << ">" << std::endl; out << "}" << std::endl ; out << "object {" << std::endl ; out << "polygon { 4 , <0,0,0>, <17,0,0>, <17,0,6>, <0,0,6> }" << std::endl ; out << "texture { pigment{ color rgb<0.25,1,0> } finish { ambient 1 diffuse 0 } }" << std::endl; out << "translate < " << 12+cornerLeftBottom[0]+5 << "," << cornerLeftBottom[2]+2 << "," << cornerLeftBottom[1]+7 << ">" << std::endl; out << "}" << std::endl ; } //draw vectors //contains for (unsigned int i = 0 ; i < simulator.envMap_.agentvect[d].size() ; ++i) { Agent * ag = simulator.envMap_.agentvect[d][i] ; int j = 0 ; for (unsigned int iA = 0 ; iA < simulator.agents_.size() ; ++iA) { if (simulator.agents_[iA] == ag) { j = iA ; break ; } } out << "cylinder {" << " <0,0,0>, <0,6,0>, 1.5 " << std::endl ; out << "scale 0.5" << std::endl ; VEC3 col = Utils::color_map_BCGYR(float(j) / float(simulator.agents_.size())) ; out << "pigment { color <" << col[0] << "," << col[1] << "," << col[2]<< "> }" << std::endl; // VEC3 pBase(ag->getPosition()) ; // VEC3 posR(pBase) ; // // Geom::Plane3D pl = Algo::Geometry::facePlane(simulator.envMap_.map, ag->part_.d, // simulator.envMap_.position) ; // posR[2] -= 1000 ; // Geom::intersectionPlaneRay(pl, posR, VEC3(0, 0, -1), posR) ; // // VEC3 dir = ag->meanDirection_ ; // VEC3 base(0, -1, 0) ; // VEC3 axisRot = base ^ dir ; // int sign = axisRot[2] > 0 ? 1 : -1 ; // // 57, 2957795 // : conversion from radian to degree // float myRot = acos(-dir[1])*57.2957795f ; // // out << "rotate <0,0," << sign * myRot << ">" << std::endl ; // out << "rotate <" << -90 << "," << 0 << "," << 0 << "> " << std::endl ; if (i < 5) out << "translate < " << cornerLeftBottom[0] + 5 + 1 + i * 2 << "," << cornerLeftBottom[2] + 2 << "," << cornerLeftBottom[1] + 7 + 1.5 << ">" << std::endl ; else out << "translate < " << cornerLeftBottom[0] + 5 + 1 + (i - 5) * 2 << "," << cornerLeftBottom[2] + 2 << "," << cornerLeftBottom[1] + 7 + 1.5 + 3 << ">" << std::endl ; out << "}" << std::endl ; } //neighbours for (unsigned int i = 0 ; i < simulator.envMap_.neighborAgentvect[d].size() ; ++i) { Agent * ag = simulator.envMap_.neighborAgentvect[d][i] ; int j = 0 ; for (unsigned int iA = 0 ; iA < simulator.agents_.size() ; ++iA) { if (simulator.agents_[iA] == ag) { j = iA ; break ; } } out << "cylinder {" << " <0,0,0>, <0,6,0>, 1.5 " << std::endl ; out << "scale 0.5" << std::endl ; VEC3 col = Utils::color_map_BCGYR(float(j) / float(simulator.agents_.size())) ; out << "pigment { color <" << col[0] << "," << col[1] << "," << col[2] << "> }" << std::endl ; // VEC3 pBase(ag->getPosition()) ; // VEC3 posR(pBase) ; // // Geom::Plane3D pl = Algo::Geometry::facePlane(simulator.envMap_.map, ag->part_.d, // simulator.envMap_.position) ; // posR[2] -= 1000 ; // Geom::intersectionPlaneRay(pl, posR, VEC3(0, 0, -1), posR) ; // // VEC3 dir = ag->meanDirection_ ; // VEC3 base(0, -1, 0) ; // VEC3 axisRot = base ^ dir ; // int sign = axisRot[2] > 0 ? 1 : -1 ; // // //57,2957795 : conversion from radian to degree // float myRot = acos(-dir[1]) * 57.2957795f ; // // out << "rotate <0,0," << sign * myRot << ">" << std::endl ; // out << "rotate <" << -90 << "," << 0 << "," << 0 << "> " << std::endl ; if (i < 8) out << "translate < " << 12 + cornerLeftBottom[0] + 5 + 1 + i * 2 << "," << cornerLeftBottom[2] + 2 << "," << cornerLeftBottom[1] + 7 + 1.5 << ">" << std::endl ; else out << "translate < " << 12 + cornerLeftBottom[0] + 5 + 1 + (i - 8) * 2 << "," << cornerLeftBottom[2] + 2 << "," << cornerLeftBottom[1] + 7 + 1.5 + 3 << ">" << std::endl ; out << "no_shadow }" << std::endl ; } } bool SocialAgents::exportScenePov(PFP::MAP& map, PFP::TVEC3& position, const std::string& filename, PFP::VEC3 cameraPos, PFP::VEC3 cameraLook, PFP::VEC3 translate, float angle_X, float angle_Y, float angle_Z) { static const bool draft = false ; static const bool highlightAgent = false ; static const bool wireDisplay = true ; static const bool infoFaces = false ; static const bool exportPath = false ; static const bool exportMovObst = true ; static const bool exportCity = false ; static const bool exportSphere = false ; static const bool exportDilatedPos = false; unsigned int highlightAgentNo = 0 ; std::ofstream out(filename.c_str(), std::ios::out) ; if (!out.good()) { std::cerr << "(export) Unable to open file " << filename << std::endl ; return false ; } float angleX = angle_X ; float angleY = angle_Y ; float angleZ = angle_Z ; //view the agent from an upper position if (highlightAgent) { Agent * agent = simulator.agents_[highlightAgentNo] ; cameraLook = agent->getPosition() ; VEC3 goalV = (agent->goals_[agent->curGoal_] - agent->getPosition()) ; goalV.normalize() ; cameraPos = cameraLook - goalV * 50.0f ; float tmp = cameraPos[1] ; cameraPos[1] = cameraPos[2] + 400.0f ; cameraPos[2] = tmp ; tmp = cameraLook[1] ; cameraLook[2] = cameraLook[1] ; cameraLook[1] = tmp ; } if (!draft) { out << "#include \"Sheriff_animated_POV_geom.inc\"" << std::endl ; out << "#include \"Cowbow_animated_POV_geom.inc\"" << std::endl ; out << "#include \"sombrero2_highres_POV_geom.inc\"" << std::endl ; out << "#include \"sombrero3_highres_POV_geom.inc\"" << std::endl ; out << "#include \"transforms.inc\"" << std::endl ; } // out // << "#declare PosSpline = spline { natural_spline 0.0,<0,3000,-1> 0.3,<0,500,-1> 0.6,<250,200,200> 1.0,<500,75,400>}" // << std::endl ; // out // << "#declare LookSpline = spline { natural_spline 0.0,<0,0,200> 0.3,<-250,0,500> 0.6,<-125,0,350> 1.0,<-250,0,650>}" // << std::endl ; // // if ((simulator.globalTime_ - 1000.0f) / 120.0f < 1.0f) // out << "camera { location PosSpline(" << (simulator.globalTime_ - 1000.0f) / 120.0f // << ") look_at LookSpline(" << (simulator.globalTime_ - 1000.0f) / 120.0f << ") " ; // else out << "camera { location <" << cameraPos[0] << "," << cameraPos[1] << "," << cameraPos[2] << "> look_at <" << cameraLook[0] << "," << cameraLook[1] << "," << cameraLook[2] << "> " ; if (highlightAgent) { out << "translate <" << translate[0] << "," << translate[1] << "," << translate[2] << "> " << std::endl ; out << "rotate <" << angleX << "," << angleY << "," << angleZ << "> }" << std::endl ; } out << "}" << std::endl ; //set a sky sphere out << "sphere { <0, 0, 0>, 5000" ; out << "texture{ pigment { color rgb <1, 1, 1>} finish { ambient 1 diffuse 0 } } }" << std::endl ; //green ground if(exportCity) { if(exportSphere) { out << "sphere { <0,0,0>, 195 texture{ pigment { color rgb <0.6, 0.8, 0.6>} finish { ambient rgb 0.3 brilliance 0.2 } } }" << std::endl; } else { out << "plane { <0,1,0>, -0.001" ; out << "texture{ pigment { color rgb <0.6, 0.8, 0.6>} finish { ambient rgb 0.3 brilliance 0.2 } } }" << std::endl ; } } // out << "light_source { <-800, 800, -800> color rgb 0.25 }" << std::endl ; //set a high quality rendering out << "global_settings {" << std::endl ; out << "radiosity {" << std::endl ; out << "pretrace_start 0.08 pretrace_end 0.04" << std::endl ; // if(draft) // out << "count 10 nearest_count 10 error_bound 0.25 recursion_limit 1 low_error_factor 0.2 gray_threshold 0.0 minimum_reuse 0.015 brightness 1.4 adc_bailout 0.01/2 normal off media off} max_trace_level 5}" << std::endl; // else out << "count 300 nearest_count 10 error_bound 0.10 recursion_limit 1 low_error_factor 0.2 gray_threshold 0.0 minimum_reuse 0.015 brightness 1.4 adc_bailout 0.01/2 normal off media off} max_trace_level 60}" << std::endl ; for (unsigned int i = 0 ; i < simulator.agents_.size() ; ++i) { if (draft) { out << "cylinder {" << " <0,0,0>, <0,6,0>, 1.5 " << std::endl ; out << "scale 0.5" << std::endl ; VEC3 col = Utils::color_map_BCGYR(float(i) / float(simulator.agents_.size())) ; out << "pigment { color <" << col[0] << "," << col[1] << "," << col[2] << "> }" << std::endl ; } else { if (i == 0) { out << "object {" << " Sheriff_animated_ " << std::endl ; out << "scale 0.165745856" << std::endl ; } else if (i % 7 == 0) { out << "object {" << " Cowbow_animated_ " << std::endl ; out << "scale 0.170454545" << std::endl ; } else if (i % 7 < 5) { out << "object {" << " sombrero2_highres_ " << std::endl ; out << "scale 0.127659574" << std::endl ; } else { out << "object {" << " sombrero3_highres_ " << std::endl ; out << "scale 0.132743363" << std::endl ; } } VEC3 pBase(simulator.agents_[i]->getPosition()) ; VEC3 posR(pBase) ; // Geom::Plane3D pl = Algo::Geometry::facePlane(map,simulator.agents_[i]->part_.d,position); // posR[2] -= 1000; // Geom::intersectionPlaneRay(pl,posR,VEC3(0,0,-1),posR); VEC3 dir = simulator.agents_[i]->meanDirection_ ; VEC3 base(0, -1, 0) ; VEC3 axisRot = base ^ dir ; int sign = axisRot[2] > 0 ? 1 : -1 ; //57,2957795 : conversion from radian to degree float myRot = acos(-dir[1]) * 57.2957795f ; out << "rotate <0,0," << -90 + sign * myRot << ">" << std::endl ; out << "rotate <" << angleX - 90 << "," << angleY << "," << angleZ << "> " << std::endl ; out << "translate <" << posR[0] << "," << posR[2] << "," << posR[1] << "> " << std::endl ; out << "translate <" << translate[0] << "," << translate[1] << "," << translate[2] << ">" << std::endl ; out << "}" << std::endl ; if (exportPath) { out << "sphere_sweep { cubic_spline" << std::endl ; out << simulator.agents_[i]->goals_.size() << "," << std::endl ; for (unsigned int j = 0 ; j < simulator.agents_[i]->goals_.size() ; ++j) { out << "<" << simulator.agents_[i]->goals_[j][0] << "," << simulator.agents_[i]->goals_[j][2] << "," << simulator.agents_[i]->goals_[j][1] << ">, 4" << std::endl ; } VEC3 col = Utils::color_map_BCGYR(float(i) / float(simulator.agents_.size())) ; out << "pigment { color <" << col[0] << "," << col[1] << "," << col[2] << "> }" << std::endl ; out << " }" << std::endl ; } } if(exportMovObst) { for (std::vector::iterator it = simulator.movingObstacles_.begin() ; it != simulator.movingObstacles_.end() ; ++it) { float bottom = 0.0f; float height = 10.0f; unsigned int nbPoints = (*it)->nbVertices; out << "prism {" << std::endl; out << "linear_sweep" << std::endl; out << "linear_spline" << std::endl; out << bottom << std::endl; // sweep the following shape from here ... out << bottom+height << std::endl; // ... up through here out << nbPoints+1 << std::endl; // the number of points making up the shape ... for(unsigned int i=0; i <= nbPoints ; ++i) { VEC3 pos = (*it)->getPosition(i%nbPoints); if(exportDilatedPos) pos = (*it)->getDilatedPosition(i%nbPoints); out << "<" << pos[0] << "," << pos[1] << ">" << std::endl; } if(exportDilatedPos) out << "pigment { Yellow }" << std::endl; else out << "pigment { Red }" << std::endl; out << "}" << std::endl; } } if (infoFaces) { CellMarker m(simulator.envMap_.map) ; for (Dart d = simulator.envMap_.map.begin() ; d != simulator.envMap_.map.end() ; simulator.envMap_.map.next(d)) { if (!m.isMarked(d)) { m.mark(d) ; exportInfoFace(out, d) ; } } } if (highlightAgent) { //find the cells to highlight DartMarkerStore highlight(map) ; for (Dart d = map.begin() ; d != map.end() ; map.next(d)) { //find the cells to highlight DartMarkerStore highlight(map) ; Agent * ag = simulator.agents_[highlightAgentNo] ; for (Dart d = map.begin() ; d != map.end() ; map.next(d)) { PFP::AGENTS listAgentInCell = simulator.envMap_.agentvect[d] ; if (std::find(listAgentInCell.begin(), listAgentInCell.end(), ag) != listAgentInCell.end()) { PFP::AGENTS listAgentInCell = simulator.envMap_.agentvect[d] ; if (std::find(listAgentInCell.begin(), listAgentInCell.end(), ag) != listAgentInCell.end()) { highlight.markOrbit(d) ; } } } } // set browser and export MapBrowserSelector mbs1(map,SelectorMarked(highlight)); map.setBrowser(&mbs1); Algo::Surface::ExportPov::exportMeshPlain(out, map, position, "facesHighlighted") ; // set browser and export MapBrowserSelector mbs2(map,SelectorUnmarked(highlight)); map.setBrowser(&mbs2); Algo::Surface::ExportPov::exportMeshPlain(out, map, position, "myMesh") ; // use all map map.setBrowser(NULL); out << "object {facesHighlighted" << std::endl ; out << "rotate <" << angleX << "," << angleY << "," << angleZ << "> " << std::endl ; out << "translate <" << translate[0] << "," << translate[1] << "," << translate[2] << ">" << std::endl ; out << "texture{ pigment{ color rgb<0.4667,0.709,0.996>} finish { ambient rgb 0.35 brilliance 0.5 } } }" << std::endl ; } else { if(exportCity) { // set browser and export MapBrowserSelector mbs1(map,SelectorCellUnmarked(simulator.envMap_.pedWayMark)); map.setBrowser(&mbs1); Algo::Surface::ExportPov::exportMeshPlain(out, simulator.envMap_.map, simulator.envMap_.position, "myCity") ; // set browser and export MapBrowserSelector mbs2(map,SelectorCellMarked(simulator.envMap_.pedWayMark)); map.setBrowser(&mbs2); Algo::Surface::ExportPov::exportMeshPlain(out, simulator.envMap_.map, simulator.envMap_.position, "myCityPed") ; // use all map map.setBrowser(NULL); Algo::Surface::ExportPov::exportMeshPlain(out,simulator.envMap_.mapScenary,simulator.envMap_.positionScenary,"myMesh"); } else { Algo::Surface::ExportPov::exportMeshPlain(out,simulator.envMap_.map,simulator.envMap_.position,"myMesh"); } // DartMarkerStore road(map); // for(Dart d=map.begin();d!=map.end();map.next(d)) // { // if(!road.isMarked(d)) // { // if(!sim.envMap_.pedWayMark.isMarked(d) && !sim.envMap_.obstacleMark.isMarked(d)) // road.mark(d); // } // } // // DartMarkerStore pedWay(map); // for(Dart d=map.begin();d!=map.end();map.next(d)) // { // if(!pedWay.isMarked(d)) // { //// if(!road.isMarked(d) && !sim.envMap_.obstacleMark.isMarked(d)) // if(sim.envMap_.pedWayMark.isMarked(d) && !sim.envMap_.obstacleMark.isMarked(d)) // pedWay.mark(d); // } // } // SelectorMarked sm(pedWay); // SelectorMarked roadM(road); // Algo::ExportPov::exportMeshPlain(out,map,position,"myCityPed",sm); // Algo::ExportPov::exportMeshPlain(out,map,position,"myCity",roadM); } if (wireDisplay) { Algo::Surface::ExportPov::exportMeshWire(out, map, position, "myMeshWire") ; out << "object {myMeshWire" << std::endl ; out << "rotate <" << angleX << "," << angleY << "," << angleZ << "> " << std::endl ; out << "translate <" << translate[0] << "," << translate[1] << "," << translate[2] << ">" << std::endl ; out << "texture{ pigment{ color rgb<0,0,0>} } }" << std::endl ; } out << "object {myMesh" << std::endl ; out << "rotate <" << angleX << "," << angleY << "," << angleZ << "> " << std::endl ; out << "translate <" << translate[0] << "," << translate[1] << "," << translate[2] << ">" << std::endl ; out << "texture{ pigment{ color rgb 0.7} finish { ambient rgb 0.3 brilliance 0.5 } } }" << std::endl ; if(exportCity) { out << "object {myCityPed" << std::endl; out << "rotate <" << angleX << "," << angleY << "," << angleZ << "> " << std::endl; out << "translate <" << translate[0] << "," << translate[1] << "," << translate[2] << ">" << std::endl; out << "texture{ pigment{ color rgb 0.7} finish { ambient rgb 0.3 brilliance 0.5 } } }" << std::endl; out << "object {myCity" << std::endl; out << "rotate <" << angleX << "," << angleY << "," << angleZ << "> " << std::endl; out << "translate <" << translate[0] << "," << translate[1] << "," << translate[2] << ">" << std::endl; out << "texture{ pigment{ color rgb 0.6} finish { ambient rgb 0.3 brilliance 0.5 } } }" << std::endl; } // out << "texture{ pigment{ color rgb<1.0,1.0,1>} finish { ambient rgb 0.05 brilliance 0.5 } } }" << std::endl; out.close() ; return true ; } #endif //void SocialAgents::cb_keyPress(int keycode) void SocialAgents::keyPressEvent(QKeyEvent *e) { // switch (keycode) switch(e->key()) { case Qt::Key_A : { if (timer->isActive()) timer->stop() ; else timer->start() ; dock.check_timer->setChecked(timer->isActive()) ; break ; } case Qt::Key_C : { simulator.envMap_.map.check() ; break ; } case Qt::Key_E : { std::cout << "exporting obstacle to file myScene.obst" << std::endl ; std::string filename("myScene.obst") ; CGoGN::ExportScene::exportSceneToFile(simulator.envMap_.map, simulator.envMap_.position, simulator.envMap_.obstacleMark, simulator.envMap_.buildingMark, filename) ; std::string filename2("myAgents.pos") ; simulator.exportAgents(filename2) ; std::cout << "exporting meshes" << std::endl ; std::string filename3("pedway.ply") ; std::string filename4("buildingMap.ply") ; std::string filename5("road.ply") ; std::string filename6("road.obj") ; MapBrowserSelector mbs(simulator.envMap_.map,SelectorCellMarked(simulator.envMap_.pedWayMark)); simulator.envMap_.map.setBrowser(&mbs); Algo::Surface::Export::exportPLY(simulator.envMap_.map, simulator.envMap_.position,filename3.c_str(), false); MapBrowserSelector mbs2(simulator.envMap_.map,SelectorCellUnmarked(simulator.envMap_.pedWayMark)); simulator.envMap_.map.setBrowser(&mbs2); Algo::Surface::Export::exportPLY(simulator.envMap_.map, simulator.envMap_.position,filename5.c_str(), false); // Algo::Surface::Export::exportOBJ(simulator.envMap_.map, simulator.envMap_.position,filename6.c_str()); // L'export OBJ ne semble pas marcher simulator.envMap_.map.setBrowser(NULL); if(simulator.config==5) Algo::Surface::Export::exportPLY(simulator.envMap_.mapScenary, simulator.envMap_.positionScenary,filename4.c_str(), false); break ; } case Qt::Key_G: { qglviewer::Camera* cam = getQGLWidget()->camera(); qglviewer::Vec lookat = cam->position() + 100*cam->viewDirection(); cam_output_file << nbIterations << " "; cam_output_file << cam->position()[0] << " "<< cam->position()[1] << " "<< cam->position()[2] << " " << lookat[0] << " "<< lookat[1] << " "<< lookat[2] << " " << cam->upVector()[0] << " "<< cam->upVector()[1] << " "<< cam->upVector()[2] << endl; break; } case Qt::Key_I: { getQGLWidget()->resize(800,600); updateGL() ; // getQGLWidget()->setSnapshotQuality(100); std::ostringstream tmpNb ; unsigned int counter = getQGLWidget()->snapshotCounter(); tmpNb << std::setfill('0') << std::setw(5) << counter ; getQGLWidget()->setSnapshotCounter(++counter); QString filename("./export/test" ); filename.append((tmpNb.str()).c_str()); filename.append(".png"); // getQGLWidget()->setSnapshotFileName(filename); // getQGLWidget()->setSnapshotFormat(QString("PNG")); QImage image = getQGLWidget()->grabFrameBuffer(); if( !image.save( filename, "PNG" ) ) { QMessageBox::warning( this, "Save Image", "Error saving image." ); } break; } case Qt::Key_P : { std::cout << simulator.globalTime_ << std::endl ; if(simulator.config==5) moveCameraTo(VEC3(10*simulator.globalTime_,10,50)); else moveCameraTo(VEC3(10*simulator.globalTime_,10,-50)); updateGLMatrices(); break ; } #ifndef SPATIAL_HASHING case Qt::Key_R : { exportScenePov(simulator.envMap_.map, simulator.envMap_.position, "planSerre/exportSceneOle0000.pov", VEC3(10, 3, 10), VEC3(0, 0, 0), VEC3(1.0f, 0, 0), 0, 0, 0) ; // exportScenePov(sim.envMap_.map, sim.envMap_.position, "exportScene0002.pov", // VEC3(43, 762, 1565), VEC3(0, 762, 0), VEC3(1.0f, 0, 0), 0, 0, 0) ; // exportScenePov(sim.envMap_.map, sim.envMap_.position, "exportScene0002.pov", // VEC3(43, 762, 65), VEC3(0, 762, 0), VEC3(1.0f, 0, 0), 0, 0, 0) ; break ; } #endif case Qt::Key_Q : { animate() ; break ; } case Qt::Key_V : { setCameraDebug(); /* qglviewer::Camera* cam = getQGLWidget()->camera(); if(simulator.config==0) { cam->setPosition(qglviewer::Vec(0,-1100,700)); cam->setUpVector(qglviewer::Vec(0,0,0)); cam->lookAt(qglviewer::Vec(0,0,0)); cam->setSceneRadius(10000); } if(simulator.config==1) { cam->setPosition(qglviewer::Vec(0,-800,700)); cam->setUpVector(qglviewer::Vec(0,0,0)); cam->lookAt(qglviewer::Vec(0,0,0)); cam->setSceneRadius(10000); } if(simulator.config==2) { cam->setPosition(qglviewer::Vec(0,-900,700)); cam->setUpVector(qglviewer::Vec(0,0,0)); cam->lookAt(qglviewer::Vec(0,0,0)); cam->setSceneRadius(10000); } if(simulator.config==3) { cam->setPosition(qglviewer::Vec(0,-900,700)); cam->setUpVector(qglviewer::Vec(0,0,0)); cam->lookAt(qglviewer::Vec(0,0,0)); cam->setSceneRadius(10000); } */ break; } case Qt::Key_5 : { FILE *fp ; int state = GL2PS_OVERFLOW, buffsize = 0 ; fp = fopen("out.svg", "wb") ; printf("Writing 'out.eps'... ") ; while (state == GL2PS_OVERFLOW) { buffsize += 1024 * 1024 ; gl2psBeginPage("test", "gl2psTestSimple", NULL, GL2PS_SVG, GL2PS_SIMPLE_SORT, GL2PS_USE_CURRENT_VIEWPORT, GL_RGBA, 0, NULL, 0, 0, 0, buffsize, fp, "out.svg") ; updateGL() ; state = gl2psEndPage() ; } fclose(fp) ; printf("Done!\n") ; break ; } case Qt::Key_9 : { render_anim = !render_anim ; std::cout << "export anim " << render_anim << std::endl; break ; } } updateGL() ; } //--------------------------------------------------------- void SocialAgents::readCameraInputFile(char *filename) { std::string line, word; // const char *c_line; cif_exists=false; cam_input_file.open(filename,std::ifstream::in); if(cam_input_file.is_open()) { cif_exists=true; cam_input_file >> cif_begin; cam_input_file >> cif_end; int nb_steps=cif_end-cif_begin+1; cif_lookfrom = new VEC3[nb_steps]; cif_lookat = new VEC3[nb_steps]; cif_upvector = new VEC3[nb_steps]; int i; for(i=0;i> word; std::istringstream iss(word); switch(j) { case 0: iss >> cif_lookfrom[i][0]; break; case 1: iss >> cif_lookfrom[i][1]; break; case 2: iss >> cif_lookfrom[i][2]; break; case 3: iss >> cif_lookat [i][0]; break; case 4: iss >> cif_lookat [i][1]; break; case 5: iss >> cif_lookat [i][2]; break; case 6: iss >> cif_upvector[i][0]; break; case 7: iss >> cif_upvector[i][1]; break; case 8: iss >> cif_upvector[i][2]; break; default : cerr << "Unexpected value for switch : " << j << endl; break; } } } cam_input_file.close(); } } /********************************************************************************************** * MAIN FUNCTION * **********************************************************************************************/ int main(int argc, char** argv) { QApplication app(argc, argv) ; std::cout << "./socialAgents scenario minSize(=41.5) nbAgent(=1000) nbObst(=20) nbIterations" << std::endl; unsigned int minSize = Agent::range_ ; unsigned int iterations = 0 ; unsigned int config = 1 ; unsigned int nbAgent = 1000; unsigned int nbObst = 20; bool multires = true; if (argc > 6) iterations = atoi(argv[6]) ; if(argc > 5) multires = atoi(argv[5])==1; if (argc > 4) nbObst = atoi(argv[4]) ; if (argc > 3) nbAgent = atoi(argv[3]) ; if (argc > 2) { minSize = atoi(argv[2]) ; // if (iterations == 0) // iterations = 4000 ; } if (argc > 1) config = atoi(argv[1]) ; SocialAgents sa(config, minSize, nbAgent, nbObst,multires, iterations) ; sa.setGeometry(0, 0, 1800, 1200) ; sa.initGUI() ; glewInit(); sa.cam_output_file.open("cams/cam.out",std::ofstream::out); char camfile[100]; sprintf(camfile,"cams/cam.scn%d.spline",config); sa.readCameraInputFile(camfile); if(sa.cif_exists) { unsigned int i; for(i=0;i 1) // sa.timer->start() ; // Arash : // S'il y a un cam input file, alors lire le premier // entier N et faire marcher la simulation N fois. // sa.readCameraInputFile("cams/cam.scn8.spline"); // sa.cam_output_file.open("cams/cam.out",std::ofstream::out); // // // unsigned int i; // for(i=0;i