Commit f0feda38 authored by Thomas Pitiot 's avatar Thomas Pitiot

surfaces OK pb couleurs

parent 8a08dc0b
......@@ -11,7 +11,7 @@ SET (CGoGN_EXT_LIBS ${CGoGN_EXT_LIBS} ${QT_LIBRARIES} ${QGLVIEWER_LIBRAIRIES})
SET(CGoGN_ROOT_DIR ${CMAKE_SOURCE_DIR}/../../CGoGN CACHE STRING "CGoGN root dir")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g ")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -Wno-deprecated-register -Wno-overloaded-virtual")
include(${CGoGN_ROOT_DIR}/apps_cmake.txt)
#add_subdirectory(${CMAKE_SOURCE_DIR}/Release Release)
......
......@@ -15,24 +15,24 @@ class ArticulatedObject
{
public :
VEC3 getPositionSegment(int index) ;
void addGeneralCell ( Dart d);
bool removeGeneralCell (Dart d);
void addGeneralCell (std::vector< std::pair<Dart,int> > general_belonging, Dart d);
bool removeGeneralCell (std::vector< std::pair<Dart,int> > general_belonging,Dart d);
VEC3 getPosition(int index);
unsigned int nbVertices;
unsigned int nbEdges;
std::vector<CGoGN::Algo::Volume::MovingObjects::ParticleCell3D<PFP>*> parts_ ;
std::vector<PARTICULE*> parts_ ;
std::vector<Segment *> Segments_;
std::vector<Dart> * belonging_cells;
std::vector<Dart> * neighbor_cells;
std::vector<std::pair<Dart, int> > general_belonging;
std::vector<std::pair<Dart, int> > general_neighbors;
double width;
Simulator* sim_;
unsigned int index_articulated;
virtual void changeColor(Segment * s, float distance)=0;
bool surfaceToColor;
float r;
float g;
float b;
......@@ -40,7 +40,7 @@ public :
float distanceColorationMaxi;
};
void resetPart(Segment * o, Dart d1);
//void resetPart(Segment * o, Dart d1);
......
......@@ -19,6 +19,7 @@ public :
virtual void refine()=0;
void changeColor(Segment * s, float distance);
bool Needle_or_knife;
VEC3 closest_point; //temp
};
......
......@@ -31,10 +31,13 @@
using namespace CGoGN ;
class Segment;
#include "pfp.h"
#include "segment.h"
#include "triangle.h"
typedef CGoGN::Algo::Volume::MovingObjects::ParticleCell3D<PFP> PARTICULE;
typedef CGoGN::Algo::Volume::MovingObjects::ParticleCell3DMemo<PFP> PARTICULEMEMO;
class EnvMap
{
......@@ -70,14 +73,16 @@ public:
VolumeAttribute<VEC3, MAP> color ;
VolumeAttribute<ARETES, MAP> RegisteredEdges ;
VolumeAttribute<ARETES, MAP> RegisteredNeighborEdges ;
VolumeAttribute<TRIANGLES, MAP> RegisteredTriangles ;
VolumeAttribute<TRIANGLES, MAP> RegisteredNeighborTriangles ;
Geom::BoundingBox<PFP::VEC3> bb;
std::vector<Dart> getMemoCross(const VEC3& pos, const VEC3& dest, Dart& d1);
void FindNeighborCells (const std::vector<Dart>& belonging_cells, std::vector<Dart> * nieghbor_cells);
// Enregistrement Aretes//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
std::vector<Dart> getMemoCross(const VEC3& pos, const VEC3& dest, Dart& d1);
void FindNeighborCellsOfSegment (const std::vector<Dart>& belonging_cells, std::vector<Dart> * nieghbor_cells);
//
//
Dart popAndPushSegment(Segment* o);
void FirstRegistrationSegment(Segment * mo);
void pushAOneCellSegment(Segment * o, Dart d);
......@@ -90,21 +95,18 @@ public:
void resetPartSubdiv(Segment* o);
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//Enregistrement Surfaces
void popAndPushTriangle(Triangle* o); // pop et push d'une Triangle
void FirstRegistrationTriangle (Triangle* o); // premier enregistrement d'une Triangle
void markSameVolume(CellMarkerMemo<MAP,VOLUME> * memo_mark, CellMarkerMemo<MAP,VOLUME> *OneRingMark, Dart d); // enregistrer une dart dans une cellule
void markMultipleVolumes(CellMarkerMemo<MAP,VOLUME> * memo_mark, CellMarkerMemo<MAP,VOLUME> * OneRingMark, const std::vector<Dart>& memo_cross); // enregistrer une dart dans un ensemble de cellules
void popTriangle(Triangle* o);
//MULTIRES/////////////////////////////////////////////////////////////////////////////
// static const unsigned int nbAgentsToSubdivide = 1 ;
// static const unsigned int nbAgentsToSimplify = 0 ;
// void refine() ;
// void coarse() ;
// void updateMap() ;
// CellMarker<FACE> refineMark ;
// CellMarker<FACE> coarsenMark ;
// std::vector<Dart> refineCandidate ;
// std::vector<Dart> coarsenCandidate ;
///////////////////////////////////////////////////////////////////////////////////////
void pushTriangleInCell(Triangle* o, Dart d);
void popTriangleInCell(Triangle* o, Dart d);
void pushTriangleInCellAsNeighbor(Triangle* cell, Dart d);
void popTriangleInCellAsNeighbor(Triangle* cell, Dart d);
void resetPartSubdiv(Triangle* cell);
} ;
......@@ -146,35 +148,6 @@ inline bool removeElementFromVector(std::vector<T>& a, T ag)
return false ;
}
///////////////////////////////////////////////////////////////MULTIRES
//
//inline void EnvMap::nbAgentsIncrease(Dart d)
//{
// if (refineMark.isMarked(d)) return ;
// if (totalNeighborSize(d) < nbAgentsToSubdivide) return ;
//
// std::pair<bool, bool>& sf = subdivisableFace[d] ;
// if (sf.first == false || (sf.first == true && sf.second))
// {
// refineMark.mark(d) ;
// refineCandidate.push_back(d) ;
// }
//}
//
//inline void EnvMap::nbAgentsDecrease(Dart d)
//{
// if (coarsenMark.isMarked(d) || refineMark.isMarked(d)) return ;
// if (totalNeighborSize(d) > nbAgentsToSimplify) return ;
//
// coarsenMark.mark(d) ;
// coarsenCandidate.push_back(map.faceOldestDart(d)) ;
//}
//inline void EnvMap::clearUpdateCandidates()
//{
// refineCandidate.clear() ;
// coarsenCandidate.clear() ;
//}
/////////////////////////////////////////////////////////////////////REGISTRATIONS
inline std::vector<Dart> EnvMap::getMemoCross(const VEC3& pos, const VEC3& dest, Dart& d1)
......@@ -189,7 +162,7 @@ inline std::vector<Dart> EnvMap::getMemoCross(const VEC3& pos, const VEC3& dest,
}
inline void EnvMap::FindNeighborCellsOfSegment (const std::vector<Dart>& belonging_cells, std::vector<Dart> *neighbor_cells)
inline void EnvMap::FindNeighborCells (const std::vector<Dart>& belonging_cells, std::vector<Dart> *neighbor_cells)
{
#ifdef IHMap
assert(map.getCurrentLevel() == map.getMaxLevel());
......@@ -203,17 +176,9 @@ inline void EnvMap::FindNeighborCellsOfSegment (const std::vector<Dart>& belongi
for (std::vector<Dart>::const_iterator it =belonging_cells.begin();it<belonging_cells.end();++it)
memo_mark.mark(*it);
std::vector<Dart>::const_iterator it=belonging_cells.begin();
Dart dd=NIL;
// CGoGNout<<"debut neighbors cellules : ";
// for (std::vector<Dart>::const_iterator it =belonging_cells.begin();it<belonging_cells.end();++it)
// CGoGNout<<(*it).index<<" ; ";
// CGoGNout<<CGoGNendl;
do
{
dd = *it;
for (Vol d : volumesAdjacentByVertex3(map,(*it)))
for( Dart dd : belonging_cells)
{
for (Vol d : volumesAdjacentByVertex3(map,dd))
{
if (!map.isBoundaryMarked<3>(d) && !memo_mark.isMarked(d) && !OneRingMark.isMarked(d) )
......@@ -222,12 +187,13 @@ inline void EnvMap::FindNeighborCellsOfSegment (const std::vector<Dart>& belongi
(*neighbor_cells).push_back(d);
}
}
++it;
}while(it!=belonging_cells.end());
}
}
inline void EnvMap::pushSegmentInCellAsNeighbor(Segment* o, Dart d)
{
#ifdef IHMap
......@@ -249,8 +215,50 @@ inline void EnvMap::popSegmentInCellAsNeighbor(Segment* o, Dart d)
removeElementFromVector<Segment*>(RegisteredNeighborEdges[d],o);
}
inline void EnvMap::pushTriangleInCellAsNeighbor(Triangle* o, Dart d)
{
#ifdef IHMap
assert(map.getCurrentLevel() == map.getMaxLevel());
#endif
assert(std::find(RegisteredNeighborTriangles[d].begin(), RegisteredNeighborTriangles[d].end(), o) == RegisteredNeighborTriangles[d].end());
addElementToVector<Triangle *>(RegisteredNeighborTriangles[d],o);
}
inline void EnvMap::popTriangleInCellAsNeighbor(Triangle* o, Dart d)
{
#ifdef IHMap
assert(map.getCurrentLevel() == map.getMaxLevel());
#endif
assert(std::find(RegisteredNeighborTriangles[d].begin(), RegisteredNeighborTriangles[d].end(), o) != RegisteredNeighborTriangles[d].end());
removeElementFromVector<Triangle* >(RegisteredNeighborTriangles[d],o);
}
inline void EnvMap::pushTriangleInCell(Triangle * o, Dart d)
{
#ifdef IHMap
assert(map.getCurrentLevel() == map.getMaxLevel());
#endif
assert(std::find(RegisteredTriangles[d].begin(), RegisteredTriangles[d].end(), o) == RegisteredTriangles[d].end());
addElementToVector<Triangle* >(RegisteredTriangles[d],o);
}
inline void EnvMap::popTriangleInCell(Triangle* o, Dart d)
{
#ifdef IHMap
assert(map.getCurrentLevel() == map.getMaxLevel());
#endif
assert(std::find(RegisteredTriangles[d].begin(), RegisteredTriangles[d].end(), o) != RegisteredTriangles[d].end());
removeElementFromVector<Triangle* >(RegisteredTriangles[d],o);
}
#endif
......@@ -20,6 +20,11 @@
#include "Algo/Multiresolution/Map2MR/Masks/sqrt3.h"
#include "Topology/generic/parameters.h"
class Segment;
class Triangle;
typedef enum
{
LOOP = 0,
......@@ -40,6 +45,8 @@ struct PFP : public PFP_STANDARD
// definition des listes d'arêtes
typedef std::vector<Segment*> ARETE ;
typedef std::vector<Triangle*> TRIANGLE ;
typedef NoTypeNameAttribute<TRIANGLE> TRIANGLES ;
typedef NoTypeNameAttribute<ARETE> ARETES ;
//
......@@ -59,7 +66,7 @@ typedef PFP::MAP MAP;
typedef PFP::VEC3 VEC3 ;
typedef PFP::REAL REAL ;
typedef PFP::ARETES ARETES;
typedef PFP::TRIANGLES TRIANGLES;
#endif /* PFP_H_ */
#ifndef _Segment_H_
#define _Segment_H_
#include "env_map.h"
class ArticulatedObject;
class Segment
{
public:
Segment(const VEC3 point1, const VEC3 point2,
Segment(const VEC3 point1, const VEC3 point2,
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),
p1(point1), p2(point2),
nid(Needle),indexPart1(indexP1),indexPart2(indexP2), index(ind),r(rouge),g(green),b(blue)
{
}
VEC3 p1 ;
VEC3 p2 ;
VEC3 p1 ;
VEC3 p2 ;
// colors
ArticulatedObject * nid ;
......
#ifndef SIMULATOR_H
#define SIMULATOR_H
#include "env_map.h"
#include "needle.h"
#include "knife.h"
#include "tree.h"
#include "surface.h"
#include "segment.h"
using namespace CGoGN ;
class Simulator
......
......@@ -4,43 +4,95 @@
#include <iostream>
#include "glm/glm.hpp"
#include "env_map.h"
#include "ArticulatedObject.h"
#include "utils.h"
#include "Algo/Tiling/Surface/triangular.h"
#include "Algo/Render/GL2/mapRender.h"
#include "Utils/vbo.h"
#include "Utils/Shaders/shaderSimpleColor.h"
//#include "Utils/Shaders/shaderSimpleColor.h"
//#include "Algo/Render/GL2/colorPerFaceRender.h"
#include "Utils/Shaders/shaderColorPerVertex.h"
//particules
using namespace CGoGN ;
class Simulator;
class Surface : public ArticulatedObject
class Surface
{
public:
Surface(Simulator* sim, VEC3 offset) ;
VEC3 getPosition(int index);
unsigned int nbVertices;
unsigned int nbTriangles;
std::vector<PARTICULE*> parts_ ;
std::vector<Triangle *> triangles_;
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;
FaceAttribute<int, SURFACE> indexTriangle;
FaceAttribute<VEC3,SURFACE> faceColor;
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);
void initOperators(SubdivisionType st); // fonction de sélection du type de subdivision pour l'ihm2
void addGeneralCell (std::vector< std::pair<Dart,int> > general_belonging, Dart d);
bool removeGeneralCell (std::vector< std::pair<Dart,int> > general_belonging,Dart d);
std::vector<Dart> * belonging_cells;
std::vector<Dart> * neighbor_cells;
std::vector<std::pair<Dart, int> > general_belonging;
std::vector<std::pair<Dart, int> > general_neighbors;
double width;
Simulator* sim_;
unsigned int index_surface;
float r; // indice de couleur rouge
float g; // indice de couleur vert
float b; // indice de couleur bleu
float distanceColorationMini; // distance minimale pour commencer a virer rouge
float distanceColorationMaxi; // distance a partir de laquelle on est completement rouge
// 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;
void initGL(); // initialisation GL
void draw(); // redessiner l'objet
float rToDraw; // indice de rouge de la couleur a dessiner
float gToDraw; // indice de VERT de la couleur a dessiner
float bToDraw; // indice de BLeu de la couleur a dessiner
void changeColor(Triangle *t, float distance);
Algo::Render::GL2::MapRender* m_render; // render de l'objet
// Algo::Render::GL2::ColorPerFaceRender * m_render;
Utils::VBO* m_positionVBO; //VBO
Utils::VBO* m_colorVBO;
// Utils::ShaderSimpleColor* m_simpleColorShader; // shader
Utils::ShaderColorPerVertex * m_shader;
};
......
......@@ -105,8 +105,117 @@ inline float dist3D_Segment_to_Segment( std::pair<VEC3,VEC3> S1, std::pair<VEC3,
}
//===================================================================
inline VEC3 closestPointInTriangle(VEC3 p1, VEC3 p2, VEC3 p3, VEC3 obj)
{
VEC3 D = p1 - obj;
VEC3 E0=p2-p1, E1 = p3 -p1;
float a=E0*E0, b=E0*E1, c=E1*E1, d= E0*D, e=E1*D;
float det=a*c-b*b, s=b*e-c*d, t=b*d-a*e;
if((s+t) <det)
{
if(s<0)
{
if(t<0)
{
s=0;
t=0; //region 4
}
else
{
s=0;
if(e>=0)
{
t=0;
}
else
{
if( -e >= c)
{
t=1;
}
else
{
t= -e/c;
}
}
//region 3
}
}
else
{
if(t<0)
{
t=0;
if(d>=0)
{
s=0;
}
else
{
if( -d >= a)
{
s=1;
}
else
{
s= -d/a;
}
} //region 5
}
else
{
float invDet = 1/det;
s*=invDet;
t*=invDet; //region 0
}
}
}
else
{
if(s<0)
{
s=0;
t=1;//region 2
}
else
{
if(t<0)
{
s=1;
t=0; //region 6
}
else
{
//region 1
float numer =c+e-b-d;
if(numer <= 0)
{
s=0;
}
else
{
float denom=a-2*b+c;
s= numer >=denom ? 1 : numer/denom;
}
}
}
}
return s*E0 +t*E1 + p1;
}
inline float distSqPointLineSegment(VEC3 a1, VEC3 b1, const VEC3& c1)
......
......@@ -34,6 +34,7 @@
#include "Utils/colorMaps.h"
#include "Utils/vbo.h"
#include "Utils/fbo.h"
......@@ -89,6 +90,7 @@ class Volusion: public Utils::QT::SimpleQT
Algo::Render::GL2::ExplodeVolumeRender* m_explode_render;
unsigned int dartSlider;
//MovingObject
......
......@@ -6,7 +6,7 @@
*/
void ArticulatedObject::addGeneralCell ( Dart d)
void ArticulatedObject::addGeneralCell (std::vector< std::pair<Dart,int> > general_belonging, Dart d)
{
bool added = false;
std::vector< std::pair<Dart,int> >::iterator it =general_belonging.begin();
......@@ -30,7 +30,7 @@ void ArticulatedObject::addGeneralCell ( Dart d)
/*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 ArticulatedObject::removeGeneralCell (Dart d)
bool ArticulatedObject::removeGeneralCell (std::vector< std::pair<Dart,int> > general_belonging,Dart d)
{
std::vector< std::pair<Dart,int> >::iterator it =general_belonging.begin();
while (it != general_belonging.end() )
......@@ -133,25 +133,25 @@ VEC3 ArticulatedObject::getPositionSegment(int index)
// }
//}
/// a implementer 4 cas
void resetPart(Segment * o, Dart d1)
{
ArticulatedObject * nid = o->nid;
if(nid!=NULL)
{
int n1 = o->indexPart1;
int n2 = o->indexPart2;
///// a implementer 4 cas
//void resetPart(Segment * o, Dart d1)
//{
// ArticulatedObject * nid = o->nid;
// if(nid!=NULL)
// {
// int n1 = o->indexPart1;
// int n2 = o->indexPart2;
if (nid->parts_[n1]->d == nid->sim_->envMap_.map.phi1(d1))
nid->parts_[n1]->d = d1;
// if (nid->parts_[n1]->d == nid->sim_->envMap_.map.phi1(d1))
// nid->parts_[n1]->d = d1;
if (nid->parts_[n2]->d == nid->sim_->envMap_.map.phi1(d1))
nid->parts_[n2]->d = d1;
// if (nid->parts_[n2]->d == nid->sim_->envMap_.map.phi1(d1))
// nid->parts_[n2]->d = d1;
}
}
// }
//}
......
This diff is collapsed.
......@@ -12,8 +12,6 @@ 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];
......
......@@ -3,6 +3,8 @@
// initialisation Needle
Needle::Needle(Simulator* sim,std::pair<VEC3, Dart> startingPoint)
{
closest_point=VEC3(1000,1000,1000);
r=0.0f;
g=0.0f;
b=1.0f;
......@@ -15,7 +17,6 @@ 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();
......@@ -25,23 +26,10 @@ Needle::Needle(Simulator* sim,std::pair<VEC3, Dart> startingPoint)
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);
// }
createEdge(0);
#ifdef IHMap
refine();
// refine();
#endif
}
......@@ -51,44 +39,33 @@ void Needle::color_close()
if(nbVertices>0)
{
Dart volume = parts_[0]->d;
VEC3 pos=getPosition(0);
VEC3 pos=parts_[0]->getPosition();
float distSq=0;
for (Segment * s : sim_->envMap_.RegisteredEdges[volume])
{
if(s->nid!=this || s->index!=nbEdges)
{
float distSq=0;
if(s->nid->surfaceToColor) //coloration des surfaces
{
}
else //coloration des aretes
{
distSq = distSqPointLineSegment(s->p1,s->p2,pos);
}
distSq = distSqPointLineSegment(s->p1,s->p2,pos);
s->nid->changeColor(s,distSq);
}
}
for (Segment * s : sim_->envMap_.RegisteredNeighborEdges[volume])
{
if(s->nid!=this || s->index!=nbEdges)
{
float distSq=0;
if(s->nid->surfaceToColor) //coloration des surfaces
{
}
else //coloration des aretes
{
distSq = distSqPointLineSegment(s->p1,s->p2,pos);
}
distSq = distSqPointLineSegment(s->p1,s->p2,pos);
s->nid->changeColor(s,distSq);
}
}
for(Triangle * t : sim_->envMap_.RegisteredTriangles[volume])
{
VEC3 closest = closestPointInTriangle(t->p1,t->p2,t->p3,pos);
// CGoGNout<<"pos :"<<pos<<" || closest :"<<closest<<CGoGNendl;
distSq = (pos-closest).norm2();
if(distSq < ((pos-closest_point).norm2()))
closest_point=closest;
t->surf->changeColor(t,distSq);
}
}
}
......@@ -99,10 +76,8 @@ void Needle::unColor_close(Dart volume)
{
if(s->nid!=this || s->index!=nbEdges)
{
s->nid->changeColor(s,-1);