Commit 24f25f0b authored by Basile Sauvage's avatar Basile Sauvage
Browse files

Merge cgogn.u-strasbg.fr:~cgogn/CGoGN

parents dd8c02f5 878c41f4
...@@ -191,6 +191,18 @@ void Viewer::cb_Save() ...@@ -191,6 +191,18 @@ void Viewer::cb_Save()
exportMesh(filename) ; exportMesh(filename) ;
} }
void Viewer::cb_keyPress(int keycode)
{
switch(keycode)
{
case 'c' :
myMap.check();
break;
default:
break;
}
}
void Viewer::importMesh(std::string& filename) void Viewer::importMesh(std::string& filename)
{ {
myMap.clear(true) ; myMap.clear(true) ;
...@@ -311,21 +323,6 @@ void Viewer::slot_normalsSize(int i) ...@@ -311,21 +323,6 @@ void Viewer::slot_normalsSize(int i)
updateGL() ; updateGL() ;
} }
void Viewer::cb_keyPress(int keycode)
{
switch(keycode)
{
case 'c' :
myMap.check();
break;
default:
break;
}
updateGLMatrices() ;
updateGL();
}
/********************************************************************************************** /**********************************************************************************************
* MAIN FUNCTION * * MAIN FUNCTION *
**********************************************************************************************/ **********************************************************************************************/
......
...@@ -46,6 +46,8 @@ ...@@ -46,6 +46,8 @@
#include "Utils/Shaders/shaderVectorPerVertex.h" #include "Utils/Shaders/shaderVectorPerVertex.h"
#include "Utils/pointSprite.h" #include "Utils/pointSprite.h"
#include "Utils/text3d.h" #include "Utils/text3d.h"
#include "Utils/vboRender.h"
#include "Utils/Qt/qtInputs.h" #include "Utils/Qt/qtInputs.h"
#include "Algo/Geometry/boundingbox.h" #include "Algo/Geometry/boundingbox.h"
......
...@@ -90,20 +90,20 @@ public: ...@@ -90,20 +90,20 @@ public:
do do
{ {
Dart next = map.phi1(it) ; Dart next = map.phi1(it) ;
unsigned int emb = map.getEmbedding<VERTEX>(it) ; unsigned int emb = map.template getEmbedding<VERTEX>(it) ;
unsigned int idx = emb == v0 ? 0 : emb == v1 ? 1 : 2 ; unsigned int idx = emb == v0 ? 0 : emb == v1 ? 1 : 2 ;
map.incCurrentLevel() ; map.incCurrentLevel() ;
Dart dd = map.phi1(next) ; Dart dd = map.phi1(next) ;
unsigned int oldEmb = map.getEmbedding<VERTEX>(dd) ; unsigned int oldEmb = map.template getEmbedding<VERTEX>(dd) ;
unsigned int newEmb = vID[children[0]->indices[idx]] ; unsigned int newEmb = vID[children[0]->indices[idx]] ;
if(oldEmb == EMBNULL) if(oldEmb == EMBNULL)
{ {
map.embedOrbit<VERTEX>(dd, newEmb) ; map.template embedOrbit<VERTEX>(dd, newEmb) ;
map.pushLevel() ; map.pushLevel() ;
for(unsigned int i = map.getCurrentLevel() + 1; i <= map.getMaxLevel(); ++i) for(unsigned int i = map.getCurrentLevel() + 1; i <= map.getMaxLevel(); ++i)
{ {
map.setCurrentLevel(i) ; map.setCurrentLevel(i) ;
map.embedOrbit<VERTEX>(dd, newEmb) ; map.template embedOrbit<VERTEX>(dd, newEmb) ;
} }
map.popLevel() ; map.popLevel() ;
} }
...@@ -120,7 +120,7 @@ public: ...@@ -120,7 +120,7 @@ public:
do do
{ {
unsigned int emb = map.getEmbedding<VERTEX>(it) ; unsigned int emb = map.template getEmbedding<VERTEX>(it) ;
unsigned int idx = emb == v0 ? 0 : emb == v1 ? 1 : 2 ; unsigned int idx = emb == v0 ? 0 : emb == v1 ? 1 : 2 ;
map.incCurrentLevel() ; map.incCurrentLevel() ;
children[idx+1]->embed<PFP>(map, it, vID) ; children[idx+1]->embed<PFP>(map, it, vID) ;
......
...@@ -41,14 +41,13 @@ inline void nextNonEmptyLine(std::ifstream& fp, std::string& line) ...@@ -41,14 +41,13 @@ inline void nextNonEmptyLine(std::ifstream& fp, std::string& line)
template <typename PFP> template <typename PFP>
bool importMRDAT(typename PFP::MAP& map, const std::string& filename, std::vector<std::string>& attrNames, QuadTree& qt) bool importMRDAT(typename PFP::MAP& map, const std::string& filename, std::vector<std::string>& attrNames, QuadTree& qt)
{ {
VertexAttribute<typename PFP::VEC3> position = map.template getAttribute<typename PFP::VEC3>(VERTEX, "position") ; VertexAttribute<typename PFP::VEC3> position = map.template getAttribute<typename PFP::VEC3, VERTEX>("position") ;
if (!position.isValid()) if (!position.isValid())
position = map.template addAttribute<typename PFP::VEC3>(VERTEX, "position") ; position = map.template addAttribute<typename PFP::VEC3, VERTEX>("position") ;
attrNames.push_back(position.name()) ; attrNames.push_back(position.name()) ;
AttributeContainer& container = map.getAttributeContainer(VERTEX) ; AttributeContainer& container = map.template getAttributeContainer<VERTEX>() ;
// open file // open file
std::ifstream fp(filename.c_str(), std::ios::in) ; std::ifstream fp(filename.c_str(), std::ios::in) ;
...@@ -206,7 +205,7 @@ bool importMRDAT(typename PFP::MAP& map, const std::string& filename, std::vecto ...@@ -206,7 +205,7 @@ bool importMRDAT(typename PFP::MAP& map, const std::string& filename, std::vecto
unsigned int emb = qt.verticesID[idx] ; unsigned int emb = qt.verticesID[idx] ;
FunctorSetEmb<typename PFP::MAP, VERTEX> fsetemb(map, emb) ; FunctorSetEmb<typename PFP::MAP, VERTEX> fsetemb(map, emb) ;
map.foreach_dart_of_orbit<PFP::MAP::VERTEX_OF_PARENT>(d, fsetemb) ; map.template foreach_dart_of_orbit<PFP::MAP::VERTEX_OF_PARENT>(d, fsetemb) ;
m.mark(d) ; // mark on the fly to unmark on second loop m.mark(d) ; // mark on the fly to unmark on second loop
vecDartsPerVertex[emb].push_back(d) ; // store incident darts for fast adjacency reconstruction vecDartsPerVertex[emb].push_back(d) ; // store incident darts for fast adjacency reconstruction
...@@ -223,11 +222,11 @@ bool importMRDAT(typename PFP::MAP& map, const std::string& filename, std::vecto ...@@ -223,11 +222,11 @@ bool importMRDAT(typename PFP::MAP& map, const std::string& filename, std::vecto
// darts incident to end vertex of edge // darts incident to end vertex of edge
std::vector<Dart>& vec = vecDartsPerVertex[map.phi1(d)] ; std::vector<Dart>& vec = vecDartsPerVertex[map.phi1(d)] ;
unsigned int embd = map.getEmbedding<VERTEX>(d) ; unsigned int embd = map.template getEmbedding<VERTEX>(d) ;
Dart good_dart = NIL ; Dart good_dart = NIL ;
for (typename std::vector<Dart>::iterator it = vec.begin(); it != vec.end() && good_dart == NIL; ++it) for (typename std::vector<Dart>::iterator it = vec.begin(); it != vec.end() && good_dart == NIL; ++it)
{ {
if (map.getEmbedding<VERTEX>(map.phi1(*it)) == embd) if (map.template getEmbedding<VERTEX>(map.phi1(*it)) == embd)
good_dart = *it ; good_dart = *it ;
} }
......
...@@ -105,6 +105,11 @@ void foreach_orbit(typename PFP::MAP& map, FunctorMapThreaded<typename PFP::MAP> ...@@ -105,6 +105,11 @@ void foreach_orbit(typename PFP::MAP& map, FunctorMapThreaded<typename PFP::MAP>
template <typename PFP, unsigned int CELL> template <typename PFP, unsigned int CELL>
void foreach_cell(typename PFP::MAP& map, FunctorMapThreaded<typename PFP::MAP>& func, unsigned int nbth, unsigned int szbuff = 8192, bool needMarkers = false, const FunctorSelect& good = allDarts); void foreach_cell(typename PFP::MAP& map, FunctorMapThreaded<typename PFP::MAP>& func, unsigned int nbth, unsigned int szbuff = 8192, bool needMarkers = false, const FunctorSelect& good = allDarts);
template <typename PFP, unsigned int CELL>
void foreach_cell2Pass(typename PFP::MAP& map, FunctorMapThreaded<typename PFP::MAP>& funcFront, FunctorMapThreaded<typename PFP::MAP>& funcBack, unsigned int nbLoops, unsigned int nbth, unsigned int szbuff = 8192, bool needMarkers = false, const FunctorSelect& good = allDarts);
/** /**
* Traverse darts of a map in parallel * Traverse darts of a map in parallel
* Functor application must be independant * Functor application must be independant
...@@ -187,6 +192,7 @@ T maxResult(const std::vector<T>& res); ...@@ -187,6 +192,7 @@ T maxResult(const std::vector<T>& res);
template <typename T> template <typename T>
T minResult(const std::vector<T>& res); T minResult(const std::vector<T>& res);
/** /**
* Class to encapsulate algorithm in a boost thread * Class to encapsulate algorithm in a boost thread
* Usage: * Usage:
......
...@@ -788,6 +788,199 @@ T minResult(const std::vector<T>& res) ...@@ -788,6 +788,199 @@ T minResult(const std::vector<T>& res)
return minr; return minr;
} }
/**
* Traverse cells of a map in parallel. Use embedding marker
* Functor application must be independant
* @param map the map
* @param func the functor to apply
* @param nbth number of thread to use (use twice as threads of processor)
* @param szbuff size of buffers to store darts in each thread (default is 8192, use less for lower memory consumsion)
* @param good a selector
*/
template <typename PFP, unsigned int CELL>
void foreach_cell2Pass(typename PFP::MAP& map, FunctorMapThreaded<typename PFP::MAP>& funcFront, FunctorMapThreaded<typename PFP::MAP>& funcBack, unsigned int nbLoops, unsigned int nbth, unsigned int szbuff, bool needMarkers, const FunctorSelect& good)
{
std::vector<Dart>* vd = new std::vector<Dart>[nbth];
for (unsigned int i = 0; i < nbth; ++i)
vd[i].reserve(szbuff);
std::vector<Dart>* tempo = new std::vector<Dart>[nbth];
for (unsigned int i = 0; i < nbth; ++i)
tempo[i].reserve(szbuff);
boost::thread** threadsA = new boost::thread*[nbth];
boost::thread** threadsB = new boost::thread*[nbth];
if (needMarkers)
{
// ensure that there is enough threads
unsigned int nbth_prec = map.getNbThreadMarkers();
if (nbth_prec < nbth+1)
map.addThreadMarker(nbth+1-nbth_prec);
}
CellMarkerNoUnmark<CELL> cm(map);
for (unsigned int loop=0; loop< nbLoops; ++loop)
{
// PASS FRONT (A)
{
Dart d = map.begin();
// fill each vd buffers with szbuff darts
unsigned int nb = 0;
while ((d != map.end()) && (nb < nbth*szbuff) )
{
if (good(d) && (!cm.isMarked(d)))
{
cm.mark(d);
vd[nb%nbth].push_back(d);
nb++;
}
map.next(d);
}
boost::barrier sync1(nbth+1);
boost::barrier sync2(nbth+1);
bool finished=false;
// lauch threads
if (needMarkers)
{
for (unsigned int i = 0; i < nbth; ++i)
threadsA[i] = new boost::thread(ThreadFunction<typename PFP::MAP>(funcFront, vd[i],sync1,sync2, finished,1+i));
}
else
{
for (unsigned int i = 0; i < nbth; ++i)
threadsA[i] = new boost::thread(ThreadFunction<typename PFP::MAP>(funcFront, vd[i],sync1,sync2, finished,0));
}
// and continue to traverse the map
while (d != map.end())
{
for (unsigned int i = 0; i < nbth; ++i)
tempo[i].clear();
unsigned int nb = 0;
while ((d != map.end()) && (nb < nbth*szbuff) )
{
if (good(d) && (!cm.isMarked(d)))
{
cm.mark(d);
tempo[nb%nbth].push_back(d);
nb++;
}
map.next(d);
}
sync1.wait();
for (unsigned int i = 0; i < nbth; ++i)
vd[i].swap(tempo[i]);
sync2.wait();
}
sync1.wait();
finished = true;
sync2.wait();
//wait for all theads to be finished
for (unsigned int i = 0; i < nbth; ++i)
threadsA[i]->join();
}
// PASS BACK (B)
{
for (unsigned int i = 0; i < nbth; ++i)
vd[i].clear();
Dart d = map.begin();
// fill each vd buffers with szbuff darts
unsigned int nb = 0;
while ((d != map.end()) && (nb < nbth*szbuff) )
{
if (good(d) && (cm.isMarked(d)))
{
cm.unmark(d);
vd[nb%nbth].push_back(d);
nb++;
}
map.next(d);
}
boost::barrier sync1(nbth+1);
boost::barrier sync2(nbth+1);
bool finished=false;
// lauch threads
if (needMarkers)
{
for (unsigned int i = 0; i < nbth; ++i)
threadsB[i] = new boost::thread(ThreadFunction<typename PFP::MAP>(funcBack, vd[i],sync1,sync2, finished,1+i));
}
else
{
for (unsigned int i = 0; i < nbth; ++i)
threadsB[i] = new boost::thread(ThreadFunction<typename PFP::MAP>(funcBack, vd[i],sync1,sync2, finished,0));
}
// and continue to traverse the map
while (d != map.end())
{
for (unsigned int i = 0; i < nbth; ++i)
tempo[i].clear();
unsigned int nb = 0;
while ((d != map.end()) && (nb < nbth*szbuff) )
{
if (good(d) && (cm.isMarked(d)))
{
cm.unmark(d);
tempo[nb%nbth].push_back(d);
nb++;
}
map.next(d);
}
sync1.wait();
for (unsigned int i = 0; i < nbth; ++i)
vd[i].swap(tempo[i]);
sync2.wait();
}
sync1.wait();
finished = true;
sync2.wait();
//wait for all theads to be finished
for (unsigned int i = 0; i < nbth; ++i)
threadsB[i]->join();
}
}
// free buffers and threads
for (unsigned int i = 0; i < nbth; ++i)
{
delete threadsA[i];
delete threadsB[i];
}
delete[] threadsA;
delete[] threadsB;
delete[] vd;
delete[] tempo;
}
} // namespace Parallel } // namespace Parallel
} // namespace Algo } // namespace Algo
......
...@@ -79,7 +79,7 @@ void drawerVertices(Utils::Drawer& dr, typename PFP::MAP& map, std::vector<Dart> ...@@ -79,7 +79,7 @@ void drawerVertices(Utils::Drawer& dr, typename PFP::MAP& map, std::vector<Dart>
* @param k shrinking factor * @param k shrinking factor
*/ */
template<typename PFP> template<typename PFP>
void drawerEdges(Utils::Drawer& dr, typename PFP::MAP& map, std::vector<Dart>& vd, const VertexAttribute<typename PFP::VEC3>& positions,float k); void drawerEdges(Utils::Drawer& dr, typename PFP::MAP& map, std::vector<Dart>& vd, const VertexAttribute<typename PFP::VEC3>& positions, float k);
/** /**
* add a set of faces to a drawer * add a set of faces to a drawer
...@@ -90,7 +90,7 @@ void drawerEdges(Utils::Drawer& dr, typename PFP::MAP& map, std::vector<Dart>& v ...@@ -90,7 +90,7 @@ void drawerEdges(Utils::Drawer& dr, typename PFP::MAP& map, std::vector<Dart>& v
* @param k shrinking factor * @param k shrinking factor
*/ */
template<typename PFP> template<typename PFP>
void drawerFaces(Utils::Drawer& dr, typename PFP::MAP& map, std::vector<Dart>& vd, const VertexAttribute<typename PFP::VEC3>& positions,float k); void drawerFaces(Utils::Drawer& dr, typename PFP::MAP& map, std::vector<Dart>& vd, const VertexAttribute<typename PFP::VEC3>& positions, float k);
/** /**
* add a set of volumes to a drawer * add a set of volumes to a drawer
...@@ -101,7 +101,7 @@ void drawerFaces(Utils::Drawer& dr, typename PFP::MAP& map, std::vector<Dart>& v ...@@ -101,7 +101,7 @@ void drawerFaces(Utils::Drawer& dr, typename PFP::MAP& map, std::vector<Dart>& v
* @param k shrinking factor * @param k shrinking factor
*/ */
template<typename PFP> template<typename PFP>
void drawerVolumes(Utils::Drawer& dr, typename PFP::MAP& map, std::vector<Dart>& vd, const VertexAttribute<typename PFP::VEC3>& positions,float k); void drawerVolumes(Utils::Drawer& dr, typename PFP::MAP& map, std::vector<Dart>& vd, const VertexAttribute<typename PFP::VEC3>& positions, float k);
/** /**
* add a vertex to a drawer * add a vertex to a drawer
...@@ -121,7 +121,7 @@ void drawerVertex(Utils::Drawer& dr, typename PFP::MAP& map, Dart d, const Verte ...@@ -121,7 +121,7 @@ void drawerVertex(Utils::Drawer& dr, typename PFP::MAP& map, Dart d, const Verte
* @param positions attribute of positions * @param positions attribute of positions
*/ */
template<typename PFP> template<typename PFP>
void drawerEdge(Utils::Drawer& dr, typename PFP::MAP& map, Dart d, const VertexAttribute<typename PFP::VEC3>& positions,float k); void drawerEdge(Utils::Drawer& dr, typename PFP::MAP& map, Dart d, const VertexAttribute<typename PFP::VEC3>& positions, float k);
/** /**
* add a face to a drawer * add a face to a drawer
...@@ -132,7 +132,7 @@ void drawerEdge(Utils::Drawer& dr, typename PFP::MAP& map, Dart d, const Vertex ...@@ -132,7 +132,7 @@ void drawerEdge(Utils::Drawer& dr, typename PFP::MAP& map, Dart d, const Vertex
* @param k shrinking factor * @param k shrinking factor
*/ */
template<typename PFP> template<typename PFP>
void drawerFace(Utils::Drawer& dr, typename PFP::MAP& map, Dart d, const VertexAttribute<typename PFP::VEC3>& positions,float k); void drawerFace(Utils::Drawer& dr, typename PFP::MAP& map, Dart d, const VertexAttribute<typename PFP::VEC3>& positions, float k);
/** /**
* add a volume to a drawer * add a volume to a drawer
...@@ -143,7 +143,7 @@ void drawerFace(Utils::Drawer& dr, typename PFP::MAP& map, Dart d, const VertexA ...@@ -143,7 +143,7 @@ void drawerFace(Utils::Drawer& dr, typename PFP::MAP& map, Dart d, const VertexA
* @param k shrinking factor * @param k shrinking factor
*/ */
template<typename PFP> template<typename PFP>
void drawerVolume(Utils::Drawer& dr, typename PFP::MAP& map, Dart d, const VertexAttribute<typename PFP::VEC3>& positions,float k); void drawerVolume(Utils::Drawer& dr, typename PFP::MAP& map, Dart d, const VertexAttribute<typename PFP::VEC3>& positions, float k);
/** /**
* add an edge to a drawer, use between begin / end * add an edge to a drawer, use between begin / end
...@@ -188,13 +188,13 @@ void drawerAddFace(Utils::Drawer& dr, typename PFP::MAP& map, Dart d, const Vert ...@@ -188,13 +188,13 @@ void drawerAddFace(Utils::Drawer& dr, typename PFP::MAP& map, Dart d, const Vert
* @param k shrinking factor * @param k shrinking factor
*/ */
template<typename PFP> template<typename PFP>
void drawerAddVolume(Utils::Drawer& dr, typename PFP::MAP& map, Dart d, const VertexAttribute<typename PFP::VEC3>& positions,float k); void drawerAddVolume(Utils::Drawer& dr, typename PFP::MAP& map, Dart d, const VertexAttribute<typename PFP::VEC3>& positions, float k);
} } // namespace Render
} } // namespace Algo
} } // namespace CGoGN
#include "Algo/Render/GL2/drawerCells.hpp" #include "Algo/Render/GL2/drawerCells.hpp"
......
...@@ -100,7 +100,7 @@ protected: ...@@ -100,7 +100,7 @@ protected:
static bool cmpVP(VertexPoly* lhs, VertexPoly* rhs); static bool cmpVP(VertexPoly* lhs, VertexPoly* rhs);
// multiset typedef for simple writing // multiset typedef for simple writing
typedef std::multiset< VertexPoly*,bool(*)(VertexPoly*,VertexPoly*)> VPMS; typedef std::multiset<VertexPoly*, bool(*)(VertexPoly*,VertexPoly*)> VPMS;
class VertexPoly class VertexPoly
{ {
...@@ -112,9 +112,9 @@ protected: ...@@ -112,9 +112,9 @@ protected:
VertexPoly* next; VertexPoly* next;
VPMS::iterator ear; VPMS::iterator ear;
VertexPoly(int i, float v, float l, VertexPoly* p=NULL): id(i),value(v), length(l), prev(p), next(NULL) VertexPoly(int i, float v, float l, VertexPoly* p = NULL) : id(i), value(v), length(l), prev(p), next(NULL)
{ {
if (prev!=NULL) if (prev != NULL)
prev->next = this; prev->next = this;
} }
...@@ -132,7 +132,6 @@ protected: ...@@ -132,7 +132,6 @@ protected:
delete vp; delete vp;
return tmp; return tmp;
} }
}; };
public: public:
......
...@@ -164,6 +164,40 @@ public: ...@@ -164,6 +164,40 @@ public:
inline typename PFP::REAL getArea() const { return area; } inline typename PFP::REAL getArea() const { return area; }
}; };
/*********************************************************
* Collector Normal Angle
*********************************************************/
/*
* collect all primitives of the connected component containing "centerDart"
* the angle between the included vertices normal vectors and the central normal vector
* stays under a given threshold
*/
template <typename PFP>
class Collector_NormalAngle : public Collector<PFP>
{
protected:
const VertexAttribute<typename PFP::VEC3>& position ;
const VertexAttribute<typename PFP::VEC3>& normal ;
typename PFP::REAL angleThreshold ;
public:
Collector_NormalAngle(
typename PFP::MAP& m,
const VertexAttribute<typename PFP::VEC3>& p,
const VertexAttribute<typename PFP::VEC3>& n,
typename PFP::REAL a
) : Collector<PFP>(m), position(p), normal(n), angleThreshold(a)
{}