From 921efcb1a866c910bc3d1f67e62f9cad2db880b7 Mon Sep 17 00:00:00 2001 From: untereiner Date: Wed, 17 Jul 2013 10:18:25 +0200 Subject: [PATCH] some changes --- Apps/Tuto/show_traversors.cpp | 1032 +++++++------- Apps/Tuto/tuto_oper2.cpp | 20 +- Apps/Tuto/tuto_oper2.h | 14 +- Apps/Tuto/tuto_oper3.cpp | 1231 +++++++++-------- Apps/Tuto/tuto_oper3.h | 15 +- Apps/Tuto/tuto_oper3.ui | 5 + .../ImplicitHierarchicalMesh/subdivision3.hpp | 292 +++- .../Map3MR/Masks/mcCrackenJoy.h | 28 +- .../Map3MR/map3MR_PrimalRegular.hpp | 54 +- src/Utils/svg.cpp | 116 +- 10 files changed, 1587 insertions(+), 1220 deletions(-) diff --git a/Apps/Tuto/show_traversors.cpp b/Apps/Tuto/show_traversors.cpp index a2bd73e3..0cb4b425 100644 --- a/Apps/Tuto/show_traversors.cpp +++ b/Apps/Tuto/show_traversors.cpp @@ -29,6 +29,8 @@ #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" @@ -43,552 +45,562 @@ Dart dglobal; void MyQT::cb_checkTopo(bool b) { - m_showTopo = b; - updateGL(); + m_showTopo = b; + updateGL(); } void MyQT::cb_combo1(int x) { - m_first3 = x; - if (m_first3!=m_second3) - traverse3(); - else - CGoGNerr <<"undefined traversor" << CGoGNendl; + 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; + 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; + 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; + 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; + 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; + 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(); + 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); + // choose to use GL version 2 + Utils::GLSLShader::setCurrentOGLVersion(2); m_render_topo = new Algo::Render::GL2::Topo3Render(); - m_render_topo->updateData(myMap, position, 0.95f, 0.9f, 0.8f); - m_dm_topo = new DartMarker(myMap); + m_render_topo->updateData(myMap, position, 0.95f, 0.9f, 0.8f); + m_dm_topo = new DartMarker(myMap); } void MyQT::cb_redraw() { - if (m_showTopo) - { - m_render_topo->drawTopo(); + if (m_showTopo) + { + m_render_topo->drawTopo(); - if (m_selected != NIL) - m_render_topo->overdrawDart(m_selected, 7, 1.0f, 0.0f, 1.0f); + if (m_selected != NIL) + m_render_topo->overdrawDart(m_selected, 7, 1.0f, 0.0f, 1.0f); - for (std::vector::iterator it=m_affDarts.begin(); it!=m_affDarts.end(); ++it) - { - m_render_topo->overdrawDart(*it, 6, 1.0f, 1.0f, 1.0f); - } - } + for (std::vector::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(); + 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(); - } + 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)"); -// Utils::SVG::SVGOut svg(filename,modelViewMatrix(),projectionMatrix()); -// m_drawer.toSVG(svg); -// m_render_topo->toSVG(svg); + 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 svg1(modelViewMatrix(), projectionMatrix()); - m_drawer.toSVG(svg1); -// 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::SVGOut svg2(modelViewMatrix(), projectionMatrix()); - m_render_topo->toSVG(svg2); -// svg2.addOpacityAnimation(1.0f); -// svg2.addOpacityAnimation(0.0f); -// svg2.addOpacityAnimation(1.0f); +// Utils::SVG::AnimatedSVGOut anim; - Utils::SVG::AnimatedSVGOut anim; +// anim.add(&svg1); +// anim.add(&svg2); + + + +// anim.write(filename, 2.0f); - anim.add(&svg1); - anim.add(&svg2); - std::string filename = selectFileSave("Export SVG file ",".","(*.svg)"); - anim.write(filename, 2.0f); } template void MyQT::colorizeCell(Dart d, float r,float g, float b) { - TraversorDartsOfOrbitdoo (myMap, d); - for (Dart e = doo.begin(); e != doo.end(); e = doo.next()) - m_render_topo->setDartColor(e, r, g, b); + TraversorDartsOfOrbitdoo (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(VERTEX+m_second2, m_drawer, myMap, m_selected, position, m_expl); - m_drawer.color3f(1.0f,0.0f,0.0f); - Traversor* tra = TraversorFactory::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(VERTEX+m_first2, m_drawer, myMap, m_affDarts, position, m_expl); - } - else // adjacent - { - Algo::Render::drawerCell(VERTEX+m_first2, m_drawer, myMap, m_selected, position, m_expl); - m_drawer.color3f(1.0f,0.0f,0.0f); - Traversor* tra = TraversorFactory::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(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(); + 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(VERTEX+m_second2, m_drawer, myMap, m_selected, position, m_expl); + m_drawer.color3f(1.0f,0.0f,0.0f); + Traversor* tra = TraversorFactory::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(VERTEX+m_first2, m_drawer, myMap, m_affDarts, position, m_expl); + } + else // adjacent + { + Algo::Render::drawerCell(VERTEX+m_first2, m_drawer, myMap, m_selected, position, m_expl); + m_drawer.color3f(1.0f,0.0f,0.0f); + Traversor* tra = TraversorFactory::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(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(m_selected); - break; - case EDGE: - m_dm_topo->markOrbit(m_selected); - break; - case FACE: - m_dm_topo->markOrbit(m_selected); - break; - case VOLUME: - m_dm_topo->markOrbit(m_selected); - break; - default: - break; - } + switch(orb) + { + case VERTEX: + m_dm_topo->markOrbit(m_selected); + break; + case EDGE: + m_dm_topo->markOrbit(m_selected); + break; + case FACE: + m_dm_topo->markOrbit(m_selected); + break; + case VOLUME: + m_dm_topo->markOrbit(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(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::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(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::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(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::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(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::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(); + 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(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::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(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::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(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::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(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::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 tra(myMap,m_selected); - for (Dart d = tra.begin(); d != tra.end(); d = tra.next()) - { - m_affDarts.push_back(d); - m_dm_topo->markOrbit(d); - } - } - break; - case 0x20: - { - Traversor3XXaY tra(myMap,m_selected); - for (Dart d = tra.begin(); d != tra.end(); d = tra.next()) - { - m_affDarts.push_back(d); - m_dm_topo->markOrbit(d); - } - } - break; - case 0x30: - { - Traversor3XXaY tra(myMap,m_selected); - for (Dart d = tra.begin(); d != tra.end(); d = tra.next()) - { - m_affDarts.push_back(d); - m_dm_topo->markOrbit(d); - } - } - break; - - case 0x01: - { - Traversor3XXaY tra(myMap,m_selected); - for (Dart d = tra.begin(); d != tra.end(); d = tra.next()) - { - m_affDarts.push_back(d); - m_dm_topo->markOrbit(d); - } - } - break; - case 0x21: - { - Traversor3XXaY tra(myMap,m_selected); - for (Dart d = tra.begin(); d != tra.end(); d = tra.next()) - { - m_affDarts.push_back(d); - m_dm_topo->markOrbit(d); - } - } - break; - case 0x31: - { - Traversor3XXaY tra(myMap,m_selected); - for (Dart d = tra.begin(); d != tra.end(); d = tra.next()) - { - m_affDarts.push_back(d); - m_dm_topo->markOrbit(d); - } - } - break; - - - case 0x02: - { - Traversor3XXaY tra(myMap,m_selected); - for (Dart d = tra.begin(); d != tra.end(); d = tra.next()) - { - m_affDarts.push_back(d); - m_dm_topo->markOrbit(d); - } - } - break; - case 0x12: - { - Traversor3XXaY tra(myMap,m_selected); - for (Dart d = tra.begin(); d != tra.end(); d = tra.next()) - { - m_affDarts.push_back(d); - m_dm_topo->markOrbit(d); - } - } - break; - case 0x32: - { - Traversor3XXaY tra(myMap,m_selected); - for (Dart d = tra.begin(); d != tra.end(); d = tra.next()) - { - m_affDarts.push_back(d); - m_dm_topo->markOrbit(d); - } - } - break; - - case 0x03: - { - Traversor3XXaY tra(myMap,m_selected); - for (Dart d = tra.begin(); d != tra.end(); d = tra.next()) - { - m_affDarts.push_back(d); - m_dm_topo->markOrbit(d); - } - } - break; - case 0x13: - { - Traversor3XXaY tra(myMap,m_selected); - for (Dart d = tra.begin(); d != tra.end(); d = tra.next()) - { - m_affDarts.push_back(d); - m_dm_topo->markOrbit(d); - } - } - break; - case 0x23: - { - Traversor3XXaY tra(myMap,m_selected); - for (Dart d = tra.begin(); d != tra.end(); d = tra.next()) - { - m_affDarts.push_back(d); - m_dm_topo->markOrbit(d); - } - } - break; - - } + unsigned int val = first *16 + second; + switch(val) + { + case 0x00: + break; + case 0x10: + { + Traversor3XXaY tra(myMap,m_selected); + for (Dart d = tra.begin(); d != tra.end(); d = tra.next()) + { + m_affDarts.push_back(d); + m_dm_topo->markOrbit(d); + } + } + break; + case 0x20: + { + Traversor3XXaY tra(myMap,m_selected); + for (Dart d = tra.begin(); d != tra.end(); d = tra.next()) + { + m_affDarts.push_back(d); + m_dm_topo->markOrbit(d); + } + } + break; + case 0x30: + { + Traversor3XXaY tra(myMap,m_selected); + for (Dart d = tra.begin(); d != tra.end(); d = tra.next()) + { + m_affDarts.push_back(d); + m_dm_topo->markOrbit(d); + } + } + break; + + case 0x01: + { + Traversor3XXaY tra(myMap,m_selected); + for (Dart d = tra.begin(); d != tra.end(); d = tra.next()) + { + m_affDarts.push_back(d); + m_dm_topo->markOrbit(d); + } + } + break; + case 0x21: + { + Traversor3XXaY tra(myMap,m_selected); + for (Dart d = tra.begin(); d != tra.end(); d = tra.next()) + { + m_affDarts.push_back(d); + m_dm_topo->markOrbit(d); + } + } + break; + case 0x31: + { + Traversor3XXaY tra(myMap,m_selected); + for (Dart d = tra.begin(); d != tra.end(); d = tra.next()) + { + m_affDarts.push_back(d); + m_dm_topo->markOrbit(d); + } + } + break; + + + case 0x02: + { + Traversor3XXaY tra(myMap,m_selected); + for (Dart d = tra.begin(); d != tra.end(); d = tra.next()) + { + m_affDarts.push_back(d); + m_dm_topo->markOrbit(d); + } + } + break; + case 0x12: + { + Traversor3XXaY tra(myMap,m_selected); + for (Dart d = tra.begin(); d != tra.end(); d = tra.next()) + { + m_affDarts.push_back(d); + m_dm_topo->markOrbit(d); + } + } + break; + case 0x32: + { + Traversor3XXaY tra(myMap,m_selected); + for (Dart d = tra.begin(); d != tra.end(); d = tra.next()) + { + m_affDarts.push_back(d); + m_dm_topo->markOrbit(d); + } + } + break; + + case 0x03: + { + Traversor3XXaY tra(myMap,m_selected); + for (Dart d = tra.begin(); d != tra.end(); d = tra.next()) + { + m_affDarts.push_back(d); + m_dm_topo->markOrbit(d); + } + } + break; + case 0x13: + { + Traversor3XXaY tra(myMap,m_selected); + for (Dart d = tra.begin(); d != tra.end(); d = tra.next()) + { + m_affDarts.push_back(d); + m_dm_topo->markOrbit(d); + } + } + break; + case 0x23: + { + Traversor3XXaY tra(myMap,m_selected); + for (Dart d = tra.begin(); d != tra.end(); d = tra.next()) + { + m_affDarts.push_back(d); + m_dm_topo->markOrbit(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 tra(myMap,m_selected); - for (Dart d = tra.begin(); d != tra.end(); d = tra.next()) - { - m_affDarts.push_back(d); - m_dm_topo->markOrbit(d); - } - } - break; - case 0x20: - { - Traversor3XY tra(myMap,m_selected); - for (Dart d = tra.begin(); d != tra.end(); d = tra.next()) - { - m_affDarts.push_back(d); - m_dm_topo->markOrbit(d); - } - } - break; - case 0x30: - { - Traversor3XY tra(myMap,m_selected); - for (Dart d = tra.begin(); d != tra.end(); d = tra.next()) - { - m_affDarts.push_back(d); - m_dm_topo->markOrbit(d); - } - } - break; - - case 0x01: - { - Traversor3XY tra(myMap,m_selected); - for (Dart d = tra.begin(); d != tra.end(); d = tra.next()) - { - m_affDarts.push_back(d); - m_dm_topo->markOrbit(d); - } - } - break; - case 0x21: - { - Traversor3XY tra(myMap,m_selected); - for (Dart d = tra.begin(); d != tra.end(); d = tra.next()) - { - m_affDarts.push_back(d); - m_dm_topo->markOrbit(d); - } - } - break; - case 0x31: - { - Traversor3XY tra(myMap,m_selected); - for (Dart d = tra.begin(); d != tra.end(); d = tra.next()) - { - m_affDarts.push_back(d); - m_dm_topo->markOrbit(d); - } - } - break; - - - case 0x02: - { - Traversor3XY tra(myMap,m_selected); - for (Dart d = tra.begin(); d != tra.end(); d = tra.next()) - { - m_affDarts.push_back(d); - m_dm_topo->markOrbit(d); - } - } - break; - case 0x12: - { - Traversor3XY tra(myMap,m_selected); - for (Dart d = tra.begin(); d != tra.end(); d = tra.next()) - { - m_affDarts.push_back(d); - m_dm_topo->markOrbit(d); - } - } - break; - case 0x32: - { - Traversor3XY tra(myMap,m_selected); - for (Dart d = tra.begin(); d != tra.end(); d = tra.next()) - { - m_affDarts.push_back(d); - m_dm_topo->markOrbit(d); - } - } - break; - - case 0x03: - { - Traversor3XY tra(myMap,m_selected); - for (Dart d = tra.begin(); d != tra.end(); d = tra.next()) - { - m_affDarts.push_back(d); - m_dm_topo->markOrbit(d); - } - } - break; - case 0x13: - { - Traversor3XY tra(myMap,m_selected); - for (Dart d = tra.begin(); d != tra.end(); d = tra.next()) - { - m_affDarts.push_back(d); - m_dm_topo->markOrbit(d); - } - } - break; - case 0x23: - { - Traversor3XY tra(myMap,m_selected); - for (Dart d = tra.begin(); d != tra.end(); d = tra.next()) - { - m_affDarts.push_back(d); - m_dm_topo->markOrbit(d); - } - } - break; - - } + unsigned int val = second *16 + first; + switch(val) + { + case 0x00: + break; + case 0x10: + { + Traversor3XY tra(myMap,m_selected); + for (Dart d = tra.begin(); d != tra.end(); d = tra.next()) + { + m_affDarts.push_back(d); + m_dm_topo->markOrbit(d); + } + } + break; + case 0x20: + { + Traversor3XY tra(myMap,m_selected); + for (Dart d = tra.begin(); d != tra.end(); d = tra.next()) + { + m_affDarts.push_back(d); + m_dm_topo->markOrbit(d); + } + } + break; + case 0x30: + { + Traversor3XY tra(myMap,m_selected); + for (Dart d = tra.begin(); d != tra.end(); d = tra.next()) + { + m_affDarts.push_back(d); + m_dm_topo->markOrbit(d); + } + } + break; + + case 0x01: + { + Traversor3XY tra(myMap,m_selected); + for (Dart d = tra.begin(); d != tra.end(); d = tra.next()) + { + m_affDarts.push_back(d); + m_dm_topo->markOrbit(d); + } + } + break; + case 0x21: + { + Traversor3XY tra(myMap,m_selected); + for (Dart d = tra.begin(); d != tra.end(); d = tra.next()) + { + m_affDarts.push_back(d); + m_dm_topo->markOrbit(d); + } + } + break; + case 0x31: + { + Traversor3XY tra(myMap,m_selected); + for (Dart d = tra.begin(); d != tra.end(); d = tra.next()) + { + m_affDarts.push_back(d); + m_dm_topo->markOrbit(d); + } + } + break; + + + case 0x02: + { + Traversor3XY tra(myMap,m_selected); + for (Dart d = tra.begin(); d != tra.end(); d = tra.next()) + { + m_affDarts.push_back(d); + m_dm_topo->markOrbit(d); + } + } + break; + case 0x12: + { + Traversor3XY tra(myMap,m_selected); + for (Dart d = tra.begin(); d != tra.end(); d = tra.next()) + { + m_affDarts.push_back(d); + m_dm_topo->markOrbit(d); + } + } + break; + case 0x32: + { + Traversor3XY tra(myMap,m_selected); + for (Dart d = tra.begin(); d != tra.end(); d = tra.next()) + { + m_affDarts.push_back(d); + m_dm_topo->markOrbit(d); + } + } + break; + + case 0x03: + { + Traversor3XY tra(myMap,m_selected); + for (Dart d = tra.begin(); d != tra.end(); d = tra.next()) + { + m_affDarts.push_back(d); + m_dm_topo->markOrbit(d); + } + } + break; + case 0x13: + { + Traversor3XY tra(myMap,m_selected); + for (Dart d = tra.begin(); d != tra.end(); d = tra.next()) + { + m_affDarts.push_back(d); + m_dm_topo->markOrbit(d); + } + } + break; + case 0x23: + { + Traversor3XY tra(myMap,m_selected); + for (Dart d = tra.begin(); d != tra.end(); d = tra.next()) + { + m_affDarts.push_back(d); + m_dm_topo->markOrbit(d); + } + } + break; + + } } */ @@ -597,46 +609,96 @@ void MyQT::dyn_trav3XY(unsigned int first, unsigned int second) int main(int argc, char **argv) { - position = myMap.addAttribute( "position"); - - Algo::Volume::Modelisation::Primitive3D prim(myMap, position); - dglobal = prim.hexaGrid_topo(4,4,4); - prim.embedHexaGrid(1.0f,1.0f,1.0f); + if(argc == 1) + { + position = myMap.addAttribute( "position"); + + Algo::Volume::Modelisation::Primitive3D prim(myMap, position); + dglobal = prim.hexaGrid_topo(3,3,3); + prim.embedHexaGrid(1.0f,1.0f,1.0f); + } + else + { + std::string filename(argv[1]); + size_t pos = filename.rfind("."); // position of "." in filename + std::string extension = filename.substr(pos); + std::vector attrNames ; + + if(extension == std::string(".off")) + { + if(!Algo::Volume::Import::importMeshToExtrude(myMap, filename, attrNames, 1.5, 2)) + { + std::cerr << "could not import " << filename << std::endl ; + return -1; + } + myMap.closeMap(); + } + + // if(extension == std::string(".off")) + // { + // if(!Algo::Surface::Import::importMeshSAsV(myMap, filename, attrNames)) + // { + // std::cerr << "could not import " << std::endl ; + // return ; + // } + // /myMap.closeMap(); + // } + else if(extension == std::string(".map")) + { + myMap.clear(true); + + if(!myMap.loadMapBin(filename)) + { + std::cout << "could not load file" << std::endl; + } + + //myMap.dumpAttributesAndMarkers(); + + position = myMap.getAttribute("position"); + } + else if(!Algo::Volume::Import::importMesh(myMap, filename, attrNames)) + { + std::cerr << "could not import " << filename << std::endl ; + return -1; + } + position = myMap.getAttribute(attrNames[0]) ; + + } // un peu d'interface - QApplication app(argc, argv); - MyQT sqt; + QApplication app(argc, argv); + MyQT sqt; - // interface de tuto5.ui + // interface de tuto5.ui Utils::QT::uiDockInterface dock; sqt.setDock(&dock); - // message d'aide - sqt.setHelpMsg("shit click to select a dart\nand select a traversor\nif keyboard focus problem\nundock"); + // message d'aide + sqt.setHelpMsg("shit click to select a dart\nand select a traversor\nif keyboard focus problem\nundock"); - // bounding box + // bounding box Geom::BoundingBox bb = Algo::Geometry::computeBoundingBox(myMap, position); float lWidthObj = std::max(std::max(bb.size(0), bb.size(1)), bb.size(2)); Geom::Vec3f lPosObj = (bb.min() + bb.max()) / PFP::REAL(2); // envoit info BB a l'interface - sqt.setParamObject(lWidthObj, lPosObj.data()); + sqt.setParamObject(lWidthObj, lPosObj.data()); - sqt.setCallBack( dock.combo1, SIGNAL( activated(int)), SLOT(cb_combo1(int)) ); - sqt.setCallBack( dock.combo2, SIGNAL( activated(int)), SLOT(cb_combo2(int)) ); - sqt.setCallBack( dock.combo3, SIGNAL( activated(int)), SLOT(cb_combo3(int)) ); + sqt.setCallBack( dock.combo1, SIGNAL( activated(int)), SLOT(cb_combo1(int)) ); + sqt.setCallBack( dock.combo2, SIGNAL( activated(int)), SLOT(cb_combo2(int)) ); + sqt.setCallBack( dock.combo3, SIGNAL( activated(int)), SLOT(cb_combo3(int)) ); - sqt.setCallBack( dock.combo4, SIGNAL( activated(int)), SLOT(cb_combo4(int)) ); - sqt.setCallBack( dock.combo5, SIGNAL( activated(int)), SLOT(cb_combo5(int)) ); - sqt.setCallBack( dock.combo6, SIGNAL( activated(int)), SLOT(cb_combo6(int)) ); - sqt.setCallBack( dock.explodeSlider, SIGNAL(valueChanged(int)), SLOT(cb_explode(int)) ); + sqt.setCallBack( dock.combo4, SIGNAL( activated(int)), SLOT(cb_combo4(int)) ); + sqt.setCallBack( dock.combo5, SIGNAL( activated(int)), SLOT(cb_combo5(int)) ); + sqt.setCallBack( dock.combo6, SIGNAL( activated(int)), SLOT(cb_combo6(int)) ); + sqt.setCallBack( dock.explodeSlider, SIGNAL(valueChanged(int)), SLOT(cb_explode(int)) ); - sqt.setCallBack( dock.checkTopo, SIGNAL( clicked(bool)), SLOT(cb_checkTopo(bool)) ); + sqt.setCallBack( dock.checkTopo, SIGNAL( clicked(bool)), SLOT(cb_checkTopo(bool)) ); - sqt.m_selected = NIL; + sqt.m_selected = NIL; - sqt.show(); + sqt.show(); - // et on attend la fin. - return app.exec(); + // et on attend la fin. + return app.exec(); } diff --git a/Apps/Tuto/tuto_oper2.cpp b/Apps/Tuto/tuto_oper2.cpp index 3b03e78c..c3398d38 100644 --- a/Apps/Tuto/tuto_oper2.cpp +++ b/Apps/Tuto/tuto_oper2.cpp @@ -194,7 +194,12 @@ void MyQT::createMap(int n) m_render_topo->setDartWidth(4.0f); m_render_topo->setInitialDartsColor(0.0f,0.0f,0.0f); m_render_topo->setInitialBoundaryDartsColor(0.0f,0.0f,0.0f); - m_render_topo->updateData(myMap, position, 0.9f, 0.9f,true); // nb + +#ifdef PRIMAL_TOPO + m_render_topo->updateData(myMap, position, 0.9); +#else + m_render_topo->updateData(myMap, position, 0.9f, 0.9f,true); +#endif for (Dart d=myMap.begin(); d!=myMap.end(); myMap.next(d)) { @@ -213,7 +218,12 @@ void MyQT::createMap(int n) void MyQT::updateMap() { m_render_topo->setInitialBoundaryDartsColor(0.0f,0.0f,0.0f); - m_render_topo->updateData(myMap, position, 0.9f, 0.9f,true); // nb +#ifdef PRIMAL_TOPO + m_render_topo->updateData(myMap, position, 0.9); +#else + m_render_topo->updateData(myMap, position, 0.9f, 0.9f,true); +#endif + for (Dart d=myMap.begin(); d!=myMap.end(); myMap.next(d)) { if (dm.isMarked(d) && (!myMap.isBoundaryMarked2(d))) @@ -229,7 +239,11 @@ void MyQT::updateMap() void MyQT::cb_initGL() { glClearColor(1.0f,1.0f,1.0f,1.0f); - m_render_topo = new Algo::Render::GL2::TopoRender(0.01f) ; +#ifdef PRIMAL_TOPO + m_render_topo = new Algo::Render::GL2::TopoPrimalRender() ; +#else + m_render_topo = new Algo::Render::GL2::TopoRender(0.01f) ; +#endif } // redraw GL callback (clear and swap already done) diff --git a/Apps/Tuto/tuto_oper2.h b/Apps/Tuto/tuto_oper2.h index 586a10e2..e5ea3d90 100644 --- a/Apps/Tuto/tuto_oper2.h +++ b/Apps/Tuto/tuto_oper2.h @@ -27,6 +27,7 @@ //#define USE_GMAP +//#define PRIMAL_TOPO 1 #include "Topology/generic/parameters.h" @@ -36,8 +37,11 @@ #include "Topology/map/embeddedMap2.h" #endif -#include "Algo/Render/GL2/topoRender.h" - +#ifdef PRIMAL_TOPO + #include "Algo/Render/GL2/topoPrimalRender.h" +#else + #include "Algo/Render/GL2/topoRender.h" +#endif #include "ui_tuto_oper2.h" #include "Utils/Qt/qtui.h" @@ -88,7 +92,11 @@ protected: DartAttribute colorDarts; // render (for the topo) - Algo::Render::GL2::TopoRender* m_render_topo; +#ifdef PRIMAL_TOPO + Algo::Render::GL2::TopoPrimalRender* m_render_topo; +#else + Algo::Render::GL2::TopoRender* m_render_topo; +#endif Dart m_selected; Dart m_selected2; DartMarker dm; diff --git a/Apps/Tuto/tuto_oper3.cpp b/Apps/Tuto/tuto_oper3.cpp index ceae3c8b..3da7f5cf 100644 --- a/Apps/Tuto/tuto_oper3.cpp +++ b/Apps/Tuto/tuto_oper3.cpp @@ -37,696 +37,753 @@ using namespace CGoGN ; int main(int argc, char **argv) { - // // interface - QApplication app(argc, argv); - MyQT sqt; + // // interface + QApplication app(argc, argv); + MyQT sqt; sqt.setDock(& sqt.dock); sqt.setCallBack( sqt.dock.listOper, SIGNAL(currentRowChanged(int)), SLOT(operation(int)) ); sqt.setCallBack( sqt.dock.svg, SIGNAL(clicked()), SLOT(svg()) ); sqt.setCallBack( sqt.dock.widthSlider, SIGNAL(valueChanged(int)), SLOT(width(int)) ); - sqt.setCallBack( sqt.dock.checkBox_hide, SIGNAL(toggled(bool)), SLOT(hide_onoff(bool)) ); - sqt.setCallBack( sqt.dock.checkBox_plane, SIGNAL(toggled(bool)), SLOT(clipping_onoff(bool)) ); - int n=3; - if (argc==2) - n = atoi(argv[1]); - - // example code itself - sqt.createMap(n); - - sqt.width(5); - - // set help message in menu - sqt.setHelpMsg("First Tuto: \nCreate two faces\nsew them\nand affect positions"); - // final show for redraw - sqt.show(); - // and wait for the end - return app.exec(); + sqt.setCallBack( sqt.dock.checkBox_hide, SIGNAL(toggled(bool)), SLOT(hide_onoff(bool)) ); + sqt.setCallBack( sqt.dock.checkBox_plane, SIGNAL(toggled(bool)), SLOT(clipping_onoff(bool)) ); + int n=3; + if (argc==2) + n = atoi(argv[1]); + + // example code itself + sqt.createMap(n); + + sqt.width(5); + + // set help message in menu + sqt.setHelpMsg("First Tuto: \nCreate two faces\nsew them\nand affect positions"); + // final show for redraw + sqt.show(); + // and wait for the end + return app.exec(); } void MyQT::clipping_onoff(bool x) { - clip_volume = x; - - if (clip_volume) - { - Geom::Vec3f pos = m_PlanePick->getPosition(); - float pipo; - Geom::Vec3f normal = m_PlanePick->getAxisScale(2, pipo); // 2 = Z axis = plane normal - m_sh1->setClipPlaneParamsAll(clip_id1, normal, pos); - m_sh2->setClipPlaneParamsAll(clip_id2, normal, pos); - m_sh3->setClipPlaneParamsAll(clip_id3, normal, pos); - m_sh4->setClipPlaneParamsAll(clip_id4, normal, pos); - } - else - { - m_sh1->setClipPlaneParamsAll(clip_id1, Geom::Vec3f(0,0,1), Geom::Vec3f(0,0,999999.9f)); - m_sh2->setClipPlaneParamsAll(clip_id2, Geom::Vec3f(0,0,1), Geom::Vec3f(0,0,999999.9f)); - m_sh3->setClipPlaneParamsAll(clip_id3, Geom::Vec3f(0,0,1), Geom::Vec3f(0,0,999999.9f)); - m_sh4->setClipPlaneParamsAll(clip_id4, Geom::Vec3f(0,0,1), Geom::Vec3f(0,0,999999.9f)); - - m_sh1->setClipColorAttenuationFactorRelative(0.0f,0.0f); - m_sh2->setClipColorAttenuationFactorRelative(0.0f,0.0f); - m_sh3->setClipColorAttenuationFactorRelative(0.0f,0.0f); - m_sh4->setClipColorAttenuationFactorRelative(0.0f,0.0f); - - } - updateMap(); - updateGL(); + clip_volume = x; + + if (clip_volume) + { + Geom::Vec3f pos = m_PlanePick->getPosition(); + float pipo; + Geom::Vec3f normal = m_PlanePick->getAxisScale(2, pipo); // 2 = Z axis = plane normal + m_sh1->setClipPlaneParamsAll(clip_id1, normal, pos); + m_sh2->setClipPlaneParamsAll(clip_id2, normal, pos); + m_sh3->setClipPlaneParamsAll(clip_id3, normal, pos); + m_sh4->setClipPlaneParamsAll(clip_id4, normal, pos); + } + else + { + m_sh1->setClipPlaneParamsAll(clip_id1, Geom::Vec3f(0,0,1), Geom::Vec3f(0,0,999999.9f)); + m_sh2->setClipPlaneParamsAll(clip_id2, Geom::Vec3f(0,0,1), Geom::Vec3f(0,0,999999.9f)); + m_sh3->setClipPlaneParamsAll(clip_id3, Geom::Vec3f(0,0,1), Geom::Vec3f(0,0,999999.9f)); + m_sh4->setClipPlaneParamsAll(clip_id4, Geom::Vec3f(0,0,1), Geom::Vec3f(0,0,999999.9f)); + + m_sh1->setClipColorAttenuationFactorRelative(0.0f,0.0f); + m_sh2->setClipColorAttenuationFactorRelative(0.0f,0.0f); + m_sh3->setClipColorAttenuationFactorRelative(0.0f,0.0f); + m_sh4->setClipColorAttenuationFactorRelative(0.0f,0.0f); + + } + updateMap(); + updateGL(); } void MyQT::hide_onoff(bool /*x*/) { - hide_clipping = !hide_clipping; - updateMap(); - updateGL(); + hide_clipping = !hide_clipping; + updateMap(); + updateGL(); } void MyQT::operation(int x) { - switch(x) - { - case 0: - CGoGNout <<"delete vertex"<::iterator it = m_selecteds.begin() ; it != m_selecteds.end() ; ++it) - std::cout << *it << " et phi2() = " << myMap.phi2(*it) << std::endl; - std::cout << "end" << std::endl; - - myMap.splitVolume(m_selecteds); - m_selecteds.clear(); - - dm.markAll(); - updateMap(); - } - break; - case 8: - CGoGNout <<"collapse face"<(myMap,m_selected,position); - Dart x = myMap.collapseFace(m_selected); - dm.markAll(); - position[x]= Q; - m_selected = NIL; - updateMap(); - } - break; - case 9: - CGoGNout <<"collapse volume"<(myMap,m_selected,position); - Dart x = myMap.collapseVolume(m_selected); - dm.markAll(); - position[x]= Q; - m_selected = NIL; - updateMap(); - } - break; - case 10: - CGoGNout <<"split vertex"<(myMap, dit, position); - Dart dres = myMap.splitVertex(m_selecteds); - //Dart dres = Algo::Modelisation::Tetrahedralization::splitVertex(myMap, m_selecteds); - position[dres] = position[dit] + Q*0.25f; - //position[dit] = position[dit] - c1*0.5f; - m_selecteds.clear(); - m_selected = NIL; - dm.markAll(); - updateMap(); - std::cout << "nb darts after = " << myMap.getNbDarts() << std::endl; - } - break; - case 11 : - CGoGNout <<"unsew volumes"<setCurrentRow(-1); + switch(x) + { + case 0: + CGoGNout <<"delete vertex"<::iterator it = m_selecteds.begin() ; it != m_selecteds.end() ; ++it) + std::cout << *it << " et phi2() = " << myMap.phi2(*it) << std::endl; + std::cout << "end" << std::endl; + + myMap.splitVolume(m_selecteds); + m_selecteds.clear(); + updateMap(); + } + break; + case 8: + CGoGNout <<"collapse face"<(myMap,m_selected,position); + Dart x = myMap.collapseFace(m_selected); + position[x]= Q; + m_selected = NIL; + updateMap(); + } + break; + case 9: + CGoGNout <<"collapse volume"<(myMap,m_selected,position); + Dart x = myMap.collapseVolume(m_selected); + position[x]= Q; + m_selected = NIL; + updateMap(); + } + break; + case 10: + CGoGNout <<"split vertex"<(myMap, dit, position); + Dart dres = myMap.splitVertex(m_selecteds); + //Dart dres = Algo::Modelisation::Tetrahedralization::splitVertex(myMap, m_selecteds); + position[dres] = position[dit] + Q*0.25f; + //position[dit] = position[dit] - c1*0.5f; + m_selecteds.clear(); + m_selected = NIL; + updateMap(); + std::cout << "nb darts after = " << myMap.getNbDarts() << std::endl; + } + break; + case 11 : + CGoGNout <<"unsew volumes"<setCurrentRow(-1); } void MyQT::createMap(int n) { - myMap.clear(true); - position = myMap.getAttribute("position"); - if (!position.isValid()) - position = myMap.addAttribute("position"); - Algo::Volume::Modelisation::Primitive3D prim(myMap, position); - prim.hexaGrid_topo(n,n,n); - prim.embedHexaGrid(1.0f,1.0f,1.0f); + myMap.clear(true); + position = myMap.getAttribute("position"); + if (!position.isValid()) + position = myMap.addAttribute("position"); + Algo::Volume::Modelisation::Primitive3D prim(myMap, position); + prim.hexaGrid_topo(n,n,n); + prim.embedHexaGrid(1.0f,1.0f,1.0f); -// Algo::Surface::Modelisation::Polyhedron poly(myMap, position); -// poly.cylinder_topo(6,1,true,true); -// poly.embedCylinder(6.0,6.0,5.0); + // Algo::Surface::Modelisation::Polyhedron poly(myMap, position); + // poly.cylinder_topo(6,1,true,true); + // poly.embedCylinder(6.0,6.0,5.0); - myMap.closeMap(); + myMap.closeMap(); -// Dart d = Algo::Surface::Modelisation::embedPrism(myMap, position, 5, true,6.0,6.0,5.0); -// Dart d2 = Algo::Surface::Modelisation::embedPyramid(myMap, position, 4, true,6.0,5.0); + // Dart d = Algo::Surface::Modelisation::embedPrism(myMap, position, 5, true,6.0,6.0,5.0); + // Dart d2 = Algo::Surface::Modelisation::embedPyramid(myMap, position, 4, true,6.0,5.0); -// myMap.sewVolumes(myMap.phi2(d),d2); -// position[myMap.phi_1(myMap.phi2(d2))] += VEC3(9.0,-5.0,-2.5); + // myMap.sewVolumes(myMap.phi2(d),d2); + // position[myMap.phi_1(myMap.phi2(d2))] += VEC3(9.0,-5.0,-2.5); - myMap.check(); + myMap.check(); // bounding box of scene - bb = Algo::Geometry::computeBoundingBox(myMap, position) ; - setParamObject(bb.maxSize(), bb.center().data()) ; - m_shift = bb.maxSize()/200.0f; + bb = Algo::Geometry::computeBoundingBox(myMap, position) ; + setParamObject(bb.maxSize(), bb.center().data()) ; + m_shift = bb.maxSize()/200.0f; - // first show for be sure that GL context is binded - show(); + // first show for be sure that GL context is binded + show(); - // render the topo of the map without boundary darts + // render the topo of the map without boundary darts - m_render_topo->setDartWidth(3.0f); - m_render_topo->setInitialDartsColor(0.0f,0.0f,0.0f); - updateMap(); + m_render_topo->setDartWidth(3.0f); + m_render_topo->setInitialDartsColor(0.0f,0.0f,0.0f); + updateMap(); } void MyQT::updateMap() { - m_render_topo->updateData(myMap, position, m_ex1,m_ex2,m_ex3/*, nb*/); - m_render_topo_boundary->updateDataBoundary(myMap,position,m_ex1,m_ex2,m_shift); +#ifdef PRIMAL_TOPO + m_render_topo->updateData(myMap, position, m_ex1, m_ex2); +#else + m_render_topo->updateData(myMap, position, m_ex1,m_ex2,m_ex3); +#endif + m_render_topo_boundary->updateDataBoundary(myMap,position,m_ex1,m_ex2,m_shift); } // initialization GL callback void MyQT::cb_initGL() { - glClearColor(1.0f,1.0f,1.0f,1.0f); - m_render_topo = new Algo::Render::GL2::Topo3Render() ; + glClearColor(1.0f,1.0f,1.0f,1.0f); - m_render_topo_boundary = new Algo::Render::GL2::TopoRender(); - m_render_topo_boundary->setInitialDartsColor(0.0f,0.9f,0.0f); +#ifdef PRIMAL_TOPO + m_render_topo = new Algo::Render::GL2::Topo3PrimalRender() ; +#else + m_render_topo = new Algo::Render::GL2::Topo3Render() ; +#endif + m_render_topo_boundary = new Algo::Render::GL2::TopoRender(); + m_render_topo_boundary->setInitialDartsColor(0.0f,0.9f,0.0f); m_PlanePick = new Utils::Pickable(Utils::Pickable::GRID,1); - m_frame = new Utils::FrameManipulator(); - m_frame->setSize(bb.maxSize()); + m_frame = new Utils::FrameManipulator(); + m_frame->setSize(bb.maxSize()); - m_sh1 = static_cast(m_render_topo->shader1()); - m_sh2 = static_cast(m_render_topo->shader2()); - m_sh3 = static_cast(m_render_topo_boundary->shader1()); - m_sh4 = static_cast(m_render_topo_boundary->shader2()); + m_sh1 = static_cast(m_render_topo->shader1()); + m_sh2 = static_cast(m_render_topo->shader2()); + m_sh3 = static_cast(m_render_topo_boundary->shader1()); + m_sh4 = static_cast(m_render_topo_boundary->shader2()); - m_sh1->insertClippingCode(); - m_sh2->insertClippingCode(); - m_sh3->insertClippingCode(); - m_sh4->insertClippingCode(); + m_sh1->insertClippingCode(); + m_sh2->insertClippingCode(); + m_sh3->insertClippingCode(); + m_sh4->insertClippingCode(); - clip_id1 = m_sh1->addClipPlane(); - clip_id2 = m_sh2->addClipPlane(); - clip_id3 = m_sh3->addClipPlane(); - clip_id4 = m_sh4->addClipPlane(); + clip_id1 = m_sh1->addClipPlane(); + clip_id2 = m_sh2->addClipPlane(); + clip_id3 = m_sh3->addClipPlane(); + clip_id4 = m_sh4->addClipPlane(); - m_sh1->setClipPlaneParamsAll(clip_id1, Geom::Vec3f(0,0,1), bb.center()); - m_sh2->setClipPlaneParamsAll(clip_id2, Geom::Vec3f(0,0,1), bb.center()); - m_sh3->setClipPlaneParamsAll(clip_id3, Geom::Vec3f(0,0,1), bb.center()); - m_sh4->setClipPlaneParamsAll(clip_id4, Geom::Vec3f(0,0,1), bb.center()); + m_sh1->setClipPlaneParamsAll(clip_id1, Geom::Vec3f(0,0,1), bb.center()); + m_sh2->setClipPlaneParamsAll(clip_id2, Geom::Vec3f(0,0,1), bb.center()); + m_sh3->setClipPlaneParamsAll(clip_id3, Geom::Vec3f(0,0,1), bb.center()); + m_sh4->setClipPlaneParamsAll(clip_id4, Geom::Vec3f(0,0,1), bb.center()); } // redraw GL callback (clear and swap already done) void MyQT::cb_redraw() { - glEnable( GL_POLYGON_OFFSET_FILL ); - glPolygonOffset( 1.0f, 1.0f ); + glEnable( GL_POLYGON_OFFSET_FILL ); + glPolygonOffset( 1.0f, 1.0f ); - m_render_topo->drawTopo(); + m_render_topo->drawTopo(); - m_render_topo_boundary->drawTopo(); + // m_render_topo_boundary->drawTopo(); - glDisable( GL_POLYGON_OFFSET_FILL ); + glDisable( GL_POLYGON_OFFSET_FILL ); - if (m_selected != NIL) - m_render_topo->overdrawDart(m_selected, 11, 1.0f, 0.0f, 0.0f); + if (m_selected != NIL) + m_render_topo->overdrawDart(m_selected, 11, 1.0f, 0.0f, 0.0f); - if (m_selected2 != NIL) - m_render_topo->overdrawDart(m_selected2, 11, 0.0f, 1.0f, 0.0f); + if (m_selected2 != NIL) + m_render_topo->overdrawDart(m_selected2, 11, 0.0f, 1.0f, 0.0f); - for (std::vector::iterator it = m_selecteds.begin(); it != m_selecteds.end(); ++it) - { - m_render_topo->overdrawDart(*it, 11, 0.0f, 0.0f, 1.0f); - } + for (std::vector::iterator it = m_selecteds.begin(); it != m_selecteds.end(); ++it) + { + m_render_topo->overdrawDart(*it, 11, 0.0f, 0.0f, 1.0f); + } - if (clip_volume && !hide_clipping) - { - m_frame->draw(); - m_PlanePick->draw(); - } + if (clip_volume && !hide_clipping) + { + m_frame->draw(); + m_PlanePick->draw(); + } } void MyQT::cb_mousePress(int button, int x, int y) { - if (Shift()) - { - Dart d = m_render_topo->picking(myMap, x,y/*,nb*/); - if (button == Qt::LeftButton) - { - if (d != Dart::nil()) - m_selected = d; - } - if (button == Qt::RightButton) - { - if (d != Dart::nil()) - m_selected2 = d; - } - updateGL(); - - if (hide_clipping || !clip_volume) - return; - - m_begX = x; - m_begY = y; - - // get ray of selection - Geom::Vec3f rayA,rayB; - float dist = getOrthoScreenRay(x,y,rayA,rayB); - Geom::Vec3f AB = rayB-rayA; - - unsigned int fr_picked =0; - // picking the frame -> axis - fr_picked = m_frame->pick(rayA,AB,dist); - - if (fr_picked != 0) - { - m_pickedAxis=fr_picked; - m_frame->highlight(m_pickedAxis); - m_frame->storeProjection(m_pickedAxis); - updateGL(); - } - } - - if (Control()) - { -// Dart d = m_render_topo->picking(myMap, x,y/*, nb*/); -// if (button == Qt::LeftButton) -// { -// if (d != Dart::nil()) -// m_selecteds.push_back(d); -// } -// updateGL(); - - - if (button == Qt::LeftButton) - { - Dart d = m_render_topo_boundary->picking(myMap, x,y,true); - if (d != Dart::nil()) - { - Dart e = myMap.phi2(d); - std::cout << "Dart "<< d.index << " / phi2:" << e.index << std::endl; - } - } - if (button == Qt::RightButton) - { - Dart d = m_render_topo->picking(myMap, x,y/*, nb*/); - if (d != Dart::nil()) - { - Dart e = myMap.phi2(d); - std::cout << "Dart "<< d.index << " / phi2:" << e.index << std::endl; - } - } - - - updateGL(); - - } + if (Shift()) + { + Dart d = m_render_topo->picking(myMap, x,y/*,nb*/); + if (button == Qt::LeftButton) + { + if (d != Dart::nil()) + m_selected = d; + } + if (button == Qt::RightButton) + { + if (d != Dart::nil()) + m_selected2 = d; + } + updateGL(); + + if (hide_clipping || !clip_volume) + return; + + m_begX = x; + m_begY = y; + + // get ray of selection + Geom::Vec3f rayA,rayB; + float dist = getOrthoScreenRay(x,y,rayA,rayB); + Geom::Vec3f AB = rayB-rayA; + + unsigned int fr_picked =0; + // picking the frame -> axis + fr_picked = m_frame->pick(rayA,AB,dist); + + if (fr_picked != 0) + { + m_pickedAxis=fr_picked; + m_frame->highlight(m_pickedAxis); + m_frame->storeProjection(m_pickedAxis); + updateGL(); + } + } + + if (Control()) + { + if (button == Qt::LeftButton) + { + Dart d = m_render_topo_boundary->picking(myMap, x,y,true); + if (d != Dart::nil()) + { + Dart e = myMap.phi2(d); + std::cout << "Dart "<< d.index << " / phi2:" << e.index << std::endl; + } + } + if (button == Qt::RightButton) + { + Dart d = m_render_topo->picking(myMap, x,y/*, nb*/); + if (d != Dart::nil()) + { + m_selecteds.push_back(d); + Dart e = myMap.phi2(d); + std::cout << "Dart "<< d.index << " / phi2:" << e.index << std::endl; + } + } + + + updateGL(); + + } } void MyQT::cb_mouseRelease(int /*button*/, int /*x*/, int /*y*/) { - if (hide_clipping || !clip_volume) - return; + if (hide_clipping || !clip_volume) + return; - m_pickedAxis=0; - m_frame->highlight(m_pickedAxis); - updateGL(); + m_pickedAxis=0; + m_frame->highlight(m_pickedAxis); + updateGL(); } void MyQT::cb_mouseMove(int buttons, int x, int y) { - if (!Shift()) - return; - - if (hide_clipping || !clip_volume) - return; - - // rotation selected ? - if (Utils::FrameManipulator::rotationAxis(m_pickedAxis)) - { - if (buttons&1) - { - float angle = m_frame->angleFromMouse(x,y,x-m_begX, y-m_begY); - m_frame->rotate(m_pickedAxis, angle); - } - else if (buttons&2) - m_frame->rotateInScreen(x-m_begX, y-m_begY); - - m_PlanePick->transfo() = m_frame->transfo(); - } - // translation selected - else if (Utils::FrameManipulator::translationAxis(m_pickedAxis)) - { - if (buttons&1) - { - float dist = m_frame->distanceFromMouse(x-m_begX, y-m_begY); - m_frame->translate(m_pickedAxis, dist); - } - else if (buttons&2) - m_frame->translateInScreen(x-m_begX, y-m_begY); - - m_PlanePick->transfo() = m_frame->transfo(); - } - // scale selected - else if (Utils::FrameManipulator::scaleAxis(m_pickedAxis) ) - { - float scale = m_frame->scaleFromMouse(x-m_begX, y-m_begY); - m_frame->scale(m_pickedAxis, scale ); - m_PlanePick->transfo() = m_frame->transfo(); - } - - Geom::Vec3f pos = m_PlanePick->getPosition(); - float pipo; - Geom::Vec3f normal = m_PlanePick->getAxisScale(2, pipo); // 2 = Z axis = plane normal - - m_sh1->setClipPlaneParamsAll(clip_id1, normal, pos); - m_sh2->setClipPlaneParamsAll(clip_id2, normal, pos); - m_sh3->setClipPlaneParamsAll(clip_id3, normal, pos); - m_sh4->setClipPlaneParamsAll(clip_id4, normal, pos); - - - m_begX = x; - m_begY = y; - updateGL(); - return; + if (!Shift()) + return; + + if (hide_clipping || !clip_volume) + return; + + // rotation selected ? + if (Utils::FrameManipulator::rotationAxis(m_pickedAxis)) + { + if (buttons&1) + { + float angle = m_frame->angleFromMouse(x,y,x-m_begX, y-m_begY); + m_frame->rotate(m_pickedAxis, angle); + } + else if (buttons&2) + m_frame->rotateInScreen(x-m_begX, y-m_begY); + + m_PlanePick->transfo() = m_frame->transfo(); + } + // translation selected + else if (Utils::FrameManipulator::translationAxis(m_pickedAxis)) + { + if (buttons&1) + { + float dist = m_frame->distanceFromMouse(x-m_begX, y-m_begY); + m_frame->translate(m_pickedAxis, dist); + } + else if (buttons&2) + m_frame->translateInScreen(x-m_begX, y-m_begY); + + m_PlanePick->transfo() = m_frame->transfo(); + } + // scale selected + else if (Utils::FrameManipulator::scaleAxis(m_pickedAxis) ) + { + float scale = m_frame->scaleFromMouse(x-m_begX, y-m_begY); + m_frame->scale(m_pickedAxis, scale ); + m_PlanePick->transfo() = m_frame->transfo(); + } + + Geom::Vec3f pos = m_PlanePick->getPosition(); + float pipo; + Geom::Vec3f normal = m_PlanePick->getAxisScale(2, pipo); // 2 = Z axis = plane normal + + m_sh1->setClipPlaneParamsAll(clip_id1, normal, pos); + m_sh2->setClipPlaneParamsAll(clip_id2, normal, pos); + m_sh3->setClipPlaneParamsAll(clip_id3, normal, pos); + m_sh4->setClipPlaneParamsAll(clip_id4, normal, pos); + + + m_begX = x; + m_begY = y; + updateGL(); + return; } void MyQT::cb_keyPress(int keycode) { - switch(keycode) - { - - case ' ': - m_selecteds.clear(); - m_selected=NIL; - m_selected2=NIL; - updateGL(); - break; - case '2': - createMap(2); - updateMap(); - updateGL(); - break; - case '3': - createMap(3); - updateMap(); - updateGL(); - break; - case '4': - createMap(4); - updateMap(); - updateGL(); - break; - case 'c': - myMap.check(); - break; - case 'a': - m_selected = myMap.phi1(m_selected); - updateGL(); - break; - case 'z': - m_selected = myMap.phi_1(m_selected); - updateGL(); - break; - case 'e': - m_selected = myMap.phi2(m_selected); - updateGL(); - break; - case 'r': - m_selected = myMap.phi3(m_selected); - updateGL(); - break; - case 'q': - m_selected2 = myMap.phi1(m_selected2); - updateGL(); - break; - case 's': - m_selected2 = myMap.phi_1(m_selected2); - updateGL(); - break; - case 'd': - m_selected2 = myMap.phi2(m_selected2); - updateGL(); - break; - case 'f': - m_selected2 = myMap.phi3(m_selected2); - updateGL(); - break; - case 'w': - m_ex1 = 0.99f; - m_ex2 = 0.99f; - m_render_topo->updateData(myMap, position, m_ex1,m_ex2,m_ex3/*, nb*/); - updateGL(); - break; - case 'W': - m_ex1 = 0.95f; - m_ex2 = 0.95f; - m_render_topo->updateData(myMap, position, m_ex1,m_ex2,m_ex3/*, nb*/); - updateGL(); - break; - -// case 'c': -// for (Dart d=myMap.begin(); d!=myMap.end(); myMap.next(d)) -// { -// if (!myMap.isBoundaryMarked3(d)) -// { -// int n = random(); -// float r = float(n&0x7f)/255.0f + 0.25f; -// float g = float((n>>8)&0x7f)/255.0f + 0.25f; -// float b = float((n>>16)&0x7f)/255.0 + 0.25f; -// colorDarts[d] = Geom::Vec3f(r,g,b); -// m_render_topo->setDartColor(d,r,g,b); -// } -// } -// break; -// case 'g': -// for (Dart d=myMap.begin(); d!=myMap.end(); myMap.next(d)) -// { -// if (!myMap.isBoundaryMarked3(d)) -// { -// colorDarts[d] = Geom::Vec3f(0.5f,0.5f,0.5f); -// m_render_topo->setDartColor(d,0.5f,0.5f,0.5f); -// } -// } -// break; -// -// case 'b': -// for (Dart d=myMap.begin(); d!=myMap.end(); myMap.next(d)) -// { -// if (!myMap.isBoundaryMarked3(d)) -// { -// colorDarts[d] = Geom::Vec3f(0.0f,0.0f,0.0f); -// m_render_topo->setDartColor(d,0.0f,0.0f,0.0f); -// } -// } -// break; - case Qt::Key_Up: - if (m_selected!=NIL) - position[m_selected][1] += m_shift; - updateMap(); - updateGL(); - break; - case Qt::Key_Down: - if (m_selected!=NIL) - position[m_selected][1] -= m_shift; - updateMap(); - updateGL(); - break; - case Qt::Key_Left: - if (m_selected!=NIL) - position[m_selected][0] -= m_shift; - updateMap(); - updateGL(); - break; - case Qt::Key_Right: - if (m_selected!=NIL) - position[m_selected][0] += m_shift; - updateMap(); - updateGL(); - break; - } - updateGL(); + switch(keycode) + { + + case ' ': + m_selecteds.clear(); + m_selected=NIL; + m_selected2=NIL; + updateGL(); + break; + case '2': + createMap(2); + updateMap(); + updateGL(); + break; + case '3': + createMap(3); + updateMap(); + updateGL(); + break; + case '4': + createMap(4); + updateMap(); + updateGL(); + break; + case 'c': + myMap.check(); + break; + case 'a': + m_selected = myMap.phi1(m_selected); + updateGL(); + break; + case 'z': + m_selected = myMap.phi_1(m_selected); + updateGL(); + break; + case 'e': + m_selected = myMap.phi2(m_selected); + updateGL(); + break; + case 'r': + m_selected = myMap.phi3(m_selected); + updateGL(); + break; + case 'q': + m_selected2 = myMap.phi1(m_selected2); + updateGL(); + break; + case 's': + m_selected2 = myMap.phi_1(m_selected2); + updateGL(); + break; + case 'd': + m_selected2 = myMap.phi2(m_selected2); + updateGL(); + break; + case 'f': + m_selected2 = myMap.phi3(m_selected2); + updateGL(); + break; + case 'w': + m_ex1 = 0.99f; + m_ex2 = 0.99f; +#ifdef PRIMAL_TOPO + m_render_topo->updateData(myMap, position, m_ex1, m_ex2); +#else + m_render_topo->updateData(myMap, position, m_ex1,m_ex2,m_ex3); +#endif + updateGL(); + break; + case 'W': + m_ex1 = 0.95f; + m_ex2 = 0.95f; +#ifdef PRIMAL_TOPO + m_render_topo->updateData(myMap, position, m_ex1, m_ex2); +#else + m_render_topo->updateData(myMap, position, m_ex1,m_ex2,m_ex3); +#endif + updateGL(); + break; + case '-': + if(Control()) + m_ex2 -= 0.05f; + else + m_ex1 -= 0.05f; +#ifdef PRIMAL_TOPO + m_render_topo->updateData(myMap, position, m_ex1, m_ex2); +#else + m_render_topo->updateData(myMap, position, m_ex1,m_ex2,m_ex3); +#endif + updateGL(); + break; + case '+': + if(Control()) + m_ex2 += 0.05f; + else + m_ex1 += 0.05f; +#ifdef PRIMAL_TOPO + m_render_topo->updateData(myMap, position, m_ex1, m_ex2); +#else + m_render_topo->updateData(myMap, position, m_ex1,m_ex2,m_ex3); +#endif + updateGL(); + break; + case '*': + { + m_selecteds.clear(); + Dart d2 = myMap.phi_1(myMap.phi_1(m_selected)); + myMap.splitFace(m_selected,d2); + Dart d3 = myMap.phi2(myMap.phi1(myMap.phi1(myMap.phi2(m_selected)))); + myMap.splitFace(myMap.phi1(d3),myMap.phi_1(d3)); + + Dart dit = myMap.phi_1(m_selected); + m_selecteds.push_back(dit); + dit = myMap.phi1(myMap.phi2(myMap.phi1(dit))); + m_selecteds.push_back(dit); + dit = myMap.phi1(myMap.phi2(myMap.phi1(dit))); + m_selecteds.push_back(dit); + dit = myMap.phi1(myMap.phi2(myMap.phi1(dit))); + m_selecteds.push_back(dit); + myMap.splitVolume(m_selecteds); + +#ifdef PRIMAL_TOPO + m_render_topo->updateData(myMap, position, m_ex1, m_ex2); +#else + m_render_topo->updateData(myMap, position, m_ex1,m_ex2,m_ex3); +#endif + updateGL(); + } + break; + // case 'c': + // for (Dart d=myMap.begin(); d!=myMap.end(); myMap.next(d)) + // { + // if (!myMap.isBoundaryMarked3(d)) + // { + // int n = random(); + // float r = float(n&0x7f)/255.0f + 0.25f; + // float g = float((n>>8)&0x7f)/255.0f + 0.25f; + // float b = float((n>>16)&0x7f)/255.0 + 0.25f; + // colorDarts[d] = Geom::Vec3f(r,g,b); + // m_render_topo->setDartColor(d,r,g,b); + // } + // } + // break; + // case 'g': + // for (Dart d=myMap.begin(); d!=myMap.end(); myMap.next(d)) + // { + // if (!myMap.isBoundaryMarked3(d)) + // { + // colorDarts[d] = Geom::Vec3f(0.5f,0.5f,0.5f); + // m_render_topo->setDartColor(d,0.5f,0.5f,0.5f); + // } + // } + // break; + // + // case 'b': + // for (Dart d=myMap.begin(); d!=myMap.end(); myMap.next(d)) + // { + // if (!myMap.isBoundaryMarked3(d)) + // { + // colorDarts[d] = Geom::Vec3f(0.0f,0.0f,0.0f); + // m_render_topo->setDartColor(d,0.0f,0.0f,0.0f); + // } + // } + // break; + case Qt::Key_Up: + if (m_selected!=NIL) + position[m_selected][1] += m_shift; + updateMap(); + updateGL(); + break; + case Qt::Key_Down: + if (m_selected!=NIL) + position[m_selected][1] -= m_shift; + updateMap(); + updateGL(); + break; + case Qt::Key_Left: + if (m_selected!=NIL) + position[m_selected][0] -= m_shift; + updateMap(); + updateGL(); + break; + case Qt::Key_Right: + if (m_selected!=NIL) + position[m_selected][0] += m_shift; + updateMap(); + updateGL(); + break; + } + updateGL(); } void MyQT::svg() { - if (m_selected != NIL) - m_render_topo->setDartColor(m_selected, 0.8f, 0.0f, 0.0f); - if (m_selected2 != NIL) - m_render_topo->setDartColor(m_selected2, 0.0f, 0.8f, 0.0f); + if (m_selected != NIL) + m_render_topo->setDartColor(m_selected, 0.8f, 0.0f, 0.0f); + if (m_selected2 != NIL) + m_render_topo->setDartColor(m_selected2, 0.0f, 0.8f, 0.0f); - std::string filename = selectFileSave("snapshot file", ".", "(*.svg)"); - m_render_topo->svgout2D(filename, modelViewMatrix(), projectionMatrix()); + std::string filename = selectFileSave("snapshot file", ".", "(*.svg)"); + m_render_topo->svgout2D(filename, modelViewMatrix(), projectionMatrix()); } void MyQT::cb_Open() { - std::string filters("all (*.*);; map (*.map)") ; - std::string filename = selectFile("Open Mesh", "", filters) ; - if (!filename.empty()) - importMesh(filename); - updateGL(); + std::string filters("all (*.*);; map (*.map)") ; + std::string filename = selectFile("Open Mesh", "", filters) ; + if (!filename.empty()) + importMesh(filename); + updateGL(); } void MyQT::cb_Save() { - std::string filename = selectFileSave("Export MAP file ",".","(*.map)"); - //Algo::Surface::Export::exportOFF(myMap, position, filename.c_str()); // ??? - if(!myMap.saveMapBin(filename)) - std::cout << "could not save file : " << filename << std::endl; + std::string filename = selectFileSave("Export MAP file ",".","(*.map)"); + //Algo::Surface::Export::exportOFF(myMap, position, filename.c_str()); // ??? + if(!myMap.saveMapBin(filename)) + std::cout << "could not save file : " << filename << std::endl; } void MyQT::importMesh(std::string& filename) { - myMap.clear(true) ; - - size_t pos = filename.rfind("."); // position of "." in filename - std::string extension = filename.substr(pos); - std::vector attrNames ; - - if (extension == std::string(".map")) - { - myMap.loadMapBin(filename); - position = myMap.getAttribute("position") ; - } - else if(!Algo::Volume::Import::importMesh(myMap, filename, attrNames)) - { - std::cerr << "could not import " << filename << std::endl ; - return ; - } - else - position = myMap.getAttribute(attrNames[0]) ; - - m_selected = NIL; - m_selected2 = NIL; - -// m_render_topo->updateData(myMap, position, m_ex1,m_ex2,m_ex3/*, nb*/); -// m_render_topo_boundary->updateDataBoundary(myMap,position,m_ex1,m_ex2,m_shift); - - bb = Algo::Geometry::computeBoundingBox(myMap, position) ; - setParamObject(bb.maxSize(), bb.center().data()) ; - m_shift = bb.maxSize()/200.0f; - - m_frame->setSize(bb.maxSize()); - - updateMap(); - updateGLMatrices() ; + myMap.clear(true) ; + + size_t pos = filename.rfind("."); // position of "." in filename + std::string extension = filename.substr(pos); + std::vector attrNames ; + + if (extension == std::string(".map")) + { + myMap.loadMapBin(filename); + position = myMap.getAttribute("position") ; + } + else if(!Algo::Volume::Import::importMesh(myMap, filename, attrNames)) + { + std::cerr << "could not import " << filename << std::endl ; + return ; + } + else + position = myMap.getAttribute(attrNames[0]) ; + + m_selected = NIL; + m_selected2 = NIL; + + // m_render_topo->updateData(myMap, position, m_ex1,m_ex2,m_ex3/*, nb*/); + // m_render_topo_boundary->updateDataBoundary(myMap,position,m_ex1,m_ex2,m_shift); + + bb = Algo::Geometry::computeBoundingBox(myMap, position) ; + setParamObject(bb.maxSize(), bb.center().data()) ; + m_shift = bb.maxSize()/200.0f; + + m_frame->setSize(bb.maxSize()); + + updateMap(); + updateGLMatrices() ; } void MyQT::width(int w) { - m_ex3 = 0.9f - 0.025f*w; - m_render_topo->updateData(myMap, position, m_ex1,m_ex2,m_ex3/*, nb*/); - updateGL(); + m_ex3 = 0.9f - 0.025f*w; +#ifdef PRIMAL_TOPO + m_render_topo->updateData(myMap, position, m_ex1, m_ex2); +#else + m_render_topo->updateData(myMap, position, m_ex1,m_ex2,m_ex3); +#endif + updateGL(); } diff --git a/Apps/Tuto/tuto_oper3.h b/Apps/Tuto/tuto_oper3.h index 32411d8b..3b6b3c73 100644 --- a/Apps/Tuto/tuto_oper3.h +++ b/Apps/Tuto/tuto_oper3.h @@ -27,6 +27,7 @@ //#define USE_GMAP +#define PRIMAL_TOPO 1 #include "Topology/generic/parameters.h" @@ -36,7 +37,12 @@ #include "Topology/map/embeddedMap3.h" #endif -#include "Algo/Render/GL2/topo3Render.h" +#ifdef PRIMAL_TOPO + #include "Algo/Render/GL2/topo3PrimalRender.h" +#else + #include "Algo/Render/GL2/topo3Render.h" +#endif + #include "Algo/Render/GL2/topoRender.h" #include "Algo/Geometry/boundingbox.h" @@ -71,7 +77,7 @@ class MyQT: public Utils::QT::SimpleQT { Q_OBJECT public: - MyQT():m_render_topo(NULL),m_selected(NIL),m_selected2(NIL),dm(myMap),m_shift(0.01f),m_ex1(0.9f),m_ex2(0.9f),m_ex3(0.9f), clip_volume(true) , hide_clipping(false) {} + MyQT():m_render_topo(NULL),m_selected(NIL),m_selected2(NIL),m_shift(0.01f),m_ex1(0.9f),m_ex2(0.9f),m_ex3(0.9f), clip_volume(true) , hide_clipping(false) {} void cb_redraw(); void cb_initGL(); @@ -95,12 +101,15 @@ protected: Geom::BoundingBox bb; // render (for the topo) +#ifdef PRIMAL_TOPO + Algo::Render::GL2::Topo3PrimalRender* m_render_topo; +#else Algo::Render::GL2::Topo3Render* m_render_topo; +#endif Algo::Render::GL2::TopoRender* m_render_topo_boundary; Dart m_selected; Dart m_selected2; std::vector m_selecteds; - DartMarker dm; float m_shift; float m_ex1, m_ex2, m_ex3; diff --git a/Apps/Tuto/tuto_oper3.ui b/Apps/Tuto/tuto_oper3.ui index 1fc06fe2..69a1d4e0 100644 --- a/Apps/Tuto/tuto_oper3.ui +++ b/Apps/Tuto/tuto_oper3.ui @@ -150,6 +150,11 @@ unsewVolumes + + + deleteVolume + + diff --git a/include/Algo/ImplicitHierarchicalMesh/subdivision3.hpp b/include/Algo/ImplicitHierarchicalMesh/subdivision3.hpp index e4676975..200ee415 100644 --- a/include/Algo/ImplicitHierarchicalMesh/subdivision3.hpp +++ b/include/Algo/ImplicitHierarchicalMesh/subdivision3.hpp @@ -1123,6 +1123,214 @@ Dart subdivideVolumeClassic2(typename PFP::MAP& map, Dart d, AttributeHandler +void subdivideEdgeLoop(typename PFP::MAP& map, Dart d, AttributeHandler& position) +{ + assert(map.getDartLevel(d) <= map.getCurrentLevel() || !"Access to a dart introduced after current level") ; + assert(!map.edgeIsSubdivided(d) || !"Trying to subdivide an already subdivided edge") ; + assert(!map.isBoundaryMarked3(d) || !"Trying to subdivide a dart marked boundary"); + + unsigned int eLevel = map.edgeLevel(d) ; + + unsigned int cur = map.getCurrentLevel() ; + map.setCurrentLevel(eLevel) ; + + Dart dd = map.phi2(d) ; + typename PFP::VEC3 p1 = position[d] ; + typename PFP::VEC3 p2 = position[map.phi1(d)] ; + + map.setCurrentLevel(eLevel + 1) ; + + map.cutEdge(d) ; + unsigned int eId = map.getEdgeId(d) ; + map.setEdgeId(map.phi1(d), eId, EDGE) ; //mise a jour de l'id d'arrete sur chaque moitie d'arete + map.setEdgeId(map.phi1(dd), eId, EDGE) ; + + map.setFaceId(EDGE, d) ; //mise a jour de l'id de face sur chaque brin de chaque moitie d'arete + map.setFaceId(EDGE, dd) ; + + position[map.phi1(d)] = (p1 + p2) * typename PFP::REAL(0.5) ; + map.setCurrentLevel(cur) ; +} + +template +void subdivideFaceLoop(typename PFP::MAP& map, Dart d, AttributeHandler& position, SubdivideType sType) +{ + assert(map.getDartLevel(d) <= map.getCurrentLevel() || !"Access to a dart introduced after current level") ; + assert(!map.faceIsSubdivided(d) || !"Trying to subdivide an already subdivided face") ; + assert(!map.isBoundaryMarked3(d) || !"Trying to subdivide a dart marked boundary"); + + unsigned int fLevel = map.faceLevel(d) ; + Dart old = map.faceOldestDart(d) ; + + unsigned int cur = map.getCurrentLevel() ; + map.setCurrentLevel(fLevel) ; // go to the level of the face to subdivide its edges + + unsigned int vLevel = map.volumeLevel(old); + //one level of subdivision in the neighbordhood +// Traversor3VW trav3EW(map, old); +// for(Dart dit = trav3EW.begin() ; dit != trav3EW.end() ; dit = trav3EW.next()) +// { +// Dart oldit = map.volumeOldestDart(dit); +// +// //std::cout << "vLevel courant = " << map.volumeLevel(oldit) << std::endl; +// +// if(((vLevel+1) - map.volumeLevel(oldit)) > 1) +// IHM::subdivideVolumeClassic(map, oldit, position); +// } + + unsigned int degree = 0 ; + typename PFP::VEC3 p ; + Traversor2FE travE(map, old); + for(Dart it = travE.begin(); it != travE.end() ; it = travE.next()) + { + ++degree; + p += position[it] ; + + if(!map.edgeIsSubdivided(it)) // first cut the edges (if they are not already) + IHM::subdivideEdgeLoop(map, it, position) ; // and compute the degree of the face + } + p /= typename PFP::REAL(degree) ; + + + map.setCurrentLevel(fLevel + 1) ; // go to the next level to perform face subdivision + + Dart res; + + if(degree == 3 && sType == IHM::S_TRI) //subdiviser une face triangulaire + { + Dart dd = map.phi1(old) ; + Dart e = map.phi1(map.phi1(dd)) ; + map.splitFace(dd, e) ; // insert a new edge + unsigned int id = map.getNewEdgeId() ; + map.setEdgeId(map.phi_1(dd), id, EDGE) ; // set the edge id of the inserted edge to the next available id + + unsigned int idface = map.getFaceId(old); + map.setFaceId(dd, idface, FACE) ; + map.setFaceId(e, idface, FACE) ; + + dd = e ; + e = map.phi1(map.phi1(dd)) ; + map.splitFace(dd, e) ; + id = map.getNewEdgeId() ; + map.setEdgeId(map.phi_1(dd), id, EDGE) ; + + map.setFaceId(dd, idface, FACE) ; + map.setFaceId(e, idface, FACE) ; + + dd = e ; + e = map.phi1(map.phi1(dd)) ; + map.splitFace(dd, e) ; + id = map.getNewEdgeId() ; + map.setEdgeId(map.phi_1(dd), id, EDGE) ; + + map.setFaceId(dd, idface, FACE) ; + map.setFaceId(e, idface, FACE) ; + + Dart stop = map.phi2(map.phi1(old)); + Dart dit = stop; + do + { + unsigned int dId = map.getEdgeId(map.phi_1(map.phi2(dit))); + unsigned int eId = map.getEdgeId(map.phi1(map.phi2(dit))); + + unsigned int t = dId + eId; + + if(t == 0) + { + map.setEdgeId(dit, 1, EDGE) ; + map.setEdgeId(map.phi2(dit), 1, EDGE) ; + } + else if(t == 1) + { + map.setEdgeId(dit, 2, EDGE) ; + map.setEdgeId(map.phi2(dit), 2, EDGE) ; + } + else if(t == 2) + { + if(dId == eId) + { + map.setEdgeId(dit, 0, EDGE) ; + map.setEdgeId(map.phi2(dit), 0, EDGE) ; + } + else + { + map.setEdgeId(dit, 1, EDGE) ; + map.setEdgeId(map.phi2(dit), 1, EDGE) ; + } + } + else if(t == 3) + { + map.setEdgeId(dit, 0, EDGE) ; + map.setEdgeId(map.phi2(dit), 0, EDGE) ; + } + + dit = map.phi1(dit); + }while(dit != stop); + + } + else + { + Dart dd = map.phi1(old) ; + map.splitFace(dd, map.phi1(map.phi1(dd))) ; + + Dart ne = map.phi2(map.phi_1(dd)); + Dart ne2 = map.phi2(ne); + + map.cutEdge(ne) ; + unsigned int id = map.getNewEdgeId() ; + map.setEdgeId(ne, id, EDGE) ; + id = map.getNewEdgeId() ; + map.setEdgeId(ne2, id, EDGE) ; + + position[map.phi1(ne)] = p ; + + dd = map.phi1(map.phi1(map.phi1(map.phi1(ne)))) ; + while(dd != ne) + { + Dart next = map.phi1(map.phi1(dd)) ; + map.splitFace(map.phi1(ne), dd) ; + Dart nne = map.phi2(map.phi_1(dd)) ; + + id = map.getNewEdgeId() ; + map.setEdgeId(nne, id, EDGE) ; + + dd = next ; + } + + unsigned int idface = map.getFaceId(old); + //Dart e = dd; + do + { + map.setFaceId(dd, idface, DART) ; + map.setFaceId(map.phi2(dd), idface, DART) ; + dd = map.phi2(map.phi1(dd)); + } + while(dd != ne); + + position[map.phi1(ne)] = p ; + } + + map.setCurrentLevel(cur) ; +} + + + + + + + + + template void subdivideLoop(typename PFP::MAP& map, Dart d, AttributeHandler& position) { @@ -1152,7 +1360,7 @@ void subdivideLoop(typename PFP::MAP& map, Dart d, AttributeHandler(map, dit, position, IHM::S_TRI); + IHM::subdivideFaceLoop(map, dit, position, IHM::S_TRI); //save a dart from the subdivided face unsigned int cur = map.getCurrentLevel() ; @@ -1259,60 +1467,60 @@ void subdivideLoop(typename PFP::MAP& map, Dart d, AttributeHandler(f3); - me.markOrbit(f32); - } + me.markOrbit(f3); + me.markOrbit(f32); + } - f = map.phi2(map.phi_1(f)); - }while(f != x); - } + f = map.phi2(map.phi_1(f)); + }while(f != x); + } - map.template setOrbitEmbedding(centralDart, map.template getEmbedding(centralDart)); + map.template setOrbitEmbedding(centralDart, map.template getEmbedding(centralDart)); - //Third step : 3-sew internal faces - for (std::vector >::iterator it = subdividedfaces.begin(); it != subdividedfaces.end(); ++it) - { - Dart f1 = (*it).first; - Dart f2 = (*it).second; + //Third step : 3-sew internal faces + for (std::vector >::iterator it = subdividedfaces.begin(); it != subdividedfaces.end(); ++it) + { + Dart f1 = (*it).first; + Dart f2 = (*it).second; - unsigned int idedge = map.getEdgeId(f1); - map.setEdgeId(map.phi2(f1), idedge, EDGE); - map.setEdgeId(map.phi2(f2), idedge, EDGE); - } + unsigned int idedge = map.getEdgeId(f1); + map.setEdgeId(map.phi2(f1), idedge, EDGE); + map.setEdgeId(map.phi2(f2), idedge, EDGE); + } - } + } map.setCurrentLevel(cur) ; } diff --git a/include/Algo/Multiresolution/Map3MR/Masks/mcCrackenJoy.h b/include/Algo/Multiresolution/Map3MR/Masks/mcCrackenJoy.h index 9f303504..5b032127 100644 --- a/include/Algo/Multiresolution/Map3MR/Masks/mcCrackenJoy.h +++ b/include/Algo/Multiresolution/Map3MR/Masks/mcCrackenJoy.h @@ -50,10 +50,11 @@ namespace Masks /* MJ96 basic functions : polyhedral meshes *********************************************************************************/ -template +template class MJ96VertexVertexFunctor : public FunctorType { protected: + typedef typename EMBV::DATA_TYPE EMB; typename PFP::MAP& m_map ; EMBV& m_attribut; //Algo::Volume::IHM::AttributeHandler_IHM& m_position ; @@ -118,7 +119,7 @@ public: Traversor3VW travVW(m_map, d); for(Dart dit = travVW.begin() ; dit != travVW.end() ; dit = travVW.next()) { - Cavg += Algo::Surface::Geometry::volumeCentroidGen(m_map, dit, m_attribut); + Cavg += Algo::Surface::Geometry::volumeCentroid(m_map, dit, m_attribut); ++degree; } Cavg /= degree; @@ -128,7 +129,7 @@ public: Traversor3VF travVF(m_map, d); for(Dart dit = travVF.begin() ; dit != travVF.end() ; dit = travVF.next()) { - Aavg += Algo::Surface::Geometry::faceCentroidGen(m_map, dit, m_attribut); + Aavg += Algo::Surface::Geometry::faceCentroid(m_map, dit, m_attribut); ++degree; } Aavg /= degree; @@ -156,10 +157,11 @@ public: } }; -template +template class MJ96EdgeVertexFunctor : public FunctorType { protected: + typedef typename EMBV::DATA_TYPE EMB; typename PFP::MAP& m_map ; EMBV& m_attribut; //Algo::Volume::IHM::AttributeHandler_IHM& m_position ; @@ -217,7 +219,7 @@ public: Traversor3EW travEW(m_map, d2); for(Dart dit = travEW.begin() ; dit != travEW.end() ; dit = travEW.next()) { - Cavg += Algo::Surface::Geometry::volumeCentroidGen(m_map, dit, m_attribut); + Cavg += Algo::Surface::Geometry::volumeCentroid(m_map, dit, m_attribut); ++degree; } Cavg /= degree; @@ -227,7 +229,7 @@ public: Traversor3EF travEF(m_map, d2); for(Dart dit = travEF.begin() ; dit != travEF.end() ; dit = travEF.next()) { - Aavg += Algo::Surface::Geometry::faceCentroidGen(m_map, dit, m_attribut); + Aavg += Algo::Surface::Geometry::faceCentroid(m_map, dit, m_attribut); ++degree; } Aavg /= degree; @@ -247,10 +249,11 @@ public: } }; -template +template class MJ96FaceVertexFunctor : public FunctorType { protected: + typedef typename EMBV::DATA_TYPE EMB; typename PFP::MAP& m_map ; EMBV& m_attribut; //Algo::Volume::IHM::AttributeHandler_IHM& m_position ; @@ -291,10 +294,10 @@ public: m_map.decCurrentLevel() ; //face points - EMB C0 = Algo::Surface::Geometry::volumeCentroidGen(m_map, df, m_attribut); - EMB C1 = Algo::Surface::Geometry::volumeCentroidGen(m_map, m_map.phi3(df), m_attribut); + EMB C0 = Algo::Surface::Geometry::volumeCentroid(m_map, df, m_attribut); + EMB C1 = Algo::Surface::Geometry::volumeCentroid(m_map, m_map.phi3(df), m_attribut); - EMB A = Algo::Surface::Geometry::faceCentroidGen(m_map, df, m_attribut); + EMB A = Algo::Surface::Geometry::faceCentroid(m_map, df, m_attribut); EMB fp = C0 + A * 2 + C1; fp /= 4; @@ -309,10 +312,11 @@ public: }; -template +template class MJ96VolumeVertexFunctor : public FunctorType { protected: + typedef typename EMBV::DATA_TYPE EMB; typename PFP::MAP& m_map ; EMBV& m_attribut; //Algo::Volume::IHM::AttributeHandler_IHM& m_position ; @@ -332,7 +336,7 @@ public: //cell points : these points are the average of the //vertices of the lattice that bound the cell - EMB p = Algo::Surface::Geometry::volumeCentroidGen(m_map,df,m_attribut); + EMB p = Algo::Surface::Geometry::volumeCentroid(m_map,df,m_attribut); m_map.incCurrentLevel() ; diff --git a/include/Algo/Multiresolution/Map3MR/map3MR_PrimalRegular.hpp b/include/Algo/Multiresolution/Map3MR/map3MR_PrimalRegular.hpp index cc28bb87..74b13ba1 100644 --- a/include/Algo/Multiresolution/Map3MR/map3MR_PrimalRegular.hpp +++ b/include/Algo/Multiresolution/Map3MR/map3MR_PrimalRegular.hpp @@ -320,42 +320,42 @@ void Map3MR::addNewLevelTetraOcta() } m_map.setCurrentLevel(m_map.getMaxLevel() - 1) ; - for(Dart dit = traW.begin(); dit != traW.end(); dit = traW.next()) - { - Traversor3WV traWV(m_map, dit); + for(Dart dit = traW.begin(); dit != traW.end(); dit = traW.next()) + { + Traversor3WV traWV(m_map, dit); - for(Dart ditWV = traWV.begin(); ditWV != traWV.end(); ditWV = traWV.next()) - { - m_map.setCurrentLevel(m_map.getMaxLevel()) ; - Dart x = m_map.phi_1(m_map.phi2(m_map.phi1(ditWV))); + for(Dart ditWV = traWV.begin(); ditWV != traWV.end(); ditWV = traWV.next()) + { + m_map.setCurrentLevel(m_map.getMaxLevel()) ; + Dart x = m_map.phi_1(m_map.phi2(m_map.phi1(ditWV))); - if(!Algo::Volume::Modelisation::Tetrahedralization::isTetrahedron(m_map,x)) - { - DartMarkerStore me(m_map); + if(!Algo::Volume::Modelisation::Tetrahedralization::isTetrahedron(m_map,x)) + { + DartMarkerStore me(m_map); - Dart f = x; + Dart f = x; - do - { - Dart f3 = m_map.phi3(f); + do + { + Dart f3 = m_map.phi3(f); - if(!me.isMarked(f3)) - { - Dart tmp = m_map.phi_1(m_map.phi2(m_map.phi_1(m_map.phi2(m_map.phi_1(f3))))); //future voisin par phi2 + if(!me.isMarked(f3)) + { + Dart tmp = m_map.phi_1(m_map.phi2(m_map.phi_1(m_map.phi2(m_map.phi_1(f3))))); //future voisin par phi2 - Dart f32 = m_map.phi2(f3); - swapEdges(f3, tmp); + Dart f32 = m_map.phi2(f3); + swapEdges(f3, tmp); - me.markOrbit(f3); - me.markOrbit(f32); - } + me.markOrbit(f3); + me.markOrbit(f32); + } - f = m_map.phi2(m_map.phi_1(f)); - }while(f != x); + f = m_map.phi2(m_map.phi_1(f)); + }while(f != x); - } - m_map.setCurrentLevel(m_map.getMaxLevel() - 1) ; - } + } + m_map.setCurrentLevel(m_map.getMaxLevel() - 1) ; + } } m_map.popLevel() ; diff --git a/src/Utils/svg.cpp b/src/Utils/svg.cpp index 8248e0a1..0ea27e8d 100644 --- a/src/Utils/svg.cpp +++ b/src/Utils/svg.cpp @@ -729,65 +729,65 @@ void AnimatedSVGOut::add(SVGOut* svg) m_svgs.push_back(svg); } -void AnimatedSVGOut::write(const std::string& /*filename*/, float /*timeStep*/) +void AnimatedSVGOut::write(const std::string& filename, float timeStep) { -// std::ofstream outfile(filename.c_str()) ; -// -// unsigned int bbX0=1000000; -// unsigned int bbY0=1000000; -// unsigned int bbX1=0; -// unsigned int bbY1=0; -// -// for (unsigned int i=0; i< m_svgs.size(); ++i) -// m_svgs[i]->computeBB(bbX0, bbY0, bbX1, bbY1); -// -// outfile << ""<< std::endl; -// outfile << ""<< std::endl; -// outfile << "Animated SVG"<< std::endl; -// outfile << ""<< std::endl; -// outfile << "Rendered from CGoGN"<< std::endl; -// outfile << ""<< std::endl; -// -// outfile << ""<< std::endl; -// -// -// for (unsigned int i=0; i< m_svgs.size(); ++i) -// { -// std::vector vds; -// m_svgs[i]->sortSimpleDepth(vds); -// -// outfile << "" << std::endl; -// for (std::vector::iterator it = vds.begin(); it != vds.end(); ++it) -// m_svgs[i]->m_objs[it->obj]->saveOne(outfile,it->id, bbX1-bbX0); -// outfile << "" << std::endl; -// } -// -// outfile << ""<< std::endl; -// -// -// for (unsigned int i=0; i< m_svgs.size(); ++i) -// { -// unsigned int nbo = m_svgs[i]->m_opacities_animations.size(); -// -// outfile << "" << std::endl; -// outfile << "m_opacities_animations[j]; -// if ( j != (nbo-1)) -// outfile<< ";"; -// } -// -// outfile << "\" calcMode=\"discrete\" repeatCount=\"indefinite\" />" << std::endl; -// outfile << "" << std::endl; -// } -// -// outfile << "" << std::endl; -// outfile.close(); +// std::ofstream outfile(filename.c_str()) ; + +// unsigned int bbX0=1000000; +// unsigned int bbY0=1000000; +// unsigned int bbX1=0; +// unsigned int bbY1=0; + +// for (unsigned int i=0; i< m_svgs.size(); ++i) +// m_svgs[i]->computeBB(bbX0, bbY0, bbX1, bbY1); + +// outfile << ""<< std::endl; +// outfile << ""<< std::endl; +// outfile << "Animated SVG"<< std::endl; +// outfile << ""<< std::endl; +// outfile << "Rendered from CGoGN"<< std::endl; +// outfile << ""<< std::endl; + +// outfile << ""<< std::endl; + + +// for (unsigned int i=0; i< m_svgs.size(); ++i) +// { +// std::vector vds; +// m_svgs[i]->sortSimpleDepth(vds); + +// outfile << "" << std::endl; +// for (std::vector::iterator it = vds.begin(); it != vds.end(); ++it) +// m_svgs[i]->m_groups[it->obj]->saveOne(outfile,it->id, bbX1-bbX0); +// outfile << "" << std::endl; +// } + +// outfile << ""<< std::endl; + + +// for (unsigned int i=0; i< m_svgs.size(); ++i) +// { +// unsigned int nbo = m_svgs[i]->m_opacities_animations.size(); + +// outfile << "" << std::endl; +// outfile << "m_opacities_animations[j]; +// if ( j != (nbo-1)) +// outfile<< ";"; +// } + +// outfile << "\" calcMode=\"discrete\" repeatCount=\"indefinite\" />" << std::endl; +// outfile << "" << std::endl; +// } + +// outfile << "" << std::endl; +// outfile.close(); } -- GitLab