Commit cc4445d8 authored by Pierre Kraemer's avatar Pierre Kraemer

Merge branch 'develop' of cgogn:~thery/CGoGNMR into develop

parents 2f294c4b 068bbeba
......@@ -36,3 +36,4 @@ ENDIF (WITH_QT)
add_subdirectory(Examples/Tests)
add_subdirectory(Tuto/Traversals)
add_subdirectory(Tuto/Attributes)
......@@ -197,6 +197,141 @@ void Viewer::cb_keyPress(int keycode)
case 'c' :
myMap.check();
break;
case 'a':
{
Utils::Chrono ch;
ch.start();
VertexAttribute<VEC3,MAP_IMPL> pos2 = myMap.getAttribute<VEC3, VERTEX>("pos2") ;
if(!pos2.isValid())
pos2 = myMap.addAttribute<VEC3, VERTEX>("pos2") ;
for (int i=0; i< 10; ++i)
{
TraversorV<MAP> trav(myMap);
for (Dart d=trav.begin(), d_end = trav.end(); d!=d_end ; d = trav.next())
{
pos2[d] = VEC3(0,0,0);
int nb=0;
Traversor2VVaF<MAP> trf(myMap,d);
for (Dart e = trf.begin(),e_end =trf.end() ; e != e_end; e = trf.next())
{
pos2[d] += position[e];
nb++;
}
pos2[d]/=nb;
}
myMap.swapAttributes(position,pos2);
}
std::cout << "Traversor "<< ch.elapsed()<< " ms "<< std::endl;
Algo::Surface::Geometry::computeNormalVertices<PFP>(myMap, position, normal) ;
m_positionVBO->updateData(position) ;
m_normalVBO->updateData(normal) ;
updateGL();
}
break;
case 'b':
{
Utils::Chrono ch;
ch.start();
VertexAttribute<VEC3,MAP_IMPL> pos2 = myMap.getAttribute<VEC3, VERTEX>("pos2") ;
if(!pos2.isValid())
pos2 = myMap.addAttribute<VEC3, VERTEX>("pos2") ;
for (int i=0; i< 10; ++i)
{
foreach_cell<VERTEX>(myMap, [&] (Vertex d)
{
pos2[d] = VEC3(0,0,0);
int nb=0;
foreach_adjacent2<FACE>(myMap,d,[&](Vertex e)
{
pos2[d] += position[e];
nb++;
});
pos2[d]/=nb;
});
myMap.swapAttributes(position,pos2);
}
std::cout << "Lambda "<< ch.elapsed()<< " ms "<< std::endl;
Algo::Surface::Geometry::computeNormalVertices<PFP>(myMap, position, normal) ;
m_positionVBO->updateData(position) ;
m_normalVBO->updateData(normal) ;
updateGL();
}
break;
case 'e':
{
Utils::Chrono ch;
ch.start();
VertexAttribute<VEC3,MAP_IMPL> pos2 = myMap.getAttribute<VEC3, VERTEX>("pos2") ;
if(!pos2.isValid())
pos2 = myMap.addAttribute<VEC3, VERTEX>("pos2") ;
for (int i=0; i< 10; ++i)
{
TraversorV<MAP> trav(myMap);
for (Dart d=trav.begin(), d_end = trav.end(); d!=d_end ; d = trav.next())
{
pos2[d] = VEC3(0,0,0);
int nb=0;
Traversor2VE<MAP> trf(myMap,d);
for (Dart e = trf.begin(),e_end =trf.end() ; e != e_end; e = trf.next())
{
pos2[d] += position[myMap.phi1(e)];
nb++;
}
pos2[d]/=nb;
}
myMap.swapAttributes(position,pos2);
}
std::cout << "Traversor "<< ch.elapsed()<< " ms "<< std::endl;
Algo::Surface::Geometry::computeNormalVertices<PFP>(myMap, position, normal) ;
m_positionVBO->updateData(position) ;
m_normalVBO->updateData(normal) ;
updateGL();
}
break;
case 'f':
{
Utils::Chrono ch;
ch.start();
VertexAttribute<VEC3,MAP_IMPL> pos2 = myMap.getAttribute<VEC3, VERTEX>("pos2") ;
if(!pos2.isValid())
pos2 = myMap.addAttribute<VEC3, VERTEX>("pos2") ;
for (int i=0; i< 10; ++i)
{
foreach_cell<VERTEX>(myMap, [&] (Vertex d)
{
pos2[d] = VEC3(0,0,0);
int nb=0;
foreach_incident2<EDGE>(myMap,d,[&](Edge e)
{
pos2[d] += position[myMap.phi1(e)];
nb++;
});
pos2[d]/=nb;
});
myMap.swapAttributes(position,pos2);
}
std::cout << "Lambda "<< ch.elapsed()<< " ms "<< std::endl;
Algo::Surface::Geometry::computeNormalVertices<PFP>(myMap, position, normal) ;
m_positionVBO->updateData(position) ;
m_normalVBO->updateData(normal) ;
updateGL();
}
break;
default:
break;
}
......
cmake_minimum_required(VERSION 2.8)
project(Tuto_Traversals)
SET (CMAKE_BUILD_TYPE Debug)
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DNOTOPOWARNING")
include_directories(
${CMAKE_CURRENT_BINARY_DIR}
${CGoGN_ROOT_DIR}/include
${CGoGN_EXT_INCLUDES}
)
# define libs path
IF(WIN32)
link_directories(${CGoGN_ROOT_DIR}/lib/$(ConfigurationName)
${Boost_LIBRARY_DIRS})
ELSE(WIN32)
link_directories(${CGoGN_ROOT_DIR}/lib/Release ${CGoGN_ROOT_DIR}/lib/Debug)
ENDIF(WIN32)
#define exec to compile
add_executable( simple_attribs simple_attribs.cpp)
target_link_libraries( simple_attribs ${CGoGN_LIBS_D} ${CGoGN_EXT_LIBS} )
add_executable( multi_attribs multi_attribs.cpp)
target_link_libraries( multi_attribs ${CGoGN_LIBS_D} ${CGoGN_EXT_LIBS} )
/*******************************************************************************
* 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 "Algo/Tiling/Surface/square.h"
#include "Topology/generic/multiAttribs.h"
#include "Algo/Geometry/centroid.h"
using namespace CGoGN ;
/**
* Struct that contains some informations about the types of the manipulated objects
* Mainly here to be used by the algorithms that are parameterized by it
*/
struct PFP: public PFP_STANDARD
{
// definition of the type of the map
typedef EmbeddedMap2 MAP;
};
// some typedef shortcuts
typedef PFP::MAP MAP ; // map type
typedef PFP::MAP::IMPL MAP_IMPL ; // map implementation
typedef PFP::VEC3 VEC3 ; // type of R³ vector
typedef PFP::VEC4 VEC4;
/**
* Example of function that work with any kin of Vertex Attribute
*/
template <typename MAP, typename ATT>
typename ATT::DATA_TYPE smooth(MAP& map, Vertex v, const ATT& attributs)
{
typename ATT::DATA_TYPE res(0);
int count=0;
foreach_adjacent2<EDGE>(map,v,[&](Vertex x) // for all its neighbours (by edges)
{
res += attributs[x];
count ++;
});
res /= typename PFP::REAL(count);
return res;
}
/**
* Example of function that work with any kind of Vertex Attribute
*/
template <typename MAP, typename ATT>
void applySmooth(MAP& map, const ATT& att_in, ATT& att_out)
{
foreach_cell<VERTEX>(map,[&](Vertex v) // for all edge e of map do
{
att_out[v] = smooth(map,v,att_in);
});
}
int main()
{
// declare a map to handle the mesh
MAP myMap;
// add position attribute on vertices and get handler on it
VertexAttribute<VEC3, MAP_IMPL> position = myMap.addAttribute<VEC3, VERTEX>("position");
// create a topo grid of 2x2 squares
Algo::Surface::Tilings::Square::Grid<PFP> grid(myMap, 2, 2, true);
// and embed it using position attribute
grid.embedIntoGrid(position, 2.,2.,0.);
// second vertex attribute (for out)
VertexAttribute<VEC3, MAP_IMPL> pos2 = myMap.addAttribute<VEC3, VERTEX>("pos2");
// first color attribute on vertices
VertexAttribute<VEC4, MAP_IMPL> vc = myMap.addAttribute<VEC4, VERTEX>("vertexColor");
// second color attribute on vertices
VertexAttribute<VEC4, MAP_IMPL> vc2 = myMap.addAttribute<VEC4, VERTEX>("vertexColor2");
// add some random on position and compute a color
for (unsigned int i= position.begin(); i != position.end(); position.next(i))
{
position[i] += VEC3(0.02f*i,0.01f*i,0.03f*i);
vc[i] = VEC4(position[i][0]*0.3f,position[i][1]*0.3f,position[i][2]*0.3f,1.0f);
}
std::cout << "========== initial values =========="<<std::endl;
// just print attributes values
foreach_cell<VERTEX>(myMap,[&](Vertex v) // for all edge e of map do
{
std::cout << position[v]<< " / "<< vc[v]<< std::endl;
});
// define two multi attributes (one for in, one for out)
Vertex2Attributes<VEC3, VEC4, MAP_IMPL> pv_in(position, vc);
Vertex2Attributes<VEC3, VEC4, MAP_IMPL> pv_out(pos2, vc2);
// and call algo once just like with simple attributes
applySmooth(myMap, pv_in, pv_out);
std::cout << "========== after smooth on position and color =========="<<std::endl;
foreach_cell<VERTEX>(myMap,[&](Vertex v) // for all edge e of map do
{
std::cout << pos2[v]<< " / "<< vc2[v]<< std::endl;
});
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 "Algo/Tiling/Surface/square.h"
using namespace CGoGN ;
/**
* Struct that contains some informations about the types of the manipulated objects
* Mainly here to be used by the algorithms that are parameterized by it
*/
struct PFP: public PFP_STANDARD
{
// definition of the type of the map
typedef EmbeddedMap2 MAP;
};
// some typedef shortcuts
typedef PFP::MAP MAP ; // map type
typedef PFP::MAP::IMPL MAP_IMPL ; // map implementation
typedef PFP::VEC3 VEC3 ; // type of R³ vector
/**
* @brief get attribute
* @param map
*/
void byNames(MAP& map, const std::string& name)
{
VertexAttribute<VEC3, MAP_IMPL> testPos = map.getAttribute<VEC3, VERTEX>(name);
if (testPos.isValid())
std::cout << "Attribute "<< name <<" valid"<< std::endl;
else
std::cout << "Attribute "<< name <<"invalid"<< std::endl;
}
/**
* @brief computeLengthEdges
* @param map the map
* @param pos attribute handler of position of vertices
* @param len attribute handler of length of edges
*/
void computeLengthEdges(MAP& map,const VertexAttribute<VEC3, MAP_IMPL>& pos, EdgeAttribute<float, MAP_IMPL> len)
{
// warning c++11 lambda syntax
foreach_cell<EDGE>(map,[&](Edge e) // for all edge e of map do
{
VEC3 P1 = pos[e.dart]; // access with dart because of access to VertexAttribute with an edge
VEC3 P2 = pos[map.phi1(e)]; // phi1 return a dart so no problem (and e can auto-cast in dart)
VEC3 V = P2 - P1;
len[e] = V.norm();
});
}
void computeNewPositions(MAP& map, VertexAttribute<VEC3, MAP_IMPL>& pos)
{
// here we need new and old positions simultaneously so create temporary position
VertexAutoAttribute<VEC3, MAP_IMPL> pos2(map);
foreach_cell<VERTEX>(map,[&](Vertex v) // for all vertices
{
int nb=0;
pos2[v] = VEC3(0,0,0);// init with 0,0,0,
foreach_adjacent2<EDGE>(map,v,[&](Vertex x) // for all its neighbours (by edges)
{
pos2[v] += pos[x];
nb++;
});
pos2[v] /= nb;
});
// swap attribute position with temporary (constant complexity !)
map.swapAttributes(pos,pos2);
}
/**
* @brief dump any attribute
* @param attr attribute
*/
template<typename ATTRIB>
void dumpAttribute(const ATTRIB& attr)
{
std::cout << "Attribute " <<attr.name() << " of orbit "<< orbitName(attr.getOrbit())<< " of type "<< attr.typeName()<< std::endl;
// NEVER USE 0 AND ++ IN FOR LOOP ON ATTRIBUTE !
// USE ONLY BEGIN / END / NEXT (for hole jumping over)
for (unsigned int i=attr.begin(); i!=attr.end(); attr.next(i))
{
std::cout << attr.name() << "["<< i << "] = "<<attr[i]<< std::endl;
}
}
int main()
{
// declare a map to handle the mesh
MAP myMap;
// add position attribute on vertices and get handler on it
VertexAttribute<VEC3, MAP_IMPL> positionAtt = myMap.addAttribute<VEC3, VERTEX>("position");
if (!positionAtt.isValid())
std::cerr << "impossible to create an attribute with name position (already used ?)"<< std::endl;
// create a topo grid of 2x2 squares
Algo::Surface::Tilings::Square::Grid<PFP> grid(myMap, 2, 2, true);
// and embed it using position attribute
grid.embedIntoGrid(positionAtt, 1.,1.,0.);
// add an attribute of type float on orbit EDGE
EdgeAttribute<float, MAP_IMPL> lengthAtt = myMap.addAttribute<float, EDGE>("length");
if (!lengthAtt.isValid())
std::cerr << "impossible to create the attribute"<< std::endl;
computeLengthEdges(myMap,positionAtt,lengthAtt);
// add an attribute of type std::string on orbit FACE
FaceAttribute<std::string, MAP_IMPL> nameAtt = myMap.addAttribute<std::string, FACE>("name");
if (!nameAtt.isValid())
std::cerr << "impossible to create the attribute"<< std::endl;
// for complex type use following template (function nameOfType not applicable)
EdgeAttribute< NoTypeNameAttribute< std::vector<int> >, MAP_IMPL> vectAtt = myMap.addAttribute< NoTypeNameAttribute< std::vector<int> >, EDGE>("vector_of_int");
if (!vectAtt.isValid())
std::cerr << "impossible to create the attribute"<< std::endl;
Dart d = myMap.begin();
// define a vertex from a dart
Vertex v(d);
// define a face from a dart
Face f(d);
// [] operator can take a dart, a cell (only same off attribute), or an unsigned inf
// access to any attributes with darts
std::cout << positionAtt[d]<< std::endl;
nameAtt[d] = "Hello";
lengthAtt[myMap.phi1(d)] = 54.0f;
std::vector<int> vi = {3,5,7,9,11};
vectAtt[d]= vi;
vectAtt[d].push_back(11);
// access to VertexAttribute with a Vertex
std::cout << positionAtt[v]<< std::endl;
// access to FaceAttribute with a Face
std::cout << nameAtt[f]<< std::endl;
// following line does not compile because of wrong cell type
// std::cout << positionAtt[f]<< std::endl;
// possible to bypass using dart access
std::cout << positionAtt[f.dart]<< std::endl;
// possible to have any number of attribute a same ORBIT
VertexAttribute<VEC3, MAP_IMPL> position2Att = myMap.addAttribute<VEC3, VERTEX>("other_position");
// copy of attribute of same type (linear complexity)
myMap.copyAttribute(position2Att,positionAtt);
positionAtt[v] += VEC3(0,0,1);
computeNewPositions(myMap,positionAtt);
dumpAttribute(positionAtt);
byNames(myMap,"position");
myMap.removeAttribute<VEC3, VERTEX>(positionAtt);
byNames(myMap,"position");
return 0;
}
......@@ -42,7 +42,13 @@ target_link_libraries( traverse_cells ${CGoGN_LIBS_D} ${CGoGN_EXT_LIBS} )
add_executable( traverse_neighbours traverse_neighbours.cpp)
target_link_libraries( traverse_neighbours ${CGoGN_LIBS_D} ${CGoGN_EXT_LIBS} )
QT4_WRAP_UI( show_traversors_ui show_traversors.ui )
QT4_WRAP_CPP(show_traversors_moc show_traversors.h)
add_executable( show_traversors show_traversors.cpp ${show_traversors_ui} ${show_traversors_moc})
target_link_libraries( show_traversors ${CGoGN_LIBS_D} ${CGoGN_EXT_LIBS} )
QT4_WRAP_UI( show_traversors_ui2 show_traversors2.ui )
QT4_WRAP_CPP(show_traversors_moc2 show_traversors2.h)
add_executable( show_traversors2 show_traversors2.cpp ${show_traversors_ui2} ${show_traversors_moc2})
target_link_libraries( show_traversors2 ${CGoGN_LIBS_D} ${CGoGN_EXT_LIBS} )
QT4_WRAP_UI( show_traversors_ui3 show_traversors3.ui )
QT4_WRAP_CPP(show_traversors_moc3 show_traversors3.h)
add_executable( show_traversors3 show_traversors3.cpp ${show_traversors_ui3} ${show_traversors_moc3})
target_link_libraries( show_traversors3 ${CGoGN_LIBS_D} ${CGoGN_EXT_LIBS} )
/*******************************************************************************
* 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 "show_traversors2.h"
#include <iostream>
#include "Algo/Tiling/Surface/square.h"
#include "Algo/Modelisation/polyhedron.h"
#include "Algo/Modelisation/subdivision.h"
#include "Algo/Import/import.h"
#include "Algo/Render/GL2/topo3Render.h"
#include "Algo/Render/SVG/mapSVGRender.h"
#include "Topology/generic/traversor/traversorFactory.h"
#include "Algo/Render/GL2/drawerCells.h"
void MyQT::cb_checkTopo(bool b)
{
m_showTopo = b;
updateGL();
}
void MyQT::cb_combo4(int x)
{
m_first2 = x;
if (m_first2!=m_second2)
traverse2();
else
CGoGNerr <<"undefined traversor" << CGoGNendl;
}
void MyQT::cb_combo5(int x)
{
m_ajd_or_inci2 = x;
if (m_first2!=m_second2)
traverse2();
else
CGoGNerr <<"undefined traversor" << CGoGNendl;
}
void MyQT::cb_combo6(int x)
{
m_second2 = x;
if (m_first2!=m_second2)
traverse2();
else
CGoGNerr <<"undefined traversor" << CGoGNendl;
}
void MyQT::cb_explode(int x)
{
m_expl = float (x) /100.0f;
if (m_last==2)
traverse2();
}
void MyQT::cb_initGL()
{
// choose to use GL version 2
Utils::GLSLShader::setCurrentOGLVersion(2);
m_render_topo = new Algo::Render::GL2::TopoRenderMap<PFP>();
m_render_topo->updateData(myMap