Commit 9ec8e54b authored by Pierre Kraemer's avatar Pierre Kraemer

static attribute parameters check in normal computation

parent 735e431d
...@@ -78,7 +78,7 @@ template <typename MAP, typename ATT> ...@@ -78,7 +78,7 @@ template <typename MAP, typename ATT>
void applySmooth(MAP& map, const ATT& att_in, ATT& att_out) void applySmooth(MAP& map, const ATT& att_in, ATT& att_out)
{ {
// check at compile if ATT is an AttributeHandler on orbit VERTEX // check at compile if ATT is an AttributeHandler on orbit VERTEX
CHECK_ATTRIBUTEHANDER_ORBIT_TYPE(ATT,VERTEX); CHECK_ATTRIBUTEHANDLER_ORBIT(ATT, VERTEX);
foreach_cell<VERTEX>(map,[&](Vertex v) // for all vertex v of map do foreach_cell<VERTEX>(map,[&](Vertex v) // for all vertex v of map do
{ {
......
...@@ -112,15 +112,15 @@ void computeNewPositions(MAP& map, VertexAttribute<VEC3, MAP>& pos) ...@@ -112,15 +112,15 @@ void computeNewPositions(MAP& map, VertexAttribute<VEC3, MAP>& pos)
template<typename ATTRIB> template<typename ATTRIB>
void dumpAttribute(const ATTRIB& attr) void dumpAttribute(const ATTRIB& attr)
{ {
CHECK_ATTRIBUTEHANDER__TYPE(ATTRIB); CHECK_ATTRIBUTEHANDLER(ATTRIB);
std::cout << "Attribute " <<attr.name() << " of orbit "<< orbitName(attr.getOrbit())<< " of type "<< attr.typeName()<< std::endl; std::cout << "Attribute " << attr.name() << " of orbit " << orbitName(attr.getOrbit()) << " of type " << attr.typeName() << std::endl;
// NEVER USE 0 AND ++ IN FOR LOOP ON ATTRIBUTE ! // NEVER USE 0 AND ++ IN FOR LOOP ON ATTRIBUTE !
// USE ONLY BEGIN / END / NEXT (for hole jumping over) // USE ONLY BEGIN / END / NEXT (for hole jumping over)
for (unsigned int i=attr.begin(); i!=attr.end(); attr.next(i)) for (unsigned int i = attr.begin(); i != attr.end(); attr.next(i))
{ {
std::cout << attr.name() << "["<< i << "] = "<<attr[i]<< std::endl; std::cout << attr.name() << "[" << i << "] = " << attr[i] << std::endl;
} }
} }
......
...@@ -45,6 +45,8 @@ namespace Geometry ...@@ -45,6 +45,8 @@ namespace Geometry
template<typename PFP, typename V_ATT> template<typename PFP, typename V_ATT>
typename V_ATT::DATA_TYPE triangleNormal(typename PFP::MAP& map, Face f, const V_ATT& position) typename V_ATT::DATA_TYPE triangleNormal(typename PFP::MAP& map, Face f, const V_ATT& position)
{ {
CHECK_ATTRIBUTEHANDLER_ORBIT(V_ATT, VERTEX);
typename V_ATT::DATA_TYPE N = Geom::triangleNormal( typename V_ATT::DATA_TYPE N = Geom::triangleNormal(
position[f.dart], position[f.dart],
position[map.phi1(f)], position[map.phi1(f)],
...@@ -57,6 +59,8 @@ typename V_ATT::DATA_TYPE triangleNormal(typename PFP::MAP& map, Face f, const V ...@@ -57,6 +59,8 @@ typename V_ATT::DATA_TYPE triangleNormal(typename PFP::MAP& map, Face f, const V
template<typename PFP, typename V_ATT> template<typename PFP, typename V_ATT>
typename V_ATT::DATA_TYPE newellNormal(typename PFP::MAP& map, Face f, const V_ATT& position) typename V_ATT::DATA_TYPE newellNormal(typename PFP::MAP& map, Face f, const V_ATT& position)
{ {
CHECK_ATTRIBUTEHANDLER_ORBIT(V_ATT, VERTEX);
typedef typename V_ATT::DATA_TYPE VEC3; typedef typename V_ATT::DATA_TYPE VEC3;
VEC3 N(0); VEC3 N(0);
...@@ -76,6 +80,8 @@ typename V_ATT::DATA_TYPE newellNormal(typename PFP::MAP& map, Face f, const V_A ...@@ -76,6 +80,8 @@ typename V_ATT::DATA_TYPE newellNormal(typename PFP::MAP& map, Face f, const V_A
template<typename PFP, typename V_ATT> template<typename PFP, typename V_ATT>
typename V_ATT::DATA_TYPE faceNormal(typename PFP::MAP& map, Face f, const V_ATT& position) typename V_ATT::DATA_TYPE faceNormal(typename PFP::MAP& map, Face f, const V_ATT& position)
{ {
CHECK_ATTRIBUTEHANDLER_ORBIT(V_ATT, VERTEX);
if(map.faceDegree(f) == 3) if(map.faceDegree(f) == 3)
return triangleNormal<PFP>(map, f, position) ; return triangleNormal<PFP>(map, f, position) ;
else else
...@@ -85,7 +91,7 @@ typename V_ATT::DATA_TYPE faceNormal(typename PFP::MAP& map, Face f, const V_ATT ...@@ -85,7 +91,7 @@ typename V_ATT::DATA_TYPE faceNormal(typename PFP::MAP& map, Face f, const V_ATT
template<typename PFP, typename V_ATT> template<typename PFP, typename V_ATT>
typename V_ATT::DATA_TYPE vertexNormal(typename PFP::MAP& map, Vertex v, const V_ATT& position) typename V_ATT::DATA_TYPE vertexNormal(typename PFP::MAP& map, Vertex v, const V_ATT& position)
{ {
CHECK_ATTRIBUTEHANDER_ORBIT_TYPE(V_ATT,VERTEX); CHECK_ATTRIBUTEHANDLER_ORBIT(V_ATT, VERTEX);
typedef typename V_ATT::DATA_TYPE VEC3 ; typedef typename V_ATT::DATA_TYPE VEC3 ;
...@@ -111,11 +117,10 @@ typename V_ATT::DATA_TYPE vertexNormal(typename PFP::MAP& map, Vertex v, const V ...@@ -111,11 +117,10 @@ typename V_ATT::DATA_TYPE vertexNormal(typename PFP::MAP& map, Vertex v, const V
return N ; return N ;
} }
template<typename PFP, typename V_ATT> template<typename PFP, typename V_ATT>
typename V_ATT::DATA_TYPE vertexBorderNormal(typename PFP::MAP& map, Vertex v, const V_ATT& position) typename V_ATT::DATA_TYPE vertexBorderNormal(typename PFP::MAP& map, Vertex v, const V_ATT& position)
{ {
CHECK_ATTRIBUTEHANDLER_ORBIT(V_ATT, VERTEX);
assert(map.dimension() == 3); assert(map.dimension() == 3);
typedef typename V_ATT::DATA_TYPE VEC3 ; typedef typename V_ATT::DATA_TYPE VEC3 ;
...@@ -151,6 +156,9 @@ typename V_ATT::DATA_TYPE vertexBorderNormal(typename PFP::MAP& map, Vertex v, c ...@@ -151,6 +156,9 @@ typename V_ATT::DATA_TYPE vertexBorderNormal(typename PFP::MAP& map, Vertex v, c
template <typename PFP, typename V_ATT, typename F_ATT> template <typename PFP, typename V_ATT, typename F_ATT>
void computeNormalFaces(typename PFP::MAP& map, const V_ATT& position, F_ATT& face_normal, unsigned int thread) void computeNormalFaces(typename PFP::MAP& map, const V_ATT& position, F_ATT& face_normal, unsigned int thread)
{ {
CHECK_ATTRIBUTEHANDLER_ORBIT(V_ATT, VERTEX);
CHECK_ATTRIBUTEHANDLER_ORBIT(F_ATT, FACE);
if ((CGoGN::Parallel::NumberOfThreads > 1) && (thread == 0)) if ((CGoGN::Parallel::NumberOfThreads > 1) && (thread == 0))
{ {
Parallel::computeNormalFaces<PFP,V_ATT,F_ATT>(map, position, face_normal); Parallel::computeNormalFaces<PFP,V_ATT,F_ATT>(map, position, face_normal);
...@@ -166,6 +174,8 @@ void computeNormalFaces(typename PFP::MAP& map, const V_ATT& position, F_ATT& fa ...@@ -166,6 +174,8 @@ void computeNormalFaces(typename PFP::MAP& map, const V_ATT& position, F_ATT& fa
template <typename PFP, typename V_ATT> template <typename PFP, typename V_ATT>
void computeNormalVertices(typename PFP::MAP& map, const V_ATT& position, V_ATT& normal, unsigned int thread) void computeNormalVertices(typename PFP::MAP& map, const V_ATT& position, V_ATT& normal, unsigned int thread)
{ {
CHECK_ATTRIBUTEHANDLER_ORBIT(V_ATT, VERTEX);
if ((CGoGN::Parallel::NumberOfThreads > 1) && (thread == 0)) if ((CGoGN::Parallel::NumberOfThreads > 1) && (thread == 0))
{ {
Parallel::computeNormalVertices<PFP,V_ATT>(map, position, normal); Parallel::computeNormalVertices<PFP,V_ATT>(map, position, normal);
...@@ -181,6 +191,8 @@ void computeNormalVertices(typename PFP::MAP& map, const V_ATT& position, V_ATT& ...@@ -181,6 +191,8 @@ void computeNormalVertices(typename PFP::MAP& map, const V_ATT& position, V_ATT&
template <typename PFP, typename V_ATT> template <typename PFP, typename V_ATT>
typename PFP::REAL computeAngleBetweenNormalsOnEdge(typename PFP::MAP& map, Edge e, const V_ATT& position) typename PFP::REAL computeAngleBetweenNormalsOnEdge(typename PFP::MAP& map, Edge e, const V_ATT& position)
{ {
CHECK_ATTRIBUTEHANDLER_ORBIT(V_ATT, VERTEX);
typedef typename V_ATT::DATA_TYPE VEC3 ; typedef typename V_ATT::DATA_TYPE VEC3 ;
if(map.isBoundaryEdge(e)) if(map.isBoundaryEdge(e))
...@@ -214,6 +226,9 @@ typename PFP::REAL computeAngleBetweenNormalsOnEdge(typename PFP::MAP& map, Edge ...@@ -214,6 +226,9 @@ typename PFP::REAL computeAngleBetweenNormalsOnEdge(typename PFP::MAP& map, Edge
template <typename PFP, typename V_ATT, typename E_ATT> template <typename PFP, typename V_ATT, typename E_ATT>
void computeAnglesBetweenNormalsOnEdges(typename PFP::MAP& map, const V_ATT& position, E_ATT& angles, unsigned int thread) void computeAnglesBetweenNormalsOnEdges(typename PFP::MAP& map, const V_ATT& position, E_ATT& angles, unsigned int thread)
{ {
CHECK_ATTRIBUTEHANDLER_ORBIT(V_ATT, VERTEX);
CHECK_ATTRIBUTEHANDLER_ORBIT(E_ATT, EDGE);
if ((CGoGN::Parallel::NumberOfThreads > 1) && (thread == 0)) if ((CGoGN::Parallel::NumberOfThreads > 1) && (thread == 0))
{ {
Parallel::computeAnglesBetweenNormalsOnEdges<PFP,V_ATT,E_ATT>(map, position, angles); Parallel::computeAnglesBetweenNormalsOnEdges<PFP,V_ATT,E_ATT>(map, position, angles);
...@@ -233,6 +248,8 @@ namespace Parallel ...@@ -233,6 +248,8 @@ namespace Parallel
template <typename PFP, typename V_ATT> template <typename PFP, typename V_ATT>
void computeNormalVertices(typename PFP::MAP& map, const V_ATT& position, V_ATT& normal) void computeNormalVertices(typename PFP::MAP& map, const V_ATT& position, V_ATT& normal)
{ {
CHECK_ATTRIBUTEHANDLER_ORBIT(V_ATT, VERTEX);
CGoGN::Parallel::foreach_cell<VERTEX>(map, [&] (Vertex v, unsigned int /*thr*/) CGoGN::Parallel::foreach_cell<VERTEX>(map, [&] (Vertex v, unsigned int /*thr*/)
{ {
normal[v] = vertexNormal<PFP>(map, v, position) ; normal[v] = vertexNormal<PFP>(map, v, position) ;
...@@ -242,6 +259,9 @@ void computeNormalVertices(typename PFP::MAP& map, const V_ATT& position, V_ATT& ...@@ -242,6 +259,9 @@ void computeNormalVertices(typename PFP::MAP& map, const V_ATT& position, V_ATT&
template <typename PFP, typename V_ATT, typename F_ATT> template <typename PFP, typename V_ATT, typename F_ATT>
void computeNormalFaces(typename PFP::MAP& map, const V_ATT& position, F_ATT& normal) void computeNormalFaces(typename PFP::MAP& map, const V_ATT& position, F_ATT& normal)
{ {
CHECK_ATTRIBUTEHANDLER_ORBIT(V_ATT, VERTEX);
CHECK_ATTRIBUTEHANDLER_ORBIT(F_ATT, FACE);
CGoGN::Parallel::foreach_cell<FACE>(map, [&] (Face f, unsigned int /*thr*/) CGoGN::Parallel::foreach_cell<FACE>(map, [&] (Face f, unsigned int /*thr*/)
{ {
normal[f] = faceNormal<PFP>(map, f, position) ; normal[f] = faceNormal<PFP>(map, f, position) ;
...@@ -251,6 +271,9 @@ void computeNormalFaces(typename PFP::MAP& map, const V_ATT& position, F_ATT& no ...@@ -251,6 +271,9 @@ void computeNormalFaces(typename PFP::MAP& map, const V_ATT& position, F_ATT& no
template <typename PFP, typename V_ATT, typename E_ATT> template <typename PFP, typename V_ATT, typename E_ATT>
void computeAnglesBetweenNormalsOnEdges(typename PFP::MAP& map, const V_ATT& position, E_ATT& angles) void computeAnglesBetweenNormalsOnEdges(typename PFP::MAP& map, const V_ATT& position, E_ATT& angles)
{ {
CHECK_ATTRIBUTEHANDLER_ORBIT(V_ATT, VERTEX);
CHECK_ATTRIBUTEHANDLER_ORBIT(E_ATT, EDGE);
CGoGN::Parallel::foreach_cell<EDGE>(map,[&](Edge e, unsigned int /*thr*/) CGoGN::Parallel::foreach_cell<EDGE>(map,[&](Edge e, unsigned int /*thr*/)
{ {
angles[e] = computeAngleBetweenNormalsOnEdge<PFP>(map, e, position) ; angles[e] = computeAngleBetweenNormalsOnEdge<PFP>(map, e, position) ;
......
...@@ -33,13 +33,14 @@ ...@@ -33,13 +33,14 @@
#include "Container/fakeAttribute.h" #include "Container/fakeAttribute.h"
#include "Topology/generic/cells.h" #include "Topology/generic/cells.h"
/// Macro that check if ATTRIBUTEHANDLER type is an AttributeHandler of orbit ORBITVALUE /// Macro that checks if ATTRIBUTEHANDLER type is an AttributeHandler
#define CHECK_ATTRIBUTEHANDER_ORBIT_TYPE(ATTRIBUTEHANDLER, ORBITVALUE) \ #define CHECK_ATTRIBUTEHANDLER(ATTRIBUTEHANDLER)\
static_assert(std::is_base_of<AttributeHandlerGen,ATTRIBUTEHANDLER>::value, "Error not AttributeHandler");\ static_assert(std::is_base_of<AttributeHandlerGen, ATTRIBUTEHANDLER>::value, "Error not AttributeHandler");
static_assert(ATTRIBUTEHANDLER::ORBIT==ORBITVALUE,"Error wrong orbit of AttributeHandler");
#define CHECK_ATTRIBUTEHANDER__TYPE(ATTRIBUTEHANDLER) \ /// Macro that checks if ATTRIBUTEHANDLER type is an AttributeHandler of orbit ORBITVALUE
static_assert(std::is_base_of<AttributeHandlerGen,ATTRIBUTEHANDLER>::value, "Error not AttributeHandler"); #define CHECK_ATTRIBUTEHANDLER_ORBIT(ATTRIBUTEHANDLER, ORBITVALUE)\
static_assert(std::is_base_of<AttributeHandlerGen, ATTRIBUTEHANDLER>::value, "Error not AttributeHandler");\
static_assert(ATTRIBUTEHANDLER::ORBIT == ORBITVALUE, "Error wrong orbit of AttributeHandler");
namespace CGoGN namespace CGoGN
{ {
...@@ -58,10 +59,7 @@ public: ...@@ -58,10 +59,7 @@ public:
valid(v) valid(v)
{} {}
bool isValid() const bool isValid() const { return valid ; }
{
return valid ;
}
virtual int getSizeOfType() const = 0; virtual int getSizeOfType() const = 0;
...@@ -73,10 +71,7 @@ public: ...@@ -73,10 +71,7 @@ public:
virtual AttributeMultiVectorGen* getDataVectorGen() const = 0; virtual AttributeMultiVectorGen* getDataVectorGen() const = 0;
protected: protected:
void setInvalid() void setInvalid() { valid = false ; }
{
valid = false ;
}
} ; } ;
/** /**
......
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