Commit 1f965877 authored by Sylvain Thery's avatar Sylvain Thery

Merge branch 'develop'

parents 8b8d8a8e d66a6841
#include "Topology/generic/parameters.h"
#include "Topology/map/embeddedMap2.h"
#include "Geometry/vector_gen.h"
#include "Algo/Import/import.h"
#include "Algo/Export/export.h"
#include "Algo/Geometry/boundingbox.h"
#include "Algo/Geometry/normal.h"
#include "Algo/Modelisation/subdivision.h"
#include "Algo/Decimation/decimation.h"
#include "Utils/chrono.h"
#include "Algo/Filtering/average.h"
using namespace CGoGN ;
struct PFP: public PFP_STANDARD
{
// definition of the map
typedef EmbeddedMap2 MAP ;
};
typedef PFP::MAP MAP ;
typedef PFP::VEC3 VEC3;
int main(int argc, char **argv)
{
if(argc != 2)
return 1;
MAP myMap;
std::vector<std::string> attrNames ;
if(!Algo::Surface::Import::importMesh<PFP>(myMap, argv[1], attrNames))
{
CGoGNerr << "could not import " << argv[1] << CGoGNendl ;
return 2;
}
VertexAttribute<PFP::VEC3, MAP> position = myMap.getAttribute<PFP::VEC3,VERTEX,MAP>( attrNames[0]) ;
FaceAttribute<VEC3, MAP> center = myMap.addAttribute<VEC3, FACE, MAP>("centerFace");
foreach_cell<FACE>(myMap, [&](Face f)
{
center[f] =Algo::Surface::Geometry::faceCentroid<PFP>(myMap,f,position);
});
EdgeAttribute<float, MAP> edge_att = myMap.addAttribute<float, EDGE, MAP>("pipoEdge");
foreach_cell<EDGE>(myMap, [&](Edge e)
{
edge_att[e] = position[e.dart][0];
});
Utils::Chrono chrono;
chrono.start();
Algo::Surface::Modelisation::LoopSubdivision<PFP>(myMap, position) ;
Algo::Surface::Modelisation::LoopSubdivision<PFP>(myMap, position) ;
Algo::Surface::Modelisation::LoopSubdivision<PFP>(myMap, position) ;
Algo::Surface::Modelisation::LoopSubdivision<PFP>(myMap, position) ;
unsigned int nbVertices = Algo::Topo::getNbOrbits<VERTEX>(myMap) ;
std::cout << "4 passes loop -> "<< std::endl;
std::cout << " NB Faces "<< Algo::Topo::getNbOrbits<FACE>(myMap) << std::endl;
std::cout << " NB Vertices "<< nbVertices << std::endl;
std::vector<VertexAttribute<typename PFP::VEC3, MAP> *> attr;
attr.push_back(&position);
Algo::Surface::Decimation::decimate<PFP>(myMap, Algo::Surface::Decimation::S_QEM, Algo::Surface::Decimation::A_QEM, attr, nbVertices * 0.05) ;
VertexAttribute<PFP::VEC3, MAP> normal = myMap.addAttribute<PFP::VEC3,VERTEX,MAP>( "normal") ;
VertexAttribute<PFP::VEC3, MAP> position2 = myMap.addAttribute<PFP::VEC3,VERTEX,MAP>( "pos2") ;
CGoGNout << "creating "<< chrono.elapsed() << " ms"<< CGoGNendl;
std::cout << "decimation 5% -> "<< std::endl;
std::cout << " NB Faces "<< Algo::Topo::getNbOrbits<FACE>(myMap) << std::endl;
std::cout << " NB Vertices "<< Algo::Topo::getNbOrbits<VERTEX>(myMap) << std::endl;
chrono.start();
for (int i=0; i < 100; ++i)
{
Geom::BoundingBox<PFP::VEC3> bb = Algo::Geometry::computeBoundingBox<PFP>(myMap, position) ;
Algo::Surface::Geometry::computeNormalVertices<PFP>(myMap, position, normal) ;
Algo::Surface::Filtering::filterAverageAttribute_OneRing<PFP,PFP::VEC3>(myMap,position,position2, Algo::Surface::Filtering::INSIDE);
myMap.swapAttributes(position,position2);
}
CGoGNout << "BenchTime process "<< chrono.elapsed() << " ms"<< CGoGNendl;
std::cout << "Topologie fragmentation: "<<myMap.fragmentation(DART)<< std::endl;
std::cout << "Vertex fragmentation: "<<myMap.fragmentation(VERTEX)<< std::endl;
std::cout << "Face fragmentation: "<<myMap.fragmentation(FACE)<< std::endl;
chrono.start();
myMap.compact();
std::cout << std::endl << "compacting in "<< chrono.elapsed() << " ms"<< std::endl << std::endl;
std::cout << "Topologie fragmentation: "<<myMap.fragmentation(DART)<< std::endl;
std::cout << "Vertex fragmentation: "<<myMap.fragmentation(VERTEX)<< std::endl;
std::cout << "Face fragmentation: "<<myMap.fragmentation(FACE)<< std::endl;
chrono.start();
for (int i=0; i < 100; ++i)
{
Geom::BoundingBox<PFP::VEC3> bb = Algo::Geometry::computeBoundingBox<PFP>(myMap, position) ;
Algo::Surface::Geometry::computeNormalVertices<PFP>(myMap, position, normal) ;
Algo::Surface::Filtering::filterAverageAttribute_OneRing<PFP,PFP::VEC3>(myMap,position,position2, Algo::Surface::Filtering::INSIDE);
myMap.swapAttributes(position,position2);
}
CGoGNout << "BenchTime after compact "<< chrono.elapsed() << " ms"<< CGoGNendl;
Algo::Surface::Export::exportOFF<PFP>(myMap,position,"bench_res.off");
return 0;
}
/*******************************************************************************
* CGoGN: Combinatorial and Geometric modeling with Generic N-dimensional Maps *
* version 0.1 *
* Copyright (C) 2009-2012, IGG Team, LSIIT, University of Strasbourg *
* *
* This library is free software; you can redistribute it and/or modify it *
* under the terms of the GNU Lesser General Public License as published by the *
* Free Software Foundation; either version 2.1 of the License, or (at your *
* option) any later version. *
* *
* This library is distributed in the hope that it will be useful, but WITHOUT *
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or *
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License *
* for more details. *
* *
* You should have received a copy of the GNU Lesser General Public License *
* along with this library; if not, write to the Free Software Foundation, *
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. *
* *
* Web site: http://cgogn.unistra.fr/ *
* Contact information: cgogn@unistra.fr *
* *
*******************************************************************************/
#include "Topology/generic/parameters.h"
#include "Topology/map/embeddedMap2.h"
#include "Algo/Tiling/Surface/square.h"
#include "Algo/Geometry/area.h"
#include "Algo/Modelisation/subdivision.h"
using namespace CGoGN ;
/**
* Struct that contains some informations about the types of the manipulated objects
* Mainly here to be used by the algorithms that are parameterized by it
*/
struct PFP2: public PFP_STANDARD
{
// definition of the type of the map
typedef EmbeddedMap2 MAP;
};
typedef PFP2::MAP MAP;
typedef PFP2::VEC3 VEC3;
int main()
{
// declare a map to handle the mesh
MAP myMap;
// add position attribute on vertices and get handler on it
VertexAttribute<VEC3, MAP> position = myMap.addAttribute<VEC3, VERTEX, MAP>("position");
Algo::Surface::Tilings::Square::Cube<PFP2> cube(myMap, 2, 2, 2);
cube.embedIntoCube(position, 10.0f, 10.0f, 10.0f);
// FaceAttribute<VEC3, MAP> color = myMap.addAttribute<VEC3, FACE, MAP>("colorFace");
// foreach_cell<FACE>(myMap, [&](Face f)
// {
// color[f] =(Algo::Surface::Geometry::faceCentroid<PFP2>(myMap,f,position)+ VEC3(5,5,5))/10.0f;
// });
CGoGNout.toStd(false);
CGoGNout.toFile("reuse_init.csv");
myMap.dumpCSV();
std::cout << "MAP dumped in reuse_init.csv"<< std::endl;
// mark central vertex of each face of the cube
CellMarker<MAP,VERTEX> cm(myMap);
foreach_cell<VERTEX>(myMap, [&](Vertex v)
{
int nb=0;
if (position[v][0] == 0.0f)
nb++;
if (position[v][1] == 0.0f)
nb++;
if (position[v][2] == 0.0f)
nb++;
if (nb == 2)
cm.mark(v);
});
// remove central vertex of each face of the cube
foreach_cell<VERTEX>(myMap, [&](Vertex v)
{
if (cm.isMarked(v))
myMap.deleteVertex(v);
});
// remove middle points of each edge of the cube
foreach_cell<EDGE>(myMap, [&](Edge e)
{
Vertex v(e.dart);
if (myMap.vertexDegree(v)==2)
myMap.uncutEdge(myMap.phi_1(v));
});
CGoGNout.toFile("reuse_before.csv");
myMap.dumpCSV();
std::cout << "MAP with holes dumped in reuse_before.csv"<< std::endl;
Algo::Surface::Modelisation::quadranguleFaces<PFP2>(myMap,position);
CGoGNout.toFile("reuse_after.csv");
myMap.dumpCSV();
std::cout << "after subdivide, MAP dumped in reuse_after.csv"<< std::endl;
myMap.saveMapBin("reused_map2.map");
return 0;
}
......@@ -26,6 +26,8 @@
#define CELLS_H_
#include "Topology/generic/dart.h"
//#include "Topology/generic/traversor/traversor2.h"
//#include "Topology/generic/traversor/traversor3.h"
namespace CGoGN
{
......@@ -58,6 +60,58 @@ public:
friend std::ostream& operator<<( std::ostream &out, const Cell<ORBIT>& fa ) { return out << fa.dart; }
inline bool valid() const { return !dart.isNil(); }
// template <unsigned int ORBIT_TO, typename MAP, typename FUNC>
// inline void foreach_incident(MAP& map, FUNC f)
// {
// switch (MAP::DIMENSION)
// {
// case 2 : foreach_incident2(map, f); break;
// case 3 : foreach_incident3(map, f); break;
// }
// }
// template <unsigned int ORBIT_TO, typename MAP, typename FUNC>
// inline void foreach_adjacent(MAP& map, FUNC f)
// {
// switch (MAP::DIMENSION)
// {
// case 2 : foreach_adjacent2(map, f); break;
// case 3 : foreach_adjacent3(map, f); break;
// }
// }
// template <unsigned int ORBIT_TO, typename MAP, typename FUNC>
// inline void foreach_incident2(MAP& map, FUNC f)
// {
// IncidentTrav2<MAP,ORBIT,ORBIT_TO> trav(const_cast<const MAP&>(map), *this);
// for (Cell<ORBIT_TO> c = trav.t.begin(), e = trav.t.end(); c.dart != e.dart; c = trav.t.next())
// f(c);
// }
// template <unsigned int THRU, typename MAP, typename FUNC>
// inline void foreach_adjacent2(MAP& map, FUNC f)
// {
// AdjacentTrav2<MAP,ORBIT,THRU> trav(const_cast<const MAP&>(map), *this);
// for (Cell<ORBIT> c = trav.t.begin(), e = trav.t.end(); c.dart != e.dart; c = trav.t.next())
// f(c);
// }
// template <unsigned int ORBIT_TO, typename MAP, typename FUNC>
// inline void foreach_incident3(MAP& map, FUNC f, bool forceDartMarker = false, unsigned int thread = 0)
// {
// Traversor3XY<MAP,ORBIT,ORBIT_TO> trav(const_cast<const MAP&>(map),*this,forceDartMarker,thread);
// for (Cell<ORBIT_TO> c = trav.begin(), e = trav.end(); c.dart != e.dart; c = trav.next())
// f(c);
// }
// template <unsigned int THRU, typename MAP, typename FUNC>
// inline void foreach_adjacent3(MAP& map, FUNC f, bool forceDartMarker = false, unsigned int thread = 0)
// {
// Traversor3XXaY<MAP,ORBIT,THRU> trav(const_cast<const MAP&>(map),*this,forceDartMarker,thread);
// for (Cell<ORBIT> c = trav.begin(), e = trav.end(); c.dart != e.dart; c = trav.next())
// f(c);
// }
};
typedef Cell<VERTEX> Vertex;
......
......@@ -26,7 +26,6 @@
#define __TRAVERSOR1_H__
#include "Topology/generic/dart.h"
#include "Topology/generic/traversor/traversorGen.h"
namespace CGoGN
{
......@@ -37,7 +36,7 @@ namespace CGoGN
// Traverse the edges incident to a given vertex
template <typename MAP>
class Traversor1VE: public Traversor
class Traversor1VE
{
private:
const MAP& m ;
......@@ -56,7 +55,7 @@ public:
// Traverse the vertices adjacent to a given vertex through sharing a common edge
template <typename MAP>
class Traversor1VVaE: public Traversor
class Traversor1VVaE
{
private:
const MAP& m ;
......@@ -79,7 +78,7 @@ public:
// Traverse the vertices incident to a given edge
template <typename MAP>
class Traversor1EV: public Traversor
class Traversor1EV
{
private:
const MAP& m ;
......@@ -98,7 +97,7 @@ public:
// Traverse the edges adjacent to a given edge through sharing a common vertex
template <typename MAP>
class Traversor1EEaV: public Traversor
class Traversor1EEaV
{
private:
const MAP& m ;
......
/*******************************************************************************
* CGoGN: Combinatorial and Geometric modeling with Generic N-dimensional Maps *
* version 0.1 *
* Copyright (C) 2009-2012, IGG Team, LSIIT, University of Strasbourg *
* *
* This library is free software; you can redistribute it and/or modify it *
* under the terms of the GNU Lesser General Public License as published by the *
* Free Software Foundation; either version 2.1 of the License, or (at your *
* option) any later version. *
* *
* This library is distributed in the hope that it will be useful, but WITHOUT *
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or *
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License *
* for more details. *
* *
* You should have received a copy of the GNU Lesser General Public License *
* along with this library; if not, write to the Free Software Foundation, *
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. *
* *
* Web site: http://cgogn.unistra.fr/ *
* Contact information: cgogn@unistra.fr *
* *
*******************************************************************************/
#ifndef __VTraversor1_VIRT_H__
#define __VTraversor1_VIRT_H__
#include "Topology/generic/dart.h"
#include "Topology/generic/traversor/traversorGen.h"
namespace CGoGN
{
/*******************************************************************************
VERTEX CENTERED TRAVERSALS
*******************************************************************************/
// Traverse the edges incident to a given vertex
template <typename MAP>
class VTraversor1VE : public Traversor
{
private:
const MAP& m ;
Dart start ;
Dart current ;
Dart d2 ;
public:
VTraversor1VE(const MAP& map, Dart dart) ;
Dart begin() ;
Dart end() ;
Dart next() ;
} ;
// Traverse the vertices adjacent to a given vertex through sharing a common edge
template <typename MAP>
class VTraversor1VVaE : public Traversor
{
private:
const MAP& m ;
Dart start ;
Dart current ;
Dart d2 ;
public:
VTraversor1VVaE(const MAP& map, Dart dart) ;
Dart begin() ;
Dart end() ;
Dart next() ;
} ;
/*******************************************************************************
EDGE CENTERED TRAVERSALS
*******************************************************************************/
// Traverse the vertices incident to a given edge
template <typename MAP>
class VTraversor1EV : public Traversor
{
private:
const MAP& m ;
Dart start ;
Dart current ;
Dart d2 ;
public:
VTraversor1EV(const MAP& map, Dart dart) ;
Dart begin() ;
Dart end() ;
Dart next() ;
} ;
// Traverse the edges adjacent to a given edge through sharing a common vertex
template <typename MAP>
class VTraversor1EEaV : public Traversor
{
private:
const MAP& m ;
Dart start ;
Dart current ;
Dart d2 ;
public:
VTraversor1EEaV(const MAP& map, Dart dart) ;
Dart begin() ;
Dart end() ;
Dart next() ;
} ;
} // namespace CGoGN
#include "Topology/generic/traversor/traversor1Virt.hpp"
#endif
/*******************************************************************************
* CGoGN: Combinatorial and Geometric modeling with Generic N-dimensional Maps *
* version 0.1 *
* Copyright (C) 2009-2012, IGG Team, LSIIT, University of Strasbourg *
* *
* This library is free software; you can redistribute it and/or modify it *
* under the terms of the GNU Lesser General Public License as published by the *
* Free Software Foundation; either version 2.1 of the License, or (at your *
* option) any later version. *
* *
* This library is distributed in the hope that it will be useful, but WITHOUT *
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or *
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License *
* for more details. *
* *
* You should have received a copy of the GNU Lesser General Public License *
* along with this library; if not, write to the Free Software Foundation, *
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. *
* *
* Web site: http://cgogn.unistra.fr/ *
* Contact information: cgogn@unistra.fr *
* *
*******************************************************************************/
namespace CGoGN
{
/*******************************************************************************
VERTEX CENTERED TRAVERSALS
*******************************************************************************/
// VTraversor1VE
template <typename MAP>
VTraversor1VE<MAP>::VTraversor1VE(const MAP& map, Dart dart) : m(map), start(dart)
{
d2 = m.phi_1(start) ;
if(d2 == start) // 1 edge loop case
d2 = NIL ;
}
template <typename MAP>
Dart VTraversor1VE<MAP>::begin()
{
current = start ;
return current ;
}
template <typename MAP>
Dart VTraversor1VE<MAP>::end()
{
return NIL ;
}
template <typename MAP>
Dart VTraversor1VE<MAP>::next()
{
if(current != NIL)
{
if(current == start)
current = d2 ;
else
current = NIL ;
}
return current ;
}
// VTraversor1VVaE
template <typename MAP>
VTraversor1VVaE<MAP>::VTraversor1VVaE(const MAP& map, Dart dart) : m(map)
{
start = m.phi_1(dart) ;
if(start == dart) // 1 edge loop case
start = NIL ;
else
{
d2 = m.phi1(dart) ;
if(d2 == start) // 2 edges loop case
d2 = NIL ;
}
}
template <typename MAP>
Dart VTraversor1VVaE<MAP>::begin()
{
current = start ;
return current ;
}
template <typename MAP>
Dart VTraversor1VVaE<MAP>::end()
{
return NIL ;
}
template <typename MAP>
Dart VTraversor1VVaE<MAP>::next()
{
if(current != NIL)
{
if(current == start)
current = d2 ;
else
current = NIL ;
}
return current ;
}
/*******************************************************************************
EDGE CENTERED TRAVERSALS
*******************************************************************************/
// VTraversor1EV
template <typename MAP>
VTraversor1EV<MAP>::VTraversor1EV(const MAP& map, Dart dart) : m(map), start(dart)
{
d2 = m.phi1(start) ;
if(d2 == start) // 1 edge loop case
d2 = NIL ;
}
template <typename MAP>
Dart VTraversor1EV<MAP>::begin()
{
current = start ;
return current ;
}
template <typename MAP>
Dart VTraversor1EV<MAP>::end()
{
return NIL ;
}
template <typename MAP>
Dart VTraversor1EV<MAP>::next()
{
if(current != NIL)
{
if(current == start)
current = d2 ;
else
current = NIL ;
}
return current ;
}
// VTraversor1EEaV
template <typename MAP>
VTraversor1EEaV<MAP>::VTraversor1EEaV(const MAP& map, Dart dart) : m(map)
{
start = m.phi_1(dart) ;
if(start == dart) // 1 edge loop case
start = NIL ;
else
{
d2 = m.phi1(dart) ;
if(d2 == start) // 2 edges loop case
d2 = NIL ;
}
}
template <typename MAP>
Dart VTraversor1EEaV<MAP>::begin()
{
current = start ;
return current ;
}
template <typename MAP>
Dart VTraversor1EEaV<MAP>::end()
{
return NIL ;
}
template <typename MAP>
Dart VTraversor1EEaV<MAP>::next()
{
if(current != NIL)
{
if(current == start)
current = d2 ;
else
current = NIL ;
}
return current ;
}
} // namespace CGoGN
......@@ -26,9 +26,7 @@
#define __TRAVERSOR2_H__
#include "Topology/generic/dart.h"
//#include "Topology/generic/traversorGen.h"
#include "Topology/generic/cells.h"
#include <functional>
namespace CGoGN
{
......@@ -39,7 +37,7 @@ namespace CGoGN
// Traverse the edges incident to a given vertex
template <typename MAP>
class Traversor2VE//: public Traversor<MAP>
class Traversor2VE
{
private:
const MAP& m ;
......@@ -57,7 +55,7 @@ public:
// Traverse the faces incident to a given vertex
template <typename MAP>
class Traversor2VF //: public Traversor<MAP>
class Traversor2VF
{
private:
const MAP& m ;
......@@ -75,7 +73,7 @@ public:
// Traverse the vertices adjacent to a given vertex through sharing a common edge
template <typename MAP>
class Traversor2VVaE //: public Traversor<MAP>
class Traversor2VVaE
{
private:
const MAP& m ;
......@@ -93,7 +91,7 @@ public:
// Traverse the vertices adjacent to a given vertex through sharing a common face
template <typename MAP>
class Traversor2VVaF //: public Traversor<MAP>
class Traversor2VVaF
{
private:
const MAP& m ;
......@@ -117,7 +115,7 @@ public:
// Traverse the vertices incident to a given edge
template <typename MAP>
class Traversor2EV //: public Traversor<MAP>
class Traversor2EV
{
private:
const MAP& m ;
......@@ -135,7 +133,7 @@ public: