Merge branch 'Snap_rounding_2-kd_tree_replacement-wkhan-old' into Snap_rounding_2-kd_tree_replacement-wkhan

Conflicts:
	Installation/changes.html
This commit is contained in:
Eric Berberich 2014-04-09 10:11:35 +02:00
commit dee9fc8235
21 changed files with 589 additions and 1725 deletions

View File

@ -112,6 +112,19 @@ and <code>src/</code> directories).
<h2 id="release4.5">Release 4.5 </h2> <h2 id="release4.5">Release 4.5 </h2>
<div> <div>
<p>Release date: September 2014 </p> <p>Release date: September 2014 </p>
<h3>Snap_rounding_2</h3>
<ul>
<li> Replaced use of private <code>kd_tree</code> with CGAL's official <code>Kd_tree</code> from <code>Spatial_searching</code> package;
results in a small performance gain. Removed the private <code>kd_tree</code> package.
</li>
</ul>
<h3>Spatial_searching</h3>
<ul>
<li> Added methods <code>reserve(size_t size)</code> and <code>size_t capacity()</code> to class <code>Kd_tree</code> to allocate
memory to store <code>size</code> points and to report that number (STL compliance).
</li>
</ul>
<h3>Vanilla package (fake package, to be removed by the RM)</h3> <h3>Vanilla package (fake package, to be removed by the RM)</h3>
<ul> <ul>
<li> Blablabla <li> Blablabla
@ -121,7 +134,6 @@ and <code>src/</code> directories).
</ul> </ul>
</div> </div>
<h2 id="release4.4">Release 4.4 </h2> <h2 id="release4.4">Release 4.4 </h2>
<div> <div>
<p>Release date: April 2014 </p> <p>Release date: April 2014 </p>

View File

@ -41,6 +41,11 @@ Models the concept `SRTraits_2::IsoRectangle_2`
*/ */
typedef unspecified_type Iso_rectangle_2; typedef unspecified_type Iso_rectangle_2;
/*!
Models the concept `SearchTraits::Cartesian_const_iterator_2`
*/
typedef unspecified_type Cartesian_const_iterator_2;
/// @} /// @}
/// \name Functor Types /// \name Functor Types
@ -93,6 +98,21 @@ Models the concept `SRTraits_2::MinkowskiSumWithPixel_2`.
*/ */
typedef unspecified_type Minkowski_sum_with_pixel_2; typedef unspecified_type Minkowski_sum_with_pixel_2;
/*!
Models the concept `ArrTraits::ConstructMinVertex_2`.
*/
typedef unspecified_type Construct_min_vertex_2;
/*!
Models the concept `ArrTraits::ConstructMaxVertex_2`.
*/
typedef unspecified_type Construct_max_vertex_2;
/*!
Models the concept `SearchTraits::Construct_cartesian_const_iterator_2`.
*/
typedef unspecified_type Construct_cartesian_const_iterator_2;
/// @} /// @}
/// \name Accessing Functor Objects /// \name Accessing Functor Objects

View File

@ -0,0 +1,5 @@
4
0 0 10 10
0 10 10 0
3 0 3 10
7 0 7 10

View File

@ -0,0 +1,139 @@
// Copyright 2009,2014 Max-Planck-Institute Saarbruecken (Germany).
// 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
// 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$
//
//
// author(s) : Waqar Khan <wkhan@mpi-inf.mpg.de>
/* Usage
*
* This example converts arbitrary-precision arrangment into fixed-precision using Snap Rounding and by using INPUT DATA FROM A USER SPECIFIED FILE.
* <Argument 1> (Mandatory) path to the input file containing the arrangment information.
* <Argument 2> (Optional) path to the output file where the results of snap rounding will be stored.
* Not providing this argument will print the result on standard output.
*
* Input file format
* Line # 1: Number of line-segments present in the file.
* Line # 2 to N+1: segment_start_point_x <space> segment_start_point_y <space> segment_end_point_x <space> segment_end_point_y
*
* Each line should contain information about just one segment.
*/
#include <CGAL/Cartesian.h>
#include <CGAL/Quotient.h>
#include <CGAL/MP_Float.h>
#include <CGAL/Snap_rounding_traits_2.h>
#include <CGAL/Snap_rounding_2.h>
#include <fstream>
typedef CGAL::Quotient<CGAL::MP_Float> Number_type;
typedef CGAL::Cartesian<Number_type> Kernel;
typedef CGAL::Snap_rounding_traits_2<Kernel> Traits;
typedef Kernel::Segment_2 Segment_2;
typedef Kernel::Point_2 Point_2;
typedef std::list<Segment_2> Segment_list_2;
typedef std::list<Point_2> Polyline_2;
typedef std::list<Polyline_2> Polyline_list_2;
int main(int argc, char* argv[])
{
//if(argc > 3 || argc < 2)
if(argc > 3)
{
std::cout<< "Incorrect input. <Arg 1> path to the INPUT file. <Arg 2> (optional) path to the OUTPUT file. No arguments to choose the default data file" << std::endl;
return -1;
}
Segment_list_2 seg_list;
Polyline_list_2 output_list;
std::ifstream my_read_file;
std::ofstream my_write_file;
if(argc > 1)
my_read_file.open(argv[1]);
else
my_read_file.open("data/snap_rounding_data");
if(!my_read_file.is_open())
{
std::cout<< "Error opening the input file"<< std::endl;
return -1;
}
if(argc==3)
{
my_write_file.open(argv[2]);
if(!my_read_file.is_open())
{
std::cout<< "Error opening the output file"<< std::endl;
return -1;
}
}
unsigned int number_of_lines = 0;
my_read_file >> number_of_lines;
for(unsigned int i=0; i<number_of_lines; i++)
{
double point_start_x, point_start_y, point_end_x, point_end_y;
my_read_file >> point_start_x;
my_read_file >> point_start_y;
my_read_file >> point_end_x;
my_read_file >> point_end_y;
seg_list.push_back(Segment_2(Point_2(point_start_x, point_start_y), Point_2(point_end_x, point_end_y)));
}
// Generate an iterated snap-rounding representation, where the centers of
// the hot pixels bear their original coordinates, using 1 kd trees:
CGAL::snap_rounding_2<Traits,Segment_list_2::const_iterator,Polyline_list_2>
(seg_list.begin(), seg_list.end(), output_list, 1.0, true, false, 1);
int counter = 0;
Polyline_list_2::const_iterator iter1;
if(argc == 3) //output to the file
{
for (iter1 = output_list.begin(); iter1 != output_list.end(); ++iter1)
{
my_write_file << "Polyline number " << ++counter << ":\n";
Polyline_2::const_iterator iter2;
for (iter2 = iter1->begin(); iter2 != iter1->end(); ++iter2)
my_write_file << " (" << iter2->x() << ":" << iter2->y() << ")\n";
}
my_write_file.close();
}
else //output to std output
{
for (iter1 = output_list.begin(); iter1 != output_list.end(); ++iter1)
{
std::cout << "Polyline number " << ++counter << ":\n";
Polyline_2::const_iterator iter2;
for (iter2 = iter1->begin(); iter2 != iter1->end(); ++iter2)
std::cout << " (" << iter2->x() << ":" << iter2->y() << ")\n";
}
}
my_read_file.close();
return(0);
}

