Commit a745baa5 authored by pitiot's avatar pitiot

debut ihm

parent 588e6cff
No preview for this file type
......@@ -55,7 +55,7 @@ public:
VEC3 mapMaxY;
VEC3 mapMinZ;
VEC3 mapMaxZ;
void subdivideVolume(Dart d);
Dart getBelongingCell(const PFP::VEC3& pos);
......
#ifndef Niddle_H
#define Niddle_H
#include <iostream>
#include "glm/glm.hpp"
#include "env_map.h"
#include "MovingObject.h"
//particules
using namespace CGoGN ;
class Simulator;
class Niddle : public MovingObject
{
public:
Niddle(Simulator* sim, std::pair<VEC3, Dart> startingPoint) ;
void move(VEC3 diff);
void createEdge(int index);
void color_close();
void unColor_close(Dart oldCell);
float edgeSize;
};
#endif
......@@ -2,17 +2,26 @@
#define PFP_H_
// carte
#define IHMap
#ifndef IHMap
#include "Topology/map/embeddedMap3.h"
//#include "Algo/ImplicitHierarchicalMesh/ihm3.hxx"
//
#include "Algo/Modelisation/tetrahedralization.h"
#else
#include "Algo/ImplicitHierarchicalMesh/ihm3.h"
#include "Algo/ImplicitHierarchicalMesh/subdivision3.h"
#endif
struct PFP : public PFP_STANDARD
{
// definition de la carte
// typedef Algo::Volume::IHM::ImplicitHierarchicalMap3 MAP ;
#ifndef IHMap
typedef EmbeddedMap3 MAP;
#else
typedef Algo::Volume::IHM::ImplicitHierarchicalMap3 MAP;
#endif
// definition des listes d'arêtes
typedef std::vector<Segment*> ARETE ;
typedef NoTypeNameAttribute<ARETE> ARETES ;
......
......@@ -2,14 +2,14 @@
#define _Segment_H_
#include "env_map.h"
class MovingObject;
class ArticulatedObject;
class Segment
{
public:
Segment(const VEC3 point1, const VEC3 point2,
MovingObject * niddle =NULL, unsigned int ind=0,float rouge=0,float green =0, float blue=1.0f) :
ArticulatedObject * Needle =NULL,unsigned int indexP1=0,unsigned int indexP2=0, unsigned int ind=0,float rouge=0,float green =0, float blue=1.0f) :
p1(point1), p2(point2),
nid(niddle), index(ind),r(rouge),g(green),b(blue)
nid(Needle),indexPart1(indexP1),indexPart2(indexP2), index(ind),r(rouge),g(green),b(blue)
{
}
......@@ -17,7 +17,9 @@ public:
VEC3 p2 ;
// colors
MovingObject * nid ;
ArticulatedObject * nid ;
unsigned int indexPart1;
unsigned int indexPart2;
unsigned int index ;
float r;
float g;
......
......@@ -2,8 +2,9 @@
#define SIMULATOR_H
#include "env_map.h"
#include "niddle.h"
#include "needle.h"
#include "knife.h"
#include "tree.h"
#include "segment.h"
using namespace CGoGN ;
......@@ -17,10 +18,13 @@ public:
void init(int argc, char **argv);
void doStep();
void initMovingObject();
void initFixedObjects();
void initEmptyMovingObject();
EnvMap envMap_;
double nbSteps_;
MovingObject * aiguille;
bool needle_or_knife;
std::vector<ArticulatedObject * >objects;
bool Needle_or_knife;
};
......
......@@ -31,8 +31,10 @@ void EnvMap::init(int argc, char **argv)
else
{
//Intialisation map
#ifdef IHMap
map.initImplicitProperties(); // Si map MR
#endif
// map.initImplicitProperties(); // Si map MR
///// initialisation attributs
position = map.addAttribute<VEC3, VERTEX, MAP>("position");
......@@ -47,7 +49,7 @@ void EnvMap::init(int argc, char **argv)
Algo::Volume::Tilings::Cubic::Grid<PFP> cubic(map, nb, nb, nb);
cubic.embedIntoGrid(position, 1.0f, 1.0f, 1.0f);
// subdivideVolume(map.begin());
// Algo::Surface::Modelisation::createTetrahedron<PFP>(map,true);
......@@ -132,6 +134,24 @@ 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
......@@ -375,10 +395,11 @@ void EnvMap::open_file(std::string filename)
void EnvMap::FirstRegistrationSegment(Segment * o)// réenregistre l'Segment en question
{
MovingObject * mo = o->nid;
ArticulatedObject * mo = o->nid;
if (mo != NULL)
{
int n = o->index;
int n1 = o->indexPart1;
int n2 = o->indexPart2;
#ifdef DEBUG_affichage
CGoGNout<<"First Registration arete "<<n<<CGoGNendl;
#endif
......@@ -388,8 +409,8 @@ void EnvMap::FirstRegistrationSegment(Segment * o)// réenregistre l'Segment en
Dart d1=NIL;
Dart d2=NIL;
std::vector<Dart> memo;
d1=mo->parts_[n]->d;
d2=mo->parts_[n+1]->d;
d1=mo->parts_[n1]->d;
d2=mo->parts_[n2]->d;
memo = getMemoCross(p1,p2,d1);
......@@ -414,13 +435,13 @@ Dart EnvMap::popAndPushSegment(Segment* o)// maj de l'enregistrement
popSegment(o);
FirstRegistrationSegment(o);
return o->nid->parts_[o->index]->d;;
return o->nid->parts_[o->indexPart1]->d;;
}
void EnvMap::pushAOneCellSegment(Segment * o, Dart d)
{
int n = o->index;
MovingObject * mo = o->nid;
ArticulatedObject * mo = o->nid;
#ifdef DEBUG_affichage
CGoGNout<<"Push in one cell segment arete "<<n<<CGoGNendl;
#endif
......@@ -451,7 +472,7 @@ void EnvMap::pushSegmentInSetOfCells(Segment* o, const std::vector<Dart>& memo_c
CGoGNout<<"Push in set of cells segment arete "<<n<<CGoGNendl;
#endif
assert(!memo_cross.empty());
MovingObject * mo = o->nid;
ArticulatedObject * mo = o->nid;
mo->belonging_cells[n] = memo_cross;
for (std::vector<Dart>::iterator it = mo->belonging_cells[n].begin(); it != mo->belonging_cells[n].end(); ++it)
......@@ -480,7 +501,7 @@ void EnvMap::pushSegmentInSetOfCells(Segment* o, const std::vector<Dart>& memo_c
void EnvMap::popSegment(Segment* o)
{
MovingObject * mo = o->nid;
ArticulatedObject * mo = o->nid;
int n = o->index;
assert(map.getCurrentLevel() == map.getMaxLevel()) ;
......
#include "simulator.h"
// initialisation niddle
Niddle::Niddle(Simulator* sim,std::pair<VEC3, Dart> startingPoint)
{
r=0.0f;
g=0.0f;
b=1.0f;
sim_=sim;
width=1.0;
niddle_or_knife=true;
nbVertices=2;
nbEdges=0;
edgeSize=1.0f;
distanceColorationMaxi=1.0f;
distanceColorationMini=5.0f;
parts_ = new CGoGN::Algo::Volume::MovingObjects::ParticleCell3D<PFP>*[nbVertices];
belonging_cells = new std::vector<Dart>[10000];
neighbor_cells = new std::vector<Dart>[10000];
parts_[0] = new CGoGN::Algo::Volume::MovingObjects::ParticleCell3D<PFP>(sim_->envMap_.map, startingPoint.second, startingPoint.first , sim_->envMap_.position);
parts_[1] = new CGoGN::Algo::Volume::MovingObjects::ParticleCell3D<PFP>(sim_->envMap_.map, startingPoint.second, startingPoint.first , sim_->envMap_.position);
this->color_close();
// for (unsigned int i = 0; i < nbEdges; i++)
// {
//#ifdef DEBUG_affichage
// CGoGNout<<" init Segment :"<< i ;
// CGoGNout<<" || nb_segments :"<< Segments_.size() <<CGoGNendl;
//#endif
// Segment* o = new Segment(parts_[i]->getPosition(),
// parts_[(i + 1)]->getPosition(),
// this, i);
// Segments_.push_back(o);
// sim_->envMap_.FirstRegistrationSegment(o);
// }
}
void Niddle::color_close()
{
Dart volume = parts_[0]->d;
VEC3 pos=getPosition(0);
for (Segment * s : sim_->envMap_.RegisteredEdges[volume])
{
if(s->nid!=this || s->index!=nbEdges)
{
float distSq = distSqPointLineSegment(s->p1,s->p2,pos);
if(distSq<distanceColorationMini)
{
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;
}
}
}
}
for (Segment * s : sim_->envMap_.RegisteredNeighborEdges[volume])
{
if(s->nid!=this || s->index!=nbEdges)
{
float distSq = distSqPointLineSegment(s->p1,s->p2,pos);
if(distSq<distanceColorationMini)
{
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;
}
}
}
}
}
void Niddle::unColor_close(Dart volume)
{
for (Segment * s : sim_->envMap_.RegisteredEdges[volume])
{
if(s->nid!=this || s->index!=nbEdges)
{
s->r=s->nid->r;
s->g=s->nid->g;
s->b=s->nid->b;
}
}
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;
}
}
}
void Niddle::createEdge(int index)
{
belonging_cells[nbEdges]=belonging_cells[0];
neighbor_cells[nbEdges]=neighbor_cells[0];
belonging_cells[0].clear();
neighbor_cells[0].clear();
Segment* o = new Segment(parts_[0]->getPosition(),
parts_[1]->getPosition(),
this, 0,r,g,b);
Segments_.push_back(o);
sim_->envMap_.FirstRegistrationSegment(o);
o->index=index;
}
void Niddle::move(VEC3 diff)
{
// VEC3 pos = getPosition(0)+diff;
// parts_[0]->move(pos);
Dart oldCell = parts_[0]->d;
VEC3 pos = getPosition(0)+diff;
if(sim_->envMap_.map.isVolumeIncidentToBoundary(parts_[0]->d))
{
if(!sim_->envMap_.checkPointInMap(pos,parts_[0]->d))
{
pos=pos-diff;
}
}
parts_[0]->move(pos);
// if(!parts_[0]->crossCell==CGoGN::Algo::Volume::MovingObjects::NO_CROSS) /// a rajouter si les cellules sont assez petites
// {
this->unColor_close(oldCell);
this->color_close();
// }
if((getPosition(0)-getPosition(1)).norm2()>edgeSize)
{
createEdge(nbEdges);
nbEdges++;
parts_[1]->move(getPosition(0));
#ifdef DEBUG_affichage
CGoGNout<<" init Segment :"<< nbEdges ;
CGoGNout<<" || nb_segments :"<< Segments_.size() <<CGoGNendl;
CGoGNout<<CGoGNendl;
CGoGNout<<CGoGNendl;
CGoGNout<<" Segment n° "<< nbEdges <<" enregistré dans "<< belonging_cells[0].size()<< " volumes." <<CGoGNendl;
for(unsigned int i =1;i<nbEdges;i++)
{
CGoGNout<<" Segment n° "<< i <<" enregistré dans "<< belonging_cells[i].size()<< " volumes." <<CGoGNendl;
}
#endif
}
}
......@@ -22,10 +22,13 @@ void Simulator::init(int argc, char **argv)
nbSteps_=0;
if (argc > 1)
needle_or_knife = atoi(argv[1]) ;
// needle_or_knife=false;
Needle_or_knife = atoi(argv[1]) ;
// Needle_or_knife=false;
initFixedObjects();
initMovingObject();
// initEmptyMovingObject();
}
void Simulator::doStep()
......@@ -34,16 +37,80 @@ void Simulator::doStep()
++nbSteps_ ;
}
void Simulator::initFixedObjects()
{
std::vector<std::pair<VEC3, Dart>> startingPoints ;
std::vector<std::pair<unsigned int, unsigned int>> segmentParts ;
std::pair<VEC3, Dart> p;
std::pair<unsigned int,unsigned int> ind;
VEC3 pos;
pos=VEC3(3,3,3);
p.first=pos;
p.second=envMap_.getBelongingCell(pos);
startingPoints.push_back(p);
pos=VEC3(-5,1,2);
p.first=pos;
p.second=envMap_.getBelongingCell(pos);
startingPoints.push_back(p);
pos=VEC3(4,-2,3);
p.first=pos;
p.second=envMap_.getBelongingCell(pos);
startingPoints.push_back(p);
pos=VEC3(1,-1,1);
p.first=pos;
p.second=envMap_.getBelongingCell(pos);
startingPoints.push_back(p);
pos=VEC3(2,-2.5f,0.5f);
p.first=pos;
p.second=envMap_.getBelongingCell(pos);
startingPoints.push_back(p);
ind.first=0;
ind.second=1;
segmentParts.push_back(ind);
ind.first=2;
ind.second=3;
segmentParts.push_back(ind);
ind.first=0;
ind.second=2;
segmentParts.push_back(ind);
ind.first=0;
ind.second=4;
segmentParts.push_back(ind);
ArticulatedObject * obj = new Tree(this,startingPoints,segmentParts);
objects.push_back(obj);
// CGoGNout<<"points :"<<p.first<<" ; "<<p2.first<<" ; "<</*p3.first<<*/CGoGNendl;
}
void Simulator::initEmptyMovingObject()
{
std::vector<std::pair<VEC3, Dart>> startingPoints ;
aiguille=new Knife(this,startingPoints);
// CGoGNout<<"points :"<<p.first<<" ; "<<p2.first<<" ; "<</*p3.first<<*/CGoGNendl;
}
void Simulator::initMovingObject()
{
if(needle_or_knife) // niddle
if(Needle_or_knife) // Needle
{
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.second=d;
aiguille=new Niddle(this,startingPoint);
aiguille=new Needle(this,startingPoint);
}
else // knife
{
......
......@@ -308,6 +308,45 @@ void Volusion::cb_redraw()
m_sprite->disableVertexAttribs();
}
if(true) // affichage objets fixes
{
for (ArticulatedObject * art : simul.objects)
{
m_ds->lineWidth(10.0f);
for(Segment * s : art->Segments_)
{
m_ds->newList(GL_COMPILE_AND_EXECUTE);
m_ds->begin(GL_LINE_STRIP);
m_ds->color3f(s->r,s->g,s->b);
m_ds->vertex(s->p1);
m_ds->vertex(s->p2);
m_ds->end();
m_ds->endList();
}
// VEC3 pos1 = simul.aiguille->parts_[0]->getPosition();
// VEC3 pos2 = simul.aiguille->parts_[1]->getPosition();
// float f;
// VEC3 cylinder_axis =cylinder->getAxisScale(2,f);
// m_frame_MovingObject->draw();
// CGoGNout<<Geom::angle(pos2-pos1,cylinder_axis)<<CGoGNendl;
// cylinder->rotate(Geom::angle(pos2-pos1,cylinder_axis),cylinder_axis^(pos2-pos1));
// cylinder->translate((((pos1+pos2)/2)-cylinder->getPosition())/2);
// cylinder->draw();
}
}
if(false) //affichage des normales
{
......@@ -573,8 +612,8 @@ void Volusion::cb_mouseMove(int buttons, int x, int y)
VEC3 diff = m_frame_MovingObject->getPosition()-oldPosSprite;
// CGoGNout<<"deplacement de : "<<diff<<CGoGNendl;
simul.aiguille->move(diff);
if(simul.aiguille->nbVertices>0)
simul.aiguille->move(diff);
startX=x;
startY=y;
......
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