Commit d648ed89 authored by pitiot's avatar pitiot
Browse files

up

parent a745baa5
No preview for this file type
......@@ -2,6 +2,8 @@
#define ENV_MAP_H
#define DEBUG_affichage
//#define DEBUG
#include <iostream>
#include <algorithm>
......@@ -26,8 +28,6 @@
//#include "Algo/ImplicitHierarchicalMesh/subdivision3.hxx"
//#define DEBUG_affichage
//#define DEBUG
/////////////////particules
#include "Algo/MovingObjects/particle_cell_3D_memo.h"
......@@ -87,7 +87,7 @@ public:
void pushSegmentInCellAsNeighbor(Segment* o, Dart d);
void popSegmentInCellAsNeighbor(Segment* o, Dart d);
void resetPartSubdiv(Segment* o);
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
......
......@@ -149,6 +149,7 @@ protected:
void cb_mouseMove(int buttons, int x, int y);
void cb_mousePress(int button, int x, int y);
void cb_mouseRelease(int button, int x, int y);
void cb_keyPress(int code);
void cb_Open();
void animate() ;
......
......@@ -136,23 +136,6 @@ void EnvMap::init(int argc, char **argv)
}
void EnvMap::subdivideVolume(Dart dglobal)
{
unsigned int max = map.getMaxLevel() ;
map.setCurrentLevel(max) ;
std::cout << "dglobal = " << dglobal << std::endl;
if(!map.isBoundaryMarked(3,dglobal) && map.getDartLevel(dglobal) <= max && !map.volumeIsSubdivided(dglobal))
Algo::Volume::IHM::subdivideVolumeClassic<PFP>(map, dglobal, position);
map.setCurrentLevel(map.getMaxLevel()) ;
CGoGNout << "current level : " << map.getCurrentLevel() << CGoGNendl;
}
VEC3 EnvMap::normaleFromVolume(Dart volume,Dart face) // renvoie la normale a la face pointant vers l'extérieur du volume
{
......@@ -401,7 +384,7 @@ void EnvMap::FirstRegistrationSegment(Segment * o)// réenregistre l'Segment en
int n1 = o->indexPart1;
int n2 = o->indexPart2;
#ifdef DEBUG_affichage
CGoGNout<<"First Registration arete "<<n<<CGoGNendl;
CGoGNout<<"First Registration arete "<<o->index<<CGoGNendl;
#endif
VEC3 p1 = o->p1;
VEC3 p2 = o->p2;
......@@ -462,6 +445,14 @@ void EnvMap::pushAOneCellSegment(Segment * o, Dart d)
#ifdef DEBUG_affichage
CGoGNout<<"fin du push , etat du belong/neighbor : "<<mo->belonging_cells[n].size()<<"/"<<mo->neighbor_cells[n].size()<<CGoGNendl;
// if(mo->neighbor_cells[n].size()>26)
// {
// for(auto d : mo->neighbor_cells[n])
// {
// CGoGNout<<" || "<<d<<" || "<<CGoGNendl;
// }
// }
#endif
}
......@@ -496,6 +487,14 @@ void EnvMap::pushSegmentInSetOfCells(Segment* o, const std::vector<Dart>& memo_c
}
#ifdef DEBUG_affichage
CGoGNout<<"fin du push , etat du belong/neighbor : "<<mo->belonging_cells[n].size()<<"/"<<mo->neighbor_cells[n].size()<<CGoGNendl;
// if(mo->neighbor_cells[n].size()>26)
// {
// for(auto d : mo->neighbor_cells[n])
// {
// CGoGNout<<" || "<<d<<" || "<<CGoGNendl;
// }
// }
#endif
}
......@@ -523,181 +522,106 @@ void EnvMap::popSegment(Segment* o)
mo->neighbor_cells[n].clear();
}
}
//
//
//void EnvMap::refine()
//{
//// CGoGNout<<"refine"<<CGoGNendl;
// for (std::vector<Dart>::iterator it = refineCandidate.begin(); it != refineCandidate.end(); ++it)
// {
// Dart d = (*it) ;
// refineMark.unmark(d) ;
//
// //if the number of agents is big enough
// if (agentvect[d].size() > nbAgentsToSubdivide)
// {
// int fLevel = -1 ;
// Dart old = map.faceOldestDart(d) ;
//
// bool subdivisable = true ;
//
// //check if faces resulting from a subdivision are big enough
// std::pair<bool, bool>& sf = subdivisableFace[old] ;
// if (sf.first == true)
// subdivisable = sf.second ;
// else
// {
//// float minSizeSq = minCellSize * minCellSize ; // diametre de vision de l'agent au carré
// float minSizeSq = Agent::neighborDistSq_;
//
// fLevel = map.faceLevel(old) ;
// map.setCurrentLevel(fLevel) ;
// PFP::VEC3 fCenter = Algo::Surface::Geometry::faceCentroid<PFP>(map, old, position) ;
// Dart fd = old ;
// do
// {
// PFP::VEC3& p = position[fd] ;
// PFP::VEC3 edge = Algo::Surface::Geometry::vectorOutOfDart<PFP>(map, fd, position) ;
// PFP::VEC3 proj = fCenter - (p + (edge * (fCenter - p) / edge.norm2()) * edge) ;
// if (proj.norm2() < minSizeSq)
// {
// subdivisable = false ;
// break ;
// }
// fd = map.phi1(fd) ;
// } while (fd != old) ;
// map.setCurrentLevel(map.getMaxLevel()) ;
//
// sf.first = true ;
// sf.second = subdivisable ;
// }
//
// if (subdivisable)
// {
// if (fLevel == -1)
// fLevel = map.faceLevel(old) ;
//
// sf.first = false ;
//
// PFP::AGENTS oldAgents(agentvect[old]) ;
// PFP::SegmentVECT oldObst(RegisteredEdges[old]) ;
// PFP::SegmentVECT oldNeighborObst(neighborRegisteredEdges[old]) ;
//
// for (PFP::AGENTS::iterator ait = oldAgents.begin(); ait != oldAgents.end(); ++ait)
// {
// popAgentInCells(*ait, old) ;
// }
// for (PFP::SegmentVECT::iterator ait = oldObst.begin(); ait != oldObst.end(); ++ait)
// this->popSegment(*ait) ;
// for (PFP::SegmentVECT::iterator ait = oldNeighborObst.begin();ait != oldNeighborObst.end(); ++ait)
// this->popSegment(*ait) ;
// neighborAgentvect[old].clear() ;
//
// map.setCurrentLevel(fLevel) ;
// Algo::Surface::IHM::subdivideFace<PFP>(map, old, position) ;
// CellMarkerStore<FACE> newF(map) ;
// unsigned int degree = 0 ;
// Dart dd = old ;
// do
// {
// ++degree ;
// newF.mark(dd) ;
// dd = map.phi1(dd) ;
// } while (dd != old) ;
// map.setCurrentLevel(fLevel+1) ;
// if (degree == 3)
// {
// Dart centerFace = map.phi2(map.phi1(old)) ;
// newF.mark(centerFace) ;
// }
//
// map.setCurrentLevel(map.getMaxLevel()) ;
// //retrieve neighbors agents from onering cells
// dd = old ;
// do
// {
// Dart d3 = dd ;
//
// do
// {
// Dart d4 = map.alpha1(map.alpha1(d3)) ;
// PFP::AGENTS& nad3 = neighborAgentvect[d3] ;
// while (d4 != d3)
// {
// if (!newF.isMarked(d4))
// {
// PFP::AGENTS& ad4 = agentvect[d4] ;
// nad3.insert(nad3.end(), ad4.begin(), ad4.end()) ;
// }
// d4 = map.alpha1(d4) ;
// }
// d3 = map.phi1(d3) ;
// } while (d3 != dd) ;
//
// map.setCurrentLevel(fLevel) ;
// dd = map.phi1(dd) ;
// map.setCurrentLevel(map.getMaxLevel()) ;
// } while (dd != old) ;
//
//
//
// if (degree == 3)
// {
// map.setCurrentLevel(fLevel+1) ;
// Dart centerFace = map.phi2(map.phi1(old)) ;
// map.setCurrentLevel(map.getMaxLevel()) ;
// Dart d3 = centerFace ;
// do
// {
// Dart d4 = map.alpha1(map.alpha1(d3)) ;
// PFP::AGENTS& nad3 = neighborAgentvect[d3] ;
// while (d4 != d3)
// {
// if (!newF.isMarked(d4))
// {
// PFP::AGENTS& ad4 = agentvect[d4] ;
// nad3.insert(neighborAgentvect[d3].end(), ad4.begin(), ad4.end()) ;
// }
// d4 = map.alpha1(d4) ;
// }
// d3 = map.phi1(d3) ;
// } while (d3 != centerFace) ;
// }
//
// //agents contained in the subdivided cell are pushed correctly
// for (PFP::AGENTS::iterator ait = oldAgents.begin(); ait != oldAgents.end(); ++ait)
// {
//// CGoGNout<<"reseting Agents"<<CGoGNendl;
// resetAgentInFace(*ait) ;
// pushAgentInCells(*ait, (*ait)->part_.d) ;
// }
//
// //same for Segments contained
// for (PFP::SegmentVECT::iterator ait = oldObst.begin(); ait != oldObst.end(); ++ait)
// {
//// CGoGNout<<"reseting Segments"<<CGoGNendl;
// resetPartSubdiv(*ait);
// pushSegmentInSetOfCells(*ait);
//
// }
//
// //same for adjacent Segments
// for (PFP::SegmentVECT::iterator ait = oldNeighborObst.begin();
// ait != oldNeighborObst.end(); ++ait)
// {
// pushSegmentInSetOfCells(*ait) ;
// }
//
//
//// CGoGNout<<"fin refine"<<CGoGNendl;
// }
// }
// }
// refineCandidate.clear() ;
//
//}
//
//
void EnvMap::subdivideVolume(Dart dglobal)
{
CGoGNout<<"debut refine"<<CGoGNendl;
unsigned int max = map.getMaxLevel() ;
map.setCurrentLevel(max) ;
std::cout << "dglobal = " << dglobal << "level = "<< max << std::endl;
ARETES oldobst(RegisteredEdges[dglobal]) ;
ARETES oldNeighborObst(RegisteredNeighborEdges[dglobal]) ;
for (Segment * s : oldobst)
this->popSegment(s) ;
for (Segment * s : oldNeighborObst)
this->popSegment(s) ;
if(!map.isBoundaryMarked(3,dglobal) )
{
#ifdef DEBUG_affichage
CGoGNout<<"debut subdivision"<< CGoGNendl;
#endif
Algo::Volume::IHM::subdivideVolumeClassic<PFP>(map, dglobal, position);
}
map.setCurrentLevel(map.getMaxLevel()) ;
map.check();
std::cout << "after level = "<< map.getMaxLevel() << std::endl;
//same for adjacent obstacles // optimiser
for (Segment * s : oldNeighborObst)
{
FirstRegistrationSegment(s) ;
}
//same for obstacles contained
for (Segment * s : oldobst)
{
// CGoGNout<<"reseting Obstacles"<<CGoGNendl;
resetPartSubdiv(s);
FirstRegistrationSegment(s);
}
CGoGNout<<"fin refine"<<CGoGNendl;
}
void EnvMap::resetPartSubdiv(Segment* o)
{
ArticulatedObject * mo = o->nid;
if (mo != NULL)
{
VEC3 pos = mo->parts_[o->indexPart1]->getPosition();
VEC3 pos2 = mo->parts_[o->indexPart2]->getPosition();
Dart d1 =mo->parts_[o->indexPart1]->d;
Dart d2 =mo->parts_[o->indexPart2]->d;
#ifdef DEBUG_affichage
CGoGNout<<"Reset part subdiv (segment ,ind1, pos1, d1, ind2, pos2, d2) : "<<o->index<<" || "<<o->indexPart1<<" || "<<pos<<" || "<<d1<<" || "<<o->indexPart2<<" || "<<pos2<<" || "<<d2<<CGoGNendl;
CGoGNout<<"Faces centroids : "<<Algo::Surface::Geometry::volumeCentroid<PFP,VertexAttribute<VEC3,MAP>>(map,d1,position)<<" || "<<Algo::Surface::Geometry::volumeCentroid<PFP,VertexAttribute<VEC3,MAP>>(map,d2,position)<<CGoGNendl;
#endif
mo->parts_[o->indexPart1]->CGoGN::Algo::MovingObjects::ParticleBase<PFP>::move(Algo::Surface::Geometry::volumeCentroid<PFP,VertexAttribute<VEC3,MAP>>(map,d1,position)) ;
#ifdef DEBUG_affichage
CGoGNout<<"part1 moved to centroid ,d : "<< mo->parts_[o->indexPart1]->getPosition()<<" || "<<mo->parts_[o->indexPart1]->d<<CGoGNendl;
#endif
mo->parts_[o->indexPart1]->setState(VOLUME) ;
mo->parts_[o->indexPart1]->move(pos) ;
#ifdef DEBUG_affichage
CGoGNout<<"part1 moved in the end (destination, arrivée,d) : "<<pos<<" || "<< mo->parts_[o->indexPart1]->getPosition()<<" || "<<mo->parts_[o->indexPart1]->d<<CGoGNendl;
#endif
mo->parts_[o->indexPart2]->CGoGN::Algo::MovingObjects::ParticleBase<PFP>::move(Algo::Surface::Geometry::volumeCentroid<PFP,VertexAttribute<VEC3,MAP>>(map,d2,position)) ;
#ifdef DEBUG_affichage
CGoGNout<<"part2 moved to centroid ,d : "<< mo->parts_[o->indexPart2]->getPosition()<<" || "<<mo->parts_[o->indexPart2]->d<<CGoGNendl;
#endif
mo->parts_[o->indexPart2]->setState(VOLUME) ;
mo->parts_[o->indexPart2]->move(pos2) ;
#ifdef DEBUG_affichage
CGoGNout<<"part2 moved in the end (destination, arrivée,d) : "<<pos2<<" || "<< mo->parts_[o->indexPart2]->getPosition()<<" || "<<mo->parts_[o->indexPart2]->d<<CGoGNendl;
#endif
}
}
//void EnvMap::coarse()
//{
//// CGoGNout<<"coarse"<<CGoGNendl;
......
......@@ -109,6 +109,7 @@ void Simulator::initMovingObject()
std::pair<VEC3, Dart> startingPoint ;
Dart d=envMap_.map.indexDart(40);
startingPoint.first=Algo::Surface::Geometry::volumeCentroid<PFP,VertexAttribute<VEC3,MAP>>(envMap_.map,d,envMap_.position);
// startingPoint.first=VEC3(-2.5f,-2.5f,2.5f);
startingPoint.second=d;
aiguille=new Needle(this,startingPoint);
}
......
......@@ -148,6 +148,25 @@ void Volusion::slider_released()
updateGL();
}
void Volusion::cb_keyPress(int code)
{
switch(code)
{
case 'r' :
{
simul.aiguille->refine();
m_MovingObjectVBO->updateData(simul.envMap_.position);
updateGL() ;
break;
}
}
}
void Volusion::cb_Open()
{
std::string filters("all (*.*)") ;
......@@ -209,7 +228,7 @@ void Volusion::cb_initGL()
m_MovingObjectVBO = new Utils::VBO();
m_MovingObjectVBO->setDataSize(3);
m_MovingObjectVBO->allocate(simul.aiguille->nbVertices);
m_MovingObjectVBO->allocate(10000);
//initialisation aiguille
......@@ -267,7 +286,11 @@ void Volusion::cb_redraw()
m_ds->begin(GL_LINE_STRIP);
m_ds->lineWidth(10.0f);
if(simul.aiguille->nbEdges>0)
{
VEC3 origin = simul.aiguille->Segments_[0]->p1;
m_ds->vertex(origin);
}
for(Segment * s : simul.aiguille->Segments_)
{
m_ds->color3f(s->r,s->g,s->b);
......@@ -275,8 +298,7 @@ void Volusion::cb_redraw()
m_ds->vertex(p);
}
m_ds->color3f(0,0.5f,1.0f);
m_ds->vertex(simul.aiguille->parts_[1]->getPosition());
m_ds->vertex(simul.aiguille->parts_[0]->getPosition());
m_ds->end();
m_ds->endList();
......@@ -285,12 +307,13 @@ void Volusion::cb_redraw()
// float f;
// VEC3 cylinder_axis =cylinder->getAxisScale(2,f);
PFP::VEC3* data = static_cast<PFP::VEC3*>(m_MovingObjectVBO->lockPtr());
int n= simul.aiguille->nbVertices;
for(int i = 0; i< n; i ++)
int i=0;
for(auto particule : simul.aiguille->parts_)
{
VEC3 p = simul.aiguille->parts_[i]->getPosition();
VEC3 p = particule->getPosition();
data[i] = p;
i++;
}
......@@ -366,14 +389,20 @@ void Volusion::cb_redraw()
}
if (draw_dart && dartSlider < (simul.envMap_.map.end().index))
if (draw_dart)
{
m_topo_render->updateData(simul.envMap_.map, simul.envMap_.position, 0.8f, 0.8f, 0.8f);
dock.spinBox_dart->setRange(0, simul.envMap_.map.end().index) ;
if( dartSlider < (simul.envMap_.map.end().index))
{
m_topo_render->overdrawDart(simul.envMap_.map.indexDart(dartSlider),15.0f,1.0f,0.0f,1.0f);
}
}
if(render_belonging)
{
m_topo_render->updateData(simul.envMap_.map, simul.envMap_.position, 0.8f, 0.8f, 0.8f);
if (dock.comboBoxEdge->count()<simul.aiguille->nbEdges)
{
dock.comboBoxEdge->clear();
......@@ -430,6 +459,7 @@ void Volusion::cb_redraw()
if(render_neighbors)
{
m_topo_render->updateData(simul.envMap_.map, simul.envMap_.position, 0.8f, 0.8f, 0.8f);
if(val_comboEdge==0)
{
for(unsigned int i =0;i<simul.aiguille->nbEdges;i++)
......@@ -465,8 +495,10 @@ void Volusion::cb_redraw()
}
if (render_topo)
{
m_topo_render->updateData(simul.envMap_.map, simul.envMap_.position, 0.8f, 0.8f, 0.8f);
m_topo_render->drawTopo();
}
......@@ -474,6 +506,7 @@ void Volusion::cb_redraw()
if (render_edges)
{
glLineWidth(2.0f);
m_explode_render->updateData<PFP>(simul.envMap_.map, simul.envMap_.position, simul.envMap_.color);
m_explode_render->drawEdges();
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment