better stats functions

This commit is contained in:
ccolin 2021-11-12 21:23:50 +01:00
parent edcffa34c3
commit 0e7e75d3f5
3 changed files with 37 additions and 85 deletions

View File

@ -128,20 +128,17 @@ void Courbures::set_fixed_colors() {
void Courbures::set_K_colors() { void Courbures::set_K_colors() {
MyStats<double> dist; auto prop = _mesh.property(vprop_K);
for (VertexHandle vh : _mesh.vertices()) { auto prop_data = prop.data_vector();
dist.push_back(_mesh.property(vprop_K, vh)); double avg = average(prop_data.begin(), prop_data.end());
} double stddev = standard_deviation
double m = dist.mean(); (prop_data.begin(), prop_data.end(), avg);
double sigma = dist.stdev(m); std::cout << "K mean : " << avg << " - sigma : " << stddev << std::endl;
std::cout << "K min : " << dist.min()
<< " - max : " << dist.max() << std::endl ;
std::cout << "K mean : " << m << " - sigma : " << sigma << std::endl;
for (VertexHandle vh : _mesh.vertices()) { for (VertexHandle vh : _mesh.vertices()) {
double tmp = _mesh.property(vprop_K, vh) - m; double tmp = _mesh.property(vprop_K, vh) - avg;
tmp = clamp<double>(tmp, -sigma, +sigma); tmp = clamp<double>(tmp, -stddev, +stddev);
tmp = (tmp + sigma) / (2 * sigma); tmp = (tmp + stddev) / (2 * stddev);
_mesh.set_color(vh, MyMesh::Color(tmp, .23, .5)); _mesh.set_color(vh, MyMesh::Color(tmp, .23, .5));
} }
} }

View File

@ -5,79 +5,6 @@
#include "quad_patch.h" #include "quad_patch.h"
template <typename T>
class MyStats {
private:
std::vector<T> _distrib ;
public:
MyStats () {} ;
void push_back (T data)
{
_distrib.push_back(data) ;
}
T min ()
{
T tmp = _distrib.at(0) ;
for (size_t i=1 ; i<_distrib.size(); i++)
{
if (_distrib.at(i) < tmp)
tmp = _distrib.at(i) ;
}
return tmp ;
}
T max ()
{
T tmp = _distrib.at(0) ;
for (size_t i=1 ; i<_distrib.size(); i++)
{
if (_distrib.at(i) > tmp)
tmp = _distrib.at(i) ;
}
return tmp ;
}
T mean ()
{
T acc(0) ;
std::cout << "acc : " << acc << std::endl;
if (_distrib.size() > 0)
{
for(size_t i=0; i<_distrib.size(); i++)
{
acc += _distrib.at(i) ;
}
return acc/(_distrib.size()) ;
}
else
return acc ;
}
T stdev ()
{
return stdev(mean());
}
T stdev (T m)
{
T acc(0), tmp ;
if (_distrib.size() > 0)
{
for(size_t i=0; i<_distrib.size(); i++)
{
tmp = _distrib.at(i) - m ;
acc += tmp * tmp ;
}
return sqrt(acc/(_distrib.size())) ;
}
else
return acc ;
}
};
class Courbures { class Courbures {
private: private:
MyMesh &_mesh ; MyMesh &_mesh ;

View File

@ -73,4 +73,32 @@ constexpr const T& clamp(const T& v, const T& lo, const T& hi) {
} }
template <typename ForwardIt>
constexpr typename ForwardIt::value_type average(const ForwardIt first,
const ForwardIt last) {
typedef typename ForwardIt::value_type value_type;
if (first == last) return 0;
value_type average = 0;
for (ForwardIt it = first; it != last; ++it) {
average += *it;
}
return average / (last - first);
}
template <typename ForwardIt>
constexpr typename ForwardIt::value_type
standard_deviation(const ForwardIt first,
const ForwardIt last,
typename ForwardIt::value_type average) {
typedef typename ForwardIt::value_type value_type;
if (first == last) return 0;
value_type accumulator = 0;
for (ForwardIt it = first; it != last; ++it) {
accumulator += (*it - average) * (*it - average);
}
return sqrt(accumulator / (last - first));
}
#endif #endif