Commit b728df3b authored by untereiner's avatar untereiner
Browse files

Merge cgogn:~thery/CGoGN

parents 4211c862 26e238b1
......@@ -56,6 +56,8 @@ protected:
Utils::ShaderExplodeVolumes* m_shader;
bool m_cpf;
Utils::ShaderExplodeVolumesLines* m_shaderL;
Utils::VBO* m_vboPos;
......@@ -78,7 +80,7 @@ public:
* @param good functor that return true for darts of part to draw
* @param type_vbo vbo to alloc ( VBO_P, VBO_PN, VBO_PNC, VBO_PC ..)
*/
ExplodeVolumeRender() ;
ExplodeVolumeRender(bool withColorPerFace=false) ;
/**
* Destructor
......@@ -106,6 +108,16 @@ public:
template<typename PFP>
void updateData(typename PFP::MAP& map, typename PFP::TVEC3& positions, const FunctorSelect& good = allDarts) ;
/**
* update all drawing buffers
* @param map the map
* @param positions attribute of position vertices
* @param colorPerFace attribute of color (per face)
* @param good selector
*/
template<typename PFP>
void updateData(typename PFP::MAP& map, typename PFP::TVEC3& positions, typename PFP::TVEC3& colorPerFace, const FunctorSelect& good = allDarts) ;
/**
* draw edges
*/
......
......@@ -40,7 +40,8 @@ namespace Render
namespace GL2
{
inline ExplodeVolumeRender::ExplodeVolumeRender()
inline ExplodeVolumeRender::ExplodeVolumeRender(bool withColorPerFace):
m_cpf(withColorPerFace)
{
m_vboPos = new Utils::VBO();
m_vboPos->setDataSize(3);
......@@ -48,7 +49,7 @@ inline ExplodeVolumeRender::ExplodeVolumeRender()
m_vboPosLine = new Utils::VBO();
m_vboPosLine->setDataSize(3);
m_shader = new Utils::ShaderExplodeVolumes();
m_shader = new Utils::ShaderExplodeVolumes(withColorPerFace);
m_shaderL = new Utils::ShaderExplodeVolumesLines();
// m_shader->setAmbiant(Geom::Vec4f(0.1f,0.1f,0.1f,0.0f));
......@@ -71,6 +72,12 @@ inline ExplodeVolumeRender::~ExplodeVolumeRender()
template<typename PFP>
void ExplodeVolumeRender::updateData(typename PFP::MAP& map, typename PFP::TVEC3& positions, const FunctorSelect& good)
{
if (m_cpf)
{
CGoGNerr<< "ExplodeVolumeRender: problem wrong update fonction use the other" << CGoGNendl;
return;
}
typedef typename PFP::VEC3 VEC3;
typedef typename PFP::REAL REAL;
......@@ -117,6 +124,85 @@ void ExplodeVolumeRender::updateData(typename PFP::MAP& map, typename PFP::TVEC3
m_shader->setAttributePosition(m_vboPos);
buffer.clear();
TraversorCell<typename PFP::MAP> traEdge(map, PFP::MAP::ORBIT_IN_PARENT(EDGE),good);
for (Dart d=traEdge.begin(); d!=traEdge.end(); d=traEdge.next())
{
buffer.push_back(centerVolumes[d]);
buffer.push_back(positions[d]);
buffer.push_back(positions[ map.phi1(d)]);
}
m_nbLines = buffer.size()/3;
m_vboPosLine->allocate(buffer.size());
ptrPos = reinterpret_cast<VEC3*>(m_vboPosLine->lockPtr());
memcpy(ptrPos,&buffer[0],buffer.size()*sizeof(VEC3));
m_vboPosLine->releasePtr();
m_shaderL->setAttributePosition(m_vboPosLine);
}
template<typename PFP>
void ExplodeVolumeRender::updateData(typename PFP::MAP& map, typename PFP::TVEC3& positions, typename PFP::TVEC3& colorPerFace, const FunctorSelect& good)
{
if (!m_cpf)
{
CGoGNerr<< "ExplodeVolumeRender: problem wrong update fonction use the other" << CGoGNendl;
return;
}
typedef typename PFP::VEC3 VEC3;
typedef typename PFP::REAL REAL;
CellMarker cmv(map,VOLUME);
AutoAttributeHandler<VEC3> centerVolumes(map,VOLUME,"centerVolumes");
TraversorW<typename PFP::MAP> traVol(map,good);
for (Dart d=traVol.begin(); d!=traVol.end(); d=traVol.next())
{
centerVolumes[d] = Algo::Geometry::volumeCentroid<PFP>(map, d, positions);
}
std::vector<VEC3> buffer;
buffer.reserve(16384);
TraversorCell<typename PFP::MAP> traFace(map, PFP::MAP::ORBIT_IN_PARENT(FACE),good);
for (Dart d=traFace.begin(); d!=traFace.end(); d=traFace.next())
{
Dart a = d;
Dart b = map.phi1(a);
Dart c = map.phi1(b);
// loop to cut a polygon in triangle on the fly (works only with convex faces)
do
{
buffer.push_back(centerVolumes[d]);
buffer.push_back(positions[d]);
buffer.push_back(positions[b]);
buffer.push_back(positions[c]);
buffer.push_back(colorPerFace[d]);
buffer.push_back(VEC3(0.,0.,0.)); // TODO use this place for center of face
b = c;
c = map.phi1(b);
} while (c != d);
}
m_nbTris = buffer.size()/4;
m_vboPos->allocate(buffer.size());
VEC3* ptrPos = reinterpret_cast<VEC3*>(m_vboPos->lockPtr());
memcpy(ptrPos,&buffer[0],buffer.size()*sizeof(VEC3));
m_vboPos->releasePtr();
m_shader->setAttributePosition(m_vboPos);
buffer.clear();
TraversorCell<typename PFP::MAP> traEdge(map, PFP::MAP::ORBIT_IN_PARENT(EDGE),good);
......@@ -140,10 +226,14 @@ void ExplodeVolumeRender::updateData(typename PFP::MAP& map, typename PFP::TVEC3
}
inline void ExplodeVolumeRender::drawFaces()
{
m_shader->enableVertexAttribs();
glDrawArrays(GL_LINES_ADJACENCY_EXT , 0 , m_nbTris*4 );
if (m_cpf)
glDrawArrays(GL_TRIANGLES_ADJACENCY_EXT , 0 , m_nbTris*6 );
else
glDrawArrays(GL_LINES_ADJACENCY_EXT , 0 , m_nbTris*4 );
m_shader->disableVertexAttribs();
}
......
......@@ -42,20 +42,6 @@
namespace CGoGN
{
/*
const unsigned int EMBNULL = 0xffffffff;
const unsigned int NB_ORBITS = 6;
const unsigned int NB_THREAD = 16;
const unsigned int VERTEX = 0;
const unsigned int EDGE = 1;
const unsigned int ORIENTED_FACE= 2;
const unsigned int FACE = 3;
const unsigned int VOLUME = 4;
const unsigned int DART = 5;
*/
/**
* Class that allows to browse a map
* This is a pure virtual class that can be overloaded in:
......@@ -129,8 +115,8 @@ protected:
AttributeContainer m_mrattribs ;
std::vector< AttributeMultiVector<unsigned int> > m_mrDarts;
AttributeMultiVector<unsigned char> m_mrLevels;
std::vector< AttributeMultiVector<unsigned int>* > m_mrDarts;
AttributeMultiVector<unsigned char>* m_mrLevels;
unsigned int m_mrCurrentLevel;
......
......@@ -201,23 +201,16 @@ public:
Dart next() ;
} ;
// Traverse the edges incident to a given face
// Traverse the edges incident to a given face (equivalent to vertices)
template <typename MAP>
class Traversor2FE
class Traversor2FE : public Traversor2FV<MAP>
{
private:
MAP& m ;
Dart start ;
Dart current ;
public:
Traversor2FE(MAP& map, Dart dart) ;
Dart begin() ;
Dart end() ;
Dart next() ;
Traversor2FE(MAP& map, Dart dart):Traversor2FV<MAP>(map,dart){}
} ;
// Traverse the faces adjacent to a given face through sharing a common vertex
template <typename MAP>
class Traversor2FFaV
......
......@@ -355,37 +355,6 @@ Dart Traversor2FV<MAP>::next()
return current ;
}
// Traversor2FE
template <typename MAP>
Traversor2FE<MAP>::Traversor2FE(MAP& map, Dart dart) : m(map), start(dart)
{}
template <typename MAP>
Dart Traversor2FE<MAP>::begin()
{
current = start ;
return current ;
}
template <typename MAP>
Dart Traversor2FE<MAP>::end()
{
return NIL ;
}
template <typename MAP>
Dart Traversor2FE<MAP>::next()
{
if(current != NIL)
{
current = m.phi1(current) ;
if(current == start)
current = NIL ;
}
return current ;
}
// Traversor2FFaV
template <typename MAP>
......
......@@ -26,121 +26,326 @@
#define __TRAVERSOR3_H__
#include "Topology/generic/dart.h"
#include "Topology/generic/traversorCell.h"
namespace CGoGN
{
/*******************************************************************************
VERTEX CENTERED TRAVERSALS
*******************************************************************************/
// Traverse the edges incident to a given vertex
template <typename MAP>
class Traversor3VE
/**
* class Marker for Traversor usefull to combine
* several TraversorXY
*/
template <typename MAP, unsigned int ORBIT>
class MarkerForTraversor
{
private:
MAP& m ;
Dart start ;
Dart current ;
MAP& m_map ;
DartMarkerStore* m_dmark ;
CellMarkerStore* m_cmark ;
public:
Traversor3VE(MAP& map, Dart dart) ;
MarkerForTraversor(MAP& map, bool forceDartMarker = false, unsigned int thread = 0) ;
~MarkerForTraversor();
DartMarkerStore* dmark();
CellMarkerStore* cmark();
void mark(Dart d);
void unmark(Dart d);
bool isMarked(Dart d);
} ;
/**
* Generic class Traversor (do not use directly)
* Traverse all Y incident to X
*/
template <typename MAP, unsigned int ORBIT_X, unsigned int ORBIT_Y>
class Traversor3XY
{
private:
MAP& m_map ;
DartMarkerStore* m_dmark ;
CellMarkerStore* m_cmark ;
Dart m_current ;
TraversorDartsOfOrbit<MAP> m_tradoo;
bool m_allocated;
public:
Traversor3XY(MAP& map, Dart dart, bool forceDartMarker = false, unsigned int thread = 0) ;
Traversor3XY(MAP& map, Dart dart, MarkerForTraversor<MAP,ORBIT_Y>& tmo, bool forceDartMarker = false, unsigned int thread = 0) ;
~Traversor3XY();
Dart begin() ;
Dart end() ;
Dart next() ;
} ;
// Traverse the faces incident to a given vertex
template <typename MAP>
class Traversor3VF
/**
* Generic class Traversor (do not use directly)
* Traverse all X adjacent to X by an Y
*/
template <typename MAP, unsigned int ORB_X, unsigned int ORB_Y>
class Traversor3XXaY
{
private:
MAP& m ;
Dart start ;
Dart current ;
MAP& m_map ;
std::vector<Dart> m_vecDarts;
std::vector<Dart>::iterator m_iter;
public:
Traversor3XXaY(MAP& map, Dart dart, bool forceDartMarker = false, unsigned int thread = 0);
Dart begin();
Dart end();
Dart next();
};
/**
* Traverse vertices incident to volume
*/
template <typename MAP>
class Traversor3WV: public Traversor3XY<MAP,VOLUME,VERTEX>
{
public:
Traversor3VF(MAP& map, Dart dart) ;
Traversor3WV(MAP& m, Dart dart, bool forceDartMarker = false, unsigned int thread = 0) : Traversor3XY<MAP,VOLUME,VERTEX>(m, dart, forceDartMarker, thread) {}
};
Dart begin() ;
Dart end() ;
Dart next() ;
} ;
/**
* Traverse edges incident to volume
*/
template <typename MAP>
class Traversor3WE: public Traversor3XY<MAP,VOLUME,EDGE>
{
public:
Traversor3WE(MAP& m, Dart dart, bool forceDartMarker = false, unsigned int thread = 0) : Traversor3XY<MAP,VOLUME,EDGE>(m, dart, forceDartMarker, thread) {}
};
// Traverse the volumes incident to a given vertex
/**
* Traverse faces incident to volume
*/
template <typename MAP>
class Traversor3VW
class Traversor3WF: public Traversor3XY<MAP,VOLUME,FACE>
{
private:
MAP& m ;
Dart start ;
Dart current ;
public:
Traversor3WF(MAP& m, Dart dart, bool forceDartMarker = false, unsigned int thread = 0) : Traversor3XY<MAP,VOLUME,FACE>(m, dart, forceDartMarker, thread) {}
};
/**
* Traverse vertices incident to face
*/
template <typename MAP>
class Traversor3FV: public Traversor3XY<MAP,FACE,VERTEX>
{
public:
Traversor3VW(MAP& map, Dart dart) ;
Traversor3FV(MAP& m, Dart dart, bool forceDartMarker = false, unsigned int thread = 0) : Traversor3XY<MAP,FACE,VERTEX>(m, dart, forceDartMarker, thread) {}
};
Dart begin() ;
Dart end() ;
Dart next() ;
} ;
/**
* Traverse edges incident to face
*/
template <typename MAP>
class Traversor3FE: public Traversor3XY<MAP,FACE,EDGE>
{
public:
Traversor3FE(MAP& m, Dart dart, bool forceDartMarker = false, unsigned int thread = 0) : Traversor3XY<MAP,FACE,EDGE>(m, dart, forceDartMarker, thread) {}
};
/*******************************************************************************
EDGE CENTERED TRAVERSALS
*******************************************************************************/
/**
* Traverse volumes incident to face
*/
template <typename MAP>
class Traversor3FW: public Traversor3XY<MAP,FACE,VOLUME>
{
public:
Traversor3FW(MAP& m, Dart dart, bool forceDartMarker = false, unsigned int thread = 0) : Traversor3XY<MAP,FACE,VOLUME>(m, dart, forceDartMarker, thread) {}
};
/**
* Traverse vertices incident to edge
*/
template <typename MAP>
class Traversor3EV: public Traversor3XY<MAP,EDGE,VERTEX>
{
public:
Traversor3EV(MAP& m, Dart dart, bool forceDartMarker = false, unsigned int thread = 0) : Traversor3XY<MAP,EDGE,VERTEX>(m, dart, forceDartMarker, thread) {}
};
/*******************************************************************************
FACE CENTERED TRAVERSALS
*******************************************************************************/
/**
* Traverse faces incident to edge
*/
template <typename MAP>
class Traversor3EF: public Traversor3XY<MAP,EDGE,FACE>
{
public:
Traversor3EF(MAP& m, Dart dart, bool forceDartMarker = false, unsigned int thread = 0) : Traversor3XY<MAP,EDGE,FACE>(m, dart, forceDartMarker, thread) {}
};
/**
* Traverse volumes incident to edge
*/
template <typename MAP>
class Traversor3EW: public Traversor3XY<MAP,EDGE,VOLUME>
{
public:
Traversor3EW(MAP& m, Dart dart, bool forceDartMarker = false, unsigned int thread = 0) : Traversor3XY<MAP,EDGE,VOLUME>(m, dart, forceDartMarker, thread) {}
};
/*******************************************************************************
VOLUME CENTERED TRAVERSALS
*******************************************************************************/
// Traverse the vertices incident to a given volume
template <typename MAP, unsigned int ORBIT>
class Traversor3WX
/**
* Traverse edges incident to vertex
*/
template <typename MAP>
class Traversor3VE: public Traversor3XY<MAP,VERTEX,EDGE>
{
private:
MAP& m ;
Dart start ;
Dart current ;
DartMarkerStore* dmark ;
CellMarkerStore* cmark ;
TraversorDartsOfOrbit<MAP> m_tradoo;
public:
Traversor3VE(MAP& m, Dart dart, bool forceDartMarker = false, unsigned int thread = 0) : Traversor3XY<MAP,VERTEX,EDGE>(m, dart, forceDartMarker, thread) {}
};
/**
* Traverse faces incident to vertex
*/
template <typename MAP>
class Traversor3VF: public Traversor3XY<MAP,VERTEX,FACE>
{
public:
Traversor3WX(MAP& map, Dart dart, bool forceDartMarker = false, unsigned int thread = 0) ;
~Traversor3WX();
Traversor3VF(MAP& m, Dart dart, bool forceDartMarker = false, unsigned int thread = 0) : Traversor3XY<MAP,VERTEX,FACE>(m, dart, forceDartMarker, thread) {}
};
Dart begin() ;
Dart end() ;
Dart next() ;
} ;
/**
* Traverse volumes incident to vertex
*/
template <typename MAP>
class Traversor3VW: public Traversor3XY<MAP,VERTEX,VOLUME>
{
public:
Traversor3VW(MAP& m, Dart dart, bool forceDartMarker = false, unsigned int thread = 0) : Traversor3XY<MAP,VERTEX,VOLUME>(m, dart, forceDartMarker, thread) {}
};
/**
* Traverse vertices adjacent to a vertex by an edge
*/
template <typename MAP>
class Traversor3VVaE: public Traversor3XXaY<MAP,VERTEX,EDGE>
{
public:
Traversor3VVaE(MAP& m, Dart d, bool forceDartMarker = false, unsigned int thread = 0) : Traversor3XXaY<MAP,VERTEX,EDGE>(m, d, forceDartMarker, thread) {}
};
/**
* Traverse vertices adjacent to a vertex by a face
*/
template <typename MAP>
class Traversor3VVaF: public Traversor3XXaY<MAP,VERTEX,FACE>
{
public:
Traversor3VVaF(MAP& m, Dart d, bool forceDartMarker = false, unsigned int thread = 0) : Traversor3XXaY<MAP,VERTEX,FACE>(m, d, forceDartMarker, thread) {}
};
/**
* Traverse vertices adjacent to a vertex by a volume
*/
template <typename MAP>
class Traversor3VVaW: public Traversor3XXaY<MAP,VERTEX,VOLUME>
{
public:
Traversor3VVaW(MAP& m, Dart d, bool forceDartMarker = false, unsigned int thread = 0) : Traversor3XXaY<MAP,VERTEX,VOLUME>(m, d, forceDartMarker, thread) {}
};
/**
* Traverse edges adjacent to an egde by a vertex
*/
template <typename MAP>
class Traversor3EEaV: public Traversor3XXaY<MAP,EDGE,VERTEX>
{
public:
Traversor3EEaV(MAP& m, Dart d, bool forceDartMarker = false, unsigned int thread = 0) : Traversor3XXaY<MAP,EDGE,VERTEX>(m, d, forceDartMarker, thread) {}
};
/**
* Traverse edges adjacent to an egde by a face
*/
template <typename MAP>
class Traversor3EEaF: public Traversor3XXaY<MAP,EDGE,FACE>
{
public:
Traversor3EEaF(MAP& m, Dart d, bool forceDartMarker = false, unsigned int thread = 0) : Traversor3XXaY<MAP,EDGE,FACE>(m, d, forceDartMarker, thread) {}
};
/**
* Traverse edges adjacent to an egde by a volume
*/
template <typename MAP>
class Traversor3EEaW: public Traversor3XXaY<MAP,EDGE,VOLUME>
{
public:
Traversor3EEaW(MAP& m, Dart d, bool forceDartMarker = false, unsigned int thread = 0) : Traversor3XXaY<MAP,EDGE,VOLUME>(m, d, forceDartMarker, thread) {}
};
/**
* Traverse faces adjacent to a face by a vertex
*/
template <typename MAP>
class Traversor3FFaV: public Traversor3XXaY