bench_trav.cpp 4.64 KB
Newer Older
Sylvain Thery's avatar
benches  
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 73 74 75 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 131 132 133
/*******************************************************************************
* 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_IMPL> position = myMap.addAttribute<VEC3, VERTEX>("position");
	constexpr 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;
}