#include "simulator.h" //initialisation Surface Surface::Surface(Simulator* sim,VEC3 offset): mapOperator(surfaceMap) { r=1.0f; g=0.627f; b=0.0f; sim_=sim; width=1.0; nbVertices=0; nbTriangles=0; distanceColorationMaxi=0.01f; distanceColorationMini=2.0f; surfaceMap.initImplicitProperties(); positionSurface = surfaceMap.addAttribute("positionSurface"); initOperators(LERP); initPlane(); indexParticule = surfaceMap.addAttribute("indexParticule"); indexTriangle= surfaceMap.addAttribute("indexTriangle"); faceColor=surfaceMap.addAttribute("faceColor"); index_surface=sim->surfaces.size(); // initialisation des particules et des attributs de sommet TraversorV tv(surfaceMap); for(Dart d = tv.begin() ; d != tv.end() ; d = tv.next()) { positionSurface[d]+=offset; indexParticule[d]=nbVertices; parts_.push_back(new CGoGN::Algo::Volume::MovingObjects::ParticleCell3D(sim_->envMap_.map, sim_->envMap_.getBelongingCell(positionSurface[d]), positionSurface[d] , sim_->envMap_.position)); nbVertices ++; } // initialisation tableaux de vecteurs qui vont stocker les belonging cells TraversorE tF2(surfaceMap); for(Dart d = tF2.begin() ; d != tF2.end() ; d = tF2.next()) { nbTriangles ++; } // initialisation des segments et des attributs d'edge TraversorF tE(surfaceMap); for(Dart d = tE.begin() ; d != tE.end() ; d = tE.next()) { faceColor[d]=VEC3(r,g,b); #ifdef DEBUG_affichage CGoGNout<<" init Segment :"<< nbTriangles ; CGoGNout<<" || nb_segments :"<< triangles_.size() <envMap_.FirstRegistrationTriangle(o); } sim_->surfaces.push_back(this); // for(Dart d = tE.begin() ; d != tE.end() ; d = tE.next()) // { // CGoGNout<<" color face :"<setAttributeColor(m_colorVBO); m_shader->setAttributePosition(m_positionVBO); m_simpleColorShader = new Utils::ShaderSimpleColor(); m_simpleColorShader->setAttributePosition(m_positionVBO); m_simpleColorShader->setColor(Geom::Vec4f(0.,1.,0.,0.)); m_render->updateVBO(*m_positionVBO,*m_colorVBO,surfaceMap,positionSurface,faceColor); m_render_map->initPrimitives(surfaceMap, Algo::Render::GL2::LINES) ; // m_render->initPrimitives(surfaceMap, Algo::Render::GL2::TRIANGLES) ; } void Surface::draw() { m_positionVBO->updateData(positionSurface) ; glLineWidth(1.0f); m_render_map->draw(m_simpleColorShader,Algo::Render::GL2::LINES); // m_colorVBO->updateData(faceColor); // colorRender->updateVBO(m_positionVBO,m_colorVBO,surfaceMap,positionSurface,colorRender); m_render->updateVBO(*m_positionVBO,*m_colorVBO,surfaceMap,positionSurface,faceColor); m_simpleColorShader->setColor(Geom::Vec4f(0.0,0.0,0.0,0.)); m_render->draw(m_shader); } void Surface::initPlane() { CGoGNout<<" initialisation d'un plan"<< CGoGNendl ; Algo::Surface::Tilings::Triangular::Grid prim(surfaceMap, 1,1) ; prim.embedIntoGrid(positionSurface,1.0f,1.0f, 0.0f) ; TraversorV tv(surfaceMap); for(Dart d = tv.begin() ; d != tv.end() ; d = tv.next()) { positionSurface[d]*=4; } TraversorF tF(surfaceMap); for(Dart d = tF.begin() ; d != tF.end() ; d = tF.next()) { REAL dist = faceMaxdistance(d); if(dist < sim_->envMap_.maxCellRay) { sim_->envMap_.maxCellRay=dist; } } // bool test = false; // while (!test) // { // test = subdiveMap(); //// CGoGNout<<"subdiv effectuée ? " < toCheck; TraversorF tF(surfaceMap); surfaceMap.setCurrentLevel(surfaceMap.getMaxLevel()) ; for(Dart d = tF.begin() ; d != tF.end() ; d = tF.next()) { toCheck.push_back(d); } for(Dart d : toCheck) { REAL dist = faceMaxdistance(d); if(dist > sim_->envMap_.maxCellRay) { // CGoGNout<<"ok pour subdiv face :"<>(surfaceMap,face,positionSurface); REAL res = (positionSurface[d]-center).norm2(); for ( Vertex vert : verticesIncidentToFace2(surfaceMap,face)) { REAL size=(positionSurface[vert]-center).norm2(); if(size>res) { res=size; } } return res; } void Surface::initOperators(SubdivisionType st) { switch (st) { case LERP : //lerp subdiv mapOperator.setEdgeVertexFunctor(new Algo::MR::Primal::Masks::LerpEdgeVertexFunctor(surfaceMap,positionSurface)); mapOperator.setVertexVertexFunctor(new Algo::MR::Primal::Masks::LerpVertexVertexFunctor(surfaceMap,positionSurface)); mapOperator.setFaceVertexFunctor(new Algo::MR::Primal::Masks::LerpFaceVertexFunctor(surfaceMap,positionSurface)); break; case LOOP : //loop subdiv mapOperator.setEdgeVertexFunctor(new Algo::MR::Primal::Masks::LoopEdgeVertexFunctor(surfaceMap,positionSurface)); mapOperator.setVertexVertexFunctor(new Algo::MR::Primal::Masks::LoopVertexVertexFunctor(surfaceMap,positionSurface)); break; case CATC : //catmull subdiv mapOperator.setEdgeVertexFunctor(new Algo::MR::Primal::Masks::CCEdgeVertexFunctor(surfaceMap,positionSurface)); mapOperator.setVertexVertexFunctor(new Algo::MR::Primal::Masks::CCVertexVertexFunctor(surfaceMap,positionSurface)); mapOperator.setFaceVertexFunctor(new Algo::MR::Primal::Masks::CCFaceVertexFunctor(surfaceMap,positionSurface)); break; case SQRT3: //sqrt subdiv mapOperator.setVertexVertexFunctor(new Algo::MR::Primal::Masks::Sqrt3VertexVertexFunctor(surfaceMap,positionSurface)); mapOperator.setFaceVertexFunctor(new Algo::MR::Primal::Masks::Sqrt3FaceVertexFunctor(surfaceMap,positionSurface)); break; default : CGoGNerr<<" subdivtype inconnu "<<__FILE__<<__LINE__<=0) { if(distancer=1.0f; t->g=0.0f; t->b=0.0f; } else { float factor = (distanceColorationMini-distance)/(distanceColorationMini-distanceColorationMaxi); t->r= r+(1.0f- r)*factor; t->g= g- g*factor; t->b= b- b*factor; } } } else { t->r= r; t->g= g; t->b= b; } faceColor[t->cell]=VEC3(t->r,t->g,t->b); } void Surface::addGeneralCell ( Dart d) { bool added = false; for(std::pair& pere : general_belonging) { // if(sim_->envMap_.map.sameVolume(pere.first,d)) if(pere.first==d) { pere.second ++; added= true; break; } } if (!added) { general_belonging.push_back(std::make_pair(d,1)); } } /*removeGeneralCell * removes cell d to general belonging decreases the number of instance of the cell, if the number is 0 the celle is removed *forever* */ bool Surface::removeGeneralCell (Dart d) { for(std::pair& pere : general_belonging) { // if(sim_->envMap_.map.sameVolume(pere.first,d)) if(pere.first==d) { pere.second--; if(pere.second==0) { pere=general_belonging.back() ; general_belonging.pop_back() ; } return true; } }; return false; } void Surface::addGeneralNeighbor ( Dart d) { bool added = false; for(std::pair& pere : general_neighbors) { // if(sim_->envMap_.map.sameVolume(pere.first,d)) if(pere.first==d) { pere.second ++; added= true; break; } } if (!added) { general_neighbors.push_back(std::make_pair(d,1)); } } /*removeGeneralCell * removes cell d to general belonging decreases the number of instance of the cell, if the number is 0 the celle is removed *forever* */ bool Surface::removeGeneralNeighbor (Dart d) { for(std::pair& pere : general_neighbors) { // if(sim_->envMap_.map.sameVolume(pere.first,d)) if(pere.first==d) { pere.second--; if(pere.second==0) { pere=general_neighbors.back() ; general_neighbors.pop_back() ; } return true; } }; return false; } VEC3 Surface::getPosition(int index) { return parts_[index]->getPosition(); }