Commit 7dbc432b authored by Sylvain Thery's avatar Sylvain Thery

histogram are back

parent 4b50f19b
cmake_minimum_required(VERSION 2.6)
project(testing_algo_booleanOperator)
add_executable( test_algo_booleanOperator
algo_booleanOperator.cpp
mergeVertices.cpp
)
target_link_libraries( test_algo_booleanOperator
${CGoGN_LIBS} ${CGoGN_EXT_LIBS})
#include <iostream>
extern int test_mergeVertices();
int main()
{
test_mergeVertices();
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 *
* *
*******************************************************************************/
#ifndef __ALGO_BOOLEANOPERATOR_VERTICES_H__
#define __ALGO_BOOLEANOPERATOR_VERTICES_H__
#include "Geometry/basic.h"
#include "Geometry/inclusion.h"
#include "Geometry/orientation.h"
namespace CGoGN
{
#include "Topology/generic/parameters.h"
#include "Topology/map/embeddedMap2.h"
#include "Topology/gmap/embeddedGMap2.h"
namespace Algo
{
namespace Surface
{
#include "Algo/BooleanOperator/mergeVertices.h"
using namespace CGoGN;
namespace BooleanOperator
struct PFP1 : public PFP_STANDARD
{
typedef EmbeddedMap2 MAP;
};
template <typename PFP>
bool isBetween(typename PFP::MAP& map, const VertexAttribute<typename PFP::VEC3, typename PFP::MAP>& positions, Dart d, Dart e, Dart f) ;
template bool Algo::Surface::BooleanOperator::isBetween<PFP1>(PFP1::MAP& map, const VertexAttribute<PFP1::VEC3, PFP1::MAP>& positions, Dart d, Dart e, Dart f);
template void Algo::Surface::BooleanOperator::mergeVertex<PFP1>(PFP1::MAP& map, VertexAttribute<PFP1::VEC3, PFP1::MAP>& positions, Dart d, Dart e);
template void Algo::Surface::BooleanOperator::mergeVertices<PFP1>(PFP1::MAP& map, VertexAttribute<PFP1::VEC3, PFP1::MAP>& positions);
template <typename PFP>
void mergeVertex(typename PFP::MAP& map, VertexAttribute<typename PFP::VEC3, typename PFP::MAP>& positions, Dart d, Dart e);
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
template <typename PFP>
void mergeVertices(typename PFP::MAP& map, VertexAttribute<typename PFP::VEC3, typename PFP::MAP>& positions);
struct PFP2 : public PFP_DOUBLE
{
typedef EmbeddedMap2 MAP;
};
}
template bool Algo::Surface::BooleanOperator::isBetween<PFP2>(PFP2::MAP& map, const VertexAttribute<PFP2::VEC3, PFP2::MAP>& positions, Dart d, Dart e, Dart f);
template void Algo::Surface::BooleanOperator::mergeVertex<PFP2>(PFP2::MAP& map, VertexAttribute<PFP2::VEC3, PFP2::MAP>& positions, Dart d, Dart e);
template void Algo::Surface::BooleanOperator::mergeVertices<PFP2>(PFP2::MAP& map, VertexAttribute<PFP2::VEC3, PFP2::MAP>& positions);
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
}
struct PFP3 : public PFP_STANDARD
{
typedef EmbeddedGMap2 MAP;
};
}
template bool Algo::Surface::BooleanOperator::isBetween<PFP3>(PFP3::MAP& map, const VertexAttribute<PFP3::VEC3, PFP3::MAP>& positions, Dart d, Dart e, Dart f);
template void Algo::Surface::BooleanOperator::mergeVertex<PFP3>(PFP3::MAP& map, VertexAttribute<PFP3::VEC3, PFP3::MAP>& positions, Dart d, Dart e);
template void Algo::Surface::BooleanOperator::mergeVertices<PFP3>(PFP3::MAP& map, VertexAttribute<PFP3::VEC3, PFP3::MAP>& positions);
#include "mergeVertices.hpp"
#endif
int test_mergeVertices()
{
return 0;
}
\ No newline at end of file
......@@ -2,12 +2,12 @@ cmake_minimum_required(VERSION 2.6)
project(testing_algo)
#add_subdirectory(BooleanOperator)
add_subdirectory(BooleanOperator)
add_subdirectory(Decimation)
add_subdirectory(Export)
add_subdirectory(Filtering)
add_subdirectory(Geometry)
#add_subdirectory(Histogram)
add_subdirectory(Histogram)
#add_subdirectory(ImplicitHierarchicalMesh)
add_subdirectory(Import)
add_subdirectory(LinearSolving)
......
cmake_minimum_required(VERSION 2.6)
project(testing_algo_histogram)
add_executable( test_algo_histogram
algo_histogram.cpp
histogram.cpp
)
target_link_libraries( test_algo_histogram
${CGoGN_LIBS} ${CGoGN_EXT_LIBS})
#include <iostream>
extern int test_histogram();
int main()
{
test_histogram();
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/embeddedMap2.h"
#include "Topology/gmap/embeddedGMap2.h"
#ifndef __HISTOGRAM__
#define __HISTOGRAM__
#include <cmath>
#include "Algo/Histogram/histogram.h"
#include "Topology/generic/attributeHandler.h"
#include "Topology/generic/cellmarker.h"
#include "Geometry/vector_gen.h"
#include "Utils/colorMaps.h"
#include "Utils/vbo_base.h"
using namespace CGoGN;
#ifdef WIN32
#ifndef CGoGN_ALGO_API
#if defined CGoGN_ALGO_DLL_EXPORT
#define CGoGN_ALGO_API __declspec(dllexport)
#else
#define CGoGN_ALGO_API __declspec(dllimport)
#endif
#endif
#else
#define CGoGN_ALGO_API
#endif
namespace CGoGN
{
namespace Algo
{
namespace Histogram
struct PFP1 : public PFP_STANDARD
{
class CGoGN_ALGO_API HistoColorMap
{
protected:
double m_min;
double m_max;
double m_w;
unsigned int m_nb;
public:
virtual ~HistoColorMap() {}
/// set min value (for update from Histogram)
void setMin(double m) {m_min = m; m_w = (m_max -m_min)/double(m_nb);}
/// set max value (for update from Histogram)
void setMax(double m) {m_max = m; m_w = (m_max -m_min)/double(m_nb);}
/// set nb value (for update from Histogram)
void setNb(unsigned int n) {m_nb = n; m_w = (m_max -m_min)/double(m_nb);}
/**
* get color from param: To implement (with call to colormap functions for examples)
*/
virtual Geom::Vec3f color(double v) const = 0 ;
/**
* get color from index (can be overload)
* compute a [0,1[ value from an index [0,nb[
* and call color with it
* Used by Histogram::colorize && Qt::DrawHistogram
*/
virtual Geom::Vec3f colorIndex(unsigned int i) const
{
double v = double(i)/double(m_nb-1) + double(1)/double(m_nb+m_nb);
return color(v);
}
typedef EmbeddedMap2 MAP;
};
typedef VertexAttribute<double, PFP1::MAP> VA1;
typedef VertexAttribute<Geom::Vec3f, PFP1::MAP> VAC1;
typedef CellMarker<PFP1::MAP, VERTEX> CM1;
/**
* inherits this class by:
* - add xxAttribute& in data (& constructor)
* - overload begin/end/next/nbElements (by calling xxxAttribute.yyy)
* - overload operator [] to return the [i] converted in double with necessary computations.
*/
class AttributeConvertGen
{
public:
virtual unsigned int begin() const = 0;
virtual unsigned int end() const = 0;
virtual void next(unsigned int& i) const = 0;
virtual unsigned int nbElements() const = 0;
virtual double operator[](unsigned int i) const = 0;
virtual ~AttributeConvertGen() {}
};
template void Algo::Histogram::Histogram::initData<VA1>(const VA1& attr);
template void Algo::Histogram::Histogram::histoColorize<VAC1>(VAC1& colors);
template void Algo::Histogram::Histogram::quantilesColorize<VAC1>(VAC1& colors, const std::vector<Geom::Vec3f>& tc);
template unsigned int Algo::Histogram::Histogram::markCellsOfHistogramColumn<CM1>(unsigned int c, CM1& cm) const;
template unsigned int Algo::Histogram::Histogram::markCellsOfQuantilesColumn<CM1>(unsigned int c, CM1& cm) const;
/**
* Helper class templated by Attribute
* Avoid the writing of begin/end/next/nbElements
*/
template <typename ATT>
class AttributeConvert: public AttributeConvertGen
{
protected:
ATT& attrib;
public:
AttributeConvert(ATT &att): attrib(att) {}
virtual unsigned int begin() const { return attrib.begin();}
virtual unsigned int end() const { return attrib.end();}
virtual void next(unsigned int& i) const { attrib.next(i);}
virtual unsigned int nbElements() const { return attrib.nbElements();}
virtual double operator[](unsigned int i) const = 0;
virtual ~AttributeConvert() {}
};
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/**
* Histogram class
* T must have operators -, / ,< ,>
*/
class CGoGN_ALGO_API Histogram
struct PFP2 : public PFP_STANDARD
{
// std::vector<double> m_data;
mutable std::vector< std::pair<double, unsigned int> > m_dataIdx;
/// number of classes in attribute
unsigned int m_nbclasses;
/// vector of population
std::vector<unsigned int> m_populations;
/// vector of intervals of quantiles
std::vector<double> m_interv;
/// vector of population for quantiles
std::vector<double> m_pop_quantiles;
/// min value
double m_min;
/// max value
double m_max;
/// interval width (in regular case)
double m_interWidth;
/// max number of population in a class
unsigned int m_nbMin;
/// max values in histo population
unsigned int m_maxBar;
/// max value in quantille population
double m_maxQBar;
HistoColorMap& m_hcolmap;
mutable bool m_sorted;
/// get data
double data(unsigned int i) const;
/// get idx of data in attribute
unsigned int idx(unsigned int i) const;
/// comparison function for sorting data
static bool dataComp( const std::pair<double, unsigned int>& a, const std::pair<double, unsigned int>& b);
/// update quantiles height from histo area for correct superposition
void quantilesAreaCorrection();
public:
/**
* create an histogram from attribute handler
*/
Histogram(HistoColorMap& hcm);
/**
* init data
* @param conv a attribute convertor
*/
void initDataConvert(const AttributeConvertGen& conv);
/**
* init data
* @param attr the attribute to copy from
* @param sortForQuantiles sort data vector for quantille generation
*/
template <typename ATTR>
void initData(const ATTR& attr);
/**
* get min value of attribute (perhaps modified by user)
*/
inline double getMin() const;
/**
* get max value of attribute (perhaps modified by user)
*/
inline double getMax() const;
/**
* get real min value of attribute
*/
inline double getQMin() const;
/**
* get real max value of attribute
*/
inline double getQMax() const;
/**
* set min value of attribute
*/
void setMin(double m);
/**
* set max value of attribute
*/
void setMax(double m);
/**
* get max population value of all bars of histo
*/
unsigned int getMaxBar() const;
/**
* get max population value of all bars of quantiles
*/
double getMaxQBar() const;
/**
* modify min/max values to center Histogram on zero if necessary
*/
void centerOnZero();
/**
* compute the histogram with given numbre of classes
*/
void populateHisto(unsigned int nbclasses = 0);
/**
* compute the histogram with given number of classes
*/
void populateQuantiles(unsigned int nbclasses = 10);
/**
* which class belong a value
*/
unsigned int whichClass(double val) const;
/**
* which class belong a value
*/
unsigned int whichQuantille(double val) const;
/**
* fill a color attribute from histo
* @param colors attribute to fill
*/
template <typename ATTC>
void histoColorize(ATTC& colors);
/**
* colorize the VBO (RGB) from histo
* @warning GL context must be accessible
* @param vbo the vbo to fill with colors
*/
void histoColorizeVBO(Utils::VBO& vbo);
/**
* fill a color attribute from quantiles
* @param colors attribute to fill
* @param tc table of color
*/
template<typename ATTC>
void quantilesColorize(ATTC& colors, const std::vector<Geom::Vec3f>& tc);
/**
* colorize the VBO (RGB) from
* @warning GL context must be accessible
* @param vbo the vbo to fill with colors
* @param tc table of color
*/
void quantilesColorizeVBO(Utils::VBO& vbo, const std::vector<Geom::Vec3f>& tc);
/**
* get the vector of class population
*/
const std::vector<unsigned int>& getPopulation() const;
/**
* get the vector of height of quantiles
*/
const std::vector<double>& getQuantilesHeights() const;
/**
* get the vector of intervals bounaries for quantiles
*/
const std::vector<double>& getQuantilesIntervals() const;
/**
* return cells of histogram's column
* @param c column of histogram
* @param vc vector of cells (indices)
* @return number of cells
*/
unsigned int cellsOfHistogramColumn(unsigned int c, std::vector<unsigned int>& vc) const;
/**
* return cells of quantile's column
* @param c column of quantile
* @param vc vector of cells (indices)
* @return number of cells
*/
unsigned int cellsOfQuantilesColumn(unsigned int c, std::vector<unsigned int>& vc) const;
/**
* mark cells of histogram's column
* @param c column of quantile
* @param cm marker
* @return number of marked cells
*/
template <typename CELLMARKER>
unsigned int markCellsOfHistogramColumn(unsigned int c, CELLMARKER& cm) const;
typedef EmbeddedMap2 MAP;
};
typedef VertexAttribute<double, PFP2::MAP> VA2;
typedef VertexAttribute<Geom::Vec3f, PFP2::MAP> VAC2;
typedef CellMarker<PFP2::MAP, VERTEX> CM2;
/**
* mark cells of quantile's column
* @param c column of quantile
* @param cm marker
* @return number of marked cells
*/
template <typename CELLMARKER>
unsigned int markCellsOfQuantilesColumn(unsigned int c, CELLMARKER& cm) const;
template void Algo::Histogram::Histogram::initData<VA2>(const VA2& attr);
template void Algo::Histogram::Histogram::histoColorize<VAC2>(VAC2& colors);
template void Algo::Histogram::Histogram::quantilesColorize<VAC2>(VAC2& colors, const std::vector<Geom::Vec3f>& tc);
template unsigned int Algo::Histogram::Histogram::markCellsOfHistogramColumn<CM2>(unsigned int c, CM2& cm) const;
template unsigned int Algo::Histogram::Histogram::markCellsOfQuantilesColumn<CM2>(unsigned int c, CM2& cm) const;
/**
* get the colorMap
*/
const HistoColorMap& colorMap() const;
};
} // namespace Histogram
} // namespace Algo
} // namespace CGoGN
int test_histogram()
{
#include "Algo/Histogram/histogram.hpp"
#endif
return 0;
}
\ No newline at end of file
///*******************************************************************************
//* 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 *
//* *
//*******************************************************************************/
//
//#ifndef __QT_HISTO_DRAW__
//#define __QT_HISTO_DRAW__
//
//
//#include <QWidget>
//#include <QPainter>
//#include <QMouseEvent>
//
//#include "Utils/Qt/qtpopup.h"
//#include "Algo/Histogram/histogram.h"
//
//#ifdef WIN32
//#if defined CGoGN_QT_DLL_EXPORT
//#define CGoGN_UTILS_API __declspec(dllexport)
//#else
//#define CGoGN_UTILS_API __declspec(dllimport)
//#endif
//#endif
//
//namespace CGoGN
//{
//
//namespace Utils
//{
//
//namespace QT
//{
//
//
//class CGoGN_UTILS_API RenderHistogram : public QWidget
//{
// Q_OBJECT
//
// static const int m_frameWidth = 10;
//
//
// const Algo::Histogram::Histogram& m_histo;
// std::vector<Geom::Vec3f> m_qcolors;
//
// unsigned int m_max;
// int m_h;
// int m_w;