Commit 2a41adea authored by untereiner's avatar untereiner
Browse files

Merge cgogn:~cgogn/CGoGN

parents b52ebd44 9a48f6a3
#include <iostream>
#include <Container/attributeContainer.h>
#include <iostream>
#include "Topology/generic/parameters.h"
#include "Topology/map/embeddedMap2.h"
//#include "Geometry/vector_gen.h"
#include "Algo/Modelisation/polyhedron.h"
using namespace CGoGN;
struct PFP: public PFP_STANDARD
{
// definition of the map
typedef EmbeddedMap2 MAP ;
};
void dump(AttributeContainer& cont, AttributeMultiVector<int>* amv)
{
std::cout << "==============================================="<<std::endl;
int j=0;
for (unsigned int it = cont.begin(); it != cont.end(); cont.next(it))
{
if (j%10 == 0)
std::cout << std::endl << j<< " : ";
std::cout << amv->operator [](it) << " / ";
j++;
}
std::cout << std::endl <<"------------------------------------------------"<<std::endl;
}
void test_compact_container()
{
#define NB 200
AttributeContainer cont;
AttributeMultiVector<int>* amv = cont.addAttribute<int>("entiers");
for (int i =0; i< NB; ++i)
{
unsigned int l = cont.insertLine();
amv->operator [](l) = i;
}
dump(cont,amv);
for (int i =0; i< NB; i+=3)
{
cont.removeLine(i);
}
dump(cont,amv);
std::vector<unsigned int> oldnew;
cont.compact(oldnew);
dump(cont,amv);
std::cout << "Size = "<< oldnew.size()<< std::endl;
int k=0;
for (std::vector<unsigned int>::iterator it =oldnew.begin(); it != oldnew.end() ;++it)
{
std::cout <<k << "->";
if (*it != 0xffffffff)
std::cout << *it;
else
std::cout << "X";
std::cout <<"/";
++k;
if (k%10 ==0)
std::cout << std::endl;
}
std::cout << std::endl;
#undef NB
}
void test_compact_map(const std::string& name)
{
EmbeddedMap2 myMap;
PFP::TVEC3 position = myMap.addAttribute<PFP::VEC3>(VERTEX, "position") ;
#define NB 256
Algo::Modelisation::Polyhedron<PFP> prim1(myMap, position);
prim1.cylinder_topo(256, 256, false, false);
prim1.embedCylinder(30.0f, 10.0f, 70.0f);
#undef NB
DartMarker dm(myMap);
std::vector<Dart> verts;
int i=0;
for (Dart d = myMap.begin(); d!= myMap.end(); myMap.next(d))
{
if (!dm.isMarked(d) && (!myMap.isBoundaryEdge(d))&& (i%11 ==0))
{
verts.push_back(d);
Dart e = d;
do // mark all edges incident to vertex;
{
dm.markOrbit( EDGE, e);
e = myMap.alpha1(e);
}while (e!=d);
}
i++;
}
for (std::vector<Dart>::iterator it=verts.begin(); it != verts.end(); ++it)
{
myMap.deleteVertex(*it);
}
myMap.saveMapBin(name+"_full.map");
myMap.compact();
myMap.saveMapBin(name+"_compact.map");
}
int main(int argc, char** argv)
{
if (argc>1)
test_compact_map(std::string(argv[1]));
else
test_compact_container();
return 0;
}
...@@ -301,8 +301,8 @@ protected: ...@@ -301,8 +301,8 @@ protected:
AttributeMultiVector<Dart>* addRelation(const std::string& name) ; AttributeMultiVector<Dart>* addRelation(const std::string& name) ;
/** /**
* Get attributeMultivector pointer of a relation attribute * Get AttributeMultivector pointer of a relation attribute
* @param anem name of relation * @param name name of the relation
* @return the attribute multi-vector pointer * @return the attribute multi-vector pointer
*/ */
AttributeMultiVector<Dart>* getRelation(const std::string& name); AttributeMultiVector<Dart>* getRelation(const std::string& name);
...@@ -388,7 +388,7 @@ public: ...@@ -388,7 +388,7 @@ public:
/** /**
* update topo relation after compacting the container: * 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 * compact the map
......
...@@ -218,6 +218,4 @@ inline AttributeMultiVector<Dart>* GenericMap::getRelation(const std::string& na ...@@ -218,6 +218,4 @@ inline AttributeMultiVector<Dart>* GenericMap::getRelation(const std::string& na
return amv ; return amv ;
} }
} //namespace CGoGN } //namespace CGoGN
...@@ -62,8 +62,6 @@ inline void Map1::update_topo_shortcuts() ...@@ -62,8 +62,6 @@ inline void Map1::update_topo_shortcuts()
m_phi_1 = getRelation("phi_1"); m_phi_1 = getRelation("phi_1");
} }
/*! @name Basic Topological Operators /*! @name Basic Topological Operators
* Access and Modification * Access and Modification
*************************************************************************/ *************************************************************************/
......
...@@ -65,7 +65,7 @@ public: ...@@ -65,7 +65,7 @@ public:
virtual void update_topo_shortcuts(); 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 /*! @name Basic Topological Operators
* Access and Modification * Access and Modification
......
...@@ -54,7 +54,6 @@ inline void Map2::clear(bool removeAttrib) ...@@ -54,7 +54,6 @@ inline void Map2::clear(bool removeAttrib)
init() ; init() ;
} }
inline void Map2::update_topo_shortcuts() inline void Map2::update_topo_shortcuts()
{ {
Map1::update_topo_shortcuts(); Map1::update_topo_shortcuts();
......
...@@ -52,7 +52,6 @@ inline void Map3::clear(bool removeAttrib) ...@@ -52,7 +52,6 @@ inline void Map3::clear(bool removeAttrib)
init() ; init() ;
} }
inline void Map3::update_topo_shortcuts() inline void Map3::update_topo_shortcuts()
{ {
Map2::update_topo_shortcuts(); Map2::update_topo_shortcuts();
......
...@@ -70,7 +70,7 @@ public: // methods ...@@ -70,7 +70,7 @@ public: // methods
/** /**
* Destructor * Destructor
*/ */
~ColourConverter() {} ; ~ColourConverter() ;
/** /**
* getR * getR
......
...@@ -61,6 +61,15 @@ ColourConverter<REAL>::ColourConverter(VEC3 col, enum ColourEncoding enc) : ...@@ -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> template<typename REAL>
Geom::Vector<3,REAL> ColourConverter<REAL>::getColour(enum ColourEncoding enc) { Geom::Vector<3,REAL> ColourConverter<REAL>::getColour(enum ColourEncoding enc) {
switch (enc) { switch (enc) {
......
...@@ -305,8 +305,6 @@ void GenericMap::removeThreadMarker(unsigned int nb) ...@@ -305,8 +305,6 @@ void GenericMap::removeThreadMarker(unsigned int nb)
* SAVE & LOAD * * SAVE & LOAD *
****************************************/ ****************************************/
bool GenericMap::saveMapBin(const std::string& filename) bool GenericMap::saveMapBin(const std::string& filename)
{ {
CGoGNostream fs(filename.c_str(), std::ios::out|std::ios::binary); CGoGNostream fs(filename.c_str(), std::ios::out|std::ios::binary);
...@@ -318,28 +316,25 @@ bool GenericMap::saveMapBin(const std::string& filename) ...@@ -318,28 +316,25 @@ bool GenericMap::saveMapBin(const std::string& filename)
// Entete // Entete
char* buff = new char[256]; char* buff = new char[256];
for (int i=0; i< 256; ++i) for (int i = 0; i < 256; ++i)
buff[i] = char(255); buff[i] = char(255);
const char* cgogn = "CGoGN_Map"; const char* cgogn = "CGoGN_Map";
memcpy(buff,cgogn,10); memcpy(buff, cgogn, 10);
std::string mt = mapTypeName(); std::string mt = mapTypeName();
const char* mtc = mt.c_str(); const char* mtc = mt.c_str();
memcpy(buff+32,mtc,mt.size()+1); memcpy(buff+32, mtc, mt.size()+1);
unsigned int *buffi = reinterpret_cast<unsigned int*>(buff+64); unsigned int *buffi = reinterpret_cast<unsigned int*>(buff + 64);
*buffi = NB_ORBITS; *buffi = NB_ORBITS;
fs.write(reinterpret_cast<const char*>(buff), 256); fs.write(reinterpret_cast<const char*>(buff), 256);
delete buff; delete buff;
// save all attribs // save all attribs
for (unsigned int i=0; i<NB_ORBITS; ++i) for (unsigned int i = 0; i < NB_ORBITS; ++i)
{ m_attribs[i].saveBin(fs, i);
m_attribs[i].saveBin(fs,i);
}
return true; return true;
} }
bool GenericMap::loadMapBin(const std::string& filename) bool GenericMap::loadMapBin(const std::string& filename)
{ {
...@@ -365,7 +360,7 @@ bool GenericMap::loadMapBin(const std::string& filename) ...@@ -365,7 +360,7 @@ bool GenericMap::loadMapBin(const std::string& filename)
} }
// Check map type // Check map type
buff_str = std::string(buff+32); buff_str = std::string(buff + 32);
std::string localType = this->mapTypeName(); std::string localType = this->mapTypeName();
...@@ -373,12 +368,12 @@ bool GenericMap::loadMapBin(const std::string& filename) ...@@ -373,12 +368,12 @@ bool GenericMap::loadMapBin(const std::string& filename)
if (fileType != localType) 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; return false;
} }
// Check max nb orbit // 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; unsigned int nbo = *ptr_nbo;
if (nbo != NB_ORBITS) if (nbo != NB_ORBITS)
{ {
...@@ -387,7 +382,7 @@ bool GenericMap::loadMapBin(const std::string& filename) ...@@ -387,7 +382,7 @@ bool GenericMap::loadMapBin(const std::string& filename)
} }
// load attrib container // 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); unsigned int id = AttributeContainer::loadBinId(fs);
m_attribs[id].loadBin(fs); m_attribs[id].loadBin(fs);
...@@ -395,14 +390,12 @@ bool GenericMap::loadMapBin(const std::string& filename) ...@@ -395,14 +390,12 @@ bool GenericMap::loadMapBin(const std::string& filename)
// retrieve m_embeddings (from m_attribs[DART] // retrieve m_embeddings (from m_attribs[DART]
update_m_emb_afterLoad(); 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(); update_topo_shortcuts();
return true; return true;
} }
void GenericMap::update_m_emb_afterLoad() void GenericMap::update_m_emb_afterLoad()
{ {
// get container of dart orbit // get container of dart orbit
...@@ -415,21 +408,18 @@ void GenericMap::update_m_emb_afterLoad() ...@@ -415,21 +408,18 @@ void GenericMap::update_m_emb_afterLoad()
// check if there are EMB_X attributes // check if there are EMB_X attributes
for (unsigned int i = 0; i < listeNames.size(); ++i) 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_") if (sub == "EMB_")
{ {
unsigned int orb = listeNames[i][4]-'0'; // easy atoi computation for one char; unsigned int orb = listeNames[i][4]-'0'; // easy atoi computation for one char;
AttributeMultiVector<unsigned int>* amv = cont.getDataVector<unsigned int>(i); AttributeMultiVector<unsigned int>* amv = cont.getDataVector<unsigned int>(i);
m_embeddings[orb] = amv ; m_embeddings[orb] = amv ;
} }
} }
} }
void GenericMap::update_topo_shortcuts() void GenericMap::update_topo_shortcuts()
{ {
for(unsigned int orbit = 0; orbit < NB_ORBITS; ++orbit) for(unsigned int orbit = 0; orbit < NB_ORBITS; ++orbit)
{ {
AttributeContainer& cont = m_attribs[orbit]; AttributeContainer& cont = m_attribs[orbit];
...@@ -440,32 +430,28 @@ void GenericMap::update_topo_shortcuts() ...@@ -440,32 +430,28 @@ void GenericMap::update_topo_shortcuts()
for (unsigned int i = 0; i < listeNames.size(); ++i) 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_") if (sub == "Mark_")
{ {
// get thread number // get thread number
unsigned int thread = listeNames[i][5]-'0'; 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'; thread = 10*thread + listeNames[i][6]-'0';
AttributeMultiVector<Mark>* amvMark = cont.getDataVector<Mark>(i); AttributeMultiVector<Mark>* amvMark = cont.getDataVector<Mark>(i);
m_markTables[orbit][thread] = amvMark ; 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); Mark m(m_boundaryMarker);
m.invert(); 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); amvMark->operator[](i).unsetMark(m);
}
} }
else // for others clear all 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(); amvMark->operator[](i).clear();
}
} }
} }
} }
...@@ -474,38 +460,36 @@ void GenericMap::update_topo_shortcuts() ...@@ -474,38 +460,36 @@ void GenericMap::update_topo_shortcuts()
void GenericMap::dumpAttributesAndMarkers() void GenericMap::dumpAttributesAndMarkers()
{ {
for (unsigned int i = 0; i<NB_ORBITS; ++i) for (unsigned int i = 0; i < NB_ORBITS; ++i)
{ {
std::vector<std::string> names; std::vector<std::string> names;
names.reserve(32); //just tp limit reallocation names.reserve(32); //just to limit reallocation
m_attribs[i].getAttributesNames(names); m_attribs[i].getAttributesNames(names);
unsigned int nb = names.size(); unsigned int nb = names.size();
if (nb>0) if (nb > 0)
{ {
CGoGNout << "ORBIT "<< i<< CGoGNendl; CGoGNout << "ORBIT "<< i << CGoGNendl;
std::vector<std::string> types; std::vector<std::string> types;
types.reserve(nb); types.reserve(nb);
m_attribs[i].getAttributesTypes(types); m_attribs[i].getAttributesTypes(types);
for (unsigned int j=0; j<nb; ++j) for (unsigned int j = 0; j < nb; ++j)
{ CGoGNout << " " << j << " : " << types[j] << " " << names[j] << CGoGNendl;
CGoGNout << " "<< j << " : "<< types[j] << " "<< names[j]<< CGoGNendl;
}
} }
} }
CGoGNout << "RESERVED MARKERS "<< CGoGNendl; CGoGNout << "RESERVED MARKERS "<< CGoGNendl;
for (unsigned int i=0; i<NB_ORBITS; ++i) for (unsigned int i = 0; i < NB_ORBITS; ++i)
{ {
for (unsigned int j=0; j<NB_THREAD; ++j) for (unsigned int j = 0; j < NB_THREAD; ++j)
{ {
MarkSet ms = m_marksets[i][j]; MarkSet ms = m_marksets[i][j];
if (!ms.isClear()) if (!ms.isClear())
{ {
CGoGNout << "Orbit " << i << " thread "<<j<< " : "; CGoGNout << "Orbit " << i << " thread " << j << " : ";
Mark m(1); Mark m(1);
for (unsigned i = 0; i< Mark::getNbMarks(); ++i) for (unsigned i = 0; i < Mark::getNbMarks(); ++i)
{ {
if (ms.testMark(m)) if (ms.testMark(m))
CGoGNout << m.getMarkVal()<< ", "; CGoGNout << m.getMarkVal() << ", ";
m.setMarkVal(m.getMarkVal()<<1); m.setMarkVal(m.getMarkVal()<<1);
} }
CGoGNout << CGoGNendl; CGoGNout << CGoGNendl;
...@@ -514,7 +498,6 @@ void GenericMap::dumpAttributesAndMarkers() ...@@ -514,7 +498,6 @@ void GenericMap::dumpAttributesAndMarkers()
} }
} }
void GenericMap::compact() void GenericMap::compact()
{ {
std::vector<unsigned int> oldnew; std::vector<unsigned int> oldnew;
...@@ -526,11 +509,11 @@ void GenericMap::compact() ...@@ -526,11 +509,11 @@ void GenericMap::compact()
{ {
m_attribs[orbit].compact(oldnew); m_attribs[orbit].compact(oldnew);
for (unsigned int i = m_attribs[DART].begin(); i!= m_attribs[DART].end(); m_attribs[DART].next(i)) for (unsigned int i = m_attribs[DART].begin(); i != m_attribs[DART].end(); m_attribs[DART].next(i))
{ {
unsigned int& idx = m_embeddings[orbit]->operator [](i); unsigned int& idx = m_embeddings[orbit]->operator [](i);
unsigned int jdx = oldnew[idx]; unsigned int jdx = oldnew[idx];
if ((jdx != 0xffffffff) && (jdx!=idx)) if ((jdx != 0xffffffff) && (jdx != idx))
idx = jdx; idx = jdx;
} }
} }
...@@ -832,5 +815,3 @@ void GenericMap::boundaryUnmarkAll() ...@@ -832,5 +815,3 @@ void GenericMap::boundaryUnmarkAll()
// //
// return true ; // return true ;
//} //}
...@@ -27,6 +27,17 @@ ...@@ -27,6 +27,17 @@
namespace CGoGN namespace CGoGN