Commit 8b8d8a8e authored by Sylvain Thery's avatar Sylvain Thery

Merge branch 'develop'

parents 825a10ea 56f2be8c
cmake_minimum_required(VERSION 2.8)
project(examples)
SET(CMAKE_BUILD_TYPE Release)
#SET(CMAKE_BUILD_TYPE Debug)
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DNOTOPOWARNING")
# define includes path
include_directories(
${CMAKE_CURRENT_BINARY_DIR}
${CGoGN_ROOT_DIR}/include
${CGoGN_EXT_INCLUDES}
)
# define libs path
IF(WIN32)
link_directories( ${CGoGN_ROOT_DIR}/lib/$(ConfigurationName) ${Boost_LIBRARY_DIRS} )
ELSE(WIN32)
link_directories( ${CGoGN_ROOT_DIR}/lib/Release )
ENDIF(WIN32)
add_executable(bench_trav bench_trav.cpp )
target_link_libraries( bench_trav ${CGoGN_LIBS_R} ${CGoGN_EXT_LIBS} )
add_executable(bench_remesh bench_remesh.cpp )
target_link_libraries( bench_remesh ${CGoGN_LIBS_R} ${CGoGN_EXT_LIBS} )
add_executable(bench_compact bench_compact.cpp )
target_link_libraries( bench_compact ${CGoGN_LIBS_R} ${CGoGN_EXT_LIBS} )
#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 ;
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]) ;
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) ;
unsigned int nbVertices = Algo::Topo::getNbOrbits<VERTEX>(myMap) ;
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.1) ;
Algo::Surface::Modelisation::LoopSubdivision<PFP>(myMap, position) ;
Algo::Surface::Modelisation::LoopSubdivision<PFP>(myMap, position) ;
nbVertices = Algo::Topo::getNbOrbits<VERTEX>(myMap) ;
Algo::Surface::Decimation::decimate<PFP>(myMap, Algo::Surface::Decimation::S_QEM, Algo::Surface::Decimation::A_QEM, attr, nbVertices * 0.1) ;
Algo::Surface::Modelisation::LoopSubdivision<PFP>(myMap, position) ;
Algo::Surface::Modelisation::LoopSubdivision<PFP>(myMap, position) ;
nbVertices = Algo::Topo::getNbOrbits<VERTEX>(myMap) ;
Algo::Surface::Decimation::decimate<PFP>(myMap, Algo::Surface::Decimation::S_QEM, Algo::Surface::Decimation::A_QEM, attr, nbVertices * 0.1) ;
Algo::Surface::Modelisation::CatmullClarkSubdivision<PFP>(myMap, position) ;
Algo::Surface::Modelisation::CatmullClarkSubdivision<PFP>(myMap, position) ;
CGoGNout << "BenchTime dynamic "<< 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/embeddedMap3.h"
#include "Algo/Tiling/Volume/cubic.h"
#include "Algo/Geometry/area.h"
#include "Algo/Geometry/volume.h"
#include "Utils/chrono.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 PFP: public PFP_STANDARD
{
// definition of the type of the map
typedef EmbeddedMap3 MAP;
typedef double REAL;
typedef Geom::Vector<3,REAL> VEC3;
};
typedef PFP::MAP MAP;
typedef PFP::MAP::IMPL MAP_IMPL;
typedef PFP::VEC3 VEC3;
int main()
{
// declare a map to handle the mesh
MAP myMap;
Utils::Chrono ch;
ch.start();
// add position attribute on vertices and get handler on it
VertexAttribute<VEC3, MAP> position = myMap.addAttribute<VEC3, VERTEX, MAP>("position");
const int nb = 100;
Algo::Volume::Tilings::Cubic::Grid<PFP> cubic(myMap, nb, nb, nb);
cubic.embedIntoGrid(position, 10.0f, 10.0f, 10.0f);
std::cout<< "construct grid in " << ch.elapsed()<< " ms"<< std::endl;
ch.start();
VEC3 centerMesh(0,0,0);
int nbVols=0;
foreach_cell<VOLUME>(myMap, [&](Vol w) // foreach volume
{
VEC3 centerVol(0,0,0);
int nbFaces=0;
foreach_incident3<FACE>(myMap, w, [&](Face f) // foreach face of each volume
{
VEC3 centerFace(0,0,0);
int nbVert=0;
foreach_incident3<VERTEX>(myMap, f, [&](Vertex v) // foreach vertex of each face of each volume
{
centerFace += position[v];
nbVert++;
});
centerFace /=nbVert;
centerVol += centerFace;
});
centerVol /= nbFaces;
centerMesh += centerVol;
});
centerMesh /= nbVols;
CGoGNout<< "Traverse with foreach in " << ch.elapsed()<< " ms"<< CGoGNendl;
ch.start();
centerMesh=VEC3(0,0,0);
nbVols=0;
TraversorW<MAP> tw(myMap); // alias for Traversor<MAP,VERTEX>
for (Dart dw=tw.begin(); dw!=tw.end(); dw=tw.next())
{
VEC3 centerVol(0,0,0);
int nbFaces=0;
Traversor3WF<MAP> trwf(myMap, dw);
for (Dart df = trwf.begin(); df != trwf.end(); df = trwf.next())
{
VEC3 centerFace(0,0,0);
int nbVert=0;
Traversor3FV<MAP> trfv(myMap, df);
for (Dart dv = trfv.begin(); dv != trfv.end(); dv = trfv.next())
{
centerFace += position[dv];
nbVert++;
}
centerFace /=nbVert;
centerVol += centerFace;
}
centerVol /= nbFaces;
centerMesh += centerVol;
}
CGoGNout<< "Traverse with traversor in " << ch.elapsed()<< " ms"<< CGoGNendl;
ch.start();
PFP::REAL vol = Algo::Geometry::totalVolume<PFP>(myMap, position);
CGoGNout<< "Parallel volume:" << ch.elapsed()<< " ms val="<<vol<< CGoGNendl;
vol = 0;
foreach_cell<VOLUME>(myMap, [&](Vol w) // foreach volume
{
vol += Algo::Geometry::convexPolyhedronVolume<PFP>(myMap, w, position) ;
});
CGoGNout<< "Linear volume:" << ch.elapsed()<< " ms val="<<vol<< CGoGNendl;
return 0;
}
......@@ -33,7 +33,9 @@ IF (WITH_QT)
ENDIF (NOT DONOT_COMPILE_SANDBOX)
ENDIF (WITH_QT)
add_subdirectory(Examples/Tests)
add_subdirectory(Tests)
add_subdirectory(Benches)
add_subdirectory(Tuto/Traversals)
add_subdirectory(Tuto/Attributes)
......
......@@ -798,7 +798,7 @@ void Clipping::importMesh(std::string& filename)
return;
}
else
position = myMap.getAttribute<VEC3, VERTEX>("position") ;
position = myMap.getAttribute<VEC3, VERTEX ,MAP>("position") ;
}
else
{
......@@ -808,10 +808,9 @@ void Clipping::importMesh(std::string& filename)
return ;
}
else
position = myMap.getAttribute<PFP::VEC3,VERTEX>(attrNames[0]) ;
position = myMap.getAttribute<VEC3, VERTEX, MAP>(attrNames[0]) ;
}
updateVBOprimitives(Algo::Render::GL2::TRIANGLES | Algo::Render::GL2::LINES | Algo::Render::GL2::POINTS) ;
m_render_topo->updateData(myMap, position, m_coeffTopoExplod[0], m_coeffTopoExplod[1], m_coeffTopoExplod[2]);
......@@ -1114,7 +1113,7 @@ int main(int argc, char** argv)
}
else
{
sqt.position = sqt.myMap.addAttribute<PFP::VEC3, VERTEX>("position");
sqt.position = sqt.myMap.addAttribute<VEC3, VERTEX, MAP>("position");
Algo::Volume::Tilings::Cubic::Grid<PFP> cubic(sqt.myMap, 10,10,10);
cubic.embedIntoGrid(sqt.position, 1.0f, 1.0f, 1.0f);
......
......@@ -71,7 +71,6 @@ struct PFP: public PFP_STANDARD
};
typedef PFP::MAP MAP;
typedef PFP::MAP::IMPL MAP_IMPL;
typedef PFP::VEC3 VEC3;
class Clipping: public Utils::QT::SimpleQT
......@@ -81,7 +80,7 @@ class Clipping: public Utils::QT::SimpleQT
public:
//Manip Carte
MAP myMap ;
VertexAttribute<VEC3, MAP_IMPL> position;
VertexAttribute<VEC3, MAP> position;
Dart dglobal;
//Render
......
......@@ -128,13 +128,12 @@ struct PFP: public PFP_STANDARD
};
typedef PFP::MAP MAP ;
typedef PFP::MAP::IMPL MAP_IMPL ;
typedef PFP::VEC3 VEC3 ;
// declaration of the map
MAP myMap;
// and attribute of position
VertexAttribute<VEC3, MAP_IMPL> position;
VertexAttribute<VEC3, MAP> position;
unsigned int nb_ears;
......@@ -245,7 +244,7 @@ void MyQT::cb_keyPress(int code)
int main(int argc, char **argv)
{
position = myMap.addAttribute<VEC3, VERTEX>("position");
position = myMap.addAttribute<VEC3, VERTEX, MAP>("position");
Dart d0 = myMap.newFace(12);
position[d0] = PFP::VEC3(0, 20, 0);
......
......@@ -53,7 +53,6 @@ struct PFP: public PFP_STANDARD
};
typedef PFP::MAP MAP ;
typedef PFP::MAP::IMPL MAP_IMPL ;
typedef PFP::VEC3 VEC3 ;
MAP myMap;
......@@ -104,7 +103,7 @@ int main(int argc, char **argv)
QApplication app(argc, argv);
MyQT sqt;
VertexAttribute<VEC3, MAP_IMPL> position = myMap.addAttribute<VEC3, VERTEX>("position") ;
VertexAttribute<VEC3, MAP> position = myMap.addAttribute<VEC3, VERTEX, MAP>("position") ;
// define the face extruded (here a cross)
std::vector<PFP::VEC3> objV;
......@@ -134,7 +133,7 @@ int main(int argc, char **argv)
}
// extrusion
Algo::Surface::Modelisation::extrusion_scale<PFP>(myMap, position, objV, PFP::VEC3(0.0,0.0,0.0), PFP::VEC3(0.0,1.0,0.0),true, pathV, false, pathRadius);
Algo::Surface::Modelisation::extrusion_scale<PFP>(myMap, position, objV, PFP::VEC3(0.0,0.0,0.0), PFP::VEC3(0.0,1.0,0.0), true, pathV, false, pathRadius);
// bounding box
Geom::BoundingBox<PFP::VEC3> bb = Algo::Geometry::computeBoundingBox<PFP>(myMap, position);
......
......@@ -138,9 +138,9 @@ void MCMesh::MC()
SAlgo::MC::WindowingGreater<DATATYPE> myWindFunc;
myWindFunc.setIsoValue(DATATYPE(127));
position = myMap.getAttribute<VEC3, VERTEX>("position");
position = myMap.getAttribute<VEC3, VERTEX, MAP>("position");
if (!position.isValid())
position = myMap.addAttribute<VEC3, VERTEX>("position");
position = myMap.addAttribute<VEC3, VERTEX, MAP>("position");
// instanciation du mc
SAlgo::MC::MarchingCube<DATATYPE, SAlgo::MC::WindowingGreater,PFP> mc(myImgFr, &myMap, position, myWindFunc, false);
......
......@@ -54,7 +54,6 @@ struct PFP: public PFP_STANDARD
};
typedef PFP::MAP MAP ;
typedef PFP::MAP::IMPL MAP_IMPL ;
typedef PFP::VEC3 VEC3 ;
typedef unsigned char DATATYPE;
......@@ -75,7 +74,7 @@ public:
bool m_drawEdges ;
bool m_drawFaces ;
VertexAttribute<VEC3, MAP_IMPL> position ;
VertexAttribute<VEC3, MAP> position ;
Algo::Render::GL2::MapRender* m_render ;
......
......@@ -30,7 +30,7 @@
SimpleGMap2::SimpleGMap2()
{
position = myMap.addAttribute<VEC3, VERTEX>("position");
position = myMap.addAttribute<VEC3, VERTEX, MAP>("position");
Dart d = Algo::Surface::Modelisation::createTetrahedron<PFP>(myMap);
position[d] = VEC3(0,0,0);
......@@ -62,7 +62,7 @@ void SimpleGMap2::cb_initGL()
{
Utils::GLSLShader::setCurrentOGLVersion(1) ;
Geom::BoundingBox<PFP::VEC3> bb = Algo::Geometry::computeBoundingBox<PFP>(myMap, position) ;
Geom::BoundingBox<VEC3> bb = Algo::Geometry::computeBoundingBox<PFP>(myMap, position) ;
VEC3 gPosObj = bb.center() ;
float tailleX = bb.size(0) ;
float tailleY = bb.size(1) ;
......
......@@ -42,7 +42,6 @@ struct PFP: public PFP_STANDARD
};
typedef PFP::MAP MAP ;
typedef PFP::MAP::IMPL MAP_IMPL ;
typedef PFP::VEC3 VEC3 ;
class SimpleGMap2 : public Utils::QT::SimpleQT
......@@ -52,7 +51,7 @@ class SimpleGMap2 : public Utils::QT::SimpleQT
public:
MAP myMap ;
VertexAttribute<VEC3, MAP_IMPL> position ;
VertexAttribute<VEC3, MAP> position ;
SimpleGMap2() ;
......@@ -61,4 +60,3 @@ public:
void cb_initGL() ;
void cb_redraw() ;
};
......@@ -30,8 +30,8 @@
SimpleGMap3::SimpleGMap3()
{
position = myMap.addAttribute<VEC3, VERTEX>("position");
volume = myMap.addAttribute<VEC3, VOLUME>("volume");
position = myMap.addAttribute<VEC3, VERTEX, MAP>("position");
volume = myMap.addAttribute<VEC3, VOLUME, MAP>("volume");
// CellMarker<EDGE> mE(myMap);
......
......@@ -43,7 +43,6 @@ struct PFP: public PFP_STANDARD
};
typedef PFP::MAP MAP ;
typedef PFP::MAP::IMPL MAP_IMPL ;
typedef PFP::VEC3 VEC3 ;
class SimpleGMap3 : public Utils::QT::SimpleQT
......@@ -53,8 +52,8 @@ class SimpleGMap3 : public Utils::QT::SimpleQT
public:
MAP myMap ;
VertexAttribute<VEC3, MAP_IMPL> position ;
VolumeAttribute<VEC3, MAP_IMPL> volume ;
VertexAttribute<VEC3, MAP> position ;
VolumeAttribute<VEC3, MAP> volume ;
Algo::Render::GL2::Topo3Render<PFP>* m_render_topo;
......
......@@ -30,63 +30,62 @@
SimpleMap3::SimpleMap3()
{
position = myMap.addAttribute<VEC3, VERTEX>("position");
position = myMap.addAttribute<VEC3, VERTEX, MAP>("position");
Algo::Volume::Tilings::Cubic::Grid<PFP> cubic(myMap, 1, 1, 1);
cubic.embedIntoGrid(position, 1.0f, 1.0f, 1.0f);
myMap.check();
Algo::Volume::Tilings::Cubic::Grid<PFP> cubic(myMap, 1, 1, 1);
cubic.embedIntoGrid(position, 1.0f, 1.0f, 1.0f);
myMap.check();
// Dart dp = Algo::Surface::Modelisation::createQuadrangularPyramid<PFP>(myMap);
// Dart dp = Algo::Surface::Modelisation::createQuadrangularPyramid<PFP>(myMap);
// position[dp] = typename PFP::VEC3(0.5,0.5,-0.5);
// position[myMap.phi1(dp)] = typename PFP::VEC3(0.5,0.5,0.5);
// position[myMap.phi1(myMap.phi1(dp))] = typename PFP::VEC3(0.5,-0.5,0.5);
// position[myMap.phi_1(dp)] = typename PFP::VEC3(0.5,-0.5,-0.5);
// position[myMap.phi_1(myMap.phi2(dp))] = typename PFP::VEC3(1.5f, 0.0f, 0.0f);
// position[dp] = typename PFP::VEC3(0.5,0.5,-0.5);
// position[myMap.phi1(dp)] = typename PFP::VEC3(0.5,0.5,0.5);
// position[myMap.phi1(myMap.phi1(dp))] = typename PFP::VEC3(0.5,-0.5,0.5);
// position[myMap.phi_1(dp)] = typename PFP::VEC3(0.5,-0.5,-0.5);
// position[myMap.phi_1(myMap.phi2(dp))] = typename PFP::VEC3(1.5f, 0.0f, 0.0f);
// Dart dtemp = myMap.phi_1(myMap.phi2(myMap.phi_1(myMap.phi_1(myMap.phi2(d)))));
// Dart dtemp = myMap.phi_1(myMap.phi2(myMap.phi_1(myMap.phi_1(myMap.phi2(d)))));
// myMap.sewVolumes(dtemp,dp);
// myMap.sewVolumes(dtemp,dp);
// Algo::Volume::Tilings::Cubic::Grid<PFP> cubic(myMap, 2, 1, 1);
// cubic.embedIntoGrid(position, 1.0f, 1.0f, 1.0f);
// myMap.check();
// Algo::Volume::Tilings::Cubic::Grid<PFP> cubic(myMap, 2, 1, 1);
// cubic.embedIntoGrid(position, 1.0f, 1.0f, 1.0f);
// myMap.check();
// unsigned int nb=0;
// for(unsigned int i = position.begin(); i!=position.end(); position.next(i))
// nb++;
// unsigned int nb=0;
// for(unsigned int i = position.begin(); i!=position.end(); position.next(i))
// nb++;
// std::cout << "Nb vertices (equals 12) : " << nb << std::endl;
// assert(nb==12);
// std::cout << "Nb vertices (equals 12) : " << nb << std::endl;
// assert(nb==12);
// d = myMap.phi2(myMap.phi1(myMap.phi1(myMap.phi2(d))));
// d = myMap.phi2(myMap.phi1(myMap.phi1(myMap.phi2(d))));
// Dart dd = myMap.phi3(d);
// Dart dd = myMap.phi3(d);
// myMap.unsewVolumes(d);
// myMap.unsewVolumes(d);
// myMap.check();
// myMap.check();
// nb=0;
// for(unsigned int i = position.begin(); i!=position.end(); position.next(i))
// nb++;
// nb=0;
// for(unsigned int i = position.begin(); i!=position.end(); position.next(i))
// nb++;
// std::cout << "Nb vertices after unsew (equals 16) : " << nb << std::endl;
// assert(nb==16);
// std::cout << "Nb vertices after unsew (equals 16) : " << nb << std::endl;
// assert(nb==16);
// myMap.sewVolumes(d,dd);
// myMap.sewVolumes(d,dd);
// myMap.check();
// myMap.check();
// nb=0;
// for(unsigned int i = position.begin(); i!=position.end(); position.next(i))
// nb++;
// nb=0;
// for(unsigned int i = position.begin(); i!=position.end(); position.next(i))
// nb++;
// std::cout << "Nb vertices after resew (equals 12) : " << nb << std::endl;
// assert(nb==12);
// std::cout << "Nb vertices after resew (equals 12) : " << nb << std::endl;
// assert(nb==12);
}
......@@ -117,46 +116,46 @@ void SimpleMap3::cb_initGL()
m_render_topo_boundary->updateDataBoundary(myMap, position, 0.9f,0.9f,bb.maxSize()/50.0f);
m_render_topo_primal = new Algo::Render::GL2::Topo3PrimalRender<PFP>();
m_render_topo_primal->setDartWidth(2.0f);
m_render_topo_primal->setInitialDartsColor(1.0f,1.0f,1.0f);
m_render_topo_primal->setDartWidth(2.0f);
m_render_topo_primal->setInitialDartsColor(1.0f,1.0f,1.0f);
m_render_topo_primal->updateData(myMap, position, 0.95f,0.85f);
}
void SimpleMap3::cb_keyPress(int code)
{
switch(code)
{
case 'e':
{
time_t rawtime;
struct tm * timeinfo;
char buffer[80];
time (&rawtime);
timeinfo = localtime (&rawtime);
strftime (buffer,80,".%F.%H:%M:%S",timeinfo);
std::string filename = std::string("topo_screenshot") + std::string(buffer) + std::string(".svg");
m_render_topo->svgout2D(filename, modelViewMatrix(), projectionMatrix());