Commit 997d253d authored by Lionel Untereiner's avatar Lionel Untereiner

Merge branch 'develop' of icube-forge.unistra.fr:cgogn/cgogn into develop

Conflicts:
	apps_cmake.txt
	include/Algo/ImplicitHierarchicalMesh/ihm3.hppxx
	include/Algo/ImplicitHierarchicalMesh/ihm3.hxx
	include/Algo/Modelisation/subdivision3.h
	include/Algo/Modelisation/subdivision3.hpp
	include/Algo/Modelisation/tetrahedralization.hpp
parents 781c9c5a c2fbbbce
# ignore QtCreator files
CMakeLists.txt.user
\ No newline at end of file
CMakeLists.txt.user
bin/
ThirdParty/bin/
SCHNApps/bin
\ No newline at end of file
......@@ -2,7 +2,7 @@
IF (ONELIB)
SET(CGoGN_LIBS cgogn)
ELSE (ONELIB)
SET(CGoGN_LIBS topology algo container utils)
SET(CGoGN_LIBS algo topology container utils)
ENDIF (ONELIB)
......
......@@ -79,6 +79,8 @@ void Viewer::initGUI()
void Viewer::cb_initGL()
{
Utils::GLSLShader::setCurrentOGLVersion(2) ;
CGoGNout << "GL VERSION = "<< glGetString(GL_VERSION)<< CGoGNendl;
Utils::GLSLShader::areShadersSupported();
m_render = new Algo::Render::GL2::MapRender() ;
m_topoRender = new Algo::Render::GL2::TopoRenderMap<PFP>() ;
......@@ -100,6 +102,7 @@ void Viewer::cb_initGL()
m_flatShader->setAttributePosition(m_positionVBO) ;
m_flatShader->setAmbiant(colClear) ;
m_flatShader->setDiffuse(colDif) ;
m_flatShader->setDiffuseBack(Geom::Vec4f(0,0,0,0)) ;
m_flatShader->setExplode(faceShrinkage) ;
m_vectorShader = new Utils::ShaderVectorPerVertex() ;
......
......@@ -171,7 +171,6 @@ void MyQT::cb_Open()
color = myMap.addAttribute<VEC3, VOLUME, MAP>("color");
TraversorCell<MAP, VOLUME> tra(myMap);
float maxV = 0.0f;
for (Dart d = tra.begin(); d != tra.end(); d = tra.next())
{
// float v = Algo::Geometry::tetrahedronVolume<PFP>(myMap, d, position);
......@@ -211,6 +210,8 @@ void MyQT::cb_initGL()
{
// choose to use GL version 2
Utils::GLSLShader::setCurrentOGLVersion(2);
CGoGNout << "GL VERSION = "<< glGetString(GL_VERSION)<< CGoGNendl;
Utils::GLSLShader::areShadersSupported();
// create the renders
m_topo_render = new Algo::Render::GL2::Topo3RenderMap<PFP>();
......@@ -522,11 +523,11 @@ int main(int argc, char **argv)
Utils::Chrono ch;
Vertex v(myMap.begin());
VEC3 p = Algo::Volume::Geometry::vertexNeighborhoodCentroid<PFP>(myMap,v,position);
// 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);
// Vol w(myMap.begin());
// VEC3 q = Algo::Surface::Geometry::volumeCentroid<PFP>(myMap,w,position);
ch.start();
float vol = Algo::Geometry::Parallel::totalVolume<PFP>(myMap, position);
......
......@@ -24,6 +24,9 @@ include_directories(${CMAKE_CURRENT_BINARY_DIR})
add_executable(multi_att multi_att.cpp)
target_link_libraries(multi_att ${CGoGN_LIBS} ${CGoGN_EXT_LIBS})
add_executable(trav3_test trav3_test.cpp)
target_link_libraries(trav3_test ${CGoGN_LIBS} ${CGoGN_EXT_LIBS})
IF (WITH_QT)
QT4_WRAP_CPP(tilings_moc tilings.h)
add_executable(tilings tilings.cpp ${tilings_moc})
......
......@@ -22,10 +22,172 @@
* *
*******************************************************************************/
#include "Topology/generic/marker.h"
#include <sstream>
namespace CGoGN
#include "Topology/generic/parameters.h"
#include "Topology/map/embeddedMap3.h"
#include "Algo/Tiling/Volume/cubic.h"
#include "Utils/chrono.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_DOUBLE
{
// definition of the type of the map
typedef EmbeddedMap3 MAP;
};
// some typedef shortcuts
typedef PFP::MAP MAP ; // map type
typedef PFP::VEC3 VEC3 ; // type of R³ vector
template <typename PFP, typename V_ATT>
typename V_ATT::DATA_TYPE localvolumeCentroidELW(typename PFP::MAP& map, Vol d, const V_ATT& attributs)
{
typedef typename V_ATT::DATA_TYPE EMB;
EMB center(0.0);
double count=0.0;
for (Edge it : edgesIncidentToVolume3(map,d))
{
EMB e1 = attributs[it.dart];
EMB e2 = attributs[map.phi1(it)];
double l = (e2-e1).norm();
center += (e1+e2)*l;
count += 2.0*l ;
}
center /= double(count);
return center ;
}
int main()
{
// declare a map to handle the mesh
MAP myMap;
// add position attribute on vertices and get handler on it
VertexAttribute<VEC3, MAP> position = myMap.addAttribute<VEC3, VERTEX, MAP>("position");
// create a topo grid of 4x4x4 squares
Algo::Volume::Tilings::Cubic::Grid<PFP> cubic(myMap, 20, 20, 20);
cubic.embedIntoGrid(position, 1.0f, 1.0f, 1.0f);
// easy way to find the central vertex of the grid
Vertex v;
foreach_cell_until<VERTEX>(myMap, [&] (Vertex it)
{
if (position[it] == VEC3(0,0,0))
{
v = it;
std::cout << "Trouve"<< std::endl;
return false;
}
return true;
});
// must test of find ok (if not v.dart is NIL)
if (! v.valid())
std::cerr << "could not find a vertex with position (0,0,0)" << std::endl;
// WITH TRAVERSORS:
// find incident faces to vertex
Traversor3VF<MAP> trvf(myMap, v.dart);
for (Dart e = trvf.begin(); e != trvf.end(); e = trvf.next())
{
std::cout << "Face of dart "<<e<< " incident to vertex of dart " << v.dart<< std::endl;
}
// find adjacent vertices thru a face
Traversor3VVaF<MAP> trvvaf(myMap, v.dart);
for (Dart e = trvvaf.begin(); e != trvvaf.end(); e = trvvaf.next())
{
std::cout << "vertex of dart "<<e<< " adjacent to vertex of dart " << v.dart<< " by a face" << std::endl;
}
// WITH FOREACH FUNCTION (C++11 lambda expression)
// find faces incident to vertex v
foreach_incident3<FACE>(myMap, v, [&](Face f)
{
std::cout << "Face of dart " << f << " incident to vertex of dart " << v.dart << std::endl;
});
// find vertices adjacent to vertex v thru a face
foreach_adjacent3<FACE>(myMap, v, [&](Vertex x)
{
std::cout << "vertex of dart " << x << " adjacent to vertex of dart " << v.dart << " by a face" << std::endl;
});
// WITH FOR C++11 SYNTAX
for(Face f : facesIncidentToVertex3(myMap,v))
std::cout << "Face of dart " << f << " incident to vertex of dart " << v.dart << std::endl;
for (Vertex x : verticesAdjacentByFace3(myMap,v))
std::cout << "vertex of dart " << x << " adjacent to vertex of dart " << v.dart << " by a face" << std::endl;
for(Vertex v1 : allVerticesOf(myMap))
{
for (Vertex v2 : verticesAdjacentByEdge3(myMap,v1))
{
for (Face f : facesIncidentToVertex3(myMap,v2))
if ((f.dart.index)%1000 == 1 )
std::cout << "juste for fun face " << f << std::endl;
}
}
Utils::Chrono ch;
VertexAttribute<VEC3,MAP> pos2 = myMap.getAttribute<VEC3, VERTEX, MAP>("pos2") ;
if(!pos2.isValid())
pos2 = myMap.addAttribute<VEC3, VERTEX, MAP>("pos2") ;
ch.start();
for (int i=0; i< 20; ++i)
{
VEC3 xx(0,0,0);
int nb=0;
for(Vol d : allVolumesOf(myMap))
{
VEC3 vCentroid = localvolumeCentroidELW<PFP>(myMap, d, position) ;
xx += vCentroid;
nb++;
}
xx /= nb;
std::cout << xx << std::endl;
}
std::cout << "for "<< ch.elapsed()<< " ms "<< std::endl;
ch.start();
for (int i=0; i< 20; ++i)
{
VEC3 xx(0,0,0);
int nb=0;
foreach_cell<VOLUME>(myMap, [&] (Vol d)
{
VEC3 vCentroid = Algo::Surface::Geometry::volumeCentroidELW<PFP>(myMap, d, position) ;
xx += vCentroid;
nb++;
});
xx /= nb;
std::cout << xx << std::endl;
}
std::cout << "Lambda "<< ch.elapsed()<< " ms "<< std::endl;
} // namespace CGoGN
return 0;
}
......@@ -80,6 +80,13 @@ void applySmooth(MAP& map, const ATT& att_in, ATT& att_out)
// check at compile if ATT is an AttributeHandler on orbit VERTEX
CHECK_ATTRIBUTEHANDLER_ORBIT(ATT, VERTEX);
// or check at runtime(take care of const!)
if (! checkAttributeHandlerOrbit<VERTEX>(att_in))
{
CGoGNerr << "function applySmooth work only with VertexAttributes !" << CGoGNendl;
return;
}
foreach_cell<VERTEX>(map,[&](Vertex v) // for all vertex v of map do
{
att_out[v] = smooth(map,v,att_in);
......
......@@ -125,6 +125,38 @@ void dumpAttribute(const ATTRIB& attr)
}
//function that apply on vertice with templated attribute type
template<typename T>
void VertexTyped(MAP& map, T& va)
{
// foreach_cell<VERTEX>(map,[&](Vertex v) // for all vertices
// {
// va[v] = 1.1 * va[v];
// });
// other syntax for traversal
for (Vertex v : allVerticesOf(map))
{
va[v] = 1.1 * va[v];
std::cout << "V:" << v << " -> "<<va[v]<< std::endl;
}
}
// version that take a VertexAttribute, check type at runtime and call instancied template version
void VertexGeneric(MAP& map, VertexAttributeGen& vg)
{
auto va3 = dynamic_cast<VertexAttribute<VEC3, MAP>*>(&vg);
if (va3 != NULL)
return VertexTyped(map,*va3);
auto vaf = dynamic_cast<VertexAttribute<float, MAP>*>(&vg);
if (vaf != NULL)
return VertexTyped(map,*vaf);
}
int main()
{
// declare a map to handle the mesh
......@@ -142,6 +174,8 @@ int main()
grid.embedIntoGrid(positionAtt, 1.,1.,0.);
VertexGeneric(myMap,positionAtt);
// ATTRIBUTE DECLARATION
// add an attribute of type float on orbit EDGE
......
......@@ -102,7 +102,7 @@ void MyQT::createMap()
// return Geom::Vec3f(float(x)/255.0f,float(x)/255.0f,float(x)/255.0f);
// });
// or with furnished operator of conversion
DataConversion::operatorScalarToRGBf<int> conv2col(0,255);
DataConversion::functorScalarToRGBf<int> conv2col(0,255);
m_colorVBO1->updateDataConversion<int,3>(colorE,conv2col);
......
......@@ -63,7 +63,16 @@ int main()
{
std::cout << id << " : " << position[id]<< " / ";
}
std::cout << std::endl;
std::cout << std::endl << "--------------------------------" << std::endl;
//using (C++11 for syntax)
// warning: if you want ot modify the attributes do not forget the &
for (auto& p: position.iterable())
{
p *= 2.0;
}
//using foreach function (C++11 lambda expression)
foreach_attribute(position, [&] (unsigned int id) // for each element of position
......@@ -71,9 +80,11 @@ int main()
std::cout << id << " : " << position[id]<< " / ";
});
std::cout << std::endl << "--------------------------------" << std::endl;
// using parallel foreach
// parameter position must be captured explicitly even if it used as first parameter of foreach !
Parallel::foreach_attribute(position, [&position] (unsigned int id, unsigned int thread) // for each elt of the position attribute
Parallel::foreach_attribute(position, [&position] (unsigned int id, unsigned int /*thread*/) // for each elt of the position attribute
{
position[id] *= 2.0f;
}, 4); // 4:4 thread, false for no need for markers in threaded code.
......
......@@ -111,17 +111,18 @@ int main()
}); // 4:4 thread, false for no need for markers in threaded code.
std::cout << "After // processing"<< std::endl;
foreach_cell<VERTEX>(myMap, [&] (Vertex v) // for each Vertex v of the MAP myMap
// last and simple traversal method (new for c++11 syntax)
for(Vertex v : allVerticesOf(myMap))
{
std::cout << position[v] << " / ";
});
}
std::cout << std::endl;
// Example with // accumulation
// computing the sum of area faces
// force number of threads to 4 (0 for traverse, 1,2,3 for computation)
CGoGN::Parallel::NumberOfThreads = 4;
......@@ -137,6 +138,8 @@ int main()
std::cout << surf[0]<< "/"<< surf[1]<< "/"<< surf[2]<< "/"<< std::endl;
std::cout << "Total="<<surf[0]+surf[1]+surf[2]<< std::endl;
// example of traversal in two pass (optimizing marking/unmarking)
TraversorV<MAP> tv0(myMap);
TraversorCellEven<MAP, VERTEX> tv1(tv0);
TraversorCellOdd<MAP, VERTEX> tv2(tv0);
......
......@@ -102,5 +102,16 @@ int main()
std::cout << "vertex of dart " << x << " adjacent to vertex of dart " << v.dart << " by a face" << std::endl;
});
// WITH FOR C++11 SYNTAX
for(Face f : facesIncidentToVertex2(myMap,v))
{
std::cout << "Face of dart " << f << " incident to vertex of dart " << v.dart << std::endl;
}
for (Vertex x : verticesAdjacentByFace2(myMap,v))
{
std::cout << "vertex of dart " << x << " adjacent to vertex of dart " << v.dart << " by a face" << std::endl;
}
return 0;
}
......@@ -94,7 +94,7 @@ int main(int argc, char **argv)
}
}
Dart dcenter = myMap.explodBorderTopo(dsave);
Dart dcenter = myMap.explodBorderTopo(/*dsave*/);
DartMarker<MAP> mf(myMap);
for(Dart dit = myMap.begin() ; dit != myMap.end() ; myMap.next(dit))
......
......@@ -143,7 +143,7 @@ IF (WITH_QT)
ADD_DEFINITIONS(${QT_DEFINITIONS})
find_package(QGLViewer REQUIRED)
SET (CGoGN_EXT_INCLUDES ${CGoGN_EXT_INCLUDES} ${QT_INCLUDE_DIR} ${QGLVIEWER_INCLUDE_DIR} )
SET (CGoGN_EXT_LIBS ${QT_LIBRARIES} ${QGLVIEWER_LIBRARIES} ${CGoGN_EXT_LIBS})
SET (CGoGN_EXT_LIBS ${QGLVIEWER_LIBRARIES} ${QT_LIBRARIES} ${CGoGN_EXT_LIBS})
ENDIF (WITH_QT)
IF (WITH_GLEWMX)
......@@ -285,22 +285,35 @@ file( GLOB_RECURSE
${CGoGN_ROOT_DIR}/ThirdParty/include/*.hpp
)
link_directories( ${CGoGN_ROOT_DIR}/lib/${CMAKE_BUILD_TYPE} )
IF (ONELIB)
IF(WITH_QT)
add_library( cgogn ${files_topology} ${files_container} ${files_algo} ${files_utils_withQt})
ELSE()
add_library( cgogn ${files_topology} ${files_container} ${files_algo} ${files_utils} )
ENDIF()
add_dependencies(cgogn shader_target )
add_dependencies(cgogn shader_target)
target_link_libraries(cgogn ${CGoGN_EXT_LIBS})
ELSE()
add_library( container ${files_container})
add_library( topology ${files_topology})
add_library( algo ${files_algo})
IF (WITH_QT)
add_library( utils ${files_utils_withQt} )
ELSE()
add_library( utils ${files_utils} )
ENDIF()
target_link_libraries(utils ${CGoGN_EXT_LIBS})
add_library( container ${files_container})
target_link_libraries(container utils)
add_library( topology ${files_topology})
target_link_libraries(topology container)
add_library( algo ${files_algo})
target_link_libraries(algo utils topology)
add_custom_target( Geometry SOURCES ${files_geometry} )
add_custom_target( ThirdParty SOURCES ${files_thirdParty} )
add_dependencies( utils shader_target )
......
......@@ -33,6 +33,7 @@ SET( QT_USE_QTXML TRUE )
SET( QT_USE_QTDESIGNER TRUE )
SET( QT_USE_QTGUI TRUE )
SET( QT_USE_QTPLUGIN TRUE )
SET( QT_USE_QTSVG TRUE )
INCLUDE(${QT_USE_FILE})
ADD_DEFINITIONS(${QT_DEFINITIONS})
......
......@@ -110,6 +110,9 @@ void MapParameters::stop(MapHandlerGen* mh)
bool Surface_Deformation_Plugin::enable()
{
// magic line that init static variables of GenericMap in the plugins
GenericMap::copyAllStatics(m_schnapps->getStaticPointers());
m_dockTab = new Surface_Deformation_DockTab(m_schnapps, this);
m_schnapps->addPluginDockTab(this, m_dockTab, "Surface_Deformation");
......@@ -539,11 +542,7 @@ void Surface_Deformation_Plugin::asRigidAsPossible(MapHandlerGen* mh)
}
}
#ifndef DEBUG
Q_EXPORT_PLUGIN2(Surface_Deformation_Plugin, Surface_Deformation_Plugin)
#else
Q_EXPORT_PLUGIN2(Surface_Deformation_PluginD, Surface_Deformation_Plugin)
#endif
} // namespace SCHNApps
......
......@@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>472</width>
<height>276</height>
<height>292</height>
</rect>
</property>
<property name="windowTitle">
......@@ -75,6 +75,16 @@
</item>
</layout>
</item>
<item>
<widget class="QCheckBox" name="enableVBO">
<property name="text">
<string>Create VBO</string>
</property>
<property name="checked">
<bool>false</bool>
</property>
</widget>
</item>
</layout>
</widget>
</item>
......
......@@ -13,6 +13,9 @@ namespace SCHNApps
bool Surface_DifferentialProperties_Plugin::enable()
{
// magic line that init static variables of GenericMap in the plugins
GenericMap::copyAllStatics(m_schnapps->getStaticPointers());
m_computeNormalDialog = new Dialog_ComputeNormal(m_schnapps);
m_computeCurvatureDialog = new Dialog_ComputeCurvature(m_schnapps);
......@@ -118,6 +121,14 @@ void Surface_DifferentialProperties_Plugin::computeNormalFromDialog()
bool autoUpdate = (currentItems[0]->checkState() == Qt::Checked);
computeNormal(mapName, positionName, normalName, autoUpdate);
// create VBO if asked
if (m_computeNormalDialog->enableVBO->isChecked())
{
MapHandlerGen* mhg = getSCHNApps()->getMap(mapName);
if (mhg != NULL)
mhg->createVBO(normalName);
}
}
}
......@@ -292,11 +303,7 @@ void Surface_DifferentialProperties_Plugin::computeCurvature(
}
}
#ifndef DEBUG
Q_EXPORT_PLUGIN2(Surface_DifferentialProperties_Plugin, Surface_DifferentialProperties_Plugin)
#else
Q_EXPORT_PLUGIN2(Surface_DifferentialProperties_PluginD, Surface_DifferentialProperties_Plugin)
#endif
} // namespace SCHNApps
......
......@@ -16,6 +16,9 @@ namespace SCHNApps
bool Surface_Import_Plugin::enable()
{
// magic line that init static variables of GenericMap in the plugins
GenericMap::copyAllStatics(m_schnapps->getStaticPointers());
importAction = new QAction("import", this);
m_schnapps->addMenuAction(this, "Surface;Import", importAction);
connect(importAction, SIGNAL(triggered()), this, SLOT(importFromFileDialog()));
......@@ -62,11 +65,7 @@ void Surface_Import_Plugin::importFromFileDialog()
}
}
#ifndef DEBUG
Q_EXPORT_PLUGIN2(Surface_Import_Plugin, Surface_Import_Plugin)
#else
Q_EXPORT_PLUGIN2(Surface_Import_PluginD, Surface_Import_Plugin)
#endif
} // namespace SCHNApps
......
......@@ -24,6 +24,9 @@ Surface_Modelisation_Plugin::Surface_Modelisation_Plugin()
bool Surface_Modelisation_Plugin::enable()
{
// magic line that init static variables of GenericMap in the plugins
GenericMap::copyAllStatics(m_schnapps->getStaticPointers());
m_dockTab = new Surface_Modelisation_DockTab(m_schnapps, this);
m_schnapps->addPluginDockTab(this, m_dockTab, "Surface_Modelisation");
......@@ -790,11 +793,7 @@ void Surface_Modelisation_Plugin::pathExtrudeFace(MapHandlerGen *mhg)
}
#ifndef DEBUG
Q_EXPORT_PLUGIN2(Surface_Modelisation_Plugin, Surface_Modelisation_Plugin)
#else
Q_EXPORT_PLUGIN2(Surface_Modelisation_PluginD, Surface_Modelisation_Plugin)
#endif
} // namespace SCHNApps
......
......@@ -6,7 +6,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>200</width>
<width>246</width>
<height>600</height>
</rect>
</property>
......@@ -14,12 +14,23 @@
<string>Form</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Position :</string>
</property>
</widget>
<item row="9" column="0" rowspan="2" colspan="2">
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<widget class="QCheckBox" name="check_renderEdges">
<property name="text">
<string>render edges</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="scolorButton">
<property name="text">
<string>Color</string>
</property>
</widget>
</item>
</layout>
</item>
<item row="1" column="1">
<widget class="QComboBox" name="combo_normalVBO">
......@@ -36,27 +47,27 @@
</item>
</widget>
</item>
<item row="3" column="0" colspan="2">
<widget class="QCheckBox" name="check_renderVertices">
<property name="text">
<string>render vertices</string>
<item row="20" column="0" colspan="2">
<spacer name="verticalSpacer">
<property name="orientation">