Merge branch 'feature-free-functions' into 'master'
Feature free functions Closes #52 See merge request OpenMesh/OpenMesh!168
This commit is contained in:
@@ -718,6 +718,47 @@ noexcept(noexcept(_v1.swap(_v2))) {
|
||||
_v1.swap(_v2);
|
||||
}
|
||||
|
||||
/// \relates OpenMesh::VectorT
|
||||
/// non-member norm
|
||||
template<typename Scalar, int DIM>
|
||||
Scalar norm(const VectorT<Scalar, DIM>& _v) {
|
||||
return _v.norm();
|
||||
}
|
||||
|
||||
/// \relates OpenMesh::VectorT
|
||||
/// non-member sqrnorm
|
||||
template<typename Scalar, int DIM>
|
||||
Scalar sqrnorm(const VectorT<Scalar, DIM>& _v) {
|
||||
return _v.sqrnorm();
|
||||
}
|
||||
/// \relates OpenMesh::VectorT
|
||||
/// non-member vectorize
|
||||
template<typename Scalar, int DIM, typename OtherScalar>
|
||||
VectorT<Scalar, DIM>& vectorize(VectorT<Scalar, DIM>& _v, OtherScalar const& _val) {
|
||||
return _v.vectorize(_val);
|
||||
}
|
||||
|
||||
/// \relates OpenMesh::VectorT
|
||||
/// non-member normalize
|
||||
template<typename Scalar, int DIM>
|
||||
VectorT<Scalar, DIM>& normalize(VectorT<Scalar, DIM>& _v) {
|
||||
return _v.normalize();
|
||||
}
|
||||
|
||||
/// \relates OpenMesh::VectorT
|
||||
/// non-member maximize
|
||||
template<typename Scalar, int DIM>
|
||||
VectorT<Scalar, DIM>& maximize(VectorT<Scalar, DIM>& _v1, VectorT<Scalar, DIM>& _v2) {
|
||||
return _v1.maximize(_v2);
|
||||
}
|
||||
|
||||
/// \relates OpenMesh::VectorT
|
||||
/// non-member minimize
|
||||
template<typename Scalar, int DIM>
|
||||
VectorT<Scalar, DIM>& minimize(VectorT<Scalar, DIM>& _v1, VectorT<Scalar, DIM>& _v2) {
|
||||
return _v1.minimize(_v2);
|
||||
}
|
||||
|
||||
//== TYPEDEFS =================================================================
|
||||
|
||||
/** 1-byte signed vector */
|
||||
|
||||
@@ -274,6 +274,52 @@ cross(const VectorT<Scalar,N>& _v1, const VectorT<Scalar,N>& _v2) {
|
||||
}
|
||||
|
||||
|
||||
/// \relates OpenMesh::VectorT
|
||||
/// non-member norm
|
||||
template<typename Scalar, int DIM>
|
||||
Scalar norm(const VectorT<Scalar, DIM>& _v) {
|
||||
return _v.norm();
|
||||
}
|
||||
|
||||
|
||||
/// \relates OpenMesh::VectorT
|
||||
/// non-member sqrnorm
|
||||
template<typename Scalar, int DIM>
|
||||
Scalar sqrnorm(const VectorT<Scalar, DIM>& _v) {
|
||||
return _v.sqrnorm();
|
||||
}
|
||||
|
||||
|
||||
/// \relates OpenMesh::VectorT
|
||||
/// non-member vectorize
|
||||
template<typename Scalar, int DIM, typename OtherScalar>
|
||||
VectorT<Scalar, DIM>& vectorize(VectorT<Scalar, DIM>& _v, OtherScalar const& _val) {
|
||||
return _v.vectorize(_val);
|
||||
}
|
||||
|
||||
|
||||
/// \relates OpenMesh::VectorT
|
||||
/// non-member normalize
|
||||
template<typename Scalar, int DIM>
|
||||
VectorT<Scalar, DIM>& normalize(VectorT<Scalar, DIM>& _v) {
|
||||
return _v.normalize();
|
||||
}
|
||||
|
||||
|
||||
/// \relates OpenMesh::VectorT
|
||||
/// non-member maximize
|
||||
template<typename Scalar, int DIM>
|
||||
VectorT<Scalar, DIM>& maximize(VectorT<Scalar, DIM>& _v1, VectorT<Scalar, DIM>& _v2) {
|
||||
return _v1.maximize(_v2);
|
||||
}
|
||||
|
||||
|
||||
/// \relates OpenMesh::VectorT
|
||||
/// non-member minimize
|
||||
template<typename Scalar, int DIM>
|
||||
VectorT<Scalar, DIM>& minimize(VectorT<Scalar, DIM>& _v1, VectorT<Scalar, DIM>& _v2) {
|
||||
return _v1.minimize(_v2);
|
||||
}
|
||||
|
||||
|
||||
//== TYPEDEFS =================================================================
|
||||
|
||||
@@ -139,18 +139,18 @@ PolyMeshT<Kernel>::calc_face_normal_impl(FaceHandle _fh, PointIs3DTag) const
|
||||
|
||||
// Due to traits, the value types of normals and points can be different.
|
||||
// Therefore we cast them here.
|
||||
n[0] += static_cast<typename Normal::value_type>(a[1] * b[2]);
|
||||
n[1] += static_cast<typename Normal::value_type>(a[2] * b[0]);
|
||||
n[2] += static_cast<typename Normal::value_type>(a[0] * b[1]);
|
||||
n[0] += static_cast<typename vector_traits<Normal>::value_type>(a[1] * b[2]);
|
||||
n[1] += static_cast<typename vector_traits<Normal>::value_type>(a[2] * b[0]);
|
||||
n[2] += static_cast<typename vector_traits<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
|
||||
// vector class does not return self after component-wise
|
||||
// self-multiplication with a scalar!!!
|
||||
return (norm != typename vector_traits<Normal>::value_type(0))
|
||||
? ((n *= (typename vector_traits<Normal>::value_type(1)/norm)), n)
|
||||
return (length != typename vector_traits<Normal>::value_type(0))
|
||||
? ((n *= (typename vector_traits<Normal>::value_type(1)/length)), n)
|
||||
: 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 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
|
||||
// vector class does not return self after component-wise
|
||||
// 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
|
||||
Point p1p0 = _p0; p1p0 -= _p1;
|
||||
Point p1p2 = _p2; p1p2 -= _p1;
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
@@ -226,7 +228,7 @@ PolyMeshT<Kernel>::
|
||||
calc_face_centroid(FaceHandle _fh) const
|
||||
{
|
||||
Point _pt;
|
||||
_pt.vectorize(0);
|
||||
vectorize(_pt, 0);
|
||||
Scalar valence = 0.0;
|
||||
for (ConstFaceVertexIter cfv_it = this->cfv_iter(_fh); cfv_it.is_valid(); ++cfv_it, valence += 1.0)
|
||||
{
|
||||
@@ -331,7 +333,7 @@ calc_halfedge_normal(HalfedgeHandle _heh, const double _feature_angle) const
|
||||
for(unsigned int i=0; i<fhs.size(); ++i)
|
||||
n += Kernel::normal(fhs[i]);
|
||||
|
||||
return n.normalize();
|
||||
return normalize(n);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -378,8 +380,8 @@ calc_vertex_normal(VertexHandle _vh) const
|
||||
Normal n;
|
||||
calc_vertex_normal_fast(_vh,n);
|
||||
|
||||
Scalar norm = n.length();
|
||||
if (norm != 0.0) n *= (Scalar(1.0)/norm);
|
||||
Scalar length = norm(n);
|
||||
if (length != 0.0) n *= (Scalar(1.0)/length);
|
||||
|
||||
return n;
|
||||
}
|
||||
@@ -389,7 +391,7 @@ template <class Kernel>
|
||||
void PolyMeshT<Kernel>::
|
||||
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)
|
||||
_n += this->normal(*vf_it);
|
||||
}
|
||||
@@ -399,7 +401,7 @@ template <class Kernel>
|
||||
void PolyMeshT<Kernel>::
|
||||
calc_vertex_normal_correct(VertexHandle _vh, Normal& _n) const
|
||||
{
|
||||
_n.vectorize(0.0);
|
||||
vectorize(_n, 0.0);
|
||||
ConstVertexIHalfedgeIter cvih_it = this->cvih_iter(_vh);
|
||||
if (! cvih_it.is_valid() )
|
||||
{//don't crash on isolated vertices
|
||||
|
||||
@@ -406,7 +406,7 @@ public:
|
||||
{
|
||||
Normal 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
|
||||
@@ -444,7 +444,7 @@ public:
|
||||
{
|
||||
Normal v0, v1;
|
||||
calc_sector_vectors(_in_heh, v0, v1);
|
||||
Scalar denom = v0.norm()*v1.norm();
|
||||
Scalar denom = norm(v0)*norm(v1);
|
||||
if ( denom == Scalar(0))
|
||||
{
|
||||
return 0;
|
||||
@@ -470,7 +470,7 @@ public:
|
||||
Normal in_vec, out_vec;
|
||||
calc_edge_vector(_in_heh, in_vec);
|
||||
calc_edge_vector(next_halfedge_handle(_in_heh), out_vec);
|
||||
Scalar denom = in_vec.norm()*out_vec.norm();
|
||||
Scalar denom = norm(in_vec)*norm(out_vec);
|
||||
if (is_zero(denom))
|
||||
{
|
||||
_cos_a = 1;
|
||||
@@ -479,7 +479,7 @@ public:
|
||||
else
|
||||
{
|
||||
_cos_a = dot(in_vec, out_vec)/denom;
|
||||
_sin_a = cross(in_vec, out_vec).norm()/denom;
|
||||
_sin_a = norm(cross(in_vec, out_vec))/denom;
|
||||
}
|
||||
}
|
||||
*/
|
||||
@@ -499,7 +499,7 @@ public:
|
||||
{
|
||||
Normal sector_normal;
|
||||
calc_sector_normal(_in_heh, sector_normal);
|
||||
return sector_normal.norm()/2;
|
||||
return norm(sector_normal)/2;
|
||||
}
|
||||
|
||||
/** calculates the dihedral angle on the halfedge _heh
|
||||
@@ -539,7 +539,7 @@ public:
|
||||
calc_sector_normal(_heh, n0);
|
||||
calc_sector_normal(this->opposite_halfedge_handle(_heh), n1);
|
||||
calc_edge_vector(_heh, he);
|
||||
Scalar denom = n0.norm()*n1.norm();
|
||||
Scalar denom = norm(n0)*norm(n1);
|
||||
if (denom == Scalar(0))
|
||||
{
|
||||
return 0;
|
||||
|
||||
@@ -359,9 +359,9 @@ public:
|
||||
VertexHandle p2 = this->to_vertex_handle(he2);
|
||||
|
||||
// Calculate midpoint coordinates
|
||||
const Point new0 = (this->point(p0) + this->point(p2)) * static_cast< typename Point::value_type >(0.5);
|
||||
const Point new1 = (this->point(p0) + this->point(p1)) * static_cast< typename Point::value_type >(0.5);
|
||||
const Point new2 = (this->point(p1) + this->point(p2)) * static_cast< typename Point::value_type >(0.5);
|
||||
const Point new0 = (this->point(p0) + this->point(p2)) * static_cast<typename vector_traits<Point>::value_type >(0.5);
|
||||
const Point new1 = (this->point(p0) + this->point(p1)) * static_cast<typename vector_traits<Point>::value_type >(0.5);
|
||||
const Point new2 = (this->point(p1) + this->point(p2)) * static_cast<typename vector_traits<Point>::value_type >(0.5);
|
||||
|
||||
// Add vertices at midpoint coordinates
|
||||
VertexHandle v0 = this->add_vertex(new0);
|
||||
|
||||
@@ -95,7 +95,6 @@ inline void vector_cast( const src_t & /*_src*/, dst_t & /*_dst*/, GenProg::Int2
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
template <typename src_t, typename dst_t, int n>
|
||||
inline void vector_copy( const src_t &_src, dst_t &_dst, GenProg::Int2Type<n> )
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user