Commit b50afe03 authored by Sylvain Thery's avatar Sylvain Thery

bugfix in copyFrom & copy constructors of maps in protected

parent 7d922fb0
...@@ -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;
} }
...@@ -50,19 +50,20 @@ typedef PFP::MAP MAP ; ...@@ -50,19 +50,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 +71,30 @@ int main(int argc, char **argv) ...@@ -70,13 +71,30 @@ 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;
} }
...@@ -273,7 +273,7 @@ public: ...@@ -273,7 +273,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 +290,7 @@ public: ...@@ -290,7 +290,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
......
...@@ -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
*/ */
......
...@@ -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
*/ */
......
...@@ -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>
{ {
protected: protected:
// protected copy constructor to prevent the copy of map
GMap0(const GMap0<MAP_IMPL>& m):MapCommon<MAP_IMPL>(m) {}
void init() ; void init() ;
public: public:
......
...@@ -37,6 +37,9 @@ template <typename MAP_IMPL> ...@@ -37,6 +37,9 @@ template <typename MAP_IMPL>
class GMap1 : public GMap0<MAP_IMPL> class GMap1 : public GMap0<MAP_IMPL>
{ {
protected: protected:
// protected copy constructor to prevent the copy of map
GMap1(const GMap1<MAP_IMPL>& m):GMap0<MAP_IMPL>(m) {}
void init() ; void init() ;
public: public:
......
...@@ -37,6 +37,9 @@ template <typename MAP_IMPL> ...@@ -37,6 +37,9 @@ template <typename MAP_IMPL>
class GMap2 : public GMap1<MAP_IMPL> class GMap2 : public GMap1<MAP_IMPL>
{ {
protected: protected:
// protected copy constructor to prevent the copy of map
GMap2(const GMap2<MAP_IMPL>& m):GMap1<MAP_IMPL>(m) {}
void init() ; void init() ;
public: public:
......
...@@ -37,6 +37,9 @@ template <typename MAP_IMPL> ...@@ -37,6 +37,9 @@ template <typename MAP_IMPL>
class GMap3 : public GMap2<MAP_IMPL> class GMap3 : public GMap2<MAP_IMPL>
{ {
protected: protected:
// protected copy constructor to prevent the copy of map
GMap3(const GMap3<MAP_IMPL>& m):GMap2<MAP_IMPL>(m) {}
void init() ; void init() ;
public: public:
......
...@@ -37,12 +37,16 @@ namespace CGoGN ...@@ -37,12 +37,16 @@ namespace CGoGN
*/ */
class EmbeddedMap2 : public Map2<MapMono> class EmbeddedMap2 : public Map2<MapMono>
{ {
EmbeddedMap2(const EmbeddedMap2& m):Map2<MapMono>(m) {}
public: public:
typedef MapMono IMPL; typedef MapMono IMPL;
typedef Map2<MapMono> TOPO_MAP; typedef Map2<MapMono> TOPO_MAP;
static const unsigned int DIMENSION = TOPO_MAP::DIMENSION ; static const unsigned int DIMENSION = TOPO_MAP::DIMENSION ;
EmbeddedMap2() {}
/* /*
*/ */
Dart newPolyLine(unsigned int nbEdges) ; Dart newPolyLine(unsigned int nbEdges) ;
......
...@@ -35,12 +35,16 @@ namespace CGoGN ...@@ -35,12 +35,16 @@ namespace CGoGN
*/ */
class EmbeddedMap3 : public Map3<MapMono> class EmbeddedMap3 : public Map3<MapMono>
{ {
EmbeddedMap3(const EmbeddedMap3& m):Map3<MapMono>(m) {}
public: public:
typedef MapMono IMPL; typedef MapMono IMPL;
typedef Map3 TOPO_MAP; typedef Map3 TOPO_MAP;
static const unsigned int DIMENSION = TOPO_MAP::DIMENSION ; static const unsigned int DIMENSION = TOPO_MAP::DIMENSION ;
EmbeddedMap3() {}
//! //!
/*! /*!
* *
......
...@@ -44,6 +44,9 @@ template <typename MAP_IMPL> ...@@ -44,6 +44,9 @@ template <typename MAP_IMPL>
class Map1 : public MapCommon<MAP_IMPL> class Map1 : public MapCommon<MAP_IMPL>
{ {
protected: protected:
// protected copy constructor to prevent the copy of map
Map1(const Map1<MAP_IMPL>& m):MapCommon<MAP_IMPL>(m) {}
void init() ; void init() ;
public: public:
......
...@@ -49,6 +49,9 @@ template <typename MAP_IMPL> ...@@ -49,6 +49,9 @@ template <typename MAP_IMPL>
class Map2 : public Map1<MAP_IMPL> class Map2 : public Map1<MAP_IMPL>
{ {
protected: protected:
// protected copy constructor to prevent the copy of map
Map2(const Map2<MAP_IMPL>& m):Map1<MAP_IMPL>(m) {}
void init() ; void init() ;
public: public:
......
...@@ -51,6 +51,9 @@ template <typename MAP_IMPL> ...@@ -51,6 +51,9 @@ template <typename MAP_IMPL>
class Map3 : public Map2<MAP_IMPL> class Map3 : public Map2<MAP_IMPL>
{ {
protected: protected:
// protected copy constructor to prevent the copy of map
Map3(const Map3<MAP_IMPL>& m):Map2<MAP_IMPL>(m) {}
void init() ; void init() ;
public: public:
......
...@@ -83,7 +83,7 @@ unsigned int AttributeContainer::getAttributeIndex(const std::string& attribName ...@@ -83,7 +83,7 @@ unsigned int AttributeContainer::getAttributeIndex(const std::string& attribName
return index - 1 ; 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(index < m_tableAttribs.size() || !"getAttributeName: attribute index out of bounds");
assert(m_tableAttribs[index] != NULL || !"getAttributeName: attribute does not exist"); assert(m_tableAttribs[index] != NULL || !"getAttributeName: attribute does not exist");
...@@ -102,7 +102,7 @@ unsigned int AttributeContainer::getAttributeBlocksPointers(unsigned int attrInd ...@@ -102,7 +102,7 @@ unsigned int AttributeContainer::getAttributeBlocksPointers(unsigned int attrInd
return atm->getBlocksPointers(vect_ptr, byteBlockSize); 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.clear() ;
names.reserve(m_nbAttributes) ; names.reserve(m_nbAttributes) ;
...@@ -752,7 +752,6 @@ bool AttributeContainer::loadBin(CGoGNistream& fs) ...@@ -752,7 +752,6 @@ bool AttributeContainer::loadBin(CGoGNistream& fs)
{ {
RegisteredBaseAttribute* ra = itAtt->second; RegisteredBaseAttribute* ra = itAtt->second;
AttributeMultiVectorGen* amvg = ra->addAttribute(*this, nameAtt); AttributeMultiVectorGen* amvg = ra->addAttribute(*this, nameAtt);
// CGoGNout << "loading attribute " << nameAtt << " : " << typeAtt << CGoGNendl;
amvg->loadBin(fs); amvg->loadBin(fs);
} }
} }
...@@ -790,6 +789,12 @@ void AttributeContainer::copyFrom(const AttributeContainer& cont) ...@@ -790,6 +789,12 @@ void AttributeContainer::copyFrom(const AttributeContainer& cont)
for (unsigned int i = 0; i < sz; ++i) for (unsigned int i = 0; i < sz; ++i)
m_holesBlocks[i] = new HoleBlockRef(*(cont.m_holesBlocks[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 // blocks with free
sz = cont.m_tableBlocksWithFree.size(); sz = cont.m_tableBlocksWithFree.size();
m_tableBlocksWithFree.resize(sz); m_tableBlocksWithFree.resize(sz);
...@@ -809,17 +814,24 @@ void AttributeContainer::copyFrom(const AttributeContainer& cont) ...@@ -809,17 +814,24 @@ void AttributeContainer::copyFrom(const AttributeContainer& cont)
{ {
if (cont.m_tableAttribs[i] != NULL) if (cont.m_tableAttribs[i] != NULL)
{ {
AttributeMultiVectorGen* ptr = cont.m_tableAttribs[i]->new_obj(); std::string sub = cont.m_tableAttribs[i]->getName().substr(0, 5);
ptr->setName(cont.m_tableAttribs[i]->getName()); if (sub != "Mark_") // Mark leaved by
ptr->setOrbit(cont.m_tableAttribs[i]->getOrbit()); {
ptr->setIndex(m_tableAttribs.size()); AttributeMultiVectorGen* ptr = cont.m_tableAttribs[i]->new_obj();
ptr->setNbBlocks(cont.m_tableAttribs[i]->getNbBlocks()); ptr->setName(cont.m_tableAttribs[i]->getName());
ptr->copy(cont.m_tableAttribs[i]); ptr->setOrbit(cont.m_tableAttribs[i]->getOrbit());
// if (cont.m_tableAttribs[i]->toProcess()) ptr->setIndex(m_tableAttribs.size());
// ptr->toggleProcess(); ptr->setNbBlocks(cont.m_tableAttribs[i]->getNbBlocks());
// else ptr->copy(cont.m_tableAttribs[i]);
// ptr->toggleNoProcess(); m_tableAttribs.push_back(ptr);
m_tableAttribs.push_back(ptr); }
else
{
// Mark always the first !
AttributeMultiVectorGen* ptr = m_tableAttribs[i];
ptr->setNbBlocks(cont.m_tableAttribs[i]->getNbBlocks());
ptr->copy(cont.m_tableAttribs[i]);
}
} }
} }
} }
......
...@@ -405,13 +405,13 @@ void GenericMap::restore_shortcuts() ...@@ -405,13 +405,13 @@ void GenericMap::restore_shortcuts()
{ // clear all marks expect boundary marks { // clear all marks expect boundary marks
Mark m(m_boundaryMarkers[0] + m_boundaryMarkers[1]); Mark m(m_boundaryMarkers[0] + m_boundaryMarkers[1]);
m.invert(); m.invert();
for (unsigned int i = cont.begin(); i != cont.end(); cont.next(i)) for (unsigned int k = cont.begin(); k != cont.end(); cont.next(k))
amvMark->operator[](i).unsetMark(m); amvMark->operator[](k).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 k = cont.begin(); k != cont.end(); cont.next(k))
amvMark->operator[](i).clear(); amvMark->operator[](k).clear();
} }
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment