mirror of https://github.com/CGAL/cgal
Switch to make_zero()
This commit is contained in:
parent
41946b72d6
commit
c5f85b212d
|
|
@ -11,48 +11,6 @@ typedef CGAL::Interpolation_traits_2<K> Traits;
|
||||||
typedef K::Vector_3 Vector_3;
|
typedef K::Vector_3 Vector_3;
|
||||||
typedef K::Point_2 Point_2;
|
typedef K::Point_2 Point_2;
|
||||||
|
|
||||||
|
|
||||||
namespace boost {
|
|
||||||
|
|
||||||
template<class K>
|
|
||||||
class value_initialized<CGAL::Vector_3<K> >
|
|
||||||
{
|
|
||||||
private :
|
|
||||||
|
|
||||||
typedef CGAL::Vector_3<K> T;
|
|
||||||
T m_data;
|
|
||||||
|
|
||||||
public :
|
|
||||||
|
|
||||||
value_initialized()
|
|
||||||
:
|
|
||||||
m_data(0,0,0)
|
|
||||||
{ }
|
|
||||||
|
|
||||||
T const & data() const
|
|
||||||
{
|
|
||||||
return m_data;
|
|
||||||
}
|
|
||||||
|
|
||||||
T& data()
|
|
||||||
{
|
|
||||||
return m_data;
|
|
||||||
}
|
|
||||||
|
|
||||||
operator T const &() const
|
|
||||||
{
|
|
||||||
return m_data;
|
|
||||||
}
|
|
||||||
|
|
||||||
operator T&()
|
|
||||||
{
|
|
||||||
return m_data;
|
|
||||||
}
|
|
||||||
} ;
|
|
||||||
|
|
||||||
} // nammespace boost
|
|
||||||
|
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
Delaunay_triangulation T;
|
Delaunay_triangulation T;
|
||||||
|
|
@ -65,14 +23,14 @@ int main()
|
||||||
|
|
||||||
for (int y=0 ; y<255 ; y++){
|
for (int y=0 ; y<255 ; y++){
|
||||||
for (int x=0 ; x<255 ; x++){
|
for (int x=0 ; x<255 ; x++){
|
||||||
K::Point_2_2 p(x,y);
|
K::Point_2 p(x,y);
|
||||||
T.insert(p);
|
T.insert(p);
|
||||||
value_function.insert(std::make_pair(p, Vector_3(x,y,1)));
|
value_function.insert(std::make_pair(p, Vector_3(x,y,1)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//coordinate computation
|
//coordinate computation
|
||||||
K::Point_2_2 p(1.3, 0.34);
|
K::Point_2 p(1.3, 0.34);
|
||||||
std::vector<std::pair<Point_2, double> > coords;
|
std::vector<std::pair<Point_2, double> > coords;
|
||||||
|
|
||||||
double norm = CGAL::natural_neighbor_coordinates_2(T, p, std::back_inserter(coords)).second;
|
double norm = CGAL::natural_neighbor_coordinates_2(T, p, std::back_inserter(coords)).second;
|
||||||
|
|
|
||||||
|
|
@ -26,9 +26,9 @@
|
||||||
#include <CGAL/Interpolation/internal/helpers.h>
|
#include <CGAL/Interpolation/internal/helpers.h>
|
||||||
#include <CGAL/double.h>
|
#include <CGAL/double.h>
|
||||||
#include <CGAL/use.h>
|
#include <CGAL/use.h>
|
||||||
|
#include <CGAL/make_zero.h>
|
||||||
|
|
||||||
#include <boost/utility/result_of.hpp>
|
#include <boost/utility/result_of.hpp>
|
||||||
#include <boost/utility/value_init.hpp>
|
|
||||||
#include <iterator>
|
#include <iterator>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
@ -65,7 +65,6 @@ typename boost::result_of<
|
||||||
::type::first_type
|
::type::first_type
|
||||||
linear_interpolation(ForwardIterator first, ForwardIterator beyond,
|
linear_interpolation(ForwardIterator first, ForwardIterator beyond,
|
||||||
const typename std::iterator_traits<ForwardIterator>::value_type::second_type& norm,
|
const typename std::iterator_traits<ForwardIterator>::value_type::second_type& norm,
|
||||||
//const Norm& norm,
|
|
||||||
ValueFunctor value_function)
|
ValueFunctor value_function)
|
||||||
{
|
{
|
||||||
CGAL_precondition(norm > 0);
|
CGAL_precondition(norm > 0);
|
||||||
|
|
@ -74,13 +73,13 @@ linear_interpolation(ForwardIterator first, ForwardIterator beyond,
|
||||||
typedef typename boost::result_of<ValueFunctor(arg_type)>::type result_type;
|
typedef typename boost::result_of<ValueFunctor(arg_type)>::type result_type;
|
||||||
typedef typename result_type::first_type Value_type;
|
typedef typename result_type::first_type Value_type;
|
||||||
|
|
||||||
boost::value_initialized<Value_type> result;
|
Value_type result = make_zero<Value_type>();
|
||||||
result_type val;
|
result_type val;
|
||||||
for(; first!=beyond; ++first)
|
for(; first!=beyond; ++first)
|
||||||
{
|
{
|
||||||
val = value_function(first->first);
|
val = value_function(first->first);
|
||||||
CGAL_assertion(val.second);
|
CGAL_assertion(val.second);
|
||||||
get(result) += (first->second / norm) * val.first;
|
result += (first->second / norm) * val.first;
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -35,6 +35,7 @@
|
||||||
#include <CGAL/representation_tags.h>
|
#include <CGAL/representation_tags.h>
|
||||||
#include <CGAL/Dimension.h>
|
#include <CGAL/Dimension.h>
|
||||||
#include <CGAL/result_of.h>
|
#include <CGAL/result_of.h>
|
||||||
|
#include <CGAL/make_zero.h>
|
||||||
#include <CGAL/IO/io.h>
|
#include <CGAL/IO/io.h>
|
||||||
|
|
||||||
namespace CGAL {
|
namespace CGAL {
|
||||||
|
|
@ -389,6 +390,15 @@ operator>>(std::istream& is, Vector_2<R>& v)
|
||||||
return extract(is, v, typename R::Kernel_tag() );
|
return extract(is, v, typename R::Kernel_tag() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <class R>
|
||||||
|
struct Make_zero<Vector_2<R> >
|
||||||
|
{
|
||||||
|
Vector_2<R> operator()() const
|
||||||
|
{
|
||||||
|
return CGAL::NULL_VECTOR;
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
} //namespace CGAL
|
} //namespace CGAL
|
||||||
|
|
||||||
#endif // CGAL_VECTOR_2_H
|
#endif // CGAL_VECTOR_2_H
|
||||||
|
|
|
||||||
|
|
@ -35,6 +35,7 @@
|
||||||
#include <CGAL/Kernel/Return_base_tag.h>
|
#include <CGAL/Kernel/Return_base_tag.h>
|
||||||
#include <CGAL/Dimension.h>
|
#include <CGAL/Dimension.h>
|
||||||
#include <CGAL/result_of.h>
|
#include <CGAL/result_of.h>
|
||||||
|
#include <CGAL/make_zero.h>
|
||||||
#include <CGAL/IO/io.h>
|
#include <CGAL/IO/io.h>
|
||||||
|
|
||||||
namespace CGAL {
|
namespace CGAL {
|
||||||
|
|
@ -371,6 +372,16 @@ operator>>(std::istream& is, Vector_3<R>& v)
|
||||||
return extract(is, v, typename R::Kernel_tag() );
|
return extract(is, v, typename R::Kernel_tag() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template <class R>
|
||||||
|
struct Make_zero<Vector_3<R> >
|
||||||
|
{
|
||||||
|
Vector_3<R> operator()() const
|
||||||
|
{
|
||||||
|
return CGAL::NULL_VECTOR;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
} //namespace CGAL
|
} //namespace CGAL
|
||||||
|
|
||||||
#endif // CGAL_VECTOR_3_H
|
#endif // CGAL_VECTOR_3_H
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,48 @@
|
||||||
|
// Copyright (c) 2018
|
||||||
|
// Utrecht University (The Netherlands),
|
||||||
|
// ETH Zurich (Switzerland),
|
||||||
|
// INRIA Sophia-Antipolis (France),
|
||||||
|
// Max-Planck-Institute Saarbruecken (Germany),
|
||||||
|
// and Tel-Aviv University (Israel). All rights reserved.
|
||||||
|
//
|
||||||
|
// This file is part of CGAL (www.cgal.org); you can redistribute it and/or
|
||||||
|
// modify it under the terms of the GNU Lesser General Public License as
|
||||||
|
// published by the Free Software Foundation; either version 3 of the License,
|
||||||
|
// or (at your option) any later version.
|
||||||
|
//
|
||||||
|
// Licensees holding a valid commercial license may use this file in
|
||||||
|
// accordance with the commercial license agreement provided with the software.
|
||||||
|
//
|
||||||
|
// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
|
||||||
|
// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
//
|
||||||
|
// $URL$
|
||||||
|
// $Id$
|
||||||
|
// SPDX-License-Identifier: LGPL-3.0+
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// Author(s) : Andreas Fabri
|
||||||
|
|
||||||
|
#ifndef CGAL_MAKE_ZERO_H
|
||||||
|
#define CGAL_MAKE_ZERO_H
|
||||||
|
|
||||||
|
namespace CGAL {
|
||||||
|
|
||||||
|
template <class T>
|
||||||
|
struct Make_zero {
|
||||||
|
T operator()()const
|
||||||
|
{
|
||||||
|
return T();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template <class T>
|
||||||
|
T make_zero()
|
||||||
|
{
|
||||||
|
Make_zero<T> mz;
|
||||||
|
return mz();
|
||||||
|
}
|
||||||
|
|
||||||
|
} //namespace CGAL
|
||||||
|
|
||||||
|
#endif // CGAL_MAKE_ZERO_H
|
||||||
Loading…
Reference in New Issue