stats.h 4.29 KB
Newer Older
Pierre Kraemer's avatar
Pierre Kraemer committed
1 2 3
/*******************************************************************************
* CGoGN: Combinatorial and Geometric modeling with Generic N-dimensional Maps  *
* version 0.1                                                                  *
4
* Copyright (C) 2009-2012, IGG Team, LSIIT, University of Strasbourg           *
Pierre Kraemer's avatar
Pierre Kraemer committed
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
*                                                                              *
* 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.           *
*                                                                              *
20
* Web site: http://cgogn.unistra.fr/                                           *
Pierre Kraemer's avatar
Pierre Kraemer committed
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
* Contact information: cgogn@unistra.fr                                        *
*                                                                              *
*******************************************************************************/

#ifndef STATS_H
#define STATS_H

namespace CGoGN
{

namespace Algo
{

namespace Geometry
{

template <typename PFP>
38
void statModele(typename PFP::MAP& map, const VertexAttribute<typename PFP::VEC3, typename PFP::MAP>& position)
Pierre Kraemer's avatar
Pierre Kraemer committed
39 40 41 42
{
	int nbFaces = 0;
	int nbVertex = 0;

Pierre Kraemer's avatar
Pierre Kraemer committed
43
	CellMarker<typename PFP::MAP, VERTEX> mVertex(map);
Pierre Kraemer's avatar
Pierre Kraemer committed
44 45 46 47 48 49

	float ratioMinMax = 0;
	int nbEdgePerVertex = 0;
	float lengthSeg = 0;
	int nbEdge = 0;

50 51
	TraversorF<typename PFP::MAP> tf(map) ;
	for(Dart d = tf.begin(); d != tf.end(); tf.next(d))
Pierre Kraemer's avatar
Pierre Kraemer committed
52
	{
53 54 55 56 57 58 59
		nbFaces++;
		bool init = true;
		float min = 0;
		float max = 0;

		Traversor2FV<typename PFP::MAP> tfe(map, d) ;
		for(Dart it = tfe.begin(); it != tfe.end(); it = tfe.next())
Pierre Kraemer's avatar
Pierre Kraemer committed
60
		{
61
			typename PFP::VEC3 segment = position[it] - position[map.phi1(it)] ;
Pierre Kraemer's avatar
Pierre Kraemer committed
62

63
			float len = segment.norm() ;
Pierre Kraemer's avatar
Pierre Kraemer committed
64

65 66
			lengthSeg += len;
			nbEdge++;
Pierre Kraemer's avatar
Pierre Kraemer committed
67

68 69 70 71
			if (init || len < min)
				min = len;
			if (init || len > max)
				max = len;
Pierre Kraemer's avatar
Pierre Kraemer committed
72

73
			init = false;
Pierre Kraemer's avatar
Pierre Kraemer committed
74

75
			if (!mVertex.isMarked(it))
Pierre Kraemer's avatar
Pierre Kraemer committed
76
			{
77 78 79 80 81
				mVertex.mark(it) ;
				nbVertex++ ;
				Traversor2VE<typename PFP::MAP> tve(map, it) ;
				for(Dart it2 = tve.begin(); it2 != tve.end(); it2 = tve.next())
					nbEdgePerVertex++ ;
Pierre Kraemer's avatar
Pierre Kraemer committed
82 83
			}
		}
84 85

		ratioMinMax += (min / max);
Pierre Kraemer's avatar
Pierre Kraemer committed
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
//	for (Dart d = map.begin(); d != map.end(); map.next(d))
//	{
//		if (!mFace.isMarked(d))
//		{
//			nbFaces++;
//			bool init = true;
//			float min = 0;
//			float max = 0;
//			Dart e = d;
//			do
//			{
//				mFace.mark(e);
//				typename PFP::VEC3 segment = position[e] - position[map.phi1(e)] ;
//
//				float len = segment.norm() ;
//
//				lengthSeg += len;
//				nbEdge++;
//
//				if (init || len < min)
//					min = len;
//				if (init || len > max)
//					max = len;
//
//				init = false;
//				e = map.phi1(e);
//			}
//			while (e != d);
//
//			ratioMinMax += (min / max);
//		}
//
//		if (!mVertex.isMarked(d))
//		{
//			mVertex.mark(d) ;
//			nbVertex++ ;
//			Dart e = d;
//			do
//			{
//				nbEdgePerVertex++ ;
128
//				e = map.phi2_1(e) ;
129 130 131 132 133
//			}
//			while (e != d) ;
//		}
//	}

134 135 136 137
	CGoGNout << "number of faces                : " << nbFaces << CGoGNendl;
	CGoGNout << "number of vertices             : " << nbVertex << CGoGNendl;
	CGoGNout << "mean ratio min max             : " << (ratioMinMax / (float) nbFaces) << CGoGNendl;
	CGoGNout << "mean number of edge per vertex : " << ((float) nbEdgePerVertex / (float) nbVertex) << CGoGNendl;
138
	CGoGNout << "mean edge length               : " << lengthSeg / (float) nbEdge << CGoGNendl;
Pierre Kraemer's avatar
Pierre Kraemer committed
139 140 141
}

} // namespace Geometry
142

Pierre Kraemer's avatar
Pierre Kraemer committed
143
} // namespace Algo
144

Pierre Kraemer's avatar
Pierre Kraemer committed
145 146
} // namespace CGoGN

147
#endif