Commit fbe84ae5 authored by Sylvain Thery's avatar Sylvain Thery

Merge branch 'develop' of cgogn:~thery/CGoGNMR into develop

parents fb9b1fb3 b9dbea54
...@@ -47,81 +47,6 @@ typedef PFP::MAP::IMPL MAP_IMPL ; // map implementation ...@@ -47,81 +47,6 @@ typedef PFP::MAP::IMPL MAP_IMPL ; // map implementation
typedef PFP::VEC3 VEC3 ; // type of R³ vector typedef PFP::VEC3 VEC3 ; // type of R³ vector
// example of cell marking with CellMarker for a simple traversal
template<unsigned int ORBIT>
void simpleTraversal(MAP& map) // NEVER COPY THE MAP, ALWAYS USE REFERENCE !!
{
CellMarker<MAP,ORBIT> cm(map);
for (Dart d = map.begin(); d != map.end(); map.next(d))
{
if (!cm.isMarked(d)) // is the cell (of dart d) not marked ?
{
std::cout << orbitName(ORBIT)<< " of dart "<< d << std::endl;
cm.mark(d); // mark the cell
}
}
std::cout << std::endl;
// all cells are unmarked automatically during the destruction of the CellMarker
}
// example of cell marking with CellMarkerNoUnmark for a double traversal
template<unsigned int ORBIT>
void doubleTraversal(MAP& map) // NEVER COPY THE MAP, ALWAYS USE REFERENCE !!
{
CellMarkerNoUnmark<MAP,ORBIT> cm(map);
for (Dart d = map.begin(); d != map.end(); map.next(d))
{
if (!cm.isMarked(d)) // is the cell (of dart d) not marked ?
{
std::cout << "First Pass" << orbitName(ORBIT)<< " of dart "<< d << std::endl;
cm.mark(d); // mark the cell
}
}
std::cout << std::endl;
for (Dart d = map.begin(); d != map.end(); map.next(d))
{
if (cm.isMarked(d)) // is the cell (of dart d) marked ?
{
std::cout << "second Pass" << orbitName(ORBIT)<< " of dart "<< d << std::endl;
cm.unmark(d); // unmark the cell
}
}
std::cout << std::endl;
// destructor does not clean the markers
// user MUST ensure that he has unmark all he has marked
}
// example of usage of CellMarkerStore
void negativePositions(MAP& map, VertexAttribute<VEC3,MAP_IMPL>& position) // NEVER COPY THE MAP, ALWAYS USE REFERENCE !!
{
// if user knows that small numbers of cell will be marked
// it is more efficient to store them instead of traverse
// all darts for cleanning. CellMarkerStore do it for you.
CellMarkerStore<MAP,VERTEX> cms(map);
for (Dart d = map.begin(); d != map.end(); map.next(d))
{
if (!cms.isMarked(d) && (position[d][0]<= 0.0) && (position[d][1]<= 0.0))
{
std::cout << "position["<<d<<"] < (0,0)" << std::endl;
cms.mark(d);
}
}
std::cout << std::endl;
}
int main() int main()
{ {
// declare a map to handle the mesh // declare a map to handle the mesh
...@@ -149,6 +74,5 @@ int main() ...@@ -149,6 +74,5 @@ int main()
position[myMap.phi<11>(f2.dart)] = VEC3(0, -2, 0); position[myMap.phi<11>(f2.dart)] = VEC3(0, -2, 0);
position[myMap.phi_1(f2.dart)] = VEC3(2, -2, 0); position[myMap.phi_1(f2.dart)] = VEC3(2, -2, 0);
return 0; return 0;
} }
...@@ -33,6 +33,7 @@ ...@@ -33,6 +33,7 @@
#include "Algo/Export/export.h" #include "Algo/Export/export.h"
#include "Algo/Modelisation/subdivision.h" #include "Algo/Modelisation/subdivision.h"
#include "Algo/Geometry/normal.h"
using namespace CGoGN ; using namespace CGoGN ;
...@@ -50,19 +51,20 @@ typedef PFP::MAP MAP ; ...@@ -50,19 +51,20 @@ typedef PFP::MAP MAP ;
typedef PFP::MAP::IMPL MAP_IMPL ; typedef PFP::MAP::IMPL MAP_IMPL ;
typedef PFP::VEC3 VEC3 ; typedef PFP::VEC3 VEC3 ;
void pipo(PFP::MAP& m)
{
std::cout << m.getNbDarts()<< std::endl;
}
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
if(argc != 3) if(argc != 3)
{ {
CGoGNout << "Usage : " << argv[0] << " filename nbSteps" << CGoGNendl; CGoGNerr << "Usage : " << argv[0] << " filename nbSteps" << CGoGNendl;
return 0; return 1;
} }
unsigned int nbSteps = atoi(argv[2]);
std::string filename(argv[1]);
unsigned int nbSteps;
std::istringstream iss(argv[2]);
iss >> nbSteps;
// declaration of the map // declaration of the map
MAP myMap; MAP myMap;
...@@ -70,13 +72,32 @@ int main(int argc, char **argv) ...@@ -70,13 +72,32 @@ int main(int argc, char **argv)
std::vector<std::string> attrNames ; std::vector<std::string> attrNames ;
Algo::Surface::Import::importMesh<PFP>(myMap, argv[1], attrNames); Algo::Surface::Import::importMesh<PFP>(myMap, argv[1], attrNames);
// get a handler to the 3D vector attribute created by the import // get a handler to the 3D vector attribute created by the import (position always the first)
VertexAttribute<VEC3, MAP_IMPL> position = myMap.getAttribute<VEC3, VERTEX>(attrNames[0]); VertexAttribute<VEC3, MAP_IMPL> position = myMap.getAttribute<VEC3, VERTEX>(attrNames[0]);
// a second map
MAP myMap2;
// for copying the initial mesh
myMap2.copyFrom(myMap);
// AttributeHandler are linked to the map, need a new one
VertexAttribute<VEC3, MAP_IMPL> position2 = myMap2.getAttribute<VEC3, VERTEX>(attrNames[0]);
// subdivide first map with Loop algo
for(unsigned int i = 0; i < nbSteps; ++i) for(unsigned int i = 0; i < nbSteps; ++i)
Algo::Surface::Modelisation::LoopSubdivision<PFP>(myMap, position); Algo::Surface::Modelisation::LoopSubdivision<PFP>(myMap, position);
Algo::Surface::Export::exportOFF<PFP>(myMap, position, "result.off"); // and export to file
Algo::Surface::Export::exportOFF<PFP>(myMap, position, "resultLoop.off");
// subdivide second map with CatmullClark (using map2/position2)
for(unsigned int i = 0; i < nbSteps; ++i)
Algo::Surface::Modelisation::CatmullClarkSubdivision<PFP>(myMap2, position2);
// and export to file (using map2/position2)
Algo::Surface::Export::exportOFF<PFP>(myMap2, position2, "resultCC.off");
return 0; return 0;
} }
...@@ -58,7 +58,8 @@ void computeCurvatureVertices_QuadraticFitting( ...@@ -58,7 +58,8 @@ void computeCurvatureVertices_QuadraticFitting(
VertexAttribute<typename PFP::REAL, typename PFP::MAP::IMPL>& kmax, VertexAttribute<typename PFP::REAL, typename PFP::MAP::IMPL>& kmax,
VertexAttribute<typename PFP::REAL, typename PFP::MAP::IMPL>& kmin, VertexAttribute<typename PFP::REAL, typename PFP::MAP::IMPL>& kmin,
VertexAttribute<typename PFP::VEC3, typename PFP::MAP::IMPL>& Kmax, VertexAttribute<typename PFP::VEC3, typename PFP::MAP::IMPL>& Kmax,
VertexAttribute<typename PFP::VEC3, typename PFP::MAP::IMPL>& Kmin) ; VertexAttribute<typename PFP::VEC3, typename PFP::MAP::IMPL>& Kmin,
unsigned int thread = 0) ;
template <typename PFP> template <typename PFP>
void computeCurvatureVertex_QuadraticFitting( void computeCurvatureVertex_QuadraticFitting(
......
...@@ -138,7 +138,8 @@ public: ...@@ -138,7 +138,8 @@ public:
~AttributeContainer(); ~AttributeContainer();
unsigned int getOrbit(); unsigned int getOrbit() const;
void setOrbit(unsigned int orbit); void setOrbit(unsigned int orbit);
void setRegistry(std::map<std::string, RegisteredBaseAttribute*>* re); void setRegistry(std::map<std::string, RegisteredBaseAttribute*>* re);
...@@ -273,7 +274,7 @@ public: ...@@ -273,7 +274,7 @@ public:
/** /**
* get the name of an attribute, given its index in the container * get the name of an attribute, given its index in the container
*/ */
const std::string& getAttributeName(unsigned int attrIndex); const std::string& getAttributeName(unsigned int attrIndex) const;
/** /**
* fill a vector with pointers to the blocks of the given attribute * fill a vector with pointers to the blocks of the given attribute
...@@ -290,7 +291,7 @@ public: ...@@ -290,7 +291,7 @@ public:
* @param names vector of names * @param names vector of names
* @return number of attributes * @return number of attributes
*/ */
unsigned int getAttributesNames(std::vector<std::string>& names); unsigned int getAttributesNames(std::vector<std::string>& names) const;
/** /**
* fill a vector with attribute type names * fill a vector with attribute type names
...@@ -364,7 +365,7 @@ public: ...@@ -364,7 +365,7 @@ public:
* @param index index of the line * @param index index of the line
* @return number of refs of the line * @return number of refs of the line
*/ */
unsigned int getNbRefs(unsigned int index); unsigned int getNbRefs(unsigned int index) const;
/** /**
* set the number of refs of the given line * set the number of refs of the given line
...@@ -473,6 +474,14 @@ public: ...@@ -473,6 +474,14 @@ public:
*/ */
void copyFrom(const AttributeContainer& cont); void copyFrom(const AttributeContainer& cont);
/**
* dump the container in CSV format (; separated columns)
*/
void dumpCSV() const;
void dumpByLines() const;
}; };
} // namespace CGoGN } // namespace CGoGN
......
...@@ -30,7 +30,7 @@ ...@@ -30,7 +30,7 @@
namespace CGoGN namespace CGoGN
{ {
inline unsigned int AttributeContainer::getOrbit() inline unsigned int AttributeContainer::getOrbit() const
{ {
return m_orbit ; return m_orbit ;
} }
...@@ -332,7 +332,7 @@ inline bool AttributeContainer::unrefLine(unsigned int index) ...@@ -332,7 +332,7 @@ inline bool AttributeContainer::unrefLine(unsigned int index)
return false; return false;
} }
inline unsigned int AttributeContainer::getNbRefs(unsigned int index) inline unsigned int AttributeContainer::getNbRefs(unsigned int index) const
{ {
unsigned int bi = index / _BLOCKSIZE_; unsigned int bi = index / _BLOCKSIZE_;
unsigned int j = index % _BLOCKSIZE_; unsigned int j = index % _BLOCKSIZE_;
......
...@@ -176,6 +176,12 @@ public: ...@@ -176,6 +176,12 @@ public:
virtual bool loadBin(CGoGNistream& fs) = 0; virtual bool loadBin(CGoGNistream& fs) = 0;
static bool skipLoadBin(CGoGNistream& fs); static bool skipLoadBin(CGoGNistream& fs);
/**
* lecture binaire
* @param fs filestream
*/
virtual void dump(unsigned int i) const = 0;
}; };
...@@ -266,17 +272,17 @@ public: ...@@ -266,17 +272,17 @@ public:
* ARITHMETIC OPERATIONS * * ARITHMETIC OPERATIONS *
**************************************/ **************************************/
void affect(unsigned int i, unsigned int j); // void affect(unsigned int i, unsigned int j);
void add(unsigned int i, unsigned int j); // void add(unsigned int i, unsigned int j);
void sub(unsigned int i, unsigned int j); // void sub(unsigned int i, unsigned int j);
void mult(unsigned int i, double alpha); // void mult(unsigned int i, double alpha);
void div(unsigned int i, double alpha); // void div(unsigned int i, double alpha);
void lerp(unsigned res, unsigned int i, unsigned int j, double alpha); // void lerp(unsigned res, unsigned int i, unsigned int j, double alpha);
/************************************** /**************************************
* SAVE & LOAD * * SAVE & LOAD *
...@@ -294,6 +300,13 @@ public: ...@@ -294,6 +300,13 @@ public:
* @param fs filestream * @param fs filestream
*/ */
bool loadBin(CGoGNistream& fs); bool loadBin(CGoGNistream& fs);
/**
* lecture binaire
* @param fs filestream
*/
virtual void dump(unsigned int i) const;
}; };
} // namespace CGoGN } // namespace CGoGN
......
...@@ -407,4 +407,11 @@ inline bool AttributeMultiVectorGen::skipLoadBin(CGoGNistream& fs) ...@@ -407,4 +407,11 @@ inline bool AttributeMultiVectorGen::skipLoadBin(CGoGNistream& fs)
return true; return true;
} }
template <typename T>
void AttributeMultiVector<T>::dump(unsigned int i) const
{
CGoGNout << this->operator[](i);
}
} // namespace CGoGN } // namespace CGoGN
...@@ -48,6 +48,13 @@ public: ...@@ -48,6 +48,13 @@ public:
static std::string CGoGNnameOfType() { return ""; } static std::string CGoGNnameOfType() { return ""; }
}; };
template <typename T>
std::ostream& operator<<(std::ostream& out, const NoTypeNameAttribute<T>&)
{
out << "no_output" ;
return out ;
}
} // namespace CGoGN } // namespace CGoGN
#endif /* FAKEATTRIBUTE_H_ */ #endif /* FAKEATTRIBUTE_H_ */
...@@ -87,6 +87,9 @@ class GenericMap ...@@ -87,6 +87,9 @@ class GenericMap
template<typename MAP, unsigned int CELL> friend class CellMarkerBase ; template<typename MAP, unsigned int CELL> friend class CellMarkerBase ;
protected: protected:
// protected copy constructor to prevent the copy of map
GenericMap(const GenericMap& ) {}
/** /**
* Attributes Containers * Attributes Containers
*/ */
...@@ -124,7 +127,7 @@ protected: ...@@ -124,7 +127,7 @@ protected:
*/ */
Mark m_boundaryMarkers[2] ; // 0 for dim 2 / 1 for dim 3 Mark m_boundaryMarkers[2] ; // 0 for dim 2 / 1 for dim 3
unsigned int m_nbThreads ; unsigned int m_nbThreadMarkers ;
/** /**
* Store links to created AttributeHandlers, DartMarkers and CellMarkers * Store links to created AttributeHandlers, DartMarkers and CellMarkers
...@@ -358,7 +361,7 @@ public: ...@@ -358,7 +361,7 @@ public:
* return allowed threads * return allowed threads
* @return the number of threads (including principal) * @return the number of threads (including principal)
*/ */
unsigned int getNbThreadMarkers() ; unsigned int getNbThreadMarkers() const;
/** /**
* Remove some added threads * Remove some added threads
...@@ -411,6 +414,11 @@ public: ...@@ -411,6 +414,11 @@ public:
* compact the map * compact the map
*/ */
void compact() ; void compact() ;
/**
* @brief dump all attributes of map in CSV format (; separated columns)
*/
void dumpCSV() const;
} ; } ;
......
...@@ -49,7 +49,7 @@ inline void GenericMap::deleteDartLine(unsigned int index) ...@@ -49,7 +49,7 @@ inline void GenericMap::deleteDartLine(unsigned int index)
{ {
m_attribs[DART].removeLine(index) ; // free the dart line m_attribs[DART].removeLine(index) ; // free the dart line
for (unsigned int t = 0; t < m_nbThreads; ++t) // clear markers of for (unsigned int t = 0; t < m_nbThreadMarkers; ++t) // clear markers of
(*m_markTables[DART][t])[index].clear() ; // the removed dart (*m_markTables[DART][t])[index].clear() ; // the removed dart
for(unsigned int orbit = 0; orbit < NB_ORBITS; ++orbit) for(unsigned int orbit = 0; orbit < NB_ORBITS; ++orbit)
...@@ -61,7 +61,7 @@ inline void GenericMap::deleteDartLine(unsigned int index) ...@@ -61,7 +61,7 @@ inline void GenericMap::deleteDartLine(unsigned int index)
{ {
if(m_attribs[orbit].unrefLine(emb)) // unref the pointed embedding line if(m_attribs[orbit].unrefLine(emb)) // unref the pointed embedding line
{ {
for (unsigned int t = 0; t < m_nbThreads; ++t) // and clear its markers if it was for (unsigned int t = 0; t < m_nbThreadMarkers; ++t) // and clear its markers if it was
(*m_markTables[orbit][t])[emb].clear() ; // its last unref (and was thus freed) (*m_markTables[orbit][t])[emb].clear() ; // its last unref (and was thus freed)
} }
} }
......
...@@ -36,6 +36,12 @@ class MapCommon : public MAP_IMPL ...@@ -36,6 +36,12 @@ class MapCommon : public MAP_IMPL
{ {
typedef MAP_IMPL IMPL; typedef MAP_IMPL IMPL;
protected:
// protected copy constructor to prevent the copy of map
MapCommon(const MapCommon<MAP_IMPL>& m) : MAP_IMPL(m) {}
public:
MapCommon() {}
/**************************************** /****************************************
* DARTS TRAVERSALS * * DARTS TRAVERSALS *
****************************************/ ****************************************/
...@@ -127,7 +133,10 @@ public: ...@@ -127,7 +133,10 @@ public:
/**************************************** /****************************************
* BOUNDARY MANAGEMENT * * BOUNDARY MANAGEMENT *
****************************************/ ****************************************/
protected: protected:
/** /**
* mark a dart as belonging to boundary * mark a dart as belonging to boundary
*/ */
......
...@@ -85,7 +85,7 @@ void MapCommon<MAP_IMPL>::setDartEmbedding(Dart d, unsigned int emb) ...@@ -85,7 +85,7 @@ void MapCommon<MAP_IMPL>::setDartEmbedding(Dart d, unsigned int emb)
{ {
if(this->m_attribs[ORBIT].unrefLine(old)) // then unref the old emb if(this->m_attribs[ORBIT].unrefLine(old)) // then unref the old emb
{ {
for (unsigned int t = 0; t < this->m_nbThreads; ++t) // clear the markers if it was the for (unsigned int t = 0; t < this->m_nbThreadMarkers; ++t) // clear the markers if it was the
(*this->m_markTables[ORBIT][t])[old].clear(); // last unref of the line (*this->m_markTables[ORBIT][t])[old].clear(); // last unref of the line
} }
} }
......
...@@ -42,6 +42,9 @@ public: ...@@ -42,6 +42,9 @@ public:
inline virtual void clear(bool removeAttrib); inline virtual void clear(bool removeAttrib);
protected: protected:
// protected copy constructor to prevent the copy of map
MapMono(const MapMono& m): GenericMap(m){}
std::vector<AttributeMultiVector<Dart>*> m_involution; std::vector<AttributeMultiVector<Dart>*> m_involution;
std::vector<AttributeMultiVector<Dart>*> m_permutation; std::vector<AttributeMultiVector<Dart>*> m_permutation;
std::vector<AttributeMultiVector<Dart>*> m_permutation_inv; std::vector<AttributeMultiVector<Dart>*> m_permutation_inv;
......
...@@ -44,6 +44,9 @@ public: ...@@ -44,6 +44,9 @@ public:
inline virtual void clear(bool removeAttrib); inline virtual void clear(bool removeAttrib);
protected: protected:
// protected copy constructor to prevent the copy of map
MapMulti(const MapMulti& m): GenericMap(m) {}
std::vector<AttributeMultiVector<Dart>*> m_involution; std::vector<AttributeMultiVector<Dart>*> m_involution;
std::vector<AttributeMultiVector<Dart>*> m_permutation; std::vector<AttributeMultiVector<Dart>*> m_permutation;
std::vector<AttributeMultiVector<Dart>*> m_permutation_inv; std::vector<AttributeMultiVector<Dart>*> m_permutation_inv;
......
...@@ -37,12 +37,15 @@ namespace CGoGN ...@@ -37,12 +37,15 @@ namespace CGoGN
*/ */
class EmbeddedGMap2 : public GMap2<MapMono> class EmbeddedGMap2 : public GMap2<MapMono>
{ {
EmbeddedGMap2(const EmbeddedGMap2& m):GMap2<MapMono>(m) {}
public: public:
typedef MapMono IMPL; typedef MapMono IMPL;
typedef GMap2<MapMono> TOPO_MAP; typedef GMap2<MapMono> TOPO_MAP;
static const unsigned int DIMENSION = TOPO_MAP::DIMENSION ; static const unsigned int DIMENSION = TOPO_MAP::DIMENSION ;
EmbeddedGMap2() {}
/** /**
* create a new face with managed embeddings * create a new face with managed embeddings
*/ */
......
...@@ -37,12 +37,15 @@ namespace CGoGN ...@@ -37,12 +37,15 @@ namespace CGoGN
*/ */
class EmbeddedGMap3 : public GMap3<MapMono> class EmbeddedGMap3 : public GMap3<MapMono>
{ {
EmbeddedGMap3(const EmbeddedGMap3& m):GMap3<MapMono>(m) {}
public: public:
typedef MapMono IMPL; typedef MapMono IMPL;
typedef GMap3<MapMono> TOPO_MAP; typedef GMap3<MapMono> TOPO_MAP;
static const unsigned int DIMENSION = TOPO_MAP::DIMENSION ; static const unsigned int DIMENSION = TOPO_MAP::DIMENSION ;
EmbeddedGMap3() {}
/*! /*!
* *
*/ */
......
...@@ -40,6 +40,9 @@ template <typename MAP_IMPL> ...@@ -40,6 +40,9 @@ template <typename MAP_IMPL>
class GMap0 : public MapCommon<MAP_IMPL> class GMap0 : public MapCommon<MAP_IMPL>
{