Commit f3132155 authored by untereiner's avatar untereiner

some changes to implicit MR management

parent 10e52114
...@@ -96,11 +96,8 @@ void MyQT::cb_redraw() ...@@ -96,11 +96,8 @@ void MyQT::cb_redraw()
m_render->draw(m_lines, Algo::Render::GL2::POINTS); m_render->draw(m_lines, Algo::Render::GL2::POINTS);
} }
// mouse picking void MyQT::squareTiling(int code)
void MyQT::tiling(int code)
{ {
//myMap.clear(false);
switch(code) switch(code)
{ {
case 1: case 1:
...@@ -187,10 +184,97 @@ void MyQT::tiling(int code) ...@@ -187,10 +184,97 @@ void MyQT::tiling(int code)
break; break;
} }
} }
}
// mouse picking
void MyQT::triangularTiling(int code)
{
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);
// m_positionVBO->updateData(position); break;
// m_lines->setAttributePosition(m_positionVBO); }
// updateGL();
default:
{
break;
}
}
} }
int main(int argc, char **argv) int main(int argc, char **argv)
...@@ -208,9 +292,12 @@ int main(int argc, char **argv) ...@@ -208,9 +292,12 @@ int main(int argc, char **argv)
if (!normal.isValid()) if (!normal.isValid())
normal = myMap.addAttribute<PFP::VEC3, VERTEX>("normal"); normal = myMap.addAttribute<PFP::VEC3, VERTEX>("normal");
if(argc == 2) if(argc == 3)
{ {
sqt.tiling(atoi(argv[1])); if(argv[1][0] == 'S')
sqt.squareTiling(atoi(argv[2]));
else if(argv[1][0] == 'T')
sqt.triangularTiling(atoi(argv[2]));
} }
......
...@@ -37,15 +37,34 @@ namespace Surface ...@@ -37,15 +37,34 @@ namespace Surface
namespace Geometry namespace Geometry
{ {
//! \brief Compute triangle area
//! @param map
//! @param d
//! @param position
//! @return
template <typename PFP> template <typename PFP>
typename PFP::REAL triangleArea(typename PFP::MAP& map, Dart d, const VertexAttribute<typename PFP::VEC3>& position) ; 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> template <typename PFP>
typename PFP::REAL convexFaceArea(typename PFP::MAP& map, Dart d, const VertexAttribute<typename PFP::VEC3>& position) ; 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> template <typename PFP>
typename PFP::REAL totalArea(typename PFP::MAP& map, const VertexAttribute<typename PFP::VEC3>& position, unsigned int thread = 0) ; 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> template <typename PFP>
typename PFP::REAL vertexOneRingArea(typename PFP::MAP& map, Dart d, const VertexAttribute<typename PFP::VEC3>& position) ; typename PFP::REAL vertexOneRingArea(typename PFP::MAP& map, Dart d, const VertexAttribute<typename PFP::VEC3>& position) ;
......
...@@ -25,7 +25,7 @@ ...@@ -25,7 +25,7 @@
#ifndef __MAP2MR_PRIMAL_ADAPT__ #ifndef __MAP2MR_PRIMAL_ADAPT__
#define __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/traversorCell.h"
#include "Topology/generic/traversor2.h" #include "Topology/generic/traversor2.h"
...@@ -52,8 +52,6 @@ class IHM2 ...@@ -52,8 +52,6 @@ class IHM2
public: public:
typedef typename PFP::MAP MAP ; typedef typename PFP::MAP MAP ;
typedef typename PFP::VEC3 VEC3 ;
typedef typename PFP::REAL REAL ;
protected: protected:
MAP& m_map; MAP& m_map;
...@@ -67,6 +65,59 @@ public: ...@@ -67,6 +65,59 @@ public:
IHM2(MAP& map) ; 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: protected:
/*************************************************** /***************************************************
* SUBDIVISION * * SUBDIVISION *
...@@ -88,11 +139,6 @@ public: ...@@ -88,11 +139,6 @@ public:
*/ */
unsigned int subdivideFace(Dart d, bool triQuad = true, bool OneLevelDifference = true); 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 * coarsen the face of d from the next level
*/ */
......
...@@ -50,25 +50,276 @@ IHM2<PFP>::IHM2(typename PFP::MAP& map) : ...@@ -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 particular case of a face
// do // with all neighboring faces regularly subdivided
// { // but not the face itself
// ++nbSubd ; // is treated here
// it = m_map.phi1(it) ;
// } while(m_map.getEdgeId(it) == eId) ;
// while(nbSubd > 1)
// {
// nbSubd /= 2 ;
// --fLevel ;
// }
m_map.setCurrentLevel(cur) ;
return fLevel ;
}
template <typename PFP>
Dart IHM2<PFP>::faceOrigin(Dart d)
{
assert(m_map.getDartLevel(d) <= m_map.getCurrentLevel() || !"Access to a dart introduced after current level") ;
unsigned int cur = m_map.getCurrentLevel() ;
Dart p = d ;
unsigned int pLevel = m_map.getDartLevel(p) ;
while(pLevel > 0)
{
p = faceOldestDart(p) ;
pLevel = m_map.getDartLevel(p) ;
m_map.setCurrentLevel(pLevel) ;
}
m_map.setCurrentLevel(cur) ;
return p ;
}
template <typename PFP>
Dart IHM2<PFP>::faceOldestDart(Dart d)
{
assert(m_map.getDartLevel(d) <= m_map.getCurrentLevel() || !"Access to a dart introduced after current level") ;
Dart it = d ;
Dart oldest = it ;
unsigned int l_old = m_map.getDartLevel(oldest) ;
do
{
unsigned int l = m_map.getDartLevel(it) ;
if(l == 0)
return it ;
if(l < l_old)
// if(l < l_old || (l == l_old && it < oldest))
{
oldest = it ;
l_old = l ;
}
it = m_map.phi1(it) ;
} while(it != d) ;
return oldest ;
}
template <typename PFP>
bool IHM2<PFP>::edgeIsSubdivided(Dart d)
{
assert(m_map.getDartLevel(d) <= m_map.getCurrentLevel() || !"Access to a dart introduced after current level") ;
if(m_map.getCurrentLevel() == m_map.getMaxLevel())
return false ;
// Dart d2 = phi2(d) ;
Dart d1 = m_map.phi1(d) ;
m_map.incCurrentLevel() ;
// Dart d2_l = phi2(d) ;
Dart d1_l = m_map.phi1(d) ;
m_map.decCurrentLevel();
if(d1 != d1_l)
return true ;
else
return false ;
}
template <typename PFP>
bool IHM2<PFP>::edgeCanBeCoarsened(Dart d)
{
assert(m_map.getDartLevel(d) <= m_map.getCurrentLevel() || !"Access to a dart introduced after current level") ;
bool subd = false ;
bool subdOnce = true ;
bool degree2 = false ;
if(edgeIsSubdivided(d))
{
subd = true ;
Dart d2 = m_map.phi2(d) ;
m_map.incCurrentLevel() ;
if(m_map.vertexDegree(m_map.phi1(d)) == 2)
{
degree2 = true ;
if(edgeIsSubdivided(d) || edgeIsSubdivided(d2))
subdOnce = false ;
}
m_map.decCurrentLevel() ;
}
return subd && degree2 && subdOnce ;
}
template <typename PFP>
bool IHM2<PFP>::faceIsSubdivided(Dart d)
{
assert(m_map.getDartLevel(d) <= m_map.getCurrentLevel() || !"Access to a dart introduced after current level") ;
unsigned int fLevel = faceLevel(d) ;
if(fLevel <= m_map.getCurrentLevel())
return false ;
bool subd = false ;
m_map.incCurrentLevel() ;
if(m_map.getDartLevel(m_map.phi1(d)) == m_map.getCurrentLevel() && m_map.getEdgeId(m_map.phi1(d)) != m_map.getEdgeId(d))
subd = true ;
m_map.decCurrentLevel() ;
return subd ;
}
template <typename PFP>
bool IHM2<PFP>::faceIsSubdividedOnce(Dart d)
{
assert(m_map.getDartLevel(d) <= m_map.getCurrentLevel() || !"Access to a dart introduced after current level") ;
unsigned int fLevel = faceLevel(d) ;
if(fLevel < m_map.getCurrentLevel()) // a face whose level in the current level map is lower than
return false ; // the current level can not be subdivided to higher levels
unsigned int degree = 0 ;
bool subd = false ;
bool subdOnce = true ;
Dart fit = d ;
do
{
m_map.incCurrentLevel() ;
if(m_map.getDartLevel(m_map.phi1(fit)) == m_map.getCurrentLevel() && m_map.getEdgeId(m_map.phi1(fit)) != m_map.getEdgeId(fit))
{
subd = true ;
m_map.incCurrentLevel() ;
if(m_map.getDartLevel(m_map.phi1(fit)) == m_map.getCurrentLevel() && m_map.getEdgeId(m_map.phi1(fit)) != m_map.getEdgeId(fit))
subdOnce = false ;
m_map.decCurrentLevel() ;
}
m_map.decCurrentLevel() ;
++degree ;
fit = m_map.phi1(fit) ;
} while(subd && subdOnce && fit != d) ;
if(degree == 3 && subd)
{
m_map.incCurrentLevel() ;
Dart cf = m_map.phi2(m_map.phi1(d)) ;
m_map.incCurrentLevel() ;
if(m_map.getDartLevel(m_map.phi1(cf)) == m_map.getCurrentLevel() && m_map.getEdgeId(m_map.phi1(cf)) != m_map.getEdgeId(cf))
subdOnce = false ;
m_map.decCurrentLevel() ;
m_map.decCurrentLevel() ;
}
return subd && subdOnce ;
}
/***************************************************
* SUBDIVISION *
***************************************************/
template <typename PFP> template <typename PFP>
void IHM2<PFP>::subdivideEdge(Dart d) void IHM2<PFP>::subdivideEdge(Dart d)
{ {
assert(m_map.getDartLevel(d) <= m_map.getCurrentLevel() || !"subdivideEdge : called with a dart inserted after current level") ; assert(m_map.getDartLevel(d) <= m_map.getCurrentLevel() || !"subdivideEdge : called with a dart inserted after current level") ;
assert(!m_map.edgeIsSubdivided(d) || !"Trying to subdivide an already subdivided edge") ; assert(!edgeIsSubdivided(d) || !"Trying to subdivide an already subdivided edge") ;
unsigned int eLevel = m_map.edgeLevel(d) ; unsigned int eLevel = edgeLevel(d) ;
unsigned int cur = m_map.getCurrentLevel() ; unsigned int cur = m_map.getCurrentLevel() ;
m_map.setCurrentLevel(eLevel) ; m_map.setCurrentLevel(eLevel) ;
Dart dd = m_map.phi2(d) ;
m_map.setCurrentLevel(eLevel + 1) ; m_map.setCurrentLevel(eLevel + 1) ;
Dart nd = m_map.cutEdge(d) ; m_map.cutEdge(d) ;
unsigned int eId = m_map.getEdgeId(d) ; unsigned int eId = m_map.getEdgeId(d) ;
m_map.setEdgeId(nd, eId) ; m_map.setEdgeId(m_map.phi1(d), eId) ;
m_map.setEdgeId(m_map.phi2(d), eId) ; m_map.setEdgeId(m_map.phi1(dd), eId) ;
(*edgeVertexFunctor)(nd) ; (*edgeVertexFunctor)(m_map.phi1(d)) ;
m_map.setCurrentLevel(cur) ; m_map.setCurrentLevel(cur) ;
} }
...@@ -94,10 +345,10 @@ template <typename PFP> ...@@ -94,10 +345,10 @@ template <typename PFP>
unsigned int IHM2<PFP>::subdivideFace(Dart d, bool triQuad, bool OneLevelDifference) unsigned int IHM2<PFP>::subdivideFace(Dart d, bool triQuad, bool OneLevelDifference)
{ {
assert(m_map.getDartLevel(d) <= m_map.getCurrentLevel() || !"subdivideFace : called with a dart inserted after current level") ; assert(m_map.getDartLevel(d) <= m_map.getCurrentLevel() || !"subdivideFace : called with a dart inserted after current level") ;
assert(!m_map.faceIsSubdivided(d) || !"Trying to subdivide an already subdivided face") ; assert(!faceIsSubdivided(d) || !"Trying to subdivide an already subdivided face") ;
unsigned int fLevel = m_map.faceLevel(d) ; unsigned int fLevel = faceLevel(d) ;
Dart old = m_map.faceOldestDart(d) ; Dart old = faceOldestDart(d) ;
unsigned int cur = m_map.getCurrentLevel() ; unsigned int cur = m_map.getCurrentLevel() ;
m_map.setCurrentLevel(fLevel) ; // go to the level of the face to subdivide its edges m_map.setCurrentLevel(fLevel) ; // go to the level of the face to subdivide its edges
...@@ -108,14 +359,14 @@ unsigned int IHM2<PFP>::subdivideFace(Dart d, bool triQuad, bool OneLevelDiffere ...@@ -108,14 +359,14 @@ unsigned int IHM2<PFP>::subdivideFace(Dart d, bool triQuad, bool OneLevelDiffere
{ {
++degree ; // compute the degree of the face ++degree ; // compute the degree of the face
//if(OneLevelDifference) if(OneLevelDifference)
//{ {
// Dart nf = m_map.phi2(it) ;