Commit 8a08dc0b authored by Thomas Pitiot 's avatar Thomas Pitiot

ajout surfaces et changement sur les couleurs

parent f3141075
No preview for this file type
......@@ -31,8 +31,8 @@ public :
double width;
Simulator* sim_;
unsigned int index_articulated;
virtual void changeColor(Segment * s, float distance)=0;
bool surfaceToColor;
float r;
float g;
float b;
......
......@@ -17,7 +17,7 @@ public :
virtual void color_close()=0;
virtual void unColor_close(Dart oldCell)=0;
virtual void refine()=0;
void changeColor(Segment * s, float distance);
bool Needle_or_knife;
};
......
......@@ -54,7 +54,7 @@ public:
VEC3 mapMaxY;
VEC3 mapMinZ;
VEC3 mapMaxZ;
float maxCellSize;
float maxCellRay;
bool subdivideVolume(Dart d );
Dart getBelongingCell(const PFP::VEC3& pos);
......
......@@ -16,6 +16,7 @@ public:
void updateRegistration();
void move(VEC3 diff);
void color_close();
void unColor_close(Dart oldCell);
void refine();
......
......@@ -15,6 +15,8 @@ public:
void move(VEC3 diff);
void updateRegistration();
void createEdge(int index);
// Fonctions sur la coloration
void color_close();
void unColor_close(Dart oldCell);
float edgeSize;
......
......@@ -13,8 +13,21 @@
#include "Algo/ImplicitHierarchicalMesh/subdivision3.h"
#endif
#include "Topology/ihmap/ihm2.h"
#include "Algo/Multiresolution/IHM2/ihm2_PrimalAdapt.h"
#include "Algo/Multiresolution/Map2MR/Masks/loop.h"
#include "Algo/Multiresolution/Map2MR/Masks/lerp.h"
#include "Algo/Multiresolution/Map2MR/Masks/catmullClark.h"
#include "Algo/Multiresolution/Map2MR/Masks/sqrt3.h"
#include "Topology/generic/parameters.h"
typedef enum
{
LOOP = 0,
LERP,
CATC,
SQRT3
} SubdivisionType;
struct PFP : public PFP_STANDARD
{
// definition de la carte
......
......@@ -23,15 +23,21 @@ public:
Surface(Simulator* sim, VEC3 offset) ;
SURFACE surfaceMap; // map
CGoGN::Algo::MR::Primal::Adaptive::IHM2<PFPSurface> mapOperator;
VertexAttribute<VEC3, SURFACE> positionSurface ; //position
VertexAttribute<int, SURFACE> indexParticule; // index des particules de chaque sommet
EdgeAttribute<int,SURFACE> indexSegment;
void initPlane(); //initialisation d'une grille
REAL faceMaxdistance(Face face); //calcul du rayon max d'une face
bool subdiveMap(); //subdivision de la map
void initOperators(SubdivisionType st);
// visualisation
void initGL();
void draw();
float rToDraw;
float gToDraw;
float bToDraw;
void changeColor(Segment * s, float distance);
Algo::Render::GL2::MapRender* m_render;
Utils::VBO* m_positionVBO;
Utils::ShaderSimpleColor* m_simpleColorShader;
......
......@@ -15,7 +15,7 @@ class Tree : public ArticulatedObject
{
public:
Tree(Simulator* sim, std::vector<std::pair<VEC3, Dart>> startingPoints, std::vector<std::pair<unsigned int, unsigned int>> segmentParts) ;
void changeColor(Segment * s, float distance);
};
......
#include "simulator.h"
void MovingObject::changeColor(Segment * s, float distance)
{
if(distance >=0)
{
if(distance<distanceColorationMini)
{
if(distance<distanceColorationMaxi)
{
s->r=1.0f;
s->g=0.0f;
s->b=0.0f;
}
else
{
float factor = (distanceColorationMini-distance)/(distanceColorationMini-distanceColorationMaxi);
s->r= r+(1.0f- r)*factor;
s->g= g- g*factor;
s->b= b- b*factor;
}
}
}
else
{
s->r= r;
s->g= g;
s->b= b;
}
}
......@@ -22,7 +22,7 @@ EnvMap::EnvMap()
void EnvMap::init(int argc, char **argv)
{
maxCellSize = 10.0f;
maxCellRay = 2.0f;
std::cout << "Init EnvMap" << std::endl ;
if (argc>2)
{
......
......@@ -12,6 +12,7 @@ Knife::Knife(Simulator* sim,std::vector<std::pair<VEC3, Dart>> startingPoints)
nbVertices=startingPoints.size();
nbEdges=nbVertices==0?0:nbVertices-1;
index_articulated=sim->objects.size();
surfaceToColor=false;
belonging_cells = new std::vector<Dart>[nbEdges];
neighbor_cells = new std::vector<Dart>[nbEdges];
......
......@@ -15,7 +15,7 @@ Needle::Needle(Simulator* sim,std::pair<VEC3, Dart> startingPoint)
int maxEdges = 10000;
distanceColorationMaxi=0.25f;
distanceColorationMini=5.0f;
surfaceToColor=false;
belonging_cells = new std::vector<Dart>[maxEdges];
neighbor_cells = new std::vector<Dart>[maxEdges];
index_articulated=sim->objects.size();
......@@ -45,6 +45,7 @@ Needle::Needle(Simulator* sim,std::pair<VEC3, Dart> startingPoint)
#endif
}
void Needle::color_close()
{
if(nbVertices>0)
......@@ -55,25 +56,18 @@ void Needle::color_close()
{
if(s->nid!=this || s->index!=nbEdges)
{
float distSq = distSqPointLineSegment(s->p1,s->p2,pos);
if(distSq<distanceColorationMini)
float distSq=0;
if(s->nid->surfaceToColor) //coloration des surfaces
{
if(distSq<distanceColorationMaxi)
{
s->r=1.0f;
s->g=0.0f;
s->b=0.0f;
}
else
{
float factor = (distanceColorationMini-distSq)/(distanceColorationMini-distanceColorationMaxi);
s->r=s->nid->r+(1.0f-s->nid->r)*factor;
s->g=s->nid->g-s->nid->g*factor;
s->b=s->nid->b-s->nid->b*factor;
}
}
else //coloration des aretes
{
distSq = distSqPointLineSegment(s->p1,s->p2,pos);
}
s->nid->changeColor(s,distSq);
}
}
......@@ -81,24 +75,18 @@ void Needle::color_close()
{
if(s->nid!=this || s->index!=nbEdges)
{
float distSq = distSqPointLineSegment(s->p1,s->p2,pos);
if(distSq<distanceColorationMini)
float distSq=0;
if(s->nid->surfaceToColor) //coloration des surfaces
{
}
else //coloration des aretes
{
if(distSq<distanceColorationMaxi)
{
s->r=1.0f;
s->g=0.0f;
s->b=0.0f;
}
else
{
float factor = (distanceColorationMini-distSq)/(distanceColorationMini-distanceColorationMaxi);
s->r=s->nid->r+(1.0f-s->nid->r)*factor;
s->g=s->nid->g-s->nid->g*factor;
s->b=s->nid->b-s->nid->b*factor;
}
distSq = distSqPointLineSegment(s->p1,s->p2,pos);
}
s->nid->changeColor(s,distSq);
}
}
}
......@@ -111,18 +99,17 @@ void Needle::unColor_close(Dart volume)
{
if(s->nid!=this || s->index!=nbEdges)
{
s->r=s->nid->r;
s->g=s->nid->g;
s->b=s->nid->b;
s->nid->changeColor(s,-1);
}
}
for (Segment * s : sim_->envMap_.RegisteredNeighborEdges[volume])
{
if(s->nid!=this || s->index!=nbEdges)
{
s->r=s->nid->r;
s->g=s->nid->g;
s->b=s->nid->b;
s->nid->changeColor(s,-1);
}
}
}
......
......@@ -23,7 +23,8 @@ void Simulator::init(int argc, char **argv)
if (argc > 1)
Needle_or_knife = atoi(argv[1]) ;
// Needle_or_knife=false;
else
Needle_or_knife=true;
// initFixedObjects();
initSurfaces();
......@@ -41,7 +42,7 @@ void Simulator::doStep()
void Simulator::initSurfaces()
{
ArticulatedObject * obj = new Surface(this,VEC3(0.2f,0,0));
ArticulatedObject * obj = new Surface(this,VEC3(-1.0f,-1.5f,0.69f));
CGoGNout<<"surface initialisée : "<<obj->index_articulated<<CGoGNendl;
}
......
#include "simulator.h"
//initialisation Surface
Surface::Surface(Simulator* sim,VEC3 offset)
Surface::Surface(Simulator* sim,VEC3 offset):
mapOperator(surfaceMap)
{
r=0.1f;
g=0.4f;
b=0.5f;
r=rToDraw=1.0f;
g=gToDraw=0.627f;
b=bToDraw=0.0f;
sim_=sim;
width=1.0;
nbVertices=0;
nbEdges=0;
surfaceToColor=true;
surfaceMap.initImplicitProperties();
positionSurface = surfaceMap.addAttribute<VEC3, VERTEX, SURFACE>("positionSurface");
initOperators(LERP);
initPlane();
indexParticule = surfaceMap.addAttribute<int, VERTEX, SURFACE>("indexParticule");
indexSegment = surfaceMap.addAttribute<int, EDGE, SURFACE>("indexSegment");
initPlane();
index_articulated=sim->surfaces.size();
......@@ -91,7 +96,7 @@ void Surface::draw()
m_positionVBO->updateData(positionSurface) ;
glLineWidth(1.0f);
m_simpleColorShader->setColor(Geom::Vec4f(1.0,0.627,0.0,0.));
m_simpleColorShader->setColor(Geom::Vec4f(rToDraw,gToDraw,bToDraw,0.));
m_render->draw(m_simpleColorShader, Algo::Render::GL2::TRIANGLES);
m_simpleColorShader->setColor(Geom::Vec4f(0.0,0.0,0.0,0.));
m_render->draw(m_simpleColorShader, Algo::Render::GL2::LINES);
......@@ -103,7 +108,150 @@ void Surface::initPlane()
{
CGoGNout<<" initialisation d'un plan"<< CGoGNendl ;
Algo::Surface::Tilings::Triangular::Grid<PFPSurface> prim(surfaceMap, 2,2) ;
prim.embedIntoGrid(positionSurface,1.0f, 1.0f, 0.0f) ;
Algo::Surface::Tilings::Triangular::Grid<PFPSurface> prim(surfaceMap, 1,1) ;
prim.embedIntoGrid(positionSurface,1.0f,1.0f, 0.0f) ;
TraversorV<SURFACE> tv(surfaceMap);
for(Dart d = tv.begin() ; d != tv.end() ; d = tv.next())
{
positionSurface[d]*=4;
}
TraversorF<SURFACE> 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 ? " <<!test<<CGoGNendl;
}
}
bool Surface::subdiveMap()
{
bool res = true;
std::vector<Dart> toCheck;
TraversorF<SURFACE> 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 :"<<d<<CGoGNendl;
mapOperator.subdivideFace(d,true,false) ;
res=false;
}
surfaceMap.setCurrentLevel(surfaceMap.getMaxLevel()) ;
}
return res;
}
REAL Surface::faceMaxdistance(Face face)
{
Dart d = face;
VEC3 center = Algo::Surface::Geometry::faceCentroid<PFPSurface,VertexAttribute<VEC3,SURFACE>>(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<PFPSurface>(surfaceMap,positionSurface));
mapOperator.setVertexVertexFunctor(new Algo::MR::Primal::Masks::LerpVertexVertexFunctor<PFPSurface>(surfaceMap,positionSurface));
mapOperator.setFaceVertexFunctor(new Algo::MR::Primal::Masks::LerpFaceVertexFunctor<PFPSurface>(surfaceMap,positionSurface));
break;
case LOOP :
//loop subdiv
mapOperator.setEdgeVertexFunctor(new Algo::MR::Primal::Masks::LoopEdgeVertexFunctor<PFPSurface>(surfaceMap,positionSurface));
mapOperator.setVertexVertexFunctor(new Algo::MR::Primal::Masks::LoopVertexVertexFunctor<PFPSurface>(surfaceMap,positionSurface));
break;
case CATC :
//catmull subdiv
mapOperator.setEdgeVertexFunctor(new Algo::MR::Primal::Masks::CCEdgeVertexFunctor<PFPSurface>(surfaceMap,positionSurface));
mapOperator.setVertexVertexFunctor(new Algo::MR::Primal::Masks::CCVertexVertexFunctor<PFPSurface>(surfaceMap,positionSurface));
mapOperator.setFaceVertexFunctor(new Algo::MR::Primal::Masks::CCFaceVertexFunctor<PFPSurface>(surfaceMap,positionSurface));
break;
case SQRT3:
//sqrt subdiv
mapOperator.setVertexVertexFunctor(new Algo::MR::Primal::Masks::Sqrt3VertexVertexFunctor<PFPSurface>(surfaceMap,positionSurface));
mapOperator.setFaceVertexFunctor(new Algo::MR::Primal::Masks::Sqrt3FaceVertexFunctor<PFPSurface>(surfaceMap,positionSurface));
break;
default : CGoGNerr<<" subdivtype inconnu "<<__FILE__<<__LINE__<<CGoGNendl;
}
}
void Surface::changeColor(Segment * s, float distance)
{
if(distance >=0)
{
if(distance<distanceColorationMini)
{
if(distance<distanceColorationMaxi)
{
rToDraw=1.0f;
gToDraw=0.0f;
bToDraw=0.0f;
}
else
{
float factor = (distanceColorationMini-distance)/(distanceColorationMini-distanceColorationMaxi);
rToDraw= r+(1.0f- r)*factor;
gToDraw= g- g*factor;
bToDraw= b- b*factor;
}
}
}
else
{
rToDraw= r;
gToDraw= g;
bToDraw= b;
}
}
......@@ -11,7 +11,7 @@ Tree::Tree(Simulator* sim, std::vector<std::pair<VEC3, Dart>> startingPoints, st
width=1.0;
nbVertices=startingPoints.size();
nbEdges=segmentParts.size();
surfaceToColor=false;
belonging_cells = new std::vector<Dart>[nbEdges];
neighbor_cells = new std::vector<Dart>[nbEdges];
......@@ -42,3 +42,32 @@ Tree::Tree(Simulator* sim, std::vector<std::pair<VEC3, Dart>> startingPoints, st
sim_->objects.push_back(this);
}
void Tree::changeColor(Segment * s, float distance)
{
if(distance >=0)
{
if(distance<distanceColorationMini)
{
if(distance<distanceColorationMaxi)
{
s->r=1.0f;
s->g=0.0f;
s->b=0.0f;
}
else
{
float factor = (distanceColorationMini-distance)/(distanceColorationMini-distanceColorationMaxi);
s->r= r+(1.0f- r)*factor;
s->g= g- g*factor;
s->b= b- b*factor;
}
}
}
else
{
s->r= r;
s->g= g;
s->b= b;
}
}
......@@ -455,7 +455,23 @@ void Volusion::cb_redraw()
}
}
m_topo_render->updateData(simul.envMap_.map, simul.envMap_.position, 0.8f, 0.8f, 0.8f);
for (ArticulatedObject * o : simul.surfaces)
{
for(unsigned int i =0;i<o->nbEdges;i++)
{
// m_topo_render->overdrawDart(simul.aiguille->parts_[i]->d,10.0f,1.0f,0,0);
for(auto it = o->belonging_cells[i].begin(); it !=o->belonging_cells[i].end();++it)
{
for (Edge d : edgesIncidentToVolume3(simul.envMap_.map,(*it)))
{
m_topo_render->overdrawDart(d,5.0f,0.5f,0,0.4f);
}
}
}
}
if ((unsigned int)dock.comboBoxEdge->count()<simul.aiguille->nbEdges)
......
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