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()
exportMesh(filename) ;
}
void Viewer::cb_keyPress(int keycode)
{
switch(keycode)
{
case 'c' :
myMap.check();
break;
default:
break;
}
}
void Viewer::importMesh(std::string& filename)
{
myMap.clear(true) ;
......@@ -311,21 +323,6 @@ void Viewer::slot_normalsSize(int i)
updateGL() ;
}
void Viewer::cb_keyPress(int keycode)
{
switch(keycode)
{
case 'c' :
myMap.check();
break;
default:
break;
}
updateGLMatrices() ;
updateGL();
}
/**********************************************************************************************
* MAIN FUNCTION *
**********************************************************************************************/
......
......@@ -46,6 +46,8 @@
#include "Utils/Shaders/shaderVectorPerVertex.h"
#include "Utils/pointSprite.h"
#include "Utils/text3d.h"
#include "Utils/vboRender.h"
#include "Utils/Qt/qtInputs.h"
#include "Algo/Geometry/boundingbox.h"
......
......@@ -90,20 +90,20 @@ public:
do
{
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 ;
map.incCurrentLevel() ;
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]] ;
if(oldEmb == EMBNULL)
{
map.embedOrbit<VERTEX>(dd, newEmb) ;
map.template embedOrbit<VERTEX>(dd, newEmb) ;
map.pushLevel() ;
for(unsigned int i = map.getCurrentLevel() + 1; i <= map.getMaxLevel(); ++i)
{
map.setCurrentLevel(i) ;
map.embedOrbit<VERTEX>(dd, newEmb) ;
map.template embedOrbit<VERTEX>(dd, newEmb) ;
}
map.popLevel() ;
}
......@@ -120,7 +120,7 @@ public:
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 ;
map.incCurrentLevel() ;
children[idx+1]->embed<PFP>(map, it, vID) ;
......
......@@ -41,14 +41,13 @@ inline void nextNonEmptyLine(std::ifstream& fp, std::string& line)
template <typename PFP>
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())
position = map.template addAttribute<typename PFP::VEC3>(VERTEX, "position") ;
position = map.template addAttribute<typename PFP::VEC3, VERTEX>("position") ;
attrNames.push_back(position.name()) ;
AttributeContainer& container = map.getAttributeContainer(VERTEX) ;
AttributeContainer& container = map.template getAttributeContainer<VERTEX>() ;
// open file
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
unsigned int emb = qt.verticesID[idx] ;
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
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
// darts incident to end vertex of edge
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 ;
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 ;
}
......
......@@ -105,6 +105,11 @@ void foreach_orbit(typename PFP::MAP& map, FunctorMapThreaded<typename PFP::MAP>
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);
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
* Functor application must be independant
......@@ -187,6 +192,7 @@ T maxResult(const std::vector<T>& res);
template <typename T>
T minResult(const std::vector<T>& res);
/**
* Class to encapsulate algorithm in a boost thread
* Usage:
......
......@@ -788,6 +788,199 @@ T minResult(const std::vector<T>& res)
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 Algo
......
......@@ -79,7 +79,7 @@ void drawerVertices(Utils::Drawer& dr, typename PFP::MAP& map, std::vector<Dart>
* @param k shrinking factor
*/
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
......@@ -90,7 +90,7 @@ void drawerEdges(Utils::Drawer& dr, typename PFP::MAP& map, std::vector<Dart>& v
* @param k shrinking factor
*/
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
......@@ -101,7 +101,7 @@ void drawerFaces(Utils::Drawer& dr, typename PFP::MAP& map, std::vector<Dart>& v
* @param k shrinking factor
*/
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
......@@ -121,7 +121,7 @@ void drawerVertex(Utils::Drawer& dr, typename PFP::MAP& map, Dart d, const Verte
* @param positions attribute of positions
*/
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
......@@ -132,7 +132,7 @@ void drawerEdge(Utils::Drawer& dr, typename PFP::MAP& map, Dart d, const Vertex
* @param k shrinking factor
*/
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
......@@ -143,7 +143,7 @@ void drawerFace(Utils::Drawer& dr, typename PFP::MAP& map, Dart d, const VertexA
* @param k shrinking factor
*/
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
......@@ -188,13 +188,13 @@ void drawerAddFace(Utils::Drawer& dr, typename PFP::MAP& map, Dart d, const Vert
* @param k shrinking factor
*/
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"
......
......@@ -100,7 +100,7 @@ protected:
static bool cmpVP(VertexPoly* lhs, VertexPoly* rhs);
// multiset typedef for simple writing
typedef std::multiset< VertexPoly*,bool(*)(VertexPoly*,VertexPoly*)> VPMS;
typedef std::multiset<VertexPoly*, bool(*)(VertexPoly*,VertexPoly*)> VPMS;
class VertexPoly
{
......@@ -112,9 +112,9 @@ protected:
VertexPoly* next;
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;
}
......@@ -132,7 +132,6 @@ protected:
delete vp;
return tmp;
}
};
public:
......
......@@ -164,6 +164,40 @@ public:
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)
{}
inline void setAngleThreshold(typename PFP::REAL a) { angleThreshold = a; }
inline typename PFP::REAL getAngleThreshold() const { return angleThreshold; }
inline const VertexAttribute<typename PFP::VEC3>& getPosition() const { return position ; }
inline const VertexAttribute<typename PFP::VEC3>& getNormal() const { return normal ; }
void collectAll(Dart d) ;
void collectBorder(Dart d) ;
};
} // namespace Selection
} // namespace Algo
......
......@@ -280,6 +280,127 @@ void Collector_WithinSphere<PFP>::computeArea()
}
}
/*********************************************************
* Collector Normal Angle
*********************************************************/
template <typename PFP>
void Collector_NormalAngle<PFP>::collectAll(Dart d)
{
typedef typename PFP::VEC3 VEC3;
typedef typename PFP::REAL REAL;
this->init(d);
this->insideEdges.reserve(32);
this->insideFaces.reserve(32);
this->border.reserve(32);
CellMarkerStore<VERTEX> vm(this->map); // mark the collected inside-vertices
CellMarkerStore<EDGE> em(this->map); // mark the collected inside-edges + border-edges
CellMarkerStore<FACE> fm(this->map); // mark the collected inside-faces + border-faces
this->insideVertices.push_back(this->centerDart);
vm.mark(this->centerDart);
VEC3 centerNormal = this->normal[d];
unsigned int i = 0;
while (i < this->insideVertices.size())
{
Dart end = this->insideVertices[i];
Dart e = end;
do
{
if (! em.isMarked(e) || ! fm.isMarked(e)) // are both tests useful ?
{
const Dart f = this->map.phi1(e);
const Dart g = this->map.phi1(f);
REAL a = Geom::angle(centerNormal, this->normal[f]);
if (a > angleThreshold)
{
this->border.push_back(e); // add to border
em.mark(e);
fm.mark(e); // is it useful ?
}
else
{
if (! vm.isMarked(f))
{
this->insideVertices.push_back(f);
vm.mark(f);
}
if (! em.isMarked(e))
{
this->insideEdges.push_back(e);
em.mark(e);
}
REAL b = Geom::angle(centerNormal, this->normal[g]);
if (! fm.isMarked(e) && b < angleThreshold)
{
this->insideFaces.push_back(e);
fm.mark(e);
}
}
}
e = this->map.phi2_1(e);
} while (e != end);
++i;
}
}
template <typename PFP>
void Collector_NormalAngle<PFP>::collectBorder(Dart d)
{
typedef typename PFP::VEC3 VEC3;
typedef typename PFP::REAL REAL;
this->init(d);
this->border.reserve(128);
this->insideVertices.reserve(128);
CellMarkerStore<VERTEX> vm(this->map); // mark the collected inside-vertices
CellMarkerStore<EDGE> em(this->map); // mark the collected inside-edges + border-edges
this->insideVertices.push_back(this->centerDart);
vm.mark(this->centerDart);
VEC3 centerNormal = this->normal[d];
unsigned int i = 0;
while (i < this->insideVertices.size())
{
Dart end = this->insideVertices[i];
Dart e = end;
do
{
if ( ! em.isMarked(e) )