Commit 573ff74e authored by Sylvain Thery's avatar Sylvain Thery

Merge branch 'master' of cgogn:~cgogn/CGoGN

parents c0ee9030 9a48f6a3
......@@ -438,10 +438,9 @@ int main(int argc, char **argv)
sqt.m_positionVBO->updateData(position);
// update des primitives du renderer
sqt.m_render->initPrimitives<PFP>(myMap, allDarts, Algo::Render::GL2::TRIANGLES);
sqt.m_render->initPrimitives<PFP>(myMap, allDarts, Algo::Render::GL2::LINES);
sqt.m_render->initPrimitives<PFP>(myMap, allDarts, Algo::Render::GL2::POINTS);
sqt.m_render->initPrimitives<PFP>(myMap, allDarts, Algo::Render::GL2::TRIANGLES, &position);
sqt.m_render->initPrimitives<PFP>(myMap, allDarts, Algo::Render::GL2::LINES, &position);
sqt.m_render->initPrimitives<PFP>(myMap, allDarts, Algo::Render::GL2::POINTS, &position);
// show final pour premier redraw
sqt.show();
......
......@@ -69,6 +69,7 @@ Dart Primitive3D<PFP>::HexaGrid1Topo(unsigned int nx)
// first cube
Dart d0 = createHexa();
m_tableVertDarts.push_back(d0);
Dart d1 = m_map.template phi<2112>(d0);
for (unsigned int i = 1; i < nx; ++i)
......
......@@ -78,7 +78,6 @@ enum bufferIndex
SIZE_BUFFER
} ;
class MapRender
{
......@@ -137,8 +136,6 @@ protected:
};
public:
/**
* Constructor
......@@ -159,7 +156,6 @@ public:
buffer_array get_nb_index_buffer() { return std::make_pair(m_nbIndices, SIZE_BUFFER); }
protected:
/**
* addition of indices table of one triangle
* @param d a dart of the triangle
......@@ -169,29 +165,28 @@ protected:
void addTri(typename PFP::MAP& map, Dart d, std::vector<GLuint>& tableIndices) ;
template<typename PFP>
inline void addEarTri(typename PFP::MAP& map, Dart d, std::vector<GLuint>& tableIndices);
inline void addEarTri(typename PFP::MAP& map, Dart d, std::vector<GLuint>& tableIndices, const typename PFP::TVEC3* position);
template<typename PFP>
float computeEarAngle(const typename PFP::VEC3& P1, const typename PFP::VEC3& P2, const typename PFP::VEC3& P3, const typename PFP::VEC3& normalPoly);
template<typename PFP>
bool computeEarIntersection(AttributeHandler<typename PFP::VEC3>& position, VertexPoly* vp, const typename PFP::VEC3& normalPoly);
bool computeEarIntersection(const typename PFP::TVEC3& position, VertexPoly* vp, const typename PFP::VEC3& normalPoly);
template<typename PFP>
void recompute2Ears( AttributeHandler<typename PFP::VEC3>& position, VertexPoly* vp, const typename PFP::VEC3& normalPoly, VPMS& ears, bool convex);
void recompute2Ears(const typename PFP::TVEC3& position, VertexPoly* vp, const typename PFP::VEC3& normalPoly, VPMS& ears, bool convex);
template<typename VEC3>
bool inTriangle(const VEC3& P, const VEC3& normal, const VEC3& Ta, const VEC3& Tb, const VEC3& Tc);
public:
/**
* creation of indices table of triangles (optimized order)
* @param tableIndices the table where indices are stored
*/
template <typename PFP>
void initTriangles(typename PFP::MAP& map, const FunctorSelect& good, std::vector<GLuint>& tableIndices, unsigned int thread = 0) ;
void initTriangles(typename PFP::MAP& map, const FunctorSelect& good, std::vector<GLuint>& tableIndices, const typename PFP::TVEC3* position, unsigned int thread = 0) ;
template <typename PFP>
void initTrianglesOptimized(typename PFP::MAP& map, const FunctorSelect& good, std::vector<GLuint>& tableIndices, unsigned int thread = 0) ;
void initTrianglesOptimized(typename PFP::MAP& map, const FunctorSelect& good, std::vector<GLuint>& tableIndices, const typename PFP::TVEC3* position, unsigned int thread = 0) ;
/**
* creation of indices table of lines (optimized order)
......@@ -216,6 +211,7 @@ public:
template <typename PFP>
void initBoundaries(typename PFP::MAP& map, const FunctorSelect& good, std::vector<GLuint>& tableIndices, unsigned int thread = 0) ;
public:
/**
* initialization of the VBO indices primitives
* computed by a traversal of the map
......@@ -224,6 +220,9 @@ public:
template <typename PFP>
void initPrimitives(typename PFP::MAP& map, const FunctorSelect& good, int prim, bool optimized = true, unsigned int thread = 0) ;
template <typename PFP>
void initPrimitives(typename PFP::MAP& map, const FunctorSelect& good, int prim, const typename PFP::TVEC3* position, bool optimized = true, unsigned int thread = 0) ;
/**
* initialization of the VBO indices primitives
* using the given table
......
......@@ -71,7 +71,7 @@ bool MapRender::inTriangle(const VEC3& P, const VEC3& normal, const VEC3& Ta, c
}
template<typename PFP>
void MapRender::recompute2Ears( AttributeHandler<typename PFP::VEC3>& position, VertexPoly* vp, const typename PFP::VEC3& normalPoly, VPMS& ears, bool convex)
void MapRender::recompute2Ears(const typename PFP::TVEC3& position, VertexPoly* vp, const typename PFP::VEC3& normalPoly, VPMS& ears, bool convex)
{
VertexPoly* vprev = vp->prev;
VertexPoly* vp2 = vp->next;
......@@ -151,7 +151,7 @@ float MapRender::computeEarAngle(const typename PFP::VEC3& P1, const typename PF
}
template<typename PFP>
bool MapRender::computeEarIntersection(AttributeHandler<typename PFP::VEC3>& position, VertexPoly* vp, const typename PFP::VEC3& normalPoly)
bool MapRender::computeEarIntersection(const typename PFP::TVEC3& position, VertexPoly* vp, const typename PFP::VEC3& normalPoly)
{
VertexPoly* endV = vp->prev;
......@@ -175,20 +175,19 @@ bool MapRender::computeEarIntersection(AttributeHandler<typename PFP::VEC3>& pos
}
template<typename PFP>
inline void MapRender::addEarTri(typename PFP::MAP& map, Dart d, std::vector<GLuint>& tableIndices)
inline void MapRender::addEarTri(typename PFP::MAP& map, Dart d, std::vector<GLuint>& tableIndices, const typename PFP::TVEC3* pos)
{
bool(*fn_pt1)(VertexPoly*,VertexPoly*) = &(MapRender::cmpVP);
VPMS ears(fn_pt1);
AttributeHandler<typename PFP::VEC3> position = map.template getAttribute<typename PFP::VEC3>(VERTEX,"position");
const typename PFP::TVEC3& position = *pos ;
// compute normal to polygon
typename PFP::VEC3 normalPoly = Algo::Geometry::newellNormal<PFP>(map, d, position);
// first pass create polygon in chained list witht angle computation
VertexPoly* vpp=NULL;
VertexPoly* prem=NULL;
VertexPoly* vpp = NULL;
VertexPoly* prem = NULL;
unsigned int nbv = 0;
unsigned int nbe = 0;
Dart a = d;
......@@ -196,27 +195,27 @@ inline void MapRender::addEarTri(typename PFP::MAP& map, Dart d, std::vector<GLu
Dart c = map.phi1(b);
do
{
typename PFP::VEC3 P1= position[map.getEmbedding(VERTEX,a)];
typename PFP::VEC3 P2= position[map.getEmbedding(VERTEX,b)];
typename PFP::VEC3 P3= position[map.getEmbedding(VERTEX,c)];
typename PFP::VEC3 P1 = position[map.getEmbedding(VERTEX, a)];
typename PFP::VEC3 P2 = position[map.getEmbedding(VERTEX, b)];
typename PFP::VEC3 P3 = position[map.getEmbedding(VERTEX, c)];
float val = computeEarAngle<PFP>(P1,P2,P3,normalPoly);
VertexPoly* vp = new VertexPoly(map.getEmbedding(VERTEX,b),val,(P3-P1).norm2(),vpp);
float val = computeEarAngle<PFP>(P1, P2, P3, normalPoly);
VertexPoly* vp = new VertexPoly(map.getEmbedding(VERTEX, b), val, (P3-P1).norm2(), vpp);
if (vp->value <5.0f)
if (vp->value < 5.0f)
nbe++;
if (vpp==NULL)
if (vpp == NULL)
prem = vp;
vpp = vp;
a = b;
b = c;
c = map.phi1(c);
nbv++;
}while (a!=d);
}while (a != d);
VertexPoly::close(prem,vpp);
VertexPoly::close(prem, vpp);
bool convex = nbe==nbv;
bool convex = nbe == nbv;
if (convex)
{
// second pass with no test of intersections with polygons
......@@ -234,7 +233,7 @@ inline void MapRender::addEarTri(typename PFP::MAP& map, Dart d, std::vector<GLu
for (unsigned int i=0; i< nbv; ++i)
{
if (vpp->value <5.0f)
computeEarIntersection<PFP>(position,vpp,normalPoly);
computeEarIntersection<PFP>(position, vpp, normalPoly);
vpp->ear = ears.insert(vpp);
vpp = vpp->next;
}
......@@ -286,40 +285,43 @@ inline void MapRender::addTri(typename PFP::MAP& map, Dart d, std::vector<GLuint
Dart b = map.phi1(a);
Dart c = map.phi1(b);
if (map.phi1(c) != a)
{
addEarTri<PFP>(map, d, tableIndices);
return;
}
tableIndices.push_back(map.getEmbedding(VERTEX, d));
tableIndices.push_back(map.getEmbedding(VERTEX, b));
tableIndices.push_back(map.getEmbedding(VERTEX, c));
// loop to cut a polygon in triangle on the fly (works only with convex faces)
// do
// {
// tableIndices.push_back(map.getEmbedding(VERTEX, d));
// tableIndices.push_back(map.getEmbedding(VERTEX, b));
// tableIndices.push_back(map.getEmbedding(VERTEX, c));
// b = c;
// c = map.phi1(b);
// } while (c != d);
do
{
tableIndices.push_back(map.getEmbedding(VERTEX, d));
tableIndices.push_back(map.getEmbedding(VERTEX, b));
tableIndices.push_back(map.getEmbedding(VERTEX, c));
b = c;
c = map.phi1(b);
} while (c != d);
}
template<typename PFP>
void MapRender::initTriangles(typename PFP::MAP& map, const FunctorSelect& good, std::vector<GLuint>& tableIndices, unsigned int thread)
void MapRender::initTriangles(typename PFP::MAP& map, const FunctorSelect& good, std::vector<GLuint>& tableIndices, const typename PFP::TVEC3* position, unsigned int thread)
{
tableIndices.reserve(4 * map.getNbDarts() / 3);
TraversorF<typename PFP::MAP> trav(map, good, thread);
for (Dart d = trav.begin(); d != trav.end(); d = trav.next())
addTri<PFP>(map, d, tableIndices);
if(position == NULL)
{
for (Dart d = trav.begin(); d != trav.end(); d = trav.next())
addTri<PFP>(map, d, tableIndices);
}
else
{
for (Dart d = trav.begin(); d != trav.end(); d = trav.next())
{
if(map.faceDegree(d) == 3)
addTri<PFP>(map, d, tableIndices);
else
addEarTri<PFP>(map, d, tableIndices, position);
}
}
}
template<typename PFP>
void MapRender::initTrianglesOptimized(typename PFP::MAP& map, const FunctorSelect& good, std::vector<GLuint>& tableIndices, unsigned int thread)
void MapRender::initTrianglesOptimized(typename PFP::MAP& map, const FunctorSelect& good, std::vector<GLuint>& tableIndices, const typename PFP::TVEC3* position, unsigned int thread)
{
#define LIST_SIZE 20
DartMarker m(map, thread);
......@@ -335,7 +337,17 @@ void MapRender::initTrianglesOptimized(typename PFP::MAP& map, const FunctorSele
std::list<Dart> bound;
if (good(dd) && !map.isBoundaryMarked(dd))
addTri<PFP>(map, dd, tableIndices);
{
if(position == NULL)
addTri<PFP>(map, dd, tableIndices);
else
{
if(map.faceDegree(dd) == 3)
addTri<PFP>(map, dd, tableIndices);
else
addEarTri<PFP>(map, dd, tableIndices, position);
}
}
m.markOrbit(FACE, dd);
bound.push_back(dd);
int nb = 1;
......@@ -351,7 +363,17 @@ void MapRender::initTrianglesOptimized(typename PFP::MAP& map, const FunctorSele
if (!m.isMarked(f))
{
if (good(f) && !map.isBoundaryMarked(f))
addTri<PFP>(map, f, tableIndices);
{
if(position == NULL)
addTri<PFP>(map, f, tableIndices);
else
{
if(map.faceDegree(f) == 3)
addTri<PFP>(map, f, tableIndices);
else
addEarTri<PFP>(map, f, tableIndices, position);
}
}
m.markOrbit(FACE, f);
bound.push_back(map.phi1(f));
++nb;
......@@ -464,6 +486,12 @@ void MapRender::initPoints(typename PFP::MAP& map, const FunctorSelect& good, st
template<typename PFP>
void MapRender::initPrimitives(typename PFP::MAP& map, const FunctorSelect& good, int prim, bool optimized, unsigned int thread)
{
initPrimitives<PFP>(map, good, prim, NULL, optimized, thread) ;
}
template <typename PFP>
void MapRender::initPrimitives(typename PFP::MAP& map, const FunctorSelect& good, int prim, const typename PFP::TVEC3* position, bool optimized, unsigned int thread)
{
std::vector<GLuint> tableIndices;
......@@ -487,9 +515,9 @@ void MapRender::initPrimitives(typename PFP::MAP& map, const FunctorSelect& good
break;
case TRIANGLES:
if(optimized)
initTrianglesOptimized<PFP>(map, good, tableIndices, thread);
initTrianglesOptimized<PFP>(map, good, tableIndices, position, thread);
else
initTriangles<PFP>(map, good, tableIndices, thread) ;
initTriangles<PFP>(map, good, tableIndices, position, thread) ;
m_nbIndices[TRIANGLE_INDICES] = tableIndices.size();
vbo_ind = m_indexBuffers[TRIANGLE_INDICES];
break;
......
......@@ -301,8 +301,8 @@ protected:
AttributeMultiVector<Dart>* addRelation(const std::string& name) ;
/**
* Get attributeMultivector pointer of a relation attribute
* @param anem name of relation
* Get AttributeMultivector pointer of a relation attribute
* @param name name of the relation
* @return the attribute multi-vector pointer
*/
AttributeMultiVector<Dart>* getRelation(const std::string& name);
......@@ -388,7 +388,7 @@ public:
/**
* update topo relation after compacting the container:
*/
virtual void compactTopoRelations(const std::vector<unsigned int>& oldnew)=0;
virtual void compactTopoRelations(const std::vector<unsigned int>& oldnew) = 0;
/**
* compact the map
......
......@@ -218,6 +218,4 @@ inline AttributeMultiVector<Dart>* GenericMap::getRelation(const std::string& na
return amv ;
}
} //namespace CGoGN
......@@ -58,6 +58,11 @@ public:
*/
virtual Dart deleteEdge(Dart d);
/*!
*
*/
bool edgeCanCollapse(Dart d);
/*!
*
*/
......
......@@ -62,8 +62,6 @@ inline void Map1::update_topo_shortcuts()
m_phi_1 = getRelation("phi_1");
}
/*! @name Basic Topological Operators
* Access and Modification
*************************************************************************/
......
......@@ -65,7 +65,7 @@ public:
virtual void update_topo_shortcuts();
virtual void compactTopoRelations( const std::vector<unsigned int>& oldnew);
virtual void compactTopoRelations(const std::vector<unsigned int>& oldnew);
/*! @name Basic Topological Operators
* Access and Modification
......
......@@ -54,7 +54,6 @@ inline void Map2::clear(bool removeAttrib)
init() ;
}
inline void Map2::update_topo_shortcuts()
{
Map1::update_topo_shortcuts();
......
......@@ -167,6 +167,14 @@ public:
*/
virtual void splitFace(Dart d, Dart e);
//! Delete a volume if and only if it has a face with degree < 3 or only 3 vertices
/*! If the volume is sewed to two distinct adjacent volumes and if the face degree
* of the two adjacent volumes is equal then those two volumes are sewed
* @param d a dart of the face
* @return true if the collapse has been executed, false otherwise
*/
virtual bool collapseDegeneretedVolume(Dart d);
//! Sew two oriented volumes along their faces.
/*! The oriented faces should not be phi3-linked and have the same degree
* @param d a dart of the first volume
......
......@@ -22,11 +22,6 @@
* *
*******************************************************************************/
#include <list>
#include <set>
#include <map>
#include <vector>
namespace CGoGN
{
......@@ -57,7 +52,6 @@ inline void Map3::clear(bool removeAttrib)
init() ;
}
inline void Map3::update_topo_shortcuts()
{
Map2::update_topo_shortcuts();
......
......@@ -6,7 +6,7 @@ VARYING_FRAG float scalar;
FRAG_OUT_DEF;
void main()
{
float s = scalar * 50.0;
float s = scalar * 30.0;
if( s - floor(s) <= 0.01 )
gl_FragColor = vec4(0.0);
else
......
......@@ -70,7 +70,7 @@ public: // methods
/**
* Destructor
*/
~ColourConverter() {} ;
~ColourConverter() ;
/**
* getR
......
......@@ -61,6 +61,15 @@ ColourConverter<REAL>::ColourConverter(VEC3 col, enum ColourEncoding enc) :
}
}
template<typename REAL>
ColourConverter<REAL>::~ColourConverter()
{
delete RGB ;
delete Luv ;
delete XYZ ;
delete Lab ;
}
template<typename REAL>
Geom::Vector<3,REAL> ColourConverter<REAL>::getColour(enum ColourEncoding enc) {
switch (enc) {
......
......@@ -37,7 +37,6 @@ namespace Render
namespace GL2
{
MapRender::MapRender()
{
glGenBuffersARB(SIZE_BUFFER, m_indexBuffers) ;
......
......@@ -305,8 +305,6 @@ void GenericMap::removeThreadMarker(unsigned int nb)
* SAVE & LOAD *
****************************************/
bool GenericMap::saveMapBin(const std::string& filename)
{
CGoGNostream fs(filename.c_str(), std::ios::out|std::ios::binary);
......@@ -318,28 +316,25 @@ bool GenericMap::saveMapBin(const std::string& filename)
// Entete
char* buff = new char[256];
for (int i=0; i< 256; ++i)
for (int i = 0; i < 256; ++i)
buff[i] = char(255);
const char* cgogn = "CGoGN_Map";
memcpy(buff,cgogn,10);
memcpy(buff, cgogn, 10);
std::string mt = mapTypeName();
const char* mtc = mt.c_str();
memcpy(buff+32,mtc,mt.size()+1);
unsigned int *buffi = reinterpret_cast<unsigned int*>(buff+64);
memcpy(buff+32, mtc, mt.size()+1);
unsigned int *buffi = reinterpret_cast<unsigned int*>(buff + 64);
*buffi = NB_ORBITS;
fs.write(reinterpret_cast<const char*>(buff), 256);
delete buff;
// save all attribs
for (unsigned int i=0; i<NB_ORBITS; ++i)
{
m_attribs[i].saveBin(fs,i);
}
for (unsigned int i = 0; i < NB_ORBITS; ++i)
m_attribs[i].saveBin(fs, i);
return true;
}
bool GenericMap::loadMapBin(const std::string& filename)
{
......@@ -365,7 +360,7 @@ bool GenericMap::loadMapBin(const std::string& filename)
}
// Check map type
buff_str = std::string(buff+32);
buff_str = std::string(buff + 32);
std::string localType = this->mapTypeName();
......@@ -373,12 +368,12 @@ bool GenericMap::loadMapBin(const std::string& filename)
if (fileType != localType)
{
CGoGNerr << "Not possible to load "<< fileType<< " into "<< localType << " object"<<CGoGNendl;
CGoGNerr << "Not possible to load "<< fileType << " into " << localType << " object" << CGoGNendl;
return false;
}
// Check max nb orbit
unsigned int *ptr_nbo = reinterpret_cast<unsigned int*>(buff+64);
unsigned int *ptr_nbo = reinterpret_cast<unsigned int*>(buff + 64);
unsigned int nbo = *ptr_nbo;
if (nbo != NB_ORBITS)
{
......@@ -387,7 +382,7 @@ bool GenericMap::loadMapBin(const std::string& filename)
}
// load attrib container
for (unsigned int i=0; i<NB_ORBITS; ++i)
for (unsigned int i = 0; i < NB_ORBITS; ++i)
{
unsigned int id = AttributeContainer::loadBinId(fs);
m_attribs[id].loadBin(fs);
......@@ -395,14 +390,12 @@ bool GenericMap::loadMapBin(const std::string& filename)
// retrieve m_embeddings (from m_attribs[DART]
update_m_emb_afterLoad();
// recursive call from real type of map (for topo relation attributes pointers) down to GenericMap ( for Marker_cleaning & pointers)
// recursive call from real type of map (for topo relation attributes pointers) down to GenericMap (for Marker_cleaning & pointers)
update_topo_shortcuts();
return true;
}
void GenericMap::update_m_emb_afterLoad()
{
// get container of dart orbit
......@@ -415,21 +408,18 @@ void GenericMap::update_m_emb_afterLoad()
// check if there are EMB_X attributes
for (unsigned int i = 0; i < listeNames.size(); ++i)
{
std::string sub = listeNames[i].substr(0,listeNames[i].size()-1);
std::string sub = listeNames[i].substr(0, listeNames[i].size() - 1);
if (sub == "EMB_")
{
unsigned int orb = listeNames[i][4]-'0'; // easy atoi computation for one char;
AttributeMultiVector<unsigned int>* amv = cont.getDataVector<unsigned int>(i);
m_embeddings[orb] = amv ;
}
}
}
void GenericMap::update_topo_shortcuts()
{
for(unsigned int orbit = 0; orbit < NB_ORBITS; ++orbit)
{
AttributeContainer& cont = m_attribs[orbit];
......@@ -440,32 +430,28 @@ void GenericMap::update_topo_shortcuts()
for (unsigned int i = 0; i < listeNames.size(); ++i)
{
std::string sub = listeNames[i].substr(0,5);
std::string sub = listeNames[i].substr(0, 5);
if (sub == "Mark_")
{
// get thread number
unsigned int thread = listeNames[i][5]-'0';
if (listeNames[i].size()>6) // thread number is >9
if (listeNames[i].size() > 6) // thread number is >9
thread = 10*thread + listeNames[i][6]-'0';
AttributeMultiVector<Mark>* amvMark = cont.getDataVector<Mark>(i);
m_markTables[orbit][thread] = amvMark ;
if ((orbit == DART) && (thread==0)) // for Marker of dart of thread O keep the boundary marker
if ((orbit == DART) && (thread == 0)) // for Marker of dart of thread O keep the boundary marker
{
Mark m(m_boundaryMarker);
m.invert();
for (unsigned int i=cont.begin();i!= cont.end(); cont.next(i))
{
for (unsigned int i = cont.begin(); i != cont.end(); cont.next(i))
amvMark->operator[](i).unsetMark(m);
}
}
else // for others clear all
{
for (unsigned int i=cont.begin();i!= cont.end(); cont.next(i))
{
for (unsigned int i = cont.begin(); i != cont.end(); cont.next(i))
amvMark->operator[](i).clear();
}
}