#include <CGAL/Simple_cartesian.h>
#include <CGAL/property_map.h>
#include <CGAL/value_type_traits.h>
#include <algorithm>
#include <vector>
#include <boost/tuple/tuple.hpp>
#include <boost/tuple/tuple_io.hpp>
typedef K::Point_3 Point_3;
typedef K::Vector_3 Vector_3;
typedef std::pair<Point_3, Vector_3> PointVectorPair;
typedef boost::tuple<int, Point_3, bool, Vector_3> IndexedPointWithOrientableNormalTuple;
template <typename T, typename PointPMap>
struct MyLess {
PointPMap pmap;
MyLess(const PointPMap& p)
: pmap(p)
{}
bool operator()(const T& t0, const T& t1) const
{
return get(pmap, t0) < get(pmap, t1);
}
};
template <typename Iterator, typename PointPMap >
{
MyLess<typename std::iterator_traits<Iterator>::value_type,PointPMap> less(pmap);
std::sort(beg,end,less);
}
template <typename Iterator>
{
process_point_set(beg,end,
CGAL::make_identity_property_map(
);
}
template <typename Iterator, typename OrientationPMap, typename NormalPMap >
void orient_normals(
Iterator beg,
Iterator end, OrientationPMap orient_pmap, NormalPMap normal_pmap)
{
for(;beg!= end;++beg){
const Vector_3& v = get(normal_pmap, *beg);
if(v.x() < 0){
put(normal_pmap,*beg, -v);
}
}
}
int main()
{
{
std::vector<Point_3> points;
process_point_set(points.begin(), points.end());
}
{
std::vector<PointVectorPair> points;
for(int i = 0; i < 10; i++){
points.push_back(std::make_pair(Point_3(9-i,0,0), Vector_3(i,0,0)));
}
process_point_set(points.begin(),
points.end(),
for(int i = 0; i < 10; i++){
std::cout << points[i].first << "\t" << points[i].second << std::endl;
}
}
{
std::vector<IndexedPointWithOrientableNormalTuple> points;
for(int i = 0; i < 10; i++){
double x = (i%2)?i:-i;
points.push_back(boost::make_tuple(i,Point_3(9-i,0,0), false, Vector_3(x,0,0)));
}
process_point_set(points.begin(),
points.end(),
std::cout << boost::tuples::set_open('[') << boost::tuples::set_close(']') << boost::tuples::set_delimiter(',');
for(int i = 0; i < 10; i++){
std::cout << points[i] << std::endl;
}
orient_normals(points.begin(),
points.end(),
CGAL::make_nth_of_tuple_property_map<2>(IndexedPointWithOrientableNormalTuple()),
CGAL::make_nth_of_tuple_property_map<3>(IndexedPointWithOrientableNormalTuple()));
std::cout << "\nAfter orient_normals\n";
for(int i = 0; i < 10; i++){
std::cout << points[i] << std::endl;
}
}
return 0;
}