Commit 7f5f7fe0 authored by Sylvain Thery's avatar Sylvain Thery
Browse files

Merge branch 'develop'

parents 6b5d560c 413747e6
......@@ -34,3 +34,9 @@ IF (WITH_QT)
ENDIF (WITH_QT)
add_subdirectory(Examples/Tests)
add_subdirectory(Tuto/Traversals)
add_subdirectory(Tuto/Attributes)
add_subdirectory(Tuto/Markers)
add_subdirectory(Tuto/Boundary)
add_subdirectory(Tuto/Modelling)
......@@ -23,6 +23,7 @@
*******************************************************************************/
#include "viewer.h"
#include "Utils/chrono.h"
Viewer::Viewer() :
m_renderStyle(FLAT),
......@@ -196,6 +197,336 @@ void Viewer::cb_keyPress(int keycode)
case 'c' :
myMap.check();
break;
case 'a':
{
Utils::Chrono ch;
ch.start();
VertexAttribute<VEC3,MAP_IMPL> pos2 = myMap.getAttribute<VEC3, VERTEX>("pos2") ;
if(!pos2.isValid())
pos2 = myMap.addAttribute<VEC3, VERTEX>("pos2") ;
for (int i=0; i< 10; ++i)
{
TraversorV<MAP> trav(myMap);
for (Dart d=trav.begin(), d_end = trav.end(); d!=d_end ; d = trav.next())
{
pos2[d] = VEC3(0,0,0);
int nb=0;
Traversor2VVaF<MAP> trf(myMap,d);
for (Dart e = trf.begin(),e_end =trf.end() ; e != e_end; e = trf.next())
{
pos2[d] += position[e];
nb++;
}
pos2[d]/=nb;
}
myMap.swapAttributes(position,pos2);
}
std::cout << "Traversor "<< ch.elapsed()<< " ms "<< std::endl;
Algo::Surface::Geometry::computeNormalVertices<PFP>(myMap, position, normal) ;
m_positionVBO->updateData(position) ;
m_normalVBO->updateData(normal) ;
updateGL();
}
break;
case 'b':
{
Utils::Chrono ch;
ch.start();
VertexAttribute<VEC3,MAP_IMPL> pos2 = myMap.getAttribute<VEC3, VERTEX>("pos2") ;
if(!pos2.isValid())
pos2 = myMap.addAttribute<VEC3, VERTEX>("pos2") ;
for (int i=0; i< 6; ++i)
{
foreach_cell<VERTEX>(myMap, [&] (Vertex d)
{
pos2[d] = VEC3(0,0,0);
int nb=0;
foreach_adjacent2<FACE>(myMap,d,[&](Vertex e)
{
pos2[d] += position[e];
nb++;
});
pos2[d]/=nb;
});
myMap.swapAttributes(position,pos2);
}
std::cout << "Lambda "<< ch.elapsed()<< " ms "<< std::endl;
Algo::Surface::Geometry::computeNormalVertices<PFP>(myMap, position, normal) ;
m_positionVBO->updateData(position) ;
m_normalVBO->updateData(normal) ;
updateGL();
}
break;
case 'B':
{
Utils::Chrono ch;
ch.start();
VertexAttribute<VEC3,MAP_IMPL> pos2 = myMap.getAttribute<VEC3, VERTEX>("pos2") ;
if(!pos2.isValid())
pos2 = myMap.addAttribute<VEC3, VERTEX>("pos2") ;
// foreach_cell_EvenOddd<VERTEX>(myMap, [&] (Vertex d)
// {
// pos2[d] = VEC3(0,0,0);
// int nb=0;
// foreach_adjacent2<FACE>(myMap,d,[&](Vertex e)
// {
// pos2[d] += position[e];
// nb++;
// });
// pos2[d]/=nb;
// },
// [&] (Vertex d)
// {
// position[d] = VEC3(0,0,0);
// int nb=0;
// foreach_adjacent2<FACE>(myMap,d,[&](Vertex e)
// {
// position[d] += pos2[e];
// nb++;
// });
// position[d]/=nb;
// },
// 3);
// std::cout << "Even/Odd "<< ch.elapsed()<< " ms "<< std::endl;
Algo::Surface::Geometry::computeNormalVertices<PFP>(myMap, position, normal) ;
m_positionVBO->updateData(position) ;
m_normalVBO->updateData(normal) ;
updateGL();
}
break;
case 'e':
{
Utils::Chrono ch;
ch.start();
VertexAttribute<VEC3,MAP_IMPL> pos2 = myMap.getAttribute<VEC3, VERTEX>("pos2") ;
if(!pos2.isValid())
pos2 = myMap.addAttribute<VEC3, VERTEX>("pos2") ;
for (int i=0; i< 10; ++i)
{
TraversorV<MAP> trav(myMap);
for (Dart d=trav.begin(), d_end = trav.end(); d!=d_end ; d = trav.next())
{
pos2[d] = VEC3(0,0,0);
int nb=0;
Traversor2VE<MAP> trf(myMap,d);
for (Dart e = trf.begin(),e_end =trf.end() ; e != e_end; e = trf.next())
{
pos2[d] += position[myMap.phi1(e)];
nb++;
}
pos2[d]/=nb;
}
myMap.swapAttributes(position,pos2);
}
std::cout << "Traversor "<< ch.elapsed()<< " ms "<< std::endl;
Algo::Surface::Geometry::computeNormalVertices<PFP>(myMap, position, normal) ;
m_positionVBO->updateData(position) ;
m_normalVBO->updateData(normal) ;
updateGL();
}
break;
case 'f':
{
Utils::Chrono ch;
ch.start();
VertexAttribute<VEC3,MAP_IMPL> pos2 = myMap.getAttribute<VEC3, VERTEX>("pos2") ;
if(!pos2.isValid())
pos2 = myMap.addAttribute<VEC3, VERTEX>("pos2") ;
for (int i=0; i< 10; ++i)
{
foreach_cell<VERTEX>(myMap, [&] (Vertex d)
{
pos2[d] = VEC3(0,0,0);
int nb=0;
foreach_incident2<EDGE>(myMap,d,[&](Edge e)
{
pos2[d] += position[myMap.phi1(e)];
nb++;
});
pos2[d]/=nb;
});
myMap.swapAttributes(position,pos2);
}
std::cout << "Lambda "<< ch.elapsed()<< " ms "<< std::endl;
Algo::Surface::Geometry::computeNormalVertices<PFP>(myMap, position, normal) ;
m_positionVBO->updateData(position) ;
m_normalVBO->updateData(normal) ;
updateGL();
}
break;
case'A':
{
myMap.disableQuickTraversal<VERTEX>() ;
#define NBLOOP 5
Utils::Chrono ch;
ch.start();
{
TraversorCell<MAP, VERTEX,FORCE_CELL_MARKING> trav(myMap,true);
for(unsigned int i=0; i<NBLOOP; ++i)
{
for (Cell<VERTEX> v = trav.begin(), e = trav.end(); v.dart != e.dart; v = trav.next())
{
normal[v][0] = 0.0f;
}
}
std::cout << "FORCE_CELL_MARKING "<< ch.elapsed()<< " ms "<< std::endl;
}
ch.start();
{
TraversorCell<MAP, VERTEX> trav(myMap);
for(unsigned int i=0; i<NBLOOP; ++i)
{
for (Cell<VERTEX> v = trav.begin(), e = trav.end(); v.dart != e.dart; v = trav.next())
{
normal[v][0] = 0.0f;
}
}
std::cout << "auto "<< ch.elapsed()<< " ms "<< std::endl;
}
ch.start();
{
TraversorCell<MAP, VERTEX> trav(myMap,true);
for(unsigned int i=0; i<NBLOOP; ++i)
{
for (Cell<VERTEX> v = trav.begin(), e = trav.end(); v.dart != e.dart; v = trav.next())
{
normal[v][0] = 0.0f;
}
}
std::cout << "auto forcedart "<< ch.elapsed()<< " ms "<< std::endl;
}
ch.start();
{
TraversorCell<MAP, VERTEX,FORCE_DART_MARKING> trav(myMap,true);
for(unsigned int i=0; i<NBLOOP; ++i)
{
for (Cell<VERTEX> v = trav.begin(), e = trav.end(); v.dart != e.dart; v = trav.next())
{
normal[v][0] = 0.0f;
}
}
std::cout << "FORCE_DART_MARKING "<< ch.elapsed()<< " ms "<< std::endl;
}
myMap.enableQuickTraversal<VERTEX>() ;
ch.start();
{
TraversorCell<MAP, VERTEX> trav(myMap);
for(unsigned int i=0; i<NBLOOP; ++i)
{
for (Cell<VERTEX> v = trav.begin(), e = trav.end(); v.dart != e.dart; v = trav.next())
{
normal[v][0] = 0.0f;
}
}
std::cout << "auto (quick) "<< ch.elapsed()<< " ms "<< std::endl;
}
ch.start();
{
TraversorCell<MAP, VERTEX,FORCE_QUICK_TRAVERSAL> trav(myMap);
for(unsigned int i=0; i<NBLOOP; ++i)
{
for (Cell<VERTEX> v = trav.begin(), e = trav.end(); v.dart != e.dart; v = trav.next())
{
normal[v][0] = 0.0f;
}
}
std::cout << "FORCE_QUICK_TRAVERSAL "<< ch.elapsed()<< " ms "<< std::endl;
}
}
break;
case'Z':
{
Utils::Chrono ch;
ch.start();
for (unsigned int i=0; i<4; ++i)
Algo::Surface::Geometry::computeNormalVertices<PFP>(myMap, position, normal) ;
std::cout << "Algo::Surface::Geometry::Parallel::computeNormalVertices "<< ch.elapsed()<< " ms "<< std::endl;
ch.start();
CGoGN::Parallel::NumberOfThreads = 1;
for (unsigned int i=0; i<4; ++i)
Algo::Surface::Geometry::Parallel::computeNormalVertices<PFP>(myMap, position, normal) ;
std::cout << "Algo::Surface::Geometry::Parallel::computeNormalVertices1 "<< ch.elapsed()<< " ms "<< std::endl;
ch.start();
CGoGN::Parallel::NumberOfThreads = 2;
for (unsigned int i=0; i<4; ++i)
Algo::Surface::Geometry::Parallel::computeNormalVertices<PFP>(myMap, position, normal) ;
std::cout << "Algo::Surface::Geometry::Parallel::computeNormalVertices2 "<< ch.elapsed()<< " ms "<< std::endl;
ch.start();
CGoGN::Parallel::NumberOfThreads = 3;
for (unsigned int i=0; i<4; ++i)
Algo::Surface::Geometry::Parallel::computeNormalVertices<PFP>(myMap, position, normal) ;
std::cout << "Algo::Surface::Geometry::Parallel::computeNormalVertices3 "<< ch.elapsed()<< " ms "<< std::endl;
ch.start();
CGoGN::Parallel::NumberOfThreads = 4;
for (unsigned int i=0; i<4; ++i)
Algo::Surface::Geometry::Parallel::computeNormalVertices<PFP>(myMap, position, normal) ;
std::cout << "Algo::Surface::Geometry::Parallel::computeNormalVertices4 "<< ch.elapsed()<< " ms "<< std::endl;
ch.start();
CGoGN::Parallel::NumberOfThreads = 8;
for (unsigned int i=0; i<4; ++i)
Algo::Surface::Geometry::Parallel::computeNormalVertices<PFP>(myMap, position, normal) ;
std::cout << "Algo::Surface::Geometry::Parallel::computeNormalVertices8 "<< ch.elapsed()<< " ms "<< std::endl;
ch.start();
for (unsigned int i=0; i<4; ++i)
Parallel::foreach_cell<VERTEX>(myMap,[&](Vertex v, unsigned int th)
{
normal[v] = Algo::Surface::Geometry::vertexNormal<PFP>(myMap,v,position);
},false,FORCE_CELL_MARKING);
std::cout << "Parallel::foreach_cell "<< ch.elapsed()<< " ms "<< std::endl;
// ch.start();
// Parallel::foreach_cell_EO<VERTEX>(myMap,[&](Vertex v, unsigned int thr)
// {
// normal[v] = Algo::Surface::Geometry::vertexNormal<PFP>(myMap,v,position);
// },
// [&](Vertex v, unsigned int th)
// {
// normal[v] = Algo::Surface::Geometry::vertexNormal<PFP>(myMap,v,position);
// },2,4,false,FORCE_CELL_MARKING);
// std::cout << "Parallel::foreach_cell_EO "<< ch.elapsed()<< " ms "<< std::endl;
}
break;
default:
break;
}
......@@ -224,7 +555,7 @@ void Viewer::importMesh(std::string& filename)
position = myMap.getAttribute<PFP::VEC3, VERTEX>(attrNames[0]) ;
}
myMap.enableQuickTraversal<VERTEX>() ;
// myMap.enableQuickTraversal<VERTEX>() ;
m_render->initPrimitives<PFP>(myMap, Algo::Render::GL2::POINTS) ;
m_render->initPrimitives<PFP>(myMap, Algo::Render::GL2::LINES) ;
......@@ -240,13 +571,18 @@ void Viewer::importMesh(std::string& filename)
if(!normal.isValid())
normal = myMap.addAttribute<VEC3, VERTEX>("normal") ;
Utils::Chrono c;
c.start();
Algo::Surface::Geometry::computeNormalVertices<PFP>(myMap, position, normal) ;
std::cout << "compute normals -> " << c.elapsed() << std::endl;
m_positionVBO->updateData(position) ;
m_normalVBO->updateData(normal) ;
setParamObject(bb.maxSize(), bb.center().data()) ;
updateGLMatrices() ;
std::cout << "#vertices -> " << Algo::Topo::getNbOrbits<VERTEX>(myMap) << std::endl;
}
void Viewer::exportMesh(std::string& filename, bool askExportMode)
......
......@@ -29,6 +29,7 @@
#include "Algo/Modelisation/polyhedron.h"
#include "Algo/Import/import.h"
#include "Algo/Geometry/volume.h"
#include "Algo/Geometry/area.h"
#include "Utils/chrono.h"
......@@ -138,8 +139,8 @@ void MyQT::cb_Open()
std::vector<std::string> attrNames ;
//size_t pos = filename.rfind("."); // position of "." in filename
//std::string extension = filename.substr(pos);
size_t pos = filename.rfind("."); // position of "." in filename
std::string extension = filename.substr(pos);
// if(extension == std::string(".off"))
// {
......@@ -163,7 +164,7 @@ void MyQT::cb_Open()
}
else
position = myMap.getAttribute<PFP::VEC3,VERTEX>(attrNames[0]) ;
// }
//}
color = myMap.addAttribute<PFP::VEC3, VOLUME>("color");
......@@ -171,16 +172,19 @@ void MyQT::cb_Open()
float maxV = 0.0f;
for (Dart d = tra.begin(); d != tra.end(); d = tra.next())
{
float v = Algo::Geometry::tetrahedronVolume<PFP>(myMap, d, position);
color[d] = PFP::VEC3(v,0,0);
if (v>maxV)
maxV=v;
}
for (unsigned int i = color.begin(); i != color.end(); color.next(i))
{
color[i][0] /= maxV;
color[i][2] = 1.0f - color[i][0];
// float v = Algo::Geometry::tetrahedronVolume<PFP>(myMap, d, position);
// color[d] = PFP::VEC3(v,0,0);
// if (v>maxV)
// maxV=v;
if(myMap.isVolumeIncidentToBoundary(d))
color[d] = PFP::VEC3(0,0,0);
}
// for (unsigned int i = color.begin(); i != color.end(); color.next(i))
// {
// color[i][0] /= maxV;
// color[i][2] = 1.0f - color[i][0];
// }
// SelectorDartNoBoundary<PFP::MAP> nb(myMap);
m_topo_render->updateData(myMap, position, 0.8f, 0.8f, 0.8f);
......@@ -379,8 +383,8 @@ int main(int argc, char **argv)
{
std::vector<std::string> attrNames ;
std::string filename(argv[1]);
// size_t pos = filename.rfind("."); // position of "." in filename
// std::string extension = filename.substr(pos);
size_t pos = filename.rfind("."); // position of "." in filename
std::string extension = filename.substr(pos);
/*
if(extension == std::string(".off"))
{
......@@ -397,7 +401,8 @@ int main(int argc, char **argv)
}
else
{
*/ if(!Algo::Volume::Import::importMesh<PFP>(myMap, filename, attrNames))
*/
if(!Algo::Volume::Import::importMesh<PFP>(myMap, filename, attrNames))
{
std::cerr << "could not import " << filename << std::endl ;
return 1;
......@@ -416,17 +421,17 @@ int main(int argc, char **argv)
color[d] = PFP::VEC3(v,0,0);
if (v>maxV)
maxV=v;
// if(myMap.isVolumeIncidentToBoundary(d))
// color[d] = PFP::VEC3(0,0,0);
// else
color[d] = PFP::VEC3(v,0,0);
}
for (unsigned int i = color.begin(); i != color.end(); color.next(i))
{
color[i][0] /= maxV;
color[i][2] = 1.0f - color[i][0];
}
// Algo::Volume::Export::exportNAS<PFP>(myMap,position,"/tmp/test2.nas");
// Algo::Volume::Export::exportMSH<PFP>(myMap,position,"/tmp/test2.msh");
// Algo::Volume::Export::exportTet<PFP>(myMap,position,"/tmp/test2.tet");
// Algo::Volume::Export::exportNodeEle<PFP>(myMap,position,"/tmp/test2");
// Algo::Volume::Export::exportVTU<PFP>(myMap,position,"/tmp/test4.vtu");
}
else
......@@ -493,22 +498,35 @@ int main(int argc, char **argv)
Utils::Chrono ch;
std::cout << "Compute Volume ->"<< std::endl;
ch.start();
float vol = Algo::Geometry::totalVolume<PFP>(myMap, position);
vol += Algo::Geometry::totalVolume<PFP>(myMap, position);
vol += Algo::Geometry::totalVolume<PFP>(myMap, position);
vol += Algo::Geometry::totalVolume<PFP>(myMap, position);
std::cout << ch.elapsed()<< " ms val="<<vol<< std::endl;
Vertex v(myMap.begin());
VEC3 p = Algo::Volume::Geometry::vertexNeighborhoodCentroid<PFP>(myMap,v,position);
Vol w(myMap.begin());
VEC3 q = Algo::Surface::Geometry::volumeCentroid<PFP>(myMap,w,position);
ch.start();
vol = Algo::Geometry::Parallel::totalVolume<PFP>(myMap, position);
float vol = Algo::Geometry::Parallel::totalVolume<PFP>(myMap, position);
vol += Algo::Geometry::Parallel::totalVolume<PFP>(myMap, position);
vol += Algo::Geometry::Parallel::totalVolume<PFP>(myMap, position);
vol += Algo::Geometry::Parallel::totalVolume<PFP>(myMap, position);
std::cout << ch.elapsed()<< " ms // val="<<vol<< std::endl;
std::cout << "Compute Volume ->"<< std::endl;
ch.start();
vol = Algo::Geometry::totalVolume<PFP>(myMap, position);
std::cout << ch.elapsed()<< " ms val="<<vol<< std::endl;
ch.start();
vol += Algo::Geometry::totalVolume<PFP>(myMap, position);
std::cout << ch.elapsed()<< " ms val="<<vol<< std::endl;
ch.start();
vol += Algo::Geometry::totalVolume<PFP>(myMap, position);
std::cout << ch.elapsed()<< " ms val="<<vol<< std::endl;
ch.start();
vol += Algo::Geometry::totalVolume<PFP>(myMap, position);
std::cout << ch.elapsed()<< " ms val="<<vol<< std::endl;
// et on attend la fin.
return app.exec();
}
......@@ -244,7 +244,7 @@ void Viewer::cb_keyPress(int keycode)
Geom::Vec3f n(0.1,0.1,1.0);
Geom::Vec3f o = bb.center();
Geom::Plane3D<PFP::REAL> plan(n,o);
Geom::Plane3D<PFP::REAL> plan(n,o);
CellMarker<MAP, FACE> over(myMap);
Algo::Surface::Modelisation::planeCut2<PFP>(myMap, position, plan, over, true);
......@@ -259,7 +259,6 @@ void Viewer::cb_keyPress(int keycode)
position[d]+= n;
}
m_render->initPrimitives<PFP>(myMap, Algo::Render::GL2::POINTS) ;
m_render->initPrimitives<PFP>(myMap, Algo::Render::GL2::LINES) ;
m_render->initPrimitives<PFP>(myMap, Algo::Render::GL2::TRIANGLES) ;
......@@ -273,6 +272,16 @@ void Viewer::cb_keyPress(int keycode)
break;
}
case 'S':
{
Geom::Vec3f p1(0.0,1.0,0.0);
Geom::Vec3f p2(1.0,0.0,0.0);
Geom::Vec3f p3(1.0,1.0,0.0);
Geom::Plane3D<PFP::REAL> plan(p1, p2, p3);
}
case 'd':
{
......
......@@ -59,6 +59,17 @@ int main(int argc, char **argv)
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)
{
// update all color to grey
......@@ -75,10 +86,12 @@ void MyQT::traversors(int x)
Traversor2VVaE<MAP> trav(myMap,m_selected);
for(Dart b=trav.begin(); b!= trav.end(); b=trav.next())
m_render_topo->setDartColor(b,0.0f,1.0f,0.0f);
}
break;
case 1:
{
Traversor2VVaF<MAP> trav(myMap,m_selected);
for(Dart b=trav.begin(); b!= trav.end(); b=trav.next())
m_render_topo->setDartColor(b,0.0f,1.0f,0.0f);
......
......@@ -31,7 +31,8 @@
#include "Utils/GLSLShader.h"
//#include "Algo/Geometry/area.h"
#include "Algo/Geometry/normal.h"