Altered PolyMesh template to work with Eigen's Vectors

This commit is contained in:
Christian Mattes
2018-04-12 11:11:55 +02:00
parent 8396dceab1
commit 5e7493b3a9
2 changed files with 19 additions and 17 deletions

View File

@@ -144,13 +144,13 @@ PolyMeshT<Kernel>::calc_face_normal_impl(FaceHandle _fh, PointIs3DTag) const
n[2] += static_cast<typename Normal::value_type>(a[0] * b[1]); n[2] += static_cast<typename Normal::value_type>(a[0] * b[1]);
} }
const typename vector_traits<Normal>::value_type norm = n.length(); const typename vector_traits<Normal>::value_type length = norm(n);
// The expression ((n *= (1.0/norm)),n) is used because the OpenSG // The expression ((n *= (1.0/norm)),n) is used because the OpenSG
// vector class does not return self after component-wise // vector class does not return self after component-wise
// self-multiplication with a scalar!!! // self-multiplication with a scalar!!!
return (norm != typename vector_traits<Normal>::value_type(0)) return (length != typename vector_traits<Normal>::value_type(0))
? ((n *= (typename vector_traits<Normal>::value_type(1)/norm)), n) ? ((n *= (typename vector_traits<Normal>::value_type(1)/length)), n)
: Normal(0, 0, 0); : Normal(0, 0, 0);
} }
@@ -194,20 +194,22 @@ calc_face_normal_impl(const Point& _p0,
Normal p1p2(vector_cast<Normal>(_p2)); p1p2 -= vector_cast<Normal>(_p1); Normal p1p2(vector_cast<Normal>(_p2)); p1p2 -= vector_cast<Normal>(_p1);
Normal n = cross(p1p2, p1p0); Normal n = cross(p1p2, p1p0);
typename vector_traits<Normal>::value_type norm = n.length(); typename vector_traits<Normal>::value_type length = norm(n);
// The expression ((n *= (1.0/norm)),n) is used because the OpenSG // The expression ((n *= (1.0/norm)),n) is used because the OpenSG
// vector class does not return self after component-wise // vector class does not return self after component-wise
// self-multiplication with a scalar!!! // self-multiplication with a scalar!!!
return (norm != typename vector_traits<Normal>::value_type(0)) ? ((n *= (typename vector_traits<Normal>::value_type(1)/norm)),n) : Normal(0,0,0); return (length != typename vector_traits<Normal>::value_type(0))
? ((n *= (typename vector_traits<Normal>::value_type(1)/length)),n)
: Normal(0,0,0);
#else #else
Point p1p0 = _p0; p1p0 -= _p1; Point p1p0 = _p0; p1p0 -= _p1;
Point p1p2 = _p2; p1p2 -= _p1; Point p1p2 = _p2; p1p2 -= _p1;
Normal n = vector_cast<Normal>(cross(p1p2, p1p0)); Normal n = vector_cast<Normal>(cross(p1p2, p1p0));
typename vector_traits<Normal>::value_type norm = n.length(); typename vector_traits<Normal>::value_type length = norm(n);
return (norm != 0.0) ? n *= (1.0/norm) : Normal(0,0,0); return (length != 0.0) ? n *= (1.0/length) : Normal(0,0,0);
#endif #endif
} }
@@ -331,7 +333,7 @@ calc_halfedge_normal(HalfedgeHandle _heh, const double _feature_angle) const
for(unsigned int i=0; i<fhs.size(); ++i) for(unsigned int i=0; i<fhs.size(); ++i)
n += Kernel::normal(fhs[i]); n += Kernel::normal(fhs[i]);
return n.normalize(); return normalize(n);
} }
} }
@@ -378,8 +380,8 @@ calc_vertex_normal(VertexHandle _vh) const
Normal n; Normal n;
calc_vertex_normal_fast(_vh,n); calc_vertex_normal_fast(_vh,n);
Scalar norm = n.length(); Scalar length = norm(n);
if (norm != 0.0) n *= (Scalar(1.0)/norm); if (length != 0.0) n *= (Scalar(1.0)/length);
return n; return n;
} }
@@ -389,7 +391,7 @@ template <class Kernel>
void PolyMeshT<Kernel>:: void PolyMeshT<Kernel>::
calc_vertex_normal_fast(VertexHandle _vh, Normal& _n) const calc_vertex_normal_fast(VertexHandle _vh, Normal& _n) const
{ {
_n.vectorize(0.0); vectorize(_n, 0.0);
for (ConstVertexFaceIter vf_it = this->cvf_iter(_vh); vf_it.is_valid(); ++vf_it) for (ConstVertexFaceIter vf_it = this->cvf_iter(_vh); vf_it.is_valid(); ++vf_it)
_n += this->normal(*vf_it); _n += this->normal(*vf_it);
} }

View File

@@ -406,7 +406,7 @@ public:
{ {
Normal edge_vec; Normal edge_vec;
calc_edge_vector(_heh, edge_vec); calc_edge_vector(_heh, edge_vec);
return edge_vec.sqrnorm(); return sqrnorm(edge_vec);
} }
/** Calculates the midpoint of the halfedge _heh, defined by the positions of /** Calculates the midpoint of the halfedge _heh, defined by the positions of
@@ -444,7 +444,7 @@ public:
{ {
Normal v0, v1; Normal v0, v1;
calc_sector_vectors(_in_heh, v0, v1); calc_sector_vectors(_in_heh, v0, v1);
Scalar denom = v0.norm()*v1.norm(); Scalar denom = length(v0)*length(v1);
if ( denom == Scalar(0)) if ( denom == Scalar(0))
{ {
return 0; return 0;
@@ -470,7 +470,7 @@ public:
Normal in_vec, out_vec; Normal in_vec, out_vec;
calc_edge_vector(_in_heh, in_vec); calc_edge_vector(_in_heh, in_vec);
calc_edge_vector(next_halfedge_handle(_in_heh), out_vec); calc_edge_vector(next_halfedge_handle(_in_heh), out_vec);
Scalar denom = in_vec.norm()*out_vec.norm(); Scalar denom = length(in_vec)*length(out_vec);
if (is_zero(denom)) if (is_zero(denom))
{ {
_cos_a = 1; _cos_a = 1;
@@ -479,7 +479,7 @@ public:
else else
{ {
_cos_a = dot(in_vec, out_vec)/denom; _cos_a = dot(in_vec, out_vec)/denom;
_sin_a = cross(in_vec, out_vec).norm()/denom; _sin_a = length(cross(in_vec, out_vec))/denom;
} }
} }
*/ */
@@ -499,7 +499,7 @@ public:
{ {
Normal sector_normal; Normal sector_normal;
calc_sector_normal(_in_heh, sector_normal); calc_sector_normal(_in_heh, sector_normal);
return sector_normal.norm()/2; return length(sector_normal)/2;
} }
/** calculates the dihedral angle on the halfedge _heh /** calculates the dihedral angle on the halfedge _heh
@@ -539,7 +539,7 @@ public:
calc_sector_normal(_heh, n0); calc_sector_normal(_heh, n0);
calc_sector_normal(this->opposite_halfedge_handle(_heh), n1); calc_sector_normal(this->opposite_halfedge_handle(_heh), n1);
calc_edge_vector(_heh, he); calc_edge_vector(_heh, he);
Scalar denom = n0.norm()*n1.norm(); Scalar denom = length(n0)*length(n1);
if (denom == Scalar(0)) if (denom == Scalar(0))
{ {
return 0; return 0;