Commit ac810106 authored by Pierre Kraemer's avatar Pierre Kraemer

advances in feature lines detection

parent 9ec12abd
/******************************************************************************* /*******************************************************************************
* CGoGN: Combinatorial and Geometric modeling with Generic N-dimensional Maps * * CGoGN: Combinatorial and Geometric modeling with Generic N-dimensional Maps *
* version 0.1 * * version 0.1 *
* Copyright (C) 2009-2012, IGG Team, LSIIT, University of Strasbourg * * Copyright (C) 2009-2011, IGG Team, LSIIT, University of Strasbourg *
* * * *
* This library is free software; you can redistribute it and/or modify it * * 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 * * under the terms of the GNU Lesser General Public License as published by the *
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
* along with this library; if not, write to the Free Software Foundation, * * along with this library; if not, write to the Free Software Foundation, *
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. *
* * * *
* Web site: http://cgogn.unistra.fr/ * * Web site: http://cgogn.u-strasbg.fr/ *
* Contact information: cgogn@unistra.fr * * Contact information: cgogn@unistra.fr *
* * * *
*******************************************************************************/ *******************************************************************************/
...@@ -37,9 +37,42 @@ namespace Geometry ...@@ -37,9 +37,42 @@ namespace Geometry
template <typename PFP> template <typename PFP>
void featureEdgeDetection(typename PFP::MAP& map, const typename PFP::TVEC3& position, CellMarker& featureEdge) ; void featureEdgeDetection(typename PFP::MAP& map, const typename PFP::TVEC3& position, CellMarker& featureEdge) ;
template <typename PFP>
void computeArea(typename PFP::MAP& map, const typename PFP::TVEC3& position, typename PFP::TREAL& area, const FunctorSelect& select = allDarts, unsigned int thread = 0) ;
template <typename PFP>
void computeFaceGradient(typename PFP::MAP& map, const typename PFP::TVEC3& position, typename PFP::TVEC3& face_gradient, const typename PFP::TVEC3& face_normal, const typename PFP::TREAL& kmax, const typename PFP::TREAL& area, const FunctorSelect& select = allDarts, unsigned int thread = 0) ;
template <typename PFP>
void computeGradient(typename PFP::MAP& map, const typename PFP::TVEC3& position, typename PFP::TVEC3& gradient, typename PFP::TVEC3& face_gradient, const typename PFP::TREAL& area, const FunctorSelect& select = allDarts, unsigned int thread = 0) ;
template <typename PFP>
void computeTriangleType(typename PFP::MAP& map, const typename PFP::TVEC3& position, CellMarker& regularMarker, const FunctorSelect& select = allDarts, unsigned int thread = 0) ;
template <typename PFP>
void computeCurvatureSign(typename PFP::MAP& map, const typename PFP::TVEC3& position, typename PFP::TVEC3& triangle_type, typename PFP::TVEC3& k, const FunctorSelect& select = allDarts, unsigned int thread = 0) ;
template <typename PFP> template <typename PFP>
std::vector<typename PFP::VEC3> occludingContoursDetection(typename PFP::MAP& map, const typename PFP::VEC3& cameraPosition, const typename PFP::TVEC3& position, const typename PFP::TVEC3& normal) ; std::vector<typename PFP::VEC3> occludingContoursDetection(typename PFP::MAP& map, const typename PFP::VEC3& cameraPosition, const typename PFP::TVEC3& position, const typename PFP::TVEC3& normal) ;
template <typename PFP>
typename PFP::TREAL faceArea(typename PFP::MAP& map, Dart d, const typename PFP::TVEC3& position) ;
template <typename PFP>
typename PFP::VEC3 faceGradient(typename PFP::MAP& map, Dart d, const typename PFP::TVEC3& position, const typename PFP::TVEC3& face_normal, const typename PFP::TREAL& kmax, const typename PFP::TREAL& area) ;
template <typename PFP>
bool triangleType(typename PFP::MAP& map, Dart d, const typename PFP::TVEC3& position) ;
template <typename PFP>
bool isInSameOctant(const typename PFP::VEC3& pos1, const typename PFP::VEC3& pos2) ;
template <typename PFP>
void curvatureSign(typename PFP::MAP& map, Dart d, const typename PFP::TVEC3& position, typename PFP::TVEC3& triangle_type, typename PFP::TVEC3& k) ;
template <typename PFP>
typename PFP::TVEC3 vertexGradient(typename PFP::MAP& map, Dart d, const typename PFP::TVEC3& position, const typename PFP::TVEC3& face_gradient, const typename PFP::TREAL& area) ;
} // namespace Geometry } // namespace Geometry
} // namespace Algo } // namespace Algo
......
/******************************************************************************* /*******************************************************************************
* CGoGN: Combinatorial and Geometric modeling with Generic N-dimensional Maps * * CGoGN: Combinatorial and Geometric modeling with Generic N-dimensional Maps *
* version 0.1 * * version 0.1 *
* Copyright (C) 2009-2012, IGG Team, LSIIT, University of Strasbourg * * Copyright (C) 2009-2011, IGG Team, LSIIT, University of Strasbourg *
* * * *
* This library is free software; you can redistribute it and/or modify it * * 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 * * under the terms of the GNU Lesser General Public License as published by the *
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
* along with this library; if not, write to the Free Software Foundation, * * along with this library; if not, write to the Free Software Foundation, *
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. *
* * * *
* Web site: http://cgogn.unistra.fr/ * * Web site: http://cgogn.u-strasbg.fr/ *
* Contact information: cgogn@unistra.fr * * Contact information: cgogn@unistra.fr *
* * * *
*******************************************************************************/ *******************************************************************************/
...@@ -58,6 +58,53 @@ void featureEdgeDetection(typename PFP::MAP& map, typename PFP::TVEC3& position, ...@@ -58,6 +58,53 @@ void featureEdgeDetection(typename PFP::MAP& map, typename PFP::TVEC3& position,
// map.template removeAttribute<VEC3>(fNormal) ; // map.template removeAttribute<VEC3>(fNormal) ;
} }
template <typename PFP>
void computeArea(typename PFP::MAP& map, const typename PFP::TVEC3& position, typename PFP::TREAL& area, const FunctorSelect& select = allDarts, unsigned int thread = 0)
{
TraversorF<typename PFP::MAP> trav(map, select, thread);
for (Dart d = trav.begin(); d != trav.end(); d = trav.next())
area[d] = faceArea<PFP>(map, d, position)[1] ;
}
template <typename PFP>
void computeFaceGradient(typename PFP::MAP& map, const typename PFP::TVEC3& position, typename PFP::TVEC3& face_gradient, const typename PFP::TVEC3& face_normal, const typename PFP::TREAL& kmax, const typename PFP::TREAL& area, const FunctorSelect& select = allDarts, unsigned int thread = 0)
{
TraversorF<typename PFP::MAP> trav(map, select, thread);
for (Dart d = trav.begin(); d != trav.end(); d = trav.next())
face_gradient[d] = faceGradient<PFP>(map, d, position, face_normal, kmax, area) ;
}
template <typename PFP>
void computeGradient(typename PFP::MAP& map, const typename PFP::TVEC3& position, typename PFP::TVEC3& gradient, typename PFP::TVEC3& face_gradient, const typename PFP::TREAL& area, const FunctorSelect& select = allDarts, unsigned int thread = 0)
{
TraversorV<typename PFP::MAP> trav(map, select, thread);
for (Dart d = trav.begin(); d != trav.end(); d = trav.next())
gradient[d] = vertexGradient<PFP>(map, d, position, face_gradient, area) ;
}
template <typename PFP>
void computeTriangleType(typename PFP::MAP& map, const typename PFP::TVEC3& position, CellMarker& regularMarker, const FunctorSelect& select = allDarts, unsigned int thread = 0)
{
TraversorF<typename PFP::MAP> trav(map, select, thread);
for (Dart d = trav.begin(); d != trav.end(); d = trav.next())
if(triangleType<PFP>(map, d, position))
regularMarker.mark(d) ;
}
template <typename PFP>
void computeCurvatureSign(typename PFP::MAP& map, const typename PFP::TVEC3& position, typename PFP::TVEC3& triangle_type, typename PFP::TVEC3& k, const FunctorSelect& select = allDarts, unsigned int thread = 0)
{
CellMarker mv(map, VERTEX, thread);
TraversorV<typename PFP::MAP> trav(map, select, thread);
for (Dart d = trav.begin(); d != trav.end(); d = trav.next())
{
if (!mv.isMarked(d))
{
curvatureSign<PFP>(map, d, position, triangle_type, k) ;
}
}
}
template <typename PFP> template <typename PFP>
std::vector<typename PFP::VEC3> occludingContoursDetection(typename PFP::MAP& map, const typename PFP::VEC3& cameraPosition, const typename PFP::TVEC3& position, const typename PFP::TVEC3& normal) std::vector<typename PFP::VEC3> occludingContoursDetection(typename PFP::MAP& map, const typename PFP::VEC3& cameraPosition, const typename PFP::TVEC3& position, const typename PFP::TVEC3& normal)
{ {
...@@ -112,6 +159,188 @@ std::vector<typename PFP::VEC3> occludingContoursDetection(typename PFP::MAP& ma ...@@ -112,6 +159,188 @@ std::vector<typename PFP::VEC3> occludingContoursDetection(typename PFP::MAP& ma
return occludingContours ; return occludingContours ;
} }
template <typename PFP>
float faceArea(typename PFP::MAP& map, Dart d, const typename PFP::TVEC3& position)
{
typedef typename PFP::REAL REAL ;
typedef typename PFP::VEC3 VEC3 ;
float A [1] ;
VEC3 pos1(0) ;
VEC3 pos2(0) ;
VEC3 pos3(0) ;
Traversor2FV<typename PFP::MAP> t(map, d) ;
Dart it = t.begin() ;
pos1 += position[it] ;
it = t.next ;
pos2 += position[it] ;
it = t.next ;
pos3 += position[it] ;
A = 1/2 * abs(
( (pos2.x - pos1.x) * (pos3.y - pos1.y) )
-
( (pos3.x - pos1.x) * (pos2.y - pos1.y) )
) ;
return A ;
}
template <typename PFP>
typename PFP::VEC3 faceGradient(typename PFP::MAP& map, Dart d, const typename PFP::TVEC3& position, const typename PFP::TVEC3& face_normal, const typename PFP::TREAL& kmax, const typename PFP::TREAL& area)
{
typedef typename PFP::REAL REAL ;
typedef typename PFP::VEC3 VEC3 ;
VEC3 G(0) ;
VEC3 pos1(0) ;
VEC3 pos2(0) ;
VEC3 pos3(0) ;
VEC3 n = face_normal[d] ;
REAL k1 ;
REAL k2 ;
REAL k3 ;
REAL a = area[d] ;
Traversor2FV<typename PFP::MAP> t(map, d) ;
Dart it = t.begin() ;
pos1 += position[it] ;
k1 = kmax[it] ;
it = t.next() ;
pos2 += position[it] ;
k2 = kmax[it] ;
it = t.next() ;
pos3 += position[it] ;
k3 = kmax[it] ;
G += k1 * ( ( n ^ ( pos3 - pos2 ) ) / ( 2 * a ) ) +
k2 * ( ( n ^ ( pos1 - pos3 ) ) / ( 2 * a ) ) +
k3 * ( ( n ^ ( pos2 - pos1 ) ) / ( 2 * a ) ) ;
G.normalize() ;
return G ;
}
template <typename PFP>
bool triangleType(typename PFP::MAP& map, Dart d, const typename PFP::TVEC3& position)
{
typedef typename PFP::REAL REAL ;
typedef typename PFP::VEC3 VEC3 ;
VEC3 pos1(0) ;
VEC3 pos2(0) ;
VEC3 pos3(0) ;
Traversor2FV<typename PFP::MAP> t(map, d) ;
Dart it = t.begin() ;
pos1 += position[it] ;
it = t.next() ;
pos2 += position[it] ;
it = t.next() ;
pos3 += position[it] ;
if ( isInSameOctant<PFP>(pos1,pos2) && isInSameOctant<PFP>(pos1,pos3) )
{
//regular triangle
return true ;
}
else
{
//singular triangle
return false ;
}
}
template <typename PFP>
bool isInSameOctant(const typename PFP::VEC3& pos1, const typename PFP::VEC3& pos2)
{
return ( ( pos1[0] > 0 && pos1[1] > 0 && pos1[2] > 0 && //one of the eight octant
( ( pos2[0] > 0 && pos2[1] > 0 && pos2[2] > 0 ) or //one choice of sign
( pos2[0] < 0 && pos2[1] < 0 && pos2[2] < 0 ) ) ) or //the other choice
( pos1[0] > 0 && pos1[1] > 0 && pos1[2] < 0 &&
( ( pos2[0] > 0 && pos2[1] > 0 && pos2[2] < 0 ) or
( pos2[0] < 0 && pos2[1] < 0 && pos2[2] > 0 ) ) ) or
( pos1[0] > 0 && pos1[1] < 0 && pos1[2] > 0 &&
( ( pos2[0] > 0 && pos2[1] < 0 && pos2[2] > 0 ) or
( pos2[0] < 0 && pos2[1] > 0 && pos2[2] < 0 ) ) ) or
( pos1[0] > 0 && pos1[1] < 0 && pos1[2] < 0 &&
( ( pos2[0] > 0 && pos2[1] < 0 && pos2[2] < 0 ) or
( pos2[0] < 0 && pos2[1] > 0 && pos2[2] > 0 ) ) ) or
( pos1[0] < 0 && pos1[1] > 0 && pos1[2] > 0 &&
( ( pos2[0] < 0 && pos2[1] > 0 && pos2[2] > 0 ) or
( pos2[0] > 0 && pos2[1] < 0 && pos2[2] < 0 ) ) ) or
( pos1[0] < 0 && pos1[1] > 0 && pos1[2] < 0 &&
( ( pos2[0] < 0 && pos2[1] > 0 && pos2[2] < 0 ) or
( pos2[0] > 0 && pos2[1] < 0 && pos2[2] > 0 ) ) ) or
( pos1[0] < 0 && pos1[1] < 0 && pos1[2] > 0 &&
( ( pos2[0] < 0 && pos2[1] < 0 && pos2[2] > 0 ) or
( pos2[0] > 0 && pos2[1] > 0 && pos2[2] < 0 ) ) ) or
( pos1[0] < 0 && pos1[1] < 0 && pos1[2] < 0 &&
( ( pos2[0] < 0 && pos2[1] < 0 && pos2[2] < 0 ) or
( pos2[0] > 0 && pos2[1] > 0 && pos2[2] > 0 ) ) ) ) ;
}
template <typename PFP>
void curvatureSign(typename PFP::MAP& map, Dart d, const typename PFP::TVEC3& position, typename PFP::TVEC3& triangle_type, typename PFP::TVEC3& k)
{
/*sommetTraité = true ;*/
Traversor2VE<typename PFP::MAP> trav2(map, d) ;
for (Dart d2 = trav2.begin(); d2 != trav2.end(); d2 = trav2.next())
{
if (/*arrete non traité*/ true)
{
if((k[d] * k[d2]) <= 0)
{
k[d2] *= -1 ;
}
/*arreteTraité = true ;*/
/*meme chose avec sommet le long de l'arrete*/
/*curvatureSign(sommet le long del'arrete) ;*/
}
}
}
template <typename PFP>
typename PFP::TVEC3 vertexGradient(typename PFP::MAP& map, Dart d, const typename PFP::TVEC3& position, const typename PFP::TVEC3& face_gradient, const typename PFP::TREAL& area)
{
typedef typename PFP::REAL REAL ;
typedef typename PFP::VEC3 VEC3 ;
VEC3 G(0) ;
REAL A = 0 ;
Traversor2VF<typename PFP::MAP> t(map, d) ;
for (Dart d = t.begin(); d != t.end(); d = t.next())
{
G += area[d] * face_gradient[d] ;
A += area[d] ;
}
G = G / A ;
G.normalize() ;
return G ;
}
} // namespace Geometry } // namespace Geometry
} // namespace Algo } // namespace Algo
......
...@@ -58,7 +58,7 @@ template <typename T> ...@@ -58,7 +58,7 @@ template <typename T>
AttributeHandler<T>::AttributeHandler(GenericMap* m, AttributeMultiVector<T>* amv) : AttributeHandler<T>::AttributeHandler(GenericMap* m, AttributeMultiVector<T>* amv) :
AttributeHandlerGen(m, false), m_attrib(amv) AttributeHandlerGen(m, false), m_attrib(amv)
{ {
if(amv != NULL && amv->getIndex() != AttributeContainer::UNKNOWN) if(m != NULL && amv != NULL && amv->getIndex() != AttributeContainer::UNKNOWN)
{ {
valid = true ; valid = true ;
registerInMap() ; registerInMap() ;
......
...@@ -252,20 +252,7 @@ bool Map2MR_PrimalAdapt::faceIsSubdividedOnce(Dart d) ...@@ -252,20 +252,7 @@ bool Map2MR_PrimalAdapt::faceIsSubdividedOnce(Dart d)
void Map2MR_PrimalAdapt::addNewLevel(bool embedNewVertices) void Map2MR_PrimalAdapt::addNewLevel(bool embedNewVertices)
{ {
pushLevel() ;
addLevel() ; addLevel() ;
setCurrentLevel(getMaxLevel()) ;
// for(unsigned int i = m_mrattribs.begin(); i != m_mrattribs.end(); m_mrattribs.next(i))
// {
// unsigned int newindex = copyDartLine((*m_mrDarts[m_mrCurrentLevel])[i]) ; // duplicate all darts
// (*m_mrDarts[m_mrCurrentLevel])[i] = newindex ; // on the new max level
// if(!shareVertexEmbeddings)
// (*m_embeddings[VERTEX])[newindex] = EMBNULL ; // set vertex embedding to EMBNULL if no sharing
// }
popLevel() ;
} }
void Map2MR_PrimalAdapt::propagateDartRelation(Dart d, AttributeMultiVector<Dart>* rel) void Map2MR_PrimalAdapt::propagateDartRelation(Dart d, AttributeMultiVector<Dart>* rel)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment