Création d'un compte pour un collaborateur extérieur au laboratoire depuis l'intranet ICube : https://intranet.icube.unistra.fr/fr/labs/member/profile

Commit 924c5ab5 authored by Sylvain Thery's avatar Sylvain Thery
Browse files

add tuto for 3D base operator

debug of collapseEdge of 3Map
debug of splitVolume of 3Map
parent 520c1ab5
......@@ -58,6 +58,13 @@ QT4_WRAP_CPP(tuto_oper2_moc tuto_oper2.h)
add_executable( tuto_oper2 tuto_oper2.cpp ${tuto_oper2_ui} ${tuto_oper2_moc})
target_link_libraries( tuto_oper2
${CGoGN_LIBS_D} ${CGoGN_EXT_LIBS} )
QT4_WRAP_UI( tuto_oper3_ui tuto_oper3.ui )
QT4_WRAP_CPP(tuto_oper3_moc tuto_oper3.h)
add_executable( tuto_oper3 tuto_oper3.cpp ${tuto_oper3_ui} ${tuto_oper3_moc})
target_link_libraries( tuto_oper3
${CGoGN_LIBS_D} ${CGoGN_EXT_LIBS} )
QT4_WRAP_UI( tuto_orbits_ui tuto_orbits.ui )
QT4_WRAP_CPP(tuto_orbits_moc tuto_orbits.h)
......
/*******************************************************************************
* 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 "tuto_oper3.h"
#include "Algo/Geometry/boundingbox.h"
#include "Algo/Modelisation/polyhedron.h"
#include "Algo/Modelisation/primitives3d.h"
#include "Algo/Geometry/centroid.h"
#include "Algo/Import/import.h"
#include "Algo/Export/export.h"
using namespace CGoGN ;
int main(int argc, char **argv)
{
// // 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)) );
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::operation(int x)
{
switch(x)
{
case 0:
CGoGNout <<"delete vertex"<<CGoGNendl;
if (m_selected != NIL)
{
dm.markAll();
m_selected=myMap.deleteVertex(m_selected);
m_selected = NIL;
updateMap();
}
break;
case 1:
CGoGNout <<"cut edge"<<CGoGNendl;
if (m_selected != NIL)
{
dm.markAll();
PFP::VEC3 Q = position[myMap.phi1(m_selected)];
myMap.cutEdge(m_selected);
position[myMap.phi1(m_selected)] = (position[m_selected] + Q)/2.0f;
updateMap();
}
break;
case 2:
CGoGNout <<"uncut edge"<<CGoGNendl;
if (m_selected != NIL)
{
dm.markAll();
PFP::VEC3 Q = position[myMap.phi1(m_selected)];
myMap.uncutEdge(m_selected);
updateMap();
}
break;
case 3:
CGoGNout <<"delete edge"<<CGoGNendl;
if (m_selected != NIL)
{
if (myMap.deleteEdgePreCond(m_selected))
{
dm.markAll();
PFP::VEC3 Q = position[myMap.phi1(m_selected)];
myMap.deleteEdge(m_selected);
m_selected = NIL;
updateMap();
}
else
{
CGoGNerr << "Could not delete this edge" << CGoGNendl;
}
}
break;
case 4:
CGoGNout <<"collapse edge"<<CGoGNendl;
if (m_selected != NIL)
{
PFP::VEC3 Q = (position[myMap.phi1(m_selected)] + position[m_selected])/2.0f;
Dart x = myMap.collapseEdge(m_selected);
dm.markAll();
position[x]= Q;
m_selected = NIL;
updateMap();
}
break;
case 5:
CGoGNout <<"split face"<<CGoGNendl;
if (m_selected != NIL)
{
myMap.splitFace(m_selected,m_selected2);
dm.markAll();
updateMap();
}
break;
case 6:
CGoGNout <<"merge volume"<<CGoGNendl;
if (m_selected != NIL)
{
myMap.mergeVolumes(m_selected);
dm.markAll();
updateMap();
}
break;
case 7:
CGoGNout <<"split volume"<<CGoGNendl;
if (!m_selecteds.empty())
{
myMap.splitVolume(m_selecteds);
dm.markAll();
updateMap();
}
break;
default:
break;
}
updateGL();
dock.listOper->setCurrentRow(-1);
}
void MyQT::createMap(int n)
{
myMap.clear(true);
position = myMap.getAttribute<PFP::VEC3>(VERTEX, "position");
if (!position.isValid())
position = myMap.addAttribute<PFP::VEC3>(VERTEX, "position");
Algo::Modelisation::Primitive3D<PFP> prim(myMap, position);
prim.hexaGrid_topo(n,n,n);
prim.embedHexaGrid(1.0f,1.0f,1.0f);
// bounding box of scene
Geom::BoundingBox<PFP::VEC3> bb = Algo::Geometry::computeBoundingBox<PFP>(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();
// 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);
m_render_topo->updateData<PFP>(myMap, position, m_ex1,m_ex2,m_ex3, nb);
}
void MyQT::updateMap()
{
m_render_topo->updateData<PFP>(myMap, position, m_ex1,m_ex2,m_ex3, nb);
}
// initialization GL callback
void MyQT::cb_initGL()
{
glClearColor(1.0f,1.0f,1.0f,1.0f);
m_render_topo = new Algo::Render::GL2::Topo3Render() ;
}
// redraw GL callback (clear and swap already done)
void MyQT::cb_redraw()
{
glEnable( GL_POLYGON_OFFSET_FILL );
glPolygonOffset( 1.0f, 1.0f );
m_render_topo->drawTopo();
glDisable( GL_POLYGON_OFFSET_FILL );
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);
for (std::vector<Dart>::iterator it = m_selecteds.begin(); it != m_selecteds.end(); ++it)
{
m_render_topo->overdrawDart(*it, 11, 0.0f, 0.0f, 1.0f);
}
}
void MyQT::cb_mousePress(int button, int x, int y)
{
if (Shift())
{
Dart d = m_render_topo->picking<PFP>(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 (Control())
{
Dart d = m_render_topo->picking<PFP>(myMap, x,y, nb);
if (button == Qt::LeftButton)
{
if (d != Dart::nil())
m_selecteds.push_back(d);
}
updateGL();
}
}
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 '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<PFP>(myMap, position, m_ex1,m_ex2,m_ex3, nb);
updateGL();
break;
case 'W':
m_ex1 = 0.9f;
m_ex2 = 0.9f;
m_render_topo->updateData<PFP>(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.isBoundaryMarked(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.isBoundaryMarked(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.isBoundaryMarked(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);
std::string filename = selectFileSave("snapshot file", ".", "(*.svg)");
m_render_topo->svgout2D(filename, modelViewMatrix(),projectionMatrix());
}
void MyQT::cb_Open()
{
std::string filters("all (*.*);; trian (*.trian);; off (*.off);; ply (*.ply);; map (*.map)") ;
std::string filename = selectFile("Open Mesh", "", filters) ;
if (!filename.empty())
importMesh(filename);
updateGL();
}
void MyQT::cb_Save()
{
std::string filename = selectFileSave("Export SVG file ",".","(*.off)");
Algo::Export::exportOFF<PFP>(myMap,position,filename.c_str());
}
void MyQT::importMesh(std::string& filename)
{
myMap.clear(true) ;
size_t pos = filename.rfind("."); // position of "." in filename
std::string extension = filename.substr(pos);
if (extension == std::string(".map"))
{
myMap.loadMapBin(filename);
position = myMap.getAttribute<PFP::VEC3>(VERTEX, "position") ;
}
else
{
std::vector<std::string> attrNames ;
if(!Algo::Import::importMesh<PFP>(myMap, filename.c_str(), attrNames))
{
CGoGNerr << "could not import " << filename << CGoGNendl ;
return;
}
position = myMap.getAttribute<PFP::VEC3>(VERTEX, attrNames[0]) ;
}
m_selected = NIL;
m_selected2 = NIL;
Geom::BoundingBox<PFP::VEC3> bb = Algo::Geometry::computeBoundingBox<PFP>(myMap, position) ;
setParamObject(bb.maxSize(), bb.center().data()) ;
m_shift = bb.maxSize()/200.0f;
updateMap();
updateGLMatrices() ;
}
void MyQT::width(int w)
{
m_ex3 = 0.9f - 0.025f*w;
m_render_topo->updateData<PFP>(myMap, position, m_ex1,m_ex2,m_ex3, nb);
updateGL();
}
/*******************************************************************************
* CGoGN: Combinatorial and Geometric modeling with Generic N-dimensional Maps *
* version 0.1 *
* Copyright (C) 2009-2012, IGG Team, LSIIT, University of Strasbourg *
* *
* This library is free software; you can redistribute it and/or modify it *
* under the terms of the GNU Lesser General Public License as published by the *
* Free Software Foundation; either version 2.1 of the License, or (at your *
* option) any later version. *
* *
* This library is distributed in the hope that it will be useful, but WITHOUT *
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or *
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License *
* for more details. *
* *
* You should have received a copy of the GNU Lesser General Public License *
* along with this library; if not, write to the Free Software Foundation, *
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. *
* *
* Web site: http://cgogn.unistra.fr/ *
* Contact information: cgogn@unistra.fr *
* *
*******************************************************************************/
#ifndef _TUTO_OPER3_
#define _TUTO_OPER3_
//#define USE_GMAP
#include "Topology/generic/parameters.h"
#ifdef USE_GMAP
#include "Topology/gmap/embeddedGMap3.h"
#else
#include "Topology/map/embeddedMap3.h"
#endif
#include "Algo/Render/GL2/topo3Render.h"
#include "ui_tuto_oper3.h"
#include "Utils/Qt/qtui.h"
#include "Utils/Qt/qtSimple.h"
#include "Utils/cgognStream.h"
using namespace CGoGN ;
/**
* Struct that contains some informations about the types of the manipulated objects
* Mainly here to be used by the algorithms that are parameterized by it
*/
struct PFP: public PFP_STANDARD
{
// definition of the type of the map
#ifdef USE_GMAP
typedef EmbeddedGMap3 MAP;
#else
typedef EmbeddedMap3 MAP;
#endif
};
class MyQT: public Utils::QT::SimpleQT
{
Q_OBJECT
public:
MyQT():nb(myMap),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) {}
void cb_redraw();
void cb_initGL();
void cb_mousePress(int button, int x, int y);
void cb_keyPress(int code);
void cb_Open();
void cb_Save();
Utils::QT::uiDockInterface dock;
protected:
// declaration of the map
PFP::MAP myMap;
PFP::TVEC3 position;
// AttributeHandler<Geom::Vec3f> colorDarts;
SelectorDartNoBoundary<PFP::MAP> nb;
// render (for the topo)
Algo::Render::GL2::Topo3Render* m_render_topo;
Dart m_selected;
Dart m_selected2;
std::vector<Dart> m_selecteds;
DartMarker dm;
float m_shift;
float m_ex1,m_ex2,m_ex3;
// just for more compact writing
inline Dart PHI1(Dart d) {return myMap.phi1(d);}
inline Dart PHI_1(Dart d) {return myMap.phi_1(d);}
inline Dart PHI2(Dart d) {return myMap.phi2(d);}
inline Dart PHI3(Dart d) {return myMap.phi3(d);}
template<int X>
Dart PHI(Dart d) {return myMap.phi<X>(d);}
public:
// example of simple map creation
void createMap(int n);
void updateMap();
void importMesh(std::string& filename);
public slots:
void operation(int x);
void svg();
void width(int w);
};
#endif
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>DockWidget</class>
<widget class="QDockWidget" name="DockWidget">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>227</width>
<height>369</height>
</rect>
</property>
<property name="minimumSize">
<size>
<width>150</width>
<height>250</height>
</size>
</property>
<property name="windowTitle">
<string>Interface</string>