Commit d980362e authored by untereiner's avatar untereiner

Merge cgogn:~thery/CGoGN

parents 0f47b2ad b2ff35a7
......@@ -24,7 +24,6 @@
#include "tuto1.h"
#include "Algo/Geometry/boundingbox.h"
#include "Topology/generic/mapBrowser.h"
using namespace CGoGN ;
......
......@@ -290,11 +290,6 @@ void MyQT::createMap(int /*n*/)
m_render_topo->setInitialDartsColor(0.0f,0.0f,0.0f);
m_render_topo->updateData<PFP>(myMap, position, m_ex1,m_ex2,m_ex3/*, nb*/);
// SelectorDartBoundary<PFP::MAP> sdb(myMap);
// MapBrowserSelector mbs(myMap,sdb);
// myMap.setBrowser(&mbs);
// m_render_topo_boundary->updateData<PFP>(myMap,position,m_ex1,m_ex2);
// myMap.setBrowser(NULL);
m_render_topo_boundary->updateDataBoundary<PFP>(myMap,position,m_ex1,m_ex2,m_shift);
}
......
......@@ -26,7 +26,6 @@
#define __COLOR_APPROXIMATOR_H__
#include "Algo/Decimation/approximator.h"
#include "Topology/generic/mapBrowser.h"
namespace CGoGN
{
......
......@@ -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 >
{
......
......@@ -26,7 +26,7 @@
#define __ALGO_GEOMETRY_NORMALIZATION_H__
#include "Geometry/vector_gen.h"
#include "Topology/generic/mapBrowser.h"
#include "Container/containerBrowser.h"
namespace CGoGN
{
......@@ -41,27 +41,50 @@ namespace Geometry
template <typename PFP, unsigned int ORBIT>
typename PFP::REAL normalizeLength(typename PFP::MAP & the_map, AttributeHandler<typename PFP::VEC3,ORBIT> & m_attr, const typename PFP::REAL scale = 1.0, )
{
// typename PFP::REAL sum = 0 ;
// int count = 0 ;
// MapBrowserLinked<typename PFP::MAP> mb(the_map) ;
// the_map.foreach_orbit(m_attr.getOrbit(), mb) ;
// for (Dart d = mb.begin(); d != mb.end(); mb.next(d))
// {
// typename PFP::VEC3 length = m_attr[d] ;
// length -= m_attr[the_map.phi2(d)] ;
// sum += length.norm() ;
// ++count ;
// }
// sum /= typename PFP::REAL(count) ;
// typename PFP::REAL div = sum / scale ; // mutiply res by scale factor
// for (Dart d = mb.begin(); d != mb.end(); mb.next(d))
// {
// m_attr[d] /= div ;
// }
// return div ;
typename PFP::REAL sum = 0 ;
int count = 0 ;
MapBrowserLinked<typename PFP::MAP> mb(the_map) ;
the_map.foreach_orbit(m_attr.getOrbit(), mb) ;
for (Dart d = mb.begin(); d != mb.end(); mb.next(d))
TraversorCell<PFP::MAP,ORBIT> trav(the_map);
for (Dart d = trav.begin(); d != trav.end(); d=trav.next())
{
typename PFP::VEC3 length = m_attr[d] ;
length -= m_attr[the_map.phi2(d)] ;
sum += length.norm() ;
++count ;
sum += length.norm() ;
++count ;
}
sum /= typename PFP::REAL(count) ;
sum /= typename PFP::REAL(count) ;
typename PFP::REAL div = sum / scale ; // mutiply res by scale factor
typename PFP::REAL div = sum / scale ; // mutiply res by scale factor
for (Dart d = mb.begin(); d != mb.end(); mb.next(d))
for (Dart d = trav.begin(); d != trav.end(); d=trav.next())
{
m_attr[d] /= div ;
m_attr[d] /= div ;
}
return div ;
......
......@@ -24,7 +24,8 @@
#ifndef IMPORTOBJTEX_H
#define IMPORTOBJTEX_H
#include "Topology/generic/mapBrowser.h"
//#include "Topology/generic/mapBrowser.h"
#include "Container/containerBrowser.h"
#include "Topology/generic/cellmarker.h"
namespace CGoGN
......@@ -180,7 +181,7 @@ public:
* @param browsers vector of MapBrowers representing the groups
* @return ok or not
*/
bool generateBrowsers(std::vector<MapBrowser*>& browsers);
bool generateBrowsers(std::vector<ContainerBrowser*>& browsers);
/**
* @brief getMaterialNames
......
......@@ -23,6 +23,7 @@
*******************************************************************************/
#include "Topology/generic/attributeHandler.h"
#include "Topology/generic/autoAttributeHandler.h"
#include "Container/fakeAttribute.h"
#include <fstream>
......@@ -214,30 +215,51 @@ void OBJModel<PFP>::readMaterials(const std::string& filename, std::vector<Mater
template <typename PFP>
bool OBJModel<PFP>::generateBrowsers(std::vector<MapBrowser*>& browsers)
bool OBJModel<PFP>::generateBrowsers(std::vector<ContainerBrowser*>& browsers)
{
browsers.clear();
// browsers.clear();
// if (m_groupNames.empty())
// return false;
// MapBrowserLinked* MBLptr = new MapBrowserLinked(m_map);
// DartAttribute<Dart>& links = MBLptr->getLinkAttr();
// browsers.push_back(MBLptr);
// for (unsigned int i = 1; i<m_groupNames.size(); ++i)
// {
// MapBrowser* MBptr = new MapBrowserLinked(m_map,links);
// browsers.push_back(MBptr);
// m_groupMaterialID[i]= m_materialNames[m_groupMaterialNames[i]];
// }
// for (Dart d=m_map.begin(); d!=m_map.end(); m_map.next(d))
// {
// unsigned int g = m_groups[d] -1 ; // groups are name from 1
// MapBrowserLinked* mb = static_cast<MapBrowserLinked*>(browsers[g]);
// mb->pushBack(d);
// }
// return true;
browsers.clear();
if (m_groupNames.empty())
return false;
MapBrowserLinked* MBLptr = new MapBrowserLinked(m_map);
DartAttribute<Dart>& links = MBLptr->getLinkAttr();
ContainerBrowserLinked* MBLptr = new ContainerBrowserLinked(m_map,DART);
browsers.push_back(MBLptr);
for (unsigned int i = 1; i<m_groupNames.size(); ++i)
{
MapBrowser* MBptr = new MapBrowserLinked(m_map,links);
ContainerBrowser* MBptr = new ContainerBrowserLinked(*MBLptr);
browsers.push_back(MBptr);
// std::string& matName = m_materialNames[i];
m_groupMaterialID[i]= m_materialNames[m_groupMaterialNames[i]];
}
for (Dart d=m_map.begin(); d!=m_map.end(); m_map.next(d))
{
unsigned int g = m_groups[d] -1 ; // groups are name from 1
MapBrowserLinked* mb = static_cast<MapBrowserLinked*>(browsers[g]);
mb->pushBack(d);
ContainerBrowserLinked* mb = static_cast<ContainerBrowserLinked*>(browsers[g]);
mb->pushBack(d.index);
}
return true;
}
......
......@@ -35,6 +35,7 @@
#include "Utils/Shaders/shaderExplodeSmoothVolumes.h"
#include "Utils/Shaders/shaderExplodeVolumes.h"
#include "Utils/Shaders/shaderExplodeVolumesLines.h"
#include "Utils/svg.h"
namespace CGoGN
{
......@@ -78,9 +79,17 @@ protected:
*/
GLuint m_nbTris;
/**
*number of lines to draw
*/
GLuint m_nbLines;
Geom::Vec3f m_globalColor;
/**
* explode volume factor
*/
float m_explodeV;
template<typename PFP>
void computeFace(typename PFP::MAP& map, Dart d, const VertexAttribute<typename PFP::VEC3>& positions,
......@@ -185,6 +194,20 @@ public:
* set color parameter for edge drawing
*/
void setColorLine(const Geom::Vec4f& col) ;
/**
* @brief svgout2D
* @param filename name of svg file
* @param model modelview matrix
* @param proj projection matrix
*/
void svgoutEdges(const std::string& filename, const glm::mat4& model, const glm::mat4& proj);
/**
* @brief toSVG
* @param svg svg struct reference
*/
void toSVG(Utils::SVG::SVGOut& svg);
};
}//end namespace GL2
......
......@@ -624,6 +624,7 @@ inline void ExplodeVolumeRender::drawEdges()
inline void ExplodeVolumeRender::setExplodeVolumes(float explode)
{
m_explodeV = explode;
if (m_smooth)
m_shaderS->setExplodeVolumes(explode);
else
......@@ -697,6 +698,40 @@ inline Utils::GLSLShader* ExplodeVolumeRender::shaderLines()
return m_shaderL;
}
inline void ExplodeVolumeRender::svgoutEdges(const std::string& filename, const glm::mat4& model, const glm::mat4& proj)
{
Utils::SVG::SVGOut svg(filename,model,proj);
toSVG(svg);
svg.write();
}
inline void ExplodeVolumeRender::toSVG(Utils::SVG::SVGOut& svg)
{
Utils::SVG::SvgGroup* svg2 = new Utils::SVG::SvgGroup("alpha2", svg.m_model, svg.m_proj);
Geom::Vec3f* ptr = reinterpret_cast<Geom::Vec3f*>(m_vboPosLine->lockPtr());
svg2->setWidth(1.0f);
svg2->beginLines();
const Geom::Vec4f& col4 = m_shaderL->getColor();
Geom::Vec3f col3(col4[0],col4[1],col4[2]);
float XexplV = (1.0f-m_explodeV);
for (unsigned int i=0; i<m_nbLines; ++i)
{
Geom::Vec3f C = ptr[3*i];
Geom::Vec3f P = XexplV*C + m_explodeV*ptr[3*i+1];
Geom::Vec3f Q = XexplV*C + m_explodeV*ptr[3*i+2];
svg2->addLine(P, Q, col3);
}
svg2->endLines();
m_vboPosLine->releasePtr();
svg.addGroup(svg2);
}
}//end namespace VBO
}//end namespace Algo
......
......@@ -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);}