Commit ac3c8969 authored by Kenneth Vanhoey's avatar Kenneth Vanhoey

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

Conflicts:
	include/Algo/Decimation/decimation.hpp
	include/Algo/Import/import2tablesSurface.hpp
	include/Algo/Modelisation/subdivision.hpp
	include/Algo/Selection/collector.hpp
parents 968b9c54 193a7dae
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 ;
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;
}
#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");