bench_compact.cpp 4.19 KB
Newer Older
Sylvain Thery's avatar
Sylvain Thery committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
#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;

73 74
	std::vector<VertexAttribute<typename PFP::VEC3, MAP> > attr;
	attr.push_back(position);
Sylvain Thery's avatar
Sylvain Thery committed
75
	Algo::Surface::Decimation::decimate<PFP>(myMap, Algo::Surface::Decimation::S_QEM, Algo::Surface::Decimation::A_QEM, attr, nbVertices /20) ;
Sylvain Thery's avatar
Sylvain Thery committed
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130

	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;
}