197
Snap_rounding_2/include/CGAL/Snap_rounding_kd_2.h Normal file → Executable file
View File

@ -1,4 +1,4 @@
// Copyright (c) 2001 Tel-Aviv University (Israel). // Copyright (c) 2001, 2009, 2014 Tel-Aviv University (Israel), Max-Planck-Institute Saarbruecken (Germany).
// All rights reserved. // All rights reserved.
// //
// This file is part of CGAL (www.cgal.org). // This file is part of CGAL (www.cgal.org).
@ -16,13 +16,14 @@
// $Id$ // $Id$
// //
// //
// author(s) : Eli Packer <elip@post.tau.ac.il> // author(s) : Eli Packer <elip@post.tau.ac.il>,
// Waqar Khan <wkhan@mpi-inf.mpg.de>
#ifndef CGAL_SNAP_ROUNDING_KD_2_H #ifndef CGAL_SNAP_ROUNDING_KD_2_H
#define CGAL_SNAP_ROUNDING_KD_2_H #define CGAL_SNAP_ROUNDING_KD_2_H
#include <list> #include <list>
#include <CGAL/basic.h> #include <CGAL/basic.h>
#include <CGAL/kdtree_d.h>
#include <CGAL/predicates_on_points_2.h> #include <CGAL/predicates_on_points_2.h>
#include <iostream> #include <iostream>
#include <CGAL/predicates_on_points_2.h> #include <CGAL/predicates_on_points_2.h>
@ -31,23 +32,81 @@
#include <boost/type_traits/is_pointer.hpp> #include <boost/type_traits/is_pointer.hpp>
#include <CGAL/Kd_tree.h>
#include <CGAL/Search_traits_2.h>
#include <CGAL/Fuzzy_iso_box.h>
namespace CGAL { namespace CGAL {
namespace internal {
//////////////////////
//////////////////////
//Point_with_hot_pixel_history
//////////////////////
template<class Traits, class SAVED_OBJECT> template<class Traits, class SAVED_OBJECT>
class My_point : public Traits::Point_2 { class Point_with_hot_pixel_history : public Traits::Point_2 {
private: private:
typedef typename Traits::Point_2 Base;
typedef typename Traits::Point_2 Point_2; typedef typename Traits::Point_2 Point_2;
typedef typename Traits::FT NT; typedef typename Traits::FT NT;
public: public:
Point_2 orig; Point_2 orig;
SAVED_OBJECT object; SAVED_OBJECT object;
My_point(const Point_2& p, const Point_2& inp_orig, SAVED_OBJECT obj) :
Point_2(p), orig(inp_orig), object(obj) {} Point_with_hot_pixel_history(const Base& p, const Point_2& inp_orig, SAVED_OBJECT obj) : Base(p), orig(inp_orig), object(obj) {}
My_point(const Point_2& p) : Point_2(p), orig(Point_2(0, 0)) {}
My_point() : Point_2(),orig() {} Point_with_hot_pixel_history(const Base& p) : Base(p), orig(Point_2(0, 0)) {}
My_point(NT x, NT y) : Point_2(x, y), orig(Point_2(0, 0)) {}
}; Point_with_hot_pixel_history() : Base(), orig() {}
Point_with_hot_pixel_history(NT x, NT y) : Base(x, y), orig(Point_2(0, 0)) {}
}; // Point_with_hot_pixel_history
//////////////////////
//////////////////////
//Search_traits_kd_tree_2
//
//(Search traits modified to be used by the Spacial Searching kd_trees for Snap rounding)
//////////////////////
template < class Traits_, class Point_ = typename Traits_::Point_2 >
class Search_traits_kd_tree_2 {
public:
typedef Traits_ Traits;
typedef Point_ Point_d;
typedef typename Traits::Iso_rectangle_2 Iso_box_d;
typedef typename Traits::Cartesian_const_iterator_2 Cartesian_const_iterator_d;
typedef typename Traits::Construct_cartesian_const_iterator_2 Construct_cartesian_const_iterator_d;
typedef typename Traits::Construct_min_vertex_2 Construct_min_vertex_d;
typedef typename Traits::Construct_max_vertex_2 Construct_max_vertex_d;
typedef typename Traits::Construct_iso_rectangle_2 Construct_iso_box_d;
typedef typename Traits::FT FT;
Construct_cartesian_const_iterator_d construct_cartesian_const_iterator_d_object() const
{
return Construct_cartesian_const_iterator_d();
}
}; // Search_traits_kd_tree_2
} // namespace internal
/////////////////////
/////////////////////
//Multiple_kd_tree
/////////////////////
template<class Traits_, class SAVED_OBJECT> template<class Traits_, class SAVED_OBJECT>
class Multiple_kd_tree { class Multiple_kd_tree {
@ -62,11 +121,14 @@ private:
typedef typename Traits::Direction_2 Direction_2; typedef typename Traits::Direction_2 Direction_2;
typedef typename Traits::Line_2 Line_2; typedef typename Traits::Line_2 Line_2;
typedef typename Traits::Aff_transformation_2 Transformation_2; typedef typename Traits::Aff_transformation_2 Transformation_2;
typedef My_point<Traits, SAVED_OBJECT> My_point_saved;
typedef CGAL::Kdtree_interface_2d<My_point_saved> Kd_interface; typedef CGAL::internal::Point_with_hot_pixel_history<Traits, SAVED_OBJECT> Point_with_hot_pixel_history_saved;
typedef CGAL::Kdtree_d<Kd_interface> Kd_tree; typedef CGAL::internal::Search_traits_kd_tree_2<Traits, Point_with_hot_pixel_history_saved>
typedef typename Kd_tree::Box Box; Search_traits;
typedef std::list<My_point_saved> Points_List; typedef CGAL::Kd_tree<Search_traits> Kd_tree;
typedef CGAL::Fuzzy_iso_box<Search_traits> Box;
typedef std::list<Point_with_hot_pixel_history_saved> Points_List;
typedef std::pair<Direction_2, NT> Direction_nt_pair; typedef std::pair<Direction_2, NT> Direction_nt_pair;
typedef std::pair<Kd_tree *,Direction_nt_pair> Kd_triple; typedef std::pair<Kd_tree *,Direction_nt_pair> Kd_triple;
typedef std::pair<Kd_tree *, Direction_nt_pair> Kd_direction_nt_pair; typedef std::pair<Kd_tree *, Direction_nt_pair> Kd_direction_nt_pair;
@ -76,8 +138,8 @@ private:
typedef std::list<Point_saved_pair> Point_saved_pair_list; typedef std::list<Point_saved_pair> Point_saved_pair_list;
typedef typename Point_saved_pair_list::iterator Point_saved_pair_iter; typedef typename Point_saved_pair_list::iterator Point_saved_pair_iter;
typedef typename std::list<My_point_saved> My_point_saved_list; typedef typename std::list<Point_with_hot_pixel_history_saved> Point_with_hot_pixel_history_saved_list;
typedef typename My_point_saved_list::iterator My_point_saved_iter; typedef typename Point_with_hot_pixel_history_saved_list::iterator Point_with_hot_pixel_history_saved_iter;
typedef std::list<Point_2> Point_list; typedef std::list<Point_2> Point_list;
typedef typename Point_list::iterator Point_iter; typedef typename Point_list::iterator Point_iter;
@ -88,11 +150,14 @@ private:
typedef std::list<Direction_2> Direction_list; typedef std::list<Direction_2> Direction_list;
typedef typename Direction_list::const_iterator Direction_const_iter; typedef typename Direction_list::const_iterator Direction_const_iter;
private: private:
Traits m_gt; Traits m_gt;
const double pi, half_pi; const double pi, half_pi;
int number_of_trees; int number_of_trees;
Kd_triple_list kd_trees_list; Kd_triple_list kd_trees_list;
Point_saved_pair_list input_points_list; Point_saved_pair_list input_points_list;
std::map<int, NT> angle_to_sines_appr; // was const int std::map<int, NT> angle_to_sines_appr; // was const int
@ -115,34 +180,37 @@ private:
/*! */ /*! */
Kd_triple create_kd_tree(NT angle) Kd_triple create_kd_tree(NT angle)
{ {
Points_List l;
Kd_tree *tree = new Kd_tree(2);
for (Point_saved_pair_iter iter = input_points_list.begin(); Kd_tree *tree = new Kd_tree();
iter != input_points_list.end(); ++iter)
tree->reserve(input_points_list.size());
for (Point_saved_pair_iter iter = input_points_list.begin(); iter != input_points_list.end(); ++iter)
{ {
Point_2 p(iter->first); Point_2 p(iter->first);
rotate(p,angle); rotate(p,angle);
My_point_saved rotated_point(p,iter->first,iter->second); Point_with_hot_pixel_history_saved rotated_point(p,iter->first,iter->second);
l.push_back(rotated_point);
tree->insert(rotated_point);
} }
tree->build(l); tree->build();
//checking validity
if (!tree->is_valid()) tree->dump();
CGAL_assertion(tree->is_valid());
typename Traits::To_double to_dbl; typename Traits::To_double to_dbl;
double buffer_angle(to_dbl(angle) - half_pi / (2 * number_of_trees)); double buffer_angle(to_dbl(angle) - half_pi / (2 * number_of_trees));
if (buffer_angle < 0) buffer_angle = 0; if (buffer_angle < 0)
buffer_angle = 0;
Line_2 li(std::tan(buffer_angle), -1, 0); Line_2 li(std::tan(buffer_angle), -1, 0);
Direction_2 d(li); Direction_2 d(li);
// rotate_by 180 degrees // rotate_by 180 degrees
Transformation_2 t(ROTATION, 0, -1); Transformation_2 t(ROTATION, 0, -1);
d = d.transform(t); d = d.transform(t);
Direction_nt_pair kp(d, angle); Direction_nt_pair kp(d, angle);
Kd_triple kt(tree, kp); Kd_triple kt(tree, kp);
return(kt); return(kt);
@ -155,10 +223,12 @@ private:
inline NT min BOOST_PREVENT_MACRO_SUBSTITUTION (NT x1, NT x2, NT x3, NT x4, NT x5, inline NT min BOOST_PREVENT_MACRO_SUBSTITUTION (NT x1, NT x2, NT x3, NT x4, NT x5,
NT x6) NT x6)
{return(min BOOST_PREVENT_MACRO_SUBSTITUTION (min BOOST_PREVENT_MACRO_SUBSTITUTION (min BOOST_PREVENT_MACRO_SUBSTITUTION (x1, x2), min BOOST_PREVENT_MACRO_SUBSTITUTION (x3, x4)),min BOOST_PREVENT_MACRO_SUBSTITUTION (x5, x6)));} {return(min BOOST_PREVENT_MACRO_SUBSTITUTION (min BOOST_PREVENT_MACRO_SUBSTITUTION (min BOOST_PREVENT_MACRO_SUBSTITUTION (x1, x2),
min BOOST_PREVENT_MACRO_SUBSTITUTION (x3, x4)),min BOOST_PREVENT_MACRO_SUBSTITUTION (x5, x6)));}
inline NT max BOOST_PREVENT_MACRO_SUBSTITUTION (NT x1, NT x2, NT x3, NT x4, NT x5, NT x6) inline NT max BOOST_PREVENT_MACRO_SUBSTITUTION (NT x1, NT x2, NT x3, NT x4, NT x5, NT x6)
{return(max BOOST_PREVENT_MACRO_SUBSTITUTION (max BOOST_PREVENT_MACRO_SUBSTITUTION (max BOOST_PREVENT_MACRO_SUBSTITUTION (x1, x2), max BOOST_PREVENT_MACRO_SUBSTITUTION (x3, x4)),max BOOST_PREVENT_MACRO_SUBSTITUTION (x5, x6)));} {return(max BOOST_PREVENT_MACRO_SUBSTITUTION (max BOOST_PREVENT_MACRO_SUBSTITUTION (max BOOST_PREVENT_MACRO_SUBSTITUTION (x1, x2),
max BOOST_PREVENT_MACRO_SUBSTITUTION (x3, x4)),max BOOST_PREVENT_MACRO_SUBSTITUTION (x5, x6)));}
/*! */ /*! */
Direction_2 get_direction(Segment_2 seg) Direction_2 get_direction(Segment_2 seg)
@ -330,6 +400,7 @@ public:
pi(3.1415), half_pi(1.57075), pi(3.1415), half_pi(1.57075),
number_of_trees(inp_number_of_trees), input_points_list(inp_points_list) number_of_trees(inp_number_of_trees), input_points_list(inp_points_list)
{ {
Kd_triple kd; Kd_triple kd;
// check that there are at least two trees // check that there are at least two trees
@ -353,9 +424,13 @@ public:
angle += half_pi / number_of_trees,++i) angle += half_pi / number_of_trees,++i)
{ {
buffer_angle = angle - half_pi / (2 * number_of_trees); buffer_angle = angle - half_pi / (2 * number_of_trees);
if (buffer_angle < 0) buffer_angle = 0;
if (buffer_angle < 0)
buffer_angle = 0;
li = Line_2(std::tan(buffer_angle), -1, 0); li = Line_2(std::tan(buffer_angle), -1, 0);
d = Direction_2(li); d = Direction_2(li);
// rotate_by 180 degrees // rotate_by 180 degrees
Transformation_2 t(ROTATION, 0, -1); Transformation_2 t(ROTATION, 0, -1);
d = d.transform(t); d = d.transform(t);
@ -369,7 +444,9 @@ public:
#ifdef CGAL_SR_DEBUG #ifdef CGAL_SR_DEBUG
int number_of_actual_kd_trees = 0; int number_of_actual_kd_trees = 0;
#endif #endif
i = 0; i = 0;
for (NT angle = 0; i < number_of_trees; for (NT angle = 0; i < number_of_trees;
angle += NT(half_pi / number_of_trees),++i) angle += NT(half_pi / number_of_trees),++i)
{ {
@ -377,6 +454,7 @@ public:
(double)number_of_segments / (double)number_of_trees / 2.0) (double)number_of_segments / (double)number_of_trees / 2.0)
{ {
kd = create_kd_tree(angle); kd = create_kd_tree(angle);
kd_trees_list.push_back(kd); kd_trees_list.push_back(kd);
#ifdef CGAL_SR_DEBUG #ifdef CGAL_SR_DEBUG
@ -397,12 +475,13 @@ public:
} }
~Multiple_kd_tree() { ~Multiple_kd_tree()
for(typename Kd_triple_list::iterator it = kd_trees_list.begin(); {
it != kd_trees_list.end(); ++it) { //delete all the kd_trees.
for(typename Kd_triple_list::iterator it = kd_trees_list.begin(); it != kd_trees_list.end(); ++it)
delete (it->first); delete (it->first);
}
//delete all the points.
for(typename Point_saved_pair_list::iterator it = input_points_list.begin(); for(typename Point_saved_pair_list::iterator it = input_points_list.begin();
it != input_points_list.end(); ++it) { it != input_points_list.end(); ++it) {
delete (it->second); delete (it->second);
@ -444,63 +523,71 @@ public:
{ {
// determine right kd-tree to work on, depending on the segment's slope // determine right kd-tree to work on, depending on the segment's slope
Direction_2 d = get_direction(s); Direction_2 d = get_direction(s);
int i = 0; int i = 0;
int n = kd_trees_list.size(); int n = kd_trees_list.size();
bool found = false; bool found = false;
typename Kd_triple_list::const_iterator iter = kd_trees_list.begin(); typename Kd_triple_list::const_iterator iter = kd_trees_list.begin();
while(i < n && !found) { while(i < n && !found)
if (iter->second.first > d) found = true; {
if (iter->second.first > d)
found = true;
++i; ++i;
++iter; ++iter;
} }
if (!found) iter = kd_trees_list.begin(); if (!found)
else --iter; iter = kd_trees_list.begin();
else
--iter;
Point_list points_list; Point_list points_list;
m_gt.minkowski_sum_with_pixel_2_object()(points_list, s, unit_square); m_gt.minkowski_sum_with_pixel_2_object()(points_list, s, unit_square);
Point_iter points_iter; Point_iter points_iter;
for (points_iter = points_list.begin(); points_iter != points_list.end(); for (points_iter = points_list.begin(); points_iter != points_list.end(); ++points_iter)
++points_iter)
rotate(*points_iter, iter->second.second); rotate(*points_iter, iter->second.second);
// query // query
points_iter = points_list.begin(); points_iter = points_list.begin();
Point_2 point_left, point_right, point_bot, point_top; Point_2 point_left, point_right, point_bot, point_top;
point_left = point_right = point_bot = point_top = *points_iter; point_left = point_right = point_bot = point_top = *points_iter;
for (++points_iter; points_iter != points_list.end(); ++points_iter) {
for (++points_iter; points_iter != points_list.end(); ++points_iter)
{
point_left = small_x_point(point_left,*points_iter); point_left = small_x_point(point_left,*points_iter);
point_right = big_x_point(point_right,*points_iter); point_right = big_x_point(point_right,*points_iter);
point_bot = small_y_point(point_bot,*points_iter); point_bot = small_y_point(point_bot,*points_iter);
point_top = big_y_point(point_top,*points_iter); point_top = big_y_point(point_top,*points_iter);
} }
typedef typename Traits::Construct_iso_rectangle_2 typedef typename Traits::Construct_iso_rectangle_2 Construct_iso_rectangle_2;
Construct_iso_rectangle_2;
Construct_iso_rectangle_2 construct_rec = Construct_iso_rectangle_2 construct_rec = m_gt.construct_iso_rectangle_2_object();
m_gt.construct_iso_rectangle_2_object();
Iso_rectangle_2 rec = Iso_rectangle_2 rec = construct_rec(point_left, point_right, point_bot, point_top);
construct_rec(point_left, point_right, point_bot, point_top);
Point_2 p1 = rec.vertex(0); Point_2 p1 = rec.vertex(0);
Point_2 p2 = rec.vertex(2); Point_2 p2 = rec.vertex(2);
My_point_saved point1(p1); Point_with_hot_pixel_history_saved point1(p1);
My_point_saved point2(p2); Point_with_hot_pixel_history_saved point2(p2);
Box b(point1, point2, 2); Box b(point1, point2);
// the kd-tree query // the kd-tree query
My_point_saved_list res; Point_with_hot_pixel_history_saved_list result;
iter->first->search(std::back_inserter(res), b);
iter->first->search(std::back_inserter(result), b);
// create result // create result
result_list.empty(); result_list.empty();
for (My_point_saved_iter my_point_iter = res.begin();
my_point_iter != res.end(); ++my_point_iter) for( Point_with_hot_pixel_history_saved_iter my_point_iter = result.begin(); my_point_iter != result.end(); ++my_point_iter )
result_list.push_back(my_point_iter->object); result_list.push_back(my_point_iter->object);
} }
}; };

18
Snap_rounding_2/include/CGAL/Snap_rounding_traits_2.h Normal file → Executable file
View File

@ -1,4 +1,4 @@
// Copyright (c) 2001 Tel-Aviv University (Israel). // Copyright (c) 2001,2009,2014 Tel-Aviv University (Israel), Max-Planck-Institute Saarbruecken (Germany).
// All rights reserved. // All rights reserved.
// //
// This file is part of CGAL (www.cgal.org). // This file is part of CGAL (www.cgal.org).
@ -16,7 +16,9 @@
// $Id$ // $Id$
// //
// //
// author(s) : Eli Packer <elip@post.tau.ac.il> // author(s) : Eli Packer <elip@post.tau.ac.il>,
// Waqar Khan <wkhan@mpi-inf.mpg.de>
#ifndef CGAL_SNAP_ROUNDING_2_TRAITS_H #ifndef CGAL_SNAP_ROUNDING_2_TRAITS_H
#define CGAL_SNAP_ROUNDING_2_TRAITS_H #define CGAL_SNAP_ROUNDING_2_TRAITS_H
@ -44,15 +46,16 @@ public: // otherwise Segment_data cannot access the types
typedef typename Base_kernel::Direction_2 Direction_2; typedef typename Base_kernel::Direction_2 Direction_2;
typedef typename Base_kernel::Construct_vertex_2 Construct_vertex_2 ; typedef typename Base_kernel::Construct_vertex_2 Construct_vertex_2 ;
typedef typename Base_kernel::Construct_segment_2 Construct_segment_2 ; typedef typename Base_kernel::Construct_segment_2 Construct_segment_2 ;
typedef typename Base_kernel::Construct_iso_rectangle_2 typedef typename Base_kernel::Construct_iso_rectangle_2 Construct_iso_rectangle_2;
Construct_iso_rectangle_2;
typedef typename Base_kernel::Compare_y_2 Compare_y_2; typedef typename Base_kernel::Compare_y_2 Compare_y_2;
typedef typename Base_kernel::Construct_min_vertex_2 Construct_min_vertex_2;
typedef typename Base_kernel::Construct_max_vertex_2 Construct_max_vertex_2;
typedef typename Base_kernel::Cartesian_const_iterator_2 Cartesian_const_iterator_2;
typedef typename Base_kernel::Construct_cartesian_const_iterator_2 Construct_cartesian_const_iterator_2;
typedef CGAL::Arr_segment_traits_2<Base_kernel> Base_traits; typedef CGAL::Arr_segment_traits_2<Base_kernel> Base_traits;
typedef typename Base_traits::Compare_x_2 Compare_x_2; typedef typename Base_traits::Compare_x_2 Compare_x_2;
typedef CGAL::To_double<NT> To_double; typedef CGAL::To_double<NT> To_double;
public: public:
@ -198,7 +201,6 @@ public:
return k.construct_iso_rectangle_2_object(); return k.construct_iso_rectangle_2_object();
} }
}; };
} //namespace CGAL } //namespace CGAL

View File

@ -105,6 +105,17 @@ The value type of the `InputIterator` must be `Point_d`.
*/ */
template <class InputIterator> void insert(InputIterator first, InputIterator beyond); template <class InputIterator> void insert(InputIterator first, InputIterator beyond);
/*
Pre-allocates memory in order to store at least 'size' points.
*/
void reserve(size_t size);
/*
Returns the number of points for which memory has been pre-allocated.
*/
size_t capacity();
/*! /*!
Reports the points that are approximately contained by `q`. Reports the points that are approximately contained by `q`.
The types `FuzzyQueryItem::Point_d` and `Point_d` must be equivalent. The types `FuzzyQueryItem::Point_d` and `Point_d` must be equivalent.

View File

@ -1,4 +1,4 @@
// Copyright (c) 2002,2011 Utrecht University (The Netherlands). // Copyright (c) 2002,2011,2014 Utrecht University (The Netherlands), Max-Planck-Institute Saarbruecken (Germany).
// All rights reserved. // All rights reserved.
// //
// This file is part of CGAL (www.cgal.org). // This file is part of CGAL (www.cgal.org).
@ -15,8 +15,8 @@
// $URL$ // $URL$
// $Id$ // $Id$
// //
// // Author(s) : Hans Tangelder (<hanst@cs.uu.nl>),
// Author(s) : Hans Tangelder (<hanst@cs.uu.nl>) // : Waqar Khan <wkhan@mpi-inf.mpg.de>
#ifndef CGAL_KD_TREE_H #ifndef CGAL_KD_TREE_H
#define CGAL_KD_TREE_H #define CGAL_KD_TREE_H
@ -267,6 +267,18 @@ public:
pts.insert(pts.end(),first, beyond); pts.insert(pts.end(),first, beyond);
} }
//For efficiency; reserve the size of the points vectors in advance (if the number of points is already known).
void reserve(size_t size)
{
pts.reserve(size);
}
//Get the capacity of the underlying points vector.
size_t capacity()
{
return pts.capacity();
}
template <class OutputIterator, class FuzzyQueryItem> template <class OutputIterator, class FuzzyQueryItem>
OutputIterator OutputIterator

View File

@ -0,0 +1,71 @@
#include <CGAL/Simple_cartesian.h>
#include <CGAL/Kd_tree.h>
#include <CGAL/point_generators_2.h>
#include <CGAL/algorithm.h>
#include <CGAL/Fuzzy_iso_box.h>
#include <CGAL/Search_traits_2.h>
typedef CGAL::Simple_cartesian<double> K;
typedef K::Point_2 Point_d;
typedef CGAL::Random_points_in_square_2<Point_d> Random_points_iterator;
typedef CGAL::Counting_iterator<Random_points_iterator> N_Random_points_iterator;
typedef CGAL::Search_traits_2<K> Traits;
typedef CGAL::Kd_tree<Traits> Tree;
typedef CGAL::Fuzzy_iso_box<Traits> Fuzzy_iso_box;
int
main() {
const size_t N = 1000;
std::list<Point_d> points;
points.push_back(Point_d(0,0));
Tree tree;
Random_points_iterator rpg;
//inserting N points one-by-one, thus the use of "reserve" is recommended, and thus we use it
tree.reserve(N);
//to test wether the tree.capacity() function works properly.
if( tree.capacity() < N)
{
std::cerr << "ERROR: Something is wrong with allocating points memory." << std::endl;
return -1;
}
for(size_t i = 0; i < N; i++)
{
tree.insert(*rpg++);
}
std::list<Point_d> result;
// define range query
Point_d p(0.2, 0.2);
Point_d q(0.7, 0.7);
// Searching an exact range
// using default value 0.0 for epsilon fuzziness paramater
// Fuzzy_box exact_range(r); replaced by
Fuzzy_iso_box exact_range(p,q);
std::cout << "tree.search(..)" << std::endl;
//tree.report_all_points(std::ostream_iterator<Point>(std::cout,"\n"));
tree.search( std::back_inserter( result ), exact_range);
std::cout << "The points in the box [0.2,0.7]x[0.2,0.7] are: " << std::endl;
std::copy (result.begin(), result.end(), std::ostream_iterator<Point_d>(std::cout,"\n") );
std::cout << std::endl;
result.clear();
// Searching a fuzzy range
// using value 0.1 for fuzziness paramater
Fuzzy_iso_box approximate_range(p, q, 0.1);
tree.search(std::back_inserter( result ), approximate_range);
std::cout << "The points in the fuzzy box [<0.1-0.3>,<0.6-0.9>]x[<0.1-0.3>,<0.6-0.9>] are: "
<< std::endl;
std::copy (result.begin(), result.end(), std::ostream_iterator<Point_d>(std::cout,"\n") );
std::cout << std::endl;
return 0;
}

View File

@ -1 +0,0 @@
examples

View File

@ -1,5 +0,0 @@
3
3
7
7

View File

@ -1,80 +0,0 @@
// Copyright (c) 1997 Tel-Aviv University (Israel).
// All rights reserved.
//
// This file is part of an example program for CGAL. This example
// program may be used, distributed and modified without limitation.
//
/*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
* example1.C -
* Simple example the CGAL KD-tree module.
*
* Written by Sariel Har-Peled
* Iddo Hanniel
\*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*/
#include <CGAL/Cartesian.h>
#include <iostream>
#include <iterator>
#include <ctime>
#include <cassert>
#include <cstdlib>
#include <list>
#include <CGAL/kdtree_d.h>
typedef CGAL::Cartesian<double> K;
typedef K::Point_2 point;
typedef CGAL::Kdtree_interface_2d<point> kd_interface;
typedef CGAL::Kdtree_d<kd_interface> kd_tree;
typedef kd_tree::Box box;
typedef std::list<point> points_list;
int main()
{
CGAL::Kdtree_d<kd_interface> tree(2);
points_list l, res;
std::srand( (unsigned)time(NULL) );
std::cout << "Insering evenly 81 points in the square (0,0)-(10,10) ...\n\n";
for (int i=1; i<10; i++)
for (int j=1; j<10; j++)
{
point p(i,j);
l.push_front(p);
}
// building the tree
tree.build( l );
// checking validity
if ( ! tree.is_valid() )
tree.dump();
assert( tree.is_valid() );
// Defining and searching the box r
double lx,ly,rx,ry;
std::cout << "Define your query square.\nEnter left x coordinate: " ;
std::cin >> lx ;
std::cout << "Enter left y coordinate: ";
std::cin >> ly;
std::cout << "Enter right x coordinate: " ;
std::cin >> rx ;
std::cout << "Enter right y coordinate: ";
std::cin >> ry;
std::cout << std::endl;
box r(point(lx,ly), point(rx,ry) ,2);
tree.search( std::back_inserter( res ), r );
std::cout << "Listing of the points in the square: \n" ;
std::copy (res.begin(),res.end(),std::ostream_iterator<point>(std::cout," \n") );
std::cout << std::endl;
tree.delete_all();
return 0;
}

View File

@ -1,93 +0,0 @@
// Copyright (c) 1997 Tel-Aviv University (Israel).
// All rights reserved.
//
// This file is part of an example program for CGAL. This example
// program may be used, distributed and modified without limitation.
//
/*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
* example2.C -
* Simple example the CGAL KD-tree module.
*
* Written by Sariel Har-Peled
* Iddo Hanniel
\*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*/
#include <CGAL/Cartesian.h>
#include <iostream>
#include <iterator>
#include <ctime>
#include <cassert>
#include <cstdlib>
#include <list>
#include <CGAL/kdtree_d.h>
typedef CGAL::Cartesian<double> K;
typedef K::Point_3 point;
typedef CGAL::Kdtree_interface_3d<point> kd_interface;
typedef CGAL::Kdtree_d<kd_interface> kd_tree;
typedef kd_tree::Box box;
typedef std::list<point> points_list;
//RANDOM FUNCTIONS
// dblRand - a random number between 0..1
#ifndef RAND_MAX
#define RAND_MAX 0x7fffffff
#endif
inline double dblRand( void )
{
return (double)std::rand() / (double)RAND_MAX;
}
void random_points( int num, points_list &l )
{
double x,y,z;
for (int j = 0; j < num; j++)
{
x = dblRand()*10 ;
y = dblRand()*10 ;
z = dblRand()*10 ;
point p(x,y,z);
l.push_front(p);
}
}
int main()
{
CGAL::Kdtree_d<kd_interface> tree(3);
std::srand( (unsigned)time(NULL) );
std::cout << "Choosing randomly 30 points in the cube (0,0,0)-(10,10,10)\n" ;
points_list l , res;
random_points( 30, l);
std::cout << "Listing of random points:\n" ;
std::copy (l.begin(),l.end(),std::ostream_iterator<point>(std::cout,"\n") );
std::cout << std::endl;
// Building the tree for the random points
tree.build( l );
// Checking validity
if ( ! tree.is_valid() )
tree.dump();
assert( tree.is_valid() );
// Searching the box r
box r(point(2,2,2), point(7,7,7) ,3);
tree.search( std::back_inserter( res ), r );
std::cout << "Listing of the points in the box (2,2,2)-(7,7,7) : \n" ;
std::copy (res.begin(),res.end(),std::ostream_iterator<point>(std::cout,"\n") );
std::cout << std::endl;
tree.delete_all();
return 0;
}

View File

@ -1,155 +0,0 @@
// Copyright (c) 1997 Tel-Aviv University (Israel).
// All rights reserved.
//
// This file is part of an example program for CGAL. This example
// program may be used, distributed and modified without limitation.
//
/*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
* example3.C -
* Simple example the CGAL KD-tree module.
* Example with user defined point_d.
*
* Written by Sariel Har-Peled
* Iddo Hanniel
\*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*/
#include <CGAL/Cartesian.h>
#include <iostream>
#include <iterator>
#include <ctime>
#include <cassert>
#include <cstdlib>
#include <list>
#include <CGAL/kdtree_d.h>
template <int DIM>
class Point_float_d
{
private:
double vec[ DIM ];
public:
Point_float_d()
{
for ( int ind = 0; ind < DIM; ind++ )
vec[ ind ] = 0;
}
int dimension() const
{
return DIM;
}
//not essential by specification but needed for initializing a general d-point
void set_coord(int k, double x)
{
assert( 0 <= k && k < DIM );
vec[ k ] = x;
}
double & operator[](int k)
{
assert( 0 <= k && k < DIM );
return vec[ k ];
}
double operator[](int k) const
{
assert( 0 <= k && k < DIM );
return vec[ k ];
}
};
// not essential by specification but nice to have
template <int DIM>
std::ostream &operator<<(std::ostream &os, const Point_float_d<DIM> &p)
{
std::cout << "(";
for(int i = 0; i < DIM; i++)
{
std::cout << p[i] ;
if (i < p.dimension() - 1) std::cout << ", ";
}
std::cout << ")";
return os;
}
typedef Point_float_d<4> point;
typedef CGAL::Kdtree_interface<point> kd_interface;
typedef CGAL::Kdtree_d<kd_interface> kd_tree;
typedef kd_tree::Box box;
typedef std::list<point> points_list;
//RANDOM FUNCTIONS
// dblRand - a random number between 0..1
#ifndef RAND_MAX
#define RAND_MAX 0x7fffffff
#endif
inline double dblRand( void )
{
return (double)std::rand() / (double)RAND_MAX;
}
void random_points( int num, points_list &l, int DIM)
{
double x;
for (int j = 0; j < num; j++)
{
point p;
for (int i=0; i<DIM; i++)
{
x = dblRand()*10 ;
p.set_coord(i,x);
}
l.push_front(p);
}
}
int main()
{
CGAL::Kdtree_d<kd_interface> tree(3);
std::srand( (unsigned)time(NULL) );
std::cout << "Choosing randomly 30 points in the cube (0,0,0)-(10,10,10)\n" ;
points_list l , res;
random_points( 30, l , 4);
std::cout << "Listing of random points:\n" ;
std::copy (l.begin(),l.end(),std::ostream_iterator<point>(std::cout,"\n") );
std::cout << std::endl;
// Building the tree for the random points
tree.build( l );
// Checking validity
if ( ! tree.is_valid() )
tree.dump();
assert( tree.is_valid() );
// Searching the box r
point p,q;
for (int k=0;k<4;k++)
{
p.set_coord(k,2);
q.set_coord(k,8);
}
box r(p, q, 4);
tree.search( std::back_inserter( res ), r );
std::cout << "Listing of the points in the box (2,2,2,2)-(8,8,8,8) : \n" ;
std::copy (res.begin(),res.end(),
std::ostream_iterator<point>(std::cout,"\n") );
std::cout << std::endl;
tree.delete_all();
return 0;
}

View File

@ -1,86 +0,0 @@
// Copyright (c) 1997 Tel-Aviv University (Israel).
// All rights reserved.
//
// This file is part of an example program for CGAL. This example
// program may be used, distributed and modified without limitation.
//
/*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
* example2.C - bench mark
* Simple example the CGAL KD-tree module.
*
* Written by Sariel Har-Peled
* Iddo Hanniel
\*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*/
#include <CGAL/Cartesian.h>
#include <iostream>
#include <fstream>
#include <iterator>
#include <ctime>
#include <cassert>
#include <list>
#include <CGAL/kdtree_d.h>
#include <CGAL/Timer.h>
#include <CGAL/Random.h>
typedef CGAL::Cartesian<double> K;
typedef K::Point_3 Point;
typedef CGAL::Kdtree_interface_3d<Point> kd_interface;
typedef CGAL::Kdtree_d<kd_interface> kd_tree;
typedef kd_tree::Box box;
typedef std::list<Point> points_list;
int main()
{
CGAL::Kdtree_d<kd_interface> tree(3);
CGAL::Timer t;
const int dim=3;
// const int data_point_number=1000000;
const int data_point_number=10000;
typedef std::list<Point> point_list;
point_list data_points,res;
// get data points
// add random points of dimension dim to data_points
CGAL::Random Rnd;
// std::cout << "started tstrandom()" << std::endl;
for (int i1=0; i1<data_point_number; i1++) {
double v[dim];
for (int i2=0; i2<dim; i2++) v[i2]=Rnd.get_double(-1.0,1.0);
Point Random_point(v[0],v[1],v[2]);
data_points.push_front(Random_point);
}
t.reset();t.start();
tree.build(data_points);
t.stop();
std::cout << "building time =" << t.time() << std::endl;
// Searching the box r
t.reset();t.start();
box r(Point(0.2,0.2,0.2), Point(0.7,0.7,0.7) ,3);
tree.search( std::back_inserter( res ), r );
t.stop();
std::cout << "searching time=" << t.time() << std::endl;
std::cout << "Number of the points in the box (0.2,0.2,0.2)-(0.7,0.7,0.7) = " <<
res.size();
// std::copy (res.begin(),res.end(),std::ostream_iterator<point>(std::cout,"\n") );
std::cout << std::endl;
return 0;
}

File diff suppressed because it is too large Load Diff

View File

@ -1 +0,0 @@
Tel-Aviv University (Israel).

View File

@ -1 +0,0 @@
The KD-tree implementation .

View File

@ -1 +0,0 @@
GPL (v3 or later)

View File

@ -1,11 +0,0 @@
CGAL KD-tree impelementation
----------------------------
The following contains the CGAL KD-tree implementation. The examples/kdtrees/
directory contains three simple examples for the use of kd-trees in 2D, 3D
(using points from the Cgal kernel) and 4D (using user-defined points).
The source is under include/CGAL/kdtree_d.h, and it can be used
independently from the rest of CGAL.
-----------------------------------------------------------------------

View File

@ -1 +0,0 @@
cgal-develop