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
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()
{
// declare a map to handle the mesh
......@@ -149,6 +74,5 @@ int main()
position[myMap.phi<11>(f2.dart)] = VEC3(0, -2, 0);
position[myMap.phi_1(f2.dart)] = VEC3(2, -2, 0);
return 0;
}
......@@ -33,6 +33,7 @@
#include "Algo/Export/export.h"
#include "Algo/Modelisation/subdivision.h"
#include "Algo/Geometry/normal.h"
using namespace CGoGN ;
......@@ -50,19 +51,20 @@ typedef PFP::MAP MAP ;
typedef PFP::MAP::IMPL MAP_IMPL ;
typedef PFP::VEC3 VEC3 ;
void pipo(PFP::MAP& m)
{
std::cout << m.getNbDarts()<< std::endl;
}
int main(int argc, char **argv)
{
if(argc != 3)
{
CGoGNout << "Usage : " << argv[0] << " filename nbSteps" << CGoGNendl;
return 0;
CGoGNerr << "Usage : " << argv[0] << " filename nbSteps" << CGoGNendl;
return 1;
}
std::string filename(argv[1]);
unsigned int nbSteps;
std::istringstream iss(argv[2]);
iss >> nbSteps;
unsigned int nbSteps = atoi(argv[2]);
// declaration of the map
MAP myMap;
......@@ -70,13 +72,32 @@ int main(int argc, char **argv)
std::vector<std::string> 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]);
// 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)
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;
}
......@@ -58,7 +58,8 @@ void computeCurvatureVertices_QuadraticFitting(
VertexAttribute<typename PFP::REAL, typename PFP::MAP::IMPL>& kmax,
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>& Kmin) ;
VertexAttribute<typename PFP::VEC3, typename PFP::MAP::IMPL>& Kmin,
unsigned int thread = 0) ;
template <typename PFP>
void computeCurvatureVertex_QuadraticFitting(
......
......@@ -138,7 +138,8 @@ public:
~AttributeContainer();
unsigned int getOrbit();
unsigned int getOrbit() const;
void setOrbit(unsigned int orbit);
void setRegistry(std::map<std::string, RegisteredBaseAttribute*>* re);
......@@ -273,7 +274,7 @@ public:
/**
* 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
......@@ -290,7 +291,7 @@ public:
* @param names vector of names
* @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
......@@ -364,7 +365,7 @@ public:
* @param index index 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
......@@ -473,6 +474,14 @@ public:
*/
void copyFrom(const AttributeContainer& cont);
/**
* dump the container in CSV format (; separated columns)
*/
void dumpCSV() const;
void dumpByLines() const;
};
} // namespace CGoGN
......
......@@ -30,7 +30,7 @@
namespace CGoGN
{
inline unsigned int AttributeContainer::getOrbit()
inline unsigned int AttributeContainer::getOrbit() const
{
return m_orbit ;
}
......@@ -332,7 +332,7 @@ inline bool AttributeContainer::unrefLine(unsigned int index)
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 j = index % _BLOCKSIZE_;
......
......@@ -176,6 +176,12 @@ public:
virtual bool loadBin(CGoGNistream& fs) = 0;
static bool skipLoadBin(CGoGNistream& fs);
/**
* lecture binaire
* @param fs filestream
*/
virtual void dump(unsigned int i) const = 0;
};
......@@ -266,17 +272,17 @@ public:
* 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 *
......@@ -294,6 +300,13 @@ public:
* @param fs filestream
*/
bool loadBin(CGoGNistream& fs);
/**
* lecture binaire
* @param fs filestream
*/
virtual void dump(unsigned int i) const;
};
} // namespace CGoGN
......
......@@ -407,4 +407,11 @@ inline bool AttributeMultiVectorGen::skipLoadBin(CGoGNistream& fs)
return true;
}
template <typename T>
void AttributeMultiVector<T>::dump(unsigned int i) const
{
CGoGNout << this->operator[](i);
}
} // namespace CGoGN
......@@ -48,6 +48,13 @@ public:
static std::string CGoGNnameOfType() { return ""; }
};
template <typename T>
std::ostream& operator<<(std::ostream& out, const NoTypeNameAttribute<T>&)
{
out << "no_output" ;
return out ;
}
} // namespace CGoGN
#endif /* FAKEATTRIBUTE_H_ */
......@@ -87,6 +87,9 @@ class GenericMap
template<typename MAP, unsigned int CELL> friend class CellMarkerBase ;
protected:
// protected copy constructor to prevent the copy of map
GenericMap(const GenericMap& ) {}
/**
* Attributes Containers
*/
......@@ -124,7 +127,7 @@ protected:
*/
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
......@@ -358,7 +361,7 @@ public:
* return allowed threads
* @return the number of threads (including principal)
*/
unsigned int getNbThreadMarkers() ;
unsigned int getNbThreadMarkers() const;
/**
* Remove some added threads
......@@ -411,6 +414,11 @@ public:
* compact the map
*/
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)
{
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
for(unsigned int orbit = 0; orbit < NB_ORBITS; ++orbit)
......@@ -61,7 +61,7 @@ inline void GenericMap::deleteDartLine(unsigned int index)
{
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)
}
}
......
......@@ -36,6 +36,12 @@ class MapCommon : public MAP_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 *
****************************************/
......@@ -127,7 +133,10 @@ public:
/****************************************
* BOUNDARY MANAGEMENT *
****************************************/
protected:
/**
* mark a dart as belonging to boundary
*/
......
......@@ -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
{
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
}
}
......
......@@ -42,6 +42,9 @@ public:
inline virtual void clear(bool removeAttrib);
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_permutation;
std::vector<AttributeMultiVector<Dart>*> m_permutation_inv;
......
......@@ -44,6 +44,9 @@ public:
inline virtual void clear(bool removeAttrib);
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_permutation;
std::vector<AttributeMultiVector<Dart>*> m_permutation_inv;
......
......@@ -37,12 +37,15 @@ namespace CGoGN
*/
class EmbeddedGMap2 : public GMap2<MapMono>
{
EmbeddedGMap2(const EmbeddedGMap2& m):GMap2<MapMono>(m) {}
public:
typedef MapMono IMPL;
typedef GMap2<MapMono> TOPO_MAP;
static const unsigned int DIMENSION = TOPO_MAP::DIMENSION ;
EmbeddedGMap2() {}
/**
* create a new face with managed embeddings
*/
......
......@@ -37,12 +37,15 @@ namespace CGoGN
*/
class EmbeddedGMap3 : public GMap3<MapMono>
{
EmbeddedGMap3(const EmbeddedGMap3& m):GMap3<MapMono>(m) {}
public:
typedef MapMono IMPL;
typedef GMap3<MapMono> TOPO_MAP;
static const unsigned int DIMENSION = TOPO_MAP::DIMENSION ;
EmbeddedGMap3() {}
/*!
*
*/
......
......@@ -40,6 +40,9 @@ template <typename MAP_IMPL>
class GMap0 : public MapCommon<MAP_IMPL>
{
protected:
// protected copy constructor to prevent the copy of map
GMap0(const GMap0<MAP_IMPL>& m):MapCommon<MAP_IMPL>(m) {}
void init() ;
public:
......
......@@ -37,6 +37,9 @@ template <typename MAP_IMPL>
class GMap1 : public GMap0<MAP_IMPL>
{
protected:
// protected copy constructor to prevent the copy of map
GMap1(const GMap1<MAP_IMPL>& m):GMap0<MAP_IMPL>(m) {}
void init() ;
public:
......
......@@ -37,6 +37,9 @@ template <typename MAP_IMPL>
class GMap2 : public GMap1<MAP_IMPL>
{
protected:
// protected copy constructor to prevent the copy of map
GMap2(const GMap2<MAP_IMPL>& m):GMap1<MAP_IMPL>(m) {}
void init() ;
public:
......
......@@ -37,6 +37,9 @@ template <typename MAP_IMPL>
class GMap3 : public GMap2<MAP_IMPL>
{
protected:
// protected copy constructor to prevent the copy of map
GMap3(const GMap3<MAP_IMPL>& m):GMap2<MAP_IMPL>(m) {}
void init() ;
public:
......
......@@ -37,12 +37,16 @@ namespace CGoGN
*/
class EmbeddedMap2 : public Map2<MapMono>
{
EmbeddedMap2(const EmbeddedMap2& m):Map2<MapMono>(m) {}
public:
typedef MapMono IMPL;
typedef Map2<MapMono> TOPO_MAP;
static const unsigned int DIMENSION = TOPO_MAP::DIMENSION ;
EmbeddedMap2() {}
/*
*/
Dart newPolyLine(unsigned int nbEdges) ;
......
......@@ -35,12 +35,16 @@ namespace CGoGN
*/
class EmbeddedMap3 : public Map3<MapMono>
{
EmbeddedMap3(const EmbeddedMap3& m):Map3<MapMono>(m) {}
public:
typedef MapMono IMPL;
typedef Map3 TOPO_MAP;
static const unsigned int DIMENSION = TOPO_MAP::DIMENSION ;
EmbeddedMap3() {}
//!
/*!
*
......
......@@ -44,6 +44,9 @@ template <typename MAP_IMPL>
class Map1 : public MapCommon<MAP_IMPL>
{
protected:
// protected copy constructor to prevent the copy of map
Map1(const Map1<MAP_IMPL>& m):MapCommon<MAP_IMPL>(m) {}
void init() ;
public:
......
......@@ -49,6 +49,9 @@ template <typename MAP_IMPL>
class Map2 : public Map1<MAP_IMPL>
{
protected:
// protected copy constructor to prevent the copy of map
Map2(const Map2<MAP_IMPL>& m):Map1<MAP_IMPL>(m) {}
void init() ;
public:
......
......@@ -51,6 +51,9 @@ template <typename MAP_IMPL>
class Map3 : public Map2<MAP_IMPL>
{
protected:
// protected copy constructor to prevent the copy of map
Map3(const Map3<MAP_IMPL>& m):Map2<MAP_IMPL>(m) {}
void init() ;
public:
......
......@@ -30,6 +30,7 @@
#include <iostream>
#include "Container/attributeContainer.h"
#include "Topology/generic/dart.h"
namespace CGoGN
{
......@@ -83,7 +84,7 @@ unsigned int AttributeContainer::getAttributeIndex(const std::string& attribName
return index - 1 ;
}
const std::string& AttributeContainer::getAttributeName(unsigned int index)
const std::string& AttributeContainer::getAttributeName(unsigned int index) const
{
assert(index < m_tableAttribs.size() || !"getAttributeName: attribute index out of bounds");
assert(m_tableAttribs[index] != NULL || !"getAttributeName: attribute does not exist");
......@@ -102,7 +103,7 @@ unsigned int AttributeContainer::getAttributeBlocksPointers(unsigned int attrInd
return atm->getBlocksPointers(vect_ptr, byteBlockSize);
}
unsigned int AttributeContainer::getAttributesNames(std::vector<std::string>& names)
unsigned int AttributeContainer::getAttributesNames(std::vector<std::string>& names) const
{
names.clear() ;
names.reserve(m_nbAttributes) ;
......@@ -752,7 +753,6 @@ bool AttributeContainer::loadBin(CGoGNistream& fs)
{
RegisteredBaseAttribute* ra = itAtt->second;
AttributeMultiVectorGen* amvg = ra->addAttribute(*this, nameAtt);
// CGoGNout << "loading attribute " << nameAtt << " : " << typeAtt << CGoGNendl;
amvg->loadBin(fs);
}
}
......@@ -790,6 +790,12 @@ void AttributeContainer::copyFrom(const AttributeContainer& cont)
for (unsigned int i = 0; i < sz; ++i)
m_holesBlocks[i] = new HoleBlockRef(*(cont.m_holesBlocks[i]));
// free indices
sz = cont.m_freeIndices.size();
m_freeIndices.resize(sz);
for (unsigned int i = 0; i < sz; ++i)
m_freeIndices[i] = cont.m_freeIndices[i];
// blocks with free
sz = cont.m_tableBlocksWithFree.size();
m_tableBlocksWithFree.resize(sz);
......@@ -808,6 +814,9 @@ void AttributeContainer::copyFrom(const AttributeContainer& cont)
for (unsigned int i = 0; i < sz; ++i)
{
if (cont.m_tableAttribs[i] != NULL)
{
std::string sub = cont.m_tableAttribs[i]->getName().substr(0, 5);
if (sub != "Mark_") // Mark leaved by
{
AttributeMultiVectorGen* ptr = cont.m_tableAttribs[i]->new_obj();
ptr->setName(cont.m_tableAttribs[i]->getName());
......@@ -815,13 +824,92 @@ void AttributeContainer::copyFrom(const AttributeContainer& cont)
ptr->setIndex(m_tableAttribs.size());
ptr->setNbBlocks(cont.m_tableAttribs[i]->getNbBlocks());
ptr->copy(cont.m_tableAttribs[i]);
// if (cont.m_tableAttribs[i]->toProcess())
// ptr->toggleProcess();
// else
// ptr->toggleNoProcess();
m_tableAttribs.push_back(ptr);
}
else
{