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

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)
This diff is collapsed.
......@@ -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);
......
This diff is collapsed.
......@@ -43,6 +43,7 @@
#include "Algo/Tiling/Surface/square.h"
#include "Algo/Tiling/Surface/triangular.h"
#include "Algo/Tiling/Surface/hexagonal.h"
// forward definitions (minimize includes)
namespace CGoGN { namespace Algo { namespace Render { namespace GL1 { class MapRender; } } } }
......@@ -76,8 +77,8 @@ public:
{}
void squareTiling(int code);
void triangularTiling(int code);
void hexagonalTiling(int code);
protected:
......
cmake_minimum_required(VERSION 2.8)
project(Tuto_Traversals)
SET (CMAKE_BUILD_TYPE Debug)
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DNOTOPOWARNING")
include_directories(
${CMAKE_CURRENT_BINARY_DIR}
${CGoGN_ROOT_DIR}/include
${CGoGN_EXT_INCLUDES}
)
# define libs path
IF(WIN32)
link_directories(${CGoGN_ROOT_DIR}/lib/$(ConfigurationName)
${Boost_LIBRARY_DIRS})
ELSE(WIN32)
link_directories(${CGoGN_ROOT_DIR}/lib/Release ${CGoGN_ROOT_DIR}/lib/Debug)
ENDIF(WIN32)
#define exec to compile
add_executable( simple_attribs simple_attribs.cpp)
target_link_libraries( simple_attribs ${CGoGN_LIBS_D} ${CGoGN_EXT_LIBS} )
add_executable( multi_attribs multi_attribs.cpp)
target_link_libraries( multi_attribs ${CGoGN_LIBS_D} ${CGoGN_EXT_LIBS} )
......@@ -22,137 +22,122 @@
* *
*******************************************************************************/
#ifndef __LINEAR_SOLVING_VARIABLES_SETUP__
#define __LINEAR_SOLVING_VARIABLES_SETUP__
namespace CGoGN
{
#include "Topology/generic/parameters.h"
#include "Topology/map/embeddedMap2.h"
#include "Algo/Tiling/Surface/square.h"
#include "Topology/generic/multiAttribs.h"
#include "Algo/Geometry/centroid.h"
using namespace CGoGN ;
namespace LinearSolving
/**
* 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
typedef EmbeddedMap2 MAP;
};
// some typedef shortcuts
typedef PFP::MAP MAP ; // map type
typedef PFP::MAP::IMPL MAP_IMPL ; // map implementation
typedef PFP::VEC3 VEC3 ; // type of R³ vector
typedef PFP::VEC4 VEC4;
/**
* Example of function that work with any kind of Vertex Attribute (normal/2/3/4)
*
* operators on multi-attribute are limited to:
* affectation
* +, -, +=, -=
* *(double) /(double) *=(double) /=(double)
*
*/
template <typename MAP, typename ATT>
typename ATT::DATA_TYPE smooth(MAP& map, Vertex v, const ATT& attributs)
{
typename ATT::DATA_TYPE res(0);
int count=0;
template <typename PFP, typename ATTR_TYPE>
class FunctorMeshToSolver_Scalar : public FunctorType
foreach_adjacent2<EDGE>(map,v,[&](Vertex x) // for all its neighbours (by edges)
{
res += attributs[x];
count ++;
});
res /= typename PFP::REAL(count);
return res;
}
/**
* Example of function that work with any kind of Vertex Attribute
*/
template <typename MAP, typename ATT>
void applySmooth(MAP& map, const ATT& att_in, ATT& att_out)
{
typedef typename PFP::MAP MAP;
typedef typename PFP::MAP::IMPL MAP_IMPL;
protected:
const VertexAttribute<unsigned int, MAP_IMPL>& indexTable ;
const CellMarker<MAP, VERTEX>& freeMarker ;
const VertexAttribute<ATTR_TYPE, MAP_IMPL>& attrTable ;
bool lockedVertices ;
public:
FunctorMeshToSolver_Scalar(
const VertexAttribute<unsigned int, MAP_IMPL>& index,
const CellMarker<MAP, VERTEX>& fm,
const VertexAttribute<ATTR_TYPE, MAP_IMPL>& attr
) : indexTable(index), freeMarker(fm), attrTable(attr), lockedVertices(false)
{}
bool operator()(Dart d)
foreach_cell<VERTEX>(map,[&](Vertex v) // for all edge e of map do
{
nlSetVariable(indexTable[d], attrTable[d]);
if(!freeMarker.isMarked(d))
{
nlLockVariable(indexTable[d]);
lockedVertices = true ;
}
return false ;
}
att_out[v] = smooth(map,v,att_in);
});
}
bool hasLockedVertices() { return lockedVertices ; }
} ;
template <typename PFP, typename ATTR_TYPE>
class FunctorMeshToSolver_Vector : public FunctorType
{
typedef typename PFP::MAP MAP;
typedef typename PFP::MAP::IMPL MAP_IMPL;
protected:
const VertexAttribute<unsigned int, MAP_IMPL>& indexTable ;
const CellMarker<MAP, VERTEX>& freeMarker ;
const VertexAttribute<ATTR_TYPE, MAP_IMPL>& attrTable ;
unsigned int coord ;
bool lockedVertices ;
public:
FunctorMeshToSolver_Vector(
const VertexAttribute<unsigned int, MAP_IMPL>& index,
const CellMarker<MAP, VERTEX>& fm,
const VertexAttribute<ATTR_TYPE, MAP_IMPL>& attr,
unsigned int c
) : indexTable(index), freeMarker(fm), attrTable(attr), coord(c), lockedVertices(false)
{}
bool operator()(Dart d)
{
nlSetVariable(indexTable[d], (attrTable[d])[coord]);
if(!freeMarker.isMarked(d))
{
nlLockVariable(indexTable[d]);
lockedVertices = true ;
}
return false ;
}
bool hasLockedVertices() { return lockedVertices ; }
} ;
template <typename PFP, typename ATTR_TYPE>
class FunctorSolverToMesh_Scalar : public FunctorType
int main()
{
typedef typename PFP::MAP MAP;
typedef typename PFP::MAP::IMPL MAP_IMPL;
// declare a map to handle the mesh
MAP myMap;
protected:
const VertexAttribute<unsigned int, MAP_IMPL>& indexTable ;
VertexAttribute<ATTR_TYPE, MAP_IMPL>& attrTable ;
// add position attribute on vertices and get handler on it
VertexAttribute<VEC3, MAP_IMPL> position = myMap.addAttribute<VEC3, VERTEX>("position");
public:
FunctorSolverToMesh_Scalar(
const VertexAttribute<unsigned int, MAP_IMPL>& index,
VertexAttribute<ATTR_TYPE, MAP_IMPL>& attr
) : indexTable(index), attrTable(attr)
{}
// create a topo grid of 2x2 squares
Algo::Surface::Tilings::Square::Grid<PFP> grid(myMap, 2, 2, true);
// and embed it using position attribute
grid.embedIntoGrid(position, 2.,2.,0.);
bool operator()(Dart d)
// second vertex attribute (for out)
VertexAttribute<VEC3, MAP_IMPL> pos2 = myMap.addAttribute<VEC3, VERTEX>("pos2");
// first color attribute on vertices
VertexAttribute<VEC4, MAP_IMPL> vc = myMap.addAttribute<VEC4, VERTEX>("vertexColor");
// second color attribute on vertices
VertexAttribute<VEC4, MAP_IMPL> vc2 = myMap.addAttribute<VEC4, VERTEX>("vertexColor2");
// add some random on position and compute a color
for (unsigned int i= position.begin(); i != position.end(); position.next(i))
{
attrTable[d] = nlGetVariable(indexTable[d]) ;
return false ;
position[i] += VEC3(0.02f*i,0.01f*i,0.03f*i);
vc[i] = VEC4(position[i][0]*0.3f,position[i][1]*0.3f,position[i][2]*0.3f,1.0f);
}
} ;
template <typename PFP, typename ATTR_TYPE>
class FunctorSolverToMesh_Vector : public FunctorType
{
typedef typename PFP::MAP MAP;
typedef typename PFP::MAP::IMPL MAP_IMPL;
protected:
const VertexAttribute<unsigned int, MAP_IMPL>& indexTable ;
VertexAttribute<ATTR_TYPE, MAP_IMPL>& attrTable ;
unsigned int coord ;
public:
FunctorSolverToMesh_Vector(
const VertexAttribute<unsigned int, MAP_IMPL>& index,
VertexAttribute<ATTR_TYPE, MAP_IMPL>& attr,
unsigned int c
) : indexTable(index), attrTable(attr), coord(c)
{}
bool operator()(Dart d)
std::cout << "========== initial values =========="<<std::endl;
// just print attributes values
foreach_cell<VERTEX>(myMap,[&](Vertex v) // for all edge e of map do
{
(attrTable[d])[coord] = nlGetVariable(indexTable[d]) ;
return false ;
}
} ;
std::cout << position[v]<< " / "<< vc[v]<< std::endl;
});
// define two multi attributes (one for in, one for out)
Vertex2Attributes<VEC3, VEC4, MAP_IMPL> pv_in(position, vc);
Vertex2Attributes<VEC3, VEC4, MAP_IMPL> pv_out(pos2, vc2);
} // namespace LinearSolving
// and call algo once just like with simple attributes
applySmooth(myMap, pv_in, pv_out);
std::cout << "========== after smooth on position and color =========="<<std::endl;
foreach_cell<VERTEX>(myMap,[&](Vertex v) // for all edge e of map do
{
std::cout << pos2[v]<< " / "<< vc2[v]<< std::endl;
});
} // namespace CGoGN
#endif
return 0;
}
/*******************************************************************************
* 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 "Topology/generic/parameters.h"
#include "Topology/map/embeddedMap2.h"
#include "Algo/Tiling/Surface/square.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
typedef EmbeddedMap2 MAP;
};
// some typedef shortcuts
typedef PFP::MAP MAP ; // map type
typedef PFP::MAP::IMPL MAP_IMPL ; // map implementation
typedef PFP::VEC3 VEC3 ; // type of R³ vector
/**
* @brief test if map has a Vertex Attribute of VEC3 named name
* @param map the map
* @param name name of attribute
*/
void testVAbyNames(MAP& map, const std::string& name)
{
VertexAttribute<VEC3, MAP_IMPL> testPos = map.getAttribute<VEC3, VERTEX>(name);
if (testPos.isValid())
std::cout << "Attribute "<< name <<" valid"<< std::endl;
else
std::cout << "Attribute "<< name <<"invalid"<< std::endl;
}
/**
* @brief computeLengthEdges
* Demonstrate usage of 2 attributes on 2 differents orbits.
* @param map the map
* @param pos attribute handler of position of vertices
* @param len attribute handler of length of edges
*/
void computeLengthEdges(MAP& map,const VertexAttribute<VEC3, MAP_IMPL>& pos, EdgeAttribute<float, MAP_IMPL> len)
{
// warning c++11 lambda syntax
foreach_cell<EDGE>(map,[&](Edge e) // for all edge e of map do
{
VEC3 P1 = pos[e.dart]; // access with dart because of access to VertexAttribute with an edge
VEC3 P2 = pos[map.phi1(e)]; // phi1 return a dart so no problem (and e can auto-cast in dart)
VEC3 V = P2 - P1;
len[e] = V.norm();
});
}
/**
* @brief computeNewPositions Demonstrate the usage of AutoAttributes
*/
void computeNewPositions(MAP& map, VertexAttribute<VEC3, MAP_IMPL>& pos)
{
// here we need new and old positions simultaneously so create temporary attribute position
VertexAutoAttribute<VEC3, MAP_IMPL> pos2(map);
foreach_cell<VERTEX>(map,[&](Vertex v) // for all vertices
{
int nb=0;
pos2[v] = VEC3(0,0,0);// init with 0,0,0,
foreach_adjacent2<EDGE>(map,v,[&](Vertex x) // for all its neighbours (by edges)
{
pos2[v] += pos[x];
nb++;
});
pos2[v] /= nb;
});
// swap attribute position with temporary (constant complexity !)
// only possible with same type and same orbit attribute.
map.swapAttributes(pos,pos2);
// destruction of VertexAutoAttribute handller remove the attribute from the map.
}
/**
* @brief dump any attribute
* @param attr attribute
*/
template<typename ATTRIB>
void dumpAttribute(const ATTRIB& attr)
{
std::cout << "Attribute " <<attr.name() << " of orbit "<< orbitName(attr.getOrbit())<< " of type "<< attr.typeName()