// ====================================================================== // // Copyright (c) 2001 The CGAL Consortium // // This software and related documentation is part of an INTERNAL release // of the Computational Geometry Algorithms Library (CGAL). It is not // intended for general use. // // ---------------------------------------------------------------------- // // release : // release_date : // // file : include/CGAL/Binary_search_tree.h // package : APSPAS // revision : 1.0 // revision_date : 2001/06/12 // maintainer : Hans Tangelder () // // ====================================================================== #ifndef CGAL_BINARY_SEARCH_TREE_H #define CGAL_BINARY_SEARCH_TREE_H #include #include #include #include #include #include namespace CGAL { template class Binary_search_tree { public: typedef Traits::Item Item; typedef Traits::InputIterator InputIterator; typedef Item::FT NT; typedef Base_node Node; typedef Binary_search_tree Tree; private: Node* tree_root; Box* bbox; std::list pts; Traits tr; int the_item_number; // protected copy constructor Binary_search_tree(const Tree& tree) {}; public: Binary_search_tree(InputIterator first, InputIterator beyond, int bucket_size=1, bool check_validity=false, Traits t = Traits()) : tr(t) { assert(first != beyond); int dim = first->dimension(); std::copy(first, beyond, std::back_inserter(pts)); Points_container c(dim, pts.begin(), pts.end()); if (check_validity) {std::cout << c.is_valid() << std::endl;} bbox = new Box(c.bounding_box()); the_item_number=c.size(); if (c.size() <= bucket_size) tree_root = new Leaf_node(c); else { if (t.use_extended_nodes()) tree_root = new Extended_internal_node(c,bucket_size); else tree_root = new Internal_node(c,bucket_size); } } ~Binary_search_tree() { delete tree_root; delete bbox; }; void generate_postscript_file(const char* filename, const float width, const int i, const int j) { float box_height = bbox->upper(j) - bbox->lower(j); float box_width = bbox->upper(i) - bbox->lower(i); const float height= width * (box_height/box_width); PS_Stream::PS_BBox bb(bbox->lower(i)-0.01*box_width, bbox->lower(j)-0.01*box_height, bbox->upper(i)+0.01*box_width, bbox->upper(j)+0.01*box_height); PS_Stream PS(bb,height,filename,PS_Stream::QUIET_EPS); // removed CGAL:: /* PS.init(bbox->lower(i),bbox->upper(i),bbox->lower(j)); cgalize(PS); // removed CGAL:: PS.display(); */ // test it PS << point_style(PS_Stream::FDOT); PS << point_size(1); PS << line_width(1); tree_root->data_to_postscript(PS, i, j, bbox->lower(i), bbox->upper(i), bbox->lower(j), bbox->upper(j)); } Traits traits() const {return tr;} // Returns the traits class; Node* root() { return tree_root; } Box* bounding_box() {return bbox; } int item_number() {return the_item_number;} bool is_valid(bool verbose = false, int level = 0) { // Perform internal consistency checks to verify the correctness // of the tree. std::list pts_1; std::back_insert_iterator > it(pts_1); // unsigned int nit = items(it); root().tree_items(it); // store the items in pts_1 // check that pts_1 and pts contain the same stuff assert( pts_1.size() == num_items(root())); std::list::const_iterator i; for (i = pts.begin(); i != pts.end(); ++i) { std::list::iterator j = std::find(pts_1.begin(), pts_1.end(), *i); assert(j != pts_1.end()); assert(*j == *i); } return 1; } // Print statistics of the tree. void statistics (bool check_validity=false) { std::cout << "Tree statistics:" << std::endl; std::cout << "Number of items stored: " << tree_root.num_items() << std::endl; std::cout << " Tree depth: " << tree_root.depth() << std::endl; if (check_validity) { std::cout << " Calling is_valid: " << is_valid() << std::endl; } } }; } // namespace CGAL #endif // CGAL_BINARY_SEARCH_TREE_H