Commit cb799b17 authored by Lionel Untereiner's avatar Lionel Untereiner

Merge cgogn:~thery/CGoGN

parents 0f47b2ad 96ca248e
......@@ -322,6 +322,12 @@ void computeCentroidELWVolumes(typename PFP::MAP& map,
const VertexAttribute<typename PFP::VEC3>& position, VolumeAttribute<typename PFP::VEC3>& vol_centroid,
unsigned int nbth = 0) ;
template <typename PFP, typename EMBV, typename EMB>
void computeCentroidELWVolumesGen(typename PFP::MAP& map,
const EMBV& position, VolumeAttribute<typename PFP::VEC3>& vol_centroid,
unsigned int nbth = 0) ;
template <typename PFP>
void computeNeighborhoodCentroidVertices(typename PFP::MAP& map,
......
......@@ -347,6 +347,35 @@ void computeCentroidELWVolumes(typename PFP::MAP& map,
}
template <typename PFP, typename EMBV, typename EMB>
class FunctorComputeCentroidELWVolumesGen: public FunctorMapThreaded<typename PFP::MAP >
{
const EMBV& m_position;
VolumeAttribute<typename PFP::VEC3>& m_vol_centroid;
public:
FunctorComputeCentroidELWVolumesGen<PFP,EMBV,EMB>( typename PFP::MAP& map, const EMBV& position, VolumeAttribute<typename PFP::VEC3>& vol_centroid):
FunctorMapThreaded<typename PFP::MAP>(map), m_position(position), m_vol_centroid(vol_centroid)
{ }
void run(Dart d, unsigned int threadID)
{
m_vol_centroid[d] = Surface::Geometry::volumeCentroidELWGen<PFP,EMBV,EMB>(this->m_map, d, m_position,threadID) ;
}
};
template <typename PFP, typename EMBV, typename EMB>
void computeCentroidELWVolumesGen(typename PFP::MAP& map,
const EMBV& position, VolumeAttribute<typename PFP::VEC3>& vol_centroid,
unsigned int nbth = 0)
{
FunctorComputeCentroidELWVolumesGen<PFP,EMBV,EMB> funct(map,position,vol_centroid);
Algo::Parallel::foreach_cell<typename PFP::MAP,VOLUME>(map, funct, nbth, true);
}
template <typename PFP>
class FunctorComputeNeighborhoodCentroidVertices: public FunctorMapThreaded<typename PFP::MAP >
{
......
......@@ -128,12 +128,13 @@ void Topo3PrimalRender::updateData(typename PFP::MAP& mapx, const VertexAttribut
if (!m_attIndex.isValid())
m_attIndex = mapx.template addAttribute<unsigned int, DART>("dart_index");
m_nbDarts = 0;
for (Dart d = mapx.begin(); d != mapx.end(); mapx.next(d))
{
// if (!map.isBoundaryMarked3(d)) // in the following code Traversor do not traverse boundary
m_nbDarts++;
}
// m_nbDarts = 0;
// for (Dart d = mapx.begin(); d != mapx.end(); mapx.next(d))
// {
// m_nbDarts++;
// }
m_nbDarts = mapx.getNbDarts();
// beta2/3
DartAutoAttribute<VEC3> fv2(mapx);
......@@ -150,8 +151,6 @@ void Topo3PrimalRender::updateData(typename PFP::MAP& mapx, const VertexAttribut
VEC3* positionDartBuf = reinterpret_cast<VEC3*>(m_bufferDartPosition);
std::vector<Dart> vecDartFaces;
vecDartFaces.reserve(m_nbDarts/6);
unsigned int posDBI=0;
int nbf=0;
......@@ -159,8 +158,6 @@ void Topo3PrimalRender::updateData(typename PFP::MAP& mapx, const VertexAttribut
TraversorF<typename PFP::MAP> traFace(mapx);
for (Dart d = traFace.begin(); d != traFace.end(); d = traFace.next())
{
vecDartFaces.push_back(d);
std::vector<VEC3> vecPos;
vecPos.reserve(16);
......
......@@ -275,6 +275,9 @@ public:
* @param kf exploding coef for face
* @param kv exploding coef for face
*/
template<typename PFP, typename EMBV, typename EMB>
void updateDataGen(typename PFP::MAP& map, const EMBV& positions, float ke, float kf, float kv);
template<typename PFP>
void updateData(typename PFP::MAP& map, const VertexAttribute<typename PFP::VEC3>& positions, float ke, float kf, float kv);
......@@ -283,8 +286,12 @@ public:
* @param map the map
* @param colors attribute of dart's colors
*/
template<typename PFP, typename EMBV, typename EMB>
void updateColorsGen(typename PFP::MAP& map, const EMBV& colors);
template<typename PFP>
void updateColors(typename PFP::MAP& map, const VertexAttribute<typename PFP::VEC3>& colors);
void updateColors(typename PFP::MAP& map, const VertexAttribute<Geom::Vec3f>& colors);
/**
* Get back middle position of drawn darts
......@@ -320,8 +327,8 @@ protected:
* @param kf exploding coef for face
* @param kv exploding coef for face
*/
template<typename PFP>
void updateDataMap3(typename PFP::MAP& map, const VertexAttribute<typename PFP::VEC3>& positions, float ke, float kf, float kv);
template<typename PFP, typename EMBV, typename EMB>
void updateDataMap3(typename PFP::MAP& map, const EMBV& positions, float ke, float kf, float kv);
/**
* update all drawing buffers to render a gmap
......@@ -331,8 +338,8 @@ protected:
* @param kf exploding coef for face
* @param kv exploding coef for face
*/
template<typename PFP>
void updateDataGMap3(typename PFP::MAP& map, const VertexAttribute<typename PFP::VEC3>& positions, float ke, float kf, float kv);
template<typename PFP, typename EMBV, typename EMB>
void updateDataGMap3(typename PFP::MAP& map, const EMBV& positions, float ke, float kf, float kv);
};
......
......@@ -52,19 +52,38 @@ void Topo3Render::updateData(typename PFP::MAP& map, const VertexAttribute<typen
Map3* ptrMap3 = dynamic_cast<Map3*>(&map);
if (ptrMap3 != NULL)
{
updateDataMap3<PFP>(map,positions,ke,kf,kv);
updateDataMap3<PFP, VertexAttribute<typename PFP::VEC3>, typename PFP::VEC3 >(map,positions,ke,kf,kv);
}
GMap3* ptrGMap3 = dynamic_cast<GMap3*>(&map);
if (ptrGMap3 != NULL)
{
updateDataGMap3<PFP>(map,positions,ke,kf,kv);
updateDataGMap3<PFP, VertexAttribute<typename PFP::VEC3>, typename PFP::VEC3>(map,positions,ke,kf,kv);
}
}
template<typename PFP>
void Topo3Render::updateDataMap3(typename PFP::MAP& mapx, const VertexAttribute<typename PFP::VEC3>& positions, float ke, float kf, float kv)
template<typename PFP, typename EMBV, typename EMB>
void Topo3Render::updateDataGen(typename PFP::MAP& map, const EMBV& positions, float ke, float kf, float kv)
{
Map3* ptrMap3 = dynamic_cast<Map3*>(&map);
if (ptrMap3 != NULL)
{
updateDataMap3<PFP,EMBV,EMB>(map,positions,ke,kf,kv);
}
GMap3* ptrGMap3 = dynamic_cast<GMap3*>(&map);
if (ptrGMap3 != NULL)
{
updateDataGMap3<PFP,EMBV,EMB>(map,positions,ke,kf,kv);
}
}
template<typename PFP, typename EMBV, typename EMB>
void Topo3Render::updateDataMap3(typename PFP::MAP& mapx, const EMBV& positions, float ke, float kf, float kv)
{
typedef typename PFP::VEC3 VEC3;
typedef EMB VEC3;
typedef typename PFP::REAL REAL;
m_attIndex = mapx.template getAttribute<unsigned int, DART>("dart_index");
......@@ -264,11 +283,11 @@ void Topo3Render::setDartsIdColor(typename PFP::MAP& map)
glUnmapBuffer(GL_ARRAY_BUFFER);
}
template<typename PFP>
void Topo3Render::updateColors(typename PFP::MAP& map, const VertexAttribute<typename PFP::VEC3>& colors)
template<typename PFP, typename EMBV, typename EMB>
void Topo3Render::updateColorsGen(typename PFP::MAP& map, const EMBV& colors)
{
m_vbo4->bind();
Geom::Vec3f* colorBuffer = reinterpret_cast<Geom::Vec3f*>(glMapBuffer(GL_ARRAY_BUFFER, GL_READ_WRITE));
EMB* colorBuffer = reinterpret_cast<EMB*>(glMapBuffer(GL_ARRAY_BUFFER, GL_READ_WRITE));
unsigned int nb=0;
for (Dart d = map.begin(); d != map.end(); map.next(d))
......@@ -290,6 +309,12 @@ void Topo3Render::updateColors(typename PFP::MAP& map, const VertexAttribute<typ
glUnmapBuffer(GL_ARRAY_BUFFER);
}
template<typename PFP>
void Topo3Render::updateColors(typename PFP::MAP& map, const VertexAttribute<Geom::Vec3f>& colors)
{
updateColorsGen<PFP, Geom::Vec3f, VertexAttribute<Geom::Vec3f> >(map,colors);
}
template<typename PFP>
Dart Topo3Render::picking(typename PFP::MAP& map, int x, int y)
{
......@@ -300,17 +325,14 @@ Dart Topo3Render::picking(typename PFP::MAP& map, int x, int y)
return d;
}
template<typename PFP>
void Topo3Render::updateDataGMap3(typename PFP::MAP& mapx, const VertexAttribute<typename PFP::VEC3>& positions, float ke, float kf, float kv)
template<typename PFP, typename EMBV, typename EMB>
void Topo3Render::updateDataGMap3(typename PFP::MAP& mapx, const EMBV& positions, float ke, float kf, float kv)
{
typedef typename PFP::VEC3 VEC3;
typedef EMB VEC3;
typedef typename PFP::REAL REAL;
GMap3& map = dynamic_cast<GMap3&>(mapx); // TODO reflechir comment virer ce warning quand on compile avec PFP::MAP=Map3
typedef typename PFP::VEC3 VEC3;
typedef typename PFP::REAL REAL;
if (m_attIndex.map() != &mapx)
m_attIndex = mapx.template getAttribute<unsigned int, DART>("dart_index");
if (!m_attIndex.isValid())
......
/*******************************************************************************
* 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 _TOPO_PRIMAL_RENDER
#define _TOPO_PRIMAL_RENDER
#include <vector>
#include <list>
#include "Topology/generic/dart.h"
#include "Topology/generic/attributeHandler.h"
#include "Topology/generic/functor.h"
#include "Geometry/vector_gen.h"
#include "Utils/GLSLShader.h"
#include "Utils/Shaders/shaderSimpleColor.h"
#include "Utils/Shaders/shaderColorPerVertex.h"
#include "Utils/vbo_base.h"
#include "Utils/svg.h"
namespace CGoGN
{
namespace Algo
{
namespace Render
{
namespace GL2
{
class TopoPrimalRender
{
protected:
/**
* vbo buffers
* 0: vertices darts
* 1: vertices alpha1
* 2: colors
*/
Utils::VBO* m_vbo0;
Utils::VBO* m_vbo1;
Utils::VBO* m_vbo2;
unsigned int m_vaId;
Utils::ShaderSimpleColor* m_shader1;
Utils::ShaderColorPerVertex* m_shader2;
/**
*number of darts to draw
*/
GLuint m_nbDarts;
/**
* number of relations 2 to draw
*/
GLuint m_nbRel1;
/**
* width of lines use to draw darts
*/
float m_topo_dart_width;
/**
* width of lines use to draw phi
*/
float m_topo_relation_width;
/**
* pointer for saved colorvbo (in picking)
*/
float *m_color_save;
/**
* initial darts color (set in update)
*/
Geom::Vec3f m_dartsColor;
/**
* initial darts color for boundary (set in update)
*/
Geom::Vec3f m_boundaryDartsColor;
/**
* attribute index to get easy correspondence dart/color
*/
DartAttribute<unsigned int> m_attIndex;
Geom::Vec3f* m_bufferDartPosition;
/**
* save colors
*/
void pushColors();
/**
* restore colors
*/
void popColors();
/**
* pick dart with color set by setDartsIdColor
* @param x position of mouse (x)
* @param y position of mouse (pass H-y, classic pb of origin)
* @return the dart or NIL
*/
Dart pickColor(unsigned int x, unsigned int y);
public:
/**
* Constructor
*/
TopoPrimalRender();
/**
* Destructor
*/
~TopoPrimalRender();
Utils::GLSLShader* shader1() { return static_cast<Utils::GLSLShader*>(m_shader1);}
Utils::GLSLShader* shader2() { return static_cast<Utils::GLSLShader*>(m_shader2);}
/**
* set the with of line use to draw darts (default val is 2)
* @param dw width
*/
void setDartWidth(float dw);
/**
* set the with of line use to draw phi (default val is ")
* @param pw width
*/
void setRelationWidth(float pw);
/**
* Drawing function for darts only
*/
void drawDarts();
/**
* Drawing function for phi2 only
*/
void drawRelation1();
/**
* draw all topo
* \warning DO NOT FORGET TO DISABLE CULLFACE BEFORE CALLING
*/
void drawTopo();
/**
* change dart drawing color
* @param d the dart
* @param r red !
* @param g green !
* @param b blue !
*/
void setDartColor(Dart d, float r, float g, float b);
/**
* change all darts drawing color
* @param r red !
* @param g green !
* @param b blue !
*/
void setAllDartsColor(float r, float g, float b);
/**
* change dart initial color (used when calling updateData)
* @param r red !
* @param g green !
* @param b blue !
*/
void setInitialDartsColor(float r, float g, float b);
void setInitialBoundaryDartsColor(float r, float g, float b);
/**
* overdraw a dart with given width and color
* @param d the dart
* @param width drawing width
* @param r red !
* @param g green !
* @param b blue !
*/
void overdrawDart(Dart d, float width, float r, float g, float b);
/**
* store darts in color for picking
*/
template<typename PFP>
void setDartsIdColor(typename PFP::MAP& map);
/**
* pick dart with color set bey setDartsIdColor
* Do not forget to apply same transformation to scene before picking than before drawing !
* @param map the map
* @param x position of mouse (x)
* @param y position of mouse (pass H-y, classic pb of origin)
* @return the dart or NIL
*/
template<typename PFP>
Dart picking(typename PFP::MAP& map, int x, int y);
/**
* compute dart from color (for picking)
*/
Dart colToDart(float* color);
/**
* compute color from dart (for picking)
*/
void dartToCol(Dart d, float& r, float& g, float& b);
/**
* update all drawing buffers to render a dual map
* @param map the map
* @param positions attribute of position vertices
* @param ke exploding coef for edge
*/
template<typename PFP>
void updateData(typename PFP::MAP& map, const VertexAttribute<typename PFP::VEC3>& positions, float ke);
/**
* update color buffer with color attribute handler
* @param map the map
* @param colors attribute of dart's colors
*/
template<typename PFP>
void updateColors(typename PFP::MAP& map, const VertexAttribute<typename PFP::VEC3>& colors);
/**
* Get back middle position of drawn darts
* @param map the map
* @param posExpl the output positions
*/
template<typename PFP>
void computeDartMiddlePositions(typename PFP::MAP& map, DartAttribute<typename PFP::VEC3>& posExpl);
/**
* render to svg struct
*/
void toSVG(Utils::SVG::SVGOut& svg);
/**
* render svg into svg file
*/
void svgout2D(const std::string& filename, const glm::mat4& model, const glm::mat4& proj);
template<typename PFP>
Dart coneSelection(typename PFP::MAP& map, const Geom::Vec3f& rayA, const Geom::Vec3f& rayAB, float angle);
template<typename PFP>
Dart raySelection(typename PFP::MAP& map, const Geom::Vec3f& rayA, const Geom::Vec3f& rayAB, float distmax);
};
}//end namespace GL2
}//end namespace Algo
}//end namespace Render
}//end namespace CGoGN
#include "Algo/Render/GL2/topoPrimalRender.hpp"
#endif
/*******************************************************************************
* 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 "Geometry/vector_gen.h"
#include "Topology/generic/autoAttributeHandler.h"
#include "Topology/generic/dartmarker.h"
#include "Topology/generic/cellmarker.h"
#include "Topology/map/map3.h"
#include "Topology/generic/traversorCell.h"
#include "Geometry/distances.h"
namespace CGoGN
{
namespace Algo
{
namespace Render
{
namespace GL2
{
template<typename PFP>
void TopoPrimalRender::setDartsIdColor(typename PFP::MAP& map)
{
m_vbo2->bind();
float* colorBuffer = reinterpret_cast<float*>(glMapBuffer(GL_ARRAY_BUFFER, GL_READ_WRITE));
unsigned int nb=0;
for (Dart d = map.begin(); d != map.end(); map.next(d))
{
if (nb < m_nbDarts)
{
float r,g,b;
dartToCol(d, r,g,b);
float* local = colorBuffer+3*m_attIndex[d]; // get the right position in VBO
*local++ = r;
*local++ = g;
*local++ = b;
*local++ = r;
*local++ = g;
*local++ = b;
nb++;
}
else
{
CGoGNerr << "Error buffer too small for color picking (change the selector parameter ?)" << CGoGNendl;
break;
}
}
glUnmapBuffer(GL_ARRAY_BUFFER);
}
template<typename PFP>
void TopoPrimalRender::updateColors(typename PFP::MAP& map, const VertexAttribute<typename PFP::VEC3>& colors)
{
m_vbo2->bind();
Geom::Vec3f* colorBuffer = reinterpret_cast<Geom::Vec3f*>(glMapBuffer(GL_ARRAY_BUFFER, GL_READ_WRITE));
unsigned int nb=0;
for (Dart d = map.begin(); d != map.end(); map.next(d))
{
if (nb < m_nbDarts)
{
colorBuffer[m_attIndex[d]] = colors[d];
nb++;
}
else
{
CGoGNerr << "Error buffer too small for color picking (change the selector parameter ?)" << CGoGNendl;
break;
}
}
glUnmapBuffer(GL_ARRAY_BUFFER);
}
template<typename PFP>
Dart TopoPrimalRender::picking(typename PFP::MAP& map, int x, int y)