Commit 17a666b7 authored by Sylvain Thery's avatar Sylvain Thery

traversor & foreach macros tutos

parent 29130379
...@@ -29,6 +29,7 @@ ...@@ -29,6 +29,7 @@
#include "Algo/Import/import.h" #include "Algo/Import/import.h"
#include "Algo/Export/export.h" #include "Algo/Export/export.h"
#include "Topology/generic/cells_macros.h"
using namespace CGoGN ; using namespace CGoGN ;
int main(int argc, char **argv) int main(int argc, char **argv)
...@@ -59,6 +60,17 @@ int main(int argc, char **argv) ...@@ -59,6 +60,17 @@ int main(int argc, char **argv)
return app.exec(); return app.exec();
} }
void fonct(const Cell<VERTEX>& v)
{
std::cout << v.dart << std::endl;
}
void fonct2(Dart d)
{
std::cout << d << std::endl;
}
void MyQT::traversors(int x) void MyQT::traversors(int x)
{ {
// update all color to grey // update all color to grey
...@@ -72,16 +84,31 @@ void MyQT::traversors(int x) ...@@ -72,16 +84,31 @@ void MyQT::traversors(int x)
{ {
case 0: case 0:
{ {
// TRAVERSE2_ADJACENT(VERTEX,EDGE,m_selected, b, MAP, myMap)
// m_render_topo->setDartColor(b,0.0f,1.0f,0.0f);
Vertex v(m_selected);
Edge e(m_selected);
fonct(v);
fonct2(e);
fonct(m_selected);
v = m_selected;
/*
Traversor2VVaE<MAP> trav(myMap,m_selected); Traversor2VVaE<MAP> trav(myMap,m_selected);
for(Dart b=trav.begin(); b!= trav.end(); b=trav.next()) for(Dart b=trav.begin(); b!= trav.end(); b=trav.next())
m_render_topo->setDartColor(b,0.0f,1.0f,0.0f); m_render_topo->setDartColor(b,0.0f,1.0f,0.0f);
*/
} }
break; break;
case 1: case 1:
{ {
foreachAdjacent2(VERTEX,FACE,m_selected, b, MAP, myMap)
m_render_topo->setDartColor(b,0.0f,1.0f,0.0f);
/*
Traversor2VVaF<MAP> trav(myMap,m_selected); Traversor2VVaF<MAP> trav(myMap,m_selected);
for(Dart b=trav.begin(); b!= trav.end(); b=trav.next()) for(Dart b=trav.begin(); b!= trav.end(); b=trav.next())
m_render_topo->setDartColor(b,0.0f,1.0f,0.0f); m_render_topo->setDartColor(b,0.0f,1.0f,0.0f);
*/
} }
break; break;
case 2: case 2:
...@@ -150,9 +177,13 @@ void MyQT::traversors(int x) ...@@ -150,9 +177,13 @@ void MyQT::traversors(int x)
break; break;
case 11: case 11:
{ {
Traversor2VF<MAP> trav(myMap,m_selected); /* Traversor2VF<MAP> trav(myMap,m_selected);
for(Dart b=trav.begin(); b!= trav.end(); b=trav.next()) for(Dart b=trav.begin(); b!= trav.end(); b=trav.next())
m_render_topo->setDartColor(b,0.0f,1.0f,0.0f); m_render_topo->setDartColor(b,0.0f,1.0f,0.0f);
*/
foreachIncident2(VERTEX,m_selected, FACE, b, MAP, myMap)
m_render_topo->setDartColor(b,0.0f,1.0f,0.0f);
} }
break; break;
default: default:
......
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
#QT4_WRAP_CPP(tuto1_moc tuto1.h)
#add_executable( tuto1 tuto1.cpp ${tuto1_moc})
#target_link_libraries( tuto1
# ${CGoGN_LIBS_D} ${CGoGN_EXT_LIBS} )
#QT4_WRAP_UI( tuto2_ui tuto2.ui )
#QT4_WRAP_CPP(tuto2_moc tuto2.h)
#add_executable( tuto2 tuto2.cpp tuto2.h ${tuto2_ui} ${tuto2_moc})
#target_link_libraries( tuto2
# ${CGoGN_LIBS_D} ${CGoGN_EXT_LIBS} )
add_executable( traverse_cells traverse_cells.cpp)
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} )
/*******************************************************************************
* 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_traversors.h"
#include <iostream>
#include "Algo/Tiling/Volume/cubic.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/traversorFactory.h"
#include "Algo/Render/GL2/drawerCells.h"
MAP myMap;
VertexAttribute<VEC3, MAP_IMPL> position ;
Dart dglobal;
void MyQT::cb_checkTopo(bool b)
{
m_showTopo = b;
updateGL();
}
void MyQT::cb_combo1(int x)
{
m_first3 = x;
if (m_first3!=m_second3)
traverse3();
else
CGoGNerr <<"undefined traversor" << CGoGNendl;
}
void MyQT::cb_combo2(int x)
{
m_ajd_or_inci3 = x;
if (m_first3!=m_second3)
traverse3();
else
CGoGNerr <<"undefined traversor" << CGoGNendl;
}
void MyQT::cb_combo3(int x)
{
m_second3 = x;
if (m_first3!=m_second3)
traverse3();
else
CGoGNerr <<"undefined traversor" << CGoGNendl;
}
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();
if (m_last==3)
traverse3();
}
void MyQT::cb_initGL()
{
// choose to use GL version 2
Utils::GLSLShader::setCurrentOGLVersion(2);
m_render_topo = new Algo::Render::GL2::Topo3RenderMap<PFP>();
m_render_topo->updateData(myMap, position, 0.95f, 0.9f, 0.8f);
m_dm_topo = new DartMarker<MAP>(myMap);
}
void MyQT::cb_redraw()
{
if (m_showTopo)
{
m_render_topo->drawTopo();
if (m_selected != NIL)
m_render_topo->overdrawDart(m_selected, 7, 1.0f, 0.0f, 1.0f);
for (std::vector<Dart>::iterator it=m_affDarts.begin(); it!=m_affDarts.end(); ++it)
{
m_render_topo->overdrawDart(*it, 6, 1.0f, 1.0f, 1.0f);
}
}
m_drawer.callList();
}
void MyQT::cb_mousePress(int /*button*/, int x, int y)
{
if (Shift())
{
Dart d = m_render_topo->picking(myMap, x, y);
if (d != Dart::nil())
{
CGoGNout << "Dart " << d << " clicked" << CGoGNendl;
m_selected = d;
}
updateGL();
}
}
void MyQT::cb_Save()
{
std::string filename = selectFileSave("Export SVG file ",".","(*.svg)");
std::string filename1 = filename + std::string("Drawer") + std::string(".svg");
std::string filename2 = filename + std::string("Topo") + std::string(".svg");
// std::string filename = selectFileSave("Export SVG file ",".","(*.svg)");
// Utils::SVG::SVGOut svg(filename,modelViewMatrix(),projectionMatrix());
// m_drawer.toSVG(svg);
// m_render_topo->toSVG(svg);
Utils::SVG::SVGOut svg1(filename1, modelViewMatrix(), projectionMatrix());
m_drawer.toSVG(svg1);
svg1.write();
// svg1.addOpacityAnimation(1.0f);
// svg1.addOpacityAnimation(1.0f);
// svg1.addOpacityAnimation(0.0f);
Utils::SVG::SVGOut svg2(filename2, modelViewMatrix(), projectionMatrix());
m_render_topo->toSVG(svg2);
svg2.write();
// svg2.addOpacityAnimation(1.0f);
// svg2.addOpacityAnimation(0.0f);
// svg2.addOpacityAnimation(1.0f);
// Utils::SVG::AnimatedSVGOut anim;
// anim.add(&svg1);
// anim.add(&svg2);
// anim.write(filename, 2.0f);
}
template <unsigned int ORBIT>
void MyQT::colorizeCell(Dart d, float r,float g, float b)
{
TraversorDartsOfOrbit<PFP::MAP, ORBIT>doo (myMap, d);
for (Dart e = doo.begin(); e != doo.end(); e = doo.next())
m_render_topo->setDartColor(e, r, g, b);
}
void MyQT::traverse2()
{
if (m_selected == NIL)
return;
m_last=2;
// int code = (m_ajd_or_inci2)*100+m_first2*10+m_second2;
m_drawer.newList(GL_COMPILE);
m_drawer.lineWidth(7.0f);
m_drawer.pointSize(9.0f);
m_drawer.color3f(0.0f,0.7f,0.0f);
m_affDarts.clear();
if (m_ajd_or_inci2 == 0) // incident
{
Algo::Render::drawerCell<PFP>(VERTEX+m_second2, m_drawer, myMap, m_selected, position, m_expl);
m_drawer.color3f(1.0f,0.0f,0.0f);
Traversor* tra = TraversorFactory<PFP::MAP>::createIncident(myMap, m_selected, 2, VERTEX+m_second2, VERTEX+m_first2);
for (Dart d=tra->begin(); d != tra->end(); d= tra->next())
m_affDarts.push_back(d);
Algo::Render::drawerCells<PFP>(VERTEX+m_first2, m_drawer, myMap, m_affDarts, position, m_expl);
}
else // adjacent
{
Algo::Render::drawerCell<PFP>(VERTEX+m_first2, m_drawer, myMap, m_selected, position, m_expl);
m_drawer.color3f(1.0f,0.0f,0.0f);
Traversor* tra = TraversorFactory<PFP::MAP>::createAdjacent(myMap, m_selected, 2, VERTEX+m_first2, VERTEX+m_second2);
for (Dart d = tra->begin(); d != tra->end(); d = tra->next())
m_affDarts.push_back(d);
Algo::Render::drawerCells<PFP>(VERTEX+m_first2, m_drawer, myMap, m_affDarts, position, m_expl);
}
m_drawer.endList();
// SelectorMarked sm(*m_dm_topo);
m_render_topo->updateData(myMap, position, 0.95f, 0.9f, 0.8f);
updateGL();
}
void MyQT::dynamicMarkOrbit(unsigned int orb)
{
switch(orb)
{
case VERTEX:
m_dm_topo->markOrbit<VERTEX>(m_selected);
break;
case EDGE:
m_dm_topo->markOrbit<EDGE>(m_selected);
break;
case FACE:
m_dm_topo->markOrbit<FACE>(m_selected);
break;
case VOLUME:
m_dm_topo->markOrbit<VOLUME>(m_selected);
break;
default:
break;
}
}
void MyQT::traverse3()
{
if (m_selected == NIL)
return;
m_last=3;
m_affDarts.clear();
m_drawer.newList(GL_COMPILE);
m_drawer.lineWidth(7.0f);
m_drawer.pointSize(9.0f);
m_drawer.color3f(0.0f,0.7f,0.0f);
m_dm_topo->unmarkAll();
//SelectorMarked sm(*m_dm_topo);
if (m_ajd_or_inci3 == 0) // incident
{
Algo::Render::drawerCell<PFP>(VERTEX+m_second3, m_drawer,myMap,m_selected,position,m_expl);
dynamicMarkOrbit(VERTEX+m_second3);
m_drawer.color3f(1.0f,0.0f,0.0f);
Traversor* tra = TraversorFactory<PFP::MAP>::createIncident(myMap,m_selected, 3, VERTEX+m_second3, VERTEX+m_first3);
for (Dart d = tra->begin(); d != tra->end(); d = tra->next())
{
m_affDarts.push_back(d);
dynamicMarkOrbit(VERTEX+m_first3);
}
Algo::Render::drawerCells<PFP>(VERTEX+m_first3, m_drawer, myMap, m_affDarts, position, m_expl);
m_render_topo->updateData(myMap, position, 0.95f, 0.9f, 0.8f); //sm
for (std::vector<Dart>::iterator id = m_affDarts.begin(); id != m_affDarts.end(); ++id)
m_render_topo->setDartColor(*id,0.7f,0.0f,0.0f);
m_render_topo->setDartColor(m_selected,0.0f,0.7f,0.0f);
}
else // adjacent
{
Algo::Render::drawerCell<PFP>(VERTEX+m_first3, m_drawer, myMap, m_selected, position, m_expl);
dynamicMarkOrbit(VERTEX+m_first3);
m_drawer.color3f(1.0f,0.0f,0.0f);
Traversor* tra = TraversorFactory<PFP::MAP>::createAdjacent(myMap,m_selected, 3, VERTEX+m_first3, VERTEX+m_second3);
for (Dart d = tra->begin(); d != tra->end(); d = tra->next())
{
m_affDarts.push_back(d);
dynamicMarkOrbit(VERTEX+m_first3);
}
Algo::Render::drawerCells<PFP>(VERTEX+m_first3, m_drawer, myMap,m_affDarts,position,m_expl);
m_render_topo->updateData(myMap, position, 0.95f, 0.9f, 0.8f); //sm
for (std::vector<Dart>::iterator id=m_affDarts.begin(); id != m_affDarts.end(); ++id)
m_render_topo->setDartColor(*id,0.7f,0.0f,0.0f);
m_render_topo->setDartColor(m_selected,0.0f,0.7f,0.0f);
}
m_drawer.endList();
updateGL();
}
/*
void MyQT::dyn_trav3XXaY(unsigned int first, unsigned int second)
{
unsigned int val = first *16 + second;
switch(val)
{
case 0x00:
break;
case 0x10:
{
Traversor3XXaY<PFP::MAP, VERTEX+1, VERTEX+0> tra(myMap,m_selected);
for (Dart d = tra.begin(); d != tra.end(); d = tra.next())
{
m_affDarts.push_back(d);
m_dm_topo->markOrbit<VERTEX+1>(d);
}
}
break;
case 0x20:
{
Traversor3XXaY<PFP::MAP, VERTEX+2, VERTEX+0> tra(myMap,m_selected);
for (Dart d = tra.begin(); d != tra.end(); d = tra.next())
{
m_affDarts.push_back(d);
m_dm_topo->markOrbit<VERTEX+2>(d);
}
}
break;
case 0x30:
{
Traversor3XXaY<PFP::MAP, VERTEX+3, VERTEX+0> tra(myMap,m_selected);
for (Dart d = tra.begin(); d != tra.end(); d = tra.next())
{
m_affDarts.push_back(d);
m_dm_topo->markOrbit<VERTEX+3>(d);
}
}
break;
case 0x01:
{
Traversor3XXaY<PFP::MAP, VERTEX, VERTEX+1> tra(myMap,m_selected);
for (Dart d = tra.begin(); d != tra.end(); d = tra.next())
{
m_affDarts.push_back(d);
m_dm_topo->markOrbit<VERTEX>(d);
}
}
break;
case 0x21:
{
Traversor3XXaY<PFP::MAP, VERTEX+2, VERTEX+1> tra(myMap,m_selected);
for (Dart d = tra.begin(); d != tra.end(); d = tra.next())
{
m_affDarts.push_back(d);
m_dm_topo->markOrbit<VERTEX+2>(d);
}
}
break;
case 0x31:
{
Traversor3XXaY<PFP::MAP, VERTEX+3, VERTEX+1> tra(myMap,m_selected);
for (Dart d = tra.begin(); d != tra.end(); d = tra.next())
{
m_affDarts.push_back(d);
m_dm_topo->markOrbit<VERTEX+3>(d);
}
}
break;
case 0x02:
{
Traversor3XXaY<PFP::MAP, VERTEX, VERTEX+2> tra(myMap,m_selected);
for (Dart d = tra.begin(); d != tra.end(); d = tra.next())
{
m_affDarts.push_back(d);
m_dm_topo->markOrbit<VERTEX>(d);
}
}
break;
case 0x12:
{
Traversor3XXaY<PFP::MAP, VERTEX+1, VERTEX+2> tra(myMap,m_selected);
for (Dart d = tra.begin(); d != tra.end(); d = tra.next())
{
m_affDarts.push_back(d);
m_dm_topo->markOrbit<VERTEX+1>(d);
}
}
break;
case 0x32:
{
Traversor3XXaY<PFP::MAP, VERTEX+3, VERTEX+2> tra(myMap,m_selected);
for (Dart d = tra.begin(); d != tra.end(); d = tra.next())
{
m_affDarts.push_back(d);
m_dm_topo->markOrbit<VERTEX+3>(d);
}
}
break;
case 0x03:
{
Traversor3XXaY<PFP::MAP, VERTEX, VERTEX+3> tra(myMap,m_selected);
for (Dart d = tra.begin(); d != tra.end(); d = tra.next())
{
m_affDarts.push_back(d);
m_dm_topo->markOrbit<VERTEX>(d);
}
}
break;
case 0x13:
{
Traversor3XXaY<PFP::MAP, VERTEX+1, VERTEX+3> tra(myMap,m_selected);
for (Dart d = tra.begin(); d != tra.end(); d = tra.next())
{
m_affDarts.push_back(d);
m_dm_topo->markOrbit<VERTEX+1>(d);
}
}
break;
case 0x23:
{
Traversor3XXaY<PFP::MAP, VERTEX+2, VERTEX+3> tra(myMap,m_selected);
for (Dart d = tra.begin(); d != tra.end(); d = tra.next())
{
m_affDarts.push_back(d);
m_dm_topo->markOrbit<VERTEX+2>(d);
}
}
break;
}
}
void MyQT::dyn_trav3XY(unsigned int first, unsigned int second)
{
unsigned int val = second *16 + first;
switch(val)
{
case 0x00:
break;
case 0x10:
{
Traversor3XY<PFP::MAP, VERTEX+1, VERTEX+0> tra(myMap,m_selected);
for (Dart d = tra.begin(); d != tra.end(); d = tra.next())
{
m_affDarts.push_back(d);
m_dm_topo->markOrbit<VERTEX+0>(d);
}
}
break;
case 0x20:
{
Traversor3XY<PFP::MAP, VERTEX+2, VERTEX+0> tra(myMap,m_selected);
for (Dart d = tra.begin(); d != tra.end(); d = tra.next())
{
m_affDarts.push_back(d);
m_dm_topo->markOrbit<VERTEX+0>(d);
}
}
break;
case 0x30:
{
Traversor3XY<PFP::MAP, VERTEX+3, VERTEX+0> tra(myMap,m_selected);
for (Dart d = tra.begin(); d != tra.end(); d = tra.next())
{
m_affDarts.push_back(d);
m_dm_topo->markOrbit<VERTEX+0>(d);
}
}
break;
case 0x01:
{
Traversor3XY<PFP::MAP, VERTEX, VERTEX+1> tra(myMap,m_selected);
for (Dart d = tra.begin(); d != tra.end(); d = tra.next())
{
m_affDarts.push_back(d);
m_dm_topo->markOrbit<VERTEX+1>(d);
}
}
break;
case 0x21:
{
Traversor3XY<PFP::MAP, VERTEX+2, VERTEX+1> tra(myMap,m_selected);
for (Dart d = tra.begin(); d != tra.end(); d = tra.next())
{
m_affDarts.push_back(d);
m_dm_topo->markOrbit<VERTEX+1>(d);
}
}
break;
case 0x31:
{
Traversor3XY<PFP::MAP, VERTEX+3, VERTEX+1> tra(myMap,m_selected);
for (Dart d = tra.begin(); d != tra.end(); d = tra.next())
{
m_affDarts.push_back(d);
m_dm_topo->markOrbit<VERTEX+1>(d);
}
}
break;
case 0x02:
{
Traversor3XY<PFP::MAP, VERTEX, VERTEX+2> tra(myMap,m_selected);
for (Dart d = tra.begin(); d != tra.end(); d = tra.next())
{
m_affDarts.push_back(d);
m_dm_topo->markOrbit<VERTEX+2>(d);
}
}
break;
case 0x12:
{
Traversor3XY<PFP::MAP, VERTEX+1, VERTEX+2> tra(myMap,m_selected);
for (Dart d = tra.begin(); d != tra.end(); d = tra.next())
{
m_affDarts.push_back(d);
m_dm_topo->markOrbit<VERTEX+2>(d);
}
}
break;
case 0x32:
{
Traversor3XY<PFP::MAP, VERTEX+3, VERTEX+2> tra(myMap,m_selected);
for (Dart d = tra.begin(); d != tra.end(); d = tra.next())
{
m_affDarts.push_back(d);
m_dm_topo->markOrbit<VERTEX+2>(d);
}
}
break;
case 0x03:
{
Traversor3XY<PFP::MAP, VERTEX, VERTEX+3> tra(myMap,m_selected);
for (Dart d = tra.begin(); d != tra.end(); d = tra.next())
{
m_affDarts.push_back(d);
m_dm_topo->markOrbit<VERTEX+3>(d);
}
}
break;
case 0x13:
{
Traversor3XY<PFP::MAP, VERTEX+1, VERTEX+3> tra(myMap,m_selected);
for (Dart d = tra.begin(); d != tra.end(); d = tra.next())
{
m_affDarts.push_back(d);
m_dm_topo->markOrbit<VERTEX+3>(d);
}
}
break;
case 0x23:
{
Traversor3XY<PFP::MAP, VERTEX+2, VERTEX+3> tra(myMap,m_selected);
for (Dart d = tra.begin(); d != tra.end(); d = tra.next())
{
m_affDarts.push_back(d);
m_dm_topo->markOrbit<VERTEX+3>(d);
}
}
break;
}