Commit f3132155 authored by untereiner's avatar untereiner

some changes to implicit MR management

parent 10e52114
......@@ -44,8 +44,8 @@ using namespace CGoGN ;
*/
struct PFP: public PFP_STANDARD
{
// definition of the map
typedef EmbeddedMap2 MAP;
// definition of the map
typedef EmbeddedMap2 MAP;
};
......@@ -56,178 +56,265 @@ VertexAttribute<PFP::VEC3> normal;
void MyQT::cb_initGL()
{
Utils::GLSLShader::setCurrentOGLVersion(2);
Utils::GLSLShader::setCurrentOGLVersion(2);
// create the render
m_render = new Algo::Render::GL2::MapRender();
// create the render
m_render = new Algo::Render::GL2::MapRender();
// create VBO for position
m_positionVBO = new Utils::VBO();
m_positionVBO->updateData(position);
// create VBO for position
m_positionVBO = new Utils::VBO();
m_positionVBO->updateData(position);
m_normalVBO = new Utils::VBO();
m_normalVBO = new Utils::VBO();
m_shader = new Utils::ShaderSimpleColor();
m_shader->setAttributePosition(m_positionVBO);
m_shader->setColor(Geom::Vec4f(1.,1.,0.,0.));
m_shader = new Utils::ShaderSimpleColor();
m_shader->setAttributePosition(m_positionVBO);
m_shader->setColor(Geom::Vec4f(1.,1.,0.,0.));
m_lines = new Utils::ShaderVectorPerVertex();
m_lines->setAttributePosition(m_positionVBO);
m_lines->setAttributeVector(m_normalVBO);
m_lines->setScale(0.2f);
m_lines->setColor(Geom::Vec4f(0.0f, 1.0f, 0.2f, 0.0f));
m_lines = new Utils::ShaderVectorPerVertex();
m_lines->setAttributePosition(m_positionVBO);
m_lines->setAttributeVector(m_normalVBO);
m_lines->setScale(0.2f);
m_lines->setColor(Geom::Vec4f(0.0f, 1.0f, 0.2f, 0.0f));
Algo::Surface::Geometry::computeNormalVertices<PFP>(myMap, position, normal) ;
Algo::Surface::Geometry::computeNormalVertices<PFP>(myMap, position, normal) ;
m_render->initPrimitives<PFP>(myMap, Algo::Render::GL2::LINES);
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::POINTS);
registerShader(m_shader);
registerShader(m_lines);
registerShader(m_shader);
registerShader(m_lines);
m_normalVBO->updateData(normal);
m_normalVBO->updateData(normal);
}
void MyQT::cb_redraw()
{
m_render->draw(m_shader, Algo::Render::GL2::LINES);
m_render->draw(m_lines, Algo::Render::GL2::POINTS);
m_render->draw(m_shader, Algo::Render::GL2::LINES);
m_render->draw(m_lines, Algo::Render::GL2::POINTS);
}
void MyQT::squareTiling(int code)
{
switch(code)
{
case 1:
{
std::cout << "square grid tiling" << std::endl;
Algo::Surface::Tilings::Square::Grid<PFP> g(myMap,10,10,true);
g.embedIntoGrid(position,50,50);
break;
}
case 2:
{
std::cout << "square grid twisted strip tiling" << std::endl;
Algo::Surface::Tilings::Square::Grid<PFP> g(myMap,10,10,true);
g.embedIntoTwistedStrip(position, 0.3, 0.8, 5);
break;
}
case 3:
{
std::cout << "square grid helocoid tiling" << std::endl;
Algo::Surface::Tilings::Square::Grid<PFP> g(myMap,20,20,true);
g.embedIntoHelicoid(position, 0.3, 0.8, 5.0, 2.0);
break;
}
case 4:
{
std::cout << "square cylinder tiling" << std::endl;
Algo::Surface::Tilings::Square::Cylinder<PFP> c(myMap,20,20);
c.embedIntoCylinder(position,0.5,0.7,5.0);
break;
}
case 5:
{
std::cout << "square cylinder tiling" << std::endl;
Algo::Surface::Tilings::Square::Cylinder<PFP> c(myMap,20,20);
c.triangleBottom();
c.triangleTop();
c.embedIntoCylinder(position,0.5,0.7,5.0);
break;
}
case 6:
{
std::cout << "square cylinder sphere tiling" << std::endl;
Algo::Surface::Tilings::Square::Cylinder<PFP> c(myMap,20,20);
c.triangleTop();
c.triangleBottom();
c.embedIntoSphere(position,0.5);
break;
}
case 7:
{
std::cout << "square cylinder cone tiling" << std::endl;
Algo::Surface::Tilings::Square::Cylinder<PFP> c(myMap,20,20);
c.triangleTop();
c.triangleBottom();
c.embedIntoCone(position,0.5, 5.0);
break;
}
case 8:
{
std::cout << "square cylinder cone tiling" << std::endl;
Algo::Surface::Tilings::Square::Cube<PFP> c(myMap,20,20,20);
c.embedIntoCube(position,5.0,5.0, 5.0);
break;
}
case 9:
{
std::cout << "square cylinder cone tiling" << std::endl;
Algo::Surface::Tilings::Square::Tore<PFP> c(myMap,20,10);
c.embedIntoTore(position,5.0,2.0);
break;
}
default:
{
break;
}
}
}
// mouse picking
void MyQT::tiling(int code)
void MyQT::triangularTiling(int code)
{
//myMap.clear(false);
switch(code)
{
case 1:
{
std::cout << "square grid tiling" << std::endl;
Algo::Surface::Tilings::Square::Grid<PFP> g(myMap,10,10,true);
g.embedIntoGrid(position,50,50);
break;
}
case 2:
{
std::cout << "square grid twisted strip tiling" << std::endl;
Algo::Surface::Tilings::Square::Grid<PFP> g(myMap,10,10,true);
g.embedIntoTwistedStrip(position, 0.3, 0.8, 5);
break;
}
case 3:
{
std::cout << "square grid helocoid tiling" << std::endl;
Algo::Surface::Tilings::Square::Grid<PFP> g(myMap,20,20,true);
g.embedIntoHelicoid(position, 0.3, 0.8, 5.0, 2.0);
break;
}
case 4:
{
std::cout << "square cylinder tiling" << std::endl;
Algo::Surface::Tilings::Square::Cylinder<PFP> c(myMap,20,20);
c.embedIntoCylinder(position,0.5,0.7,5.0);
break;
}
case 5:
{
std::cout << "square cylinder tiling" << std::endl;
Algo::Surface::Tilings::Square::Cylinder<PFP> c(myMap,20,20);
c.triangleBottom();
c.triangleTop();
c.embedIntoCylinder(position,0.5,0.7,5.0);
break;
}
case 6:
{
std::cout << "square cylinder sphere tiling" << std::endl;
Algo::Surface::Tilings::Square::Cylinder<PFP> c(myMap,20,20);
c.triangleTop();
c.triangleBottom();
c.embedIntoSphere(position,0.5);
break;
}
case 7:
{
std::cout << "square cylinder cone tiling" << std::endl;
Algo::Surface::Tilings::Square::Cylinder<PFP> c(myMap,20,20);
c.triangleTop();
c.triangleBottom();
c.embedIntoCone(position,0.5, 5.0);
break;
}
case 8:
{
std::cout << "square cylinder cone tiling" << std::endl;
Algo::Surface::Tilings::Square::Cube<PFP> c(myMap,20,20,20);
c.embedIntoCube(position,5.0,5.0, 5.0);
break;
}
case 9:
{
std::cout << "square cylinder cone tiling" << std::endl;
Algo::Surface::Tilings::Square::Tore<PFP> c(myMap,20,10);
c.embedIntoTore(position,5.0,2.0);
break;
}
default:
{
break;
}
}
// m_positionVBO->updateData(position);
// m_lines->setAttributePosition(m_positionVBO);
// updateGL();
switch(code)
{
case 1:
{
std::cout << "square grid tiling" << std::endl;
Algo::Surface::Tilings::Triangular::Grid<PFP> g(myMap,10,10,true);
g.embedIntoGrid(position,50,50);
break;
}
case 2:
{
// std::cout << "square grid twisted strip tiling" << std::endl;
// Algo::Surface::Tilings::Square::Grid<PFP> g(myMap,10,10,true);
// g.embedIntoTwistedStrip(position, 0.3, 0.8, 5);
break;
}
case 3:
{
// std::cout << "square grid helocoid tiling" << std::endl;
// Algo::Surface::Tilings::Square::Grid<PFP> g(myMap,20,20,true);
// g.embedIntoHelicoid(position, 0.3, 0.8, 5.0, 2.0);
break;
}
case 4:
{
// std::cout << "square cylinder tiling" << std::endl;
// Algo::Surface::Tilings::Square::Cylinder<PFP> c(myMap,20,20);
// c.embedIntoCylinder(position,0.5,0.7,5.0);
break;
}
case 5:
{
// std::cout << "square cylinder tiling" << std::endl;
// Algo::Surface::Tilings::Square::Cylinder<PFP> c(myMap,20,20);
// c.triangleBottom();
// c.triangleTop();
// c.embedIntoCylinder(position,0.5,0.7,5.0);
break;
}
case 6:
{
// std::cout << "square cylinder sphere tiling" << std::endl;
// Algo::Surface::Tilings::Square::Cylinder<PFP> c(myMap,20,20);
// c.triangleTop();
// c.triangleBottom();
// c.embedIntoSphere(position,0.5);
break;
}
case 7:
{
// std::cout << "square cylinder cone tiling" << std::endl;
// Algo::Surface::Tilings::Square::Cylinder<PFP> c(myMap,20,20);
// c.triangleTop();
// c.triangleBottom();
// c.embedIntoCone(position,0.5, 5.0);
break;
}
case 8:
{
// std::cout << "square cylinder cone tiling" << std::endl;
// Algo::Surface::Tilings::Square::Cube<PFP> c(myMap,20,20,20);
// c.embedIntoCube(position,5.0,5.0, 5.0);
break;
}
case 9:
{
// std::cout << "square cylinder cone tiling" << std::endl;
// Algo::Surface::Tilings::Square::Tore<PFP> c(myMap,20,10);
// c.embedIntoTore(position,5.0,2.0);
break;
}
default:
{
break;
}
}
}
int main(int argc, char **argv)
{
// interface:
QApplication app(argc, argv);
MyQT sqt;
// interface:
QApplication app(argc, argv);
MyQT sqt;
sqt.statusMsg("Neww to create a sphere or Load for a mesh file");
CGoGNStream::allToConsole(&sqt);
sqt.statusMsg("Neww to create a sphere or Load for a mesh file");
CGoGNStream::allToConsole(&sqt);
if (!position.isValid())
position = myMap.addAttribute<PFP::VEC3, VERTEX>("position");
if (!position.isValid())
position = myMap.addAttribute<PFP::VEC3, VERTEX>("position");
if (!normal.isValid())
normal = myMap.addAttribute<PFP::VEC3, VERTEX>("normal");
if (!normal.isValid())
normal = myMap.addAttribute<PFP::VEC3, VERTEX>("normal");
if(argc == 2)
{
sqt.tiling(atoi(argv[1]));
}
if(argc == 3)
{
if(argv[1][0] == 'S')
sqt.squareTiling(atoi(argv[2]));
else if(argv[1][0] == 'T')
sqt.triangularTiling(atoi(argv[2]));
}
// bounding box
Geom::BoundingBox<PFP::VEC3> bb = Algo::Geometry::computeBoundingBox<PFP>(myMap, position);
float lWidthObj = std::max<PFP::REAL>(std::max<PFP::REAL>(bb.size(0), bb.size(1)), bb.size(2));
Geom::Vec3f lPosObj = (bb.min() + bb.max()) / PFP::REAL(2);
CGoGNout << "lPosObj=" << lPosObj << CGoGNendl;
CGoGNout << "lWidthObj=" << lWidthObj << CGoGNendl;
sqt.setParamObject(lWidthObj,lPosObj.data());
// bounding box
Geom::BoundingBox<PFP::VEC3> bb = Algo::Geometry::computeBoundingBox<PFP>(myMap, position);
float lWidthObj = std::max<PFP::REAL>(std::max<PFP::REAL>(bb.size(0), bb.size(1)), bb.size(2));
Geom::Vec3f lPosObj = (bb.min() + bb.max()) / PFP::REAL(2);
CGoGNout << "lPosObj=" << lPosObj << CGoGNendl;
CGoGNout << "lWidthObj=" << lWidthObj << CGoGNendl;
sqt.setParamObject(lWidthObj,lPosObj.data());
// myMap.enableQuickTraversal<EDGE>() ;
// myMap.enableQuickTraversal<VERTEX>() ;
// myMap.enableQuickTraversal<EDGE>() ;
// myMap.enableQuickTraversal<VERTEX>() ;
sqt.show();
sqt.show();
return app.exec();
return app.exec();
}
......@@ -37,15 +37,34 @@ namespace Surface
namespace Geometry
{
//! \brief Compute triangle area
//! @param map
//! @param d
//! @param position
//! @return
template <typename PFP>
typename PFP::REAL triangleArea(typename PFP::MAP& map, Dart d, const VertexAttribute<typename PFP::VEC3>& position) ;
//! \brief Compute convex polygonal face area
//! @param map
//! @param d
//! @param position
//! @return
template <typename PFP>
typename PFP::REAL convexFaceArea(typename PFP::MAP& map, Dart d, const VertexAttribute<typename PFP::VEC3>& position) ;
//! \brief Compute the total area of a mesh by summing all face areas.
//! @param map
//! @param position
//! @return
template <typename PFP>
typename PFP::REAL totalArea(typename PFP::MAP& map, const VertexAttribute<typename PFP::VEC3>& position, unsigned int thread = 0) ;
//! \brief Compute the area of the faces around a vertex.
//! @param map
//! @param d
//! @param position
//! @return
template <typename PFP>
typename PFP::REAL vertexOneRingArea(typename PFP::MAP& map, Dart d, const VertexAttribute<typename PFP::VEC3>& position) ;
......
......@@ -25,7 +25,7 @@
#ifndef __MAP2MR_PRIMAL_ADAPT__
#define __MAP2MR_PRIMAL_ADAPT__
#include "Topology/map/embeddedMap2.h"
#include "Topology/ihmap/ihm2.h"
#include "Topology/generic/traversorCell.h"
#include "Topology/generic/traversor2.h"
......@@ -52,8 +52,6 @@ class IHM2
public:
typedef typename PFP::MAP MAP ;
typedef typename PFP::VEC3 VEC3 ;
typedef typename PFP::REAL REAL ;
protected:
MAP& m_map;
......@@ -67,6 +65,59 @@ public:
IHM2(MAP& map) ;
/***************************************************
* CELLS INFORMATION *
***************************************************/
/**
* Return the level of the edge of d in the current level map
*/
unsigned int edgeLevel(Dart d) ;
/**
* Return the level of the face of d in the current level map
*/
unsigned int faceLevel(Dart d) ;
/**
* Given the face of d in the current level map,
* return a level 0 dart of its origin face
*/
Dart faceOrigin(Dart d) ;
/**
* Return the oldest dart of the face of d in the current level map
*/
Dart faceOldestDart(Dart d) ;
/**
* Return true if the edge of d in the current level map
* has already been subdivided to the next level
*/
bool edgeIsSubdivided(Dart d) ;
/**
* Return true if the edge of d in the current level map
* is subdivided to the next level,
* none of its resulting edges is in turn subdivided to the next level
* and the middle vertex is of degree 2
*/
bool edgeCanBeCoarsened(Dart d) ;
/**
* Return true if the face of d in the current level map
* has already been subdivided to the next level
*/
bool faceIsSubdivided(Dart d) ;
/**
* Return true if the face of d in the current level map
* is subdivided to the next level
* and none of its resulting faces is in turn subdivided to the next level
*/
bool faceIsSubdividedOnce(Dart d) ;
protected:
/***************************************************
* SUBDIVISION *
......@@ -88,11 +139,6 @@ public:
*/
unsigned int subdivideFace(Dart d, bool triQuad = true, bool OneLevelDifference = true);
/**
*
*/
unsigned int subdivideFaceSqrt3(Dart d);
/**
* coarsen the face of d from the next level
*/
......
......@@ -50,25 +50,276 @@ IHM2<PFP>::IHM2(typename PFP::MAP& map) :
}
/***************************************************
* CELLS INFORMATION *
***************************************************/
template <typename PFP>
unsigned int IHM2<PFP>::edgeLevel(Dart d)
{
assert(m_map.getDartLevel(d) <= m_map.getCurrentLevel() || !"Access to a dart introduced after current level") ;
unsigned int ld = m_map.getDartLevel(d);
// unsigned int ldd = m_dartLevel[phi2(d)] ; // the level of an edge is the maximum of the
unsigned int ldd = m_map.getDartLevel(m_map.phi1(d));
return ld < ldd ? ldd : ld ;
}
template <typename PFP>
unsigned int IHM2<PFP>::faceLevel(Dart d)
{
assert(m_map.getDartLevel(d) <= m_map.getCurrentLevel() || !"Access to a dart introduced after current level") ;
if(m_map.getCurrentLevel() == 0)
return 0 ;
// unsigned int cur = m_curLevel ;
// Dart it = d ;
// Dart end = d ;
// bool resetEnd = true ;
// bool firstEdge = true ;
// do
// {
// if(!resetEnd)
// firstEdge = false ;
//
// unsigned int eId = m_edgeId[it] ;
// Dart next = it ;
// do
// {
// unsigned int l = edgeLevel(next) ;
// if(l < m_curLevel)
// m_curLevel = l ;
// else // l == curLevel
// {
// if(!firstEdge)
// {
// --m_curLevel ;
// next = it ;
// }
// }
// next = phi1(next) ;
// } while(m_edgeId[next] == eId) ;
// it = next ;
//
// if(resetEnd)
// {
// end = it ;
// resetEnd = false ;
// }
//
// } while(!firstEdge && it != end) ;
//
// unsigned int fLevel = m_curLevel ;
// m_curLevel = cur ;
Dart it = d ;
Dart old = it ;
unsigned int l_old = m_map.getDartLevel(old) ;
unsigned int fLevel = edgeLevel(it) ;
do
{
it = m_map.phi1(it) ;
unsigned int dl = m_map.getDartLevel(it) ;
if(dl < l_old) // compute the oldest dart of the face
{ // in the same time
old = it ;
l_old = dl ;
} // in a first time, the level of a face
unsigned int l = edgeLevel(it) ; // is the minimum of the levels
fLevel = l < fLevel ? l : fLevel ; // of its edges
} while(it != d) ;
unsigned int cur = m_map.getCurrentLevel() ;
m_map.setCurrentLevel(fLevel) ;
// unsigned int nbSubd = 0 ;
// it = old ;
// unsigned int eId = m_map.getEdgeId(old) ; // the