From 1182319f5d0857e14e599167ed47caf7fee31b43 Mon Sep 17 00:00:00 2001 From: Guillaume Damiand Date: Thu, 30 Oct 2014 16:05:22 +0100 Subject: [PATCH 01/30] Redo all the modifs to remove all the cpp files from cgal. First step where all the XXX.cpp are copied into XXX_impl.h files. The macro CGAL_HEADER_ONLY allows to know if impl files need to be included or not into header files; and allow to decide if functions are in impl files are inline or not. Next step: process with static variables for the header only version. --- .../include/CGAL/Bbox_2_Line_2_intersection.h | 4 + .../CGAL/Bbox_2_Line_2_intersection_impl.h | 213 +++++++++ .../include/CGAL/Ray_2_Bbox_2_intersection.h | 4 +- .../CGAL/Ray_2_Bbox_2_intersection_impl.h | 209 +++++++++ .../src/CGAL/Bbox_2_intersections.cpp | 345 +-------------- Kernel_23/include/CGAL/Origin.h | 4 + Kernel_23/include/CGAL/Origin_impl.h | 32 ++ .../include/CGAL/aff_transformation_tags.h | 14 +- .../CGAL/aff_transformation_tags_impl.h | 35 ++ Kernel_23/src/CGAL/kernel.cpp | 17 +- STL_Extension/include/CGAL/assertions.h | 4 + STL_Extension/src/CGAL/assertions.cpp | 198 +-------- Stream_support/include/CGAL/IO/Color.h | 4 + Stream_support/include/CGAL/IO/Color_impl.h | 23 + .../include/CGAL/IO/File_header_OFF.h | 5 + .../include/CGAL/IO/File_header_OFF_impl.h | 409 ++++++++++++++++++ .../CGAL/IO/File_header_extended_OFF.h | 5 + .../CGAL/IO/File_header_extended_OFF_impl.h | 212 +++++++++ .../include/CGAL/IO/File_scanner_OFF.h | 4 + .../include/CGAL/IO/File_scanner_OFF_impl.h | 133 ++++++ .../include/CGAL/IO/File_writer_OFF.h | 5 + .../include/CGAL/IO/File_writer_OFF_impl.h | 56 +++ .../include/CGAL/IO/File_writer_VRML_2.h | 5 + .../include/CGAL/IO/File_writer_VRML_2_impl.h | 82 ++++ .../include/CGAL/IO/File_writer_inventor.h | 5 + .../CGAL/IO/File_writer_inventor_impl.h | 73 ++++ .../include/CGAL/IO/File_writer_wavefront.h | 5 + .../CGAL/IO/File_writer_wavefront_impl.h | 57 +++ Stream_support/include/CGAL/IO/io.h | 4 +- Stream_support/src/CGAL/Color.cpp | 2 +- Stream_support/src/CGAL/File_header_OFF.cpp | 366 +--------------- .../src/CGAL/File_header_extended_OFF.cpp | 170 +------- Stream_support/src/CGAL/File_scanner_OFF.cpp | 99 +---- Stream_support/src/CGAL/File_writer_OFF.cpp | 23 +- .../src/CGAL/File_writer_VRML_2.cpp | 49 +-- .../src/CGAL/File_writer_inventor.cpp | 38 +- .../src/CGAL/File_writer_wavefront.cpp | 24 +- Stream_support/src/CGAL/io.cpp | 95 +--- 38 files changed, 1613 insertions(+), 1419 deletions(-) create mode 100644 Intersections_2/include/CGAL/Bbox_2_Line_2_intersection_impl.h create mode 100644 Intersections_2/include/CGAL/Ray_2_Bbox_2_intersection_impl.h create mode 100644 Kernel_23/include/CGAL/Origin_impl.h create mode 100644 Kernel_23/include/CGAL/aff_transformation_tags_impl.h create mode 100644 Stream_support/include/CGAL/IO/Color_impl.h create mode 100644 Stream_support/include/CGAL/IO/File_header_OFF_impl.h create mode 100644 Stream_support/include/CGAL/IO/File_header_extended_OFF_impl.h create mode 100644 Stream_support/include/CGAL/IO/File_scanner_OFF_impl.h create mode 100644 Stream_support/include/CGAL/IO/File_writer_OFF_impl.h create mode 100644 Stream_support/include/CGAL/IO/File_writer_VRML_2_impl.h create mode 100644 Stream_support/include/CGAL/IO/File_writer_inventor_impl.h create mode 100644 Stream_support/include/CGAL/IO/File_writer_wavefront_impl.h diff --git a/Intersections_2/include/CGAL/Bbox_2_Line_2_intersection.h b/Intersections_2/include/CGAL/Bbox_2_Line_2_intersection.h index 02503f3c08d..f9f15e76094 100644 --- a/Intersections_2/include/CGAL/Bbox_2_Line_2_intersection.h +++ b/Intersections_2/include/CGAL/Bbox_2_Line_2_intersection.h @@ -96,4 +96,8 @@ inline bool do_intersect( } //namespace CGAL +#ifdef CGAL_HEADER_ONLY +#include +#endif // CGAL_HEADER_ONLY + #endif diff --git a/Intersections_2/include/CGAL/Bbox_2_Line_2_intersection_impl.h b/Intersections_2/include/CGAL/Bbox_2_Line_2_intersection_impl.h new file mode 100644 index 00000000000..c4a5132c0fe --- /dev/null +++ b/Intersections_2/include/CGAL/Bbox_2_Line_2_intersection_impl.h @@ -0,0 +1,213 @@ +// Copyright (c) 2000 +// 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$ +// +// +// Author(s) : Geert-Jan Giezeman + +#ifdef CGAL_HEADER_ONLY +#define CGAL_INLINE_FUNCTION inline +#else +#define CGAL_INLINE_FUNCTION +#endif + +#include +#include +typedef CGAL::Simple_cartesian Lcart; + + +namespace CGAL { + +class Bbox_2_Line_2_pair_impl +{ +public: + Bbox_2_Line_2_pair_impl() {} + Bbox_2_Line_2_pair_impl(Bbox_2 const &bb, Lcart::Line_2 const &line) + : _bbox(bb), _line(line), _known(false) {} + Bbox_2 _bbox; + Lcart::Line_2 _line; + mutable bool _known; + mutable Bbox_2_Line_2_pair::Intersection_results _result; + mutable double _min, _max; +}; + +CGAL_INLINE_FUNCTION +Bbox_2_Line_2_pair::~Bbox_2_Line_2_pair() +{ + delete pimpl; +} + +CGAL_INLINE_FUNCTION +Bbox_2_Line_2_pair::Bbox_2_Line_2_pair() +{ + pimpl = new Bbox_2_Line_2_pair_impl; + pimpl->_known = false; +} + +CGAL_INLINE_FUNCTION +Bbox_2_Line_2_pair::Bbox_2_Line_2_pair(Bbox_2_Line_2_pair const &o) +{ + pimpl = new Bbox_2_Line_2_pair_impl(*o.pimpl); +} + +CGAL_INLINE_FUNCTION +Bbox_2_Line_2_pair::Bbox_2_Line_2_pair( + Bbox_2 const &bbox, double line_a, double line_b, double line_c) +{ + pimpl = new Bbox_2_Line_2_pair_impl(bbox, + Lcart::Line_2(line_a, line_b, line_c)); +} + +CGAL_INLINE_FUNCTION +Bbox_2_Line_2_pair & +Bbox_2_Line_2_pair::operator=(Bbox_2_Line_2_pair const &o) +{ + *pimpl = *o.pimpl; + return *this; +} + + +CGAL_INLINE_FUNCTION +Bbox_2_Line_2_pair::Intersection_results +Bbox_2_Line_2_pair::intersection_type() const +{ + if (pimpl->_known) + return pimpl->_result; + // The non const this pointer is used to cast away const. + pimpl->_known = true; + const Lcart::Point_2 &ref_point = pimpl->_line.point(); + const Lcart::Vector_2 &dir = + pimpl->_line.direction().to_vector(); + bool to_infinity = true; +// first on x value + if (dir.x() == 0.0) { + if (ref_point.x() < pimpl->_bbox.xmin()) { + pimpl->_result = NO_INTERSECTION; + return pimpl->_result; + } + if (ref_point.x() > pimpl->_bbox.xmax()) { + pimpl->_result = NO_INTERSECTION; + return pimpl->_result; + } + } else { + double newmin, newmax; + if (dir.x() > 0.0) { + newmin = (pimpl->_bbox.xmin()-ref_point.x())/dir.x(); + newmax = (pimpl->_bbox.xmax()-ref_point.x())/dir.x(); + } else { + newmin = (pimpl->_bbox.xmax()-ref_point.x())/dir.x(); + newmax = (pimpl->_bbox.xmin()-ref_point.x())/dir.x(); + } + if (to_infinity) { + pimpl->_min = newmin; + pimpl->_max = newmax; + } else { + if (newmin > pimpl->_min) + pimpl->_min = newmin; + if (newmax < pimpl->_max) + pimpl->_max = newmax; + if (pimpl->_max < pimpl->_min) { + pimpl->_result = NO_INTERSECTION; + return pimpl->_result; + } + } + to_infinity = false; + } +// now on y value + if (dir.y() == 0.0) { + if (ref_point.y() < pimpl->_bbox.ymin()) { + pimpl->_result = NO_INTERSECTION; + return pimpl->_result; + } + if (ref_point.y() > pimpl->_bbox.ymax()) { + pimpl->_result = NO_INTERSECTION; + return pimpl->_result; + } + } else { + double newmin, newmax; + if (dir.y() > 0.0) { + newmin = (pimpl->_bbox.ymin()-ref_point.y())/dir.y(); + newmax = (pimpl->_bbox.ymax()-ref_point.y())/dir.y(); + } else { + newmin = (pimpl->_bbox.ymax()-ref_point.y())/dir.y(); + newmax = (pimpl->_bbox.ymin()-ref_point.y())/dir.y(); + } + if (to_infinity) { + pimpl->_min = newmin; + pimpl->_max = newmax; + } else { + if (newmin > pimpl->_min) + pimpl->_min = newmin; + if (newmax < pimpl->_max) + pimpl->_max = newmax; + if (pimpl->_max < pimpl->_min) { + pimpl->_result = NO_INTERSECTION; + return pimpl->_result; + } + } + to_infinity = false; + } + CGAL_kernel_assertion(!to_infinity); + if (pimpl->_max == pimpl->_min) { + pimpl->_result = POINT; + return pimpl->_result; + } + pimpl->_result = SEGMENT; + return pimpl->_result; +} + + +CGAL_INLINE_FUNCTION +bool +Bbox_2_Line_2_pair::intersection( + double &x1, double &y1, double &x2, double &y2) const +{ + if (!pimpl->_known) + intersection_type(); + if (pimpl->_result != SEGMENT) + return false; + Lcart::Point_2 p1(pimpl->_line.point() + + pimpl->_min*pimpl->_line.direction().to_vector()); + Lcart::Point_2 p2(pimpl->_line.point() + + pimpl->_max*pimpl->_line.direction().to_vector()); + x1 = p1.x(); + y1 = p1.y(); + x2 = p2.x(); + y2 = p2.y(); + return true; +} + +CGAL_INLINE_FUNCTION +bool +Bbox_2_Line_2_pair::intersection( + double &x, double &y) const +{ + if (!pimpl->_known) + intersection_type(); + if (pimpl->_result != POINT) + return false; + Lcart::Point_2 pt(pimpl->_line.point() + + pimpl->_min*pimpl->_line.direction().to_vector()); + x = pt.x(); + y = pt.y(); + return true; +} + +} //namespace CGAL diff --git a/Intersections_2/include/CGAL/Ray_2_Bbox_2_intersection.h b/Intersections_2/include/CGAL/Ray_2_Bbox_2_intersection.h index 13323e874ba..1c4dc287c9b 100644 --- a/Intersections_2/include/CGAL/Ray_2_Bbox_2_intersection.h +++ b/Intersections_2/include/CGAL/Ray_2_Bbox_2_intersection.h @@ -75,6 +75,8 @@ inline bool do_intersect_ray_2( } } //namespace CGAL - +#ifdef CGAL_HEADER_ONLY +#include +#endif // CGAL_HEADER_ONLY #endif diff --git a/Intersections_2/include/CGAL/Ray_2_Bbox_2_intersection_impl.h b/Intersections_2/include/CGAL/Ray_2_Bbox_2_intersection_impl.h new file mode 100644 index 00000000000..2ad3d7a2800 --- /dev/null +++ b/Intersections_2/include/CGAL/Ray_2_Bbox_2_intersection_impl.h @@ -0,0 +1,209 @@ +// Copyright (c) 2000 +// 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$ +// +// +// Author(s) : Geert-Jan Giezeman + +#ifdef CGAL_HEADER_ONLY +#define CGAL_INLINE_FUNCTION inline +#else +#define CGAL_INLINE_FUNCTION +#endif + +#include +#include +typedef CGAL::Simple_cartesian Rcart; + + +namespace CGAL { + +class Bbox_2_Ray_2_pair_impl +{ +public: + Bbox_2_Ray_2_pair_impl():_known(false) {} + Bbox_2_Ray_2_pair_impl(Bbox_2 const &bbox, Rcart::Point_2 const &pt, + Rcart::Vector_2 const &dir) + :_box(bbox), _known(false), _ref_point(pt), _dir(dir), _min(0.0) {} + Ray_2< Rcart > _ray; + Bbox_2 _box; + bool _known; + Bbox_2_Ray_2_pair::Intersection_results _result; + Rcart::Point_2 _ref_point; + Rcart::Vector_2 _dir; + double _min, _max; +}; + +CGAL_INLINE_FUNCTION +Bbox_2_Ray_2_pair::~Bbox_2_Ray_2_pair() +{ + delete pimpl; +} + +CGAL_INLINE_FUNCTION +Bbox_2_Ray_2_pair::Bbox_2_Ray_2_pair() +{ + pimpl = new Bbox_2_Ray_2_pair_impl; +} + +CGAL_INLINE_FUNCTION +Bbox_2_Ray_2_pair::Bbox_2_Ray_2_pair(Bbox_2_Ray_2_pair const &o) +{ + pimpl = new Bbox_2_Ray_2_pair_impl(*o.pimpl); +} + +CGAL_INLINE_FUNCTION +Bbox_2_Ray_2_pair::Bbox_2_Ray_2_pair( + Bbox_2 const &bbox, double x, double y, double dx, double dy) +{ + pimpl = new Bbox_2_Ray_2_pair_impl(bbox, + Rcart::Point_2(x,y), Rcart::Vector_2(dx,dy)); +} + +CGAL_INLINE_FUNCTION +Bbox_2_Ray_2_pair & +Bbox_2_Ray_2_pair::operator=(Bbox_2_Ray_2_pair const &o) +{ + *pimpl = *o.pimpl; + return *this; +} + +CGAL_INLINE_FUNCTION +Bbox_2_Ray_2_pair::Intersection_results +Bbox_2_Ray_2_pair::intersection_type() const +{ + if (pimpl->_known) + return pimpl->_result; + pimpl->_known = true; + bool to_infinity = true; +// first on x value + if (pimpl->_dir.x() == 0.0) { + if (pimpl->_ref_point.x() < pimpl->_box.xmin()) { + pimpl->_result = NO_INTERSECTION; + return pimpl->_result; + } + if (pimpl->_ref_point.x() > pimpl->_box.xmax()) { + pimpl->_result = NO_INTERSECTION; + return pimpl->_result; + } + } else { + double newmin, newmax; + if (pimpl->_dir.x() > 0.0) { + newmin =(pimpl->_box.xmin()-pimpl->_ref_point.x())/pimpl->_dir.x(); + newmax =(pimpl->_box.xmax()-pimpl->_ref_point.x())/pimpl->_dir.x(); + } else { + newmin =(pimpl->_box.xmax()-pimpl->_ref_point.x())/pimpl->_dir.x(); + newmax =(pimpl->_box.xmin()-pimpl->_ref_point.x())/pimpl->_dir.x(); + } + if (newmin > pimpl->_min) + pimpl->_min = newmin; + if (to_infinity) { + pimpl->_max = newmax; + } else { + if (newmax < pimpl->_max) + pimpl->_max = newmax; + } + if (pimpl->_max < pimpl->_min){ + pimpl->_result = NO_INTERSECTION; + return pimpl->_result; + } + to_infinity = false; + } +// now on y value + if (pimpl->_dir.y() == 0.0) { + if (pimpl->_ref_point.y() < pimpl->_box.ymin()) { + pimpl->_result = NO_INTERSECTION; + return pimpl->_result; + } + if (pimpl->_ref_point.y() > pimpl->_box.ymax()) { + pimpl->_result = NO_INTERSECTION; + return pimpl->_result; + } + } else { + double newmin, newmax; + if (pimpl->_dir.y() > 0.0) { + newmin =(pimpl->_box.ymin()-pimpl->_ref_point.y())/pimpl->_dir.y(); + newmax =(pimpl->_box.ymax()-pimpl->_ref_point.y())/pimpl->_dir.y(); + } else { + newmin =(pimpl->_box.ymax()-pimpl->_ref_point.y())/pimpl->_dir.y(); + newmax =(pimpl->_box.ymin()-pimpl->_ref_point.y())/pimpl->_dir.y(); + } + if (newmin > pimpl->_min) + pimpl->_min = newmin; + if (to_infinity) { + pimpl->_max = newmax; + } else { + if (newmax < pimpl->_max) + pimpl->_max = newmax; + } + if (pimpl->_max < pimpl->_min) { + pimpl->_result = NO_INTERSECTION; + return pimpl->_result; + } + to_infinity = false; + } + CGAL_kernel_assertion(!to_infinity); + if (pimpl->_max == pimpl->_min) { + pimpl->_result = POINT; + return pimpl->_result; + } + pimpl->_result = SEGMENT; + return pimpl->_result; +} + +CGAL_INLINE_FUNCTION +bool Bbox_2_Ray_2_pair:: +intersection(double &x1, double &y1, double &x2, double &y2) const +{ + if (!pimpl->_known) + intersection_type(); + if (pimpl->_result != SEGMENT) + return false; + Rcart::Point_2 p1(pimpl->_ref_point + pimpl->_min*pimpl->_dir); + Rcart::Point_2 p2(pimpl->_ref_point + pimpl->_max*pimpl->_dir); + x1 = p1.x(); + y1 = p1.y(); + x2 = p2.x(); + y2 = p2.y(); + return true; +} + +CGAL_INLINE_FUNCTION +bool Bbox_2_Ray_2_pair::intersection(double &x, double &y) const +{ + if (!pimpl->_known) + intersection_type(); + if (pimpl->_result != POINT) + return false; + Rcart::Point_2 pt = pimpl->_ref_point + pimpl->_min*pimpl->_dir; + x = pt.x(); + y = pt.y(); + return true; +} + +CGAL_INLINE_FUNCTION +bool do_intersect_ray_2( + const Bbox_2 &box, double x, double y, double dx, double dy) +{ + Bbox_2_Ray_2_pair pair(box, x, y, dx, dy); + return pair.intersection_type() != Bbox_2_Ray_2_pair::NO_INTERSECTION; +} + +} //namespace CGAL diff --git a/Intersections_2/src/CGAL/Bbox_2_intersections.cpp b/Intersections_2/src/CGAL/Bbox_2_intersections.cpp index baa4bf5b4ac..6b624b62961 100644 --- a/Intersections_2/src/CGAL/Bbox_2_intersections.cpp +++ b/Intersections_2/src/CGAL/Bbox_2_intersections.cpp @@ -22,346 +22,5 @@ // // Author(s) : Geert-Jan Giezeman - -#include -#include -#include -typedef CGAL::Simple_cartesian Rcart; - - -namespace CGAL { - -class Bbox_2_Line_2_pair_impl -{ -public: - Bbox_2_Line_2_pair_impl() {} - Bbox_2_Line_2_pair_impl(Bbox_2 const &bb, Rcart::Line_2 const &line) - : _bbox(bb), _line(line), _known(false) {} - Bbox_2 _bbox; - Rcart::Line_2 _line; - mutable bool _known; - mutable Bbox_2_Line_2_pair::Intersection_results _result; - mutable double _min, _max; -}; - -Bbox_2_Line_2_pair::~Bbox_2_Line_2_pair() -{ - delete pimpl; -} - -Bbox_2_Line_2_pair::Bbox_2_Line_2_pair() -{ - pimpl = new Bbox_2_Line_2_pair_impl; - pimpl->_known = false; -} - -Bbox_2_Line_2_pair::Bbox_2_Line_2_pair(Bbox_2_Line_2_pair const &o) -{ - pimpl = new Bbox_2_Line_2_pair_impl(*o.pimpl); -} - -Bbox_2_Line_2_pair::Bbox_2_Line_2_pair( - Bbox_2 const &bbox, double line_a, double line_b, double line_c) -{ - pimpl = new Bbox_2_Line_2_pair_impl(bbox, - Rcart::Line_2(line_a, line_b, line_c)); -} - -Bbox_2_Line_2_pair & -Bbox_2_Line_2_pair::operator=(Bbox_2_Line_2_pair const &o) -{ - *pimpl = *o.pimpl; - return *this; -} - - -Bbox_2_Line_2_pair::Intersection_results -Bbox_2_Line_2_pair::intersection_type() const -{ - if (pimpl->_known) - return pimpl->_result; - // The non const this pointer is used to cast away const. - pimpl->_known = true; - const Rcart::Point_2 &ref_point = pimpl->_line.point(); - const Rcart::Vector_2 &dir = - pimpl->_line.direction().to_vector(); - bool to_infinity = true; -// first on x value - if (dir.x() == 0.0) { - if (ref_point.x() < pimpl->_bbox.xmin()) { - pimpl->_result = NO_INTERSECTION; - return pimpl->_result; - } - if (ref_point.x() > pimpl->_bbox.xmax()) { - pimpl->_result = NO_INTERSECTION; - return pimpl->_result; - } - } else { - double newmin, newmax; - if (dir.x() > 0.0) { - newmin = (pimpl->_bbox.xmin()-ref_point.x())/dir.x(); - newmax = (pimpl->_bbox.xmax()-ref_point.x())/dir.x(); - } else { - newmin = (pimpl->_bbox.xmax()-ref_point.x())/dir.x(); - newmax = (pimpl->_bbox.xmin()-ref_point.x())/dir.x(); - } - if (to_infinity) { - pimpl->_min = newmin; - pimpl->_max = newmax; - } else { - if (newmin > pimpl->_min) - pimpl->_min = newmin; - if (newmax < pimpl->_max) - pimpl->_max = newmax; - if (pimpl->_max < pimpl->_min) { - pimpl->_result = NO_INTERSECTION; - return pimpl->_result; - } - } - to_infinity = false; - } -// now on y value - if (dir.y() == 0.0) { - if (ref_point.y() < pimpl->_bbox.ymin()) { - pimpl->_result = NO_INTERSECTION; - return pimpl->_result; - } - if (ref_point.y() > pimpl->_bbox.ymax()) { - pimpl->_result = NO_INTERSECTION; - return pimpl->_result; - } - } else { - double newmin, newmax; - if (dir.y() > 0.0) { - newmin = (pimpl->_bbox.ymin()-ref_point.y())/dir.y(); - newmax = (pimpl->_bbox.ymax()-ref_point.y())/dir.y(); - } else { - newmin = (pimpl->_bbox.ymax()-ref_point.y())/dir.y(); - newmax = (pimpl->_bbox.ymin()-ref_point.y())/dir.y(); - } - if (to_infinity) { - pimpl->_min = newmin; - pimpl->_max = newmax; - } else { - if (newmin > pimpl->_min) - pimpl->_min = newmin; - if (newmax < pimpl->_max) - pimpl->_max = newmax; - if (pimpl->_max < pimpl->_min) { - pimpl->_result = NO_INTERSECTION; - return pimpl->_result; - } - } - to_infinity = false; - } - CGAL_kernel_assertion(!to_infinity); - if (pimpl->_max == pimpl->_min) { - pimpl->_result = POINT; - return pimpl->_result; - } - pimpl->_result = SEGMENT; - return pimpl->_result; -} - - -bool -Bbox_2_Line_2_pair::intersection( - double &x1, double &y1, double &x2, double &y2) const -{ - if (!pimpl->_known) - intersection_type(); - if (pimpl->_result != SEGMENT) - return false; - Rcart::Point_2 p1(pimpl->_line.point() - + pimpl->_min*pimpl->_line.direction().to_vector()); - Rcart::Point_2 p2(pimpl->_line.point() - + pimpl->_max*pimpl->_line.direction().to_vector()); - x1 = p1.x(); - y1 = p1.y(); - x2 = p2.x(); - y2 = p2.y(); - return true; -} - -bool -Bbox_2_Line_2_pair::intersection( - double &x, double &y) const -{ - if (!pimpl->_known) - intersection_type(); - if (pimpl->_result != POINT) - return false; - Rcart::Point_2 pt(pimpl->_line.point() - + pimpl->_min*pimpl->_line.direction().to_vector()); - x = pt.x(); - y = pt.y(); - return true; -} - - -class Bbox_2_Ray_2_pair_impl -{ -public: - Bbox_2_Ray_2_pair_impl():_known(false) {} - Bbox_2_Ray_2_pair_impl(Bbox_2 const &bbox, Rcart::Point_2 const &pt, - Rcart::Vector_2 const &dir) - :_box(bbox), _known(false), _ref_point(pt), _dir(dir), _min(0.0) {} - Ray_2< Rcart > _ray; - Bbox_2 _box; - bool _known; - Bbox_2_Ray_2_pair::Intersection_results _result; - Rcart::Point_2 _ref_point; - Rcart::Vector_2 _dir; - double _min, _max; -}; - -Bbox_2_Ray_2_pair::~Bbox_2_Ray_2_pair() -{ - delete pimpl; -} - -Bbox_2_Ray_2_pair::Bbox_2_Ray_2_pair() -{ - pimpl = new Bbox_2_Ray_2_pair_impl; -} - -Bbox_2_Ray_2_pair::Bbox_2_Ray_2_pair(Bbox_2_Ray_2_pair const &o) -{ - pimpl = new Bbox_2_Ray_2_pair_impl(*o.pimpl); -} - -Bbox_2_Ray_2_pair::Bbox_2_Ray_2_pair( - Bbox_2 const &bbox, double x, double y, double dx, double dy) -{ - pimpl = new Bbox_2_Ray_2_pair_impl(bbox, - Rcart::Point_2(x,y), Rcart::Vector_2(dx,dy)); -} - -Bbox_2_Ray_2_pair & -Bbox_2_Ray_2_pair::operator=(Bbox_2_Ray_2_pair const &o) -{ - *pimpl = *o.pimpl; - return *this; -} - - -Bbox_2_Ray_2_pair::Intersection_results -Bbox_2_Ray_2_pair::intersection_type() const -{ - if (pimpl->_known) - return pimpl->_result; - pimpl->_known = true; - bool to_infinity = true; -// first on x value - if (pimpl->_dir.x() == 0.0) { - if (pimpl->_ref_point.x() < pimpl->_box.xmin()) { - pimpl->_result = NO_INTERSECTION; - return pimpl->_result; - } - if (pimpl->_ref_point.x() > pimpl->_box.xmax()) { - pimpl->_result = NO_INTERSECTION; - return pimpl->_result; - } - } else { - double newmin, newmax; - if (pimpl->_dir.x() > 0.0) { - newmin =(pimpl->_box.xmin()-pimpl->_ref_point.x())/pimpl->_dir.x(); - newmax =(pimpl->_box.xmax()-pimpl->_ref_point.x())/pimpl->_dir.x(); - } else { - newmin =(pimpl->_box.xmax()-pimpl->_ref_point.x())/pimpl->_dir.x(); - newmax =(pimpl->_box.xmin()-pimpl->_ref_point.x())/pimpl->_dir.x(); - } - if (newmin > pimpl->_min) - pimpl->_min = newmin; - if (to_infinity) { - pimpl->_max = newmax; - } else { - if (newmax < pimpl->_max) - pimpl->_max = newmax; - } - if (pimpl->_max < pimpl->_min){ - pimpl->_result = NO_INTERSECTION; - return pimpl->_result; - } - to_infinity = false; - } -// now on y value - if (pimpl->_dir.y() == 0.0) { - if (pimpl->_ref_point.y() < pimpl->_box.ymin()) { - pimpl->_result = NO_INTERSECTION; - return pimpl->_result; - } - if (pimpl->_ref_point.y() > pimpl->_box.ymax()) { - pimpl->_result = NO_INTERSECTION; - return pimpl->_result; - } - } else { - double newmin, newmax; - if (pimpl->_dir.y() > 0.0) { - newmin =(pimpl->_box.ymin()-pimpl->_ref_point.y())/pimpl->_dir.y(); - newmax =(pimpl->_box.ymax()-pimpl->_ref_point.y())/pimpl->_dir.y(); - } else { - newmin =(pimpl->_box.ymax()-pimpl->_ref_point.y())/pimpl->_dir.y(); - newmax =(pimpl->_box.ymin()-pimpl->_ref_point.y())/pimpl->_dir.y(); - } - if (newmin > pimpl->_min) - pimpl->_min = newmin; - if (to_infinity) { - pimpl->_max = newmax; - } else { - if (newmax < pimpl->_max) - pimpl->_max = newmax; - } - if (pimpl->_max < pimpl->_min) { - pimpl->_result = NO_INTERSECTION; - return pimpl->_result; - } - to_infinity = false; - } - CGAL_kernel_assertion(!to_infinity); - if (pimpl->_max == pimpl->_min) { - pimpl->_result = POINT; - return pimpl->_result; - } - pimpl->_result = SEGMENT; - return pimpl->_result; -} - - -bool Bbox_2_Ray_2_pair:: -intersection(double &x1, double &y1, double &x2, double &y2) const -{ - if (!pimpl->_known) - intersection_type(); - if (pimpl->_result != SEGMENT) - return false; - Rcart::Point_2 p1(pimpl->_ref_point + pimpl->_min*pimpl->_dir); - Rcart::Point_2 p2(pimpl->_ref_point + pimpl->_max*pimpl->_dir); - x1 = p1.x(); - y1 = p1.y(); - x2 = p2.x(); - y2 = p2.y(); - return true; -} - -bool Bbox_2_Ray_2_pair::intersection(double &x, double &y) const -{ - if (!pimpl->_known) - intersection_type(); - if (pimpl->_result != POINT) - return false; - Rcart::Point_2 pt = pimpl->_ref_point + pimpl->_min*pimpl->_dir; - x = pt.x(); - y = pt.y(); - return true; -} - - -bool do_intersect_ray_2( - const Bbox_2 &box, double x, double y, double dx, double dy) -{ - Bbox_2_Ray_2_pair pair(box, x, y, dx, dy); - return pair.intersection_type() != Bbox_2_Ray_2_pair::NO_INTERSECTION; -} - -} //namespace CGAL +#include +#include diff --git a/Kernel_23/include/CGAL/Origin.h b/Kernel_23/include/CGAL/Origin.h index 70b3f949531..39a1c123464 100644 --- a/Kernel_23/include/CGAL/Origin.h +++ b/Kernel_23/include/CGAL/Origin.h @@ -42,4 +42,8 @@ CGAL_EXPORT extern const Null_vector NULL_VECTOR; } //namespace CGAL +#ifdef CGAL_HEADER_ONLY +#include +#endif // CGAL_HEADER_ONLY + #endif // CGAL_ORIGIN_H diff --git a/Kernel_23/include/CGAL/Origin_impl.h b/Kernel_23/include/CGAL/Origin_impl.h new file mode 100644 index 00000000000..c9b89e40877 --- /dev/null +++ b/Kernel_23/include/CGAL/Origin_impl.h @@ -0,0 +1,32 @@ +// Copyright (c) 1999 +// 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$ +// +// +// Author(s) : Andreas Fabri, Stefan Schirra + +#include + +namespace CGAL { + +const Origin ORIGIN = Origin(); +const Null_vector NULL_VECTOR = Null_vector(); + +} //namespace CGAL diff --git a/Kernel_23/include/CGAL/aff_transformation_tags.h b/Kernel_23/include/CGAL/aff_transformation_tags.h index f950814c9b3..f94bfa5f0f3 100644 --- a/Kernel_23/include/CGAL/aff_transformation_tags.h +++ b/Kernel_23/include/CGAL/aff_transformation_tags.h @@ -36,12 +36,16 @@ class Scaling {}; class Reflection {}; class Identity_transformation {}; -CGAL_EXPORT extern Translation TRANSLATION; -CGAL_EXPORT extern Rotation ROTATION; -CGAL_EXPORT extern Scaling SCALING; -CGAL_EXPORT extern Reflection REFLECTION; -CGAL_EXPORT extern Identity_transformation IDENTITY; +CGAL_EXPORT extern const Translation TRANSLATION; +CGAL_EXPORT extern const Rotation ROTATION; +CGAL_EXPORT extern const Scaling SCALING; +CGAL_EXPORT extern const Reflection REFLECTION; +CGAL_EXPORT extern const Identity_transformation IDENTITY; } //namespace CGAL +#ifdef CGAL_HEADER_ONLY +#include +#endif // CGAL_HEADER_ONLY + #endif // CGAL_AFF_TRANSFORMATION_TAGS_H diff --git a/Kernel_23/include/CGAL/aff_transformation_tags_impl.h b/Kernel_23/include/CGAL/aff_transformation_tags_impl.h new file mode 100644 index 00000000000..13919e563b8 --- /dev/null +++ b/Kernel_23/include/CGAL/aff_transformation_tags_impl.h @@ -0,0 +1,35 @@ +// Copyright (c) 1999 +// 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$ +// +// +// Author(s) : Andreas Fabri, Stefan Schirra + +#include + +namespace CGAL { + +const Translation TRANSLATION; +const Rotation ROTATION; +const Scaling SCALING; +const Reflection REFLECTION; +const Identity_transformation IDENTITY; + +} //namespace CGAL diff --git a/Kernel_23/src/CGAL/kernel.cpp b/Kernel_23/src/CGAL/kernel.cpp index 8e4ec40822f..3fb9a710ad9 100644 --- a/Kernel_23/src/CGAL/kernel.cpp +++ b/Kernel_23/src/CGAL/kernel.cpp @@ -22,18 +22,5 @@ // // Author(s) : Andreas Fabri, Stefan Schirra -#include -#include - -namespace CGAL { - -Translation TRANSLATION; -Rotation ROTATION; -Scaling SCALING; -Reflection REFLECTION; -Identity_transformation IDENTITY; - -const Origin ORIGIN = Origin(); -const Null_vector NULL_VECTOR = Null_vector(); - -} //namespace CGAL +#include +#include diff --git a/STL_Extension/include/CGAL/assertions.h b/STL_Extension/include/CGAL/assertions.h index 63144c96a3d..c9dd318cf71 100644 --- a/STL_Extension/include/CGAL/assertions.h +++ b/STL_Extension/include/CGAL/assertions.h @@ -343,4 +343,8 @@ inline bool possibly(Uncertain c); // But the macros need CGAL::possibly(). #include +#ifdef CGAL_HEADER_ONLY +#include +#endif // CGAL_HEADER_ONLY + #endif // CGAL_ASSERTIONS_H diff --git a/STL_Extension/src/CGAL/assertions.cpp b/STL_Extension/src/CGAL/assertions.cpp index 44e187df0a6..9491e18dc72 100644 --- a/STL_Extension/src/CGAL/assertions.cpp +++ b/STL_Extension/src/CGAL/assertions.cpp @@ -22,201 +22,5 @@ // // Author(s) : Geert-Jan Giezeman and Sven Schönherr -#include #include -#include -#include - -#include -#include - -namespace CGAL { - -namespace { - -// behaviour variables -// ------------------- - -Failure_behaviour _error_behaviour = THROW_EXCEPTION; -Failure_behaviour _warning_behaviour = CONTINUE; - -// standard error handlers -// ----------------------- -void -_standard_error_handler( - const char* what, - const char* expr, - const char* file, - int line, - const char* msg ) -{ -#if defined(__GNUG__) && !defined(__llvm__) - // After g++ 3.4, std::terminate defaults to printing to std::cerr itself. - if (_error_behaviour == THROW_EXCEPTION) - return; -#endif - std::cerr << "CGAL error: " << what << " violation!" << std::endl - << "Expression : " << expr << std::endl - << "File : " << file << std::endl - << "Line : " << line << std::endl - << "Explanation: " << msg << std::endl - << "Refer to the bug-reporting instructions at http://www.cgal.org/bug_report.html" - << std::endl; -} - - -// standard warning handler -// ------------------------ -void -_standard_warning_handler( const char *, - const char* expr, - const char* file, - int line, - const char* msg ) -{ -#if defined(__GNUG__) && !defined(__llvm__) - // After g++ 3.4, std::terminate defaults to printing to std::cerr itself. - if (_warning_behaviour == THROW_EXCEPTION) - return; -#endif - std::cerr << "CGAL warning: check violation!" << std::endl - << "Expression : " << expr << std::endl - << "File : " << file << std::endl - << "Line : " << line << std::endl - << "Explanation: " << msg << std::endl - << "Refer to the bug-reporting instructions at http://www.cgal.org/bug_report.html" - << std::endl; -} - -// default handler settings -// ------------------------ -Failure_function _error_handler = _standard_error_handler; -Failure_function _warning_handler = _standard_warning_handler; - -} // anonymous namespace - -// failure functions -// ----------------- -void -assertion_fail( const char* expr, - const char* file, - int line, - const char* msg) -{ - _error_handler("assertion", expr, file, line, msg); - switch (_error_behaviour) { - case ABORT: - std::abort(); - case EXIT: - std::exit(1); // EXIT_FAILURE - case EXIT_WITH_SUCCESS: - std::exit(0); // EXIT_SUCCESS - case CONTINUE: // The CONTINUE case should not be used anymore. - case THROW_EXCEPTION: - default: - throw Assertion_exception("CGAL", expr, file, line, msg); - } -} - -void -precondition_fail( const char* expr, - const char* file, - int line, - const char* msg) -{ - _error_handler("precondition", expr, file, line, msg); - switch (_error_behaviour) { - case ABORT: - std::abort(); - case EXIT: - std::exit(1); // EXIT_FAILURE - case EXIT_WITH_SUCCESS: - std::exit(0); // EXIT_SUCCESS - case CONTINUE: - case THROW_EXCEPTION: - default: - throw Precondition_exception("CGAL", expr, file, line, msg); - } -} - -void -postcondition_fail(const char* expr, - const char* file, - int line, - const char* msg) -{ - _error_handler("postcondition", expr, file, line, msg); - switch (_error_behaviour) { - case ABORT: - std::abort(); - case EXIT: - std::exit(1); // EXIT_FAILURE - case EXIT_WITH_SUCCESS: - std::exit(0); // EXIT_SUCCESS - case CONTINUE: - case THROW_EXCEPTION: - default: - throw Postcondition_exception("CGAL", expr, file, line, msg); - } -} - - -// warning function -// ---------------- -void -warning_fail( const char* expr, - const char* file, - int line, - const char* msg) -{ - _warning_handler("warning", expr, file, line, msg); - switch (_warning_behaviour) { - case ABORT: - std::abort(); - case EXIT: - std::exit(1); // EXIT_FAILURE - case EXIT_WITH_SUCCESS: - std::exit(0); // EXIT_SUCCESS - case THROW_EXCEPTION: - throw Warning_exception("CGAL", expr, file, line, msg); - case CONTINUE: - ; - } -} - - -// error handler set functions -// --------------------------- -Failure_function -set_error_handler( Failure_function handler) -{ - Failure_function result = _error_handler; - _error_handler = handler; - return result; -} - -Failure_function -set_warning_handler( Failure_function handler) -{ - Failure_function result = _warning_handler; - _warning_handler = handler; - return result; -} - -Failure_behaviour -set_error_behaviour(Failure_behaviour eb) -{ - Failure_behaviour result = _error_behaviour; - _error_behaviour = eb; - return result; -} - -Failure_behaviour -set_warning_behaviour(Failure_behaviour eb) -{ - Failure_behaviour result = _warning_behaviour; - _warning_behaviour = eb; - return result; -} - -} //namespace CGAL +#include diff --git a/Stream_support/include/CGAL/IO/Color.h b/Stream_support/include/CGAL/IO/Color.h index 9a8e02bcf15..ca4a4af376c 100644 --- a/Stream_support/include/CGAL/IO/Color.h +++ b/Stream_support/include/CGAL/IO/Color.h @@ -95,4 +95,8 @@ CGAL_EXPORT extern const Color YELLOW ; } //namespace CGAL +#ifdef CGAL_HEADER_ONLY +#include +#endif // CGAL_HEADER_ONLY + #endif // CGAL_COLOR_H diff --git a/Stream_support/include/CGAL/IO/Color_impl.h b/Stream_support/include/CGAL/IO/Color_impl.h new file mode 100644 index 00000000000..a2c023ebe8d --- /dev/null +++ b/Stream_support/include/CGAL/IO/Color_impl.h @@ -0,0 +1,23 @@ +// Copyright (c) 1997 +// 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$ +// +// +// Author(s) : Andreas Fabri, Hervé Brönnimann diff --git a/Stream_support/include/CGAL/IO/File_header_OFF.h b/Stream_support/include/CGAL/IO/File_header_OFF.h index 726e3aa3b9a..15a56771390 100644 --- a/Stream_support/include/CGAL/IO/File_header_OFF.h +++ b/Stream_support/include/CGAL/IO/File_header_OFF.h @@ -116,5 +116,10 @@ CGAL_EXPORT std::ostream& operator<<( std::ostream& out, const File_header_OFF& CGAL_EXPORT std::istream& operator>>( std::istream& in, File_header_OFF& h); } //namespace CGAL + +#ifdef CGAL_HEADER_ONLY +#include +#endif // CGAL_HEADER_ONLY + #endif // CGAL_IO_FILE_HEADER_OFF_H // // EOF // diff --git a/Stream_support/include/CGAL/IO/File_header_OFF_impl.h b/Stream_support/include/CGAL/IO/File_header_OFF_impl.h new file mode 100644 index 00000000000..9ac3e1fc83d --- /dev/null +++ b/Stream_support/include/CGAL/IO/File_header_OFF_impl.h @@ -0,0 +1,409 @@ +// Copyright (c) 1997 +// 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$ +// +// +// Author(s) : Lutz Kettner + +#ifdef CGAL_HEADER_ONLY +#define CGAL_INLINE_FUNCTION inline +#else +#define CGAL_INLINE_FUNCTION +#endif + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace CGAL { + +CGAL_INLINE_FUNCTION +File_header_OFF::File_header_OFF( bool verbose) +: File_header_extended_OFF( verbose), + n_vertices(0), + n_facets(0), + m_skel(false), + m_binary(false), + m_no_comments(false), + m_offset(0), + m_colors(false), + m_normals(false), + m_tag4(false), + m_tagDim(false), + m_dim(3) +{} +CGAL_INLINE_FUNCTION +File_header_OFF::File_header_OFF( + bool binary, bool noc, bool skel, bool verbose) +: File_header_extended_OFF( verbose), + n_vertices(0), + n_facets(0), + m_skel(skel), + m_binary(binary), + m_no_comments(noc), + m_offset(0), + m_colors(false), + m_normals(false), + m_tag4(false), + m_tagDim(false), + m_dim(3) +{} +//CGAL_INLINE_FUNCTION +//File_header_OFF::File_header_OFF( int v, int h, int f, +// bool verbose) +//: File_header_extended_OFF( verbose), +// n_vertices(v), +// n_facets(f), +// m_skel(false), +// m_binary(false), +// m_no_comments(false), +// m_offset(0), +// m_colors(false), +// m_normals(false), +// m_tag4(false), +// m_tagDim(false), +// m_dim(3) +//{ +// set_halfedges(h); +//} +CGAL_INLINE_FUNCTION +File_header_OFF::File_header_OFF( std::size_t v, std::size_t h, std::size_t f, + bool binary, bool noc, bool skel, bool verbose) +: File_header_extended_OFF( verbose), + n_vertices(v), + n_facets(f), + m_skel(skel), + m_binary(binary), + m_no_comments(noc), + m_offset(0), + m_colors(false), + m_normals(false), + m_tag4(false), + m_tagDim(false), + m_dim(3) +{ + set_halfedges(h); +} +CGAL_INLINE_FUNCTION +File_header_OFF::File_header_OFF( + const File_header_extended_OFF& ext_header) +: File_header_extended_OFF( ext_header), + n_vertices(0), + n_facets(0), + m_skel(false), + m_binary(false), + m_no_comments(false), + m_offset(0), + m_colors(false), + m_normals(false), + m_tag4(false), + m_tagDim(false), + m_dim(3) +{} +CGAL_INLINE_FUNCTION +File_header_OFF::File_header_OFF( + const File_header_extended_OFF& ext_header, + bool binary, bool noc, bool skel) +: File_header_extended_OFF( ext_header), + n_vertices(0), + n_facets(0), + m_skel(skel), + m_binary(binary), + m_no_comments(noc), + m_offset(0), + m_colors(false), + m_normals(false), + m_tag4(false), + m_tagDim(false), + m_dim(3) +{} +CGAL_INLINE_FUNCTION +File_header_OFF::File_header_OFF( + std::size_t v, std::size_t h, std::size_t f, + const File_header_extended_OFF& ext_header) +: File_header_extended_OFF( ext_header), + n_vertices(v), + n_facets(f), + m_skel(false), + m_binary(false), + m_no_comments(false), + m_offset(0), + m_colors(false), + m_normals(false), + m_tag4(false), + m_tagDim(false), + m_dim(3) +{ + set_halfedges(h); +} +CGAL_INLINE_FUNCTION +File_header_OFF::File_header_OFF( + std::size_t v, std::size_t h, std::size_t f, + const File_header_extended_OFF& ext_header, + bool binary, bool noc, bool skel) +: File_header_extended_OFF( ext_header), + n_vertices(v), + n_facets(f), + m_skel(skel), + m_binary(binary), + m_no_comments(noc), + m_offset(0), + m_colors(false), + m_normals(false), + m_tag4(false), + m_tagDim(false), + m_dim(3) +{ + set_halfedges(h); +} + +CGAL_INLINE_FUNCTION +File_header_OFF& File_header_OFF:: +operator+=( const File_header_OFF& header) { + (File_header_extended_OFF&)(*this) = header; + n_vertices += header.n_vertices; + n_facets += header.n_facets; + return *this; +} + +// Write header. +CGAL_INLINE_FUNCTION +std::ostream& operator<<( std::ostream& out, const File_header_OFF& h) { + if ( h.comments()) { + out << "# Output of a CGAL tool\n"; + out << static_cast( h); + } + if ( h.has_normals()) + out << 'N'; + if ( h.skel()) + out << "SKEL"; + else + out << "OFF"; + if ( h.binary()) { + out << " BINARY\n"; + I_Binary_write_big_endian_integer32( out, static_cast(h.size_of_vertices())); + I_Binary_write_big_endian_integer32( out, static_cast(h.size_of_facets())); + if ( h.off()) + I_Binary_write_big_endian_integer32( out, 0); + } else { + out << '\n'; + out << h.size_of_vertices() << ' '<< h.size_of_facets(); + if ( h.off()) + out << " 0"; + if ( h.comments()) { + out << "\n\n# " << h.size_of_vertices() << " vertices\n"; + out << "# ------------------------------------------\n"; + } + out << std::endl; + } + return out; +} + +// Scan header. Marks streams badbit if not in SKEL format nor in OFF. +CGAL_INLINE_FUNCTION +std::istream& operator>>( std::istream& in, File_header_OFF& h) { + // read in the first character and scan for comments, `OFF', or `NOFF', + // or `SKEL', or `4SKEL'. + h.set_off_header( false); + char c; + while ( (in >> c) && c == '#') { + if ( in.get(c) && c == 'C' && + in.get(c) && c == 'B' && + in.get(c) && c == 'P') { + in >> static_cast( h); + } else if ( c != '\n') + in >> skip_until_EOL; + } + if ( ! in) + return in; + h.set_skel( false); + h.set_binary( false); + h.set_index_offset( 1); + h.set_colors( false); + h.set_normals( false); + h.set_homogeneous( false); + h.set_dimensional( false); + h.set_dimension( 3); + + const int max_keyword = 42; + char keyword[max_keyword] = ""; + int i = 0; + keyword[i++] = c; + while( i < max_keyword - 1 && in.get(c) && std::isalnum(c)) + keyword[i++] = c; + keyword[i] = '\0'; + if ( i < 2 || (std::isdigit(keyword[0]) && keyword[0] != '4') + || std::isdigit(keyword[1])) { + h.set_vertices( std::atoi( keyword)); + } else { + h.set_index_offset( 0); + int j = 0; + if ( j < i && keyword[j] == 'C') { + h.set_colors( true); + j++; + } + if ( j < i && keyword[j] == 'N') { + h.set_normals( true); + j++; + } + if ( j < i && keyword[j] == '4') { + h.set_homogeneous( true); + j++; + } + if ( j < i && keyword[j] == 'n') { + h.set_dimensional( true); + j++; + } + if ( i-j != 3 || keyword[j] != 'O' + || keyword[j+1] != 'F' + || keyword[j+2] != 'F') { + if ( i-j != 4 || keyword[j] != 'S' + || keyword[j+1] != 'K' + || keyword[j+2] != 'E' + || keyword[j+3] != 'L') { + in.clear( std::ios::badbit); + if ( h.verbose()) { + std::cerr << " " << std::endl; + std::cerr << "error: File_header_OFF: " + "wrong format: neither OFF nor SKEL." + << std::endl; + } + return in; + } else { + h.set_skel( true); + } + } + in >> skip_comment_OFF >> c; + if ( std::isdigit(c)) { + in.putback(c); + int n; + in >> n; + h.set_vertices(n); + } else { + i = 0; + keyword[i++] = c; + while( i < max_keyword - 1 && in.get(c) && + std::isalnum(c)) + keyword[i++] = c; + keyword[i] = '\0'; + if ( std::strcmp( keyword, "BINARY") == 0) { + h.set_binary( true); + if ( c != '\n') + in >> skip_until_EOL; + } else { + in.clear( std::ios::badbit); + if ( h.verbose()) { + std::cerr << " " << std::endl; + std::cerr << "error: File_header_OFF(): " + "wrong format: neither OFF nor SKEL." + << std::endl; + } + return in; + } + } + } + // Read remaining size value(s). + int n_h; + if ( h.binary()) { + boost::int32_t a, b, c; + I_Binary_read_big_endian_integer32( in, a); + if ( h.n_dimensional()) { + h.set_dimension( a); + I_Binary_read_big_endian_integer32( in, a); + } + I_Binary_read_big_endian_integer32( in, b); + if ( h.off()) + I_Binary_read_big_endian_integer32( in, c); + else + c = 0; + h.set_vertices( a); + if (b<0){ + in.clear( std::ios::badbit ); + if ( h.verbose()) { + std::cerr << " " << std::endl; + std::cerr << "error: File_header_OFF(): File contains < 0 facets." + << std::endl; + } + return in; + } + h.set_facets( b); + n_h = c; + } else { + int n; + if ( h.n_dimensional()) { + h.set_dimension( static_cast(h.size_of_vertices())); + in >> n; + h.set_vertices(n); + } + in >> n; + if (n < 0){ + in.clear( std::ios::badbit ); + if ( h.verbose()) { + std::cerr << " " << std::endl; + std::cerr << "error: File_header_OFF(): File contains < 0 facets." + << std::endl; + } + return in; + } + h.set_facets(n); + if ( h.off()) + in >> n_h; + else + n_h = 0; + } + if ( n_h == 0) + h.set_index_offset( 0); + if ( ! in || h.size_of_vertices() <= 0 ) { + in.clear( std::ios::badbit); + if ( h.verbose()) { + std::cerr << " " << std::endl; + std::cerr << "error: File_header_OFF(): File contains <= 0 vertices." + << std::endl; + } + return in; + } + if ( h.size_of_halfedges() == 0) { + // be careful, because border edges count twice + h.set_halfedges( 2 * n_h); + // check against the Eulerian equation for connected planar graphs. + // We do not know the number of holes we must represent as dummy + // facets and we do not know the genus of the surface. + // So we add 12 and a factor of 5 percent. + if ( h.size_of_halfedges() == 0 + || h.size_of_halfedges() > (h.size_of_vertices() + + h.size_of_facets() - 2 + 12) * 2.1 + || h.size_of_halfedges() < (h.size_of_vertices() + + h.size_of_facets() - 2) * 2 + ) + h.set_halfedges( int((h.size_of_vertices() + + h.size_of_facets() - 2 + 12) * 2.1)); + } + h.set_off_header( h.off()); + return in; +} + +} //namespace CGAL +// EOF // diff --git a/Stream_support/include/CGAL/IO/File_header_extended_OFF.h b/Stream_support/include/CGAL/IO/File_header_extended_OFF.h index 75679a488b2..8317be5b3bd 100644 --- a/Stream_support/include/CGAL/IO/File_header_extended_OFF.h +++ b/Stream_support/include/CGAL/IO/File_header_extended_OFF.h @@ -124,5 +124,10 @@ inline std::istream& skip_comment_OFF( std::istream& in) { } } //namespace CGAL + +#ifdef CGAL_HEADER_ONLY +#include +#endif // CGAL_HEADER_ONLY + #endif // CGAL_IO_FILE_HEADER_EXTENDED_OFF_H // // EOF // diff --git a/Stream_support/include/CGAL/IO/File_header_extended_OFF_impl.h b/Stream_support/include/CGAL/IO/File_header_extended_OFF_impl.h new file mode 100644 index 00000000000..0fad299f811 --- /dev/null +++ b/Stream_support/include/CGAL/IO/File_header_extended_OFF_impl.h @@ -0,0 +1,212 @@ +// Copyright (c) 1997 +// 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$ +// +// +// Author(s) : Lutz Kettner + +#ifdef CGAL_HEADER_ONLY +#define CGAL_INLINE_FUNCTION inline +#else +#define CGAL_INLINE_FUNCTION +#endif + +#include +#include + +#include +#include +#include +#include +#include +#include + + +namespace CGAL { + +CGAL_INLINE_FUNCTION +bool File_header_extended_OFF:: +is_POL() const { + return is_OFF() && polyhedral_surface(); +} + +CGAL_INLINE_FUNCTION +bool File_header_extended_OFF:: +is_CBP() const { + return is_POL() && triangulated() && non_empty_facets() && + normalized_to_sphere() && radius() <= 1.0; +} + +CGAL_INLINE_FUNCTION +bool File_header_extended_OFF:: +is_TRN() const { return is_CBP() && terrain(); } + +CGAL_INLINE_FUNCTION +int File_header_extended_OFF:: +is_CBPn() const { + if ( is_POL() && triangulated() && non_empty_facets() && + normalized_to_sphere() && rounded() && + (radius() <= ( 1l << rounded_bits()))) + return rounded_bits(); + else + return 0; +} + +CGAL_INLINE_FUNCTION +int File_header_extended_OFF:: +is_TRNn() const { return ( terrain() ? is_CBPn() : 0); } + + +// The proper file suffix with respect to file format. +CGAL_INLINE_FUNCTION +std::string File_header_extended_OFF:: +suffix() const { + if ( is_TRNn()) { + std::ostringstream out; + out << "trn" << m_rounded_bits << '\0'; + return out.str(); + } + if ( is_TRN()) + return std::string("trn"); + if ( is_CBPn()) { + std::ostringstream out; + out << "cbp" << m_rounded_bits << '\0'; + return out.str(); + } + if ( is_CBP()) + return std::string("cbp"); + if ( is_POL()) + return std::string("pol"); + return std::string("off"); +} + +// The proper format name. +CGAL_INLINE_FUNCTION +std::string File_header_extended_OFF:: +format_name() const { + if ( is_TRNn()) { + std::ostringstream out; + out << "TRN" << m_rounded_bits << '\0'; + return out.str(); + } + if ( is_TRN()) + return std::string("TRN"); + if ( is_CBPn()) { + std::ostringstream out; + out << "CBP" << m_rounded_bits << '\0'; + return out.str(); + } + if ( is_CBP()) + return std::string("CBP"); + if ( is_POL()) + return std::string("POL"); + return std::string("OFF"); +} + +CGAL_INLINE_FUNCTION +File_header_extended_OFF& File_header_extended_OFF:: +operator+=( const File_header_extended_OFF& header) { + m_verbose = m_verbose || header.m_verbose; + m_polyhedral_surface = m_polyhedral_surface && + header.m_polyhedral_surface; + m_halfedges += header.m_halfedges; + m_triangulated = m_triangulated && header.m_triangulated; + m_non_empty_facets = m_non_empty_facets && + header.m_non_empty_facets; + m_terrain = m_terrain && header.m_terrain; + m_normalized_to_sphere = m_normalized_to_sphere && + header.m_normalized_to_sphere; + m_radius = (std::max)(m_radius, header.m_radius); + m_rounded = m_rounded && header.m_rounded; + m_rounded_bits = (std::max)( m_rounded_bits, + header.m_rounded_bits); + m_off_header = m_off_header && header.m_off_header; + return *this; +} + +#define CGAL_OUT(item) out << "# " #item " " << h.item() << '\n' +#define CGAL_OUTBOOL(item) out << "# " #item " " <<(h.item() ? '1':'0') << '\n' + +// Write extended header incl. CGAL/ENDCBP keywords. +CGAL_INLINE_FUNCTION +std::ostream& operator<<( std::ostream& out, + const File_header_extended_OFF& h) { + out << "#CBP\n"; + CGAL_OUTBOOL( polyhedral_surface); + CGAL_OUT( halfedges); + CGAL_OUTBOOL( triangulated); + CGAL_OUTBOOL( non_empty_facets); + CGAL_OUTBOOL( terrain); + CGAL_OUTBOOL( normalized_to_sphere); + CGAL_OUT( radius); + CGAL_OUTBOOL( rounded); + CGAL_OUT( rounded_bits); + out << "# ENDCBP\n" << std::endl; + return out; +} +#undef CGAL_OUT +#undef OUTBOOL + +#define CGAL_IN(item,type) \ + else if ( std::strcmp( keyword, #item) == 0) { \ + type t; \ + in >> t; \ + h.set_##item( t); \ + } + +#define CGAL_INBOOL(item) \ + else if ( std::strcmp( keyword, #item) == 0) { \ + in >> c; \ + h.set_##item( c == '1'); \ + } + +// Scan extended header. The CBP keyword must be read already. +CGAL_INLINE_FUNCTION +std::istream& operator>>( std::istream& in, File_header_extended_OFF& h) { + const int max_keyword = 42; + char c; + char keyword[max_keyword] = ""; + in >> keyword; + while ( in && std::strcmp( keyword, "ENDCBP") != 0) { + if ( std::strcmp( keyword, "#") == 0) + ; + CGAL_INBOOL( polyhedral_surface) + CGAL_IN( halfedges, int) + CGAL_INBOOL( triangulated) + CGAL_INBOOL( non_empty_facets) + CGAL_INBOOL( terrain) + CGAL_INBOOL( normalized_to_sphere) + CGAL_IN( radius, double) + CGAL_INBOOL( rounded) + CGAL_IN( rounded_bits, int) + else if ( h.verbose()) { + std::cerr << "warning: File_header_extended_OFF: unknown key '" + << keyword << "'." << std::endl; + } + in >> keyword; + } + in >> skip_until_EOL >> skip_comment_OFF; + return in; +} +#undef CGAL_IN +#undef CGAL_INBOOL + +} //namespace CGAL +// EOF // diff --git a/Stream_support/include/CGAL/IO/File_scanner_OFF.h b/Stream_support/include/CGAL/IO/File_scanner_OFF.h index 9ab83d5747c..2ca437c01d6 100644 --- a/Stream_support/include/CGAL/IO/File_scanner_OFF.h +++ b/Stream_support/include/CGAL/IO/File_scanner_OFF.h @@ -462,5 +462,9 @@ file_scan_normal( File_scanner_OFF& scanner, Vector& v) { } //namespace CGAL +#ifdef CGAL_HEADER_ONLY +#include +#endif // CGAL_HEADER_ONLY + #endif // CGAL_IO_FILE_SCANNER_OFF_H // // EOF // diff --git a/Stream_support/include/CGAL/IO/File_scanner_OFF_impl.h b/Stream_support/include/CGAL/IO/File_scanner_OFF_impl.h new file mode 100644 index 00000000000..36e2e8d393e --- /dev/null +++ b/Stream_support/include/CGAL/IO/File_scanner_OFF_impl.h @@ -0,0 +1,133 @@ +// Copyright (c) 1997 +// 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$ +// +// +// Author(s) : Lutz Kettner + +#ifdef CGAL_HEADER_ONLY +#define CGAL_INLINE_FUNCTION inline +#else +#define CGAL_INLINE_FUNCTION +#endif + +#include +#include +#include +#include +#include + +namespace CGAL { + +CGAL_INLINE_FUNCTION +void +File_scanner_OFF:: +skip_to_next_vertex( std::size_t current_vertex) { + CGAL_assertion( current_vertex < size_of_vertices()); + if ( binary()) { + float f; + if ( has_normals() && ! normals_read) { + I_Binary_read_big_endian_float32( m_in, f); + I_Binary_read_big_endian_float32( m_in, f); + I_Binary_read_big_endian_float32( m_in, f); + if ( is_homogeneous()) + I_Binary_read_big_endian_float32( m_in, f); + } + if ( has_colors()) { + // It is not well stated in the Geomview manual + // how color is coded following a vertex. It is + // parsed similar to the optional color for facets. + boost::int32_t k; + I_Binary_read_big_endian_integer32( m_in, k); + if (k<0 || k>4) { + m_in.clear( std::ios::badbit); + if ( verbose()) { + std::cerr << " " << std::endl; + std::cerr << "File_scanner_OFF::" << std::endl; + std::cerr << "skip_to_next_vertex(): input error: bad " + " number of color indices at vertex " + << current_vertex << "." << std::endl; + } + set_off_header( false); + return; + } + while (k--) { + float dummy; + I_Binary_read_big_endian_float32( m_in, dummy); + } + } + } else { + if ( has_normals() && ! normals_read) { + double dummy; + if ( is_homogeneous()) { + m_in >> dummy >> dummy >> dummy >> dummy; + } else { + m_in >> dummy >> dummy >> dummy; + } + } + if ( has_colors()) { // skip color entries (1 to 4) + m_in >> skip_until_EOL; + } + } + if( ! m_in) { + if ( verbose()) { + std::cerr << " " << std::endl; + std::cerr << "File_scanner_OFF::" << std::endl; + std::cerr << "skip_to_next_vertex(): input error: cannot read " + "OFF file beyond vertex " << current_vertex << "." + << std::endl; + } + set_off_header( false); + return; + } + normals_read = false; +} + +CGAL_INLINE_FUNCTION +void +File_scanner_OFF:: +skip_to_next_facet( std::size_t current_facet) { + // Take care of trailing informations like color triples. + if ( binary()) { + boost::int32_t k; + I_Binary_read_big_endian_integer32( m_in, k); + if (k<0 || k>4) { + m_in.clear( std::ios::badbit); + if ( verbose()) { + std::cerr << " " << std::endl; + std::cerr << "File_scanner_OFF::" << std::endl; + std::cerr << "skip_to_next_facet(): input error: bad " + "number of color indices at vertex " + << current_facet << "." << std::endl; + } + set_off_header( false); + return; + } + while (k--) { + float dummy; + I_Binary_read_big_endian_float32( m_in, dummy); + } + } else { + m_in >> skip_until_EOL; + } +} + +} //namespace CGAL +// EOF // diff --git a/Stream_support/include/CGAL/IO/File_writer_OFF.h b/Stream_support/include/CGAL/IO/File_writer_OFF.h index ae1d35b568f..12555671468 100644 --- a/Stream_support/include/CGAL/IO/File_writer_OFF.h +++ b/Stream_support/include/CGAL/IO/File_writer_OFF.h @@ -104,5 +104,10 @@ public: }; } //namespace CGAL + +#ifdef CGAL_HEADER_ONLY +#include +#endif // CGAL_HEADER_ONLY + #endif // CGAL_IO_FILE_WRITER_OFF_H // // EOF // diff --git a/Stream_support/include/CGAL/IO/File_writer_OFF_impl.h b/Stream_support/include/CGAL/IO/File_writer_OFF_impl.h new file mode 100644 index 00000000000..936e8d5b36b --- /dev/null +++ b/Stream_support/include/CGAL/IO/File_writer_OFF_impl.h @@ -0,0 +1,56 @@ +// Copyright (c) 1997 +// 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$ +// +// +// Author(s) : Lutz Kettner + +#ifdef CGAL_HEADER_ONLY +#define CGAL_INLINE_FUNCTION inline +#else +#define CGAL_INLINE_FUNCTION +#endif + +#include +#include +#include + +namespace CGAL { + +CGAL_INLINE_FUNCTION +void +File_writer_OFF:: +write_header( std::ostream& o, + std::size_t vertices, + std::size_t halfedges, + std::size_t facets, + bool normals) { + m_out = &o; + m_header.set_vertices( vertices); + // Don't. This halfdges aren't trusted: + // m_header.set_halfedges( halfedges); + (void)halfedges; + m_header.set_facets( facets); + m_header.set_normals( normals); + // Print header. + out() << m_header; +} +} //namespace CGAL +// EOF // diff --git a/Stream_support/include/CGAL/IO/File_writer_VRML_2.h b/Stream_support/include/CGAL/IO/File_writer_VRML_2.h index 174f8ad307a..69b7c0ffa95 100644 --- a/Stream_support/include/CGAL/IO/File_writer_VRML_2.h +++ b/Stream_support/include/CGAL/IO/File_writer_VRML_2.h @@ -55,5 +55,10 @@ public: }; } //namespace CGAL + +#ifdef CGAL_HEADER_ONLY +#include +#endif // CGAL_HEADER_ONLY + #endif // CGAL_IO_FILE_WRITER_VRML_2_H // // EOF // diff --git a/Stream_support/include/CGAL/IO/File_writer_VRML_2_impl.h b/Stream_support/include/CGAL/IO/File_writer_VRML_2_impl.h new file mode 100644 index 00000000000..7e807711f88 --- /dev/null +++ b/Stream_support/include/CGAL/IO/File_writer_VRML_2_impl.h @@ -0,0 +1,82 @@ +// Copyright (c) 1997 +// 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$ +// +// +// Author(s) : Lutz Kettner + +#ifdef CGAL_HEADER_ONLY +#define CGAL_INLINE_FUNCTION inline +#else +#define CGAL_INLINE_FUNCTION +#endif + +#include +#include +#include + +namespace CGAL { + +CGAL_INLINE_FUNCTION +void +File_writer_VRML_2:: +write_header( std::ostream& o, + std::size_t vertices, + std::size_t halfedges, + std::size_t facets) { + m_out = &o; + m_facets = facets; + + out() << " #-- Begin of Polyhedron_3\n"; + out() << " # " << vertices << " vertices\n"; + out() << " # " << halfedges << " halfedges\n"; + out() << " # " << facets << " facets\n"; + out() << " Group {\n" + " children [\n" + " Shape {\n" + " appearance Appearance { material " + "USE Material }\n" + " geometry IndexedFaceSet {\n" + " convex FALSE\n" + " solid FALSE\n" + " coord Coordinate {\n" + " point [" << std::endl; +} + +void +File_writer_VRML_2:: +write_facet_header() const { + out() << " ] #point\n" + " } #coord Coordinate\n" + " coordIndex [" << std::endl; +} + +void +File_writer_VRML_2:: +write_footer() const { + out() << " ] #coordIndex\n" + " } #geometry\n" + " } #Shape\n" + " ] #children\n" + " } #Group" << std::endl; +} + +} //namespace CGAL +// EOF // diff --git a/Stream_support/include/CGAL/IO/File_writer_inventor.h b/Stream_support/include/CGAL/IO/File_writer_inventor.h index b6948d06d81..4b49bee0750 100644 --- a/Stream_support/include/CGAL/IO/File_writer_inventor.h +++ b/Stream_support/include/CGAL/IO/File_writer_inventor.h @@ -52,5 +52,10 @@ public: }; } //namespace CGAL + +#ifdef CGAL_HEADER_ONLY +#include +#endif // CGAL_HEADER_ONLY + #endif // CGAL_IO_FILE_WRITER_INVENTOR_H // // EOF // diff --git a/Stream_support/include/CGAL/IO/File_writer_inventor_impl.h b/Stream_support/include/CGAL/IO/File_writer_inventor_impl.h new file mode 100644 index 00000000000..3cfda77aacf --- /dev/null +++ b/Stream_support/include/CGAL/IO/File_writer_inventor_impl.h @@ -0,0 +1,73 @@ +// Copyright (c) 1997 +// 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$ +// +// +// Author(s) : Lutz Kettner + +#ifdef CGAL_HEADER_ONLY +#define CGAL_INLINE_FUNCTION inline +#else +#define CGAL_INLINE_FUNCTION +#endif + +#include + +namespace CGAL { + +CGAL_INLINE_FUNCTION +void +File_writer_inventor:: +write_header( std::ostream& o, + std::size_t vertices, + std::size_t halfedges, + std::size_t facets){ + m_out = &o; + m_facets = facets; + out() << "# " << vertices << " vertices\n"; + out() << "# " << halfedges << " halfedges\n"; + out() << "# " << facets << " facets\n\n"; + out() << "Separator {\n" + " Coordinate3 {\n" + " point [" << std::endl; +} + +CGAL_INLINE_FUNCTION +void +File_writer_inventor:: +write_facet_header() const { + out() << " ] #point\n" + " } #Coordinate3\n" + " # " << m_facets << " facets\n" + " IndexedFaceSet {\n" + " coordIndex [\n"; +} + +CGAL_INLINE_FUNCTION +void +File_writer_inventor:: +write_footer() const { + out() << " ] #coordIndex\n" + " } #IndexedFaceSet\n" + "} #Separator" << std::endl; +} + +} //namespace CGAL +// EOF // diff --git a/Stream_support/include/CGAL/IO/File_writer_wavefront.h b/Stream_support/include/CGAL/IO/File_writer_wavefront.h index d3ee8cbf05e..bd4fee51eaa 100644 --- a/Stream_support/include/CGAL/IO/File_writer_wavefront.h +++ b/Stream_support/include/CGAL/IO/File_writer_wavefront.h @@ -56,5 +56,10 @@ public: }; } //namespace CGAL + +#ifdef CGAL_HEADER_ONLY +#include +#endif // CGAL_HEADER_ONLY + #endif // CGAL_IO_FILE_WRITER_WAVEFRONT_H // // EOF // diff --git a/Stream_support/include/CGAL/IO/File_writer_wavefront_impl.h b/Stream_support/include/CGAL/IO/File_writer_wavefront_impl.h new file mode 100644 index 00000000000..82691d5ec07 --- /dev/null +++ b/Stream_support/include/CGAL/IO/File_writer_wavefront_impl.h @@ -0,0 +1,57 @@ +// Copyright (c) 1997 +// 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$ +// +// +// Author(s) : Lutz Kettner + +#ifdef CGAL_HEADER_ONLY +#define CGAL_INLINE_FUNCTION inline +#else +#define CGAL_INLINE_FUNCTION +#endif + +#include +#include +#include + +namespace CGAL { + +CGAL_INLINE_FUNCTION +void +File_writer_wavefront:: +write_header( std::ostream& o, + std::size_t vertices, + std::size_t halfedges, + std::size_t facets){ + m_out = &o; + m_facets = facets; + // Print header. + out() << "# file written from a CGAL tool in Wavefront obj format\n"; + out() << "# " << vertices << " vertices\n"; + out() << "# " << halfedges << " halfedges\n"; + out() << "# " << facets << " facets\n\n"; + + out() << "\n# " << vertices << " vertices\n"; + out() << "# ------------------------------------------\n\n"; +} + +} //namespace CGAL +// EOF // diff --git a/Stream_support/include/CGAL/IO/io.h b/Stream_support/include/CGAL/IO/io.h index 7bf4be91fcd..cc58e185eb8 100644 --- a/Stream_support/include/CGAL/IO/io.h +++ b/Stream_support/include/CGAL/IO/io.h @@ -304,7 +304,9 @@ void swallow(std::istream &is, char d); CGAL_EXPORT void swallow(std::istream &is, const std::string& s ); - +#ifdef CGAL_HEADER_ONLY +#include +#endif // CGAL_HEADER_ONLY } //namespace CGAL diff --git a/Stream_support/src/CGAL/Color.cpp b/Stream_support/src/CGAL/Color.cpp index 55bc10aff7d..af1f572da74 100644 --- a/Stream_support/src/CGAL/Color.cpp +++ b/Stream_support/src/CGAL/Color.cpp @@ -23,7 +23,7 @@ // Author(s) : Andreas Fabri, Hervé Brönnimann #include - +#include namespace CGAL { diff --git a/Stream_support/src/CGAL/File_header_OFF.cpp b/Stream_support/src/CGAL/File_header_OFF.cpp index 71112bbca18..375822c4cf1 100644 --- a/Stream_support/src/CGAL/File_header_OFF.cpp +++ b/Stream_support/src/CGAL/File_header_OFF.cpp @@ -22,371 +22,7 @@ // // Author(s) : Lutz Kettner -#include -#include -#include -#include -#include -#include #include -#include -#include +#include -namespace CGAL { - -File_header_OFF::File_header_OFF( bool verbose) -: File_header_extended_OFF( verbose), - n_vertices(0), - n_facets(0), - m_skel(false), - m_binary(false), - m_no_comments(false), - m_offset(0), - m_colors(false), - m_normals(false), - m_tag4(false), - m_tagDim(false), - m_dim(3) -{} -File_header_OFF::File_header_OFF( - bool binary, bool noc, bool skel, bool verbose) -: File_header_extended_OFF( verbose), - n_vertices(0), - n_facets(0), - m_skel(skel), - m_binary(binary), - m_no_comments(noc), - m_offset(0), - m_colors(false), - m_normals(false), - m_tag4(false), - m_tagDim(false), - m_dim(3) -{} -//File_header_OFF::File_header_OFF( int v, int h, int f, -// bool verbose) -//: File_header_extended_OFF( verbose), -// n_vertices(v), -// n_facets(f), -// m_skel(false), -// m_binary(false), -// m_no_comments(false), -// m_offset(0), -// m_colors(false), -// m_normals(false), -// m_tag4(false), -// m_tagDim(false), -// m_dim(3) -//{ -// set_halfedges(h); -//} -File_header_OFF::File_header_OFF( std::size_t v, std::size_t h, std::size_t f, - bool binary, bool noc, bool skel, bool verbose) -: File_header_extended_OFF( verbose), - n_vertices(v), - n_facets(f), - m_skel(skel), - m_binary(binary), - m_no_comments(noc), - m_offset(0), - m_colors(false), - m_normals(false), - m_tag4(false), - m_tagDim(false), - m_dim(3) -{ - set_halfedges(h); -} -File_header_OFF::File_header_OFF( - const File_header_extended_OFF& ext_header) -: File_header_extended_OFF( ext_header), - n_vertices(0), - n_facets(0), - m_skel(false), - m_binary(false), - m_no_comments(false), - m_offset(0), - m_colors(false), - m_normals(false), - m_tag4(false), - m_tagDim(false), - m_dim(3) -{} -File_header_OFF::File_header_OFF( - const File_header_extended_OFF& ext_header, - bool binary, bool noc, bool skel) -: File_header_extended_OFF( ext_header), - n_vertices(0), - n_facets(0), - m_skel(skel), - m_binary(binary), - m_no_comments(noc), - m_offset(0), - m_colors(false), - m_normals(false), - m_tag4(false), - m_tagDim(false), - m_dim(3) -{} -File_header_OFF::File_header_OFF( - std::size_t v, std::size_t h, std::size_t f, - const File_header_extended_OFF& ext_header) -: File_header_extended_OFF( ext_header), - n_vertices(v), - n_facets(f), - m_skel(false), - m_binary(false), - m_no_comments(false), - m_offset(0), - m_colors(false), - m_normals(false), - m_tag4(false), - m_tagDim(false), - m_dim(3) -{ - set_halfedges(h); -} -File_header_OFF::File_header_OFF( - std::size_t v, std::size_t h, std::size_t f, - const File_header_extended_OFF& ext_header, - bool binary, bool noc, bool skel) -: File_header_extended_OFF( ext_header), - n_vertices(v), - n_facets(f), - m_skel(skel), - m_binary(binary), - m_no_comments(noc), - m_offset(0), - m_colors(false), - m_normals(false), - m_tag4(false), - m_tagDim(false), - m_dim(3) -{ - set_halfedges(h); -} - -File_header_OFF& File_header_OFF:: -operator+=( const File_header_OFF& header) { - (File_header_extended_OFF&)(*this) = header; - n_vertices += header.n_vertices; - n_facets += header.n_facets; - return *this; -} - -// Write header. -std::ostream& operator<<( std::ostream& out, const File_header_OFF& h) { - if ( h.comments()) { - out << "# Output of a CGAL tool\n"; - out << static_cast( h); - } - if ( h.has_normals()) - out << 'N'; - if ( h.skel()) - out << "SKEL"; - else - out << "OFF"; - if ( h.binary()) { - out << " BINARY\n"; - I_Binary_write_big_endian_integer32( out, static_cast(h.size_of_vertices())); - I_Binary_write_big_endian_integer32( out, static_cast(h.size_of_facets())); - if ( h.off()) - I_Binary_write_big_endian_integer32( out, 0); - } else { - out << '\n'; - out << h.size_of_vertices() << ' '<< h.size_of_facets(); - if ( h.off()) - out << " 0"; - if ( h.comments()) { - out << "\n\n# " << h.size_of_vertices() << " vertices\n"; - out << "# ------------------------------------------\n"; - } - out << std::endl; - } - return out; -} - -// Scan header. Marks streams badbit if not in SKEL format nor in OFF. -std::istream& operator>>( std::istream& in, File_header_OFF& h) { - // read in the first character and scan for comments, `OFF', or `NOFF', - // or `SKEL', or `4SKEL'. - h.set_off_header( false); - char c; - while ( (in >> c) && c == '#') { - if ( in.get(c) && c == 'C' && - in.get(c) && c == 'B' && - in.get(c) && c == 'P') { - in >> static_cast( h); - } else if ( c != '\n') - in >> skip_until_EOL; - } - if ( ! in) - return in; - h.set_skel( false); - h.set_binary( false); - h.set_index_offset( 1); - h.set_colors( false); - h.set_normals( false); - h.set_homogeneous( false); - h.set_dimensional( false); - h.set_dimension( 3); - - const int max_keyword = 42; - char keyword[max_keyword] = ""; - int i = 0; - keyword[i++] = c; - while( i < max_keyword - 1 && in.get(c) && std::isalnum(c)) - keyword[i++] = c; - keyword[i] = '\0'; - if ( i < 2 || (std::isdigit(keyword[0]) && keyword[0] != '4') - || std::isdigit(keyword[1])) { - h.set_vertices( std::atoi( keyword)); - } else { - h.set_index_offset( 0); - int j = 0; - if ( j < i && keyword[j] == 'C') { - h.set_colors( true); - j++; - } - if ( j < i && keyword[j] == 'N') { - h.set_normals( true); - j++; - } - if ( j < i && keyword[j] == '4') { - h.set_homogeneous( true); - j++; - } - if ( j < i && keyword[j] == 'n') { - h.set_dimensional( true); - j++; - } - if ( i-j != 3 || keyword[j] != 'O' - || keyword[j+1] != 'F' - || keyword[j+2] != 'F') { - if ( i-j != 4 || keyword[j] != 'S' - || keyword[j+1] != 'K' - || keyword[j+2] != 'E' - || keyword[j+3] != 'L') { - in.clear( std::ios::badbit); - if ( h.verbose()) { - std::cerr << " " << std::endl; - std::cerr << "error: File_header_OFF: " - "wrong format: neither OFF nor SKEL." - << std::endl; - } - return in; - } else { - h.set_skel( true); - } - } - in >> skip_comment_OFF >> c; - if ( std::isdigit(c)) { - in.putback(c); - int n; - in >> n; - h.set_vertices(n); - } else { - i = 0; - keyword[i++] = c; - while( i < max_keyword - 1 && in.get(c) && - std::isalnum(c)) - keyword[i++] = c; - keyword[i] = '\0'; - if ( std::strcmp( keyword, "BINARY") == 0) { - h.set_binary( true); - if ( c != '\n') - in >> skip_until_EOL; - } else { - in.clear( std::ios::badbit); - if ( h.verbose()) { - std::cerr << " " << std::endl; - std::cerr << "error: File_header_OFF(): " - "wrong format: neither OFF nor SKEL." - << std::endl; - } - return in; - } - } - } - // Read remaining size value(s). - int n_h; - if ( h.binary()) { - boost::int32_t a, b, c; - I_Binary_read_big_endian_integer32( in, a); - if ( h.n_dimensional()) { - h.set_dimension( a); - I_Binary_read_big_endian_integer32( in, a); - } - I_Binary_read_big_endian_integer32( in, b); - if ( h.off()) - I_Binary_read_big_endian_integer32( in, c); - else - c = 0; - h.set_vertices( a); - if (b<0){ - in.clear( std::ios::badbit ); - if ( h.verbose()) { - std::cerr << " " << std::endl; - std::cerr << "error: File_header_OFF(): File contains < 0 facets." - << std::endl; - } - return in; - } - h.set_facets( b); - n_h = c; - } else { - int n; - if ( h.n_dimensional()) { - h.set_dimension( static_cast(h.size_of_vertices())); - in >> n; - h.set_vertices(n); - } - in >> n; - if (n < 0){ - in.clear( std::ios::badbit ); - if ( h.verbose()) { - std::cerr << " " << std::endl; - std::cerr << "error: File_header_OFF(): File contains < 0 facets." - << std::endl; - } - return in; - } - h.set_facets(n); - if ( h.off()) - in >> n_h; - else - n_h = 0; - } - if ( n_h == 0) - h.set_index_offset( 0); - if ( ! in || h.size_of_vertices() <= 0 ) { - in.clear( std::ios::badbit); - if ( h.verbose()) { - std::cerr << " " << std::endl; - std::cerr << "error: File_header_OFF(): File contains <= 0 vertices." - << std::endl; - } - return in; - } - if ( h.size_of_halfedges() == 0) { - // be careful, because border edges count twice - h.set_halfedges( 2 * n_h); - // check against the Eulerian equation for connected planar graphs. - // We do not know the number of holes we must represent as dummy - // facets and we do not know the genus of the surface. - // So we add 12 and a factor of 5 percent. - if ( h.size_of_halfedges() == 0 - || h.size_of_halfedges() > (h.size_of_vertices() - + h.size_of_facets() - 2 + 12) * 2.1 - || h.size_of_halfedges() < (h.size_of_vertices() - + h.size_of_facets() - 2) * 2 - ) - h.set_halfedges( int((h.size_of_vertices() + - h.size_of_facets() - 2 + 12) * 2.1)); - } - h.set_off_header( h.off()); - return in; -} - -} //namespace CGAL // EOF // diff --git a/Stream_support/src/CGAL/File_header_extended_OFF.cpp b/Stream_support/src/CGAL/File_header_extended_OFF.cpp index 3f709ff65fa..43e0e30ff79 100644 --- a/Stream_support/src/CGAL/File_header_extended_OFF.cpp +++ b/Stream_support/src/CGAL/File_header_extended_OFF.cpp @@ -23,174 +23,6 @@ // Author(s) : Lutz Kettner #include -#include +#include -#include -#include -#include -#include -#include -#include - - -namespace CGAL { - -bool File_header_extended_OFF:: -is_POL() const { - return is_OFF() && polyhedral_surface(); -} - -bool File_header_extended_OFF:: -is_CBP() const { - return is_POL() && triangulated() && non_empty_facets() && - normalized_to_sphere() && radius() <= 1.0; -} - -bool File_header_extended_OFF:: -is_TRN() const { return is_CBP() && terrain(); } - -int File_header_extended_OFF:: -is_CBPn() const { - if ( is_POL() && triangulated() && non_empty_facets() && - normalized_to_sphere() && rounded() && - (radius() <= ( 1l << rounded_bits()))) - return rounded_bits(); - else - return 0; -} - -int File_header_extended_OFF:: -is_TRNn() const { return ( terrain() ? is_CBPn() : 0); } - - -// The proper file suffix with respect to file format. -std::string File_header_extended_OFF:: -suffix() const { - if ( is_TRNn()) { - std::ostringstream out; - out << "trn" << m_rounded_bits << '\0'; - return out.str(); - } - if ( is_TRN()) - return std::string("trn"); - if ( is_CBPn()) { - std::ostringstream out; - out << "cbp" << m_rounded_bits << '\0'; - return out.str(); - } - if ( is_CBP()) - return std::string("cbp"); - if ( is_POL()) - return std::string("pol"); - return std::string("off"); -} - -// The proper format name. -std::string File_header_extended_OFF:: -format_name() const { - if ( is_TRNn()) { - std::ostringstream out; - out << "TRN" << m_rounded_bits << '\0'; - return out.str(); - } - if ( is_TRN()) - return std::string("TRN"); - if ( is_CBPn()) { - std::ostringstream out; - out << "CBP" << m_rounded_bits << '\0'; - return out.str(); - } - if ( is_CBP()) - return std::string("CBP"); - if ( is_POL()) - return std::string("POL"); - return std::string("OFF"); -} - -File_header_extended_OFF& File_header_extended_OFF:: -operator+=( const File_header_extended_OFF& header) { - m_verbose = m_verbose || header.m_verbose; - m_polyhedral_surface = m_polyhedral_surface && - header.m_polyhedral_surface; - m_halfedges += header.m_halfedges; - m_triangulated = m_triangulated && header.m_triangulated; - m_non_empty_facets = m_non_empty_facets && - header.m_non_empty_facets; - m_terrain = m_terrain && header.m_terrain; - m_normalized_to_sphere = m_normalized_to_sphere && - header.m_normalized_to_sphere; - m_radius = (std::max)(m_radius, header.m_radius); - m_rounded = m_rounded && header.m_rounded; - m_rounded_bits = (std::max)( m_rounded_bits, - header.m_rounded_bits); - m_off_header = m_off_header && header.m_off_header; - return *this; -} - -#define CGAL_OUT(item) out << "# " #item " " << h.item() << '\n' -#define CGAL_OUTBOOL(item) out << "# " #item " " <<(h.item() ? '1':'0') << '\n' - -// Write extended header incl. CGAL/ENDCBP keywords. -std::ostream& operator<<( std::ostream& out, - const File_header_extended_OFF& h) { - out << "#CBP\n"; - CGAL_OUTBOOL( polyhedral_surface); - CGAL_OUT( halfedges); - CGAL_OUTBOOL( triangulated); - CGAL_OUTBOOL( non_empty_facets); - CGAL_OUTBOOL( terrain); - CGAL_OUTBOOL( normalized_to_sphere); - CGAL_OUT( radius); - CGAL_OUTBOOL( rounded); - CGAL_OUT( rounded_bits); - out << "# ENDCBP\n" << std::endl; - return out; -} -#undef CGAL_OUT -#undef OUTBOOL - -#define CGAL_IN(item,type) \ - else if ( std::strcmp( keyword, #item) == 0) { \ - type t; \ - in >> t; \ - h.set_##item( t); \ - } - -#define CGAL_INBOOL(item) \ - else if ( std::strcmp( keyword, #item) == 0) { \ - in >> c; \ - h.set_##item( c == '1'); \ - } - -// Scan extended header. The CBP keyword must be read already. -std::istream& operator>>( std::istream& in, File_header_extended_OFF& h) { - const int max_keyword = 42; - char c; - char keyword[max_keyword] = ""; - in >> keyword; - while ( in && std::strcmp( keyword, "ENDCBP") != 0) { - if ( std::strcmp( keyword, "#") == 0) - ; - CGAL_INBOOL( polyhedral_surface) - CGAL_IN( halfedges, int) - CGAL_INBOOL( triangulated) - CGAL_INBOOL( non_empty_facets) - CGAL_INBOOL( terrain) - CGAL_INBOOL( normalized_to_sphere) - CGAL_IN( radius, double) - CGAL_INBOOL( rounded) - CGAL_IN( rounded_bits, int) - else if ( h.verbose()) { - std::cerr << "warning: File_header_extended_OFF: unknown key '" - << keyword << "'." << std::endl; - } - in >> keyword; - } - in >> skip_until_EOL >> skip_comment_OFF; - return in; -} -#undef CGAL_IN -#undef CGAL_INBOOL - -} //namespace CGAL // EOF // diff --git a/Stream_support/src/CGAL/File_scanner_OFF.cpp b/Stream_support/src/CGAL/File_scanner_OFF.cpp index 3361a458680..21d85d72c9c 100644 --- a/Stream_support/src/CGAL/File_scanner_OFF.cpp +++ b/Stream_support/src/CGAL/File_scanner_OFF.cpp @@ -22,104 +22,7 @@ // // Author(s) : Lutz Kettner -#include -#include -#include -#include #include +#include -namespace CGAL { - -void -File_scanner_OFF:: -skip_to_next_vertex( std::size_t current_vertex) { - CGAL_assertion( current_vertex < size_of_vertices()); - if ( binary()) { - float f; - if ( has_normals() && ! normals_read) { - I_Binary_read_big_endian_float32( m_in, f); - I_Binary_read_big_endian_float32( m_in, f); - I_Binary_read_big_endian_float32( m_in, f); - if ( is_homogeneous()) - I_Binary_read_big_endian_float32( m_in, f); - } - if ( has_colors()) { - // It is not well stated in the Geomview manual - // how color is coded following a vertex. It is - // parsed similar to the optional color for facets. - boost::int32_t k; - I_Binary_read_big_endian_integer32( m_in, k); - if (k<0 || k>4) { - m_in.clear( std::ios::badbit); - if ( verbose()) { - std::cerr << " " << std::endl; - std::cerr << "File_scanner_OFF::" << std::endl; - std::cerr << "skip_to_next_vertex(): input error: bad " - " number of color indices at vertex " - << current_vertex << "." << std::endl; - } - set_off_header( false); - return; - } - while (k--) { - float dummy; - I_Binary_read_big_endian_float32( m_in, dummy); - } - } - } else { - if ( has_normals() && ! normals_read) { - double dummy; - if ( is_homogeneous()) { - m_in >> dummy >> dummy >> dummy >> dummy; - } else { - m_in >> dummy >> dummy >> dummy; - } - } - if ( has_colors()) { // skip color entries (1 to 4) - m_in >> skip_until_EOL; - } - } - if( ! m_in) { - if ( verbose()) { - std::cerr << " " << std::endl; - std::cerr << "File_scanner_OFF::" << std::endl; - std::cerr << "skip_to_next_vertex(): input error: cannot read " - "OFF file beyond vertex " << current_vertex << "." - << std::endl; - } - set_off_header( false); - return; - } - normals_read = false; -} - -void -File_scanner_OFF:: -skip_to_next_facet( std::size_t current_facet) { - // Take care of trailing informations like color triples. - if ( binary()) { - boost::int32_t k; - I_Binary_read_big_endian_integer32( m_in, k); - if (k<0 || k>4) { - m_in.clear( std::ios::badbit); - if ( verbose()) { - std::cerr << " " << std::endl; - std::cerr << "File_scanner_OFF::" << std::endl; - std::cerr << "skip_to_next_facet(): input error: bad " - "number of color indices at vertex " - << current_facet << "." << std::endl; - } - set_off_header( false); - return; - } - while (k--) { - float dummy; - I_Binary_read_big_endian_float32( m_in, dummy); - } - } else { - m_in >> skip_until_EOL; - } -} - -} //namespace CGAL // EOF // diff --git a/Stream_support/src/CGAL/File_writer_OFF.cpp b/Stream_support/src/CGAL/File_writer_OFF.cpp index cb288f2d6b4..51ff52b3e05 100644 --- a/Stream_support/src/CGAL/File_writer_OFF.cpp +++ b/Stream_support/src/CGAL/File_writer_OFF.cpp @@ -22,28 +22,7 @@ // // Author(s) : Lutz Kettner -#include -#include #include +#include -namespace CGAL { - -void -File_writer_OFF:: -write_header( std::ostream& o, - std::size_t vertices, - std::size_t halfedges, - std::size_t facets, - bool normals) { - m_out = &o; - m_header.set_vertices( vertices); - // Don't. This halfdges aren't trusted: - // m_header.set_halfedges( halfedges); - (void)halfedges; - m_header.set_facets( facets); - m_header.set_normals( normals); - // Print header. - out() << m_header; -} -} //namespace CGAL // EOF // diff --git a/Stream_support/src/CGAL/File_writer_VRML_2.cpp b/Stream_support/src/CGAL/File_writer_VRML_2.cpp index ecec30c2535..c18f90ceda9 100644 --- a/Stream_support/src/CGAL/File_writer_VRML_2.cpp +++ b/Stream_support/src/CGAL/File_writer_VRML_2.cpp @@ -22,54 +22,7 @@ // // Author(s) : Lutz Kettner -#include -#include #include +#include -namespace CGAL { - -void -File_writer_VRML_2:: -write_header( std::ostream& o, - std::size_t vertices, - std::size_t halfedges, - std::size_t facets) { - m_out = &o; - m_facets = facets; - - out() << " #-- Begin of Polyhedron_3\n"; - out() << " # " << vertices << " vertices\n"; - out() << " # " << halfedges << " halfedges\n"; - out() << " # " << facets << " facets\n"; - out() << " Group {\n" - " children [\n" - " Shape {\n" - " appearance Appearance { material " - "USE Material }\n" - " geometry IndexedFaceSet {\n" - " convex FALSE\n" - " solid FALSE\n" - " coord Coordinate {\n" - " point [" << std::endl; -} - -void -File_writer_VRML_2:: -write_facet_header() const { - out() << " ] #point\n" - " } #coord Coordinate\n" - " coordIndex [" << std::endl; -} - -void -File_writer_VRML_2:: -write_footer() const { - out() << " ] #coordIndex\n" - " } #geometry\n" - " } #Shape\n" - " ] #children\n" - " } #Group" << std::endl; -} - -} //namespace CGAL // EOF // diff --git a/Stream_support/src/CGAL/File_writer_inventor.cpp b/Stream_support/src/CGAL/File_writer_inventor.cpp index e40a1d0dd65..fecb6106fea 100644 --- a/Stream_support/src/CGAL/File_writer_inventor.cpp +++ b/Stream_support/src/CGAL/File_writer_inventor.cpp @@ -23,42 +23,6 @@ // Author(s) : Lutz Kettner #include +#include -namespace CGAL { - -void -File_writer_inventor:: -write_header( std::ostream& o, - std::size_t vertices, - std::size_t halfedges, - std::size_t facets){ - m_out = &o; - m_facets = facets; - out() << "# " << vertices << " vertices\n"; - out() << "# " << halfedges << " halfedges\n"; - out() << "# " << facets << " facets\n\n"; - out() << "Separator {\n" - " Coordinate3 {\n" - " point [" << std::endl; -} - -void -File_writer_inventor:: -write_facet_header() const { - out() << " ] #point\n" - " } #Coordinate3\n" - " # " << m_facets << " facets\n" - " IndexedFaceSet {\n" - " coordIndex [\n"; -} - -void -File_writer_inventor:: -write_footer() const { - out() << " ] #coordIndex\n" - " } #IndexedFaceSet\n" - "} #Separator" << std::endl; -} - -} //namespace CGAL // EOF // diff --git a/Stream_support/src/CGAL/File_writer_wavefront.cpp b/Stream_support/src/CGAL/File_writer_wavefront.cpp index 2fee7344ad6..e2a948199f0 100644 --- a/Stream_support/src/CGAL/File_writer_wavefront.cpp +++ b/Stream_support/src/CGAL/File_writer_wavefront.cpp @@ -22,29 +22,7 @@ // // Author(s) : Lutz Kettner -#include -#include #include +#include -namespace CGAL { - -void -File_writer_wavefront:: -write_header( std::ostream& o, - std::size_t vertices, - std::size_t halfedges, - std::size_t facets){ - m_out = &o; - m_facets = facets; - // Print header. - out() << "# file written from a CGAL tool in Wavefront obj format\n"; - out() << "# " << vertices << " vertices\n"; - out() << "# " << halfedges << " halfedges\n"; - out() << "# " << facets << " facets\n\n"; - - out() << "\n# " << vertices << " vertices\n"; - out() << "# ------------------------------------------\n\n"; -} - -} //namespace CGAL // EOF // diff --git a/Stream_support/src/CGAL/io.cpp b/Stream_support/src/CGAL/io.cpp index 955ed6a2e2a..f40f96016ad 100644 --- a/Stream_support/src/CGAL/io.cpp +++ b/Stream_support/src/CGAL/io.cpp @@ -22,104 +22,11 @@ // // Author(s) : Andreas Fabri -#include #include -#include - -#include -#include +#include namespace CGAL { int IO::mode = std::ios::xalloc(); - -IO::Mode -get_mode(std::ios& i) -{ - return static_cast(i.iword(IO::mode)); -} - -IO::Mode -set_ascii_mode(std::ios& i) -{ - IO::Mode m = get_mode(i); - i.iword(IO::mode) = IO::ASCII; - return m; -} - - -IO::Mode -set_binary_mode(std::ios& i) -{ - IO::Mode m = get_mode(i); - i.iword(IO::mode) = IO::BINARY; - return m; -} - - -IO::Mode -set_pretty_mode(std::ios& i) -{ - IO::Mode m = get_mode(i); - i.iword(IO::mode) = IO::PRETTY; - return m; -} - -IO::Mode -set_mode(std::ios& i, IO::Mode m) -{ - IO::Mode old = get_mode(i); - i.iword(IO::mode) = m; - return old; -} - -bool -is_pretty(std::ios& i) -{ - return i.iword(IO::mode) == IO::PRETTY; -} - -bool -is_ascii(std::ios& i) -{ - return i.iword(IO::mode) == IO::ASCII; -} - - -bool -is_binary(std::ios& i) -{ - return i.iword(IO::mode) == IO::BINARY; -} - -const char* -mode_name( IO::Mode m) { - static const char* const names[] = {"ASCII", "PRETTY", "BINARY" }; - CGAL_assertion( IO::ASCII <= m && m <= IO::BINARY ); - return names[m]; -} - -void -swallow(std::istream &is, char d) { - char c; - do is.get(c); while (isspace(c)); - if (c != d) { - std::stringstream msg; - msg << "input error: expected '" << d << "' but got '" << c << "'"; - CGAL_error_msg( msg.str().c_str() ); - } -} - -void -swallow(std::istream &is, const std::string& s ) { - std::string t; - is >> t; - if (s != t) { - std::stringstream msg; - msg << "input error: expected '" << s << "' but got '" << t << "'"; - CGAL_error_msg( msg.str().c_str() ); - } -} - } //namespace CGAL From 5895d2b9e03d6dd34306cadb2d211f20af2ea705 Mon Sep 17 00:00:00 2001 From: Guillaume Damiand Date: Thu, 30 Oct 2014 18:51:03 +0100 Subject: [PATCH 02/30] Add io_impl --- Stream_support/include/CGAL/IO/io_impl.h | 121 +++++++++++++++++++++++ 1 file changed, 121 insertions(+) create mode 100644 Stream_support/include/CGAL/IO/io_impl.h diff --git a/Stream_support/include/CGAL/IO/io_impl.h b/Stream_support/include/CGAL/IO/io_impl.h new file mode 100644 index 00000000000..154acc590ed --- /dev/null +++ b/Stream_support/include/CGAL/IO/io_impl.h @@ -0,0 +1,121 @@ +// Copyright (c) 1997 +// 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$ +// +// +// Author(s) : Andreas Fabri + +#include +#include + +#include +#include + +namespace CGAL { + +IO::Mode +get_mode(std::ios& i) +{ + return static_cast(i.iword(IO::mode)); +} + +IO::Mode +set_ascii_mode(std::ios& i) +{ + IO::Mode m = get_mode(i); + i.iword(IO::mode) = IO::ASCII; + return m; +} + + +IO::Mode +set_binary_mode(std::ios& i) +{ + IO::Mode m = get_mode(i); + i.iword(IO::mode) = IO::BINARY; + return m; +} + + +IO::Mode +set_pretty_mode(std::ios& i) +{ + IO::Mode m = get_mode(i); + i.iword(IO::mode) = IO::PRETTY; + return m; +} + +IO::Mode +set_mode(std::ios& i, IO::Mode m) +{ + IO::Mode old = get_mode(i); + i.iword(IO::mode) = m; + return old; +} + +bool +is_pretty(std::ios& i) +{ + return i.iword(IO::mode) == IO::PRETTY; +} + +bool +is_ascii(std::ios& i) +{ + return i.iword(IO::mode) == IO::ASCII; +} + + +bool +is_binary(std::ios& i) +{ + return i.iword(IO::mode) == IO::BINARY; +} + +const char* +mode_name( IO::Mode m) { + static const char* const names[] = {"ASCII", "PRETTY", "BINARY" }; + CGAL_assertion( IO::ASCII <= m && m <= IO::BINARY ); + return names[m]; +} + +void +swallow(std::istream &is, char d) { + char c; + do is.get(c); while (isspace(c)); + if (c != d) { + std::stringstream msg; + msg << "input error: expected '" << d << "' but got '" << c << "'"; + CGAL_error_msg( msg.str().c_str() ); + } +} + +void +swallow(std::istream &is, const std::string& s ) { + std::string t; + is >> t; + if (s != t) { + std::stringstream msg; + msg << "input error: expected '" << s << "' but got '" << t << "'"; + CGAL_error_msg( msg.str().c_str() ); + } +} + +} //namespace CGAL From bc30ff8d98a33605b642b95b655f8eb26530fc70 Mon Sep 17 00:00:00 2001 From: Guillaume Damiand Date: Thu, 30 Oct 2014 18:51:45 +0100 Subject: [PATCH 03/30] Add assertions_impl --- STL_Extension/include/CGAL/assertions_impl.h | 224 +++++++++++++++++++ 1 file changed, 224 insertions(+) create mode 100644 STL_Extension/include/CGAL/assertions_impl.h diff --git a/STL_Extension/include/CGAL/assertions_impl.h b/STL_Extension/include/CGAL/assertions_impl.h new file mode 100644 index 00000000000..b68be94a682 --- /dev/null +++ b/STL_Extension/include/CGAL/assertions_impl.h @@ -0,0 +1,224 @@ +// Copyright (c) 1997 +// 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$ +// +// +// Author(s) : Geert-Jan Giezeman and Sven Schönherr + +#include +#include +#include +#include + +#include +#include + +namespace CGAL { + +namespace { + + // behaviour variables +// ------------------- + +Failure_behaviour _error_behaviour = THROW_EXCEPTION; +Failure_behaviour _warning_behaviour = CONTINUE; + + +// standard error handlers +// ----------------------- +void +_standard_error_handler( + const char* what, + const char* expr, + const char* file, + int line, + const char* msg ) +{ +#if defined(__GNUG__) && !defined(__llvm__) + // After g++ 3.4, std::terminate defaults to printing to std::cerr itself. + if (_error_behaviour == THROW_EXCEPTION) + return; +#endif + std::cerr << "CGAL error: " << what << " violation!" << std::endl + << "Expression : " << expr << std::endl + << "File : " << file << std::endl + << "Line : " << line << std::endl + << "Explanation: " << msg << std::endl + << "Refer to the bug-reporting instructions at http://www.cgal.org/bug_report.html" + << std::endl; +} + + +// standard warning handler +// ------------------------ +void +_standard_warning_handler( const char *, + const char* expr, + const char* file, + int line, + const char* msg ) +{ +#if defined(__GNUG__) && !defined(__llvm__) + // After g++ 3.4, std::terminate defaults to printing to std::cerr itself. + if (_warning_behaviour == THROW_EXCEPTION) + return; +#endif + std::cerr << "CGAL warning: check violation!" << std::endl + << "Expression : " << expr << std::endl + << "File : " << file << std::endl + << "Line : " << line << std::endl + << "Explanation: " << msg << std::endl + << "Refer to the bug-reporting instructions at http://www.cgal.org/bug_report.html" + << std::endl; +} + +// default handler settings +// ------------------------ +Failure_function _error_handler = _standard_error_handler; +Failure_function _warning_handler = _standard_warning_handler; + + +} // anonymous namespace + +// failure functions +// ----------------- +void +assertion_fail( const char* expr, + const char* file, + int line, + const char* msg) +{ + _error_handler("assertion", expr, file, line, msg); + switch (_error_behaviour) { + case ABORT: + std::abort(); + case EXIT: + std::exit(1); // EXIT_FAILURE + case EXIT_WITH_SUCCESS: + std::exit(0); // EXIT_SUCCESS + case CONTINUE: // The CONTINUE case should not be used anymore. + case THROW_EXCEPTION: + default: + throw Assertion_exception("CGAL", expr, file, line, msg); + } +} + +void +precondition_fail( const char* expr, + const char* file, + int line, + const char* msg) +{ + _error_handler("precondition", expr, file, line, msg); + switch (_error_behaviour) { + case ABORT: + std::abort(); + case EXIT: + std::exit(1); // EXIT_FAILURE + case EXIT_WITH_SUCCESS: + std::exit(0); // EXIT_SUCCESS + case CONTINUE: + case THROW_EXCEPTION: + default: + throw Precondition_exception("CGAL", expr, file, line, msg); + } +} + +void +postcondition_fail(const char* expr, + const char* file, + int line, + const char* msg) +{ + _error_handler("postcondition", expr, file, line, msg); + switch (_error_behaviour) { + case ABORT: + std::abort(); + case EXIT: + std::exit(1); // EXIT_FAILURE + case EXIT_WITH_SUCCESS: + std::exit(0); // EXIT_SUCCESS + case CONTINUE: + case THROW_EXCEPTION: + default: + throw Postcondition_exception("CGAL", expr, file, line, msg); + } +} + + +// warning function +// ---------------- +void +warning_fail( const char* expr, + const char* file, + int line, + const char* msg) +{ + _warning_handler("warning", expr, file, line, msg); + switch (_warning_behaviour) { + case ABORT: + std::abort(); + case EXIT: + std::exit(1); // EXIT_FAILURE + case EXIT_WITH_SUCCESS: + std::exit(0); // EXIT_SUCCESS + case THROW_EXCEPTION: + throw Warning_exception("CGAL", expr, file, line, msg); + case CONTINUE: + ; + } +} + + +// error handler set functions +// --------------------------- +Failure_function +set_error_handler( Failure_function handler) +{ + Failure_function result = _error_handler; + _error_handler = handler; + return result; +} + +Failure_function +set_warning_handler( Failure_function handler) +{ + Failure_function result = _warning_handler; + _warning_handler = handler; + return result; +} + +Failure_behaviour +set_error_behaviour(Failure_behaviour eb) +{ + Failure_behaviour result = _error_behaviour; + _error_behaviour = eb; + return result; +} + +Failure_behaviour +set_warning_behaviour(Failure_behaviour eb) +{ + Failure_behaviour result = _warning_behaviour; + _warning_behaviour = eb; + return result; +} + +} //namespace CGAL From 15b1cfdcb799dea5a9306c439ba77c460173e1e0 Mon Sep 17 00:00:00 2001 From: Guillaume Damiand Date: Thu, 30 Oct 2014 19:37:47 +0100 Subject: [PATCH 04/30] Color_impl and io_impl ok --- Stream_support/include/CGAL/IO/Color.h | 18 ++++---- Stream_support/include/CGAL/IO/Color_impl.h | 19 ++++++++ Stream_support/include/CGAL/IO/io_impl.h | 48 ++++++++++++++++----- Stream_support/src/CGAL/Color.cpp | 20 --------- Stream_support/src/CGAL/io.cpp | 4 ++ 5 files changed, 71 insertions(+), 38 deletions(-) diff --git a/Stream_support/include/CGAL/IO/Color.h b/Stream_support/include/CGAL/IO/Color.h index ca4a4af376c..2696ce8dcee 100644 --- a/Stream_support/include/CGAL/IO/Color.h +++ b/Stream_support/include/CGAL/IO/Color.h @@ -1,9 +1,9 @@ -// Copyright (c) 1997 +// Copyright (c) 1997 // Utrecht University (The Netherlands), // ETH Zurich (Switzerland), // INRIA Sophia-Antipolis (France), // Max-Planck-Institute Saarbruecken (Germany), -// and Tel-Aviv University (Israel). All rights reserved. +// 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 @@ -18,7 +18,7 @@ // // $URL$ // $Id$ -// +// // // Author(s) : Andreas Fabri @@ -32,9 +32,9 @@ namespace CGAL { class Color { public: Color() {} - Color(unsigned char red, - unsigned char green, - unsigned char blue, + Color(unsigned char red, + unsigned char green, + unsigned char blue, unsigned char alpha = 120) : _red(red), _green(green), _blue(blue), _alpha(alpha) {} @@ -76,15 +76,16 @@ private: unsigned char _alpha; }; +#ifndef CGAL_HEADER_ONLY CGAL_EXPORT extern const Color BLACK ; CGAL_EXPORT extern const Color WHITE ; -CGAL_EXPORT extern const Color GRAY ; +CGAL_EXPORT extern const Color GRAY ; CGAL_EXPORT extern const Color RED ; CGAL_EXPORT extern const Color GREEN ; -CGAL_EXPORT extern const Color DEEPBLUE ; +CGAL_EXPORT extern const Color DEEPBLUE; CGAL_EXPORT extern const Color BLUE ; CGAL_EXPORT extern const Color PURPLE ; CGAL_EXPORT extern const Color VIOLET ; @@ -92,6 +93,7 @@ CGAL_EXPORT extern const Color VIOLET ; CGAL_EXPORT extern const Color ORANGE ; CGAL_EXPORT extern const Color YELLOW ; +#endif // CGAL_HEADER_ONLY } //namespace CGAL diff --git a/Stream_support/include/CGAL/IO/Color_impl.h b/Stream_support/include/CGAL/IO/Color_impl.h index a2c023ebe8d..cfca8dea9bb 100644 --- a/Stream_support/include/CGAL/IO/Color_impl.h +++ b/Stream_support/include/CGAL/IO/Color_impl.h @@ -21,3 +21,22 @@ // // // Author(s) : Andreas Fabri, Hervé Brönnimann + +namespace CGAL { + +const Color BLACK = Color(0, 0, 0); +const Color WHITE = Color(255, 255, 255); +const Color GRAY = Color(100,100,100); + +const Color GREEN = Color(0, 255, 0); + +const Color DEEPBLUE = Color(10, 0, 100); +const Color BLUE = Color(0, 0, 255); +const Color VIOLET = Color(255, 0, 255); +const Color PURPLE = Color(100, 0, 70); + +const Color RED = Color(255, 0, 0); +const Color ORANGE = Color(235, 150, 0); +const Color YELLOW = Color(255, 255, 0); + +} //namespace CGAL diff --git a/Stream_support/include/CGAL/IO/io_impl.h b/Stream_support/include/CGAL/IO/io_impl.h index 154acc590ed..4233dcd1c4f 100644 --- a/Stream_support/include/CGAL/IO/io_impl.h +++ b/Stream_support/include/CGAL/IO/io_impl.h @@ -22,6 +22,12 @@ // // Author(s) : Andreas Fabri +#ifdef CGAL_HEADER_ONLY +#define CGAL_INLINE_FUNCTION inline +#else +#define CGAL_INLINE_FUNCTION +#endif + #include #include @@ -30,65 +36,85 @@ namespace CGAL { +#ifdef CGAL_HEADER_ONLY +inline +static int& get_static_mode() +{ + static int IO::mode = std::ios::xalloc(); + return IO::mode; +} +#else // CGAL_HEADER_ONLY +inline +static int& get_static_mode() +{ return IO::mode; } +#endif // CGAL_HEADER_ONLY + +CGAL_INLINE_FUNCTION IO::Mode get_mode(std::ios& i) { - return static_cast(i.iword(IO::mode)); + return static_cast(i.iword(get_static_mode())); } +CGAL_INLINE_FUNCTION IO::Mode set_ascii_mode(std::ios& i) { IO::Mode m = get_mode(i); - i.iword(IO::mode) = IO::ASCII; + i.iword(get_static_mode()) = IO::ASCII; return m; } - +CGAL_INLINE_FUNCTION IO::Mode set_binary_mode(std::ios& i) { IO::Mode m = get_mode(i); - i.iword(IO::mode) = IO::BINARY; + i.iword(get_static_mode()) = IO::BINARY; return m; } +CGAL_INLINE_FUNCTION IO::Mode set_pretty_mode(std::ios& i) { IO::Mode m = get_mode(i); - i.iword(IO::mode) = IO::PRETTY; + i.iword(get_static_mode()) = IO::PRETTY; return m; } +CGAL_INLINE_FUNCTION IO::Mode set_mode(std::ios& i, IO::Mode m) { IO::Mode old = get_mode(i); - i.iword(IO::mode) = m; + i.iword(get_static_mode()) = m; return old; } +CGAL_INLINE_FUNCTION bool is_pretty(std::ios& i) { - return i.iword(IO::mode) == IO::PRETTY; + return i.iword(get_static_mode()) == IO::PRETTY; } +CGAL_INLINE_FUNCTION bool is_ascii(std::ios& i) { - return i.iword(IO::mode) == IO::ASCII; + return i.iword(get_static_mode()) == IO::ASCII; } - +CGAL_INLINE_FUNCTION bool is_binary(std::ios& i) { - return i.iword(IO::mode) == IO::BINARY; + return i.iword(get_static_mode()) == IO::BINARY; } +CGAL_INLINE_FUNCTION const char* mode_name( IO::Mode m) { static const char* const names[] = {"ASCII", "PRETTY", "BINARY" }; @@ -96,6 +122,7 @@ mode_name( IO::Mode m) { return names[m]; } +CGAL_INLINE_FUNCTION void swallow(std::istream &is, char d) { char c; @@ -107,6 +134,7 @@ swallow(std::istream &is, char d) { } } +CGAL_INLINE_FUNCTION void swallow(std::istream &is, const std::string& s ) { std::string t; diff --git a/Stream_support/src/CGAL/Color.cpp b/Stream_support/src/CGAL/Color.cpp index af1f572da74..f63912940c3 100644 --- a/Stream_support/src/CGAL/Color.cpp +++ b/Stream_support/src/CGAL/Color.cpp @@ -24,23 +24,3 @@ #include #include - -namespace CGAL { - -const Color BLACK = Color(0, 0, 0); -const Color WHITE = Color(255, 255, 255); -const Color GRAY = Color(100,100,100); - -const Color GREEN = Color(0, 255, 0); - -const Color DEEPBLUE = Color(10, 0, 100); -const Color BLUE = Color(0, 0, 255); -const Color VIOLET = Color(255, 0, 255); -const Color PURPLE = Color(100, 0, 70); - -const Color RED = Color(255, 0, 0); -const Color ORANGE = Color(235, 150, 0); -const Color YELLOW = Color(255, 255, 0); - -} //namespace CGAL - diff --git a/Stream_support/src/CGAL/io.cpp b/Stream_support/src/CGAL/io.cpp index f40f96016ad..a94c72a4af3 100644 --- a/Stream_support/src/CGAL/io.cpp +++ b/Stream_support/src/CGAL/io.cpp @@ -25,8 +25,12 @@ #include #include +#ifndef CGAL_HEADER_ONLY + namespace CGAL { int IO::mode = std::ios::xalloc(); } //namespace CGAL + +#endif From e8fe29c79c1c4e59b18970a4117e0c4ff84ec9df Mon Sep 17 00:00:00 2001 From: Guillaume Damiand Date: Fri, 31 Oct 2014 17:09:48 +0100 Subject: [PATCH 05/30] Ok for the compilation version header only (only for the treated files). --- .../CGAL/Bbox_2_Line_2_intersection_impl.h | 3 - .../CGAL/Ray_2_Bbox_2_intersection_impl.h | 1 - .../src/CGAL/Bbox_2_intersections.cpp | 7 ++ Kernel_23/include/CGAL/Bbox_2.h | 4 +- Kernel_23/include/CGAL/Bbox_3.h | 4 +- Kernel_23/include/CGAL/Circle_2.h | 4 +- Kernel_23/include/CGAL/Direction_2.h | 8 +- Kernel_23/include/CGAL/Direction_3.h | 8 +- Kernel_23/include/CGAL/Iso_cuboid_3.h | 2 +- Kernel_23/include/CGAL/Iso_rectangle_2.h | 2 +- Kernel_23/include/CGAL/Line_2.h | 4 +- Kernel_23/include/CGAL/Line_3.h | 2 +- Kernel_23/include/CGAL/Origin.h | 7 +- Kernel_23/include/CGAL/Origin_impl.h | 2 - Kernel_23/include/CGAL/Plane_3.h | 4 +- Kernel_23/include/CGAL/Point_2.h | 8 +- Kernel_23/include/CGAL/Point_3.h | 8 +- Kernel_23/include/CGAL/Ray_2.h | 4 +- Kernel_23/include/CGAL/Ray_3.h | 4 +- Kernel_23/include/CGAL/Segment_2.h | 2 +- Kernel_23/include/CGAL/Segment_3.h | 2 +- Kernel_23/include/CGAL/Sphere_3.h | 8 +- Kernel_23/include/CGAL/Tetrahedron_3.h | 2 +- Kernel_23/include/CGAL/Triangle_2.h | 2 +- Kernel_23/include/CGAL/Triangle_3.h | 2 +- Kernel_23/include/CGAL/Vector_2.h | 8 +- Kernel_23/include/CGAL/Vector_3.h | 8 +- .../include/CGAL/aff_transformation_tags.h | 4 + .../CGAL/aff_transformation_tags_impl.h | 2 - Kernel_23/src/CGAL/kernel.cpp | 9 +- Kernel_d/include/CGAL/Kernel_d/Matrix__.h | 4 +- Kernel_d/include/CGAL/Kernel_d/Pair_d.h | 4 +- Kernel_d/include/CGAL/Kernel_d/Tuple_d.h | 4 +- Kernel_d/include/CGAL/Kernel_d/Vector__.h | 4 +- .../demo/Linear_cell_complex/CMakeLists.txt | 2 + Nef_2/include/CGAL/Nef_2/Polynomial.h | 4 +- Number_types/include/CGAL/FPU.h | 24 +++-- .../include/CGAL/Interval_arithmetic_impl.h | 72 ++++++++++++++ Number_types/include/CGAL/number_type_basic.h | 1 - Number_types/src/CGAL/Interval_arithmetic.cpp | 32 +------ STL_Extension/include/CGAL/assertions_impl.h | 95 +++++++++++++++---- STL_Extension/src/CGAL/assertions.cpp | 4 + Stream_support/include/CGAL/IO/io.h | 56 ++--------- Stream_support/include/CGAL/IO/io_impl.h | 56 +++++++++-- Stream_support/src/CGAL/Color.cpp | 4 + Stream_support/src/CGAL/File_header_OFF.cpp | 4 + .../src/CGAL/File_header_extended_OFF.cpp | 4 + Stream_support/src/CGAL/File_scanner_OFF.cpp | 4 + Stream_support/src/CGAL/File_writer_OFF.cpp | 4 + .../src/CGAL/File_writer_VRML_2.cpp | 4 + .../src/CGAL/File_writer_inventor.cpp | 4 + .../src/CGAL/File_writer_wavefront.cpp | 4 + Stream_support/src/CGAL/io.cpp | 4 +- 53 files changed, 351 insertions(+), 182 deletions(-) create mode 100644 Number_types/include/CGAL/Interval_arithmetic_impl.h diff --git a/Intersections_2/include/CGAL/Bbox_2_Line_2_intersection_impl.h b/Intersections_2/include/CGAL/Bbox_2_Line_2_intersection_impl.h index c4a5132c0fe..241ca508898 100644 --- a/Intersections_2/include/CGAL/Bbox_2_Line_2_intersection_impl.h +++ b/Intersections_2/include/CGAL/Bbox_2_Line_2_intersection_impl.h @@ -29,7 +29,6 @@ #endif #include -#include typedef CGAL::Simple_cartesian Lcart; @@ -83,7 +82,6 @@ Bbox_2_Line_2_pair::operator=(Bbox_2_Line_2_pair const &o) return *this; } - CGAL_INLINE_FUNCTION Bbox_2_Line_2_pair::Intersection_results Bbox_2_Line_2_pair::intersection_type() const @@ -173,7 +171,6 @@ Bbox_2_Line_2_pair::intersection_type() const return pimpl->_result; } - CGAL_INLINE_FUNCTION bool Bbox_2_Line_2_pair::intersection( diff --git a/Intersections_2/include/CGAL/Ray_2_Bbox_2_intersection_impl.h b/Intersections_2/include/CGAL/Ray_2_Bbox_2_intersection_impl.h index 2ad3d7a2800..3f0943baf7b 100644 --- a/Intersections_2/include/CGAL/Ray_2_Bbox_2_intersection_impl.h +++ b/Intersections_2/include/CGAL/Ray_2_Bbox_2_intersection_impl.h @@ -29,7 +29,6 @@ #endif #include -#include typedef CGAL::Simple_cartesian Rcart; diff --git a/Intersections_2/src/CGAL/Bbox_2_intersections.cpp b/Intersections_2/src/CGAL/Bbox_2_intersections.cpp index 6b624b62961..c8cc5e01466 100644 --- a/Intersections_2/src/CGAL/Bbox_2_intersections.cpp +++ b/Intersections_2/src/CGAL/Bbox_2_intersections.cpp @@ -22,5 +22,12 @@ // // Author(s) : Geert-Jan Giezeman +#ifndef CGAL_HEADER_ONLY + +#include #include + +#include #include + +#endif // CGAL_HEADER_ONLY diff --git a/Kernel_23/include/CGAL/Bbox_2.h b/Kernel_23/include/CGAL/Bbox_2.h index 7ccfe8300aa..d34dbf169c3 100644 --- a/Kernel_23/include/CGAL/Bbox_2.h +++ b/Kernel_23/include/CGAL/Bbox_2.h @@ -166,7 +166,7 @@ inline std::ostream& operator<<(std::ostream &os, const Bbox_2 &b) { - switch(os.iword(IO::mode)) { + switch(get_mode(os)) { case IO::ASCII : os << b.xmin() << ' ' << b.ymin() << ' ' << b.xmax() << ' ' << b.ymax(); @@ -191,7 +191,7 @@ operator>>(std::istream &is, Bbox_2 &b) { double xmin, ymin, xmax, ymax; - switch(is.iword(IO::mode)) { + switch(get_mode(is)) { case IO::ASCII : is >> xmin >> ymin >> xmax >> ymax; break; diff --git a/Kernel_23/include/CGAL/Bbox_3.h b/Kernel_23/include/CGAL/Bbox_3.h index 6518a4cc704..0ad0d6c0d90 100644 --- a/Kernel_23/include/CGAL/Bbox_3.h +++ b/Kernel_23/include/CGAL/Bbox_3.h @@ -184,7 +184,7 @@ inline std::ostream& operator<<(std::ostream &os, const Bbox_3& b) { - switch(os.iword(IO::mode)) + switch(get_mode(os)) { case IO::ASCII : return os << b.xmin() << ' ' << b.ymin() << ' ' << b.zmin() @@ -214,7 +214,7 @@ operator>>(std::istream &is, Bbox_3& b) { double xmin, ymin, zmin, xmax, ymax, zmax; - switch(is.iword(IO::mode)) + switch(get_mode(is)) { case IO::ASCII : is >> xmin >> ymin >> zmin >> xmax >> ymax >> zmax; diff --git a/Kernel_23/include/CGAL/Circle_2.h b/Kernel_23/include/CGAL/Circle_2.h index 70d27c066fa..48dcae149b1 100644 --- a/Kernel_23/include/CGAL/Circle_2.h +++ b/Kernel_23/include/CGAL/Circle_2.h @@ -228,7 +228,7 @@ template std::ostream& insert(std::ostream& os, const Circle_2& c) { - switch(os.iword(IO::mode)) { + switch(get_mode(os)) { case IO::ASCII : os << c.center() << ' ' << c.squared_radius() << ' ' << static_cast(c.orientation()); @@ -271,7 +271,7 @@ extract(std::istream& is, Circle_2& c) typename R::Point_2 center; typename R::FT squared_radius; int o; - switch(is.iword(IO::mode)) { + switch(get_mode(is)) { case IO::ASCII : is >> center >> squared_radius >> o; break; diff --git a/Kernel_23/include/CGAL/Direction_2.h b/Kernel_23/include/CGAL/Direction_2.h index 265ff825ff4..b86c8e2db7f 100644 --- a/Kernel_23/include/CGAL/Direction_2.h +++ b/Kernel_23/include/CGAL/Direction_2.h @@ -186,7 +186,7 @@ std::ostream& insert(std::ostream& os, const Direction_2& d, const Cartesian_tag&) { typename R::Vector_2 v = d.to_vector(); - switch(os.iword(IO::mode)) { + switch(get_mode(os)) { case IO::ASCII : return os << v.x() << ' ' << v.y(); case IO::BINARY : @@ -202,7 +202,7 @@ template std::ostream& insert(std::ostream& os, const Direction_2& d, const Homogeneous_tag&) { - switch(os.iword(IO::mode)) + switch(get_mode(os)) { case IO::ASCII : return os << d.dx() << ' ' << d.dy(); @@ -229,7 +229,7 @@ std::istream& extract(std::istream& is, Direction_2& d, const Cartesian_tag&) { typename R::FT x, y; - switch(is.iword(IO::mode)) { + switch(get_mode(is)) { case IO::ASCII : is >> x >> y; break; @@ -252,7 +252,7 @@ std::istream& extract(std::istream& is, Direction_2& d, const Homogeneous_tag&) { typename R::RT x, y; - switch(is.iword(IO::mode)) + switch(get_mode(is)) { case IO::ASCII : is >> x >> y; diff --git a/Kernel_23/include/CGAL/Direction_3.h b/Kernel_23/include/CGAL/Direction_3.h index 91afea14091..a9556080742 100644 --- a/Kernel_23/include/CGAL/Direction_3.h +++ b/Kernel_23/include/CGAL/Direction_3.h @@ -139,7 +139,7 @@ std::ostream& insert(std::ostream& os, const Direction_3& d, const Cartesian_tag&) { typename R::Vector_3 v = d.to_vector(); - switch(os.iword(IO::mode)) { + switch(get_mode(os)) { case IO::ASCII : return os << v.x() << ' ' << v.y() << ' ' << v.z(); case IO::BINARY : @@ -157,7 +157,7 @@ template std::ostream& insert(std::ostream& os, const Direction_3& d, const Homogeneous_tag&) { - switch(os.iword(IO::mode)) + switch(get_mode(os)) { case IO::ASCII : return os << d.dx() << ' ' << d.dy() << ' ' << d.dz(); @@ -186,7 +186,7 @@ std::istream& extract(std::istream& is, Direction_3& d, const Cartesian_tag&) { typename R::FT x, y, z; - switch(is.iword(IO::mode)) { + switch(get_mode(is)) { case IO::ASCII : is >> x >> y >> z; break; @@ -210,7 +210,7 @@ std::istream& extract(std::istream& is, Direction_3& d, const Homogeneous_tag&) { typename R::RT x, y, z; - switch(is.iword(IO::mode)) + switch(get_mode(is)) { case IO::ASCII : is >> x >> y >> z; diff --git a/Kernel_23/include/CGAL/Iso_cuboid_3.h b/Kernel_23/include/CGAL/Iso_cuboid_3.h index 72706efa2ff..184a30f574b 100644 --- a/Kernel_23/include/CGAL/Iso_cuboid_3.h +++ b/Kernel_23/include/CGAL/Iso_cuboid_3.h @@ -239,7 +239,7 @@ template < class R > std::ostream & operator<<(std::ostream& os, const Iso_cuboid_3& r) { - switch(os.iword(IO::mode)) { + switch(get_mode(os)) { case IO::ASCII : return os << (r.min)() << ' ' << (r.max)(); case IO::BINARY : diff --git a/Kernel_23/include/CGAL/Iso_rectangle_2.h b/Kernel_23/include/CGAL/Iso_rectangle_2.h index e18c132f908..9df885f0a3a 100644 --- a/Kernel_23/include/CGAL/Iso_rectangle_2.h +++ b/Kernel_23/include/CGAL/Iso_rectangle_2.h @@ -230,7 +230,7 @@ template < class R > std::ostream & operator<<(std::ostream &os, const Iso_rectangle_2 &r) { - switch(os.iword(IO::mode)) { + switch(get_mode(os)) { case IO::ASCII : return os << (r.min)() << ' ' << (r.max)(); case IO::BINARY : diff --git a/Kernel_23/include/CGAL/Line_2.h b/Kernel_23/include/CGAL/Line_2.h index 772bbf26987..ccebd8e4e26 100644 --- a/Kernel_23/include/CGAL/Line_2.h +++ b/Kernel_23/include/CGAL/Line_2.h @@ -233,7 +233,7 @@ template std::ostream& insert(std::ostream& os, const Line_2& l) { - switch(os.iword(IO::mode)) { + switch(get_mode(os)) { case IO::ASCII : return os << l.a() << ' ' << l.b() << ' ' << l.c(); case IO::BINARY : @@ -260,7 +260,7 @@ std::istream& extract(std::istream& is, Line_2& l) { typename R::RT a, b, c; - switch(is.iword(IO::mode)) { + switch(get_mode(is)) { case IO::ASCII : is >> a >> b >> c; break; diff --git a/Kernel_23/include/CGAL/Line_3.h b/Kernel_23/include/CGAL/Line_3.h index 4429b11c06e..47696e5a9ab 100644 --- a/Kernel_23/include/CGAL/Line_3.h +++ b/Kernel_23/include/CGAL/Line_3.h @@ -145,7 +145,7 @@ template < class R > std::ostream & operator<<(std::ostream &os, const Line_3 &l) { - switch(os.iword(IO::mode)) { + switch(get_mode(os)) { case IO::ASCII : return os << l.point(0) << ' ' << l.point(1); case IO::BINARY : diff --git a/Kernel_23/include/CGAL/Origin.h b/Kernel_23/include/CGAL/Origin.h index 39a1c123464..78ec935776b 100644 --- a/Kernel_23/include/CGAL/Origin.h +++ b/Kernel_23/include/CGAL/Origin.h @@ -33,13 +33,16 @@ namespace CGAL { class Origin {}; -CGAL_EXPORT extern const Origin ORIGIN; - class Null_vector {}; +#ifndef CGAL_HEADER_ONLY + +CGAL_EXPORT extern const Origin ORIGIN; CGAL_EXPORT extern const Null_vector NULL_VECTOR; +#endif + } //namespace CGAL #ifdef CGAL_HEADER_ONLY diff --git a/Kernel_23/include/CGAL/Origin_impl.h b/Kernel_23/include/CGAL/Origin_impl.h index c9b89e40877..38a00c486b3 100644 --- a/Kernel_23/include/CGAL/Origin_impl.h +++ b/Kernel_23/include/CGAL/Origin_impl.h @@ -22,8 +22,6 @@ // // Author(s) : Andreas Fabri, Stefan Schirra -#include - namespace CGAL { const Origin ORIGIN = Origin(); diff --git a/Kernel_23/include/CGAL/Plane_3.h b/Kernel_23/include/CGAL/Plane_3.h index 9414daa74eb..f96d85160b3 100644 --- a/Kernel_23/include/CGAL/Plane_3.h +++ b/Kernel_23/include/CGAL/Plane_3.h @@ -235,7 +235,7 @@ template < class R > std::ostream & operator<<(std::ostream &os, const Plane_3 &p) { - switch(os.iword(IO::mode)) { + switch(get_mode(os)) { case IO::ASCII : return os << p.a() << ' ' << p.b() << ' ' << p.c() << ' ' << p.d(); case IO::BINARY : @@ -256,7 +256,7 @@ std::istream & operator>>(std::istream &is, Plane_3 &p) { typename R::RT a, b, c, d; - switch(is.iword(IO::mode)) { + switch(get_mode(is)) { case IO::ASCII : is >> a >> b >> c >> d; break; diff --git a/Kernel_23/include/CGAL/Point_2.h b/Kernel_23/include/CGAL/Point_2.h index 1d15459eff3..c486007fcca 100644 --- a/Kernel_23/include/CGAL/Point_2.h +++ b/Kernel_23/include/CGAL/Point_2.h @@ -169,7 +169,7 @@ template std::ostream& insert(std::ostream& os, const Point_2& p,const Cartesian_tag&) { - switch(os.iword(IO::mode)) { + switch(get_mode(os)) { case IO::ASCII : return os << p.x() << ' ' << p.y(); case IO::BINARY : @@ -185,7 +185,7 @@ template std::ostream& insert(std::ostream& os, const Point_2& p,const Homogeneous_tag&) { - switch(os.iword(IO::mode)) + switch(get_mode(os)) { case IO::ASCII : return os << p.hx() << ' ' << p.hy() << ' ' << p.hw(); @@ -214,7 +214,7 @@ std::istream& extract(std::istream& is, Point_2& p, const Cartesian_tag&) { typename R::FT x, y; - switch(is.iword(IO::mode)) { + switch(get_mode(is)) { case IO::ASCII : is >> x >> y; break; @@ -238,7 +238,7 @@ std::istream& extract(std::istream& is, Point_2& p, const Homogeneous_tag&) { typename R::RT hx, hy, hw; - switch(is.iword(IO::mode)) + switch(get_mode(is)) { case IO::ASCII : is >> hx >> hy >> hw; diff --git a/Kernel_23/include/CGAL/Point_3.h b/Kernel_23/include/CGAL/Point_3.h index c595cd9765e..05d2df8f1dd 100644 --- a/Kernel_23/include/CGAL/Point_3.h +++ b/Kernel_23/include/CGAL/Point_3.h @@ -195,7 +195,7 @@ template std::ostream& insert(std::ostream& os, const Point_3& p,const Cartesian_tag&) { - switch(os.iword(IO::mode)) { + switch(get_mode(os)) { case IO::ASCII : return os << p.x() << ' ' << p.y() << ' ' << p.z(); case IO::BINARY : @@ -213,7 +213,7 @@ template std::ostream& insert(std::ostream& os, const Point_3& p,const Homogeneous_tag&) { - switch(os.iword(IO::mode)) + switch(get_mode(os)) { case IO::ASCII : return os << p.hx() << ' ' << p.hy() << ' ' << p.hz() << ' ' << p.hw(); @@ -244,7 +244,7 @@ std::istream& extract(std::istream& is, Point_3& p, const Cartesian_tag&) { typename R::FT x, y, z; - switch(is.iword(IO::mode)) { + switch(get_mode(is)) { case IO::ASCII : is >> x >> y >> z; break; @@ -269,7 +269,7 @@ std::istream& extract(std::istream& is, Point_3& p, const Homogeneous_tag&) { typename R::RT hx, hy, hz, hw; - switch(is.iword(IO::mode)) + switch(get_mode(is)) { case IO::ASCII : is >> hx >> hy >> hz >> hw; diff --git a/Kernel_23/include/CGAL/Ray_2.h b/Kernel_23/include/CGAL/Ray_2.h index f01f6feb4d6..b5bb85fd726 100644 --- a/Kernel_23/include/CGAL/Ray_2.h +++ b/Kernel_23/include/CGAL/Ray_2.h @@ -207,7 +207,7 @@ template std::ostream& insert(std::ostream& os, const Ray_2& r, const Cartesian_tag&) { - switch(os.iword(IO::mode)) { + switch(get_mode(os)) { case IO::ASCII : return os << r.source() << ' ' << r.second_point(); case IO::BINARY : @@ -221,7 +221,7 @@ template std::ostream& insert(std::ostream& os, const Ray_2& r, const Homogeneous_tag&) { - switch(os.iword(IO::mode)) + switch(get_mode(os)) { case IO::ASCII : return os << r.source() << ' ' << r.second_point(); diff --git a/Kernel_23/include/CGAL/Ray_3.h b/Kernel_23/include/CGAL/Ray_3.h index 1d004ec2063..2d8dcae6966 100644 --- a/Kernel_23/include/CGAL/Ray_3.h +++ b/Kernel_23/include/CGAL/Ray_3.h @@ -173,7 +173,7 @@ template std::ostream& insert(std::ostream& os, const Ray_3& r, const Cartesian_tag&) { - switch(os.iword(IO::mode)) { + switch(get_mode(os)) { case IO::ASCII : return os << r.start() << ' ' << r.direction(); case IO::BINARY : @@ -187,7 +187,7 @@ template std::ostream& insert(std::ostream& os, const Ray_3& r, const Homogeneous_tag&) { - switch(os.iword(IO::mode)) + switch(get_mode(os)) { case IO::ASCII : return os << r.start() << ' ' << r.direction(); diff --git a/Kernel_23/include/CGAL/Segment_2.h b/Kernel_23/include/CGAL/Segment_2.h index 2aa7307554a..ea6cebe2e02 100644 --- a/Kernel_23/include/CGAL/Segment_2.h +++ b/Kernel_23/include/CGAL/Segment_2.h @@ -282,7 +282,7 @@ template < class R > std::ostream & operator<<(std::ostream &os, const Segment_2 &s) { - switch(os.iword(IO::mode)) { + switch(get_mode(os)) { case IO::ASCII : return os << s.source() << ' ' << s.target(); case IO::BINARY : diff --git a/Kernel_23/include/CGAL/Segment_3.h b/Kernel_23/include/CGAL/Segment_3.h index a811035c094..de335d7398a 100644 --- a/Kernel_23/include/CGAL/Segment_3.h +++ b/Kernel_23/include/CGAL/Segment_3.h @@ -198,7 +198,7 @@ template < class R > std::ostream & operator<<(std::ostream &os, const Segment_3 &s) { - switch(os.iword(IO::mode)) { + switch(get_mode(os)) { case IO::ASCII : return os << s.source() << ' ' << s.target(); case IO::BINARY : diff --git a/Kernel_23/include/CGAL/Sphere_3.h b/Kernel_23/include/CGAL/Sphere_3.h index 436d580ffc1..5dc8f3c2384 100644 --- a/Kernel_23/include/CGAL/Sphere_3.h +++ b/Kernel_23/include/CGAL/Sphere_3.h @@ -216,7 +216,7 @@ template std::ostream& insert(std::ostream& os, const Sphere_3& c,const Cartesian_tag&) { - switch(os.iword(IO::mode)) { + switch(get_mode(os)) { case IO::ASCII : os << c.center() << ' ' << c.squared_radius() << ' ' << static_cast(c.orientation()); @@ -248,7 +248,7 @@ template std::ostream& insert(std::ostream& os, const Sphere_3& c, const Homogeneous_tag&) { - switch(os.iword(IO::mode)) { + switch(get_mode(os)) { case IO::ASCII : os << c.center() << ' ' << c.squared_radius() << ' ' << static_cast(c.orientation()); @@ -291,7 +291,7 @@ extract(std::istream& is, Sphere_3& c, const Cartesian_tag&) typename R::Point_3 center; typename R::FT squared_radius; int o=0; - switch(is.iword(IO::mode)) { + switch(get_mode(is)) { case IO::ASCII : is >> center >> squared_radius >> o; break; @@ -318,7 +318,7 @@ extract(std::istream& is, Sphere_3& c, const Homogeneous_tag&) typename R::Point_3 center; typename R::FT squared_radius; int o; - switch(is.iword(IO::mode)) { + switch(get_mode(is)) { case IO::ASCII : is >> center >> squared_radius >> o; break; diff --git a/Kernel_23/include/CGAL/Tetrahedron_3.h b/Kernel_23/include/CGAL/Tetrahedron_3.h index 625421b28c6..c58882b3bc6 100644 --- a/Kernel_23/include/CGAL/Tetrahedron_3.h +++ b/Kernel_23/include/CGAL/Tetrahedron_3.h @@ -155,7 +155,7 @@ template < class R > std::ostream & operator<<(std::ostream &os, const Tetrahedron_3 &t) { - switch(os.iword(IO::mode)) { + switch(get_mode(os)) { case IO::ASCII : return os << t[0] << ' ' << t[1] << ' ' << t[2] << ' ' << t[3]; case IO::BINARY : diff --git a/Kernel_23/include/CGAL/Triangle_2.h b/Kernel_23/include/CGAL/Triangle_2.h index f89aa93fd85..75bcedaaa26 100644 --- a/Kernel_23/include/CGAL/Triangle_2.h +++ b/Kernel_23/include/CGAL/Triangle_2.h @@ -182,7 +182,7 @@ template < class R > std::ostream & operator<<(std::ostream &os, const Triangle_2 &t) { - switch(os.iword(IO::mode)) { + switch(get_mode(os)) { case IO::ASCII : return os << t[0] << ' ' << t[1] << ' ' << t[2]; case IO::BINARY : diff --git a/Kernel_23/include/CGAL/Triangle_3.h b/Kernel_23/include/CGAL/Triangle_3.h index b1d04a16c1d..211a8b59820 100644 --- a/Kernel_23/include/CGAL/Triangle_3.h +++ b/Kernel_23/include/CGAL/Triangle_3.h @@ -125,7 +125,7 @@ template < class R > std::ostream & operator<<(std::ostream &os, const Triangle_3 &t) { - switch(os.iword(IO::mode)) { + switch(get_mode(os)) { case IO::ASCII : return os << t[0] << ' ' << t[1] << ' ' << t[2]; case IO::BINARY : diff --git a/Kernel_23/include/CGAL/Vector_2.h b/Kernel_23/include/CGAL/Vector_2.h index b0418063344..6594321abc0 100644 --- a/Kernel_23/include/CGAL/Vector_2.h +++ b/Kernel_23/include/CGAL/Vector_2.h @@ -251,7 +251,7 @@ template std::ostream& insert(std::ostream& os, const Vector_2& v, const Cartesian_tag&) { - switch(os.iword(IO::mode)) { + switch(get_mode(os)) { case IO::ASCII : return os << v.x() << ' ' << v.y(); case IO::BINARY : @@ -267,7 +267,7 @@ template std::ostream& insert(std::ostream& os, const Vector_2& v, const Homogeneous_tag&) { - switch(os.iword(IO::mode)) + switch(get_mode(os)) { case IO::ASCII : return os << v.hx() << ' ' << v.hy() << ' ' << v.hw(); @@ -297,7 +297,7 @@ std::istream& extract(std::istream& is, Vector_2& v, const Cartesian_tag&) { typename R::FT x, y; - switch(is.iword(IO::mode)) { + switch(get_mode(is)) { case IO::ASCII : is >> x >> y; break; @@ -321,7 +321,7 @@ std::istream& extract(std::istream& is, Vector_2& v, const Homogeneous_tag&) { typename R::RT hx, hy, hw; - switch(is.iword(IO::mode)) + switch(get_mode(is)) { case IO::ASCII : is >> hx >> hy >> hw; diff --git a/Kernel_23/include/CGAL/Vector_3.h b/Kernel_23/include/CGAL/Vector_3.h index bb5cd39c114..1b78be305d0 100644 --- a/Kernel_23/include/CGAL/Vector_3.h +++ b/Kernel_23/include/CGAL/Vector_3.h @@ -228,7 +228,7 @@ template std::ostream& insert(std::ostream& os, const Vector_3& v, const Cartesian_tag&) { - switch(os.iword(IO::mode)) { + switch(get_mode(os)) { case IO::ASCII : return os << v.x() << ' ' << v.y() << ' ' << v.z(); case IO::BINARY : @@ -246,7 +246,7 @@ template std::ostream& insert(std::ostream& os, const Vector_3& v, const Homogeneous_tag&) { - switch(os.iword(IO::mode)) + switch(get_mode(os)) { case IO::ASCII : return os << v.hx() << ' ' << v.hy() << ' ' << v.hz() << ' ' << v.hw(); @@ -277,7 +277,7 @@ std::istream& extract(std::istream& is, Vector_3& v, const Cartesian_tag&) { typename R::FT x, y, z; - switch(is.iword(IO::mode)) { + switch(get_mode(is)) { case IO::ASCII : is >> x >> y >> z; break; @@ -301,7 +301,7 @@ std::istream& extract(std::istream& is, Vector_3& v, const Homogeneous_tag&) { typename R::RT hx, hy, hz, hw; - switch(is.iword(IO::mode)) + switch(get_mode(is)) { case IO::ASCII : is >> hx >> hy >> hz >> hw; diff --git a/Kernel_23/include/CGAL/aff_transformation_tags.h b/Kernel_23/include/CGAL/aff_transformation_tags.h index f94bfa5f0f3..788269938ec 100644 --- a/Kernel_23/include/CGAL/aff_transformation_tags.h +++ b/Kernel_23/include/CGAL/aff_transformation_tags.h @@ -36,12 +36,16 @@ class Scaling {}; class Reflection {}; class Identity_transformation {}; +#ifndef CGAL_HEADER_ONLY + CGAL_EXPORT extern const Translation TRANSLATION; CGAL_EXPORT extern const Rotation ROTATION; CGAL_EXPORT extern const Scaling SCALING; CGAL_EXPORT extern const Reflection REFLECTION; CGAL_EXPORT extern const Identity_transformation IDENTITY; +#endif + } //namespace CGAL #ifdef CGAL_HEADER_ONLY diff --git a/Kernel_23/include/CGAL/aff_transformation_tags_impl.h b/Kernel_23/include/CGAL/aff_transformation_tags_impl.h index 13919e563b8..4d4fdf2b8a0 100644 --- a/Kernel_23/include/CGAL/aff_transformation_tags_impl.h +++ b/Kernel_23/include/CGAL/aff_transformation_tags_impl.h @@ -22,8 +22,6 @@ // // Author(s) : Andreas Fabri, Stefan Schirra -#include - namespace CGAL { const Translation TRANSLATION; diff --git a/Kernel_23/src/CGAL/kernel.cpp b/Kernel_23/src/CGAL/kernel.cpp index 3fb9a710ad9..a681d9490b0 100644 --- a/Kernel_23/src/CGAL/kernel.cpp +++ b/Kernel_23/src/CGAL/kernel.cpp @@ -21,6 +21,13 @@ // // // Author(s) : Andreas Fabri, Stefan Schirra - + +#ifndef CGAL_HEADER_ONLY + +#include #include + +#include #include + +#endif // CGAL_HEADER_ONLY diff --git a/Kernel_d/include/CGAL/Kernel_d/Matrix__.h b/Kernel_d/include/CGAL/Kernel_d/Matrix__.h index 978ecf814b2..6613cbe9b9d 100644 --- a/Kernel_d/include/CGAL/Kernel_d/Matrix__.h +++ b/Kernel_d/include/CGAL/Kernel_d/Matrix__.h @@ -747,7 +747,7 @@ std::ostream& operator<<(std::ostream& os, const Matrix_& M) int d = M.row_dimension(); int k = M.column_dimension(); - switch (os.iword(CGAL::IO::mode)) { + switch (get_mode(os)) { case CGAL::IO::BINARY: CGAL::write( os, d); CGAL::write( os, k); @@ -791,7 +791,7 @@ std::istream& operator>>(std::istream& is, Matrix_& M) x_d2,0 ... x_d2,d1-1 */ int cdim, rdim, i; - switch(is.iword(CGAL::IO::mode)) { + switch(get_mode(is)) { case CGAL::IO::BINARY : CGAL::read(is,rdim); CGAL::read(is,cdim); diff --git a/Kernel_d/include/CGAL/Kernel_d/Pair_d.h b/Kernel_d/include/CGAL/Kernel_d/Pair_d.h index 564e143b658..e91abb3ac02 100644 --- a/Kernel_d/include/CGAL/Kernel_d/Pair_d.h +++ b/Kernel_d/include/CGAL/Kernel_d/Pair_d.h @@ -69,7 +69,7 @@ Direction_d direction() const void read(std::istream& is) { - switch( is.iword(CGAL::IO::mode) ) { + switch( get_mode(is) ) { case CGAL::IO::ASCII : is >> _p[0] >> _p[1]; break; case CGAL::IO::BINARY : @@ -81,7 +81,7 @@ void read(std::istream& is) void print(std::ostream& os, const char* _name) const { - switch( os.iword(CGAL::IO::mode) ) { + switch( get_mode(os) ) { case CGAL::IO::ASCII : os << _p[0] << " " << _p[1]; break; case CGAL::IO::BINARY : diff --git a/Kernel_d/include/CGAL/Kernel_d/Tuple_d.h b/Kernel_d/include/CGAL/Kernel_d/Tuple_d.h index 425a82a968f..6f07dbe1886 100644 --- a/Kernel_d/include/CGAL/Kernel_d/Tuple_d.h +++ b/Kernel_d/include/CGAL/Kernel_d/Tuple_d.h @@ -220,7 +220,7 @@ Comparison_result operator()( template void Tuple_d::print(std::ostream& os, const char* l) const { int i; - switch( os.iword(CGAL::IO::mode) ) { + switch( get_mode(os) ) { case CGAL::IO::ASCII : os << size() << " "; for (i = 0; i < size(); ++i) @@ -241,7 +241,7 @@ void Tuple_d::print(std::ostream& os, const char* l) const template void Tuple_d::read(std::istream& is) { int i = 0, d; - switch( is.iword(CGAL::IO::mode) ) { + switch( get_mode(is) ) { case CGAL::IO::ASCII : is >> d; v = Vector(d); while (i < d && is >> v[i] ) ++i; diff --git a/Kernel_d/include/CGAL/Kernel_d/Vector__.h b/Kernel_d/include/CGAL/Kernel_d/Vector__.h index b731d0ea23a..bcacfee52ef 100644 --- a/Kernel_d/include/CGAL/Kernel_d/Vector__.h +++ b/Kernel_d/include/CGAL/Kernel_d/Vector__.h @@ -403,7 +403,7 @@ std::ostream& operator<<(std::ostream& os, const Vector_& v) /*{\Xbinopfunc writes |\Mvar| componentwise to the output stream $O$.}*/ { /* syntax: d x_0 x_1 ... x_d-1 */ int d = v.dimension(); - switch (os.iword(CGAL::IO::mode)) { + switch (get_mode(os)) { case CGAL::IO::BINARY: CGAL::write( os, d); for ( int i = 0; i < d; ++i) @@ -432,7 +432,7 @@ std::istream& operator>>(std::istream& is, Vector_& v) /*{\Xbinopfunc reads |\Mvar| componentwise from the input stream $I$.}*/ { /* syntax: d x_0 x_1 ... x_d-1 */ int d; - switch (is.iword(CGAL::IO::mode)) { + switch (get_mode(is)) { case CGAL::IO::ASCII : case CGAL::IO::BINARY : is >> d; diff --git a/Linear_cell_complex/demo/Linear_cell_complex/CMakeLists.txt b/Linear_cell_complex/demo/Linear_cell_complex/CMakeLists.txt index 6e32ab848d4..f26043666f9 100644 --- a/Linear_cell_complex/demo/Linear_cell_complex/CMakeLists.txt +++ b/Linear_cell_complex/demo/Linear_cell_complex/CMakeLists.txt @@ -11,6 +11,8 @@ else() cmake_policy(VERSION 2.6) endif() +add_definitions(-DCGAL_HEADER_ONLY) + ## To add expensive tests # add_definitions("-DCGAL_CHECK_EXPENSIVE") diff --git a/Nef_2/include/CGAL/Nef_2/Polynomial.h b/Nef_2/include/CGAL/Nef_2/Polynomial.h index a5e805bbadf..5eb40e198da 100644 --- a/Nef_2/include/CGAL/Nef_2/Polynomial.h +++ b/Nef_2/include/CGAL/Nef_2/Polynomial.h @@ -1752,7 +1752,7 @@ template std::ostream& operator << (std::ostream& os, const Polynomial& p) { int i; - switch( os.iword(CGAL::IO::mode) ) + switch( get_mode(os) ) { case CGAL::IO::ASCII : os << p.degree() << ' '; @@ -1788,7 +1788,7 @@ std::istream& operator >> (std::istream& is, Polynomial& p) { char ch; NT c; bool pretty = false; - switch( is.iword(CGAL::IO::mode) ) { + switch( get_mode(is) ) { case CGAL::IO::ASCII : case CGAL::IO::PRETTY : is >> ch; diff --git a/Number_types/include/CGAL/FPU.h b/Number_types/include/CGAL/FPU.h index 1880d51533a..a5d3daeaa6b 100644 --- a/Number_types/include/CGAL/FPU.h +++ b/Number_types/include/CGAL/FPU.h @@ -1,9 +1,9 @@ -// Copyright (c) 1998-2008 +// Copyright (c) 1998-2008 // Utrecht University (The Netherlands), // ETH Zurich (Switzerland), // INRIA Sophia-Antipolis (France), // Max-Planck-Institute Saarbruecken (Germany), -// and Tel-Aviv University (Israel). All rights reserved. +// 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 @@ -66,7 +66,11 @@ extern "C" { # if defined CGAL_CFG_DENORMALS_COMPILE_BUG // For compilers crashing when dealing with denormalized values. // So we have to generate it at run time instead. +#ifdef CGAL_HEADER_ONLY +# define CGAL_IA_MIN_DOUBLE (CGAL::internal::get_static_minimin()) +#else # define CGAL_IA_MIN_DOUBLE (CGAL::internal::minimin) +#endif // CGAL_HEADER_ONLY # else # define CGAL_IA_MIN_DOUBLE (5e-324) # endif @@ -115,14 +119,22 @@ extern "C" { # define CGAL_USE_SSE2 1 #endif -namespace CGAL { - -namespace internal { - #ifdef CGAL_CFG_DENORMALS_COMPILE_BUG + +#ifdef CGAL_HEADER_ONLY +#include // To define get_static_minimin(); +#else // CGAL_HEADER_ONLY +namespace CGAL { +namespace internal { CGAL_EXPORT extern double minimin; +} +} +#endif // CGAL_HEADER_ONLY + #endif +namespace CGAL { +namespace internal { #ifdef __INTEL_COMPILER const double infinity = std::numeric_limits::infinity(); #else diff --git a/Number_types/include/CGAL/Interval_arithmetic_impl.h b/Number_types/include/CGAL/Interval_arithmetic_impl.h new file mode 100644 index 00000000000..1d0ed4710f1 --- /dev/null +++ b/Number_types/include/CGAL/Interval_arithmetic_impl.h @@ -0,0 +1,72 @@ +// Copyright (c) 1999-2004 +// 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$ +// +// +// Author(s) : Sylvain Pion + +namespace CGAL { + +#ifdef CGAL_CFG_DENORMALS_COMPILE_BUG +// For compilers which bug on denormalized values at compile time. +// We generate CGAL_IA_MIN_DOUBLE at run time. +namespace { +double init_min_double() +{ + double d = 1; + double e = 1; + do { + d = e; + e = CGAL_IA_FORCE_TO_DOUBLE(e/2); + } while (e != 0); + return d; +} +} // anonymous namespace + +#ifndef CGAL_HEADER_ONLY + +namespace internal { +double minimin = init_min_double(); +} + +#else // CGAL_HEADER_ONLY + +namespace internal { + double& get_static_minimin() + { + static double minimin = init_min_double(); + return minimin; + } +} +#endif // CGAL_HEADER_ONLY + +#endif // CGAL_CFG_DENORMALS_COMPILE_BUG + +#ifndef CGAL_HEADER_ONLY + +#ifdef _MSC_VER +namespace { +int dummy_symbol_for_stopping_VC_linker_warning; +} // namespace +#endif + +#endif // CGAL_HEADER_ONLY + +} //namespace CGAL diff --git a/Number_types/include/CGAL/number_type_basic.h b/Number_types/include/CGAL/number_type_basic.h index bc71689703d..886ba274858 100644 --- a/Number_types/include/CGAL/number_type_basic.h +++ b/Number_types/include/CGAL/number_type_basic.h @@ -55,7 +55,6 @@ #include #include #include - #include #include #include diff --git a/Number_types/src/CGAL/Interval_arithmetic.cpp b/Number_types/src/CGAL/Interval_arithmetic.cpp index 50f643cdc7e..20b4d44578b 100644 --- a/Number_types/src/CGAL/Interval_arithmetic.cpp +++ b/Number_types/src/CGAL/Interval_arithmetic.cpp @@ -24,34 +24,4 @@ #include #include - -namespace CGAL { - -#ifdef CGAL_CFG_DENORMALS_COMPILE_BUG -// For compilers which bug on denormalized values at compile time. -// We generate CGAL_IA_MIN_DOUBLE at run time. -namespace { -double init_min_double() -{ - double d = 1; - double e = 1; - do { - d = e; - e = CGAL_IA_FORCE_TO_DOUBLE(e/2); - } while (e != 0); - return d; -} -} // anonymous namespace - -namespace internal { -double minimin = init_min_double(); -} -#endif - -#ifdef _MSC_VER -namespace { -int dummy_symbol_for_stopping_VC_linker_warning; -} // namespace -#endif - -} //namespace CGAL +#include diff --git a/STL_Extension/include/CGAL/assertions_impl.h b/STL_Extension/include/CGAL/assertions_impl.h index b68be94a682..340fab72aa1 100644 --- a/STL_Extension/include/CGAL/assertions_impl.h +++ b/STL_Extension/include/CGAL/assertions_impl.h @@ -22,6 +22,12 @@ // // Author(s) : Geert-Jan Giezeman and Sven Schönherr +#ifdef CGAL_HEADER_ONLY +#define CGAL_INLINE_FUNCTION inline +#else +#define CGAL_INLINE_FUNCTION +#endif + #include #include #include @@ -34,15 +40,37 @@ namespace CGAL { namespace { - // behaviour variables +#ifdef CGAL_HEADER_ONLY + +inline Failure_behaviour& get_static_error_behaviour() +{ + static Failure_behaviour _error_behaviour = THROW_EXCEPTION; + return _error_behaviour; +} +inline Failure_behaviour& get_static_warning_behaviour() +{ + static Failure_behaviour _warning_behaviour = CONTINUE; + return _warning_behaviour; +} + +#else // CGAL_HEADER_ONLY + +// behaviour variables // ------------------- Failure_behaviour _error_behaviour = THROW_EXCEPTION; Failure_behaviour _warning_behaviour = CONTINUE; +inline Failure_behaviour& get_static_error_behaviour() +{ return _error_behaviour; } +inline Failure_behaviour& get_static_warning_behaviour() +{ return _warning_behaviour; } + +#endif // CGAL_HEADER_ONLY // standard error handlers // ----------------------- +CGAL_INLINE_FUNCTION void _standard_error_handler( const char* what, @@ -53,7 +81,7 @@ _standard_error_handler( { #if defined(__GNUG__) && !defined(__llvm__) // After g++ 3.4, std::terminate defaults to printing to std::cerr itself. - if (_error_behaviour == THROW_EXCEPTION) + if (get_static_error_behaviour() == THROW_EXCEPTION) return; #endif std::cerr << "CGAL error: " << what << " violation!" << std::endl @@ -68,6 +96,7 @@ _standard_error_handler( // standard warning handler // ------------------------ +CGAL_INLINE_FUNCTION void _standard_warning_handler( const char *, const char* expr, @@ -77,7 +106,7 @@ _standard_warning_handler( const char *, { #if defined(__GNUG__) && !defined(__llvm__) // After g++ 3.4, std::terminate defaults to printing to std::cerr itself. - if (_warning_behaviour == THROW_EXCEPTION) + if (get_static_warning_behaviour() == THROW_EXCEPTION) return; #endif std::cerr << "CGAL warning: check violation!" << std::endl @@ -89,24 +118,45 @@ _standard_warning_handler( const char *, << std::endl; } +#ifdef CGAL_HEADER_ONLY + +inline Failure_function& get_static_error_handler() +{ + static Failure_function _error_handler = _standard_error_handler; + return _error_handler; +} +inline Failure_function& get_static_warning_handler() +{ + static Failure_function _warning_handler = _standard_warning_handler; + return _warning_handler; +} + +#else // CGAL_HEADER_ONLY // default handler settings // ------------------------ Failure_function _error_handler = _standard_error_handler; Failure_function _warning_handler = _standard_warning_handler; +inline Failure_function& get_static_error_handler() +{ return _error_handler; } +inline Failure_function& get_static_warning_handler() +{ return _warning_handler; } + +#endif // CGAL_HEADER_ONLY } // anonymous namespace // failure functions // ----------------- +CGAL_INLINE_FUNCTION void assertion_fail( const char* expr, const char* file, int line, const char* msg) { - _error_handler("assertion", expr, file, line, msg); - switch (_error_behaviour) { + get_static_error_handler()("assertion", expr, file, line, msg); + switch (get_static_error_behaviour()) { case ABORT: std::abort(); case EXIT: @@ -120,14 +170,15 @@ assertion_fail( const char* expr, } } +CGAL_INLINE_FUNCTION void precondition_fail( const char* expr, const char* file, int line, const char* msg) { - _error_handler("precondition", expr, file, line, msg); - switch (_error_behaviour) { + get_static_error_handler()("precondition", expr, file, line, msg); + switch (get_static_error_behaviour()) { case ABORT: std::abort(); case EXIT: @@ -141,14 +192,15 @@ precondition_fail( const char* expr, } } +CGAL_INLINE_FUNCTION void postcondition_fail(const char* expr, const char* file, int line, const char* msg) { - _error_handler("postcondition", expr, file, line, msg); - switch (_error_behaviour) { + get_static_error_handler()("postcondition", expr, file, line, msg); + switch (get_static_error_behaviour()) { case ABORT: std::abort(); case EXIT: @@ -165,14 +217,15 @@ postcondition_fail(const char* expr, // warning function // ---------------- +CGAL_INLINE_FUNCTION void warning_fail( const char* expr, const char* file, int line, const char* msg) { - _warning_handler("warning", expr, file, line, msg); - switch (_warning_behaviour) { + get_static_warning_handler()("warning", expr, file, line, msg); + switch (get_static_warning_behaviour()) { case ABORT: std::abort(); case EXIT: @@ -189,35 +242,39 @@ warning_fail( const char* expr, // error handler set functions // --------------------------- +CGAL_INLINE_FUNCTION Failure_function set_error_handler( Failure_function handler) { - Failure_function result = _error_handler; - _error_handler = handler; + Failure_function result = get_static_error_handler(); + get_static_error_handler() = handler; return result; } +CGAL_INLINE_FUNCTION Failure_function set_warning_handler( Failure_function handler) { - Failure_function result = _warning_handler; - _warning_handler = handler; + Failure_function result = get_static_warning_handler(); + get_static_warning_handler() = handler; return result; } +CGAL_INLINE_FUNCTION Failure_behaviour set_error_behaviour(Failure_behaviour eb) { - Failure_behaviour result = _error_behaviour; - _error_behaviour = eb; + Failure_behaviour result = get_static_error_behaviour(); + get_static_error_behaviour() = eb; return result; } +CGAL_INLINE_FUNCTION Failure_behaviour set_warning_behaviour(Failure_behaviour eb) { - Failure_behaviour result = _warning_behaviour; - _warning_behaviour = eb; + Failure_behaviour result = get_static_warning_behaviour(); + get_static_warning_behaviour() = eb; return result; } diff --git a/STL_Extension/src/CGAL/assertions.cpp b/STL_Extension/src/CGAL/assertions.cpp index 9491e18dc72..9df3b1ac79c 100644 --- a/STL_Extension/src/CGAL/assertions.cpp +++ b/STL_Extension/src/CGAL/assertions.cpp @@ -22,5 +22,9 @@ // // Author(s) : Geert-Jan Giezeman and Sven Schönherr +#ifndef CGAL_HEADER_ONLY + #include #include + +#endif // CGAL_HEADER_ONLY diff --git a/Stream_support/include/CGAL/IO/io.h b/Stream_support/include/CGAL/IO/io.h index cc58e185eb8..c9d2bda0a6a 100644 --- a/Stream_support/include/CGAL/IO/io.h +++ b/Stream_support/include/CGAL/IO/io.h @@ -39,7 +39,9 @@ namespace CGAL { class IO { public: +#ifndef CGAL_HEADER_ONLY CGAL_EXPORT static int mode; +#endif // CGAL_HEADER_ONLY enum Mode {ASCII = 0, PRETTY, BINARY}; }; @@ -167,8 +169,13 @@ CGAL_EXPORT bool is_binary(std::ios& i); +extern +std::ostream& operator<<( std::ostream& out, const Color& col); - inline std::istream& extract(std::istream& is, double &d) +extern +std::istream &operator>>(std::istream &is, Color& col); + +inline std::istream& extract(std::istream& is, double &d) { #if defined( _MSC_VER ) && ( _MSC_VER > 1600 ) std::string s; @@ -251,49 +258,6 @@ read(std::istream& is, T& t) read(is, t, typename Io_traits::Io_tag()); } - -inline -std::ostream& operator<<( std::ostream& out, const Color& col) -{ - switch(out.iword(IO::mode)) { - case IO::ASCII : - return out << static_cast(col.red()) << ' ' - << static_cast(col.green()) << ' ' - << static_cast(col.blue()); - case IO::BINARY : - write(out, static_cast(col.red())); - write(out, static_cast(col.green())); - write(out, static_cast(col.blue())); - return out; - default: - return out << "Color(" << static_cast(col.red()) << ", " - << static_cast(col.green()) << ", " - << static_cast(col.blue()) << ')'; - } -} - -inline -std::istream &operator>>(std::istream &is, Color& col) -{ - int r = 0, g = 0, b = 0; - switch(is.iword(IO::mode)) { - case IO::ASCII : - is >> r >> g >> b; - break; - case IO::BINARY : - read(is, r); - read(is, g); - read(is, b); - break; - default: - std::cerr << "" << std::endl; - std::cerr << "Stream must be in ascii or binary mode" << std::endl; - break; - } - col = Color((unsigned char)r,(unsigned char)g,(unsigned char)b); - return is; -} - CGAL_EXPORT const char* mode_name( IO::Mode m ); @@ -304,10 +268,10 @@ void swallow(std::istream &is, char d); CGAL_EXPORT void swallow(std::istream &is, const std::string& s ); +} //namespace CGAL + #ifdef CGAL_HEADER_ONLY #include #endif // CGAL_HEADER_ONLY -} //namespace CGAL - #endif // CGAL_IO_H diff --git a/Stream_support/include/CGAL/IO/io_impl.h b/Stream_support/include/CGAL/IO/io_impl.h index 4233dcd1c4f..ad8e7bca33c 100644 --- a/Stream_support/include/CGAL/IO/io_impl.h +++ b/Stream_support/include/CGAL/IO/io_impl.h @@ -37,16 +37,18 @@ namespace CGAL { #ifdef CGAL_HEADER_ONLY -inline -static int& get_static_mode() +namespace { +inline int& get_static_mode() { - static int IO::mode = std::ios::xalloc(); - return IO::mode; + static int mode = std::ios::xalloc(); + return mode; } +} // namespace #else // CGAL_HEADER_ONLY -inline -static int& get_static_mode() +namespace { +inline int& get_static_mode() { return IO::mode; } +} // namespace #endif // CGAL_HEADER_ONLY CGAL_INLINE_FUNCTION @@ -122,6 +124,48 @@ mode_name( IO::Mode m) { return names[m]; } +CGAL_INLINE_FUNCTION +std::ostream& operator<<( std::ostream& out, const Color& col) +{ + switch(out.iword(get_static_mode())) { + case IO::ASCII : + return out << static_cast(col.red()) << ' ' + << static_cast(col.green()) << ' ' + << static_cast(col.blue()); + case IO::BINARY : + write(out, static_cast(col.red())); + write(out, static_cast(col.green())); + write(out, static_cast(col.blue())); + return out; + default: + return out << "Color(" << static_cast(col.red()) << ", " + << static_cast(col.green()) << ", " + << static_cast(col.blue()) << ')'; + } +} + +CGAL_INLINE_FUNCTION +std::istream &operator>>(std::istream &is, Color& col) +{ + int r = 0, g = 0, b = 0; + switch(is.iword(get_static_mode())) { + case IO::ASCII : + is >> r >> g >> b; + break; + case IO::BINARY : + read(is, r); + read(is, g); + read(is, b); + break; + default: + std::cerr << "" << std::endl; + std::cerr << "Stream must be in ascii or binary mode" << std::endl; + break; + } + col = Color((unsigned char)r,(unsigned char)g,(unsigned char)b); + return is; +} + CGAL_INLINE_FUNCTION void swallow(std::istream &is, char d) { diff --git a/Stream_support/src/CGAL/Color.cpp b/Stream_support/src/CGAL/Color.cpp index f63912940c3..3d4e3bf882d 100644 --- a/Stream_support/src/CGAL/Color.cpp +++ b/Stream_support/src/CGAL/Color.cpp @@ -22,5 +22,9 @@ // // Author(s) : Andreas Fabri, Hervé Brönnimann +#ifndef CGAL_HEADER_ONLY + #include #include + +#endif // CGAL_HEADER_ONLY diff --git a/Stream_support/src/CGAL/File_header_OFF.cpp b/Stream_support/src/CGAL/File_header_OFF.cpp index 375822c4cf1..c70a2c3a0bf 100644 --- a/Stream_support/src/CGAL/File_header_OFF.cpp +++ b/Stream_support/src/CGAL/File_header_OFF.cpp @@ -22,7 +22,11 @@ // // Author(s) : Lutz Kettner +#ifndef CGAL_HEADER_ONLY + #include #include +#endif // CGAL_HEADER_ONLY + // EOF // diff --git a/Stream_support/src/CGAL/File_header_extended_OFF.cpp b/Stream_support/src/CGAL/File_header_extended_OFF.cpp index 43e0e30ff79..735fe404387 100644 --- a/Stream_support/src/CGAL/File_header_extended_OFF.cpp +++ b/Stream_support/src/CGAL/File_header_extended_OFF.cpp @@ -22,7 +22,11 @@ // // Author(s) : Lutz Kettner +#ifndef CGAL_HEADER_ONLY + #include #include +#endif // CGAL_HEADER_ONLY + // EOF // diff --git a/Stream_support/src/CGAL/File_scanner_OFF.cpp b/Stream_support/src/CGAL/File_scanner_OFF.cpp index 21d85d72c9c..b7e1ed08838 100644 --- a/Stream_support/src/CGAL/File_scanner_OFF.cpp +++ b/Stream_support/src/CGAL/File_scanner_OFF.cpp @@ -22,7 +22,11 @@ // // Author(s) : Lutz Kettner +#ifndef CGAL_HEADER_ONLY + #include #include +#endif // CGAL_HEADER_ONLY + // EOF // diff --git a/Stream_support/src/CGAL/File_writer_OFF.cpp b/Stream_support/src/CGAL/File_writer_OFF.cpp index 51ff52b3e05..6162f9ad34e 100644 --- a/Stream_support/src/CGAL/File_writer_OFF.cpp +++ b/Stream_support/src/CGAL/File_writer_OFF.cpp @@ -22,7 +22,11 @@ // // Author(s) : Lutz Kettner +#ifndef CGAL_HEADER_ONLY + #include #include +#endif // CGAL_HEADER_ONLY + // EOF // diff --git a/Stream_support/src/CGAL/File_writer_VRML_2.cpp b/Stream_support/src/CGAL/File_writer_VRML_2.cpp index c18f90ceda9..a595f0f3b48 100644 --- a/Stream_support/src/CGAL/File_writer_VRML_2.cpp +++ b/Stream_support/src/CGAL/File_writer_VRML_2.cpp @@ -22,7 +22,11 @@ // // Author(s) : Lutz Kettner +#ifndef CGAL_HEADER_ONLY + #include #include +#endif // CGAL_HEADER_ONLY + // EOF // diff --git a/Stream_support/src/CGAL/File_writer_inventor.cpp b/Stream_support/src/CGAL/File_writer_inventor.cpp index fecb6106fea..7c669692802 100644 --- a/Stream_support/src/CGAL/File_writer_inventor.cpp +++ b/Stream_support/src/CGAL/File_writer_inventor.cpp @@ -22,7 +22,11 @@ // // Author(s) : Lutz Kettner +#ifndef CGAL_HEADER_ONLY + #include #include +#endif // CGAL_HEADER_ONLY + // EOF // diff --git a/Stream_support/src/CGAL/File_writer_wavefront.cpp b/Stream_support/src/CGAL/File_writer_wavefront.cpp index e2a948199f0..d7c4ec4845c 100644 --- a/Stream_support/src/CGAL/File_writer_wavefront.cpp +++ b/Stream_support/src/CGAL/File_writer_wavefront.cpp @@ -22,7 +22,11 @@ // // Author(s) : Lutz Kettner +#ifndef CGAL_HEADER_ONLY + #include #include +#endif // CGAL_HEADER_ONLY + // EOF // diff --git a/Stream_support/src/CGAL/io.cpp b/Stream_support/src/CGAL/io.cpp index a94c72a4af3..6514769ace3 100644 --- a/Stream_support/src/CGAL/io.cpp +++ b/Stream_support/src/CGAL/io.cpp @@ -22,11 +22,11 @@ // // Author(s) : Andreas Fabri +#ifndef CGAL_HEADER_ONLY + #include #include -#ifndef CGAL_HEADER_ONLY - namespace CGAL { int IO::mode = std::ios::xalloc(); From 74c9ac90c777c1afdbd74554483ba8fc8903fa0d Mon Sep 17 00:00:00 2001 From: Guillaume Damiand Date: Fri, 31 Oct 2014 18:48:26 +0100 Subject: [PATCH 06/30] add cppfile --- cppfiles.txt | 74 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 cppfiles.txt diff --git a/cppfiles.txt b/cppfiles.txt new file mode 100644 index 00000000000..b85d1d3e216 --- /dev/null +++ b/cppfiles.txt @@ -0,0 +1,74 @@ +CGAL: + +Clement: + +#include "/home/gdamiand/sources/CGAL/Geomview/src/CGAL/Geomview_stream.cpp" +#include "/home/gdamiand/sources/CGAL/Nef_2/src/CGAL/NefPolynomial.cpp" +#include "/home/gdamiand/sources/CGAL/Kinetic_data_structures/src/CGAL/JAMA_numeric_solver.cpp" +#include "/home/gdamiand/sources/CGAL/Kinetic_data_structures/src/CGAL/KDS_Log.cpp" +#include "/home/gdamiand/sources/CGAL/Kinetic_data_structures/src/CGAL/numeric_solvers_support.cpp" +#include "/home/gdamiand/sources/CGAL/Kinetic_data_structures/src/CGAL/Turkowski_numeric_solver.cpp" +#include "/home/gdamiand/sources/CGAL/Profiling_tools/src/CGAL/Timer.cpp" // static mais doit pouvoir se remplacer en membre +#include "/home/gdamiand/sources/CGAL/Profiling_tools/src/CGAL/Real_timer.cpp" // static mais doit pouvoir se remplacer en membre +#include "/home/gdamiand/sources/CGAL/Random_numbers/src/CGAL/Random.cpp" // static mais doit pouvoir se remplacer en membre +#include "/home/gdamiand/sources/CGAL/Number_types/src/CGAL/test_FPU_rounding_mode.cpp" // static const +#include "/home/gdamiand/sources/CGAL/Modular_arithmetic/src/CGAL/Residue_type.cpp" +#include "/home/gdamiand/sources/CGAL/Modular_arithmetic/src/CGAL/primes.cpp" + +Guillaume + +#include "/home/gdamiand/sources/CGAL/STL_Extension/src/CGAL/assertions.cpp" // variables globales +#include "/home/gdamiand/sources/CGAL/Stream_support/src/CGAL/io.cpp" // variable statique de classe +#include "/home/gdamiand/sources/CGAL/Stream_support/src/CGAL/Color.cpp" // constantes globales +#include "/home/gdamiand/sources/CGAL/Kernel_23/src/CGAL/kernel.cpp" // constantes globales +#include "/home/gdamiand/sources/CGAL/Number_types/src/CGAL/Interval_arithmetic.cpp" // constante globale + +#include "/home/gdamiand/sources/CGAL/Intersections_2/src/CGAL/Bbox_2_intersections.cpp" +#include "/home/gdamiand/sources/CGAL/Stream_support/src/CGAL/File_header_extended_OFF.cpp" +#include "/home/gdamiand/sources/CGAL/Stream_support/src/CGAL/File_writer_inventor.cpp" +#include "/home/gdamiand/sources/CGAL/Stream_support/src/CGAL/File_header_OFF.cpp" +#include "/home/gdamiand/sources/CGAL/Stream_support/src/CGAL/File_scanner_OFF.cpp" +#include "/home/gdamiand/sources/CGAL/Stream_support/src/CGAL/File_writer_OFF.cpp" +#include "/home/gdamiand/sources/CGAL/Stream_support/src/CGAL/File_writer_VRML_2.cpp" +#include "/home/gdamiand/sources/CGAL/Stream_support/src/CGAL/File_writer_wavefront.cpp" + +CGAL_Core: + +#include "/home/gdamiand/sources/CGAL/CGAL_Core/src/CGAL_Core/CoreIO.cpp" +#include "/home/gdamiand/sources/CGAL/CGAL_Core/src/CGAL_Core/CoreAux.cpp" +#include "/home/gdamiand/sources/CGAL/CGAL_Core/src/CGAL_Core/CoreDefs.cpp" +#include "/home/gdamiand/sources/CGAL/CGAL_Core/src/CGAL_Core/Expr.cpp" +#include "/home/gdamiand/sources/CGAL/CGAL_Core/src/CGAL_Core/GmpIO.cpp" +#include "/home/gdamiand/sources/CGAL/CGAL_Core/src/CGAL_Core/BigFloat.cpp" +#include "/home/gdamiand/sources/CGAL/CGAL_Core/src/CGAL_Core/Real.cpp" +#include "/home/gdamiand/sources/CGAL/CGAL_Core/src/CGAL_Core/extLong.cpp" + +CGAL_ImageIO: + +#include "/home/gdamiand/sources/CGAL/CGAL_ImageIO/src/CGAL_ImageIO/bmpread.cpp" +#include "/home/gdamiand/sources/CGAL/CGAL_ImageIO/src/CGAL_ImageIO/mincio.cpp" +#include "/home/gdamiand/sources/CGAL/CGAL_ImageIO/src/CGAL_ImageIO/analyze.cpp" +#include "/home/gdamiand/sources/CGAL/CGAL_ImageIO/src/CGAL_ImageIO/recline.cpp" +#include "/home/gdamiand/sources/CGAL/CGAL_ImageIO/src/CGAL_ImageIO/convert.cpp" +#include "/home/gdamiand/sources/CGAL/CGAL_ImageIO/src/CGAL_ImageIO/recbuffer.cpp" +#include "/home/gdamiand/sources/CGAL/CGAL_ImageIO/src/CGAL_ImageIO/gif.cpp" +#include "/home/gdamiand/sources/CGAL/CGAL_ImageIO/src/CGAL_ImageIO/reech4x4.cpp" +#include "/home/gdamiand/sources/CGAL/CGAL_ImageIO/src/CGAL_ImageIO/gis.cpp" +#include "/home/gdamiand/sources/CGAL/CGAL_ImageIO/src/CGAL_ImageIO/bmp.cpp" +#include "/home/gdamiand/sources/CGAL/CGAL_ImageIO/src/CGAL_ImageIO/bmpendian.cpp" +#include "/home/gdamiand/sources/CGAL/CGAL_ImageIO/src/CGAL_ImageIO/iris.cpp" +#include "/home/gdamiand/sources/CGAL/CGAL_ImageIO/src/CGAL_ImageIO/fgetns.cpp" +#include "/home/gdamiand/sources/CGAL/CGAL_ImageIO/src/CGAL_ImageIO/Image_3.cpp" +#include "/home/gdamiand/sources/CGAL/CGAL_ImageIO/src/CGAL_ImageIO/pnm.cpp" +#include "/home/gdamiand/sources/CGAL/CGAL_ImageIO/src/CGAL_ImageIO/ImageIO.cpp" +#include "/home/gdamiand/sources/CGAL/CGAL_ImageIO/src/CGAL_ImageIO/inr.cpp" + +CGAL_Qt4: + +DONE #include "/home/gdamiand/sources/CGAL/GraphicsView/src/CGAL_Qt4/utility.cpp" + +#include "/home/gdamiand/sources/CGAL/GraphicsView/src/CGAL_Qt4/resources.cpp" +#include "/home/gdamiand/sources/CGAL/GraphicsView/src/CGAL_Qt4/debug.cpp" +#include "/home/gdamiand/sources/CGAL/GraphicsView/src/CGAL_Qt4/GraphicsViewPolylineInput.cpp" +#include "/home/gdamiand/sources/CGAL/GraphicsView/src/CGAL_Qt4/DemosMainWindow.cpp" +#include "/home/gdamiand/sources/CGAL/GraphicsView/src/CGAL_Qt4/GraphicsViewNavigation.cpp" From 941824738e9d344d03fb7129618646d7fc122a33 Mon Sep 17 00:00:00 2001 From: Guillaume Damiand Date: Fri, 31 Oct 2014 19:20:18 +0100 Subject: [PATCH 07/30] Header files for GraphicsView --- .../include/CGAL/Qt/DemosMainWindow.h | 4 + .../include/CGAL/Qt/GraphicsViewNavigation.h | 4 + .../CGAL/Qt/GraphicsViewPolylineInput.h | 4 + GraphicsView/include/CGAL/Qt/debug.h | 3 + GraphicsView/include/CGAL/Qt/resources.h | 4 + GraphicsView/include/CGAL/Qt/utility.h | 4 + GraphicsView/src/CGAL_Qt4/DemosMainWindow.cpp | 386 +----------------- .../src/CGAL_Qt4/GraphicsViewNavigation.cpp | 319 +-------------- .../CGAL_Qt4/GraphicsViewPolylineInput.cpp | 175 +------- GraphicsView/src/CGAL_Qt4/debug.cpp | 34 +- GraphicsView/src/CGAL_Qt4/resources.cpp | 14 +- GraphicsView/src/CGAL_Qt4/utility.cpp | 35 +- .../demo/Linear_cell_complex/CMakeLists.txt | 2 +- cppfiles.txt | 11 +- 14 files changed, 52 insertions(+), 947 deletions(-) diff --git a/GraphicsView/include/CGAL/Qt/DemosMainWindow.h b/GraphicsView/include/CGAL/Qt/DemosMainWindow.h index bbac07903b2..6e9f7869cd6 100644 --- a/GraphicsView/include/CGAL/Qt/DemosMainWindow.h +++ b/GraphicsView/include/CGAL/Qt/DemosMainWindow.h @@ -122,4 +122,8 @@ protected: Q_DECLARE_OPERATORS_FOR_FLAGS(CGAL::Qt::DemosMainWindow::Options) +#ifdef CGAL_HEADER_ONLY +#include +#endif // CGAL_HEADER_ONLY + #endif // CGAL_QT_DEMOS_MAIN_WINDOW_H diff --git a/GraphicsView/include/CGAL/Qt/GraphicsViewNavigation.h b/GraphicsView/include/CGAL/Qt/GraphicsViewNavigation.h index 76e9352e74e..0254d65d356 100644 --- a/GraphicsView/include/CGAL/Qt/GraphicsViewNavigation.h +++ b/GraphicsView/include/CGAL/Qt/GraphicsViewNavigation.h @@ -69,4 +69,8 @@ private: } // namespace Qt } // namespace CGAL +#ifdef CGAL_HEADER_ONLY +#include +#endif // CGAL_HEADER_ONLY + #endif // CGAL_QT_GRAPHICS_VIEW_NAVIGATION_H diff --git a/GraphicsView/include/CGAL/Qt/GraphicsViewPolylineInput.h b/GraphicsView/include/CGAL/Qt/GraphicsViewPolylineInput.h index c9078d3c76d..6f56a9a03c3 100644 --- a/GraphicsView/include/CGAL/Qt/GraphicsViewPolylineInput.h +++ b/GraphicsView/include/CGAL/Qt/GraphicsViewPolylineInput.h @@ -107,4 +107,8 @@ protected: } // namespace Qt } // namespace CGAL +#ifdef CGAL_HEADER_ONLY +#include +#endif // CGAL_HEADER_ONLY + #endif // CGAL_QT_GRAPHICS_VIEW_POLYLINE_INPUT_H diff --git a/GraphicsView/include/CGAL/Qt/debug.h b/GraphicsView/include/CGAL/Qt/debug.h index d886332b171..42ead5ee358 100644 --- a/GraphicsView/include/CGAL/Qt/debug.h +++ b/GraphicsView/include/CGAL/Qt/debug.h @@ -43,5 +43,8 @@ CGAL_QT4_EXPORT void traverse_resources(const QString& name, } // namespace Qt } // namespace CGAL +#ifdef CGAL_HEADER_ONLY +#include +#endif // CGAL_HEADER_ONLY #endif // CGAL_QT_DEBUG_H diff --git a/GraphicsView/include/CGAL/Qt/resources.h b/GraphicsView/include/CGAL/Qt/resources.h index 2e390d04bc3..7bb04b2ecfe 100644 --- a/GraphicsView/include/CGAL/Qt/resources.h +++ b/GraphicsView/include/CGAL/Qt/resources.h @@ -30,4 +30,8 @@ CGAL_QT4_EXPORT void CGAL_Qt4_init_resources(); // The do{}while(0) trick is used to make that macro value a regular // statement and not a compound statement. +#ifdef CGAL_HEADER_ONLY +#include +#endif // CGAL_HEADER_ONLY + #endif // CGAL_QT_RESOURCES_H diff --git a/GraphicsView/include/CGAL/Qt/utility.h b/GraphicsView/include/CGAL/Qt/utility.h index 5221beb0e75..0a81e0d1c5f 100644 --- a/GraphicsView/include/CGAL/Qt/utility.h +++ b/GraphicsView/include/CGAL/Qt/utility.h @@ -39,4 +39,8 @@ CGAL_QT4_EXPORT QRectF viewportsBbox(const QGraphicsScene*); } // namespace Qt } // namespace CGAL +#ifdef CGAL_HEADER_ONLY +#include +#endif // CGAL_HEADER_ONLY + #endif // CGAL_QT_UTILITY_H diff --git a/GraphicsView/src/CGAL_Qt4/DemosMainWindow.cpp b/GraphicsView/src/CGAL_Qt4/DemosMainWindow.cpp index d43b5e00fc4..0e3c0f5462d 100644 --- a/GraphicsView/src/CGAL_Qt4/DemosMainWindow.cpp +++ b/GraphicsView/src/CGAL_Qt4/DemosMainWindow.cpp @@ -19,389 +19,9 @@ // Author(s) : Andreas Fabri // Laurent Rineau -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#ifndef CGAL_HEADER_ONLY -#include // needed to get CGAL_VERSION_STR #include -#include +#include -namespace CGAL { -namespace Qt { - -DemosMainWindow::DemosMainWindow(QWidget * parent, ::Qt::WindowFlags flags) - : QMainWindow(parent, flags), - maxNumRecentFiles(10), - recentFileActs(maxNumRecentFiles) -{ - // prepare the QLabel xycoord for inclusion in the statusBar() - xycoord = new QLabel(" -0.00000 , -0.00000 ", this); - xycoord->setAlignment(::Qt::AlignHCenter); - xycoord->setMinimumSize(xycoord->sizeHint()); - xycoord->clear(); - - actionUse_OpenGL = new QAction(this); - actionUse_OpenGL->setObjectName("actionUse_OpenGL"); - actionUse_OpenGL->setCheckable(true); - actionUse_OpenGL->setText(tr("Use &OpenGL")); - actionUse_OpenGL->setStatusTip(tr("Make Qt use OpenGL to display the graphical items, instead of its native painting system.")); - actionUse_OpenGL->setShortcut(tr("Ctrl+G")); - - actionUse_Antialiasing = new QAction(this); - actionUse_Antialiasing->setObjectName("actionUse_Antialiasing"); - actionUse_Antialiasing->setCheckable(true); - actionUse_Antialiasing->setText(tr("Use &anti-aliasing")); - actionUse_Antialiasing->setStatusTip(tr("Make Qt use anti-aliasing when displaying the graphical items.")); - actionUse_Antialiasing->setShortcut(tr("Ctrl+A")); - - actionAboutCGAL = new QAction(this); - actionAboutCGAL->setObjectName("actionAboutCGAL"); - actionAboutCGAL->setText(tr("About &CGAL...")); - - actionAbout = new QAction(this); - actionAbout->setObjectName("actionAbout"); - actionAbout->setText(tr("&About...")); - - setAcceptDrops(true); -} - - -void -DemosMainWindow::dragEnterEvent(QDragEnterEvent *event) -{ - if (event->mimeData()->hasFormat("text/uri-list")) - event->acceptProposedAction(); -} - -void -DemosMainWindow::dropEvent(QDropEvent *event) -{ - Q_FOREACH(QUrl url, event->mimeData()->urls()) { - QString filename = url.toLocalFile(); - this->open(filename); - } - event->acceptProposedAction(); -} - -void -DemosMainWindow::addNavigation(QGraphicsView* graphicsView) -{ - navigation = new CGAL::Qt::GraphicsViewNavigation(); - graphicsView->viewport()->installEventFilter(navigation); - graphicsView->installEventFilter(navigation); - QObject::connect(navigation, SIGNAL(mouseCoordinates(QString)), - xycoord, SLOT(setText(QString))); - view = graphicsView; -} - -void -DemosMainWindow::setupStatusBar() -{ - this->statusBar()->addWidget(new QLabel(this), 1); - this->statusBar()->addWidget(xycoord, 0); -} - -void -DemosMainWindow::setupOptionsMenu(QMenu* menuOptions) -{ - // search for the Options menu - if(!menuOptions) { - menuOptions = getMenu("menuOptions", tr("&Options")); - } - - // if not found, then create it - if(!menuOptions) { - menuOptions = new QMenu(this->menuBar()); - menuOptions->setTitle(tr("&Options")); - this->menuBar()->addAction(menuOptions->menuAction()); - menuOptions->setObjectName("menuOptions"); - } - - if(!menuOptions->isEmpty()) { - menuOptions->addSeparator(); - } - menuOptions->addAction(actionUse_OpenGL); - menuOptions->addAction(actionUse_Antialiasing); - connect(actionUse_Antialiasing, SIGNAL(toggled(bool)), - this, SLOT(setUseAntialiasing(bool))); - connect(actionUse_OpenGL, SIGNAL(toggled(bool)), - this, SLOT(setUseOpenGL(bool))); - actionUse_Antialiasing->setChecked(true); -} - -void -DemosMainWindow::setUseAntialiasing(bool checked) -{ - view->setRenderHint(QPainter::Antialiasing, checked); -#if QT_VERSION >= 0x040300 - view->setRenderHint(QPainter::HighQualityAntialiasing, checked); -#endif - statusBar()->showMessage(tr("Antialiasing %1activated").arg(checked?"":"de-"), - 1000); -} - -void -DemosMainWindow::setUseOpenGL(bool checked) -{ - if(checked) { - QGLWidget* new_viewport = new QGLWidget; - - // Setup the format to allow antialiasing with OpenGL: - // one need to activate the SampleBuffers, if the graphic driver allows - // this. - QGLFormat glformat = new_viewport->format(); - glformat.setOption(QGL::SampleBuffers); - new_viewport->setFormat(glformat); - - view->setViewport(new_viewport); - } - else { - view->setViewport(new QWidget); - } - statusBar()->showMessage(tr("OpenGL %1activated").arg(checked?"":"de-"), - 1000); - view->viewport()->installEventFilter(navigation); - view->setFocus(); -} - -QMenu* -DemosMainWindow::getMenu(QString objectName, QString title) -{ - QMenu* menu = NULL; - - QString title2 = title; - title2.remove('&'); - // search if a menu has objectName()==objectName - menu = this->findChild(objectName); - - // then search if a menu has title()==title - if(menu) { - return menu; - } else { - Q_FOREACH(menu, this->findChildren()) { - if(menu->title() == title || - menu->title() == title2) { - return menu; - } - } - } - return NULL; -} - -void -DemosMainWindow::popupAboutBox(QString title, QString html_resource_name) -{ - QFile about_CGAL(html_resource_name); - about_CGAL.open(QIODevice::ReadOnly); - QString about_CGAL_txt = QTextStream(&about_CGAL).readAll(); -#ifdef CGAL_VERSION_STR - QString cgal_version(CGAL_VERSION_STR); -# ifdef CGAL_FAKE_PUBLIC_RELEASE - cgal_version.replace(QRegExp("-Ic?.*"), ""); -# endif - about_CGAL_txt.replace("", - QString(" (version %1)") - .arg(cgal_version)); -#endif - QMessageBox mb(QMessageBox::NoIcon, - title, - about_CGAL_txt, - QMessageBox::Ok, - this); - - QLabel* mb_label = mb.findChild("qt_msgbox_label"); - if(mb_label) { - mb_label->setTextInteractionFlags(mb_label->textInteractionFlags() | - ::Qt::LinksAccessibleByMouse | - ::Qt::LinksAccessibleByKeyboard); - } - else { - std::cerr << "Cannot find child \"qt_msgbox_label\" in QMessageBox\n" - << " with Qt version " << QT_VERSION_STR << "!\n"; - } - mb.exec(); -} - -QMenu* DemosMainWindow::getHelpMenu() -{ - QMenu* menuHelp = getMenu("menuHelp", tr("&Help")); - if(!menuHelp) { - menuHelp = new QMenu(this->menuBar()); - menuHelp->setTitle(tr("&Help")); - this->menuBar()->addAction(menuHelp->menuAction()); - menuHelp->setObjectName("menuHelp"); - } - return menuHelp; -} - -void -DemosMainWindow::addAboutCGAL(QMenu* menuHelp) -{ - if(!menuHelp) { - menuHelp = getHelpMenu(); - } - menuHelp->addAction(actionAboutCGAL); - - connect(actionAboutCGAL, SIGNAL(triggered()), - this, SLOT(popupAboutCGAL())); -} - -void -DemosMainWindow::addAboutDemo(QString htmlResourceName, QMenu* menuHelp) -{ - if(!menuHelp) { - menuHelp = getHelpMenu(); - } - menuHelp->addAction(actionAbout); - aboutHtmlResource = htmlResourceName; - - connect(actionAbout, SIGNAL(triggered()), - this, SLOT(popupAboutDemo())); -} - -void -DemosMainWindow::popupAboutCGAL() -{ - popupAboutBox(tr("About CGAL..."), - ":/cgal/help/about_CGAL.html"); -} - -void -DemosMainWindow::popupAboutDemo() -{ - popupAboutBox(tr("About the demo..."), - aboutHtmlResource); -} - -void -DemosMainWindow::setMaxNumberOfRecentFiles(const unsigned int i) -{ - maxNumRecentFiles = i; - recentFileActs.resize(maxNumRecentFiles); -} - -unsigned int -DemosMainWindow::maxNumberOfRecentFiles() const -{ - return maxNumRecentFiles; -} - -void -DemosMainWindow::openRecentFile_aux() -{ - QAction *action = qobject_cast(sender()); - if (action) - emit openRecentFile(action->data().toString()); -} - -void -DemosMainWindow::addToRecentFiles(QString fileName) -{ - QSettings settings; - QStringList files = settings.value("recentFileList").toStringList(); - files.removeAll(fileName); - files.prepend(fileName); - while (files.size() > (int)maxNumberOfRecentFiles()) - files.removeLast(); - - settings.setValue("recentFileList", files); - - updateRecentFileActions(); -} - -void -DemosMainWindow::addRecentFiles(QMenu* menu, QAction* insertBeforeAction) -{ - if(!insertBeforeAction) { - recentFilesSeparator = menu->addSeparator(); - } - - for (unsigned int i = 0; i < maxNumberOfRecentFiles(); ++i) { - recentFileActs[i] = new QAction(this); - recentFileActs[i]->setVisible(false); - connect(recentFileActs[i], SIGNAL(triggered()), - this, SLOT(openRecentFile_aux())); - if(insertBeforeAction) - menu->insertAction(insertBeforeAction, recentFileActs[i]); - else - menu->addAction(recentFileActs[i]); - } - - if(insertBeforeAction) { - recentFilesSeparator = menu->insertSeparator(insertBeforeAction); - } - - recentFilesSeparator->setVisible(false); - - updateRecentFileActions(); -} - -void -DemosMainWindow::updateRecentFileActions() -{ - QSettings settings; - QStringList files = settings.value("recentFileList").toStringList(); - - int numRecentFiles = qMin(files.size(), (int)this->maxNumberOfRecentFiles()); - - for (int i = 0; i < numRecentFiles; ++i) { - QString strippedName = QFileInfo(files[i]).fileName(); - QString text = tr("&%1 %2").arg(i).arg(strippedName); - recentFileActs[i]->setText(text); - recentFileActs[i]->setData(files[i]); - recentFileActs[i]->setVisible(true); - } - for (unsigned int j = numRecentFiles; j < maxNumberOfRecentFiles(); ++j) - recentFileActs[j]->setVisible(false); - - recentFilesSeparator->setVisible(numRecentFiles > 0); -} - -void DemosMainWindow::writeState(QString groupname) -{ - QSettings settings; - - settings.beginGroup(groupname); - settings.setValue("size", size()); - settings.setValue("pos", pos()); - settings.setValue("state", saveState()); - settings.endGroup(); -} - -void DemosMainWindow::readState(QString groupname, Options /*what_to_save*/) -{ - QSettings settings; - - settings.beginGroup(groupname); - resize(settings.value("size", this->size()).toSize()); - - QDesktopWidget* desktop = qApp->desktop(); - QPoint pos = settings.value("pos", this->pos()).toPoint(); - if(desktop->availableGeometry(pos).contains(pos)) { - move(pos); - } - QByteArray mainWindowState = settings.value("state").toByteArray(); - if(!mainWindowState.isNull()) { - this->restoreState(mainWindowState); - } - settings.endGroup(); -} - - -} // namespace Qt -} // namespace CGAL +#endif // CGAL_HEADER_ONLY diff --git a/GraphicsView/src/CGAL_Qt4/GraphicsViewNavigation.cpp b/GraphicsView/src/CGAL_Qt4/GraphicsViewNavigation.cpp index 712c4bb9a66..66fd8c0f887 100644 --- a/GraphicsView/src/CGAL_Qt4/GraphicsViewNavigation.cpp +++ b/GraphicsView/src/CGAL_Qt4/GraphicsViewNavigation.cpp @@ -19,320 +19,9 @@ // Author(s) : Andreas Fabri // Laurent Rineau +#ifndef CGAL_HEADER_ONLY + #include -#include // for mapToScene(QGraphicsView*, QRect) -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include - -namespace CGAL { -namespace Qt { - - GraphicsViewNavigation::GraphicsViewNavigation() - : rectItem(new QGraphicsRectItem), - dragging(false) - { - QColor rect_color(250, 221, 0); - rect_color.setAlpha(50); - rectItem->setBrush(rect_color); - rect_color.setAlpha(255); - rectItem->setPen(QPen(rect_color, 0, ::Qt::DashLine)); - rectItem->hide(); - rectItem->setZValue(10000); - } - - GraphicsViewNavigation::~GraphicsViewNavigation() - { - delete rectItem; - } - - bool - GraphicsViewNavigation::eventFilter(QObject *obj, QEvent *event) - { - QGraphicsView* v = qobject_cast(obj); - if(v == NULL) { - QWidget* viewport = qobject_cast(obj); - if(viewport == NULL) { - return false; - } - v = qobject_cast(viewport->parent()); - if(v == NULL) { - return false; - } - } - switch(event->type()) - { - case QEvent::KeyPress: { - QKeyEvent *keyEvent = static_cast(event); - int offset = 10; - if( (keyEvent->modifiers() & ::Qt::ShiftModifier) - || (keyEvent->modifiers() & ::Qt::ControlModifier) ) { - offset = 20; - } - switch (keyEvent->key()) { - case ::Qt::Key_Up: - translateView(v, 0, -offset); - break; - case ::Qt::Key_Down: - translateView(v, 0, offset); - break; - case ::Qt::Key_Left: - translateView(v, -offset, 0); - break; - case ::Qt::Key_Right: - translateView(v, offset, 0); - break; - case ::Qt::Key_PageUp: - v->rotate(-6); - break; - case ::Qt::Key_PageDown: - v->rotate(6); - break; - case ::Qt::Key_Plus: - scaleView(v, 1.2); - break; - case ::Qt::Key_Minus: - scaleView(v, 1 / 1.2); - break; - case ::Qt::Key_Control: - cursor_backup = v->cursor(); - v->setCursor(::Qt::CrossCursor); - default: - return false; - } - // display_parameters(); - return true; - break; - } // end case KeyPress - case QEvent::KeyRelease: { - QKeyEvent *keyEvent = static_cast(event); - if(keyEvent->key() == ::Qt::Key_Control) { - if(rectItem->isVisible() ) { - dragging = false; - v->scene()->removeItem(rectItem); - rectItem->hide(); - } - v->setCursor(cursor_backup); - return true; - } - return false; - break; - } // end case KeyRelease - case QEvent::Wheel: { - QWheelEvent *wheelEvent = static_cast(event); - if(wheelEvent->orientation() != ::Qt::Vertical) { - return false; - } - double zoom_ratio = 240.0; - if( (wheelEvent->modifiers() & ::Qt::ShiftModifier) - || (wheelEvent->modifiers() & ::Qt::ControlModifier) ) { - zoom_ratio = 120.0; - } - scaleView(v, pow((double)2, -wheelEvent->delta() / zoom_ratio)); - - // display_parameters(); - return true; - break; - } // end case Wheel - case QEvent::MouseButtonPress: { - QMouseEvent* mouseEvent = static_cast(event); - if( (mouseEvent->modifiers() == (::Qt::ControlModifier | ::Qt::ShiftModifier)) - && mouseEvent->button() == ::Qt::RightButton ) - { - QPoint offset = mouseEvent->pos() - v->viewport()->rect().center(); - translateView(v, offset.x(), offset.y()); - return true; - } - else if( mouseEvent->modifiers() == ::Qt::ControlModifier ) { - if(mouseEvent->button() == ::Qt::LeftButton) { - rect_first_point = v->mapToScene(mouseEvent->pos()); - rectItem->setRect(QRectF(rect_first_point, QSizeF(0.,0.))); - rectItem->show(); - v->scene()->addItem(rectItem); - return true; - } - else if( mouseEvent->button() == ::Qt::RightButton) { - dragging = true; - dragging_start = v->mapToScene(mouseEvent->pos()); - v->setCursor(::Qt::ClosedHandCursor); - return true; - } - } - return false; - break; - } // end case MouseRelease - case QEvent::MouseMove: { - QMouseEvent* mouseEvent = static_cast(event); - QPointF pos = v->mapToScene(mouseEvent->pos()); - QString xy = QString(" ") + QString::number(pos.x(),'g', 6) + " , " + QString::number(pos.y(),'g', 6) + " "; - emit mouseCoordinates(xy); - if(rectItem->isVisible()) { - QPointF size = v->mapToScene(mouseEvent->pos()); - size = size - rect_first_point; - rectItem->setRect(rect_first_point.x(), - rect_first_point.y(), - size.x(), - size.y()); - } - if( dragging ) - { -// std::cerr << boost::format("mouseMove: globalpos=(%1%, %2%)\n" -// " pos=(%3%, %4%)\n" -// " sender=%5% (class %6%), parent class %7%\n") -// % mouseEvent->globalPos().x() -// % mouseEvent->globalPos().y() -// % mouseEvent->pos().x() -// % mouseEvent->pos().y() -// % (&*obj) -// % obj->metaObject()->className() -// % obj->parent()->metaObject()->className(); - -// drag_to(mouseEvent->pos()); - } - break; - } // end MouseMove - case QEvent::MouseButtonRelease: { - QMouseEvent* mouseEvent = static_cast(event); - if(rectItem->isVisible() && mouseEvent->button() == ::Qt::LeftButton){ - v->setSceneRect(v->sceneRect() | rectItem->rect()); - v->fitInView(rectItem->rect(), ::Qt::KeepAspectRatio); - v->scene()->removeItem(rectItem); - rectItem->hide(); - return true; - } - else if( mouseEvent->button() == ::Qt::RightButton ) { - if(dragging) { - dragging = false; - drag_to(v, mouseEvent->pos()); - v->setCursor(cursor_backup); - return true; - } - } - return false; - break; - } // end MouseRelease - default: - return false; - } // end switch - return false; - } - - - void - GraphicsViewNavigation::scaleView(QGraphicsView* v, qreal scaleFactor) - { - QPointF center = v->mapToScene(v->viewport()->rect().center()); -// qreal factor = v->matrix().scale(scaleFactor, scaleFactor).mapRect(QRectF(0, 0, 1, 1)).width(); - //if (factor < 0.001 || factor > 2000) - // return; - - v->scale(scaleFactor, scaleFactor); - QPoint offset = v->mapFromScene(center) - v->viewport()->rect().center(); - translateView(v, offset.x(), offset.y()); - } - - void GraphicsViewNavigation::drag_to(QGraphicsView* v, QPoint new_pos) - { - QPoint dragging_start_in_view = v->mapFromScene(dragging_start); - QPoint offset = new_pos - dragging_start_in_view; -// std::cerr << boost::format("drag_to: origin=(%1%, %2%)\n" -// " offset=(%3%, %4%)\n") -// % dragging_start_in_view.x() % dragging_start_in_view.y() -// % offset.x() % offset.y(); - translateView(v, -offset.x(), -offset.y()); - dragging_start_in_view = v->mapFromScene(dragging_start); -// std::cerr << boost::format(" after=(%1%, %2%)\n") -// % dragging_start_in_view.x() % dragging_start_in_view.y(); - } - - void GraphicsViewNavigation::translateView(QGraphicsView* v, int dx, int dy) - { - if( dx == 0 && dy == 0 ) { - return; - } - - int horizontalScrollBarValue = v->horizontalScrollBar()->value(); - int verticalScrollBarValue = v->verticalScrollBar()->value(); - - if( (horizontalScrollBarValue + dx <= - v->horizontalScrollBar()->maximum()) && - (horizontalScrollBarValue + dx >= - v->horizontalScrollBar()->minimum()) && - (verticalScrollBarValue + dy <= - v->verticalScrollBar()->maximum()) && - (verticalScrollBarValue + dy >= - v->verticalScrollBar()->minimum()) ) - { - v->horizontalScrollBar()->setValue(horizontalScrollBarValue + dx); - v->verticalScrollBar()->setValue(verticalScrollBarValue + dy); - } - else - { - QRect vp_rect = v->viewport()->rect(); - QPointF new_center = v->mapToScene(vp_rect.center() + QPoint(dx, dy)); - vp_rect |= vp_rect.translated(dx, dy); - QRectF rect = mapToScene(v, vp_rect); - v->setSceneRect(v->sceneRect() | rect); - v->centerOn(new_center); - - // QGraphicsView::centerOn makes rounding errors. - // The following two "if" make them unnoticable when dx==0 or dy==0. - if(dx == 0) { - v->horizontalScrollBar()->setValue(horizontalScrollBarValue); - } - if(dy == 0) { - v->verticalScrollBar()->setValue(verticalScrollBarValue); - } - } -// display_parameters(); - } - - void GraphicsViewNavigation::display_parameters(QGraphicsView* v) - { - std::cerr << - boost::format("matrix translation=(%1%, %2%)\n" - " rotation=(%3% - %4% )\n" - " (%5% - %6% )\n") - % v->matrix().dx() - % v->matrix().dy() - % v->matrix().m11() - % v->matrix().m12() - % v->matrix().m21() - % v->matrix().m22(); - - QRect vp_rect = v->viewport()->rect(); - QPoint vp_top_left = vp_rect.topLeft(); - QPoint vp_bottom_right = vp_rect.bottomRight(); - QPointF top_left = v->mapToScene(vp_top_left); - QPointF bottom_right = v->mapToScene(vp_bottom_right); - - std::cerr << - boost::format("view=(%1% - %2%) x (%3% - %4%)\n") - % top_left.x() % bottom_right.x() - % top_left.y() % bottom_right.y(); - std::cerr << - boost::format("viewport=(%1% - %2%) x (%3% - %4%)\n") - % vp_top_left.x() % vp_bottom_right.x() - % vp_top_left.y() % vp_bottom_right.y(); - std::cerr << - boost::format("scrollbars=(%1% <= %2% <= %3%) x (%4% <= %5% <= %6%)\n") - % v->horizontalScrollBar()->minimum() - % v->horizontalScrollBar()->value() - % v->horizontalScrollBar()->maximum() - % v->verticalScrollBar()->minimum() - % v->verticalScrollBar()->value() - % v->verticalScrollBar()->maximum(); - } - -} // namespace Qt -} // namespace CGAL +#include +#endif // CGAL_HEADER_ONLY diff --git a/GraphicsView/src/CGAL_Qt4/GraphicsViewPolylineInput.cpp b/GraphicsView/src/CGAL_Qt4/GraphicsViewPolylineInput.cpp index 7780ef0aa7b..c08bdeaa84b 100644 --- a/GraphicsView/src/CGAL_Qt4/GraphicsViewPolylineInput.cpp +++ b/GraphicsView/src/CGAL_Qt4/GraphicsViewPolylineInput.cpp @@ -19,178 +19,9 @@ // Author(s) : Andreas Fabri // Laurent Rineau -#include -#include -#include -#include -#include -#include -#include -#include -#include +#ifndef CGAL_HEADER_ONLY #include +#include -namespace CGAL { -namespace Qt { - -GraphicsViewPolylineInput_non_templated_base:: -GraphicsViewPolylineInput_non_templated_base(QObject* parent, - QGraphicsScene* s, - int n, - bool closed) - : GraphicsViewInput(parent), closed_(closed), path_item(NULL), b(NULL), e(NULL), n_(n), scene_(s) -{} - - -bool -GraphicsViewPolylineInput_non_templated_base::mousePressEvent(QGraphicsSceneMouseEvent *event) -{ - if( event->modifiers() ){ - return false; - } - if( event->button() != ::Qt::RightButton - && event->button() != ::Qt::LeftButton ){ - return false; - } - polygon.push_back(event->scenePos()); - if(path_item){ - scene_->removeItem(path_item); - delete path_item; - path_item = NULL; - } - if( (event->button() == ::Qt::RightButton) || (polygon.size() == n_) ){ - // call the virtual function generate_polygon(), that emit a - // CGAL::Object containing a list of points - generate_polygon(); - polygon.clear(); - if(b){ - scene_->removeItem(b); - delete b; - b = NULL; - } - if(e){ - scene_->removeItem(e); - delete e; - e = NULL; - } - return true; - } - if(event->button() == ::Qt::LeftButton){ - QPainterPath qpp; - qpp.addPolygon(polygon); - path_item = new QGraphicsPathItem(qpp); - path_item->setPen(QPen(::Qt::red, 0, ::Qt::SolidLine, ::Qt::RoundCap, ::Qt::RoundJoin)); - scene_->addItem(path_item); - return true; - } - return false; -} - - -void -GraphicsViewPolylineInput_non_templated_base::rubberbands(const QPointF& p) -{ - if(polygon.empty()){ - return; - } - if(!b && closed_ ){ - b = new QGraphicsLineItem(); - b->setPen(QPen(::Qt::red, 0, ::Qt::SolidLine, ::Qt::RoundCap, ::Qt::RoundJoin)); - scene_->addItem(b); - } - if( !e){ - e = new QGraphicsLineItem(); - e->setPen(QPen(::Qt::red, 0, ::Qt::SolidLine, ::Qt::RoundCap, ::Qt::RoundJoin)); - scene_->addItem(e); - } - if(closed_){ - QLineF bLine(polygon.front(), p); - b->setLine(bLine); - } - QLineF eLine(polygon.back(), p); - e->setLine(eLine); -} - - -void -GraphicsViewPolylineInput_non_templated_base::mouseMoveEvent(QGraphicsSceneMouseEvent *event) -{ - sp = event->scenePos(); - rubberbands(sp); -} - - -bool -GraphicsViewPolylineInput_non_templated_base::keyPressEvent ( QKeyEvent * event ) -{ - if( event->modifiers() ) - return false; - - switch(event->key()) - { - case ::Qt::Key_Delete: - case ::Qt::Key_Escape: - case ::Qt::Key_Backspace: - break; - default: - return false; - } - if(polygon.empty()){ - return true; - } - polygon.pop_back(); - if(polygon.empty()){ - if(b){ - scene_->removeItem(b); - delete b; - b = NULL; - } - if(e){ - scene_->removeItem(e); - delete e; - e = NULL; - } - return true; - } - if(path_item){ - scene_->removeItem(path_item); - delete path_item; - path_item = NULL; - } - QPainterPath qpp; - qpp.addPolygon(polygon); - path_item = new QGraphicsPathItem(qpp); - path_item->setPen(QPen(::Qt::red, 0, ::Qt::SolidLine, ::Qt::RoundCap, ::Qt::RoundJoin)); - scene_->addItem(path_item); - rubberbands(sp); - return true; -} - - - -bool -GraphicsViewPolylineInput_non_templated_base::eventFilter(QObject *obj, QEvent *event) -{ - if (event->type() == QEvent::GraphicsSceneMousePress) { - QGraphicsSceneMouseEvent *mouseEvent = static_cast(event); - if(!mousePressEvent(mouseEvent)) { - // standard event processing if mousePressEvent has returned false - return QObject::eventFilter(obj, event); - } - } else if (event->type() == QEvent::GraphicsSceneMouseMove) { - QGraphicsSceneMouseEvent *mouseEvent = static_cast(event); - mouseMoveEvent(mouseEvent); - return QObject::eventFilter(obj, event); - } else if (event->type() == QEvent::KeyPress) { - QKeyEvent *keyEvent = static_cast(event); - if(!keyPressEvent(keyEvent)) { - return QObject::eventFilter(obj, event); - } - } - // standard event processing if keyPressEvent has returned false - return QObject::eventFilter(obj, event); -} - -} // namespace Qt -} // namespace CGAL +#endif // CGAL_HEADER_ONLY diff --git a/GraphicsView/src/CGAL_Qt4/debug.cpp b/GraphicsView/src/CGAL_Qt4/debug.cpp index 6d7712ac73b..a75a5c27ff2 100644 --- a/GraphicsView/src/CGAL_Qt4/debug.cpp +++ b/GraphicsView/src/CGAL_Qt4/debug.cpp @@ -19,35 +19,9 @@ // Author(s) : Andreas Fabri // Laurent Rineau +#ifndef CGAL_HEADER_ONLY + #include -#include +#include -#include - -namespace CGAL { -namespace Qt { - - -void traverse_resources(const QString& name, const QString& dirname, int indent) -{ - std::cerr << qPrintable(QString(indent, ' ')) - << qPrintable(name); - QString fullname = - dirname.isEmpty() ? - name : - dirname + "/" + name; - QDir dir(fullname); - if(dir.exists()) { - std::cerr << "/\n"; - Q_FOREACH(QString path, dir.entryList()) - { - traverse_resources(path, fullname, indent + 2); - } - } - else { - std::cerr << "\n"; - } -} - -} // namesapce Qt -} // namespace CGAL +#endif // CGAL_HEADER_ONLY diff --git a/GraphicsView/src/CGAL_Qt4/resources.cpp b/GraphicsView/src/CGAL_Qt4/resources.cpp index e15cc66b861..f38ef67d1fd 100644 --- a/GraphicsView/src/CGAL_Qt4/resources.cpp +++ b/GraphicsView/src/CGAL_Qt4/resources.cpp @@ -18,13 +18,9 @@ // // Author(s) : Laurent Rineau -#include -#include +#ifndef CGAL_HEADER_ONLY -// cannot use namespaces because of the Q_INIT_RESOURCE macro -void CGAL_Qt4_init_resources() { - Q_INIT_RESOURCE(File); - Q_INIT_RESOURCE(Triangulation_2); - Q_INIT_RESOURCE(Input); - Q_INIT_RESOURCE(CGAL); -} +#include +#include + +#endif // CGAL_HEADER_ONLY diff --git a/GraphicsView/src/CGAL_Qt4/utility.cpp b/GraphicsView/src/CGAL_Qt4/utility.cpp index caa1ea353bd..756ef452770 100644 --- a/GraphicsView/src/CGAL_Qt4/utility.cpp +++ b/GraphicsView/src/CGAL_Qt4/utility.cpp @@ -19,36 +19,9 @@ // Author(s) : Andreas Fabri // Laurent Rineau +#ifndef CGAL_HEADER_ONLY + #include -#include -#include -#include -#include -#include +#include -namespace CGAL { -namespace Qt { - -QRectF mapToScene(const QGraphicsView* v, const QRect rect) -{ - QPointF top_left = v->mapToScene(rect.topLeft()); - QPointF size = v->mapToScene(rect.bottomRight()); - size -= top_left; - return QRectF(top_left.x(), - top_left.y(), - size.x(), - size.y()); -} - -QRectF viewportsBbox(const QGraphicsScene* scene) { - QRectF rect; - Q_FOREACH(QGraphicsView* view, scene->views()) - { - rect |= mapToScene(view, view->viewport()->rect()); - } - rect = rect.normalized(); - return rect; -} - -} // namespace Qt -} // namespace CGAL +#endif // CGAL_HEADER_ONLY diff --git a/Linear_cell_complex/demo/Linear_cell_complex/CMakeLists.txt b/Linear_cell_complex/demo/Linear_cell_complex/CMakeLists.txt index f26043666f9..cb639a8b127 100644 --- a/Linear_cell_complex/demo/Linear_cell_complex/CMakeLists.txt +++ b/Linear_cell_complex/demo/Linear_cell_complex/CMakeLists.txt @@ -11,7 +11,7 @@ else() cmake_policy(VERSION 2.6) endif() -add_definitions(-DCGAL_HEADER_ONLY) +# add_definitions(-DCGAL_HEADER_ONLY) ## To add expensive tests # add_definitions("-DCGAL_CHECK_EXPENSIVE") diff --git a/cppfiles.txt b/cppfiles.txt index b85d1d3e216..1aca68caf54 100644 --- a/cppfiles.txt +++ b/cppfiles.txt @@ -66,9 +66,8 @@ CGAL_ImageIO: CGAL_Qt4: DONE #include "/home/gdamiand/sources/CGAL/GraphicsView/src/CGAL_Qt4/utility.cpp" - -#include "/home/gdamiand/sources/CGAL/GraphicsView/src/CGAL_Qt4/resources.cpp" -#include "/home/gdamiand/sources/CGAL/GraphicsView/src/CGAL_Qt4/debug.cpp" -#include "/home/gdamiand/sources/CGAL/GraphicsView/src/CGAL_Qt4/GraphicsViewPolylineInput.cpp" -#include "/home/gdamiand/sources/CGAL/GraphicsView/src/CGAL_Qt4/DemosMainWindow.cpp" -#include "/home/gdamiand/sources/CGAL/GraphicsView/src/CGAL_Qt4/GraphicsViewNavigation.cpp" +DONE #include "/home/gdamiand/sources/CGAL/GraphicsView/src/CGAL_Qt4/resources.cpp" +DONE #include "/home/gdamiand/sources/CGAL/GraphicsView/src/CGAL_Qt4/debug.cpp" +DONE #include "/home/gdamiand/sources/CGAL/GraphicsView/src/CGAL_Qt4/GraphicsViewPolylineInput.cpp" +DONE #include "/home/gdamiand/sources/CGAL/GraphicsView/src/CGAL_Qt4/DemosMainWindow.cpp" +DONE #include "/home/gdamiand/sources/CGAL/GraphicsView/src/CGAL_Qt4/GraphicsViewNavigation.cpp" From a7d968f88e44c9de044163b99f85e3e545f96fc2 Mon Sep 17 00:00:00 2001 From: Guillaume Damiand Date: Fri, 31 Oct 2014 19:31:37 +0100 Subject: [PATCH 08/30] Add missing impl files. --- .../include/CGAL/Qt/DemosMainWindow_impl.h | 436 ++++++++++++++++++ .../CGAL/Qt/GraphicsViewNavigation_impl.h | 351 ++++++++++++++ .../CGAL/Qt/GraphicsViewPolylineInput_impl.h | 208 +++++++++ GraphicsView/include/CGAL/Qt/debug_impl.h | 60 +++ GraphicsView/include/CGAL/Qt/resources_impl.h | 37 ++ GraphicsView/include/CGAL/Qt/utility_impl.h | 62 +++ 6 files changed, 1154 insertions(+) create mode 100644 GraphicsView/include/CGAL/Qt/DemosMainWindow_impl.h create mode 100644 GraphicsView/include/CGAL/Qt/GraphicsViewNavigation_impl.h create mode 100644 GraphicsView/include/CGAL/Qt/GraphicsViewPolylineInput_impl.h create mode 100644 GraphicsView/include/CGAL/Qt/debug_impl.h create mode 100644 GraphicsView/include/CGAL/Qt/resources_impl.h create mode 100644 GraphicsView/include/CGAL/Qt/utility_impl.h diff --git a/GraphicsView/include/CGAL/Qt/DemosMainWindow_impl.h b/GraphicsView/include/CGAL/Qt/DemosMainWindow_impl.h new file mode 100644 index 00000000000..5f4fee7b156 --- /dev/null +++ b/GraphicsView/include/CGAL/Qt/DemosMainWindow_impl.h @@ -0,0 +1,436 @@ +// Copyright (c) 2008 GeometryFactory Sarl (France). +// 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) : Andreas Fabri +// Laurent Rineau + +#ifdef CGAL_HEADER_ONLY +#define CGAL_INLINE_FUNCTION inline +#else +#define CGAL_INLINE_FUNCTION +#endif + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include // needed to get CGAL_VERSION_STR +#include +#include + +namespace CGAL { +namespace Qt { + +CGAL_INLINE_FUNCTION +DemosMainWindow::DemosMainWindow(QWidget * parent, ::Qt::WindowFlags flags) + : QMainWindow(parent, flags), + maxNumRecentFiles(10), + recentFileActs(maxNumRecentFiles) +{ + // prepare the QLabel xycoord for inclusion in the statusBar() + xycoord = new QLabel(" -0.00000 , -0.00000 ", this); + xycoord->setAlignment(::Qt::AlignHCenter); + xycoord->setMinimumSize(xycoord->sizeHint()); + xycoord->clear(); + + actionUse_OpenGL = new QAction(this); + actionUse_OpenGL->setObjectName("actionUse_OpenGL"); + actionUse_OpenGL->setCheckable(true); + actionUse_OpenGL->setText(tr("Use &OpenGL")); + actionUse_OpenGL->setStatusTip(tr("Make Qt use OpenGL to display the graphical items, instead of its native painting system.")); + actionUse_OpenGL->setShortcut(tr("Ctrl+G")); + + actionUse_Antialiasing = new QAction(this); + actionUse_Antialiasing->setObjectName("actionUse_Antialiasing"); + actionUse_Antialiasing->setCheckable(true); + actionUse_Antialiasing->setText(tr("Use &anti-aliasing")); + actionUse_Antialiasing->setStatusTip(tr("Make Qt use anti-aliasing when displaying the graphical items.")); + actionUse_Antialiasing->setShortcut(tr("Ctrl+A")); + + actionAboutCGAL = new QAction(this); + actionAboutCGAL->setObjectName("actionAboutCGAL"); + actionAboutCGAL->setText(tr("About &CGAL...")); + + actionAbout = new QAction(this); + actionAbout->setObjectName("actionAbout"); + actionAbout->setText(tr("&About...")); + + setAcceptDrops(true); +} + + +CGAL_INLINE_FUNCTION +void +DemosMainWindow::dragEnterEvent(QDragEnterEvent *event) +{ + if (event->mimeData()->hasFormat("text/uri-list")) + event->acceptProposedAction(); +} + +CGAL_INLINE_FUNCTION +void +DemosMainWindow::dropEvent(QDropEvent *event) +{ + Q_FOREACH(QUrl url, event->mimeData()->urls()) { + QString filename = url.toLocalFile(); + this->open(filename); + } + event->acceptProposedAction(); +} + +CGAL_INLINE_FUNCTION +void +DemosMainWindow::addNavigation(QGraphicsView* graphicsView) +{ + navigation = new CGAL::Qt::GraphicsViewNavigation(); + graphicsView->viewport()->installEventFilter(navigation); + graphicsView->installEventFilter(navigation); + QObject::connect(navigation, SIGNAL(mouseCoordinates(QString)), + xycoord, SLOT(setText(QString))); + view = graphicsView; +} + +CGAL_INLINE_FUNCTION +void +DemosMainWindow::setupStatusBar() +{ + this->statusBar()->addWidget(new QLabel(this), 1); + this->statusBar()->addWidget(xycoord, 0); +} + +CGAL_INLINE_FUNCTION +void +DemosMainWindow::setupOptionsMenu(QMenu* menuOptions) +{ + // search for the Options menu + if(!menuOptions) { + menuOptions = getMenu("menuOptions", tr("&Options")); + } + + // if not found, then create it + if(!menuOptions) { + menuOptions = new QMenu(this->menuBar()); + menuOptions->setTitle(tr("&Options")); + this->menuBar()->addAction(menuOptions->menuAction()); + menuOptions->setObjectName("menuOptions"); + } + + if(!menuOptions->isEmpty()) { + menuOptions->addSeparator(); + } + menuOptions->addAction(actionUse_OpenGL); + menuOptions->addAction(actionUse_Antialiasing); + connect(actionUse_Antialiasing, SIGNAL(toggled(bool)), + this, SLOT(setUseAntialiasing(bool))); + connect(actionUse_OpenGL, SIGNAL(toggled(bool)), + this, SLOT(setUseOpenGL(bool))); + actionUse_Antialiasing->setChecked(true); +} + +CGAL_INLINE_FUNCTION +void +DemosMainWindow::setUseAntialiasing(bool checked) +{ + view->setRenderHint(QPainter::Antialiasing, checked); +#if QT_VERSION >= 0x040300 + view->setRenderHint(QPainter::HighQualityAntialiasing, checked); +#endif + statusBar()->showMessage(tr("Antialiasing %1activated").arg(checked?"":"de-"), + 1000); +} + +CGAL_INLINE_FUNCTION +void +DemosMainWindow::setUseOpenGL(bool checked) +{ + if(checked) { + QGLWidget* new_viewport = new QGLWidget; + + // Setup the format to allow antialiasing with OpenGL: + // one need to activate the SampleBuffers, if the graphic driver allows + // this. + QGLFormat glformat = new_viewport->format(); + glformat.setOption(QGL::SampleBuffers); + new_viewport->setFormat(glformat); + + view->setViewport(new_viewport); + } + else { + view->setViewport(new QWidget); + } + statusBar()->showMessage(tr("OpenGL %1activated").arg(checked?"":"de-"), + 1000); + view->viewport()->installEventFilter(navigation); + view->setFocus(); +} + +CGAL_INLINE_FUNCTION +QMenu* +DemosMainWindow::getMenu(QString objectName, QString title) +{ + QMenu* menu = NULL; + + QString title2 = title; + title2.remove('&'); + // search if a menu has objectName()==objectName + menu = this->findChild(objectName); + + // then search if a menu has title()==title + if(menu) { + return menu; + } else { + Q_FOREACH(menu, this->findChildren()) { + if(menu->title() == title || + menu->title() == title2) { + return menu; + } + } + } + return NULL; +} + +CGAL_INLINE_FUNCTION +void +DemosMainWindow::popupAboutBox(QString title, QString html_resource_name) +{ + QFile about_CGAL(html_resource_name); + about_CGAL.open(QIODevice::ReadOnly); + QString about_CGAL_txt = QTextStream(&about_CGAL).readAll(); +#ifdef CGAL_VERSION_STR + QString cgal_version(CGAL_VERSION_STR); +# ifdef CGAL_FAKE_PUBLIC_RELEASE + cgal_version.replace(QRegExp("-Ic?.*"), ""); +# endif + about_CGAL_txt.replace("", + QString(" (version %1)") + .arg(cgal_version)); +#endif + QMessageBox mb(QMessageBox::NoIcon, + title, + about_CGAL_txt, + QMessageBox::Ok, + this); + + QLabel* mb_label = mb.findChild("qt_msgbox_label"); + if(mb_label) { + mb_label->setTextInteractionFlags(mb_label->textInteractionFlags() | + ::Qt::LinksAccessibleByMouse | + ::Qt::LinksAccessibleByKeyboard); + } + else { + std::cerr << "Cannot find child \"qt_msgbox_label\" in QMessageBox\n" + << " with Qt version " << QT_VERSION_STR << "!\n"; + } + mb.exec(); +} + +CGAL_INLINE_FUNCTION +QMenu* DemosMainWindow::getHelpMenu() +{ + QMenu* menuHelp = getMenu("menuHelp", tr("&Help")); + if(!menuHelp) { + menuHelp = new QMenu(this->menuBar()); + menuHelp->setTitle(tr("&Help")); + this->menuBar()->addAction(menuHelp->menuAction()); + menuHelp->setObjectName("menuHelp"); + } + return menuHelp; +} + +CGAL_INLINE_FUNCTION +void +DemosMainWindow::addAboutCGAL(QMenu* menuHelp) +{ + if(!menuHelp) { + menuHelp = getHelpMenu(); + } + menuHelp->addAction(actionAboutCGAL); + + connect(actionAboutCGAL, SIGNAL(triggered()), + this, SLOT(popupAboutCGAL())); +} + +CGAL_INLINE_FUNCTION +void +DemosMainWindow::addAboutDemo(QString htmlResourceName, QMenu* menuHelp) +{ + if(!menuHelp) { + menuHelp = getHelpMenu(); + } + menuHelp->addAction(actionAbout); + aboutHtmlResource = htmlResourceName; + + connect(actionAbout, SIGNAL(triggered()), + this, SLOT(popupAboutDemo())); +} + +CGAL_INLINE_FUNCTION +void +DemosMainWindow::popupAboutCGAL() +{ + popupAboutBox(tr("About CGAL..."), + ":/cgal/help/about_CGAL.html"); +} + +CGAL_INLINE_FUNCTION +void +DemosMainWindow::popupAboutDemo() +{ + popupAboutBox(tr("About the demo..."), + aboutHtmlResource); +} + +CGAL_INLINE_FUNCTION +void +DemosMainWindow::setMaxNumberOfRecentFiles(const unsigned int i) +{ + maxNumRecentFiles = i; + recentFileActs.resize(maxNumRecentFiles); +} + +CGAL_INLINE_FUNCTION +unsigned int +DemosMainWindow::maxNumberOfRecentFiles() const +{ + return maxNumRecentFiles; +} + +CGAL_INLINE_FUNCTION +void +DemosMainWindow::openRecentFile_aux() +{ + QAction *action = qobject_cast(sender()); + if (action) + emit openRecentFile(action->data().toString()); +} + +CGAL_INLINE_FUNCTION +void +DemosMainWindow::addToRecentFiles(QString fileName) +{ + QSettings settings; + QStringList files = settings.value("recentFileList").toStringList(); + files.removeAll(fileName); + files.prepend(fileName); + while (files.size() > (int)maxNumberOfRecentFiles()) + files.removeLast(); + + settings.setValue("recentFileList", files); + + updateRecentFileActions(); +} + +CGAL_INLINE_FUNCTION +void +DemosMainWindow::addRecentFiles(QMenu* menu, QAction* insertBeforeAction) +{ + if(!insertBeforeAction) { + recentFilesSeparator = menu->addSeparator(); + } + + for (unsigned int i = 0; i < maxNumberOfRecentFiles(); ++i) { + recentFileActs[i] = new QAction(this); + recentFileActs[i]->setVisible(false); + connect(recentFileActs[i], SIGNAL(triggered()), + this, SLOT(openRecentFile_aux())); + if(insertBeforeAction) + menu->insertAction(insertBeforeAction, recentFileActs[i]); + else + menu->addAction(recentFileActs[i]); + } + + if(insertBeforeAction) { + recentFilesSeparator = menu->insertSeparator(insertBeforeAction); + } + + recentFilesSeparator->setVisible(false); + + updateRecentFileActions(); +} + +CGAL_INLINE_FUNCTION +void +DemosMainWindow::updateRecentFileActions() +{ + QSettings settings; + QStringList files = settings.value("recentFileList").toStringList(); + + int numRecentFiles = qMin(files.size(), (int)this->maxNumberOfRecentFiles()); + + for (int i = 0; i < numRecentFiles; ++i) { + QString strippedName = QFileInfo(files[i]).fileName(); + QString text = tr("&%1 %2").arg(i).arg(strippedName); + recentFileActs[i]->setText(text); + recentFileActs[i]->setData(files[i]); + recentFileActs[i]->setVisible(true); + } + for (unsigned int j = numRecentFiles; j < maxNumberOfRecentFiles(); ++j) + recentFileActs[j]->setVisible(false); + + recentFilesSeparator->setVisible(numRecentFiles > 0); +} + +CGAL_INLINE_FUNCTION +void DemosMainWindow::writeState(QString groupname) +{ + QSettings settings; + + settings.beginGroup(groupname); + settings.setValue("size", size()); + settings.setValue("pos", pos()); + settings.setValue("state", saveState()); + settings.endGroup(); +} + +CGAL_INLINE_FUNCTION +void DemosMainWindow::readState(QString groupname, Options /*what_to_save*/) +{ + QSettings settings; + + settings.beginGroup(groupname); + resize(settings.value("size", this->size()).toSize()); + + QDesktopWidget* desktop = qApp->desktop(); + QPoint pos = settings.value("pos", this->pos()).toPoint(); + if(desktop->availableGeometry(pos).contains(pos)) { + move(pos); + } + QByteArray mainWindowState = settings.value("state").toByteArray(); + if(!mainWindowState.isNull()) { + this->restoreState(mainWindowState); + } + settings.endGroup(); +} + + +} // namespace Qt +} // namespace CGAL diff --git a/GraphicsView/include/CGAL/Qt/GraphicsViewNavigation_impl.h b/GraphicsView/include/CGAL/Qt/GraphicsViewNavigation_impl.h new file mode 100644 index 00000000000..0570920869f --- /dev/null +++ b/GraphicsView/include/CGAL/Qt/GraphicsViewNavigation_impl.h @@ -0,0 +1,351 @@ +// Copyright (c) 2008 GeometryFactory Sarl (France). +// 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) : Andreas Fabri +// Laurent Rineau + +#ifdef CGAL_HEADER_ONLY +#define CGAL_INLINE_FUNCTION inline +#else +#define CGAL_INLINE_FUNCTION +#endif + +#include +#include // for mapToScene(QGraphicsView*, QRect) +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +namespace CGAL { +namespace Qt { + + CGAL_INLINE_FUNCTION + GraphicsViewNavigation::GraphicsViewNavigation() + : rectItem(new QGraphicsRectItem), + dragging(false) + { + QColor rect_color(250, 221, 0); + rect_color.setAlpha(50); + rectItem->setBrush(rect_color); + rect_color.setAlpha(255); + rectItem->setPen(QPen(rect_color, 0, ::Qt::DashLine)); + rectItem->hide(); + rectItem->setZValue(10000); + } + + CGAL_INLINE_FUNCTION + GraphicsViewNavigation::~GraphicsViewNavigation() + { + delete rectItem; + } + + CGAL_INLINE_FUNCTION + bool + GraphicsViewNavigation::eventFilter(QObject *obj, QEvent *event) + { + QGraphicsView* v = qobject_cast(obj); + if(v == NULL) { + QWidget* viewport = qobject_cast(obj); + if(viewport == NULL) { + return false; + } + v = qobject_cast(viewport->parent()); + if(v == NULL) { + return false; + } + } + switch(event->type()) + { + case QEvent::KeyPress: { + QKeyEvent *keyEvent = static_cast(event); + int offset = 10; + if( (keyEvent->modifiers() & ::Qt::ShiftModifier) + || (keyEvent->modifiers() & ::Qt::ControlModifier) ) { + offset = 20; + } + switch (keyEvent->key()) { + case ::Qt::Key_Up: + translateView(v, 0, -offset); + break; + case ::Qt::Key_Down: + translateView(v, 0, offset); + break; + case ::Qt::Key_Left: + translateView(v, -offset, 0); + break; + case ::Qt::Key_Right: + translateView(v, offset, 0); + break; + case ::Qt::Key_PageUp: + v->rotate(-6); + break; + case ::Qt::Key_PageDown: + v->rotate(6); + break; + case ::Qt::Key_Plus: + scaleView(v, 1.2); + break; + case ::Qt::Key_Minus: + scaleView(v, 1 / 1.2); + break; + case ::Qt::Key_Control: + cursor_backup = v->cursor(); + v->setCursor(::Qt::CrossCursor); + default: + return false; + } + // display_parameters(); + return true; + break; + } // end case KeyPress + case QEvent::KeyRelease: { + QKeyEvent *keyEvent = static_cast(event); + if(keyEvent->key() == ::Qt::Key_Control) { + if(rectItem->isVisible() ) { + dragging = false; + v->scene()->removeItem(rectItem); + rectItem->hide(); + } + v->setCursor(cursor_backup); + return true; + } + return false; + break; + } // end case KeyRelease + case QEvent::Wheel: { + QWheelEvent *wheelEvent = static_cast(event); + if(wheelEvent->orientation() != ::Qt::Vertical) { + return false; + } + double zoom_ratio = 240.0; + if( (wheelEvent->modifiers() & ::Qt::ShiftModifier) + || (wheelEvent->modifiers() & ::Qt::ControlModifier) ) { + zoom_ratio = 120.0; + } + scaleView(v, pow((double)2, -wheelEvent->delta() / zoom_ratio)); + + // display_parameters(); + return true; + break; + } // end case Wheel + case QEvent::MouseButtonPress: { + QMouseEvent* mouseEvent = static_cast(event); + if( (mouseEvent->modifiers() == (::Qt::ControlModifier | ::Qt::ShiftModifier)) + && mouseEvent->button() == ::Qt::RightButton ) + { + QPoint offset = mouseEvent->pos() - v->viewport()->rect().center(); + translateView(v, offset.x(), offset.y()); + return true; + } + else if( mouseEvent->modifiers() == ::Qt::ControlModifier ) { + if(mouseEvent->button() == ::Qt::LeftButton) { + rect_first_point = v->mapToScene(mouseEvent->pos()); + rectItem->setRect(QRectF(rect_first_point, QSizeF(0.,0.))); + rectItem->show(); + v->scene()->addItem(rectItem); + return true; + } + else if( mouseEvent->button() == ::Qt::RightButton) { + dragging = true; + dragging_start = v->mapToScene(mouseEvent->pos()); + v->setCursor(::Qt::ClosedHandCursor); + return true; + } + } + return false; + break; + } // end case MouseRelease + case QEvent::MouseMove: { + QMouseEvent* mouseEvent = static_cast(event); + QPointF pos = v->mapToScene(mouseEvent->pos()); + QString xy = QString(" ") + QString::number(pos.x(),'g', 6) + " , " + QString::number(pos.y(),'g', 6) + " "; + emit mouseCoordinates(xy); + if(rectItem->isVisible()) { + QPointF size = v->mapToScene(mouseEvent->pos()); + size = size - rect_first_point; + rectItem->setRect(rect_first_point.x(), + rect_first_point.y(), + size.x(), + size.y()); + } + if( dragging ) + { +// std::cerr << boost::format("mouseMove: globalpos=(%1%, %2%)\n" +// " pos=(%3%, %4%)\n" +// " sender=%5% (class %6%), parent class %7%\n") +// % mouseEvent->globalPos().x() +// % mouseEvent->globalPos().y() +// % mouseEvent->pos().x() +// % mouseEvent->pos().y() +// % (&*obj) +// % obj->metaObject()->className() +// % obj->parent()->metaObject()->className(); + +// drag_to(mouseEvent->pos()); + } + break; + } // end MouseMove + case QEvent::MouseButtonRelease: { + QMouseEvent* mouseEvent = static_cast(event); + if(rectItem->isVisible() && mouseEvent->button() == ::Qt::LeftButton){ + v->setSceneRect(v->sceneRect() | rectItem->rect()); + v->fitInView(rectItem->rect(), ::Qt::KeepAspectRatio); + v->scene()->removeItem(rectItem); + rectItem->hide(); + return true; + } + else if( mouseEvent->button() == ::Qt::RightButton ) { + if(dragging) { + dragging = false; + drag_to(v, mouseEvent->pos()); + v->setCursor(cursor_backup); + return true; + } + } + return false; + break; + } // end MouseRelease + default: + return false; + } // end switch + return false; + } + + + CGAL_INLINE_FUNCTION + void + GraphicsViewNavigation::scaleView(QGraphicsView* v, qreal scaleFactor) + { + QPointF center = v->mapToScene(v->viewport()->rect().center()); +// qreal factor = v->matrix().scale(scaleFactor, scaleFactor).mapRect(QRectF(0, 0, 1, 1)).width(); + //if (factor < 0.001 || factor > 2000) + // return; + + v->scale(scaleFactor, scaleFactor); + QPoint offset = v->mapFromScene(center) - v->viewport()->rect().center(); + translateView(v, offset.x(), offset.y()); + } + + CGAL_INLINE_FUNCTION + void GraphicsViewNavigation::drag_to(QGraphicsView* v, QPoint new_pos) + { + QPoint dragging_start_in_view = v->mapFromScene(dragging_start); + QPoint offset = new_pos - dragging_start_in_view; +// std::cerr << boost::format("drag_to: origin=(%1%, %2%)\n" +// " offset=(%3%, %4%)\n") +// % dragging_start_in_view.x() % dragging_start_in_view.y() +// % offset.x() % offset.y(); + translateView(v, -offset.x(), -offset.y()); + dragging_start_in_view = v->mapFromScene(dragging_start); +// std::cerr << boost::format(" after=(%1%, %2%)\n") +// % dragging_start_in_view.x() % dragging_start_in_view.y(); + } + + CGAL_INLINE_FUNCTION + void GraphicsViewNavigation::translateView(QGraphicsView* v, int dx, int dy) + { + if( dx == 0 && dy == 0 ) { + return; + } + + int horizontalScrollBarValue = v->horizontalScrollBar()->value(); + int verticalScrollBarValue = v->verticalScrollBar()->value(); + + if( (horizontalScrollBarValue + dx <= + v->horizontalScrollBar()->maximum()) && + (horizontalScrollBarValue + dx >= + v->horizontalScrollBar()->minimum()) && + (verticalScrollBarValue + dy <= + v->verticalScrollBar()->maximum()) && + (verticalScrollBarValue + dy >= + v->verticalScrollBar()->minimum()) ) + { + v->horizontalScrollBar()->setValue(horizontalScrollBarValue + dx); + v->verticalScrollBar()->setValue(verticalScrollBarValue + dy); + } + else + { + QRect vp_rect = v->viewport()->rect(); + QPointF new_center = v->mapToScene(vp_rect.center() + QPoint(dx, dy)); + vp_rect |= vp_rect.translated(dx, dy); + QRectF rect = mapToScene(v, vp_rect); + v->setSceneRect(v->sceneRect() | rect); + v->centerOn(new_center); + + // QGraphicsView::centerOn makes rounding errors. + // The following two "if" make them unnoticable when dx==0 or dy==0. + if(dx == 0) { + v->horizontalScrollBar()->setValue(horizontalScrollBarValue); + } + if(dy == 0) { + v->verticalScrollBar()->setValue(verticalScrollBarValue); + } + } +// display_parameters(); + } + + CGAL_INLINE_FUNCTION + void GraphicsViewNavigation::display_parameters(QGraphicsView* v) + { + std::cerr << + boost::format("matrix translation=(%1%, %2%)\n" + " rotation=(%3% - %4% )\n" + " (%5% - %6% )\n") + % v->matrix().dx() + % v->matrix().dy() + % v->matrix().m11() + % v->matrix().m12() + % v->matrix().m21() + % v->matrix().m22(); + + QRect vp_rect = v->viewport()->rect(); + QPoint vp_top_left = vp_rect.topLeft(); + QPoint vp_bottom_right = vp_rect.bottomRight(); + QPointF top_left = v->mapToScene(vp_top_left); + QPointF bottom_right = v->mapToScene(vp_bottom_right); + + std::cerr << + boost::format("view=(%1% - %2%) x (%3% - %4%)\n") + % top_left.x() % bottom_right.x() + % top_left.y() % bottom_right.y(); + std::cerr << + boost::format("viewport=(%1% - %2%) x (%3% - %4%)\n") + % vp_top_left.x() % vp_bottom_right.x() + % vp_top_left.y() % vp_bottom_right.y(); + std::cerr << + boost::format("scrollbars=(%1% <= %2% <= %3%) x (%4% <= %5% <= %6%)\n") + % v->horizontalScrollBar()->minimum() + % v->horizontalScrollBar()->value() + % v->horizontalScrollBar()->maximum() + % v->verticalScrollBar()->minimum() + % v->verticalScrollBar()->value() + % v->verticalScrollBar()->maximum(); + } + +} // namespace Qt +} // namespace CGAL + diff --git a/GraphicsView/include/CGAL/Qt/GraphicsViewPolylineInput_impl.h b/GraphicsView/include/CGAL/Qt/GraphicsViewPolylineInput_impl.h new file mode 100644 index 00000000000..fa7a88b9c94 --- /dev/null +++ b/GraphicsView/include/CGAL/Qt/GraphicsViewPolylineInput_impl.h @@ -0,0 +1,208 @@ +// Copyright (c) 2008 GeometryFactory Sarl (France). +// 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) : Andreas Fabri +// Laurent Rineau + +#ifdef CGAL_HEADER_ONLY +#define CGAL_INLINE_FUNCTION inline +#else +#define CGAL_INLINE_FUNCTION +#endif + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +namespace CGAL { +namespace Qt { + +CGAL_INLINE_FUNCTION +GraphicsViewPolylineInput_non_templated_base:: +GraphicsViewPolylineInput_non_templated_base(QObject* parent, + QGraphicsScene* s, + int n, + bool closed) + : GraphicsViewInput(parent), closed_(closed), path_item(NULL), b(NULL), e(NULL), n_(n), scene_(s) +{} + + +CGAL_INLINE_FUNCTION +bool +GraphicsViewPolylineInput_non_templated_base::mousePressEvent(QGraphicsSceneMouseEvent *event) +{ + if( event->modifiers() ){ + return false; + } + if( event->button() != ::Qt::RightButton + && event->button() != ::Qt::LeftButton ){ + return false; + } + polygon.push_back(event->scenePos()); + if(path_item){ + scene_->removeItem(path_item); + delete path_item; + path_item = NULL; + } + if( (event->button() == ::Qt::RightButton) || (polygon.size() == n_) ){ + // call the virtual function generate_polygon(), that emit a + // CGAL::Object containing a list of points + generate_polygon(); + polygon.clear(); + if(b){ + scene_->removeItem(b); + delete b; + b = NULL; + } + if(e){ + scene_->removeItem(e); + delete e; + e = NULL; + } + return true; + } + if(event->button() == ::Qt::LeftButton){ + QPainterPath qpp; + qpp.addPolygon(polygon); + path_item = new QGraphicsPathItem(qpp); + path_item->setPen(QPen(::Qt::red, 0, ::Qt::SolidLine, ::Qt::RoundCap, ::Qt::RoundJoin)); + scene_->addItem(path_item); + return true; + } + return false; +} + + +CGAL_INLINE_FUNCTION +void +GraphicsViewPolylineInput_non_templated_base::rubberbands(const QPointF& p) +{ + if(polygon.empty()){ + return; + } + if(!b && closed_ ){ + b = new QGraphicsLineItem(); + b->setPen(QPen(::Qt::red, 0, ::Qt::SolidLine, ::Qt::RoundCap, ::Qt::RoundJoin)); + scene_->addItem(b); + } + if( !e){ + e = new QGraphicsLineItem(); + e->setPen(QPen(::Qt::red, 0, ::Qt::SolidLine, ::Qt::RoundCap, ::Qt::RoundJoin)); + scene_->addItem(e); + } + if(closed_){ + QLineF bLine(polygon.front(), p); + b->setLine(bLine); + } + QLineF eLine(polygon.back(), p); + e->setLine(eLine); +} + + +CGAL_INLINE_FUNCTION +void +GraphicsViewPolylineInput_non_templated_base::mouseMoveEvent(QGraphicsSceneMouseEvent *event) +{ + sp = event->scenePos(); + rubberbands(sp); +} + + +CGAL_INLINE_FUNCTION +bool +GraphicsViewPolylineInput_non_templated_base::keyPressEvent ( QKeyEvent * event ) +{ + if( event->modifiers() ) + return false; + + switch(event->key()) + { + case ::Qt::Key_Delete: + case ::Qt::Key_Escape: + case ::Qt::Key_Backspace: + break; + default: + return false; + } + if(polygon.empty()){ + return true; + } + polygon.pop_back(); + if(polygon.empty()){ + if(b){ + scene_->removeItem(b); + delete b; + b = NULL; + } + if(e){ + scene_->removeItem(e); + delete e; + e = NULL; + } + return true; + } + if(path_item){ + scene_->removeItem(path_item); + delete path_item; + path_item = NULL; + } + QPainterPath qpp; + qpp.addPolygon(polygon); + path_item = new QGraphicsPathItem(qpp); + path_item->setPen(QPen(::Qt::red, 0, ::Qt::SolidLine, ::Qt::RoundCap, ::Qt::RoundJoin)); + scene_->addItem(path_item); + rubberbands(sp); + return true; +} + + + +CGAL_INLINE_FUNCTION +bool +GraphicsViewPolylineInput_non_templated_base::eventFilter(QObject *obj, QEvent *event) +{ + if (event->type() == QEvent::GraphicsSceneMousePress) { + QGraphicsSceneMouseEvent *mouseEvent = static_cast(event); + if(!mousePressEvent(mouseEvent)) { + // standard event processing if mousePressEvent has returned false + return QObject::eventFilter(obj, event); + } + } else if (event->type() == QEvent::GraphicsSceneMouseMove) { + QGraphicsSceneMouseEvent *mouseEvent = static_cast(event); + mouseMoveEvent(mouseEvent); + return QObject::eventFilter(obj, event); + } else if (event->type() == QEvent::KeyPress) { + QKeyEvent *keyEvent = static_cast(event); + if(!keyPressEvent(keyEvent)) { + return QObject::eventFilter(obj, event); + } + } + // standard event processing if keyPressEvent has returned false + return QObject::eventFilter(obj, event); +} + +} // namespace Qt +} // namespace CGAL diff --git a/GraphicsView/include/CGAL/Qt/debug_impl.h b/GraphicsView/include/CGAL/Qt/debug_impl.h new file mode 100644 index 00000000000..e7bf2904420 --- /dev/null +++ b/GraphicsView/include/CGAL/Qt/debug_impl.h @@ -0,0 +1,60 @@ +// Copyright (c) 2008 GeometryFactory Sarl (France). +// 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) : Andreas Fabri +// Laurent Rineau + +#ifdef CGAL_HEADER_ONLY +#define CGAL_INLINE_FUNCTION inline +#else +#define CGAL_INLINE_FUNCTION +#endif + +#include +#include + +#include + +namespace CGAL { +namespace Qt { + + +CGAL_INLINE_FUNCTION +void traverse_resources(const QString& name, const QString& dirname, int indent) +{ + std::cerr << qPrintable(QString(indent, ' ')) + << qPrintable(name); + QString fullname = + dirname.isEmpty() ? + name : + dirname + "/" + name; + QDir dir(fullname); + if(dir.exists()) { + std::cerr << "/\n"; + Q_FOREACH(QString path, dir.entryList()) + { + traverse_resources(path, fullname, indent + 2); + } + } + else { + std::cerr << "\n"; + } +} + +} // namesapce Qt +} // namespace CGAL diff --git a/GraphicsView/include/CGAL/Qt/resources_impl.h b/GraphicsView/include/CGAL/Qt/resources_impl.h new file mode 100644 index 00000000000..bfe784c860c --- /dev/null +++ b/GraphicsView/include/CGAL/Qt/resources_impl.h @@ -0,0 +1,37 @@ +// Copyright (c) 2011 GeometryFactory Sarl (France). +// 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) : Laurent Rineau + +#ifdef CGAL_HEADER_ONLY +#define CGAL_INLINE_FUNCTION inline +#else +#define CGAL_INLINE_FUNCTION +#endif + +#include +#include + +// cannot use namespaces because of the Q_INIT_RESOURCE macro +CGAL_INLINE_FUNCTION +void CGAL_Qt4_init_resources() { + Q_INIT_RESOURCE(File); + Q_INIT_RESOURCE(Triangulation_2); + Q_INIT_RESOURCE(Input); + Q_INIT_RESOURCE(CGAL); +} diff --git a/GraphicsView/include/CGAL/Qt/utility_impl.h b/GraphicsView/include/CGAL/Qt/utility_impl.h new file mode 100644 index 00000000000..4fea3451f07 --- /dev/null +++ b/GraphicsView/include/CGAL/Qt/utility_impl.h @@ -0,0 +1,62 @@ +// Copyright (c) 2008 GeometryFactory Sarl (France). +// 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) : Andreas Fabri +// Laurent Rineau + +#ifdef CGAL_HEADER_ONLY +#define CGAL_INLINE_FUNCTION inline +#else +#define CGAL_INLINE_FUNCTION +#endif + +#include +#include +#include +#include +#include +#include + +namespace CGAL { +namespace Qt { + +CGAL_INLINE_FUNCTION +QRectF mapToScene(const QGraphicsView* v, const QRect rect) +{ + QPointF top_left = v->mapToScene(rect.topLeft()); + QPointF size = v->mapToScene(rect.bottomRight()); + size -= top_left; + return QRectF(top_left.x(), + top_left.y(), + size.x(), + size.y()); +} + +CGAL_INLINE_FUNCTION +QRectF viewportsBbox(const QGraphicsScene* scene) { + QRectF rect; + Q_FOREACH(QGraphicsView* view, scene->views()) + { + rect |= mapToScene(view, view->viewport()->rect()); + } + rect = rect.normalized(); + return rect; +} + +} // namespace Qt +} // namespace CGAL From 2f52912a797d7fa6ab954832addff9ef4ab33936 Mon Sep 17 00:00:00 2001 From: Guillaume Damiand Date: Sun, 2 Nov 2014 17:53:02 +0100 Subject: [PATCH 09/30] One more file (NefPolynomial.cpp). --- Nef_2/include/CGAL/Nef_2/Polynomial.h | 10 +- Nef_2/include/CGAL/Nef_2/Polynomial_impl.h | 204 +++++++++++++++++++++ Nef_2/src/CGAL/NefPolynomial.cpp | 175 +----------------- cppfiles.txt | 28 +-- 4 files changed, 225 insertions(+), 192 deletions(-) create mode 100644 Nef_2/include/CGAL/Nef_2/Polynomial_impl.h diff --git a/Nef_2/include/CGAL/Nef_2/Polynomial.h b/Nef_2/include/CGAL/Nef_2/Polynomial.h index 5eb40e198da..732a276ec05 100644 --- a/Nef_2/include/CGAL/Nef_2/Polynomial.h +++ b/Nef_2/include/CGAL/Nef_2/Polynomial.h @@ -1973,12 +1973,8 @@ using Nef::gcd; } //namespace CGAL - - - - - - - +#ifdef CGAL_HEADER_ONLY +#include +#endif // CGAL_HEADER_ONLY #endif // CGAL_NEF_2_POLYNOMIAL_H diff --git a/Nef_2/include/CGAL/Nef_2/Polynomial_impl.h b/Nef_2/include/CGAL/Nef_2/Polynomial_impl.h new file mode 100644 index 00000000000..af23caf540b --- /dev/null +++ b/Nef_2/include/CGAL/Nef_2/Polynomial_impl.h @@ -0,0 +1,204 @@ +// Copyright (c) 2000 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 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$ +// +// +// Author(s) : Michael Seel +// Andreas Fabri + +#ifdef CGAL_HEADER_ONLY +#define CGAL_INLINE_FUNCTION inline +#else +#define CGAL_INLINE_FUNCTION +#endif + +namespace CGAL{ + + namespace Nef { + +CGAL_INLINE_FUNCTION +void Polynomial::euclidean_div( + const Polynomial& f, const Polynomial& g, + Polynomial& q, Polynomial& r) +{ + r = f; r.copy_on_write(); + int rd=r.degree(), gd=g.degree(), qd; + if ( rd < gd ) { q = Polynomial(int(0)); } + else { qd = rd-gd+1; q = Polynomial(std::size_t(qd)); } + while ( rd >= gd && !(r.is_zero())) { + int S = r[rd] / g[gd]; + qd = rd-gd; + q.coeff(qd) += S; + r.minus_offsetmult(g,S,qd); + rd = r.degree(); + } + CGAL_postcondition( f==q*g+r ); +} + + + +CGAL_INLINE_FUNCTION +void Polynomial::pseudo_div( + const Polynomial& f, const Polynomial& g, + Polynomial& q, Polynomial& r, int& D) +{ + CGAL_NEF_TRACEN("pseudo_div "<(0); r = f; D = 1; + CGAL_postcondition(Polynomial(D)*f==q*g+r); return; + } + // now we know fd >= gd and f>=g + int qd=fd-gd, delta=qd+1, rd=fd; + { q = Polynomial( std::size_t(delta) ); }; // workaround for SUNPRO + int G = g[gd]; // highest order coeff of g + D = G; while (--delta) D*=G; // D = G^delta + Polynomial res = Polynomial(D)*f; + CGAL_NEF_TRACEN(" pseudo_div start "<= 0) { + int F = res[rd]; // highest order coeff of res + int t = F/G; // ensured to be integer by multiplication of D + q.coeff(qd) = t; // store q coeff + res.minus_offsetmult(g,t,qd); + if (res.is_zero()) break; + rd = res.degree(); + qd = rd - gd; + } + r = res; + CGAL_postcondition(Polynomial(D)*f==q*g+r); + CGAL_NEF_TRACEN(" returning "< Polynomial::gcd( + const Polynomial& p1, const Polynomial& p2) +{ CGAL_NEF_TRACEN("gcd("<(int(1)); + else return p2.abs(); + } + if ( p2.is_zero() ) + return p1.abs(); + + Polynomial f1 = p1.abs(); + Polynomial f2 = p2.abs(); + int f1c = f1.content(), f2c = f2.content(); + f1 /= f1c; f2 /= f2c; + int F = CGAL::gcd(f1c,f2c); + Polynomial q,r; int M=1,D; + bool first = true; + while ( ! f2.is_zero() ) { + Polynomial::pseudo_div(f1,f2,q,r,D); + if (!first) M*=D; + CGAL_NEF_TRACEV(f1);CGAL_NEF_TRACEV(f2);CGAL_NEF_TRACEV(q);CGAL_NEF_TRACEV(r);CGAL_NEF_TRACEV(M); + r /= r.content(); + f1=f2; f2=r; + first=false; + } + CGAL_NEF_TRACEV(f1.content()); + return Polynomial(F)*f1.abs(); +} + + + + +CGAL_INLINE_FUNCTION +void Polynomial::euclidean_div( + const Polynomial& f, const Polynomial& g, + Polynomial& q, Polynomial& r) +{ + r = f; r.copy_on_write(); + int rd=r.degree(), gd=g.degree(), qd; + if ( rd < gd ) { q = Polynomial(double(0)); } + else { qd = rd-gd+1; q = Polynomial(std::size_t(qd)); } + while ( rd >= gd && !(r.is_zero())) { + double S = r[rd] / g[gd]; + qd = rd-gd; + q.coeff(qd) += S; + r.minus_offsetmult(g,S,qd); + rd = r.degree(); + } + CGAL_postcondition( f==q*g+r ); +} + + + +CGAL_INLINE_FUNCTION +void Polynomial::pseudo_div( + const Polynomial& f, const Polynomial& g, + Polynomial& q, Polynomial& r, double& D) +{ + CGAL_NEF_TRACEN("pseudo_div "<(0); r = f; D = 1; + CGAL_postcondition(Polynomial(D)*f==q*g+r); return; + } + // now we know fd >= gd and f>=g + int qd=fd-gd, delta=qd+1, rd=fd; + q = Polynomial( std::size_t(delta) ); + double G = g[gd]; // highest order coeff of g + D = G; while (--delta) D*=G; // D = G^delta + Polynomial res = Polynomial(D)*f; + CGAL_NEF_TRACEN(" pseudo_div start "<= 0) { + double F = res[rd]; // highest order coeff of res + double t = F/G; // ensured to be integer by multiplication of D + q.coeff(qd) = t; // store q coeff + res.minus_offsetmult(g,t,qd); + if (res.is_zero()) break; + rd = res.degree(); + qd = rd - gd; + } + r = res; + CGAL_postcondition(Polynomial(D)*f==q*g+r); + CGAL_NEF_TRACEN(" returning "< Polynomial::gcd( + const Polynomial& p1, const Polynomial& p2) +{ CGAL_NEF_TRACEN("gcd("<(double(1)); + else return p2.abs(); + } + if ( p2.is_zero() ) + return p1.abs(); + + Polynomial f1 = p1.abs(); + Polynomial f2 = p2.abs(); + double f1c = f1.content(), f2c = f2.content(); + f1 /= f1c; f2 /= f2c; + Polynomial q,r; double M=1,D; + bool first = true; + while ( ! f2.is_zero() ) { + Polynomial::pseudo_div(f1,f2,q,r,D); + if (!first) M*=D; + CGAL_NEF_TRACEV(f1);CGAL_NEF_TRACEV(f2);CGAL_NEF_TRACEV(q);CGAL_NEF_TRACEV(r);CGAL_NEF_TRACEV(M); + r /= r.content(); + f1=f2; f2=r; + first=false; + } + CGAL_NEF_TRACEV(f1.content()); + return Polynomial(1)*f1.abs(); +} + + +} // end namespace Nef +}//end namespace CGAL diff --git a/Nef_2/src/CGAL/NefPolynomial.cpp b/Nef_2/src/CGAL/NefPolynomial.cpp index 261074845cf..aa717ca140c 100644 --- a/Nef_2/src/CGAL/NefPolynomial.cpp +++ b/Nef_2/src/CGAL/NefPolynomial.cpp @@ -19,176 +19,9 @@ // Author(s) : Michael Seel // Andreas Fabri +#ifndef CGAL_HEADER_ONLY + #include +#include -namespace CGAL{ - - namespace Nef { - -void Polynomial::euclidean_div( - const Polynomial& f, const Polynomial& g, - Polynomial& q, Polynomial& r) -{ - r = f; r.copy_on_write(); - int rd=r.degree(), gd=g.degree(), qd; - if ( rd < gd ) { q = Polynomial(int(0)); } - else { qd = rd-gd+1; q = Polynomial(std::size_t(qd)); } - while ( rd >= gd && !(r.is_zero())) { - int S = r[rd] / g[gd]; - qd = rd-gd; - q.coeff(qd) += S; - r.minus_offsetmult(g,S,qd); - rd = r.degree(); - } - CGAL_postcondition( f==q*g+r ); -} - - - -void Polynomial::pseudo_div( - const Polynomial& f, const Polynomial& g, - Polynomial& q, Polynomial& r, int& D) -{ - CGAL_NEF_TRACEN("pseudo_div "<(0); r = f; D = 1; - CGAL_postcondition(Polynomial(D)*f==q*g+r); return; - } - // now we know fd >= gd and f>=g - int qd=fd-gd, delta=qd+1, rd=fd; - { q = Polynomial( std::size_t(delta) ); }; // workaround for SUNPRO - int G = g[gd]; // highest order coeff of g - D = G; while (--delta) D*=G; // D = G^delta - Polynomial res = Polynomial(D)*f; - CGAL_NEF_TRACEN(" pseudo_div start "<= 0) { - int F = res[rd]; // highest order coeff of res - int t = F/G; // ensured to be integer by multiplication of D - q.coeff(qd) = t; // store q coeff - res.minus_offsetmult(g,t,qd); - if (res.is_zero()) break; - rd = res.degree(); - qd = rd - gd; - } - r = res; - CGAL_postcondition(Polynomial(D)*f==q*g+r); - CGAL_NEF_TRACEN(" returning "< Polynomial::gcd( - const Polynomial& p1, const Polynomial& p2) -{ CGAL_NEF_TRACEN("gcd("<(int(1)); - else return p2.abs(); - } - if ( p2.is_zero() ) - return p1.abs(); - - Polynomial f1 = p1.abs(); - Polynomial f2 = p2.abs(); - int f1c = f1.content(), f2c = f2.content(); - f1 /= f1c; f2 /= f2c; - int F = CGAL::gcd(f1c,f2c); - Polynomial q,r; int M=1,D; - bool first = true; - while ( ! f2.is_zero() ) { - Polynomial::pseudo_div(f1,f2,q,r,D); - if (!first) M*=D; - CGAL_NEF_TRACEV(f1);CGAL_NEF_TRACEV(f2);CGAL_NEF_TRACEV(q);CGAL_NEF_TRACEV(r);CGAL_NEF_TRACEV(M); - r /= r.content(); - f1=f2; f2=r; - first=false; - } - CGAL_NEF_TRACEV(f1.content()); - return Polynomial(F)*f1.abs(); -} - - - - -void Polynomial::euclidean_div( - const Polynomial& f, const Polynomial& g, - Polynomial& q, Polynomial& r) -{ - r = f; r.copy_on_write(); - int rd=r.degree(), gd=g.degree(), qd; - if ( rd < gd ) { q = Polynomial(double(0)); } - else { qd = rd-gd+1; q = Polynomial(std::size_t(qd)); } - while ( rd >= gd && !(r.is_zero())) { - double S = r[rd] / g[gd]; - qd = rd-gd; - q.coeff(qd) += S; - r.minus_offsetmult(g,S,qd); - rd = r.degree(); - } - CGAL_postcondition( f==q*g+r ); -} - - - -void Polynomial::pseudo_div( - const Polynomial& f, const Polynomial& g, - Polynomial& q, Polynomial& r, double& D) -{ - CGAL_NEF_TRACEN("pseudo_div "<(0); r = f; D = 1; - CGAL_postcondition(Polynomial(D)*f==q*g+r); return; - } - // now we know fd >= gd and f>=g - int qd=fd-gd, delta=qd+1, rd=fd; - q = Polynomial( std::size_t(delta) ); - double G = g[gd]; // highest order coeff of g - D = G; while (--delta) D*=G; // D = G^delta - Polynomial res = Polynomial(D)*f; - CGAL_NEF_TRACEN(" pseudo_div start "<= 0) { - double F = res[rd]; // highest order coeff of res - double t = F/G; // ensured to be integer by multiplication of D - q.coeff(qd) = t; // store q coeff - res.minus_offsetmult(g,t,qd); - if (res.is_zero()) break; - rd = res.degree(); - qd = rd - gd; - } - r = res; - CGAL_postcondition(Polynomial(D)*f==q*g+r); - CGAL_NEF_TRACEN(" returning "< Polynomial::gcd( - const Polynomial& p1, const Polynomial& p2) -{ CGAL_NEF_TRACEN("gcd("<(double(1)); - else return p2.abs(); - } - if ( p2.is_zero() ) - return p1.abs(); - - Polynomial f1 = p1.abs(); - Polynomial f2 = p2.abs(); - double f1c = f1.content(), f2c = f2.content(); - f1 /= f1c; f2 /= f2c; - Polynomial q,r; double M=1,D; - bool first = true; - while ( ! f2.is_zero() ) { - Polynomial::pseudo_div(f1,f2,q,r,D); - if (!first) M*=D; - CGAL_NEF_TRACEV(f1);CGAL_NEF_TRACEV(f2);CGAL_NEF_TRACEV(q);CGAL_NEF_TRACEV(r);CGAL_NEF_TRACEV(M); - r /= r.content(); - f1=f2; f2=r; - first=false; - } - CGAL_NEF_TRACEV(f1.content()); - return Polynomial(1)*f1.abs(); -} - - -} // end namespace Nef -}//end namespace CGAL +#endif // CGAL_HEADER_ONLY diff --git a/cppfiles.txt b/cppfiles.txt index 1aca68caf54..b26c6096497 100644 --- a/cppfiles.txt +++ b/cppfiles.txt @@ -3,7 +3,6 @@ CGAL: Clement: #include "/home/gdamiand/sources/CGAL/Geomview/src/CGAL/Geomview_stream.cpp" -#include "/home/gdamiand/sources/CGAL/Nef_2/src/CGAL/NefPolynomial.cpp" #include "/home/gdamiand/sources/CGAL/Kinetic_data_structures/src/CGAL/JAMA_numeric_solver.cpp" #include "/home/gdamiand/sources/CGAL/Kinetic_data_structures/src/CGAL/KDS_Log.cpp" #include "/home/gdamiand/sources/CGAL/Kinetic_data_structures/src/CGAL/numeric_solvers_support.cpp" @@ -17,20 +16,21 @@ Clement: Guillaume -#include "/home/gdamiand/sources/CGAL/STL_Extension/src/CGAL/assertions.cpp" // variables globales -#include "/home/gdamiand/sources/CGAL/Stream_support/src/CGAL/io.cpp" // variable statique de classe -#include "/home/gdamiand/sources/CGAL/Stream_support/src/CGAL/Color.cpp" // constantes globales -#include "/home/gdamiand/sources/CGAL/Kernel_23/src/CGAL/kernel.cpp" // constantes globales -#include "/home/gdamiand/sources/CGAL/Number_types/src/CGAL/Interval_arithmetic.cpp" // constante globale +DONE #include "/home/gdamiand/sources/CGAL/STL_Extension/src/CGAL/assertions.cpp" // variables globales +DONE #include "/home/gdamiand/sources/CGAL/Stream_support/src/CGAL/io.cpp" // variable statique de classe +DONE #include "/home/gdamiand/sources/CGAL/Stream_support/src/CGAL/Color.cpp" // constantes globales +DONE #include "/home/gdamiand/sources/CGAL/Kernel_23/src/CGAL/kernel.cpp" // constantes globales +DONE #include "/home/gdamiand/sources/CGAL/Number_types/src/CGAL/Interval_arithmetic.cpp" // constante globale -#include "/home/gdamiand/sources/CGAL/Intersections_2/src/CGAL/Bbox_2_intersections.cpp" -#include "/home/gdamiand/sources/CGAL/Stream_support/src/CGAL/File_header_extended_OFF.cpp" -#include "/home/gdamiand/sources/CGAL/Stream_support/src/CGAL/File_writer_inventor.cpp" -#include "/home/gdamiand/sources/CGAL/Stream_support/src/CGAL/File_header_OFF.cpp" -#include "/home/gdamiand/sources/CGAL/Stream_support/src/CGAL/File_scanner_OFF.cpp" -#include "/home/gdamiand/sources/CGAL/Stream_support/src/CGAL/File_writer_OFF.cpp" -#include "/home/gdamiand/sources/CGAL/Stream_support/src/CGAL/File_writer_VRML_2.cpp" -#include "/home/gdamiand/sources/CGAL/Stream_support/src/CGAL/File_writer_wavefront.cpp" +DONE #include "/home/gdamiand/sources/CGAL/Intersections_2/src/CGAL/Bbox_2_intersections.cpp" +DONE #include "/home/gdamiand/sources/CGAL/Stream_support/src/CGAL/File_header_extended_OFF.cpp" +DONE #include "/home/gdamiand/sources/CGAL/Stream_support/src/CGAL/File_writer_inventor.cpp" +DONE #include "/home/gdamiand/sources/CGAL/Stream_support/src/CGAL/File_header_OFF.cpp" +DONE #include "/home/gdamiand/sources/CGAL/Stream_support/src/CGAL/File_scanner_OFF.cpp" +DONE #include "/home/gdamiand/sources/CGAL/Stream_support/src/CGAL/File_writer_OFF.cpp" +DONE #include "/home/gdamiand/sources/CGAL/Stream_support/src/CGAL/File_writer_VRML_2.cpp" +DONE #include "/home/gdamiand/sources/CGAL/Stream_support/src/CGAL/File_writer_wavefront.cpp" +DONE #include "/home/gdamiand/sources/CGAL/Nef_2/src/CGAL/NefPolynomial.cpp" CGAL_Core: From 60ee1c73894981a6e1227f85c6cfdeafa74713a9 Mon Sep 17 00:00:00 2001 From: Guillaume Damiand Date: Tue, 4 Nov 2014 12:38:58 +0100 Subject: [PATCH 10/30] cpp file --- cppfiles.txt | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/cppfiles.txt b/cppfiles.txt index b26c6096497..6c1d20b87bc 100644 --- a/cppfiles.txt +++ b/cppfiles.txt @@ -32,6 +32,15 @@ DONE #include "/home/gdamiand/sources/CGAL/Stream_support/src/CGAL/File_writer_V DONE #include "/home/gdamiand/sources/CGAL/Stream_support/src/CGAL/File_writer_wavefront.cpp" DONE #include "/home/gdamiand/sources/CGAL/Nef_2/src/CGAL/NefPolynomial.cpp" +CGAL_Qt4: + +DONE #include "/home/gdamiand/sources/CGAL/GraphicsView/src/CGAL_Qt4/utility.cpp" +DONE #include "/home/gdamiand/sources/CGAL/GraphicsView/src/CGAL_Qt4/resources.cpp" +DONE #include "/home/gdamiand/sources/CGAL/GraphicsView/src/CGAL_Qt4/debug.cpp" +DONE #include "/home/gdamiand/sources/CGAL/GraphicsView/src/CGAL_Qt4/GraphicsViewPolylineInput.cpp" +DONE #include "/home/gdamiand/sources/CGAL/GraphicsView/src/CGAL_Qt4/DemosMainWindow.cpp" +DONE #include "/home/gdamiand/sources/CGAL/GraphicsView/src/CGAL_Qt4/GraphicsViewNavigation.cpp" + CGAL_Core: #include "/home/gdamiand/sources/CGAL/CGAL_Core/src/CGAL_Core/CoreIO.cpp" @@ -62,12 +71,3 @@ CGAL_ImageIO: #include "/home/gdamiand/sources/CGAL/CGAL_ImageIO/src/CGAL_ImageIO/pnm.cpp" #include "/home/gdamiand/sources/CGAL/CGAL_ImageIO/src/CGAL_ImageIO/ImageIO.cpp" #include "/home/gdamiand/sources/CGAL/CGAL_ImageIO/src/CGAL_ImageIO/inr.cpp" - -CGAL_Qt4: - -DONE #include "/home/gdamiand/sources/CGAL/GraphicsView/src/CGAL_Qt4/utility.cpp" -DONE #include "/home/gdamiand/sources/CGAL/GraphicsView/src/CGAL_Qt4/resources.cpp" -DONE #include "/home/gdamiand/sources/CGAL/GraphicsView/src/CGAL_Qt4/debug.cpp" -DONE #include "/home/gdamiand/sources/CGAL/GraphicsView/src/CGAL_Qt4/GraphicsViewPolylineInput.cpp" -DONE #include "/home/gdamiand/sources/CGAL/GraphicsView/src/CGAL_Qt4/DemosMainWindow.cpp" -DONE #include "/home/gdamiand/sources/CGAL/GraphicsView/src/CGAL_Qt4/GraphicsViewNavigation.cpp" From e2ce91fa42024f8fdd2f5d0507eb5b09bf654f85 Mon Sep 17 00:00:00 2001 From: Guillaume Damiand Date: Tue, 4 Nov 2014 18:42:29 +0100 Subject: [PATCH 11/30] One more file (Geomview_stream.cpp) --- Geomview/include/CGAL/IO/Geomview_stream.h | 4 + .../include/CGAL/IO/Geomview_stream_impl.h | 615 ++++++++++++++++++ Geomview/src/CGAL/Geomview_stream.cpp | 545 +--------------- cppfiles.txt | 2 +- 4 files changed, 622 insertions(+), 544 deletions(-) create mode 100644 Geomview/include/CGAL/IO/Geomview_stream_impl.h diff --git a/Geomview/include/CGAL/IO/Geomview_stream.h b/Geomview/include/CGAL/IO/Geomview_stream.h index e3b3f222fe1..e7d5f8ef80e 100644 --- a/Geomview/include/CGAL/IO/Geomview_stream.h +++ b/Geomview/include/CGAL/IO/Geomview_stream.h @@ -593,4 +593,8 @@ operator>>(Geomview_stream &gv, Point_3 &point) } //namespace CGAL +#ifdef CGAL_HEADER_ONLY +#include +#endif // CGAL_HEADER_ONLY + #endif // CGAL_GEOMVIEW_STREAM_H diff --git a/Geomview/include/CGAL/IO/Geomview_stream_impl.h b/Geomview/include/CGAL/IO/Geomview_stream_impl.h new file mode 100644 index 00000000000..131a57b9264 --- /dev/null +++ b/Geomview/include/CGAL/IO/Geomview_stream_impl.h @@ -0,0 +1,615 @@ +// Copyright (c) 1999-2004 +// 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$ +// +// +// Author(s) : Andreas Fabri, Herve Bronnimann, Sylvain Pion + +#ifdef CGAL_HEADER_ONLY +#define CGAL_INLINE_FUNCTION inline +#else +#define CGAL_INLINE_FUNCTION +#endif + +#include + +#ifdef CGAL_USE_GEOMVIEW + +#include +#include +#include +#include +#include +#include + +#include // kill() on SunPro requires these 2 #includes. +#include + +#include +#include + +namespace CGAL { + +CGAL_INLINE_FUNCTION +Geomview_stream::Geomview_stream(const Bbox_3 &bbox, + const char *machine, + const char *login) + : bb(bbox), vertex_color(BLACK), edge_color(BLACK), face_color(BLACK), + wired_flag(false), echo_flag(true), raw_flag(false), + trace_flag(false), binary_flag(false), + line_width(1) +{ + setup_geomview(machine, login); + frame(bbox); + pickplane(bbox); + set_vertex_radius((bbox.xmax() - bbox.xmin())/100.0); +} + +CGAL_INLINE_FUNCTION +Geomview_stream::~Geomview_stream() +{ + kill(pid, SIGKILL); // kills geomview +} + +CGAL_INLINE_FUNCTION +void Geomview_stream::setup_geomview(const char *machine, const char *login) +{ + int pipe_out[2], pipe_in[2]; + + // Communication between CGAL and geomview should be possible + // in two directions. To achieve this we open two pipes + + std::cout << "Starting Geomview..." << std::flush; + if (pipe(pipe_out) < 0) { + CGAL_error_msg( "out pipe failed" ); + } + + if (pipe(pipe_in) < 0) { + CGAL_error_msg( "in pipe failed" ); + } + + switch (pid = fork()){ + case -1: + CGAL_error_msg( "fork failed" ); + case 0: // The child process + close(pipe_out[1]); // does not write to the out pipe, + close(pipe_in[0]); // does not read from the in pipe. + + if (dup2(pipe_out[0], 0) != 0) + std::cerr << "Connect pipe to stdin failed." << std::endl; + if (dup2(pipe_in[1], 1) != 1) + std::cerr << "Connect pipe to stdout failed." << std::endl; + + if (machine && (std::strlen(machine)>0)) { + std::string s (" rgeomview "); + s += machine; + s += ":0.0"; + execlp("rsh", "rsh", machine, "-l", login, s.data(), + static_cast(NULL)); // cast to stop gcc warning + } else { + execlp("geomview", "geomview", "-c", "-", + static_cast(NULL)); // cast to stop gcc warning + } + + // if we get to this point something went wrong. + std::cerr << "execl geomview failed" << std::endl; + switch(errno) { + case EACCES: + std::cerr << "please check your environment variable PATH" + << std::endl; + std::cerr << "make sure the file `geomview' is contained in it" + << std::endl; + std::cerr << "and is executable" << std::endl; + break; + case ELOOP: + std::cerr << "too many links for filename `geomview'" << std::endl; + break; + default: + std::cerr << "error number " << errno << " (check `man execlp')" + << std::endl; + }; + CGAL_error(); + default: // The parent process + close(pipe_out[0]); // does not read from the out pipe, + close(pipe_in[1]); // does not write to the in pipe. + + in = pipe_in[0]; + out = pipe_out[1]; + + // Necessary to wait a little bit for Geomview, + // otherwise you won't be able to ask for points... + sleep(1); + +#if 1 + // We want to get rid of the requirement in the CGAL doc about + // (echo "started"). But we want to be backward compatible, that is, + // people who have this echo in their .geomview must still have CGAL + // working, at least for a few public releases. + // So the plan is to send, from CGAL, the command : (echo "CGAL-3D") + // It's the same length as "started", 7. + // Then we read 7 chars from Geomview, and test which string it is. + // If it's "CGAL-3D", then fine, the user doesn't have .geomview with + // the back-compatible echo command. + // In the very long run, we'll be able to get rid of all this code as + // well. + // Maybe we should simply read the pipe, till we find "CGAL-3D" ? + + *this << "(echo \"CGAL-3D\")"; + + char inbuf[10]; + std::size_t retread=::read(in, inbuf, 7); + (void)retread; + + if (std::strncmp(inbuf, "started", 7) == 0) + { + // std::cerr << "You still have a .geomview file with the\n" + // << "(echo \"started\") command. Note that this is not\n" + // << "compulsory anymore, since CGAL 2.3" << std::endl; + + // Then the next one is supposed to be CGAL-3D. + retread=::read(in, inbuf, 7); + (void)retread; + if (std::strncmp(inbuf, "CGAL-3D", 7) != 0) + std::cerr << "Unexpected string from Geomview !" << std::endl; + } + else if (std::strncmp(inbuf, "CGAL-3D", 7) == 0) + { + // std::cerr << "Good, you don't have a .geomview file with the\n" + // << "(echo \"started\") command" << std::endl; + } + else + { + std::cerr << "Unexcepted string from Geomview at initialization!\n" + << "Going on nevertheless !" << std::endl; + } +#else + // Old original version + char inbuf[10]; + // Waits for "started" from the .geomview file. + retread=::read(in, inbuf, 7); + (void)retread; +#endif + + std::cout << "done." << std::endl; + + (*this) << "(normalization g* none)(bbox-draw g* no)"; + } +} + +CGAL_INLINE_FUNCTION +void +Geomview_stream::pickplane(const Bbox_3 &bbox) +{ + bool bin_bak = set_binary_mode(); + (*this) << "(geometry pickplane {QUAD BINARY\n" + << 1 + // here are the four corners + << bbox.xmin() << bbox.ymin() << bbox.zmin() + << bbox.xmin() << bbox.ymax() << bbox.zmin() + << bbox.xmax() << bbox.ymax() << bbox.zmin() + << bbox.xmax() << bbox.ymin() << bbox.zmin() + + // close the text bracket + << "}) (pickable pickplane no)"; + set_ascii_mode(bin_bak); +} + +CGAL_INLINE_FUNCTION +void +Geomview_stream::clear() +{ + (*this) << "(delete World)"; + id.clear(); +} + +CGAL_INLINE_FUNCTION +void +Geomview_stream::look_recenter() +{ + (*this) << "(look-recenter World)"; +} + +CGAL_INLINE_FUNCTION +Geomview_stream& +Geomview_stream::operator<<(const std::string & s) +{ + if ((int)s.length() != ::write(out, s.data(), s.length())) { + CGAL_error_msg( "write problem in the pipe while sending data to geomview" ); + } + trace(s); + + return *this; +} + +CGAL_INLINE_FUNCTION +Geomview_stream& +Geomview_stream::operator<<(int i) +{ + // Depending on the mode chosen + if (get_binary_mode()) { + // we write raw binary data to the stream. + int num = i; + I_swap_to_big_endian(num); + std::size_t retwrite=::write(out, (char*)&num, sizeof(num)); + (void)retwrite; + trace(i); + } else { + // transform the int in a character sequence and put whitespace around + std::ostringstream str; + str << i << ' ' << std::ends; + *this << str.str().c_str(); + } + + return *this; +} + +CGAL_INLINE_FUNCTION +Geomview_stream& +Geomview_stream::operator<<(unsigned int i) +{ + // Depending on the mode chosen + if (get_binary_mode()) { + // we write raw binary data to the stream. + unsigned int num = i; + I_swap_to_big_endian(num); + std::size_t retwrite=::write(out, (char*)&num, sizeof(num)); + (void)retwrite; + trace(i); + } else { + // transform the int in a character sequence and put whitespace around + std::ostringstream str; + str << i << ' ' << std::ends; + *this << str.str().c_str(); + } + + return *this; +} + +CGAL_INLINE_FUNCTION +Geomview_stream& +Geomview_stream::operator<<(long i) +{ + return operator<<((int) i); +} + +CGAL_INLINE_FUNCTION +Geomview_stream& +Geomview_stream::operator<<(unsigned long i) +{ + return operator<<((unsigned int) i); +} + +CGAL_INLINE_FUNCTION +Geomview_stream& +Geomview_stream::operator<<(double d) +{ + float f = d; + if (get_binary_mode()) { + float num = d; + I_swap_to_big_endian(num); + std::size_t retwrite= ::write(out, (char*)&num, sizeof(num)); + (void)retwrite; + trace(f); + } else { + // 'copy' the float in a string and append a blank + std::ostringstream str; + str << f << ' ' << std::ends; + *this << str.str().c_str(); + } + return *this; +} + +CGAL_INLINE_FUNCTION +Geomview_stream& +operator<<(Geomview_stream &gv, const Bbox_2 &bbox) +{ + bool ascii_bak = gv.set_ascii_mode(); + gv << "(geometry " << gv.get_new_id("Bbox") + << " {VECT 1 5 0 5 0 "; + // here are the four corners + + gv << bbox.xmin() << bbox.ymin() << 0.0 + << bbox.xmin() << bbox.ymax() << 0.0 + << bbox.xmax() << bbox.ymax() << 0.0 + << bbox.xmax() << bbox.ymin() << 0.0 + << bbox.xmin() << bbox.ymin() << 0.0; + + // close the text bracket + gv << "})"; + gv.set_ascii_mode(ascii_bak); + + return gv; +} + +CGAL_INLINE_FUNCTION +Geomview_stream& +operator<<(Geomview_stream &gv, const Bbox_3 &bbox) +{ + bool ascii_bak = gv.set_ascii_mode(); + gv << "(geometry " << gv.get_new_id("Bbox") + << " {appearance {material {edgecolor " + << gv.ecr() << gv.ecg() << gv.ecb() << "}}{SKEL 8 4 " + // here are the corners + << bbox.xmin() << bbox.ymin() << bbox.zmin() + << bbox.xmin() << bbox.ymax() << bbox.zmin() + << bbox.xmax() << bbox.ymax() << bbox.zmin() + << bbox.xmax() << bbox.ymin() << bbox.zmin() + << bbox.xmax() << bbox.ymin() << bbox.zmax() + << bbox.xmax() << bbox.ymax() << bbox.zmax() + << bbox.xmin() << bbox.ymax() << bbox.zmax() + << bbox.xmin() << bbox.ymin() << bbox.zmax() + + << "10 0 1 2 3 4 5 6 7 0 3\n" + << "2 1 6\n" + << "2 2 5\n" + << "2 4 7\n" + + // close the text bracket + << "}})"; + gv.set_ascii_mode(ascii_bak); + + return gv; +} + +CGAL_INLINE_FUNCTION +void +Geomview_stream::set_bg_color(const Color &c) +{ + bool ascii_bak = set_ascii_mode(); + *this << "(backcolor \"Camera\" " + << double(c.r())/255.0 + << double(c.g())/255.0 + << double(c.b())/255.0 + << ")"; + set_ascii_mode(ascii_bak); +} + +CGAL_INLINE_FUNCTION +Geomview_stream& +Geomview_stream::operator<<(const Color &c) +{ + vertex_color = edge_color = face_color = c; + return (*this); +} + +CGAL_INLINE_FUNCTION +Color +Geomview_stream::get_vertex_color() const +{ + return vertex_color; +} + +CGAL_INLINE_FUNCTION +Color +Geomview_stream::get_edge_color() const +{ + return edge_color; +} + +CGAL_INLINE_FUNCTION +Color +Geomview_stream::get_face_color() const +{ + return face_color; +} + +CGAL_INLINE_FUNCTION +Color +Geomview_stream::set_vertex_color(const Color &c) +{ + Color old = vertex_color; + vertex_color = c; + return old; +} + +CGAL_INLINE_FUNCTION +Color +Geomview_stream::set_edge_color(const Color &c) +{ + Color old = edge_color; + edge_color = c; + return old; +} + +CGAL_INLINE_FUNCTION +Color +Geomview_stream::set_face_color(const Color &c) +{ + Color old = face_color; + face_color = c; + return old; +} + +CGAL_INLINE_FUNCTION +double +Geomview_stream::vcr() const +{ + return double(vertex_color.r())/255.0; +} + +CGAL_INLINE_FUNCTION +double +Geomview_stream::vcg() const +{ + return double(vertex_color.g())/255.0; +} + +CGAL_INLINE_FUNCTION +double +Geomview_stream::vcb() const +{ + return double(vertex_color.b())/255.0; +} + +CGAL_INLINE_FUNCTION +double +Geomview_stream::ecr() const +{ + return double(edge_color.r())/255.0; +} + +CGAL_INLINE_FUNCTION +double +Geomview_stream::ecg() const +{ + return double(edge_color.g())/255.0; +} + +CGAL_INLINE_FUNCTION +double +Geomview_stream::ecb() const +{ + return double(edge_color.b())/255.0; +} + +CGAL_INLINE_FUNCTION +double +Geomview_stream::fcr() const +{ + return double(face_color.r())/255.0; +} + +CGAL_INLINE_FUNCTION +double +Geomview_stream::fcg() const +{ + return double(face_color.g())/255.0; +} + +CGAL_INLINE_FUNCTION +double +Geomview_stream::fcb() const +{ + return double(face_color.b())/255.0; +} + +CGAL_INLINE_FUNCTION +void +Geomview_stream::frame(const Bbox_3 &bbox) +{ + (*this) << bbox << "(look-recenter g0 c0)"; +} + +CGAL_INLINE_FUNCTION +Geomview_stream& +Geomview_stream::operator>>(char *expr) +{ + // Skip whitespaces + do { + std::size_t retread=::read(in, expr, 1); + (void)retread; + } while (expr[0] != '('); + + int pcount = 1; + int i = 1; + while (1) { + std::size_t retread=::read(in, &expr[i], 1); + (void)retread; + if (expr[i] == ')'){ + pcount--; + } else if (expr[i] == '('){ + pcount++; + } + if (pcount == 0){ + expr[i+1]='\0'; + break; // we encountered a balanced number of parantheses + } + i++; + } + return *this; +} + +// Parse a Lisp expression, return a pointer to the beginning of the +// nth subexpression, and terminate it by '\0'. +// It's either a word terminated by ' ' or ')', or a well parenthesed +// expression, or a quoted "string". +CGAL_INLINE_FUNCTION +char* +Geomview_stream::nth(char* s, int count) +{ + s++; // skip first character (always a parenthesis) + + // Skip "count" words. + for(; count != 0; count--) { + while (*s == ' ') // skip whitespaces + s++; + s++; + while (*s != ' ') // skip a word + s++; + } + while (*s == ' ') // skip whitespaces + s++; + + // Now we have the beginning of the searched sub-expression. + int j = 1; + if (*s == '(') // Case of a well-parenthesed expression. + for (int pcount = 1; pcount != 0;) { + if (s[j] == ')') pcount--; + if (s[j] == '(') pcount++; + j++; + } + else if (*s == '"') { // Case of a quoted "string". + while (s[j] != '"') + j++; + j++; + } + else // Case of a word terminated by ' ' or ')'. + while (s[j] != ' ' && s[j] != ')') + j++; + + s[j] = '\0'; + return s; +} + +CGAL_INLINE_FUNCTION +void +Geomview_stream::parse_point(const char* pickpoint, + double &x, double &y, double &z, double &w) +{ + std::stringstream ss; + ss << pickpoint << std::ends; + + char parenthesis; + ss >> parenthesis >> x >> y >> z >> w; +} + +CGAL_INLINE_FUNCTION +std::string +Geomview_stream::get_new_id(const std::string & s) +{ + std::ostringstream str; + str << s << id[s]++ << std::ends; + return str.str(); +} + +} //namespace CGAL + +#else + +#ifndef CGAL_HEADER_ONLY +// Add a dummy symbol to prevent warnings of empty translation unit. +namespace CGAL { +namespace { +int dummy; +} +} //namespace CGAL +#endif + +#endif // CGAL_USE_GEOMVIEW diff --git a/Geomview/src/CGAL/Geomview_stream.cpp b/Geomview/src/CGAL/Geomview_stream.cpp index a34af8ceabc..927d518f8d0 100644 --- a/Geomview/src/CGAL/Geomview_stream.cpp +++ b/Geomview/src/CGAL/Geomview_stream.cpp @@ -22,550 +22,9 @@ // // Author(s) : Andreas Fabri, Herve Bronnimann, Sylvain Pion -#include - -#ifdef CGAL_USE_GEOMVIEW - -#include -#include -#include -#include -#include -#include - -#include // kill() on SunPro requires these 2 #includes. -#include +#ifndef CGAL_HEADER_ONLY #include -#include +#include -namespace CGAL { - -Geomview_stream::Geomview_stream(const Bbox_3 &bbox, - const char *machine, - const char *login) - : bb(bbox), vertex_color(BLACK), edge_color(BLACK), face_color(BLACK), - wired_flag(false), echo_flag(true), raw_flag(false), - trace_flag(false), binary_flag(false), - line_width(1) -{ - setup_geomview(machine, login); - frame(bbox); - pickplane(bbox); - set_vertex_radius((bbox.xmax() - bbox.xmin())/100.0); -} - -Geomview_stream::~Geomview_stream() -{ - kill(pid, SIGKILL); // kills geomview -} - -void Geomview_stream::setup_geomview(const char *machine, const char *login) -{ - int pipe_out[2], pipe_in[2]; - - // Communication between CGAL and geomview should be possible - // in two directions. To achieve this we open two pipes - - std::cout << "Starting Geomview..." << std::flush; - if (pipe(pipe_out) < 0) { - CGAL_error_msg( "out pipe failed" ); - } - - if (pipe(pipe_in) < 0) { - CGAL_error_msg( "in pipe failed" ); - } - - switch (pid = fork()){ - case -1: - CGAL_error_msg( "fork failed" ); - case 0: // The child process - close(pipe_out[1]); // does not write to the out pipe, - close(pipe_in[0]); // does not read from the in pipe. - - if (dup2(pipe_out[0], 0) != 0) - std::cerr << "Connect pipe to stdin failed." << std::endl; - if (dup2(pipe_in[1], 1) != 1) - std::cerr << "Connect pipe to stdout failed." << std::endl; - - if (machine && (std::strlen(machine)>0)) { - std::string s (" rgeomview "); - s += machine; - s += ":0.0"; - execlp("rsh", "rsh", machine, "-l", login, s.data(), - static_cast(NULL)); // cast to stop gcc warning - } else { - execlp("geomview", "geomview", "-c", "-", - static_cast(NULL)); // cast to stop gcc warning - } - - // if we get to this point something went wrong. - std::cerr << "execl geomview failed" << std::endl; - switch(errno) { - case EACCES: - std::cerr << "please check your environment variable PATH" - << std::endl; - std::cerr << "make sure the file `geomview' is contained in it" - << std::endl; - std::cerr << "and is executable" << std::endl; - break; - case ELOOP: - std::cerr << "too many links for filename `geomview'" << std::endl; - break; - default: - std::cerr << "error number " << errno << " (check `man execlp')" - << std::endl; - }; - CGAL_error(); - default: // The parent process - close(pipe_out[0]); // does not read from the out pipe, - close(pipe_in[1]); // does not write to the in pipe. - - in = pipe_in[0]; - out = pipe_out[1]; - - // Necessary to wait a little bit for Geomview, - // otherwise you won't be able to ask for points... - sleep(1); - -#if 1 - // We want to get rid of the requirement in the CGAL doc about - // (echo "started"). But we want to be backward compatible, that is, - // people who have this echo in their .geomview must still have CGAL - // working, at least for a few public releases. - // So the plan is to send, from CGAL, the command : (echo "CGAL-3D") - // It's the same length as "started", 7. - // Then we read 7 chars from Geomview, and test which string it is. - // If it's "CGAL-3D", then fine, the user doesn't have .geomview with - // the back-compatible echo command. - // In the very long run, we'll be able to get rid of all this code as - // well. - // Maybe we should simply read the pipe, till we find "CGAL-3D" ? - - *this << "(echo \"CGAL-3D\")"; - - char inbuf[10]; - std::size_t retread=::read(in, inbuf, 7); - (void)retread; - - if (std::strncmp(inbuf, "started", 7) == 0) - { - // std::cerr << "You still have a .geomview file with the\n" - // << "(echo \"started\") command. Note that this is not\n" - // << "compulsory anymore, since CGAL 2.3" << std::endl; - - // Then the next one is supposed to be CGAL-3D. - retread=::read(in, inbuf, 7); - (void)retread; - if (std::strncmp(inbuf, "CGAL-3D", 7) != 0) - std::cerr << "Unexpected string from Geomview !" << std::endl; - } - else if (std::strncmp(inbuf, "CGAL-3D", 7) == 0) - { - // std::cerr << "Good, you don't have a .geomview file with the\n" - // << "(echo \"started\") command" << std::endl; - } - else - { - std::cerr << "Unexcepted string from Geomview at initialization!\n" - << "Going on nevertheless !" << std::endl; - } -#else - // Old original version - char inbuf[10]; - // Waits for "started" from the .geomview file. - retread=::read(in, inbuf, 7); - (void)retread; #endif - - std::cout << "done." << std::endl; - - (*this) << "(normalization g* none)(bbox-draw g* no)"; - } -} - -void -Geomview_stream::pickplane(const Bbox_3 &bbox) -{ - bool bin_bak = set_binary_mode(); - (*this) << "(geometry pickplane {QUAD BINARY\n" - << 1 - // here are the four corners - << bbox.xmin() << bbox.ymin() << bbox.zmin() - << bbox.xmin() << bbox.ymax() << bbox.zmin() - << bbox.xmax() << bbox.ymax() << bbox.zmin() - << bbox.xmax() << bbox.ymin() << bbox.zmin() - - // close the text bracket - << "}) (pickable pickplane no)"; - set_ascii_mode(bin_bak); -} - -void -Geomview_stream::clear() -{ - (*this) << "(delete World)"; - id.clear(); -} - -void -Geomview_stream::look_recenter() -{ - (*this) << "(look-recenter World)"; -} - -Geomview_stream& -Geomview_stream::operator<<(const std::string & s) -{ - if ((int)s.length() != ::write(out, s.data(), s.length())) { - CGAL_error_msg( "write problem in the pipe while sending data to geomview" ); - } - trace(s); - - return *this; -} - -Geomview_stream& -Geomview_stream::operator<<(int i) -{ - // Depending on the mode chosen - if (get_binary_mode()) { - // we write raw binary data to the stream. - int num = i; - I_swap_to_big_endian(num); - std::size_t retwrite=::write(out, (char*)&num, sizeof(num)); - (void)retwrite; - trace(i); - } else { - // transform the int in a character sequence and put whitespace around - std::ostringstream str; - str << i << ' ' << std::ends; - *this << str.str().c_str(); - } - - return *this; -} - -Geomview_stream& -Geomview_stream::operator<<(unsigned int i) -{ - // Depending on the mode chosen - if (get_binary_mode()) { - // we write raw binary data to the stream. - unsigned int num = i; - I_swap_to_big_endian(num); - std::size_t retwrite=::write(out, (char*)&num, sizeof(num)); - (void)retwrite; - trace(i); - } else { - // transform the int in a character sequence and put whitespace around - std::ostringstream str; - str << i << ' ' << std::ends; - *this << str.str().c_str(); - } - - return *this; -} - -Geomview_stream& -Geomview_stream::operator<<(long i) -{ - return operator<<((int) i); -} - -Geomview_stream& -Geomview_stream::operator<<(unsigned long i) -{ - return operator<<((unsigned int) i); -} - -Geomview_stream& -Geomview_stream::operator<<(double d) -{ - float f = d; - if (get_binary_mode()) { - float num = d; - I_swap_to_big_endian(num); - std::size_t retwrite= ::write(out, (char*)&num, sizeof(num)); - (void)retwrite; - trace(f); - } else { - // 'copy' the float in a string and append a blank - std::ostringstream str; - str << f << ' ' << std::ends; - *this << str.str().c_str(); - } - return *this; -} - -Geomview_stream& -operator<<(Geomview_stream &gv, const Bbox_2 &bbox) -{ - bool ascii_bak = gv.set_ascii_mode(); - gv << "(geometry " << gv.get_new_id("Bbox") - << " {VECT 1 5 0 5 0 "; - // here are the four corners - - gv << bbox.xmin() << bbox.ymin() << 0.0 - << bbox.xmin() << bbox.ymax() << 0.0 - << bbox.xmax() << bbox.ymax() << 0.0 - << bbox.xmax() << bbox.ymin() << 0.0 - << bbox.xmin() << bbox.ymin() << 0.0; - - // close the text bracket - gv << "})"; - gv.set_ascii_mode(ascii_bak); - - return gv; -} - -Geomview_stream& -operator<<(Geomview_stream &gv, const Bbox_3 &bbox) -{ - bool ascii_bak = gv.set_ascii_mode(); - gv << "(geometry " << gv.get_new_id("Bbox") - << " {appearance {material {edgecolor " - << gv.ecr() << gv.ecg() << gv.ecb() << "}}{SKEL 8 4 " - // here are the corners - << bbox.xmin() << bbox.ymin() << bbox.zmin() - << bbox.xmin() << bbox.ymax() << bbox.zmin() - << bbox.xmax() << bbox.ymax() << bbox.zmin() - << bbox.xmax() << bbox.ymin() << bbox.zmin() - << bbox.xmax() << bbox.ymin() << bbox.zmax() - << bbox.xmax() << bbox.ymax() << bbox.zmax() - << bbox.xmin() << bbox.ymax() << bbox.zmax() - << bbox.xmin() << bbox.ymin() << bbox.zmax() - - << "10 0 1 2 3 4 5 6 7 0 3\n" - << "2 1 6\n" - << "2 2 5\n" - << "2 4 7\n" - - // close the text bracket - << "}})"; - gv.set_ascii_mode(ascii_bak); - - return gv; -} - -void -Geomview_stream::set_bg_color(const Color &c) -{ - bool ascii_bak = set_ascii_mode(); - *this << "(backcolor \"Camera\" " - << double(c.r())/255.0 - << double(c.g())/255.0 - << double(c.b())/255.0 - << ")"; - set_ascii_mode(ascii_bak); -} - -Geomview_stream& -Geomview_stream::operator<<(const Color &c) -{ - vertex_color = edge_color = face_color = c; - return (*this); -} - -Color -Geomview_stream::get_vertex_color() const -{ - return vertex_color; -} - -Color -Geomview_stream::get_edge_color() const -{ - return edge_color; -} - -Color -Geomview_stream::get_face_color() const -{ - return face_color; -} - -Color -Geomview_stream::set_vertex_color(const Color &c) -{ - Color old = vertex_color; - vertex_color = c; - return old; -} - -Color -Geomview_stream::set_edge_color(const Color &c) -{ - Color old = edge_color; - edge_color = c; - return old; -} - -Color -Geomview_stream::set_face_color(const Color &c) -{ - Color old = face_color; - face_color = c; - return old; -} - -double -Geomview_stream::vcr() const -{ - return double(vertex_color.r())/255.0; -} - -double -Geomview_stream::vcg() const -{ - return double(vertex_color.g())/255.0; -} - -double -Geomview_stream::vcb() const -{ - return double(vertex_color.b())/255.0; -} - -double -Geomview_stream::ecr() const -{ - return double(edge_color.r())/255.0; -} - -double -Geomview_stream::ecg() const -{ - return double(edge_color.g())/255.0; -} - -double -Geomview_stream::ecb() const -{ - return double(edge_color.b())/255.0; -} - -double -Geomview_stream::fcr() const -{ - return double(face_color.r())/255.0; -} - -double -Geomview_stream::fcg() const -{ - return double(face_color.g())/255.0; -} - -double -Geomview_stream::fcb() const -{ - return double(face_color.b())/255.0; -} - -void -Geomview_stream::frame(const Bbox_3 &bbox) -{ - (*this) << bbox << "(look-recenter g0 c0)"; -} - -Geomview_stream& -Geomview_stream::operator>>(char *expr) -{ - // Skip whitespaces - do { - std::size_t retread=::read(in, expr, 1); - (void)retread; - } while (expr[0] != '('); - - int pcount = 1; - int i = 1; - while (1) { - std::size_t retread=::read(in, &expr[i], 1); - (void)retread; - if (expr[i] == ')'){ - pcount--; - } else if (expr[i] == '('){ - pcount++; - } - if (pcount == 0){ - expr[i+1]='\0'; - break; // we encountered a balanced number of parantheses - } - i++; - } - return *this; -} - -// Parse a Lisp expression, return a pointer to the beginning of the -// nth subexpression, and terminate it by '\0'. -// It's either a word terminated by ' ' or ')', or a well parenthesed -// expression, or a quoted "string". -char* -Geomview_stream::nth(char* s, int count) -{ - s++; // skip first character (always a parenthesis) - - // Skip "count" words. - for(; count != 0; count--) { - while (*s == ' ') // skip whitespaces - s++; - s++; - while (*s != ' ') // skip a word - s++; - } - while (*s == ' ') // skip whitespaces - s++; - - // Now we have the beginning of the searched sub-expression. - int j = 1; - if (*s == '(') // Case of a well-parenthesed expression. - for (int pcount = 1; pcount != 0;) { - if (s[j] == ')') pcount--; - if (s[j] == '(') pcount++; - j++; - } - else if (*s == '"') { // Case of a quoted "string". - while (s[j] != '"') - j++; - j++; - } - else // Case of a word terminated by ' ' or ')'. - while (s[j] != ' ' && s[j] != ')') - j++; - - s[j] = '\0'; - return s; -} - -void -Geomview_stream::parse_point(const char* pickpoint, - double &x, double &y, double &z, double &w) -{ - std::stringstream ss; - ss << pickpoint << std::ends; - - char parenthesis; - ss >> parenthesis >> x >> y >> z >> w; -} - -std::string -Geomview_stream::get_new_id(const std::string & s) -{ - std::ostringstream str; - str << s << id[s]++ << std::ends; - return str.str(); -} - -} //namespace CGAL - -#else - -// Add a dummy symbol to prevent warnings of empty translation unit. -namespace CGAL { -namespace { -int dummy; -} -} //namespace CGAL - -#endif // CGAL_USE_GEOMVIEW diff --git a/cppfiles.txt b/cppfiles.txt index 6c1d20b87bc..3192a2e6d93 100644 --- a/cppfiles.txt +++ b/cppfiles.txt @@ -2,7 +2,6 @@ CGAL: Clement: -#include "/home/gdamiand/sources/CGAL/Geomview/src/CGAL/Geomview_stream.cpp" #include "/home/gdamiand/sources/CGAL/Kinetic_data_structures/src/CGAL/JAMA_numeric_solver.cpp" #include "/home/gdamiand/sources/CGAL/Kinetic_data_structures/src/CGAL/KDS_Log.cpp" #include "/home/gdamiand/sources/CGAL/Kinetic_data_structures/src/CGAL/numeric_solvers_support.cpp" @@ -22,6 +21,7 @@ DONE #include "/home/gdamiand/sources/CGAL/Stream_support/src/CGAL/Color.cpp" // DONE #include "/home/gdamiand/sources/CGAL/Kernel_23/src/CGAL/kernel.cpp" // constantes globales DONE #include "/home/gdamiand/sources/CGAL/Number_types/src/CGAL/Interval_arithmetic.cpp" // constante globale +DONE #include "/home/gdamiand/sources/CGAL/Geomview/src/CGAL/Geomview_stream.cpp" DONE #include "/home/gdamiand/sources/CGAL/Intersections_2/src/CGAL/Bbox_2_intersections.cpp" DONE #include "/home/gdamiand/sources/CGAL/Stream_support/src/CGAL/File_header_extended_OFF.cpp" DONE #include "/home/gdamiand/sources/CGAL/Stream_support/src/CGAL/File_writer_inventor.cpp" From a4c39c813f3c69f573220704fed7236fa2126108 Mon Sep 17 00:00:00 2001 From: Guillaume Damiand Date: Fri, 14 Nov 2014 10:45:42 +0100 Subject: [PATCH 12/30] Inline for test_FPU_rounding_mode.cpp. There is const static variable, transformed into a static variable of a global function. This is not a problem since this is only used in debug mode to test the rounding mode at the end of the program. Testing it several times is ok. --- CMakeLists.txt | 2 ++ .../CGAL/Qt/GraphicsViewPolylineInput.h | 1 + .../CGAL/Qt/GraphicsViewPolylineInput_impl.h | 2 -- Number_types/include/CGAL/FPU.h | 16 +++++++++- Number_types/src/CGAL/Interval_arithmetic.cpp | 4 +++ .../src/CGAL/test_FPU_rounding_mode.cpp | 31 ++----------------- cppfiles.txt | 2 +- 7 files changed, 26 insertions(+), 32 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index f5ce4359bf2..4b4e2501871 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,6 +9,8 @@ else() cmake_minimum_required(VERSION 2.6.2) endif() +# add_definitions(-DCGAL_HEADER_ONLY) + # option for branch build option( CGAL_BRANCH_BUILD "Create CGAL from branch" ON) diff --git a/GraphicsView/include/CGAL/Qt/GraphicsViewPolylineInput.h b/GraphicsView/include/CGAL/Qt/GraphicsViewPolylineInput.h index 6f56a9a03c3..518f794d75d 100644 --- a/GraphicsView/include/CGAL/Qt/GraphicsViewPolylineInput.h +++ b/GraphicsView/include/CGAL/Qt/GraphicsViewPolylineInput.h @@ -34,6 +34,7 @@ class QGraphicsScene; class QGraphicsSceneMouseEvent; class QGraphicsItem; class QGraphicsPathItem; +class QGraphicsLineItem; class QKeyEvent; class QEvent; class QObject; diff --git a/GraphicsView/include/CGAL/Qt/GraphicsViewPolylineInput_impl.h b/GraphicsView/include/CGAL/Qt/GraphicsViewPolylineInput_impl.h index fa7a88b9c94..5932a1b51a0 100644 --- a/GraphicsView/include/CGAL/Qt/GraphicsViewPolylineInput_impl.h +++ b/GraphicsView/include/CGAL/Qt/GraphicsViewPolylineInput_impl.h @@ -35,8 +35,6 @@ #include #include -#include - namespace CGAL { namespace Qt { diff --git a/Number_types/include/CGAL/FPU.h b/Number_types/include/CGAL/FPU.h index a5d3daeaa6b..d3ad46ba145 100644 --- a/Number_types/include/CGAL/FPU.h +++ b/Number_types/include/CGAL/FPU.h @@ -422,11 +422,25 @@ FPU_get_cw (void) return cw; } +} // namespace CGAL + +#ifdef CGAL_HEADER_ONLY +#include +#endif // CGAL_HEADER_ONLY + +namespace CGAL { + +// User interface (cont): + inline void FPU_set_cw (FPU_CW_t cw) { - CGAL_IA_SETFPCW(cw); +#ifndef CGAL_NDEBUG + const Check_FPU_rounding_mode_is_restored & tmp = get_static_check_fpu_rounding_mode_is_restored(); +#endif + + CGAL_IA_SETFPCW(cw); } inline diff --git a/Number_types/src/CGAL/Interval_arithmetic.cpp b/Number_types/src/CGAL/Interval_arithmetic.cpp index 20b4d44578b..943b2f94cf2 100644 --- a/Number_types/src/CGAL/Interval_arithmetic.cpp +++ b/Number_types/src/CGAL/Interval_arithmetic.cpp @@ -22,6 +22,10 @@ // // Author(s) : Sylvain Pion +#ifndef CGAL_HEADER_ONLY + #include #include #include + +#endif diff --git a/Number_types/src/CGAL/test_FPU_rounding_mode.cpp b/Number_types/src/CGAL/test_FPU_rounding_mode.cpp index 8f347794db3..9821a5cadf5 100644 --- a/Number_types/src/CGAL/test_FPU_rounding_mode.cpp +++ b/Number_types/src/CGAL/test_FPU_rounding_mode.cpp @@ -18,34 +18,9 @@ // // Author(s) : Laurent Rineau -#ifndef CGAL_NDEBUG +#ifndef CGAL_HEADER_ONLY -#include #include -#include +#include -namespace CGAL { - - -struct Check_FPU_rounding_mode_is_restored { - FPU_CW_t mode; - - Check_FPU_rounding_mode_is_restored() - : mode( FPU_get_cw()) {} - - ~Check_FPU_rounding_mode_is_restored() - { - CGAL_assertion_msg( FPU_get_cw() == mode, - "The default FPU rounding mode has not been restored " - " before the exit of the program. " - "That may be a bug in some CGAL kernel code."); - } -}; - -// A global object that emits a warning if the rounding mode at the -// beginning and the end of the program are not the same. -static const Check_FPU_rounding_mode_is_restored check_fpu_rounding_mode_is_restored; - -} // end namespace CGAL - -#endif // #ifnedef CGAL_NDEBUG +#endif diff --git a/cppfiles.txt b/cppfiles.txt index 3192a2e6d93..4ac04e1ceb1 100644 --- a/cppfiles.txt +++ b/cppfiles.txt @@ -9,7 +9,6 @@ Clement: #include "/home/gdamiand/sources/CGAL/Profiling_tools/src/CGAL/Timer.cpp" // static mais doit pouvoir se remplacer en membre #include "/home/gdamiand/sources/CGAL/Profiling_tools/src/CGAL/Real_timer.cpp" // static mais doit pouvoir se remplacer en membre #include "/home/gdamiand/sources/CGAL/Random_numbers/src/CGAL/Random.cpp" // static mais doit pouvoir se remplacer en membre -#include "/home/gdamiand/sources/CGAL/Number_types/src/CGAL/test_FPU_rounding_mode.cpp" // static const #include "/home/gdamiand/sources/CGAL/Modular_arithmetic/src/CGAL/Residue_type.cpp" #include "/home/gdamiand/sources/CGAL/Modular_arithmetic/src/CGAL/primes.cpp" @@ -20,6 +19,7 @@ DONE #include "/home/gdamiand/sources/CGAL/Stream_support/src/CGAL/io.cpp" // va DONE #include "/home/gdamiand/sources/CGAL/Stream_support/src/CGAL/Color.cpp" // constantes globales DONE #include "/home/gdamiand/sources/CGAL/Kernel_23/src/CGAL/kernel.cpp" // constantes globales DONE #include "/home/gdamiand/sources/CGAL/Number_types/src/CGAL/Interval_arithmetic.cpp" // constante globale +DONE #include "/home/gdamiand/sources/CGAL/Number_types/src/CGAL/test_FPU_rounding_mode.cpp" // static const (ok car utilisé que pour debug) DONE #include "/home/gdamiand/sources/CGAL/Geomview/src/CGAL/Geomview_stream.cpp" DONE #include "/home/gdamiand/sources/CGAL/Intersections_2/src/CGAL/Bbox_2_intersections.cpp" From f6faf3fee20e572686bf12f2811a5b857aec9302 Mon Sep 17 00:00:00 2001 From: Guillaume Damiand Date: Fri, 14 Nov 2014 12:11:33 +0100 Subject: [PATCH 13/30] Add missing impl file; protect static variable to use it only in the case CGAL_HEADER_ONLY, in FPU_set_cw, replace one more IO::mode. --- CMakeLists.txt | 2 +- Number_types/include/CGAL/FPU.h | 2 + .../CGAL/test_FPU_rounding_mode_impl.h | 71 +++++++++++++++++++ Triangulation_2/include/CGAL/Weighted_point.h | 2 +- cppfiles.txt | 1 + 5 files changed, 76 insertions(+), 2 deletions(-) create mode 100644 Number_types/include/CGAL/test_FPU_rounding_mode_impl.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 4b4e2501871..6d8ec962c36 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,7 +9,7 @@ else() cmake_minimum_required(VERSION 2.6.2) endif() -# add_definitions(-DCGAL_HEADER_ONLY) +add_definitions(-DCGAL_HEADER_ONLY) # option for branch build diff --git a/Number_types/include/CGAL/FPU.h b/Number_types/include/CGAL/FPU.h index d3ad46ba145..94bedba4765 100644 --- a/Number_types/include/CGAL/FPU.h +++ b/Number_types/include/CGAL/FPU.h @@ -437,7 +437,9 @@ void FPU_set_cw (FPU_CW_t cw) { #ifndef CGAL_NDEBUG +#ifdef CGAL_HEADER_ONLY const Check_FPU_rounding_mode_is_restored & tmp = get_static_check_fpu_rounding_mode_is_restored(); +#endif #endif CGAL_IA_SETFPCW(cw); diff --git a/Number_types/include/CGAL/test_FPU_rounding_mode_impl.h b/Number_types/include/CGAL/test_FPU_rounding_mode_impl.h new file mode 100644 index 00000000000..b407e2a91fa --- /dev/null +++ b/Number_types/include/CGAL/test_FPU_rounding_mode_impl.h @@ -0,0 +1,71 @@ +// Copyright (c) 2008 GeometryFactory (France) +// 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$ +// +// +// Author(s) : Laurent Rineau + +#ifdef CGAL_HEADER_ONLY +#define CGAL_INLINE_FUNCTION inline +#else +#define CGAL_INLINE_FUNCTION +#endif + +#ifndef CGAL_NDEBUG + +#include +#include + +namespace CGAL { + +struct Check_FPU_rounding_mode_is_restored { + FPU_CW_t mode; + + Check_FPU_rounding_mode_is_restored() + : mode( FPU_get_cw()) {} + + ~Check_FPU_rounding_mode_is_restored() + { + std::cout<<"DELETE ~Check_FPU_rounding_mode_is_restored()"< std::ostream & operator<<(std::ostream &os, const Weighted_point &p) { - switch(os.iword(IO::mode)) + switch(get_mode(os)) { case IO::ASCII : return os << p.point() << " " << p.weight(); diff --git a/cppfiles.txt b/cppfiles.txt index 4ac04e1ceb1..2d2d47e2e3d 100644 --- a/cppfiles.txt +++ b/cppfiles.txt @@ -6,6 +6,7 @@ Clement: #include "/home/gdamiand/sources/CGAL/Kinetic_data_structures/src/CGAL/KDS_Log.cpp" #include "/home/gdamiand/sources/CGAL/Kinetic_data_structures/src/CGAL/numeric_solvers_support.cpp" #include "/home/gdamiand/sources/CGAL/Kinetic_data_structures/src/CGAL/Turkowski_numeric_solver.cpp" + #include "/home/gdamiand/sources/CGAL/Profiling_tools/src/CGAL/Timer.cpp" // static mais doit pouvoir se remplacer en membre #include "/home/gdamiand/sources/CGAL/Profiling_tools/src/CGAL/Real_timer.cpp" // static mais doit pouvoir se remplacer en membre #include "/home/gdamiand/sources/CGAL/Random_numbers/src/CGAL/Random.cpp" // static mais doit pouvoir se remplacer en membre From 707aae22b03681d4a0e7f4a8b64f5172bfafa2d4 Mon Sep 17 00:00:00 2001 From: Guillaume Damiand Date: Fri, 14 Nov 2014 12:29:25 +0100 Subject: [PATCH 14/30] Timers for inline header only. --- Profiling_tools/include/CGAL/Real_timer.h | 6 + .../include/CGAL/Real_timer_impl.h | 127 +++++++++++++++ Profiling_tools/include/CGAL/Timer.h | 6 + Profiling_tools/include/CGAL/Timer_impl.h | 154 ++++++++++++++++++ Profiling_tools/src/CGAL/Real_timer.cpp | 83 +--------- Profiling_tools/src/CGAL/Timer.cpp | 109 +------------ cppfiles.txt | 5 +- 7 files changed, 305 insertions(+), 185 deletions(-) create mode 100644 Profiling_tools/include/CGAL/Real_timer_impl.h create mode 100644 Profiling_tools/include/CGAL/Timer_impl.h diff --git a/Profiling_tools/include/CGAL/Real_timer.h b/Profiling_tools/include/CGAL/Real_timer.h index 130f36d0aa3..062d57ef256 100644 --- a/Profiling_tools/include/CGAL/Real_timer.h +++ b/Profiling_tools/include/CGAL/Real_timer.h @@ -50,7 +50,9 @@ private: int interv; bool running; +#ifndef CGAL_HEADER_ONLY static bool m_failed; +#endif // CGAL_HEADER_ONLY double get_real_time() const; // in seconds double compute_precision() const; // in seconds @@ -114,5 +116,9 @@ inline double Real_timer::time() const { } //namespace CGAL +#ifdef CGAL_HEADER_ONLY +#include +#endif // CGAL_HEADER_ONLY + #endif // CGAL_REAL_TIMER_H // // EOF // diff --git a/Profiling_tools/include/CGAL/Real_timer_impl.h b/Profiling_tools/include/CGAL/Real_timer_impl.h new file mode 100644 index 00000000000..070556dbb74 --- /dev/null +++ b/Profiling_tools/include/CGAL/Real_timer_impl.h @@ -0,0 +1,127 @@ +// Copyright (c) 1997 +// 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$ +// +// +// Author(s) : Lutz Kettner +// Matthias Baesken + +#ifdef CGAL_HEADER_ONLY +#define CGAL_INLINE_FUNCTION inline +#else +#define CGAL_INLINE_FUNCTION +#endif + +#if defined (_MSC_VER) +# include +# include + +#elif defined (__MINGW32__) +# include +# include + +#else +// If none of the above PC compilers, use POSIX fct. gettimeofday() +# include +#endif + +#ifdef CGAL_HEADER_ONLY +namespace { +inline bool& get_static_realtimer_m_failed() +{ + static bool m_failed = false; + return m_failed; +} +} // namespace +#else // CGAL_HEADER_ONLY +namespace { +inline bool& get_static_realtimer_m_failed() +{ return Real_timer::m_failed; } +} // namespace +#endif // CGAL_HEADER_ONLY + +namespace CGAL { + +// Member functions for Real_timer +// ===================================== + +CGAL_INLINE_FUNCTION +double Real_timer::get_real_time() const { + // Depends on the operating system. + // Returns a (weakly ;-) monotone increasing time in seconds (with + // possible wrap-around in case of overflow, see max()), or 0.0 + // if the system call for the time failed. If the system call + // failed the static flag 'm_failed' is set and can be used + // by the caller. +#if defined(_MSC_VER) + struct _timeb t; + _ftime(&t); + return double(t.time) + double(t.millitm) / 1000.0; +#elif defined (__MINGW32__) + struct timeb t; + ftime(&t); + return double(t.time) + double(t.millitm) / 1000.0; +#else // ! _MSC_VER && ! __MINGW32__// + struct timeval t; + int ret = gettimeofday( &t, NULL); + CGAL_warning_msg( ret == 0, "Call to gettimeofday() in class " + "CGAL::Real_timer failed - timings will be 0."); + if ( ret == 0) { + return double(t.tv_sec) + double(t.tv_usec) / 1000000; + } + get_static_realtimer_m_failed() = true; + return 0.0; +#endif // ! _MSC_VER && ! __MINGW32__// +} + +CGAL_INLINE_FUNCTION +double Real_timer::compute_precision() const { + // Computes timer precision in seconds dynamically. Note that + // the timer system call is probably non-trivial and will show + // up in this time here (probably for one call). But that is just + // fine that the call to the timer itself if reported as noise + // in the precision. + double min_res = DBL_MAX; + for ( int i = 0; i < 5; ++i) { + double current = get_real_time(); + if ( get_static_realtimer_m_failed() ) + return -1.0; + double next = get_real_time(); + while ( current >= next) { // wait until timer increases + next = get_real_time(); + if ( get_static_realtimer_m_failed() ) + return -1.0; + } + // Get the minimum timing difference of all runs. + if ( min_res > next - current) + min_res = next - current; + } + return min_res; +} + +CGAL_INLINE_FUNCTION +double Real_timer::precision() const { + // computes precision upon first call + // returns -1.0 if timer system call fails. + static double prec = compute_precision(); + return prec; +} + +} //namespace CGAL diff --git a/Profiling_tools/include/CGAL/Timer.h b/Profiling_tools/include/CGAL/Timer.h index 4e63563c202..030ec7a62b7 100644 --- a/Profiling_tools/include/CGAL/Timer.h +++ b/Profiling_tools/include/CGAL/Timer.h @@ -48,7 +48,9 @@ private: int interv; bool running; +#ifndef CGAL_HEADER_ONLY static bool m_failed; +#endif // CGAL_HEADER_ONLY double user_process_time() const; // in seconds double compute_precision() const; // in seconds @@ -112,5 +114,9 @@ inline double Timer::time() const { } //namespace CGAL +#ifdef CGAL_HEADER_ONLY +#include +#endif // CGAL_HEADER_ONLY + #endif // CGAL_TIMER_H // // EOF // diff --git a/Profiling_tools/include/CGAL/Timer_impl.h b/Profiling_tools/include/CGAL/Timer_impl.h new file mode 100644 index 00000000000..e85064416a1 --- /dev/null +++ b/Profiling_tools/include/CGAL/Timer_impl.h @@ -0,0 +1,154 @@ +// Copyright (c) 1997 +// 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$ +// +// +// Author(s) : Lutz Kettner +// Matthias Baesken + +#ifdef CGAL_HEADER_ONLY +#define CGAL_INLINE_FUNCTION inline +#else +#define CGAL_INLINE_FUNCTION +#endif + +// Determine if the POSIX function getrusage is available, otherwise +// use the previous solution based on std::clock(). +// First, detect POSIX. We cannot reliably use "unistd.h", +// but limits.h is part of the C standard. +#include +#ifdef _POSIX_ARG_MAX // now that should be POSIX +#include +#ifdef _POSIX_VERSION +#ifdef _XOPEN_UNIX // XSI: X/Open System Interfaces Extension +#define CGAL__GETRUSAGE 1 +#endif +#endif +#endif + + +#ifdef CGAL__GETRUSAGE +// types, function prototype and constants for the POSIX function +// int getrusage (int who, struct rusage *usage); +#include +// For the numerical limits +#else // CGAL__GETRUSAGE // +// used for clock() +#include +#endif // CGAL__GETRUSAGE // + +// For the numerical limits +#include + +#ifdef CGAL_HEADER_ONLY +namespace { +inline bool& get_static_timer_m_failed() +{ + static bool m_failed = false; + return m_failed; +} +} // namespace +#else // CGAL_HEADER_ONLY +namespace { +inline bool& get_static_timer_m_failed() +{ return Timer::m_failed; } +} // namespace +#endif // CGAL_HEADER_ONLY + +namespace CGAL { + +// Member functions for Timer +// ===================================== + +CGAL_INLINE_FUNCTION +double Timer::user_process_time() const { + // Depends on the operating system. + // Returns a (weakly ;-) monotone increasing time in seconds (with + // possible wrap-around in case of overflow, see max()), or 0.0 + // if the system call for the time failed. If the system call + // failed the static flag 'm_failed' is set and can be used + // by the caller. +#ifdef CGAL__GETRUSAGE + struct rusage usage; + int ret = getrusage( RUSAGE_SELF, &usage); + CGAL_warning_msg( ret == 0, "Call to getrusage() in class CGAL::Timer " + "failed - timings will be 0."); + if ( ret == 0) { + return double( usage.ru_utime.tv_sec) // seconds + + double( usage.ru_utime.tv_usec) / 1000000.0; // microseconds + } +#else // CGAL__GETRUSAGE // + std::clock_t clk = std::clock(); + CGAL_warning_msg( clk != (std::clock_t)-1, + "Call to clock() in class CGAL::Timer failed - timings will be 0."); + if ( clk != (std::clock_t)-1) { + return double(clk) / CLOCKS_PER_SEC; + } +#endif // CGAL__GETRUSAGE // + get_static_timer_m_failed() = true; + return 0.0; +} + +CGAL_INLINE_FUNCTION +double Timer::compute_precision() const { + // Computes timer precision in seconds dynamically. Note that + // the timer system call is probably non-trivial and will show + // up in this time here (probably for one call). But that is just + // fine that the call to the timer itself if reported as noise + // in the precision. + double min_res = DBL_MAX; + for ( int i = 0; i < 5; ++i) { + double current = user_process_time(); + if ( get_static_timer_m_failed() ) + return -1.0; + double next = user_process_time(); + while ( current >= next) { // wait until timer increases + next = user_process_time(); + if ( get_static_timer_m_failed() ) + return -1.0; + } + // Get the minimum timing difference of all runs. + if ( min_res > next - current) + min_res = next - current; + } + return min_res; +} + +CGAL_INLINE_FUNCTION +double Timer::precision() const { + // computes precision upon first call + // returns -1.0 if timer system call fails. + static double prec = compute_precision(); + return prec; +} + +CGAL_INLINE_FUNCTION +double Timer::max BOOST_PREVENT_MACRO_SUBSTITUTION () const { + // Depends on the operating system. +#ifdef CGAL__GETRUSAGE + return DBL_MAX; +#else // CGAL__GETRUSAGE // + return 2146.0; +#endif // CGAL__GETRUSAGE // +} + +} //namespace CGAL + +// EOF // diff --git a/Profiling_tools/src/CGAL/Real_timer.cpp b/Profiling_tools/src/CGAL/Real_timer.cpp index e0a258b42bc..2a13b9be599 100644 --- a/Profiling_tools/src/CGAL/Real_timer.cpp +++ b/Profiling_tools/src/CGAL/Real_timer.cpp @@ -23,88 +23,15 @@ // Author(s) : Lutz Kettner // Matthias Baesken +#ifndef CGAL_HEADER_ONLY + #include - -#if defined (_MSC_VER) -# include -# include - -#elif defined (__MINGW32__) -# include -# include - -#else -// If none of the above PC compilers, use POSIX fct. gettimeofday() -# include -#endif +#include namespace CGAL { -// Static member variable for Real_timer -// ===================================== - bool Real_timer::m_failed = false; -// Member functions for Real_timer -// ===================================== - -double Real_timer::get_real_time() const { - // Depends on the operating system. - // Returns a (weakly ;-) monotone increasing time in seconds (with - // possible wrap-around in case of overflow, see max()), or 0.0 - // if the system call for the time failed. If the system call - // failed the static flag 'm_failed' is set and can be used - // by the caller. -#if defined(_MSC_VER) - struct _timeb t; - _ftime(&t); - return double(t.time) + double(t.millitm) / 1000.0; -#elif defined (__MINGW32__) - struct timeb t; - ftime(&t); - return double(t.time) + double(t.millitm) / 1000.0; -#else // ! _MSC_VER && ! __MINGW32__// - struct timeval t; - int ret = gettimeofday( &t, NULL); - CGAL_warning_msg( ret == 0, "Call to gettimeofday() in class " - "CGAL::Real_timer failed - timings will be 0."); - if ( ret == 0) { - return double(t.tv_sec) + double(t.tv_usec) / 1000000; - } - m_failed = true; - return 0.0; -#endif // ! _MSC_VER && ! __MINGW32__// -} - -double Real_timer::compute_precision() const { - // Computes timer precision in seconds dynamically. Note that - // the timer system call is probably non-trivial and will show - // up in this time here (probably for one call). But that is just - // fine that the call to the timer itself if reported as noise - // in the precision. - double min_res = DBL_MAX; - for ( int i = 0; i < 5; ++i) { - double current = get_real_time(); - if ( m_failed) - return -1.0; - double next = get_real_time(); - while ( current >= next) { // wait until timer increases - next = get_real_time(); - if ( m_failed) - return -1.0; - } - // Get the minimum timing difference of all runs. - if ( min_res > next - current) - min_res = next - current; - } - return min_res; -} - -double Real_timer::precision() const { - // computes precision upon first call - // returns -1.0 if timer system call fails. - static double prec = compute_precision(); - return prec; -} - } //namespace CGAL + +#endif // CGAL_HEADER_ONLY diff --git a/Profiling_tools/src/CGAL/Timer.cpp b/Profiling_tools/src/CGAL/Timer.cpp index 290d4f13cdf..3e45e00229a 100644 --- a/Profiling_tools/src/CGAL/Timer.cpp +++ b/Profiling_tools/src/CGAL/Timer.cpp @@ -23,116 +23,15 @@ // Author(s) : Lutz Kettner // Matthias Baesken +#ifndef CGAL_HEADER_ONLY + #include - -// Determine if the POSIX function getrusage is available, otherwise -// use the previous solution based on std::clock(). -// First, detect POSIX. We cannot reliably use "unistd.h", -// but limits.h is part of the C standard. -#include -#ifdef _POSIX_ARG_MAX // now that should be POSIX -#include -#ifdef _POSIX_VERSION -#ifdef _XOPEN_UNIX // XSI: X/Open System Interfaces Extension -#define CGAL__GETRUSAGE 1 -#endif -#endif -#endif - - -#ifdef CGAL__GETRUSAGE -// types, function prototype and constants for the POSIX function -// int getrusage (int who, struct rusage *usage); -#include -// For the numerical limits -#else // CGAL__GETRUSAGE // -// used for clock() -#include -#endif // CGAL__GETRUSAGE // - -// For the numerical limits -#include - +#include namespace CGAL { - -// Static member variable for Timer -// ===================================== - bool Timer::m_failed = false; -// Member functions for Timer -// ===================================== - -double Timer::user_process_time() const { - // Depends on the operating system. - // Returns a (weakly ;-) monotone increasing time in seconds (with - // possible wrap-around in case of overflow, see max()), or 0.0 - // if the system call for the time failed. If the system call - // failed the static flag 'm_failed' is set and can be used - // by the caller. -#ifdef CGAL__GETRUSAGE - struct rusage usage; - int ret = getrusage( RUSAGE_SELF, &usage); - CGAL_warning_msg( ret == 0, "Call to getrusage() in class CGAL::Timer " - "failed - timings will be 0."); - if ( ret == 0) { - return double( usage.ru_utime.tv_sec) // seconds - + double( usage.ru_utime.tv_usec) / 1000000.0; // microseconds - } -#else // CGAL__GETRUSAGE // - std::clock_t clk = std::clock(); - CGAL_warning_msg( clk != (std::clock_t)-1, - "Call to clock() in class CGAL::Timer failed - timings will be 0."); - if ( clk != (std::clock_t)-1) { - return double(clk) / CLOCKS_PER_SEC; - } -#endif // CGAL__GETRUSAGE // - m_failed = true; - return 0.0; -} - -double Timer::compute_precision() const { - // Computes timer precision in seconds dynamically. Note that - // the timer system call is probably non-trivial and will show - // up in this time here (probably for one call). But that is just - // fine that the call to the timer itself if reported as noise - // in the precision. - double min_res = DBL_MAX; - for ( int i = 0; i < 5; ++i) { - double current = user_process_time(); - if ( m_failed) - return -1.0; - double next = user_process_time(); - while ( current >= next) { // wait until timer increases - next = user_process_time(); - if ( m_failed) - return -1.0; - } - // Get the minimum timing difference of all runs. - if ( min_res > next - current) - min_res = next - current; - } - return min_res; -} - -double Timer::precision() const { - // computes precision upon first call - // returns -1.0 if timer system call fails. - static double prec = compute_precision(); - return prec; -} - -double Timer::max BOOST_PREVENT_MACRO_SUBSTITUTION () const { - // Depends on the operating system. -#ifdef CGAL__GETRUSAGE - return DBL_MAX; -#else // CGAL__GETRUSAGE // - return 2146.0; -#endif // CGAL__GETRUSAGE // -} - } //namespace CGAL -// EOF // +#endif // CGAL_HEADER_ONLY diff --git a/cppfiles.txt b/cppfiles.txt index 2d2d47e2e3d..1ead35fbe1f 100644 --- a/cppfiles.txt +++ b/cppfiles.txt @@ -7,9 +7,8 @@ Clement: #include "/home/gdamiand/sources/CGAL/Kinetic_data_structures/src/CGAL/numeric_solvers_support.cpp" #include "/home/gdamiand/sources/CGAL/Kinetic_data_structures/src/CGAL/Turkowski_numeric_solver.cpp" -#include "/home/gdamiand/sources/CGAL/Profiling_tools/src/CGAL/Timer.cpp" // static mais doit pouvoir se remplacer en membre -#include "/home/gdamiand/sources/CGAL/Profiling_tools/src/CGAL/Real_timer.cpp" // static mais doit pouvoir se remplacer en membre #include "/home/gdamiand/sources/CGAL/Random_numbers/src/CGAL/Random.cpp" // static mais doit pouvoir se remplacer en membre + #include "/home/gdamiand/sources/CGAL/Modular_arithmetic/src/CGAL/Residue_type.cpp" #include "/home/gdamiand/sources/CGAL/Modular_arithmetic/src/CGAL/primes.cpp" @@ -21,6 +20,8 @@ DONE #include "/home/gdamiand/sources/CGAL/Stream_support/src/CGAL/Color.cpp" // DONE #include "/home/gdamiand/sources/CGAL/Kernel_23/src/CGAL/kernel.cpp" // constantes globales DONE #include "/home/gdamiand/sources/CGAL/Number_types/src/CGAL/Interval_arithmetic.cpp" // constante globale DONE #include "/home/gdamiand/sources/CGAL/Number_types/src/CGAL/test_FPU_rounding_mode.cpp" // static const (ok car utilisé que pour debug) +DONE #include "/home/gdamiand/sources/CGAL/Profiling_tools/src/CGAL/Timer.cpp" // variable statique de classe +DONE #include "/home/gdamiand/sources/CGAL/Profiling_tools/src/CGAL/Real_timer.cpp" // variable statique de classe DONE #include "/home/gdamiand/sources/CGAL/Geomview/src/CGAL/Geomview_stream.cpp" DONE #include "/home/gdamiand/sources/CGAL/Intersections_2/src/CGAL/Bbox_2_intersections.cpp" From ebc4300334b3d22c71e1cec7c09bccea56a659ba Mon Sep 17 00:00:00 2001 From: Guillaume Damiand Date: Fri, 14 Nov 2014 14:20:26 +0100 Subject: [PATCH 15/30] Header only for random.cpp. For the header only version, the global variable default_random no more exist => we need to replace all occurences of default_random by a call to the global function get_default_random(). As usual, no modification for the non header only version. --- Bounding_volumes/include/CGAL/Min_circle_2.h | 4 +- Bounding_volumes/include/CGAL/Min_ellipse_2.h | 4 +- .../rectangular_p_center_2_random1_test.cpp | 5 +- .../rectangular_p_center_2_random2_test.cpp | 5 +- .../Bounding_volumes/test_Min_annulus_d_2.cpp | 4 +- .../Bounding_volumes/test_Min_annulus_d_3.cpp | 6 +- .../Bounding_volumes/test_Min_annulus_d_d.cpp | 2 +- .../test_trilinear_interpolation.cpp | 2 +- .../Convex_hull_d/chull_dd-geomview-demo.cpp | 2 +- .../demo/Convex_hull_d/chull_dd-runtime.cpp | 2 +- .../Convex_hull_d/delaunay_dd-runtime.cpp | 2 +- .../Generator/random_degenerate_point_set.cpp | 2 +- Generator/include/CGAL/generators.h | 4 +- Generator/include/CGAL/point_generators_2.h | 18 +-- Generator/include/CGAL/point_generators_3.h | 6 +- Generator/include/CGAL/point_generators_d.h | 6 +- Generator/include/CGAL/random_selection.h | 2 +- Generator/test/Generator/test_generators.cpp | 2 +- Kernel_23/test/Kernel_23/Kernel_checker.cpp | 2 +- .../test/Kernel_d/Linear_algebra-test.cpp | 120 +++++++++--------- Mesh_2/test/Mesh_2/test_double_map.cpp | 2 +- Mesh_2/test/Mesh_2/test_filtred_container.cpp | 2 +- Number_types/test/Number_types/MP_Float.cpp | 16 +-- .../include/CGAL/Polygon_2/Polygon_2_impl.h | 2 +- ...hedron_demo_remeshing_plugin_cgal_code.cpp | 2 +- .../test_Polytope_distance_d_2.cpp | 16 +-- .../test_Polytope_distance_d_3.cpp | 20 +-- .../test_Polytope_distance_d_d.cpp | 4 +- .../CGAL/QP_solver/QP_partial_exact_pricing.h | 2 +- .../QP_solver/QP_partial_filtered_pricing.h | 2 +- Random_numbers/include/CGAL/Random.h | 8 +- Random_numbers/include/CGAL/Random_impl.h | 105 +++++++++++++++ Random_numbers/src/CGAL/Random.cpp | 62 +-------- .../test/Random_numbers/test_Random.cpp | 52 ++++---- .../STL_Extension/test_Compact_container.cpp | 2 +- .../test_Concurrent_compact_container.cpp | 2 +- .../Triangulation_benchmark_3.cpp | 2 +- .../Triangulation_3/fast_location_3.cpp | 6 +- .../Triangulation_3/test_static_filters.cpp | 2 +- cppfiles.txt | 3 +- 40 files changed, 283 insertions(+), 229 deletions(-) create mode 100644 Random_numbers/include/CGAL/Random_impl.h diff --git a/Bounding_volumes/include/CGAL/Min_circle_2.h b/Bounding_volumes/include/CGAL/Min_circle_2.h index 856317940b8..d59566ac0a5 100644 --- a/Bounding_volumes/include/CGAL/Min_circle_2.h +++ b/Bounding_volumes/include/CGAL/Min_circle_2.h @@ -58,7 +58,7 @@ class Min_circle_2 { Min_circle_2( InputIterator first, InputIterator last, bool randomize = false, - Random& random = default_random, + Random& random = get_default_random(), const Traits& traits = Traits()); Min_circle_2( const Traits& traits = Traits()); @@ -302,7 +302,7 @@ class Min_circle_2 { = false #endif , - Random& random = default_random, + Random& random = get_default_random(), const Traits& traits = Traits()) : tco( traits) { diff --git a/Bounding_volumes/include/CGAL/Min_ellipse_2.h b/Bounding_volumes/include/CGAL/Min_ellipse_2.h index 274ab47e8c0..31e766e02e1 100644 --- a/Bounding_volumes/include/CGAL/Min_ellipse_2.h +++ b/Bounding_volumes/include/CGAL/Min_ellipse_2.h @@ -57,7 +57,7 @@ class Min_ellipse_2 { Min_ellipse_2( InputIterator first, InputIterator last, bool randomize = false, - Random& random = default_random, + Random& random = get_default_random(), const Traits& traits = Traits()); Min_ellipse_2( const Traits& traits = Traits()); @@ -328,7 +328,7 @@ class Min_ellipse_2 { = false #endif , - Random& random = default_random, + Random& random = get_default_random(), const Traits& traits = Traits()) : tco( traits) { diff --git a/Bounding_volumes/test/Bounding_volumes/rectangular_p_center_2_random1_test.cpp b/Bounding_volumes/test/Bounding_volumes/rectangular_p_center_2_random1_test.cpp index dfef6980a5e..60122b18196 100644 --- a/Bounding_volumes/test/Bounding_volumes/rectangular_p_center_2_random1_test.cpp +++ b/Bounding_volumes/test/Bounding_volumes/rectangular_p_center_2_random1_test.cpp @@ -45,7 +45,6 @@ using CGAL::Creator_uniform_2; using CGAL::Random_points_in_square_2; using CGAL::Random; using CGAL::Timer; -using CGAL::default_random; using CGAL::rectangular_p_center_2; #ifndef CGAL_PCENTER_NO_OUTPUT using std::ostream; @@ -108,7 +107,7 @@ public: Random_p_clusters_2(int n_, double c_size_, double r = 1, - Random& rnd = default_random) + Random& rnd = CGAL::get_default_random()) : Base(r - c_size_, rnd), n(n_), c_size(c_size_), @@ -163,7 +162,7 @@ main(int argc, char* argv[]) #endif // CGAL_PCENTER_NO_OUTPUT // generate random seed - random_seed = default_random.get_int(0, (1 << 30)); + random_seed = CGAL::get_default_random().get_int(0, (1 << 30)); } else random_seed = atoi(argv[2]); diff --git a/Bounding_volumes/test/Bounding_volumes/rectangular_p_center_2_random2_test.cpp b/Bounding_volumes/test/Bounding_volumes/rectangular_p_center_2_random2_test.cpp index 3b9bedddae7..22b280152d1 100644 --- a/Bounding_volumes/test/Bounding_volumes/rectangular_p_center_2_random2_test.cpp +++ b/Bounding_volumes/test/Bounding_volumes/rectangular_p_center_2_random2_test.cpp @@ -50,7 +50,6 @@ using CGAL::Creator_uniform_2; using CGAL::Random_points_in_square_2; using CGAL::Random; using CGAL::Timer; -using CGAL::default_random; using CGAL::rectangular_p_center_2; #ifndef CGAL_PCENTER_NO_OUTPUT using std::ostream; @@ -110,7 +109,7 @@ public: Random_p_clusters_2(int n_, double c_size_, double r = 1, - Random& rnd = default_random) + Random& rnd = CGAL::get_default_random()) : Base(r - c_size_, rnd), n(n_), c_size(c_size_), @@ -165,7 +164,7 @@ main(int argc, char* argv[]) #endif // CGAL_PCENTER_NO_OUTPUT // generate random seed - random_seed = default_random.get_int(0, (1 << 30)); + random_seed = CGAL::get_default_random().get_int(0, (1 << 30)); } else random_seed = std::atoi(argv[2]); diff --git a/Bounding_volumes/test/Bounding_volumes/test_Min_annulus_d_2.cpp b/Bounding_volumes/test/Bounding_volumes/test_Min_annulus_d_2.cpp index 7515da92efa..6032734721e 100644 --- a/Bounding_volumes/test/Bounding_volumes/test_Min_annulus_d_2.cpp +++ b/Bounding_volumes/test/Bounding_volumes/test_Min_annulus_d_2.cpp @@ -73,8 +73,8 @@ void process () for ( int i = 0; i < 100; ++i) { points.push_back (typename K::Point_2 - (CGAL::default_random( 0x100000), - CGAL::default_random( 0x100000), + (CGAL::get_default_random()( 0x100000), + CGAL::get_default_random()( 0x100000), hom)); } diff --git a/Bounding_volumes/test/Bounding_volumes/test_Min_annulus_d_3.cpp b/Bounding_volumes/test/Bounding_volumes/test_Min_annulus_d_3.cpp index 3f6fa8b8f85..9a333abc68f 100644 --- a/Bounding_volumes/test/Bounding_volumes/test_Min_annulus_d_3.cpp +++ b/Bounding_volumes/test/Bounding_volumes/test_Min_annulus_d_3.cpp @@ -73,9 +73,9 @@ void process () for ( int i = 0; i < 100; ++i) { points.push_back (typename K::Point_3 - (CGAL::default_random( 0x100000), - CGAL::default_random( 0x100000), - CGAL::default_random( 0x100000), + (CGAL::get_default_random()( 0x100000), + CGAL::get_default_random()( 0x100000), + CGAL::get_default_random()( 0x100000), hom)); } diff --git a/Bounding_volumes/test/Bounding_volumes/test_Min_annulus_d_d.cpp b/Bounding_volumes/test/Bounding_volumes/test_Min_annulus_d_d.cpp index e4db5fffeab..2eeb684def3 100644 --- a/Bounding_volumes/test/Bounding_volumes/test_Min_annulus_d_d.cpp +++ b/Bounding_volumes/test/Bounding_volumes/test_Min_annulus_d_d.cpp @@ -75,7 +75,7 @@ void process () double hom = 2.0; for ( i = 0; i < 100; ++i) { for (j=0; j random_point_in_range(int d,int l,int h, { std::vector V(d+1); V[d]=1; for(int i = 0; i(d,V.begin(),V.end()); } diff --git a/Convex_hull_d/demo/Convex_hull_d/chull_dd-runtime.cpp b/Convex_hull_d/demo/Convex_hull_d/chull_dd-runtime.cpp index daa073d92e7..e9b947124b6 100644 --- a/Convex_hull_d/demo/Convex_hull_d/chull_dd-runtime.cpp +++ b/Convex_hull_d/demo/Convex_hull_d/chull_dd-runtime.cpp @@ -59,7 +59,7 @@ CGAL::Timer timer; void random_d_tuple_in_range(p_int V, int d, int l, int h) { for(int i = 0; i random_point_in_range(int d,int l,int h, { std::vector V(d+1); V[d]=1; for(int i = 0; i(d,V.begin(),V.end()); } diff --git a/Generator/examples/Generator/random_degenerate_point_set.cpp b/Generator/examples/Generator/random_degenerate_point_set.cpp index b9e32d1f952..d1bc4325cf9 100644 --- a/Generator/examples/Generator/random_degenerate_point_set.cpp +++ b/Generator/examples/Generator/random_degenerate_point_set.cpp @@ -40,7 +40,7 @@ int main() { // Use a random permutation to hide the creation history // of the point set. - std::random_shuffle( points.begin(), points.end(), default_random); + std::random_shuffle( points.begin(), points.end(), get_default_random()); // Check range of values. for ( Vector::iterator i = points.begin(); i != points.end(); i++){ diff --git a/Generator/include/CGAL/generators.h b/Generator/include/CGAL/generators.h index 3e38f593bc8..b30c40433d1 100644 --- a/Generator/include/CGAL/generators.h +++ b/Generator/include/CGAL/generators.h @@ -68,7 +68,7 @@ protected: public: typedef Random_generator_base This; - Random_generator_base() : _rnd( default_random) {} + Random_generator_base() : _rnd( get_default_random()) {} Random_generator_base( double range, Random& rnd) : Generator_base( range), _rnd( rnd) {} Random_generator_base( const T& item, double range, Random& rnd) @@ -83,7 +83,7 @@ class Random_double_in_interval : public Random_generator_base { public: typedef Random_double_in_interval This; - Random_double_in_interval(double a = 1, Random& rnd = default_random) + Random_double_in_interval(double a = 1, Random& rnd = get_default_random()) // g is an input iterator creating points of type `P' uniformly // distributed in the half-open square with side length a, // centered around the origin, i.e. \forall p = `*g': -\frac{a}{2} diff --git a/Generator/include/CGAL/point_generators_2.h b/Generator/include/CGAL/point_generators_2.h index cce5d767385..098c563b574 100644 --- a/Generator/include/CGAL/point_generators_2.h +++ b/Generator/include/CGAL/point_generators_2.h @@ -36,7 +36,7 @@ class Random_points_in_disc_2 : public Random_generator_base

{ void generate_point(); public: typedef Random_points_in_disc_2 This; - Random_points_in_disc_2( double r = 1, Random& rnd = default_random) + Random_points_in_disc_2( double r = 1, Random& rnd = get_default_random()) // g is an input iterator creating points of type `P' uniformly // distributed in the open disc with radius r, i.e. |`*g'| < r . // Two random numbers are needed from `rnd' for each point. @@ -71,7 +71,7 @@ class Random_points_on_circle_2 : public Random_generator_base

{ void generate_point(); public: typedef Random_points_on_circle_2 This; - Random_points_on_circle_2( double r = 1, Random& rnd = default_random) + Random_points_on_circle_2( double r = 1, Random& rnd = get_default_random()) // g is an input iterator creating points of type `P' uniformly // distributed on the circle with radius r, i.e. |`*g'| == r . A // single random number is needed from `rnd' for each point. @@ -105,7 +105,7 @@ class Random_points_in_square_2 : public Random_generator_base

{ void generate_point(); public: typedef Random_points_in_square_2 This; - Random_points_in_square_2( double a = 1, Random& rnd = default_random) + Random_points_in_square_2( double a = 1, Random& rnd = get_default_random()) // g is an input iterator creating points of type `P' uniformly // distributed in the half-open square with side length a, // centered around the origin, i.e. \forall p = `*g': -\frac{a}{2} @@ -141,7 +141,7 @@ class Random_points_on_square_2 : public Random_generator_base

{ void generate_point(); public: typedef Random_points_on_square_2 This; - Random_points_on_square_2( double a = 1, Random& rnd = default_random) + Random_points_on_square_2( double a = 1, Random& rnd = get_default_random()) // g is an input iterator creating points of type `P' uniformly // distributed on the boundary of the square with side length a, // centered around the origin, i.e. \forall p = `*g': one @@ -194,7 +194,7 @@ class Random_points_in_iso_rectangle_2 : public Random_generator_base

{ void generate_point(); public: typedef Random_points_in_iso_rectangle_2 This; - Random_points_in_iso_rectangle_2( const P&p, const P& q, Random& rnd = default_random) + Random_points_in_iso_rectangle_2( const P&p, const P& q, Random& rnd = get_default_random()) : Random_generator_base

( 1.0 , rnd) { left = (std::min)(to_double(p.x()), to_double(q.x())); @@ -238,7 +238,7 @@ public: typedef Random_points_on_segment_2 This; Random_points_on_segment_2( const P& p = P( -1, 0), const P& q = P( 1, 0), - Random& rnd = default_random) + Random& rnd = get_default_random()) // g is an input iterator creating points of type `P' uniformly // distributed on the segment from p to q except q, i.e. `*g' == // \lambda p + (1-\lambda)\, q where 0 <= \lambda < 1 . A single @@ -423,7 +423,7 @@ void perturb_points_2( ForwardIterator first, double xeps, double yeps) { - perturb_points_2( first, last, xeps, yeps, default_random); + perturb_points_2( first, last, xeps, yeps, get_default_random()); } template @@ -431,7 +431,7 @@ void perturb_points_2( ForwardIterator first, ForwardIterator last, double xeps) { - perturb_points_2( first, last, xeps, xeps, default_random); + perturb_points_2( first, last, xeps, xeps, get_default_random()); } template OutputIterator random_collinear_points_2( @@ -489,7 +489,7 @@ OutputIterator random_collinear_points_2( OutputIterator first2) { return random_collinear_points_2( first, last, n, first2, - default_random); + get_default_random()); } diff --git a/Generator/include/CGAL/point_generators_3.h b/Generator/include/CGAL/point_generators_3.h index 7a262e50a86..e4806182e60 100644 --- a/Generator/include/CGAL/point_generators_3.h +++ b/Generator/include/CGAL/point_generators_3.h @@ -36,7 +36,7 @@ class Random_points_in_sphere_3 : public Random_generator_base

{ void generate_point(); public: typedef Random_points_in_sphere_3 This; - Random_points_in_sphere_3( double r = 1, Random& rnd = default_random) + Random_points_in_sphere_3( double r = 1, Random& rnd = get_default_random()) // g is an input iterator creating points of type `P' uniformly // distributed in the open sphere with radius r, i.e. |`*g'| < r . // Three random numbers are needed from `rnd' for each point @@ -75,7 +75,7 @@ class Random_points_on_sphere_3 : public Random_generator_base

{ void generate_point(); public: typedef Random_points_on_sphere_3 This; - Random_points_on_sphere_3( double r = 1, Random& rnd = default_random) + Random_points_on_sphere_3( double r = 1, Random& rnd = get_default_random()) // g is an input iterator creating points of type `P' uniformly // distributed on the sphere with radius r, i.e. |`*g'| == r . A // two random numbers are needed from `rnd' for each point. @@ -113,7 +113,7 @@ class Random_points_in_cube_3 : public Random_generator_base

{ void generate_point(); public: typedef Random_points_in_cube_3 This; - Random_points_in_cube_3( double a = 1, Random& rnd = default_random) + Random_points_in_cube_3( double a = 1, Random& rnd = get_default_random()) : Random_generator_base

( a, rnd) { generate_point(); } This& operator++() { generate_point(); diff --git a/Generator/include/CGAL/point_generators_d.h b/Generator/include/CGAL/point_generators_d.h index f946ea126d0..59d11fd6bc3 100644 --- a/Generator/include/CGAL/point_generators_d.h +++ b/Generator/include/CGAL/point_generators_d.h @@ -35,7 +35,7 @@ class Random_points_in_ball_d : public Random_generator_base

{ public: typedef Random_points_in_ball_d

This; Random_points_in_ball_d( int dim, double a = 1, - Random& rnd = default_random) + Random& rnd = get_default_random()) // g is an input iterator creating points of type `P' uniformly // distributed in the open sphere with radius r, i.e. |`*g'| < r . : Random_generator_base

( a, rnd), dimension(dim) { generate_point(); } @@ -84,7 +84,7 @@ class Random_points_on_sphere_d : public Random_generator_base

{ public: typedef Random_points_on_sphere_d

This; Random_points_on_sphere_d( int dim, double a = 1, - Random& rnd = default_random) + Random& rnd = get_default_random()) // g is an input iterator creating points of type `P' uniformly // distributed on the sphere with radius r, i.e. |`*g'| == r . : Random_generator_base

( a, rnd), dimension(dim) { generate_point(); } @@ -129,7 +129,7 @@ class Random_points_in_cube_d : public Random_generator_base

{ public: typedef Random_points_in_cube_d

This; Random_points_in_cube_d( int dim, double a = 1, - Random& rnd = default_random) + Random& rnd = get_default_random()) : Random_generator_base

( a, rnd), dimension(dim) { generate_point(); } This& operator++() { generate_point(); diff --git a/Generator/include/CGAL/random_selection.h b/Generator/include/CGAL/random_selection.h index 0a4283b1279..b671b19e910 100644 --- a/Generator/include/CGAL/random_selection.h +++ b/Generator/include/CGAL/random_selection.h @@ -57,7 +57,7 @@ OutputIterator random_selection( RandomAccessIterator first, Size n, OutputIterator result) { - return random_selection( first, last, n, result, default_random); + return random_selection( first, last, n, result, get_default_random()); } } //namespace CGAL diff --git a/Generator/test/Generator/test_generators.cpp b/Generator/test/Generator/test_generators.cpp index addc06c7eea..9c4788ee9e3 100644 --- a/Generator/test/Generator/test_generators.cpp +++ b/Generator/test/Generator/test_generators.cpp @@ -97,7 +97,7 @@ void test_point_generators_2() { perturb_points_2( i1, i2, 10.0); // Create a random permutation. - std::random_shuffle( points.begin(), points.end(), default_random); + std::random_shuffle( points.begin(), points.end(), get_default_random()); assert( points.size() == 1000); for ( std::vector::iterator i = points.begin(); diff --git a/Kernel_23/test/Kernel_23/Kernel_checker.cpp b/Kernel_23/test/Kernel_23/Kernel_checker.cpp index 4c7c34a790d..001cda3219f 100644 --- a/Kernel_23/test/Kernel_23/Kernel_checker.cpp +++ b/Kernel_23/test/Kernel_23/Kernel_checker.cpp @@ -24,7 +24,7 @@ typedef CGAL::Delaunay_triangulation_3 Delaunay3d; int my_rand() { - return int(CGAL::default_random.get_double()*(1<<31)); + return int(CGAL::get_default_random().get_double()*(1<<31)); } int main() diff --git a/Kernel_d/test/Kernel_d/Linear_algebra-test.cpp b/Kernel_d/test/Kernel_d/Linear_algebra-test.cpp index eefecd03070..af5a3cad1be 100644 --- a/Kernel_d/test/Kernel_d/Linear_algebra-test.cpp +++ b/Kernel_d/test/Kernel_d/Linear_algebra-test.cpp @@ -39,7 +39,7 @@ int main(int argc, char* argv[]) typedef LA::Matrix Matrix; typedef LA::Vector Vector; bool IOTEST = true; - { + { int vec_dim; if (argc == 2) vec_dim = std::atoi(argv[1]); else vec_dim = VEC_DIM; @@ -48,7 +48,7 @@ int main(int argc, char* argv[]) Vector v0(vec_dim), v1(vec_dim), v2(vec_dim); int F[] = { 1,2,3,4,5 }; Vector v11(F,F+2), v12(F,F+3), v13(F,F+4), v14(F,F+5), - v15(v13.begin(),v13.end()), + v15(v13.begin(),v13.end()), v16(vec_dim,NT(1)); CGAL_TEST(v13==v15){} CGAL_TEST(v0==v1){} @@ -64,7 +64,7 @@ int main(int argc, char* argv[]) v1 -= v2; v1 = -v1; CGAL_TEST((v1*v1 == NT(vec_dim*vec_dim*vec_dim))){} - /* squared length of (v1 + v2) = v1*v1 + /* squared length of (v1 + v2) = v1*v1 should be equal to dim*dim*dim */ NT res1 = (v1*v1 - v2*v2); NT res2 = ((v1-v2)*(v1+v2)); @@ -78,7 +78,7 @@ int main(int argc, char* argv[]) if (IOTEST) CGAL_IO_TEST(v1,v2,CGAL::IO::ASCII); } - { + { int mat_dim; if (argc == 2) mat_dim = std::atoi(argv[1]); else mat_dim = MAT_DIM; @@ -86,16 +86,16 @@ int main(int argc, char* argv[]) /* some construction and access ops */ Matrix::Identity ID; Matrix A(mat_dim,mat_dim), B(mat_dim), - I(mat_dim,ID), One(mat_dim,mat_dim,NT(2)); + I(mat_dim,ID), One(mat_dim,mat_dim,NT(2)); CGAL_TEST(A==B){} CGAL_TEST(One*I==One){} std::vector F(mat_dim); - int i,j; + int i,j; for (i = 0; i < mat_dim; i++) { Vector v(mat_dim); - for (j = 0; j < mat_dim; j++) { - A(i,j) = i; + for (j = 0; j < mat_dim; j++) { + A(i,j) = i; B(i,j) = j; v[j] = j; } @@ -115,7 +115,7 @@ int main(int argc, char* argv[]) (0,1,2,3...) (0,1,2,3...) ... - C = A = D = E; + C = A = D = E; */ Matrix::iterator it; @@ -130,15 +130,15 @@ int main(int argc, char* argv[]) CGAL_TEST(A.row(1)*B.column(1)==NT(mat_dim)){} /* some basic arithmetic testing */ - C = A; C += A; - C -= NT(3)*A; - C = -C; + C = A; C += A; + C -= NT(3)*A; + C = -C; CGAL_TEST(C==A){} /* row sum test: */ - Vector ones(mat_dim), row_sum_vec(mat_dim); + Vector ones(mat_dim), row_sum_vec(mat_dim); for (i = 0; i < mat_dim; i++) { - ones[i] = 1; + ones[i] = 1; row_sum_vec[i] = i*mat_dim; } CGAL_TEST(A*ones==row_sum_vec){} @@ -147,16 +147,16 @@ int main(int argc, char* argv[]) /* matrix operations + ,* and |transpose|, |rank| */ CGAL_TEST(C==LA::transpose(C)){} C = C-B; - CGAL_TEST(C==A){} + CGAL_TEST(C==A){} C = I+A; CGAL_TEST(LA::rank(C)==mat_dim){} - + /* matrix operations 2* , |determinant| */ C = NT(2) * I; C = C * NT(2); - Matrix L,U; - Vector c; - std::vector q; + Matrix L,U; + Vector c; + std::vector q; NT det = LA::determinant(C, L, U, q, c); // det must be 2^{2*mat_dim} NT pot = 1; for (i=0; i 0.0; f-=0.1) { Matrix E = C; for (i = 0; i< mat_dim; ++i) for (j = 0; j < mat_dim; ++j) - if ( CGAL::default_random.get_double() > f ) E(i,j)=0; + if ( CGAL::get_default_random().get_double() > f ) E(i,j)=0; if (LA::linear_solver(E, b, x, denom, A, e)) { CGAL_TEST(E*x == b*denom){} @@ -212,10 +212,10 @@ int main(int argc, char* argv[]) if (mat_dim > 1) { // ueberbestimmt: Matrix N(mat_dim,mat_dim-1); - for (i = 0; i < mat_dim; i++) { - for (j = 0; j < mat_dim-1; j++) - N(i,j) = CGAL::default_random.get_int(-mat_dim,mat_dim); - b[i] = CGAL::default_random.get_int(-mat_dim,mat_dim); + for (i = 0; i < mat_dim; i++) { + for (j = 0; j < mat_dim-1; j++) + N(i,j) = CGAL::get_default_random().get_int(-mat_dim,mat_dim); + b[i] = CGAL::get_default_random().get_int(-mat_dim,mat_dim); } if (LA::linear_solver(N,b,x,denom,e)) { CGAL_TEST(N*x == b*denom){} @@ -235,7 +235,7 @@ int main(int argc, char* argv[]) typedef LA::Matrix Matrix; typedef LA::Vector Vector; bool IOTEST = false; - { + { int vec_dim; if (argc == 2) vec_dim = std::atoi(argv[1]); else vec_dim = VEC_DIM; @@ -245,7 +245,7 @@ int main(int argc, char* argv[]) Vector v0(vec_dim), v1(vec_dim), v2(vec_dim); int F[] = { 1,2,3,4,5 }; Vector v11(F,F+2), v12(F,F+3), v13(F,F+4), v14(F,F+5), - v15(v13.begin(),v13.end()), + v15(v13.begin(),v13.end()), v16(vec_dim,NT(1)); CGAL_TEST(v13==v15){} CGAL_TEST(v0==v1){} @@ -261,7 +261,7 @@ int main(int argc, char* argv[]) v1 -= v2; v1 = -v1; CGAL_TEST((v1*v1 == NT(vec_dim*vec_dim*vec_dim))){} - /* squared length of (v1 + v2) = v1*v1 + /* squared length of (v1 + v2) = v1*v1 should be equal to dim*dim*dim */ NT res1 = (v1*v1 - v2*v2); NT res2 = ((v1-v2)*(v1+v2)); @@ -276,7 +276,7 @@ int main(int argc, char* argv[]) if (IOTEST) CGAL_IO_TEST(v1,v2,CGAL::IO::ASCII); } - { + { int mat_dim; if (argc == 2) mat_dim = std::atoi(argv[1]); else mat_dim = MAT_DIM; @@ -284,16 +284,16 @@ int main(int argc, char* argv[]) /* some construction and access ops */ Matrix::Identity ID; Matrix A(mat_dim,mat_dim), B(mat_dim), - I(mat_dim,ID), One(mat_dim,mat_dim,NT(2)); + I(mat_dim,ID), One(mat_dim,mat_dim,NT(2)); CGAL_TEST(A==B){} CGAL_TEST(One*I==One){} std::vector F(mat_dim); - int i,j; + int i,j; for (i = 0; i < mat_dim; i++) { Vector v(mat_dim); - for (j = 0; j < mat_dim; j++) { - A(i,j) = i; + for (j = 0; j < mat_dim; j++) { + A(i,j) = i; B(i,j) = j; v[j] = j; } @@ -313,7 +313,7 @@ int main(int argc, char* argv[]) (0,1,2,3...) (0,1,2,3...) ... - C = A = D = E; + C = A = D = E; */ Matrix::iterator it; @@ -328,15 +328,15 @@ int main(int argc, char* argv[]) CGAL_TEST(A.row(1)*B.column(1)==NT(mat_dim)){} /* some basic arithmetic testing */ - C = A; C += A; - C -= NT(3)*A; - C = -C; + C = A; C += A; + C -= NT(3)*A; + C = -C; CGAL_TEST(C==A){} /* row sum test: */ - Vector ones(mat_dim), row_sum_vec(mat_dim); + Vector ones(mat_dim), row_sum_vec(mat_dim); for (i = 0; i < mat_dim; i++) { - ones[i] = 1; + ones[i] = 1; row_sum_vec[i] = i*mat_dim; } CGAL_TEST(A*ones==row_sum_vec){} @@ -345,16 +345,16 @@ int main(int argc, char* argv[]) /* matrix operations + ,* and |transpose|, |rank| */ CGAL_TEST(C==LA::transpose(C)){} C = C-B; - CGAL_TEST(C==A){} + CGAL_TEST(C==A){} C = I+A; CGAL_TEST(LA::rank(C)==mat_dim){} - + /* matrix operations 2* , |determinant| */ C = NT(2) * I; C = C * NT(2); - Matrix L,U; - Vector c; - std::vector q; + Matrix L,U; + Vector c; + std::vector q; NT det = LA::determinant(C, L, U, q, c); // det must be 2^{2*mat_dim} NT pot = 1; for (i=0; i 0.0; f-=0.1) { Matrix E = C; for (i = 0; i< mat_dim; ++i) for (j = 0; j < mat_dim; ++j) - if ( CGAL::default_random.get_double() > f ) E(i,j)=0; + if ( CGAL::get_default_random().get_double() > f ) E(i,j)=0; if (LA::linear_solver(E, b, x, denom, A, e)) { CGAL_TEST(E*x == b*denom){} @@ -409,10 +409,10 @@ int main(int argc, char* argv[]) if (mat_dim > 1) { // ueberbestimmt: Matrix N(mat_dim,mat_dim-1); - for (i = 0; i < mat_dim; i++) { - for (j = 0; j < mat_dim-1; j++) - N(i,j) = CGAL::default_random.get_int(-mat_dim,mat_dim); - b[i] = CGAL::default_random.get_int(-mat_dim,mat_dim); + for (i = 0; i < mat_dim; i++) { + for (j = 0; j < mat_dim-1; j++) + N(i,j) = CGAL::get_default_random().get_int(-mat_dim,mat_dim); + b[i] = CGAL::get_default_random().get_int(-mat_dim,mat_dim); } if (LA::linear_solver(N,b,x,denom,e)) { CGAL_TEST(N*x == b*denom){} diff --git a/Mesh_2/test/Mesh_2/test_double_map.cpp b/Mesh_2/test/Mesh_2/test_double_map.cpp index 465160ec548..a8e1597cf75 100644 --- a/Mesh_2/test/Mesh_2/test_double_map.cpp +++ b/Mesh_2/test/Mesh_2/test_double_map.cpp @@ -61,7 +61,7 @@ int main(int argc, char** argv) std::cerr << "Filling f with " << number_of_elements << " random integers...\n"; for(unsigned int n=0; n QMPF; double non_zero_double(){ double d; do { - d = CGAL::default_random.get_double(); + d = CGAL::get_default_random().get_double(); if(d ==0) { std::cout << "generated zero" << std::endl; } @@ -130,7 +130,7 @@ void square_test() { for (int i = 0; i<1000; ++i) { - double d = CGAL::default_random.get_double(); + double d = CGAL::get_default_random().get_double(); MPF D(d); assert(D*D == CGAL_NTS square(D)); } @@ -274,8 +274,8 @@ int main(int argc, char **argv) std::cout << "Checking MP_Float(float) constructor." << std::endl; for (int i = 0; i < loops; ++i) { - float d = (float)CGAL::default_random.get_double(); - int exp = int((CGAL::default_random.get_double()-.5)*256); + float d = (float)CGAL::get_default_random().get_double(); + int exp = int((CGAL::get_default_random().get_double()-.5)*256); d = std::ldexp(d, exp); // std::cout << d << std::endl; // std::cout << MPF(d) << std::endl; @@ -289,8 +289,8 @@ int main(int argc, char **argv) std::cout << "Checking MP_Float(double) constructor." << std::endl; MPF y = 0.5000000000000001; // see bug-report on cgal-discuss (2006-06-23). for (int i = 0; i < loops; ++i) { - double d = CGAL::default_random.get_double(); - int exp = int((CGAL::default_random.get_double()-.5)*1024); + double d = CGAL::get_default_random().get_double(); + int exp = int((CGAL::get_default_random().get_double()-.5)*1024); d = std::ldexp(d, exp); // std::cout << d << std::endl; // std::cout << MPF(d) << std::endl; @@ -303,9 +303,9 @@ int main(int argc, char **argv) std::cout << "Checking MP_Float(long double) constructor." << std::endl; for (int i = 0; i < loops; ++i) { - long double d = CGAL::default_random.get_double(); + long double d = CGAL::get_default_random().get_double(); d = d*d; // to get more bits - int exp = int((CGAL::default_random.get_double()-.5)*1024); + int exp = int((CGAL::get_default_random().get_double()-.5)*1024); d = d * std::ldexp(1.0, exp); //std::cout << d << std::endl; //std::cout << MPF(d) << std::endl; diff --git a/Polygon/include/CGAL/Polygon_2/Polygon_2_impl.h b/Polygon/include/CGAL/Polygon_2/Polygon_2_impl.h index add348aad03..be890c5720e 100644 --- a/Polygon/include/CGAL/Polygon_2/Polygon_2_impl.h +++ b/Polygon/include/CGAL/Polygon_2/Polygon_2_impl.h @@ -116,7 +116,7 @@ operator<<(std::ostream &os, const Polygon_2& p) { typename Polygon_2::Vertex_const_iterator i; - switch(os.iword(IO::mode)) { + switch(get_mode(os)) { case IO::ASCII : os << p.size() << ' '; for (i = p.vertices_begin(); i != p.vertices_end(); ++i) { diff --git a/Polyhedron/demo/Polyhedron/Polyhedron_demo_remeshing_plugin_cgal_code.cpp b/Polyhedron/demo/Polyhedron/Polyhedron_demo_remeshing_plugin_cgal_code.cpp index 071120a6711..3f46420eb02 100644 --- a/Polyhedron/demo/Polyhedron/Polyhedron_demo_remeshing_plugin_cgal_code.cpp +++ b/Polyhedron/demo/Polyhedron/Polyhedron_demo_remeshing_plugin_cgal_code.cpp @@ -285,7 +285,7 @@ Scene_item* cgal_code_remesh(QWidget* parent, triangulation.dimension() < 3 ); n = triangulation.number_of_vertices()) { - const int pos = CGAL::default_random.get_int(0, (int)polyhedron_points.size()); + const int pos = CGAL::get_default_random().get_int(0, (int)polyhedron_points.size()); triangulation.insert(polyhedron_points[pos]); } } diff --git a/Polytope_distance_d/test/Polytope_distance_d/test_Polytope_distance_d_2.cpp b/Polytope_distance_d/test/Polytope_distance_d/test_Polytope_distance_d_2.cpp index 4f7e0714fee..d90c48ac530 100644 --- a/Polytope_distance_d/test/Polytope_distance_d/test_Polytope_distance_d_2.cpp +++ b/Polytope_distance_d/test/Polytope_distance_d/test_Polytope_distance_d_2.cpp @@ -55,7 +55,7 @@ typedef CGAL::Polytope_distance_d_traits_2 HTraits1; #include "test_Polytope_distance_d.h" template -void process () +void process () { // generate point set std::vector p_points, q_points; @@ -67,26 +67,26 @@ void process () for ( i = 0; i < 50; ++i) { p_points.push_back (typename K::Point_2( - CGAL::default_random( 0x100000), - CGAL::default_random( 0x100000), + CGAL::get_default_random()( 0x100000), + CGAL::get_default_random()( 0x100000), hom)); } hom = 3.0; for ( i = 0; i < 50; ++i) { q_points.push_back (typename K::Point_2( - -CGAL::default_random( 0x100000), - -CGAL::default_random( 0x100000), + -CGAL::get_default_random()( 0x100000), + -CGAL::get_default_random()( 0x100000), hom)); } } - + // call test function CGAL::test_Polytope_distance_d( p_points.begin(), p_points.end(), q_points.begin(), q_points.end(), Traits(), 1); } - + // main // ---- int @@ -95,5 +95,5 @@ main() process(); process(); } - + // ===== EOF ================================================================== diff --git a/Polytope_distance_d/test/Polytope_distance_d/test_Polytope_distance_d_3.cpp b/Polytope_distance_d/test/Polytope_distance_d/test_Polytope_distance_d_3.cpp index 769b3a60c68..0e19f181359 100644 --- a/Polytope_distance_d/test/Polytope_distance_d/test_Polytope_distance_d_3.cpp +++ b/Polytope_distance_d/test/Polytope_distance_d/test_Polytope_distance_d_3.cpp @@ -55,7 +55,7 @@ typedef CGAL::Polytope_distance_d_traits_3 HTraits1; #include "test_Polytope_distance_d.h" template -void process () +void process () { // generate point set std::vector p_points, q_points; @@ -67,28 +67,28 @@ void process () for ( i = 0; i < 50; ++i) { p_points.push_back (typename K::Point_3( - CGAL::default_random( 0x100000), - CGAL::default_random( 0x100000), - CGAL::default_random( 0x100000), + CGAL::get_default_random()( 0x100000), + CGAL::get_default_random()( 0x100000), + CGAL::get_default_random()( 0x100000), hom)); } hom = 3.0; for ( i = 0; i < 50; ++i) { q_points.push_back (typename K::Point_3( - -CGAL::default_random( 0x100000), - -CGAL::default_random( 0x100000), - -CGAL::default_random( 0x100000), + -CGAL::get_default_random()( 0x100000), + -CGAL::get_default_random()( 0x100000), + -CGAL::get_default_random()( 0x100000), hom)); } } - + // call test function CGAL::test_Polytope_distance_d( p_points.begin(), p_points.end(), q_points.begin(), q_points.end(), Traits(), 1); } - + // main // ---- int @@ -97,5 +97,5 @@ main() process(); process(); } - + // ===== EOF ================================================================== diff --git a/Polytope_distance_d/test/Polytope_distance_d/test_Polytope_distance_d_d.cpp b/Polytope_distance_d/test/Polytope_distance_d/test_Polytope_distance_d_d.cpp index bdc760d965e..3c1e66de7a5 100644 --- a/Polytope_distance_d/test/Polytope_distance_d/test_Polytope_distance_d_d.cpp +++ b/Polytope_distance_d/test/Polytope_distance_d/test_Polytope_distance_d_d.cpp @@ -68,7 +68,7 @@ void process () double hom = 2.0; for ( i = 0; i < 50; ++i) { for (j=0; j { // creation QP_partial_exact_pricing( bool randomize = false, - Random& random = default_random); + Random& random = get_default_random()); // operations int pricing(int& direction ); diff --git a/QP_solver/include/CGAL/QP_solver/QP_partial_filtered_pricing.h b/QP_solver/include/CGAL/QP_solver/QP_partial_filtered_pricing.h index 5395e6ace14..e1c13cd6158 100644 --- a/QP_solver/include/CGAL/QP_solver/QP_partial_filtered_pricing.h +++ b/QP_solver/include/CGAL/QP_solver/QP_partial_filtered_pricing.h @@ -78,7 +78,7 @@ class QP_partial_filtered_pricing // creation QP_partial_filtered_pricing( bool randomize = false, - Random& random = default_random, + Random& random = get_default_random(), ET2NT et2nt = ET2NT()); // operations diff --git a/Random_numbers/include/CGAL/Random.h b/Random_numbers/include/CGAL/Random.h index b6ea695da1f..22cddd1d164 100644 --- a/Random_numbers/include/CGAL/Random.h +++ b/Random_numbers/include/CGAL/Random.h @@ -222,12 +222,16 @@ public: boost::rand48 rng; }; +#ifndef CGAL_HEADER_ONLY // Global variables // ================ CGAL_EXPORT extern Random default_random; +#endif // CGAL_HEADER_ONLY } //namespace CGAL +#ifdef CGAL_HEADER_ONLY +#include +#endif // CGAL_HEADER_ONLY + #endif // CGAL_RANDOM_H - - diff --git a/Random_numbers/include/CGAL/Random_impl.h b/Random_numbers/include/CGAL/Random_impl.h new file mode 100644 index 00000000000..c620df02ab0 --- /dev/null +++ b/Random_numbers/include/CGAL/Random_impl.h @@ -0,0 +1,105 @@ +// Copyright (c) 1997-2001 +// 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$ +// +// +// Author(s) : Sven Schönherr + +#ifdef CGAL_HEADER_ONLY +#define CGAL_INLINE_FUNCTION inline +#else +#define CGAL_INLINE_FUNCTION +#endif + +#include +#include + +namespace CGAL { + +#ifdef CGAL_HEADER_ONLY +inline Random& get_default_random() +{ + static Random default_random; + return default_random; +} +#else // CGAL_HEADER_ONLY +inline Random& get_default_random() +{ return Random::default_random; } +#endif // CGAL_HEADER_ONLY + +// Class implementation (continued) +// ================================ + +// constructors +CGAL_INLINE_FUNCTION +Random:: +Random( ) + : val(0) +{ + // get system's time + std::time_t s; + std::time( &s); + seed = (unsigned int)s; + + // initialize random numbers generator + rng.seed(static_cast(seed)); + random_value = get_int(0, 1<<15); +} + +CGAL_INLINE_FUNCTION +Random:: +Random( unsigned int seed) + : val(0), seed(seed) +{ + // initialize random numbers generator + rng.seed(static_cast(seed)); + random_value = get_int(0, 1<<15); +} + +// seed +CGAL_INLINE_FUNCTION +unsigned int +Random::get_seed () const +{ + return seed; +} + +// state +CGAL_INLINE_FUNCTION +void +Random::save_state( Random::State& state) const +{ + std::ostringstream os; + os << rng; + state = Random::State(os.str(),random_value, val, seed); +} + +CGAL_INLINE_FUNCTION +void +Random::restore_state( const Random::State& state) +{ + std::istringstream is(state.rng); + is >> rng; + random_value = state.random_value; + val = state.val; + seed = state.seed; +} + +} //namespace CGAL diff --git a/Random_numbers/src/CGAL/Random.cpp b/Random_numbers/src/CGAL/Random.cpp index 9a5887a1b15..471accc5128 100644 --- a/Random_numbers/src/CGAL/Random.cpp +++ b/Random_numbers/src/CGAL/Random.cpp @@ -22,67 +22,15 @@ // // Author(s) : Sven Schönherr +#ifndef CGAL_HEADER_ONLY + #include -#include -#include +#include namespace CGAL { -// Class implementation (continued) -// ================================ - -// constructors -Random:: -Random( ) - : val(0) -{ - // get system's time - std::time_t s; - std::time( &s); - seed = (unsigned int)s; - - // initialize random numbers generator - rng.seed(static_cast(seed)); - random_value = get_int(0, 1<<15); -} - -Random:: -Random( unsigned int seed) - : val(0), seed(seed) -{ - // initialize random numbers generator - rng.seed(static_cast(seed)); - random_value = get_int(0, 1<<15); -} - -// seed -unsigned int -Random::get_seed () const -{ - return seed; -} - -// state -void -Random::save_state( Random::State& state) const -{ - std::ostringstream os; - os << rng; - state = Random::State(os.str(),random_value, val, seed); -} - -void -Random::restore_state( const Random::State& state) -{ - std::istringstream is(state.rng); - is >> rng; - random_value = state.random_value; - val = state.val; - seed = state.seed; -} - -// Global variables -// ================ Random default_random; } //namespace CGAL + +#endif diff --git a/Random_numbers/test/Random_numbers/test_Random.cpp b/Random_numbers/test/Random_numbers/test_Random.cpp index c09a960a4d3..ae46b8ee517 100644 --- a/Random_numbers/test/Random_numbers/test_Random.cpp +++ b/Random_numbers/test/Random_numbers/test_Random.cpp @@ -32,33 +32,33 @@ main() { // test get_bool { - bool b = CGAL::default_random.get_bool(); + bool b = CGAL::get_default_random().get_bool(); assert( ! b || b); } // test get_int { - int l = CGAL::default_random.get_int( -100, 0); - int u = CGAL::default_random.get_int( 0, 1000); - int i = CGAL::default_random.get_int( l, u); + int l = CGAL::get_default_random().get_int( -100, 0); + int u = CGAL::get_default_random().get_int( 0, 1000); + int i = CGAL::get_default_random().get_int( l, u); assert( ( l <= i) && ( i < u)); { std::size_t l = 0, u = 10; - std::size_t i = CGAL::default_random.uniform_int(l,u); + std::size_t i = CGAL::get_default_random().uniform_int(l,u); assert( ( l <= i) && ( i <= u)); } { std::ptrdiff_t l = 0, u = 10; - std::ptrdiff_t i = CGAL::default_random.uniform_int(l,u); + std::ptrdiff_t i = CGAL::get_default_random().uniform_int(l,u); assert( ( l <= i) && ( i <= u)); } { std::ptrdiff_t l = 0, u = 10; - std::ptrdiff_t i = CGAL::default_random.uniform_smallint(l,u); + std::ptrdiff_t i = CGAL::get_default_random().uniform_smallint(l,u); assert( ( l <= i) && ( i <= u)); } @@ -67,39 +67,39 @@ main() // test get_double { - double l = CGAL::default_random.get_double( -123.45, -0.99); - double u = CGAL::default_random.get_double( 22.0/7.0, 33.3); - double d = CGAL::default_random.get_double( l, u); + double l = CGAL::get_default_random().get_double( -123.45, -0.99); + double u = CGAL::get_default_random().get_double( 22.0/7.0, 33.3); + double d = CGAL::get_default_random().get_double( l, u); assert( ( l <= d) && ( d < u)); - double ho = CGAL::default_random.get_double(0.5); + double ho = CGAL::get_default_random().get_double(0.5); assert( (0.5 <= ho) && (ho < 1.0)); - double zo = CGAL::default_random.get_double(); + double zo = CGAL::get_default_random().get_double(); assert( (0 <= zo) && (zo < 1.0)); } // test uniform_real { - double d = CGAL::default_random.uniform_real(-10.0, 10.0); + double d = CGAL::get_default_random().uniform_real(-10.0, 10.0); assert( (d >= -10.0) && (d < 10.0) ); - d = CGAL::default_random.uniform_real(0.2); + d = CGAL::get_default_random().uniform_real(0.2); assert( (d >= 0.2) && (d < 1.0) ); - d = CGAL::default_random.uniform_real(); + d = CGAL::get_default_random().uniform_real(); assert( (d >= 0) && (d < 1) ); - d = CGAL::default_random.uniform_01(); + d = CGAL::get_default_random().uniform_01(); assert( (d >= 0) && (d < 1) ); } { - float d = CGAL::default_random.uniform_real(-10.0f, 10.0f); + float d = CGAL::get_default_random().uniform_real(-10.0f, 10.0f); assert( (d >= -10.0f) && (d < 10.0f) ); - d = CGAL::default_random.uniform_real(0.2f); + d = CGAL::get_default_random().uniform_real(0.2f); assert( (d >= 0.2) && (d < 1.0) ); - d = CGAL::default_random.uniform_real(); + d = CGAL::get_default_random().uniform_real(); assert( (d >= 0) && (d < 1) ); - d = CGAL::default_random.uniform_01(); + d = CGAL::get_default_random().uniform_01(); assert( (d >= 0) && (d < 1) ); } @@ -110,10 +110,10 @@ main() int p3[8] = {0,}; int p4[16] = {0,}; for (int loops=0; loops < (1<<16); ++loops) { - unsigned int l1 = CGAL::default_random.get_bits<1>(); - unsigned int l2 = CGAL::default_random.get_bits<2>(); - unsigned int l3 = CGAL::default_random.get_bits<3>(); - unsigned int l4 = CGAL::default_random.get_bits<4>(); + unsigned int l1 = CGAL::get_default_random().get_bits<1>(); + unsigned int l2 = CGAL::get_default_random().get_bits<2>(); + unsigned int l3 = CGAL::get_default_random().get_bits<3>(); + unsigned int l4 = CGAL::get_default_random().get_bits<4>(); assert(l1 < 2); assert(l2 < 4); assert(l3 < 8); @@ -138,7 +138,7 @@ main() // test operator() { - int i = CGAL::default_random( 5555); + int i = CGAL::get_default_random()( 5555); assert( ( 0 <= i) && ( i < 5555)); } @@ -160,7 +160,7 @@ main() std::vector numbers; numbers.push_back(1); - std::random_shuffle(numbers.begin(), numbers.end(), CGAL::default_random); + std::random_shuffle(numbers.begin(), numbers.end(), CGAL::get_default_random()); return( 0); } diff --git a/STL_Extension/test/STL_Extension/test_Compact_container.cpp b/STL_Extension/test/STL_Extension/test_Compact_container.cpp index 04e365e2a0e..567e78c872f 100644 --- a/STL_Extension/test/STL_Extension/test_Compact_container.cpp +++ b/STL_Extension/test/STL_Extension/test_Compact_container.cpp @@ -63,7 +63,7 @@ class Node_2 public: Node_2() - : p(NULL), rnd(CGAL::default_random.get_int(0, 100)) {} + : p(NULL), rnd(CGAL::get_default_random().get_int(0, 100)) {} bool operator==(const Node_2 &n) const { return rnd == n.rnd; } bool operator!=(const Node_2 &n) const { return rnd != n.rnd; } diff --git a/STL_Extension/test/STL_Extension/test_Concurrent_compact_container.cpp b/STL_Extension/test/STL_Extension/test_Concurrent_compact_container.cpp index 5794411d442..b4f6ede8654 100644 --- a/STL_Extension/test/STL_Extension/test_Concurrent_compact_container.cpp +++ b/STL_Extension/test/STL_Extension/test_Concurrent_compact_container.cpp @@ -47,7 +47,7 @@ public: int rnd; Node_2() - : p(NULL), rnd(CGAL::default_random.get_int(0, 100)) {} + : p(NULL), rnd(CGAL::get_default_random().get_int(0, 100)) {} bool operator==(const Node_2 &n) const { return rnd == n.rnd; } bool operator!=(const Node_2 &n) const { return rnd != n.rnd; } diff --git a/Triangulation_3/benchmark/Triangulation_3/Triangulation_benchmark_3.cpp b/Triangulation_3/benchmark/Triangulation_3/Triangulation_benchmark_3.cpp index 9532bb7c2af..2910a3f983e 100644 --- a/Triangulation_3/benchmark/Triangulation_3/Triangulation_benchmark_3.cpp +++ b/Triangulation_3/benchmark/Triangulation_3/Triangulation_benchmark_3.cpp @@ -153,7 +153,7 @@ public: ~Time_accumulator() { timer.stop(); accumulator += timer.time(); } }; -#define drand48 CGAL::default_random.get_double +#define drand48 CGAL::get_default_random().get_double Point rnd_point() { diff --git a/Triangulation_3/examples/Triangulation_3/fast_location_3.cpp b/Triangulation_3/examples/Triangulation_3/fast_location_3.cpp index 1d2ce0ccc77..b6a86304ba5 100644 --- a/Triangulation_3/examples/Triangulation_3/fast_location_3.cpp +++ b/Triangulation_3/examples/Triangulation_3/fast_location_3.cpp @@ -27,9 +27,9 @@ int main() // performing nearest vertex queries to a series of random points, // which is a case where the Fast_location policy is beneficial. for (int i=0; i<10000; ++i) - T.nearest_vertex(Point(CGAL::default_random.get_double(0, 20), - CGAL::default_random.get_double(0, 20), - CGAL::default_random.get_double(0, 20))); + T.nearest_vertex(Point(CGAL::get_default_random().get_double(0, 20), + CGAL::get_default_random().get_double(0, 20), + CGAL::get_default_random().get_double(0, 20))); return 0; } diff --git a/Triangulation_3/test/Triangulation_3/test_static_filters.cpp b/Triangulation_3/test/Triangulation_3/test_static_filters.cpp index 80a325054fd..c1c657f29dd 100644 --- a/Triangulation_3/test/Triangulation_3/test_static_filters.cpp +++ b/Triangulation_3/test/Triangulation_3/test_static_filters.cpp @@ -218,7 +218,7 @@ int main(int argc, char **argv) int loops = (argc < 2) ? 2000 : std::atoi(argv[1]); - int seed = (argc < 3) ? CGAL::default_random.get_int(0, 1<<30) + int seed = (argc < 3) ? CGAL::get_default_random().get_int(0, 1<<30) : std::atoi(argv[2]); std::cout << "Initializing random generator with seed = " << seed diff --git a/cppfiles.txt b/cppfiles.txt index 1ead35fbe1f..a52ee011013 100644 --- a/cppfiles.txt +++ b/cppfiles.txt @@ -7,8 +7,6 @@ Clement: #include "/home/gdamiand/sources/CGAL/Kinetic_data_structures/src/CGAL/numeric_solvers_support.cpp" #include "/home/gdamiand/sources/CGAL/Kinetic_data_structures/src/CGAL/Turkowski_numeric_solver.cpp" -#include "/home/gdamiand/sources/CGAL/Random_numbers/src/CGAL/Random.cpp" // static mais doit pouvoir se remplacer en membre - #include "/home/gdamiand/sources/CGAL/Modular_arithmetic/src/CGAL/Residue_type.cpp" #include "/home/gdamiand/sources/CGAL/Modular_arithmetic/src/CGAL/primes.cpp" @@ -22,6 +20,7 @@ DONE #include "/home/gdamiand/sources/CGAL/Number_types/src/CGAL/Interval_arithm DONE #include "/home/gdamiand/sources/CGAL/Number_types/src/CGAL/test_FPU_rounding_mode.cpp" // static const (ok car utilisé que pour debug) DONE #include "/home/gdamiand/sources/CGAL/Profiling_tools/src/CGAL/Timer.cpp" // variable statique de classe DONE #include "/home/gdamiand/sources/CGAL/Profiling_tools/src/CGAL/Real_timer.cpp" // variable statique de classe +DONE #include "/home/gdamiand/sources/CGAL/Random_numbers/src/CGAL/Random.cpp" // variable globale; utilisée directement (donc pb pour header only) -> we need to replace the use of CGAL::default_random by CGAL::get_default_random(). DONE #include "/home/gdamiand/sources/CGAL/Geomview/src/CGAL/Geomview_stream.cpp" DONE #include "/home/gdamiand/sources/CGAL/Intersections_2/src/CGAL/Bbox_2_intersections.cpp" From d3452cff45d2c51f91459508e7b3f17330927a08 Mon Sep 17 00:00:00 2001 From: Guillaume Damiand Date: Fri, 14 Nov 2014 14:33:31 +0100 Subject: [PATCH 16/30] Version header only for primes.cpp --- Modular_arithmetic/include/CGAL/primes.h | 6 ++++++ Modular_arithmetic/src/CGAL/primes.cpp | 13 ++++--------- cppfiles.txt | 2 +- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/Modular_arithmetic/include/CGAL/primes.h b/Modular_arithmetic/include/CGAL/primes.h index ddc0c8ca24d..b9649b2427f 100644 --- a/Modular_arithmetic/include/CGAL/primes.h +++ b/Modular_arithmetic/include/CGAL/primes.h @@ -27,7 +27,9 @@ namespace CGAL { namespace internal { +#ifndef CGAL_HEADER_ONLY CGAL_EXPORT extern int primes[2000]; +#endif // CGAL_HEADER_ONLY static inline int get_next_lower_prime(int current_prime){ @@ -63,4 +65,8 @@ int get_next_lower_prime(int current_prime){ } } +#ifdef CGAL_HEADER_ONLY +#include +#endif // CGAL_HEADER_ONLY + #endif // CGAL_PRIMES_H diff --git a/Modular_arithmetic/src/CGAL/primes.cpp b/Modular_arithmetic/src/CGAL/primes.cpp index 4d7fdc528a1..63b8b4d2800 100644 --- a/Modular_arithmetic/src/CGAL/primes.cpp +++ b/Modular_arithmetic/src/CGAL/primes.cpp @@ -17,14 +17,9 @@ // // Author(s) : Michael Hemmer -#include +#ifndef CGAL_HEADER_ONLY + #include +#include -namespace CGAL { -namespace internal { - -int primes [2000] = { - 67111067,67111043,67111027,67111013,67110947,67110943,67110931,67110929,67110889,67110881,67110853,67110851,67110847,67110839,67110829,67110817,67110779,67110739,67110733,67110709,67110677,67110661,67110653,67110647,67110613,67110607,67110601,67110599,67110569,67110559,67110557,67110551,67110541,67110521,67110497,67110493,67110479,67110469,67110467,67110457,67110419,67110391,67110377,67110367,67110353,67110331,67110311,67110301,67110283,67110269,67110259,67110247,67110221,67110209,67110191,67110167,67110161,67110151,67110149,67110139,67110107,67110091,67110083,67110077,67110073,67110023,67110013,67110007,67109969,67109941,67109923,67109773,67109759,67109747,67109737,67109723,67109701,67109687,67109671,67109663,67109633,67109629,67109593,67109573,67109563,67109543,67109519,67109507,67109479,67109443,67109431,67109417,67109407,67109363,67109323,67109321,67109299,67109291,67109281,67109269,67109243,67109233,67109227,67109221,67109209,67109201,67109191,67109177,67109171,67109167,67109131,67109123,67109071,67109051,67109033,67109023,67108981,67108961,67108957,67108933,67108919,67108913,67108879,67108859,67108837,67108819,67108777,67108763,67108757,67108753,67108747,67108739,67108729,67108721,67108709,67108693,67108669,67108667,67108661,67108649,67108633,67108597,67108579,67108529,67108511,67108507,67108493,67108471,67108463,67108453,67108439,67108387,67108373,67108369,67108351,67108331,67108313,67108303,67108289,67108271,67108219,67108207,67108201,67108199,67108187,67108183,67108177,67108127,67108109,67108081,67108049,67108039,67108037,67108033,67108009,67108007,67108003,67107983,67107977,67107967,67107941,67107919,67107913,67107883,67107881,67107871,67107863,67107809,67107797,67107793,67107787,67107773,67107757,67107749,67107739,67107737,67107713,67107707,67107697,67107673,67107643,67107641,67107631,67107617,67107569,67107553,67107541,67107539,67107533,67107527,67107499,67107497,67107473,67107463,67107461,67107457,67107427,67107389,67107349,67107331,67107323,67107319,67107317,67107311,67107301,67107289,67107253,67107241,67107223,67107217,67107203,67107191,67107151,67107149,67107101,67107097,67107071,67107043,67106989,67106987,67106983,67106903,67106833,67106821,67106813,67106797,67106761,67106749,67106737,67106719,67106717,67106693,67106687,67106657,67106591,67106587,67106561,67106539,67106503,67106483,67106477,67106447,67106407,67106399,67106393,67106383,67106357,67106339,67106323,67106311,67106279,67106257,67106243,67106239,67106231,67106213,67106189,67106167,67106159,67106113,67106107,67106099,67106093,67106063,67106059,67106033,67106023,67105991,67105963,67105949,67105943,67105937,67105933,67105903,67105879,67105877,67105873,67105867,67105849,67105837,67105823,67105811,67105781,67105771,67105769,67105763,67105729,67105711,67105699,67105691,67105609,67105567,67105553,67105517,67105501,67105487,67105481,67105471,67105459,67105453,67105439,67105399,67105393,67105373,67105369,67105349,67105319,67105303,67105267,67105249,67105219,67105211,67105201,67105193,67105187,67105141,67105133,67105127,67105091,67105081,67105061,67104997,67104991,67104977,67104949,67104931,67104923,67104913,67104907,67104901,67104893,67104883,67104871,67104859,67104857,67104847,67104841,67104833,67104803,67104769,67104757,67104743,67104707,67104691,67104689,67104679,67104649,67104647,67104617,67104607,67104601,67104589,67104581,67104571,67104563,67104539,67104529,67104517,67104449,67104439,67104437,67104419,67104379,67104361,67104341,67104313,67104293,67104277,67104263,67104251,67104227,67104161,67104139,67104127,67104113,67104073,67104071,67104061,67104053,67104047,67104043,67104031,67104019,67104007,67103983,67103969,67103963,67103909,67103893,67103887,67103867,67103851,67103837,67103821,67103761,67103749,67103737,67103731,67103711,67103689,67103669,67103657,67103653,67103633,67103609,67103587,67103579,67103549,67103513,67103507,67103503,67103483,67103479,67103467,67103431,67103423,67103411,67103389,67103359,67103327,67103321,67103297,67103293,67103273,67103249,67103227,67103219,67103209,67103191,67103173,67103159,67103149,67103147,67103143,67103137,67103107,67103083,67103051,67103039,67103033,67103027,67103021,67103009,67102991,67102969,67102967,67102963,67102949,67102943,67102921,67102913,67102901,67102873,67102843,67102801,67102741,67102733,67102729,67102727,67102703,67102669,67102663,67102657,67102649,67102639,67102627,67102613,67102603,67102561,67102537,67102531,67102499,67102487,67102459,67102457,67102447,67102439,67102397,67102391,67102333,67102331,67102291,67102283,67102249,67102241,67102237,67102223,67102219,67102193,67102181,67102177,67102163,67102159,67102153,67102151,67102099,67102093,67102069,67102067,67102051,67102033,67102031,67102019,67102003,67101997,67101989,67101961,67101919,67101899,67101883,67101877,67101799,67101791,67101779,67101743,67101739,67101691,67101689,67101637,67101631,67101623,67101613,67101607,67101569,67101523,67101509,67101493,67101491,67101479,67101469,67101449,67101443,67101421,67101413,67101361,67101343,67101341,67101323,67101299,67101271,67101263,67101247,67101241,67101191,67101187,67101173,67101169,67101161,67101119,67101109,67101079,67101053,67101043,67100987,67100981,67100977,67100963,67100953,67100947,67100939,67100911,67100909,67100899,67100897,67100861,67100857,67100851,67100849,67100827,67100801,67100791,67100779,67100777,67100773,67100753,67100731,67100713,67100699,67100687,67100681,67100669,67100659,67100653,67100639,67100617,67100599,67100587,67100569,67100531,67100497,67100489,67100459,67100447,67100389,67100357,67100353,67100347,67100329,67100311,67100303,67100281,67100273,67100263,67100261,67100251,67100249,67100239,67100233,67100197,67100179,67100141,67100123,67100101,67100087,67100017,67100009,67099999,67099987,67099957,67099951,67099937,67099931,67099927,67099913,67099889,67099861,67099853,67099831,67099829,67099819,67099801,67099793,67099789,67099783,67099771,67099727,67099699,67099687,67099633,67099589,67099577,67099559,67099547,67099541,67099523,67099517,67099499,67099481,67099457,67099447,67099433,67099399,67099397,67099387,67099369,67099363,67099339,67099321,67099309,67099273,67099271,67099267,67099231,67099223,67099217,67099213,67099199,67099171,67099141,67099133,67099129,67099121,67099111,67099103,67099057,67099037,67099031,67098991,67098971,67098931,67098923,67098917,67098907,67098853,67098851,67098839,67098827,67098821,67098809,67098793,67098769,67098761,67098743,67098739,67098697,67098653,67098637,67098623,67098589,67098529,67098527,67098487,67098463,67098457,67098433,67098419,67098403,67098389,67098377,67098359,67098347,67098341,67098323,67098319,67098313,67098307,67098301,67098299,67098277,67098271,67098259,67098233,67098203,67098197,67098193,67098179,67098151,67098149,67098121,67098091,67098071,67098067,67098049,67098047,67098041,67098029,67098019,67098013,67098007,67098001,67097993,67097977,67097959,67097917,67097903,67097869,67097837,67097819,67097813,67097803,67097749,67097747,67097729,67097707,67097699,67097669,67097659,67097603,67097593,67097579,67097567,67097551,67097543,67097507,67097489,67097447,67097441,67097413,67097383,67097369,67097363,67097339,67097333,67097323,67097321,67097297,67097291,67097281,67097273,67097269,67097267,67097209,67097183,67097179,67097123,67097111,67097087,67097081,67097053,67097047,67096987,67096979,67096973,67096921,67096919,67096907,67096903,67096867,67096837,67096817,67096769,67096751,67096717,67096703,67096697,67096693,67096669,67096663,67096649,67096613,67096607,67096583,67096559,67096553,67096507,67096499,67096487,67096483,67096439,67096423,67096411,67096409,67096387,67096373,67096327,67096319,67096303,67096301,67096291,67096261,67096247,67096243,67096231,67096223,67096177,67096151,67096109,67096103,67096097,67096069,67096067,67096063,67096031,67096021,67096013,67096009,67095989,67095983,67095971,67095929,67095893,67095883,67095869,67095857,67095851,67095799,67095797,67095737,67095733,67095731,67095703,67095701,67095683,67095667,67095659,67095629,67095607,67095559,67095551,67095529,67095521,67095499,67095493,67095487,67095421,67095419,67095407,67095383,67095359,67095349,67095317,67095239,67095227,67095221,67095211,67095199,67095173,67095143,67095139,67095131,67095101,67095079,67095047,67095043,67095037,67095013,67095011,67095001,67094987,67094981,67094969,67094941,67094917,67094899,67094891,67094837,67094831,67094827,67094821,67094809,67094759,67094743,67094723,67094717,67094711,67094707,67094701,67094647,67094639,67094593,67094591,67094581,67094557,67094527,67094513,67094507,67094501,67094497,67094471,67094459,67094437,67094411,67094407,67094389,67094369,67094353,67094351,67094329,67094311,67094309,67094299,67094297,67094281,67094267,67094179,67094177,67094173,67094161,67094143,67094141,67094123,67094119,67094099,67094047,67094039,67094021,67094011,67093993,67093979,67093937,67093933,67093931,67093903,67093861,67093853,67093843,67093841,67093801,67093759,67093757,67093723,67093721,67093699,67093681,67093633,67093627,67093619,67093613,67093603,67093597,67093591,67093547,67093519,67093489,67093471,67093409,67093381,67093349,67093319,67093307,67093303,67093297,67093291,67093267,67093249,67093223,67093183,67093181,67093171,67093163,67093157,67093129,67093121,67093109,67093087,67093079,67093069,67093043,67093031,67093007,67093003,67092997,67092953,67092947,67092911,67092887,67092871,67092869,67092847,67092841,67092821,67092811,67092787,67092757,67092749,67092737,67092721,67092709,67092691,67092673,67092671,67092643,67092637,67092611,67092607,67092589,67092563,67092539,67092521,67092511,67092491,67092461,67092451,67092419,67092407,67092391,67092367,67092331,67092323,67092301,67092271,67092247,67092227,67092203,67092199,67092197,67092143,67092139,67092133,67092119,67092107,67092079,67092071,67092041,67092017,67092001,67091987,67091939,67091933,67091923,67091903,67091873,67091861,67091839,67091833,67091821,67091807,67091803,67091797,67091779,67091771,67091743,67091737,67091729,67091683,67091681,67091677,67091669,67091617,67091611,67091561,67091551,67091543,67091501,67091491,67091477,67091467,67091447,67091443,67091441,67091417,67091407,67091369,67091357,67091351,67091341,67091329,67091317,67091291,67091287,67091251,67091243,67091203,67091159,67091149,67091131,67091113,67091107,67091077,67091041,67091039,67091029,67090999,67090979,67090973,67090939,67090937,67090921,67090871,67090861,67090841,67090783,67090769,67090763,67090759,67090711,67090703,67090693,67090679,67090631,67090627,67090613,67090591,67090589,67090579,67090571,67090567,67090561,67090553,67090549,67090547,67090523,67090519,67090489,67090459,67090451,67090433,67090411,67090403,67090399,67090351,67090343,67090321,67090307,67090271,67090259,67090237,67090229,67090223,67090217,67090207,67090189,67090171,67090151,67090129,67090117,67090099,67090091,67090073,67090061,67090043,67090033,67090031,67090027,67090013,67089989,67089949,67089943,67089907,67089877,67089857,67089839,67089829,67089811,67089809,67089793,67089751,67089739,67089733,67089721,67089707,67089697,67089683,67089619,67089587,67089577,67089541,67089527,67089511,67089479,67089469,67089461,67089377,67089329,67089299,67089287,67089283,67089277,67089271,67089241,67089233,67089223,67089221,67089199,67089097,67089059,67089049,67089047,67089013,67088993,67088969,67088963,67088951,67088939,67088911,67088873,67088849,67088839,67088821,67088797,67088779,67088731,67088719,67088717,67088713,67088711,67088683,67088657,67088653,67088627,67088621,67088603,67088597,67088573,67088561,67088521,67088509,67088501,67088473,67088453,67088429,67088393,67088383,67088381,67088347,67088323,67088311,67088303,67088291,67088279,67088267,67088257,67088249,67088209,67088159,67088149,67088117,67088101,67088093,67088081,67088071,67088059,67088039,67088023,67088011,67087981,67087973,67087961,67087957,67087913,67087901,67087883,67087873,67087871,67087859,67087799,67087781,67087777,67087747,67087723,67087717,67087693,67087681,67087679,67087649,67087637,67087591,67087583,67087571,67087567,67087547,67087529,67087519,67087487,67087483,67087463,67087459,67087451,67087421,67087417,67087381,67087367,67087351,67087277,67087259,67087249,67087243,67087217,67087201,67087187,67087177,67087171,67087127,67087123,67087103,67087087,67087039,67087019,67086983,67086979,67086961,67086949,67086937,67086931,67086917,67086893,67086871,67086869,67086839,67086827,67086823,67086793,67086757,67086727,67086673,67086671,67086667,67086647,67086637,67086629,67086623,67086611,67086589,67086559,67086521,67086457,67086433,67086421,67086391,67086361,67086347,67086337,67086323,67086317,67086311,67086307,67086293,67086281,67086259,67086211,67086191,67086137,67086109,67086083,67086067,67086053,67086049,67086043,67086013,67086007,67086001,67085959,67085939,67085933,67085923,67085911,67085899,67085869,67085867,67085861,67085849,67085839,67085831,67085819,67085813,67085803,67085801,67085783,67085771,67085761,67085741,67085731,67085701,67085677,67085657,67085647,67085639,67085617,67085609,67085569,67085533,67085531,67085527,67085521,67085453,67085443,67085437,67085429,67085401,67085377,67085357,67085353,67085351,67085341,67085303,67085287,67085267,67085261,67085233,67085191,67085189,67085173,67085171,67085159,67085119,67085101,67085099,67085093,67085059,67085047,67085003,67084993,67084981,67084973,67084931,67084891,67084879,67084861,67084817,67084807,67084799,67084793,67084789,67084783,67084781,67084777,67084757,67084753,67084751,67084723,67084709,67084681,67084679,67084657,67084643,67084639,67084637,67084609,67084603,67084553,67084547,67084517,67084513,67084483,67084477,67084471,67084447,67084439,67084427,67084417,67084387,67084349,67084333,67084331,67084313,67084309,67084289,67084267,67084247,67084189,67084187,67084177,67084141,67084139,67084111,67084097,67084081,67084049,67084033,67084013,67084001,67083977,67083959,67083943,67083937,67083901,67083883,67083871,67083859,67083829,67083811,67083803,67083799,67083787,67083781,67083773,67083769,67083761,67083739,67083727,67083707,67083703,67083697,67083689,67083631,67083629,67083619,67083613,67083589,67083539,67083521,67083517,67083481,67083461,67083451,67083437,67083371,67083323,67083239,67083221,67083217,67083209,67083199,67083197,67083193,67083113,67083097,67083067,67083043,67083041,67083017,67082989,67082987,67082963,67082933,67082909,67082891,67082861,67082857,67082843,67082831,67082809,67082801,67082783,67082779,67082753,67082707,67082699,67082689,67082671,67082657,67082599,67082579,67082557,67082551,67082549,67082531,67082503,67082497,67082453,67082417,67082399,67082383,67082363,67082341,67082339,67082321,67082311,67082251,67082231,67082227,67082189,67082159,67082143,67082131,67082129,67082123,67082101,67082083,67082023,67082003,67081957,67081919,67081897,67081871,67081841,67081829,67081811,67081787,67081783,67081771,67081769,67081759,67081741,67081733,67081717,67081709,67081697,67081691,67081687,67081681,67081661,67081633,67081631,67081621,67081603,67081601,67081583,67081579,67081577,67081537,67081529,67081499,67081477,67081459,67081429,67081423,67081393,67081351,67081319,67081309,67081283,67081249,67081243,67081237,67081219,67081213,67081211,67081159,67081139,67081127,67081123,67081103,67081097,67081073,67081057,67081051,67080977,67080971,67080967,67080947,67080917,67080859,67080833,67080823,67080821,67080803,67080781,67080763,67080757,67080751,67080737,67080709,67080701,67080679,67080653,67080647,67080631,67080557,67080553,67080527,67080491,67080479,67080439,67080437,67080413,67080367,67080361,67080353,67080337,67080329,67080323,67080319,67080287,67080281,67080271,67080217,67080191,67080179,67080173,67080157,67080131,67080107,67080073,67080061,67080047,67080037,67080031,67080023,67079993,67079989,67079981,67079963,67079941,67079933,67079917,67079911,67079869,67079863,67079849,67079839,67079801,67079791,67079777,67079767,67079759,67079737,67079711,67079693,67079657,67079647,67079641,67079599,67079591,67079587,67079497,67079491,67079489,67079473,67079461,67079459,67079449,67079437,67079429,67079423,67079393,67079359,67079351,67079347,67079333,67079323,67079317,67079303,67079281,67079267,67079249,67079237,67079219,67079213,67079209,67079203,67079197,67079179,67079153,67079149,67079141,67079123,67079107,67079087,67079083,67079081,67079053,67079041,67079027,67079021,67078981,67078961,67078931,67078919,67078903,67078877,67078871,67078819,67078813,67078807,67078801,67078793,67078789,67078777,67078763,67078703,67078673,67078643,67078577,67078573,67078553,67078519,67078483,67078469,67078463,67078433,67078423,67078391,67078387,67078369,67078367,67078343,67078331,67078309,67078301,67078289,67078283,67078217,67078213,67078199,67078181,67078171,67078169,67078159,67078153,67078147,67078139,67078133,67078127,67078117,67078069,67078061,67078013,67078007,67078001,67077991,67077947,67077931,67077917,67077877,67077859,67077851,67077827,67077811,67077799,67077797,67077793,67077761,67077757,67077737,67077719,67077697,67077643,67077623,67077611,67077607,67077553,67077541,67077539,67077523,67077511,67077503,67077497,67077473,67077469,67077449,67077419,67077403,67077379,67077349,67077341,67077313,67077301,67077299,67077293,67077287,67077259,67077217,67077181,67077173,67077169,67077167,67077161,67077133,67077103,67077079,67077071,67077047,67077007,67077001,67076953,67076929,67076927,67076903,67076899,67076887,67076879,67076869,67076857,67076851,67076843,67076833,67076803,67076773,67076741,67076729,67076693,67076683,67076677,67076663,67076651,67076629,67076627,67076599,67076573,67076549,67076539,67076519,67076497,67076489,67076413,67076411,67076389,67076371,67076357,67076353,67076351,67076341,67076291,67076279,67076263,67076231,67076189,67076147,67076117,67076077,67076071,67076069,67076057,67076039,67076029,67075993,67075991,67075973,67075963,67075949,67075937,67075933,67075913,67075907,67075873,67075867,67075849,67075837,67075823,67075787,67075781,67075769,67075747,67075741,67075699,67075691,67075669,67075663,67075649,67075639,67075633,67075621,67075609,67075607,67075601,67075583,67075577,67075573,67075531 }; - -} // namespace internal -} // namespace CGAL +#endif diff --git a/cppfiles.txt b/cppfiles.txt index a52ee011013..35a9358f694 100644 --- a/cppfiles.txt +++ b/cppfiles.txt @@ -8,7 +8,6 @@ Clement: #include "/home/gdamiand/sources/CGAL/Kinetic_data_structures/src/CGAL/Turkowski_numeric_solver.cpp" #include "/home/gdamiand/sources/CGAL/Modular_arithmetic/src/CGAL/Residue_type.cpp" -#include "/home/gdamiand/sources/CGAL/Modular_arithmetic/src/CGAL/primes.cpp" Guillaume @@ -21,6 +20,7 @@ DONE #include "/home/gdamiand/sources/CGAL/Number_types/src/CGAL/test_FPU_roundi DONE #include "/home/gdamiand/sources/CGAL/Profiling_tools/src/CGAL/Timer.cpp" // variable statique de classe DONE #include "/home/gdamiand/sources/CGAL/Profiling_tools/src/CGAL/Real_timer.cpp" // variable statique de classe DONE #include "/home/gdamiand/sources/CGAL/Random_numbers/src/CGAL/Random.cpp" // variable globale; utilisée directement (donc pb pour header only) -> we need to replace the use of CGAL::default_random by CGAL::get_default_random(). +DONE #include "/home/gdamiand/sources/CGAL/Modular_arithmetic/src/CGAL/primes.cpp" // constante globale DONE #include "/home/gdamiand/sources/CGAL/Geomview/src/CGAL/Geomview_stream.cpp" DONE #include "/home/gdamiand/sources/CGAL/Intersections_2/src/CGAL/Bbox_2_intersections.cpp" From b92bcae1a9186e5ff13305613d3b675df4cd85fa Mon Sep 17 00:00:00 2001 From: Guillaume Damiand Date: Fri, 14 Nov 2014 14:53:54 +0100 Subject: [PATCH 17/30] Header only for Residue_type.cpp --- .../CGAL/Modular_arithmetic/Residue_type.h | 281 +++++++++++------- Modular_arithmetic/src/CGAL/Residue_type.cpp | 5 +- 2 files changed, 182 insertions(+), 104 deletions(-) diff --git a/Modular_arithmetic/include/CGAL/Modular_arithmetic/Residue_type.h b/Modular_arithmetic/include/CGAL/Modular_arithmetic/Residue_type.h index 0f6228347f3..6af77fd5329 100644 --- a/Modular_arithmetic/include/CGAL/Modular_arithmetic/Residue_type.h +++ b/Modular_arithmetic/include/CGAL/Modular_arithmetic/Residue_type.h @@ -32,8 +32,75 @@ namespace CGAL { +#ifdef CGAL_HAS_THREADS + +#ifdef CGAL_HEADER_ONLY +inline boost::thread_specific_ptr& get_static_prime_int_() +{ + static boost::thread_specific_ptr prime_int_; + return prime_int_; +} +inline boost::thread_specific_ptr& get_static_prime_() +{ + static boost::thread_specific_ptr prime_; + return prime_; +} +inline boost::thread_specific_ptr& get_static_prime_inv_() +{ + static boost::thread_specific_ptr prime_inv_; + return prime_inv_; +} +#else // CGAL_HEADER_ONLY +inline boost::thread_specific_ptr& get_static_prime_int_() +{ return Residue::prime_int_; } +inline boost::thread_specific_ptr& get_static_prime_() +{ return Residue::prime_; } +inline boost::thread_specific_ptr& get_static_prime_inv_() +{ return Residue::prime_inv_; } +#endif // CGAL_HEADER_ONLY + +#else // CGAL_HAS_THREADS + +#ifdef CGAL_HEADER_ONLY +inline int& get_static_prime_int() +{ + static int prime_int = 67111067; + return prime_int; +} +inline double& get_static_prime() +{ + static double prime = 67111067.0; + return prime; +} +inline double& get_static_prime_inv() +{ + static double prime_inv = 1/67111067.0; + return prime_inv; +} +#else // CGAL_HEADER_ONLY +inline int& get_static_prime_int() +{ return Residue::prime_int; } +inline double& get_static_prime() +{ return Residue::prime; } +inline double& get_static_prime_inv() +{ return Residue::prime_inv; } +#endif // CGAL_HEADER_ONLY + +#endif // CGAL_HAS_THREADS + +#ifdef CGAL_HEADER_ONLY +inline double& get_static_CST_CUT() +{ + static double CST_CUT = std::ldexp( 3., 51 ); + return CST_CUT; +} +#else // CGAL_HEADER_ONLY +inline double& get_static_CST_CUT() +{ return Residue::CST_CUT; } +#endif // CGAL_HEADER_ONLY + class Residue; - + Residue operator + (const Residue&); Residue operator - (const Residue&); @@ -41,78 +108,86 @@ std::ostream& operator << (std::ostream& os, const Residue& p); std::istream& operator >> (std::istream& is, Residue& p); /*! \ingroup CGAL_Modular_traits - * \brief This class represents the Field Z mod p. - * - * This class uses the type double for representation. + * \brief This class represents the Field Z mod p. + * + * This class uses the type double for representation. * Therefore the value of p is restricted to primes less than 2^26. * By default p is set to 67111067. * * It provides the standard operators +,-,*,/ as well as in&output. - * + * * \see Modular_traits */ class Residue: boost::ordered_field_operators1< Residue, boost::ordered_field_operators2< Residue, int > >{ - + public: typedef Residue Self; typedef Residue NT; - + private: - CGAL_EXPORT static const double CST_CUT; - +#ifndef CGAL_HEADER_ONLY + CGAL_EXPORT static const double CST_CUT; +#endif // CGAL_HEADER_ONLY + #ifdef CGAL_HAS_THREADS + +#ifndef CGAL_HEADER_ONLY CGAL_EXPORT static boost::thread_specific_ptr prime_int_; CGAL_EXPORT static boost::thread_specific_ptr prime_; CGAL_EXPORT static boost::thread_specific_ptr prime_inv_; - +#endif // CGAL_HEADER_ONLY + static void init_class_for_thread(){ - CGAL_precondition(prime_int_.get() == NULL); - CGAL_precondition(prime_.get() == NULL); - CGAL_precondition(prime_inv_.get() == NULL); - prime_int_.reset(new int(67111067)); - prime_.reset(new double(67111067.0)); - prime_inv_.reset(new double(1.0/67111067.0)); + CGAL_precondition(get_static_prime_int_().get() == NULL); + CGAL_precondition(get_static_prime_().get() == NULL); + CGAL_precondition(get_static_prime_inv_().get() == NULL); + get_static_prime_int_().reset(new int(67111067)); + get_static_prime_().reset(new double(67111067.0)); + get_static_prime_inv_().reset(new double(1.0/67111067.0)); } - + static inline int get_prime_int(){ - if (prime_int_.get() == NULL) + if (get_static_prime_int_().get() == NULL) init_class_for_thread(); - return *prime_int_.get(); + return *get_static_prime_int_().get(); } - + static inline double get_prime(){ - if (prime_.get() == NULL) + if (get_static_prime_().get() == NULL) init_class_for_thread(); - return *prime_.get(); + return *get_static_prime_().get(); } - + static inline double get_prime_inv(){ - if (prime_inv_.get() == NULL) + if (get_static_prime_inv_().get() == NULL) init_class_for_thread(); - return *prime_inv_.get(); + return *get_static_prime_inv_().get(); } -#else +#else // CGAL_HAS_THREADS + +#ifndef CGAL_HEADER_ONLY CGAL_EXPORT static int prime_int; CGAL_EXPORT static double prime; CGAL_EXPORT static double prime_inv; - static int get_prime_int(){ return prime_int;} - static double get_prime() { return prime;} - static double get_prime_inv(){ return prime_inv;} +#endif // CGAL_HEADER_ONLY + static int get_prime_int(){ return get_static_prime_int();} + static double get_prime() { return get_static_prime();} + static double get_prime_inv(){ return get_static_prime_inv();} #endif - /* Quick integer rounding, valid if a<2^51. for double */ - static inline + /* Quick integer rounding, valid if a<2^51. for double */ + static inline double RES_round (double a){ // call CGAL::Protect_FPU_rounding pfr(CGAL_FE_TONEAREST) - // before using modular arithmetic + // before using modular arithmetic CGAL_assertion(FPU_get_cw() == CGAL_FE_TONEAREST); - return ( (a + CST_CUT) - CST_CUT); + return ( (a + get_static_CST_CUT()) - get_static_CST_CUT()); } /* Big modular reduction (e.g. after multiplication) */ - static inline + static inline double RES_reduce (double a){ double result = a - get_prime() * RES_round(a * get_prime_inv()); CGAL_postcondition(2*result < get_prime()); @@ -121,7 +196,7 @@ private: } /* Little modular reduction (e.g. after a simple addition). */ - static inline + static inline double RES_soft_reduce (double a){ double p = get_prime(); double b = 2*a; @@ -129,16 +204,16 @@ private: ((b<-p) ? a+p : a); } - + /* -a */ - static inline + static inline double RES_negate(double a){ return RES_soft_reduce(-a); } /* a*b */ - static inline + static inline double RES_mul (double a, double b){ double c = a*b; return RES_reduce(c); @@ -146,21 +221,21 @@ private: /* a+b */ - static inline + static inline double RES_add (double a, double b){ double c = a+b; return RES_soft_reduce(c); } - + /* a^-1, using Bezout (extended Euclidian algorithm). */ - static inline + static inline double RES_inv (double ri1){ double bi = 0.0; double bi1 = 1.0; double ri = get_prime(); double p, tmp, tmp2; - + Real_embeddable_traits::Abs double_abs; while (double_abs(ri1) != 1.0) { @@ -175,131 +250,131 @@ private: return ri1 * RES_soft_reduce(bi1); /* Quicker !!!! */ } - + /* a/b */ - static inline + static inline double RES_div (double a, double b){ return RES_mul(a, RES_inv(b)); - } + } public: - /*! \brief sets the current prime. - * + /*! \brief sets the current prime. + * * Note that you are going to change a static member! * \pre p is prime, but we abstained from such a test. * \pre 0 < p < 2^26 - * + * */ - static int - set_current_prime(int p){ - int old_prime = get_prime_int(); + static int + set_current_prime(int p){ + int old_prime = get_prime_int(); #ifdef CGAL_HAS_THREADS - *prime_int_.get() = p; - *prime_.get() = double(p); - *prime_inv_.get() = 1.0/double(p); + *get_static_prime_int_().get() = p; + *get_static_prime_().get() = double(p); + *get_static_prime_inv_().get() = 1.0/double(p); #else - prime_int = p; - prime = double(p); - prime_inv = 1.0 / prime; + get_static_prime_int() = p; + get_static_prime() = double(p); + get_static_prime_inv() = 1.0 / prime; #endif - return old_prime; + return old_prime; } - + /*! \brief return the current prime. */ static int get_current_prime(){ return get_prime_int(); } - + int get_value() const{ CGAL_precondition(2*x_ < get_prime()); CGAL_precondition(2*x_ > -get_prime()); return int(x_); } - + private: double x_; -public: +public: - //! constructor of Residue, from int + //! constructor of Residue, from int Residue(int n = 0){ x_= RES_reduce(n); } - //! constructor of Residue, from long + //! constructor of Residue, from long Residue(long n){ x_= RES_reduce((double)n); } - - //! Access operator for x, \c const + + //! Access operator for x, \c const const double& x() const { return x_; } //! Access operator for x - double& x() { return x_; } + double& x() { return x_; } - Self& operator += (const Self& p2) { - x() = RES_add(x(),p2.x()); - return (*this); + Self& operator += (const Self& p2) { + x() = RES_add(x(),p2.x()); + return (*this); } - Self& operator -= (const Self& p2){ - x() = RES_add(x(),RES_negate(p2.x())); - return (*this); + Self& operator -= (const Self& p2){ + x() = RES_add(x(),RES_negate(p2.x())); + return (*this); } - Self& operator *= (const Self& p2){ - x() = RES_mul(x(),p2.x()); - return (*this); + Self& operator *= (const Self& p2){ + x() = RES_mul(x(),p2.x()); + return (*this); } - Self& operator /= (const Self& p2) { - x() = RES_div(x(),p2.x()); - return (*this); + Self& operator /= (const Self& p2) { + x() = RES_div(x(),p2.x()); + return (*this); } - // - Self& operator += (int p2) { - x() = RES_add(x(),Residue(p2).x()); - return (*this); + // + Self& operator += (int p2) { + x() = RES_add(x(),Residue(p2).x()); + return (*this); } - Self& operator -= (int p2){ - x() = RES_add(x(),Residue(-p2).x()); - return (*this); + Self& operator -= (int p2){ + x() = RES_add(x(),Residue(-p2).x()); + return (*this); } - Self& operator *= (int p2){ - x() = RES_mul(x(),Residue(p2).x()); - return (*this); + Self& operator *= (int p2){ + x() = RES_mul(x(),Residue(p2).x()); + return (*this); } - Self& operator /= (int p2) { - x() = RES_div(x(),Residue(p2).x()); - return (*this); + Self& operator /= (int p2) { + x() = RES_div(x(),Residue(p2).x()); + return (*this); } - + friend Self operator + (const Self&); - friend Self operator - (const Self&); + friend Self operator - (const Self&); }; inline Residue operator + (const Residue& p1) { return p1; } -inline Residue operator - (const Residue& p1){ +inline Residue operator - (const Residue& p1){ typedef Residue RES; - Residue r; + Residue r; r.x() = RES::RES_negate(p1.x()); - return r; + return r; } inline bool operator == (const Residue& p1, const Residue& p2) -{ return ( p1.x()==p2.x() ); } +{ return ( p1.x()==p2.x() ); } inline bool operator == (const Residue& p1, int p2) -{ return ( p1 == Residue(p2) ); } +{ return ( p1 == Residue(p2) ); } inline bool operator < (const Residue& p1, const Residue& p2) -{ return ( p1.x() < p2.x() ); } +{ return ( p1.x() < p2.x() ); } inline bool operator < (const Residue& p1, int p2) -{ return ( p1.x() < Residue(p2).x() ); } +{ return ( p1.x() < Residue(p2).x() ); } -// I/O -inline std::ostream& operator << (std::ostream& os, const Residue& p) { +// I/O +inline std::ostream& operator << (std::ostream& os, const Residue& p) { typedef Residue RES; os <<"("<< int(p.x())<<"%"< +#include namespace CGAL{ #ifdef CGAL_HAS_THREADS @@ -35,3 +36,5 @@ double Residue::prime_inv =1/67111067.0; const double Residue::CST_CUT = std::ldexp( 3., 51 ); } + +#endif From ef550fd3bb41d213ce4299e9209af80613f29539 Mon Sep 17 00:00:00 2001 From: Guillaume Damiand Date: Fri, 14 Nov 2014 17:22:06 +0100 Subject: [PATCH 18/30] Ok for first version. --- CMakeLists.txt | 2 +- Generator/include/CGAL/generators.h | 4 +- Generator/include/CGAL/point_generators_2.h | 18 +- Generator/include/CGAL/point_generators_3.h | 6 +- .../CGAL/Modular_arithmetic/Residue_type.h | 140 +++--- Modular_arithmetic/include/CGAL/primes.h | 2 +- Nef_3/include/CGAL/Nef_3/Pluecker_line_3.h | 2 +- Nef_3/include/CGAL/Nef_3/SNC_io_parser.h | 436 +++++++++--------- Nef_S2/include/CGAL/Nef_S2/SM_io_parser.h | 4 +- .../CGAL/test_FPU_rounding_mode_impl.h | 1 - Profiling_tools/include/CGAL/Real_timer.h | 10 +- .../include/CGAL/Real_timer_impl.h | 15 - Profiling_tools/include/CGAL/Timer.h | 10 +- Profiling_tools/include/CGAL/Timer_impl.h | 15 - Random_numbers/include/CGAL/Random.h | 11 + Random_numbers/include/CGAL/Random_impl.h | 11 - cppfiles.txt | 23 +- 17 files changed, 348 insertions(+), 362 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6d8ec962c36..4b4e2501871 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,7 +9,7 @@ else() cmake_minimum_required(VERSION 2.6.2) endif() -add_definitions(-DCGAL_HEADER_ONLY) +# add_definitions(-DCGAL_HEADER_ONLY) # option for branch build diff --git a/Generator/include/CGAL/generators.h b/Generator/include/CGAL/generators.h index b30c40433d1..0bdc224b7ed 100644 --- a/Generator/include/CGAL/generators.h +++ b/Generator/include/CGAL/generators.h @@ -68,7 +68,7 @@ protected: public: typedef Random_generator_base This; - Random_generator_base() : _rnd( get_default_random()) {} + Random_generator_base() : _rnd( CGAL::get_default_random() ) {} Random_generator_base( double range, Random& rnd) : Generator_base( range), _rnd( rnd) {} Random_generator_base( const T& item, double range, Random& rnd) @@ -83,7 +83,7 @@ class Random_double_in_interval : public Random_generator_base { public: typedef Random_double_in_interval This; - Random_double_in_interval(double a = 1, Random& rnd = get_default_random()) + Random_double_in_interval(double a = 1, Random& rnd = CGAL::get_default_random()) // g is an input iterator creating points of type `P' uniformly // distributed in the half-open square with side length a, // centered around the origin, i.e. \forall p = `*g': -\frac{a}{2} diff --git a/Generator/include/CGAL/point_generators_2.h b/Generator/include/CGAL/point_generators_2.h index 098c563b574..ec11cd98415 100644 --- a/Generator/include/CGAL/point_generators_2.h +++ b/Generator/include/CGAL/point_generators_2.h @@ -36,7 +36,7 @@ class Random_points_in_disc_2 : public Random_generator_base

{ void generate_point(); public: typedef Random_points_in_disc_2 This; - Random_points_in_disc_2( double r = 1, Random& rnd = get_default_random()) + Random_points_in_disc_2( double r = 1, Random& rnd = CGAL::get_default_random()) // g is an input iterator creating points of type `P' uniformly // distributed in the open disc with radius r, i.e. |`*g'| < r . // Two random numbers are needed from `rnd' for each point. @@ -71,7 +71,7 @@ class Random_points_on_circle_2 : public Random_generator_base

{ void generate_point(); public: typedef Random_points_on_circle_2 This; - Random_points_on_circle_2( double r = 1, Random& rnd = get_default_random()) + Random_points_on_circle_2( double r = 1, Random& rnd = CGAL::get_default_random()) // g is an input iterator creating points of type `P' uniformly // distributed on the circle with radius r, i.e. |`*g'| == r . A // single random number is needed from `rnd' for each point. @@ -105,7 +105,7 @@ class Random_points_in_square_2 : public Random_generator_base

{ void generate_point(); public: typedef Random_points_in_square_2 This; - Random_points_in_square_2( double a = 1, Random& rnd = get_default_random()) + Random_points_in_square_2( double a = 1, Random& rnd = CGAL::get_default_random()) // g is an input iterator creating points of type `P' uniformly // distributed in the half-open square with side length a, // centered around the origin, i.e. \forall p = `*g': -\frac{a}{2} @@ -141,7 +141,7 @@ class Random_points_on_square_2 : public Random_generator_base

{ void generate_point(); public: typedef Random_points_on_square_2 This; - Random_points_on_square_2( double a = 1, Random& rnd = get_default_random()) + Random_points_on_square_2( double a = 1, Random& rnd = CGAL::get_default_random()) // g is an input iterator creating points of type `P' uniformly // distributed on the boundary of the square with side length a, // centered around the origin, i.e. \forall p = `*g': one @@ -194,7 +194,7 @@ class Random_points_in_iso_rectangle_2 : public Random_generator_base

{ void generate_point(); public: typedef Random_points_in_iso_rectangle_2 This; - Random_points_in_iso_rectangle_2( const P&p, const P& q, Random& rnd = get_default_random()) + Random_points_in_iso_rectangle_2( const P&p, const P& q, Random& rnd = CGAL::get_default_random()) : Random_generator_base

( 1.0 , rnd) { left = (std::min)(to_double(p.x()), to_double(q.x())); @@ -238,7 +238,7 @@ public: typedef Random_points_on_segment_2 This; Random_points_on_segment_2( const P& p = P( -1, 0), const P& q = P( 1, 0), - Random& rnd = get_default_random()) + Random& rnd = CGAL::get_default_random()) // g is an input iterator creating points of type `P' uniformly // distributed on the segment from p to q except q, i.e. `*g' == // \lambda p + (1-\lambda)\, q where 0 <= \lambda < 1 . A single @@ -423,7 +423,7 @@ void perturb_points_2( ForwardIterator first, double xeps, double yeps) { - perturb_points_2( first, last, xeps, yeps, get_default_random()); + perturb_points_2( first, last, xeps, yeps, CGAL::get_default_random()); } template @@ -431,7 +431,7 @@ void perturb_points_2( ForwardIterator first, ForwardIterator last, double xeps) { - perturb_points_2( first, last, xeps, xeps, get_default_random()); + perturb_points_2( first, last, xeps, xeps, CGAL::get_default_random()); } template OutputIterator random_collinear_points_2( @@ -489,7 +489,7 @@ OutputIterator random_collinear_points_2( OutputIterator first2) { return random_collinear_points_2( first, last, n, first2, - get_default_random()); + CGAL::get_default_random()); } diff --git a/Generator/include/CGAL/point_generators_3.h b/Generator/include/CGAL/point_generators_3.h index e4806182e60..15cbb3ff01d 100644 --- a/Generator/include/CGAL/point_generators_3.h +++ b/Generator/include/CGAL/point_generators_3.h @@ -36,7 +36,7 @@ class Random_points_in_sphere_3 : public Random_generator_base

{ void generate_point(); public: typedef Random_points_in_sphere_3 This; - Random_points_in_sphere_3( double r = 1, Random& rnd = get_default_random()) + Random_points_in_sphere_3( double r = 1, Random& rnd = CGAL::get_default_random()) // g is an input iterator creating points of type `P' uniformly // distributed in the open sphere with radius r, i.e. |`*g'| < r . // Three random numbers are needed from `rnd' for each point @@ -75,7 +75,7 @@ class Random_points_on_sphere_3 : public Random_generator_base

{ void generate_point(); public: typedef Random_points_on_sphere_3 This; - Random_points_on_sphere_3( double r = 1, Random& rnd = get_default_random()) + Random_points_on_sphere_3( double r = 1, Random& rnd = CGAL::get_default_random()) // g is an input iterator creating points of type `P' uniformly // distributed on the sphere with radius r, i.e. |`*g'| == r . A // two random numbers are needed from `rnd' for each point. @@ -113,7 +113,7 @@ class Random_points_in_cube_3 : public Random_generator_base

{ void generate_point(); public: typedef Random_points_in_cube_3 This; - Random_points_in_cube_3( double a = 1, Random& rnd = get_default_random()) + Random_points_in_cube_3( double a = 1, Random& rnd = CGAL::get_default_random()) : Random_generator_base

( a, rnd) { generate_point(); } This& operator++() { generate_point(); diff --git a/Modular_arithmetic/include/CGAL/Modular_arithmetic/Residue_type.h b/Modular_arithmetic/include/CGAL/Modular_arithmetic/Residue_type.h index 6af77fd5329..0fa8b7be42d 100644 --- a/Modular_arithmetic/include/CGAL/Modular_arithmetic/Residue_type.h +++ b/Modular_arithmetic/include/CGAL/Modular_arithmetic/Residue_type.h @@ -32,73 +32,6 @@ namespace CGAL { -#ifdef CGAL_HAS_THREADS - -#ifdef CGAL_HEADER_ONLY -inline boost::thread_specific_ptr& get_static_prime_int_() -{ - static boost::thread_specific_ptr prime_int_; - return prime_int_; -} -inline boost::thread_specific_ptr& get_static_prime_() -{ - static boost::thread_specific_ptr prime_; - return prime_; -} -inline boost::thread_specific_ptr& get_static_prime_inv_() -{ - static boost::thread_specific_ptr prime_inv_; - return prime_inv_; -} -#else // CGAL_HEADER_ONLY -inline boost::thread_specific_ptr& get_static_prime_int_() -{ return Residue::prime_int_; } -inline boost::thread_specific_ptr& get_static_prime_() -{ return Residue::prime_; } -inline boost::thread_specific_ptr& get_static_prime_inv_() -{ return Residue::prime_inv_; } -#endif // CGAL_HEADER_ONLY - -#else // CGAL_HAS_THREADS - -#ifdef CGAL_HEADER_ONLY -inline int& get_static_prime_int() -{ - static int prime_int = 67111067; - return prime_int; -} -inline double& get_static_prime() -{ - static double prime = 67111067.0; - return prime; -} -inline double& get_static_prime_inv() -{ - static double prime_inv = 1/67111067.0; - return prime_inv; -} -#else // CGAL_HEADER_ONLY -inline int& get_static_prime_int() -{ return Residue::prime_int; } -inline double& get_static_prime() -{ return Residue::prime; } -inline double& get_static_prime_inv() -{ return Residue::prime_inv; } -#endif // CGAL_HEADER_ONLY - -#endif // CGAL_HAS_THREADS - -#ifdef CGAL_HEADER_ONLY -inline double& get_static_CST_CUT() -{ - static double CST_CUT = std::ldexp( 3., 51 ); - return CST_CUT; -} -#else // CGAL_HEADER_ONLY -inline double& get_static_CST_CUT() -{ return Residue::CST_CUT; } -#endif // CGAL_HEADER_ONLY - class Residue; Residue operator + (const Residue&); @@ -107,6 +40,20 @@ Residue operator - (const Residue&); std::ostream& operator << (std::ostream& os, const Residue& p); std::istream& operator >> (std::istream& is, Residue& p); +#ifdef CGAL_HAS_THREADS + +#ifdef CGAL_HEADER_ONLY +#else // CGAL_HEADER_ONLY +#endif // CGAL_HEADER_ONLY + +#else // CGAL_HAS_THREADS + +#ifdef CGAL_HEADER_ONLY +#else // CGAL_HEADER_ONLY +#endif // CGAL_HEADER_ONLY + +#endif // CGAL_HAS_THREADS + /*! \ingroup CGAL_Modular_traits * \brief This class represents the Field Z mod p. * @@ -127,16 +74,46 @@ public: typedef Residue NT; private: -#ifndef CGAL_HEADER_ONLY +#ifdef CGAL_HEADER_ONLY + static const double& get_static_CST_CUT() + { + static const double CST_CUT = std::ldexp( 3., 51 ); + return CST_CUT; + } +#else // CGAL_HEADER_ONLY CGAL_EXPORT static const double CST_CUT; + static const double& get_static_CST_CUT() + { return Residue::CST_CUT; } #endif // CGAL_HEADER_ONLY #ifdef CGAL_HAS_THREADS -#ifndef CGAL_HEADER_ONLY +#ifdef CGAL_HEADER_ONLY + static boost::thread_specific_ptr& get_static_prime_int_() + { + static boost::thread_specific_ptr prime_int_; + return prime_int_; + } + static boost::thread_specific_ptr& get_static_prime_() + { + static boost::thread_specific_ptr prime_; + return prime_; + } + static boost::thread_specific_ptr& get_static_prime_inv_() + { + static boost::thread_specific_ptr prime_inv_; + return prime_inv_; + } +#else // CGAL_HEADER_ONLY CGAL_EXPORT static boost::thread_specific_ptr prime_int_; CGAL_EXPORT static boost::thread_specific_ptr prime_; CGAL_EXPORT static boost::thread_specific_ptr prime_inv_; + static boost::thread_specific_ptr& get_static_prime_int_() + { return Residue::prime_int_; } + static boost::thread_specific_ptr& get_static_prime_() + { return Residue::prime_; } + static boost::thread_specific_ptr& get_static_prime_inv_() + { return Residue::prime_inv_; } #endif // CGAL_HEADER_ONLY static void init_class_for_thread(){ @@ -167,10 +144,33 @@ private: } #else // CGAL_HAS_THREADS -#ifndef CGAL_HEADER_ONLY +#ifdef CGAL_HEADER_ONLY + static int& get_static_prime_int() + { + static int prime_int = 67111067; + return prime_int; + } + static double& get_static_prime() + { + static double prime = 67111067.0; + return prime; + } + static double& get_static_prime_inv() + { + static double prime_inv = 1/67111067.0; + return prime_inv; + } + +#else // CGAL_EXPORT static int prime_int; CGAL_EXPORT static double prime; CGAL_EXPORT static double prime_inv; + static int& get_static_prime_int() + { return Residue::prime_int; } + static double& get_static_prime() + { return Residue::prime; } + static double& get_static_prime_inv() + { return Residue::prime_inv; } #endif // CGAL_HEADER_ONLY static int get_prime_int(){ return get_static_prime_int();} static double get_prime() { return get_static_prime();} diff --git a/Modular_arithmetic/include/CGAL/primes.h b/Modular_arithmetic/include/CGAL/primes.h index b9649b2427f..3dc47dd8263 100644 --- a/Modular_arithmetic/include/CGAL/primes.h +++ b/Modular_arithmetic/include/CGAL/primes.h @@ -28,7 +28,7 @@ namespace CGAL { namespace internal { #ifndef CGAL_HEADER_ONLY -CGAL_EXPORT extern int primes[2000]; +CGAL_EXPORT extern const int primes[2000]; #endif // CGAL_HEADER_ONLY static inline diff --git a/Nef_3/include/CGAL/Nef_3/Pluecker_line_3.h b/Nef_3/include/CGAL/Nef_3/Pluecker_line_3.h index b80beff7301..193d3c2543e 100644 --- a/Nef_3/include/CGAL/Nef_3/Pluecker_line_3.h +++ b/Nef_3/include/CGAL/Nef_3/Pluecker_line_3.h @@ -321,7 +321,7 @@ on their Pluecker coefficient tuples.}*/ template std::ostream& operator<<(std::ostream& os, const Pluecker_line_3& l) { - switch( os.iword(CGAL::IO::mode) ) { + switch( get_mode(os) ) { case CGAL::IO::ASCII : for (unsigned i=0; i<6; ++i) os << l[i] << " "; return os; diff --git a/Nef_3/include/CGAL/Nef_3/SNC_io_parser.h b/Nef_3/include/CGAL/Nef_3/SNC_io_parser.h index b15d1d8e985..6bea47f058e 100644 --- a/Nef_3/include/CGAL/Nef_3/SNC_io_parser.h +++ b/Nef_3/include/CGAL/Nef_3/SNC_io_parser.h @@ -14,7 +14,7 @@ // // $URL$ // $Id$ -// +// // // Author(s) : Michael Seel // Miguel Granados @@ -123,16 +123,16 @@ typename Type_converter::Vector_3 get_vector(const CGAL::Vector_3& v){ ret template class moreLeft : public T { - + typedef typename T::SM_decorator SM_decorator; typedef typename T::SHalfedge_handle SHalfedge_handle; typedef typename T::Vector_3 Vector_3; typedef typename T::FT FT; typedef typename T::RT RT; - + public: moreLeft(T D) : T(D) {} - + int operator()(SHalfedge_handle se1, SHalfedge_handle se2) { CGAL_assertion(se1 != SHalfedge_handle()); @@ -145,12 +145,12 @@ class moreLeft : public T { if(vec1 == vec2) return 0; - + if(vec1.x() == RT(0) && vec2.x() == RT(0)) { if(vec1.y() != vec2.y()) { if(vec1.y() < vec2.y()) return -1; - else + else return 1; } if(vec1.z() < vec2.z()) @@ -158,7 +158,7 @@ class moreLeft : public T { else return 1; } - + Vector_3 minus(-1,0,0); FT sk1(minus*vec1), sk2(minus*vec2); if((sk1 >= FT(0) && sk2 <= FT(0)) || @@ -172,11 +172,11 @@ class moreLeft : public T { FT len1 = vec1.x()*vec1.x()+vec1.y()*vec1.y()+vec1.z()*vec1.z(); FT len2 = vec2.x()*vec2.x()+vec2.y()*vec2.y()+vec2.z()*vec2.z(); FT diff = len1*sk2*sk2 - len2*sk1*sk1; - + if(diff != FT(0)) { if((sk1>FT(0) && diffFT(0))) return -1; - else + else return 1; } @@ -186,30 +186,30 @@ class moreLeft : public T { template class sort_vertices : public SNC_decorator { - + typedef T SNC_structure; typedef CGAL::SNC_decorator Base; typedef typename T::Vertex_handle Vertex_handle; typedef typename T::Point_3 Point_3; - + public: sort_vertices(T& D) : Base(D) {} - + bool operator() (Vertex_handle v1, Vertex_handle v2) const { return lexicographically_xyz_smaller(v1->point(), v2->point()); } }; - + template class sort_edges : public SNC_decorator { - - typedef T SNC_structure; + + typedef T SNC_structure; typedef CGAL::SNC_decorator Base; typedef typename T::Halfedge_handle Halfedge_handle; - + public: sort_edges(T& D) : Base(D) {} - + bool operator() (Halfedge_handle e1, Halfedge_handle e2) const { sort_vertices SORT(*this->sncp()); if(e1->source() != e2->source()) @@ -220,8 +220,8 @@ class sort_edges : public SNC_decorator { template class sort_facets : public SNC_decorator { - - typedef T SNC_structure; + + typedef T SNC_structure; typedef SNC_decorator Base; typedef typename T::Halffacet_handle Halffacet_handle; typedef typename T::SHalfedge_handle SHalfedge_handle; @@ -230,25 +230,25 @@ class sort_facets : public SNC_decorator { public: sort_facets(T& D) : Base(D) {} - + bool operator() (Halffacet_handle f1, Halffacet_handle f2) const { - + Plane_3 p1(f1->plane()); Plane_3 p2(f2->plane()); - + if(p1.d() != p2.d()) return p1.d() < p2.d(); else if(p1.a() != p2.a()) return p1.a() < p2.a(); else if(p1.b() != p2.b()) - return p1.b() < p2.b(); + return p1.b() < p2.b(); else if(p1.c() != p2.c()) - return p1.c() < p2.c(); + return p1.c() < p2.c(); SHalfedge_handle se1 = SHalfedge_handle(f1->facet_cycles_begin()); SHalfedge_handle se2 = SHalfedge_handle(f2->facet_cycles_begin()); - + sort_vertices SORT(*this->sncp()); if(se1->source()->source() != se2->source()->source()) return SORT(se1->source()->source(), se2->source()->source()); @@ -258,14 +258,14 @@ class sort_facets : public SNC_decorator { CGAL_assertion(se1->source()->source() != se2->source()->source()); return SORT(se1->source()->source(), se2->source()->source()); - + } }; template class sort_sedges : public SNC_decorator { - - typedef T SNC_structure; + + typedef T SNC_structure; typedef CGAL::SNC_decorator Base; typedef CGAL::SM_decorator SM_decorator; typedef typename T::Vertex_handle Vertex_handle; @@ -274,12 +274,12 @@ class sort_sedges : public SNC_decorator { public: sort_sedges(T& D) : Base(D) {} - + bool operator() (SHalfedge_handle se1, SHalfedge_handle se2) const { CGAL_NEF_TRACEN("sort sedges"); if(se1 == se2) return false; sort_vertices SORT(*this->sncp()); - CGAL_NEF_TRACEN(" center verices: " << se1->source()->source()->point() << + CGAL_NEF_TRACEN(" center verices: " << se1->source()->source()->point() << " , " << se2->source()->source()->point()); if(se1->source()->source() != se2->source()->source()) return SORT(se1->source()->source(),se2->source()->source()); @@ -291,23 +291,23 @@ class sort_sedges : public SNC_decorator { return vec1.a() < vec2.a(); else if(vec1.b() != vec2.b()) return vec1.b() < vec2.b(); - return vec1.c() < vec2.c(); + return vec1.c() < vec2.c(); } else return SORT(se1->source()->twin()->source(), se2->source()->twin()->source()); } - if(SORT(se1->twin()->source()->twin()->source(), + if(SORT(se1->twin()->source()->twin()->source(), se1->source()->twin()->source())) se1 = se1->twin(); - if(SORT(se2->twin()->source()->twin()->source(), + if(SORT(se2->twin()->source()->twin()->source(), se2->source()->twin()->source())) se2 = se2->twin(); - CGAL_NEF_TRACEN(" ssources " << se1->source()->twin()->source()->point() + CGAL_NEF_TRACEN(" ssources " << se1->source()->twin()->source()->point() << " , " << se2->source()->twin()->source()->point()); if(se1->source() != se2->source()) return SORT(se1->source()->twin()->source(), se2->source()->twin()->source()); - CGAL_NEF_TRACEN(" starget " << se1->twin()->source()->twin()->source()->point() << + CGAL_NEF_TRACEN(" starget " << se1->twin()->source()->twin()->source()->point() << " , " << se2->twin()->source()->twin()->source()->point()); if(se1->twin()->source()->twin()->source() != se2->twin()->source()->twin()->source()) return SORT(se1->twin()->source()->twin()->source(), se2->twin()->source()->twin()->source()); @@ -315,26 +315,26 @@ class sort_sedges : public SNC_decorator { CGAL_assertion(se1->circle() != se2->circle()); Sphere_circle vec1 = se1->circle(); Sphere_circle vec2 = se2->circle(); - + if(vec1.a() != vec2.a()) return vec1.a() < vec2.a(); else if(vec1.b() != vec2.b()) return vec1.b() < vec2.b(); - return vec1.c() < vec2.c(); + return vec1.c() < vec2.c(); } }; template class sort_sloops : public SNC_decorator { - - typedef T SNC_structure; + + typedef T SNC_structure; typedef CGAL::SNC_decorator Base; typedef typename T::SHalfloop_handle SHalfloop_handle; - + public: sort_sloops(T& D) : Base(D) {} - + bool operator() (SHalfloop_handle sl1, SHalfloop_handle sl2) const { if(sl1 == sl2) return false; sort_vertices SORTV(*this->sncp()); @@ -347,8 +347,8 @@ class sort_sloops : public SNC_decorator { template class sort_sface_cycle_entries : public SNC_decorator { - - typedef T SNC_structure; + + typedef T SNC_structure; typedef CGAL::SNC_decorator Base; typedef typename T::SM_decorator SM_decorator; typedef typename T::Object_handle Object_handle; @@ -358,10 +358,10 @@ class sort_sface_cycle_entries : public SNC_decorator { typedef typename T::SFace_handle SFace_handle; typedef typename T::Point_3 Point_3; typedef typename T::Vector_3 Vector_3; - + public: sort_sface_cycle_entries(T D) : Base(D) {} - + bool operator() (Object_handle o1, Object_handle o2) const { CGAL_NEF_TRACEN("sort sface cycles "); SVertex_handle sv1, sv2; @@ -370,10 +370,10 @@ class sort_sface_cycle_entries : public SNC_decorator { if(!CGAL::assign(se1,o1) && !CGAL::assign(sl1,o1) && !CGAL::assign(sv1,o1)) CGAL_error_msg("wrong handle"); - + if(!CGAL::assign(se2,o2) && !CGAL::assign(sl2,o2) && !CGAL::assign(sv2,o2)) - CGAL_error_msg("wrong handle"); - + CGAL_error_msg("wrong handle"); + if(se1 != SHalfedge_handle() && se2 == SHalfedge_handle()) return true; @@ -408,7 +408,7 @@ class sort_sface_cycle_entries : public SNC_decorator { else if(vec1.y() != vec2.y()) return vec1.y() < vec2.y(); else if(vec1.z() != vec2.z()) - return vec1.z() < vec2.z(); + return vec1.z() < vec2.z(); } CGAL_assertion(sv1 != SVertex_handle() && sv2 != SVertex_handle()); @@ -419,7 +419,7 @@ class sort_sface_cycle_entries : public SNC_decorator { template class sort_sfaces : public SNC_decorator { - + typedef T SNC_structure; typedef CGAL::SNC_decorator Base; typedef typename T::SM_decorator SM_decorator; @@ -432,16 +432,16 @@ class sort_sfaces : public SNC_decorator { typedef typename T::SFace_cycle_iterator SFace_cycle_iterator; typedef typename T::SHalfedge_around_sface_circulator SHalfedge_around_sface_circulator; - + public: sort_sfaces(T& D) : Base(D) {} bool operator() (SFace_handle sf1, SFace_handle sf2) const { CGAL_NEF_TRACEN("sort sfaces"); if(&*sf1 == &*sf2) return false; - + sort_vertices SORT(*this->sncp()); - + CGAL_NEF_TRACEN(" vertices " << sf1->center_vertex()->point() << " , " << sf2->center_vertex()->point()); if(sf1->center_vertex() != sf2->center_vertex()) return SORT(sf1->center_vertex(), sf2->center_vertex()); @@ -454,7 +454,7 @@ class sort_sfaces : public SNC_decorator { Vector_3 plus(1,0,0); SFace_cycle_iterator fc; - + CGAL_NEF_TRACEN(" sface 1"); SHalfedge_handle se1; @@ -464,7 +464,7 @@ class sort_sfaces : public SNC_decorator { SHalfedge_handle se(fc); SHalfedge_around_sface_circulator ec(se),ee(se); CGAL_For_all(ec,ee) { - CGAL_NEF_TRACEN(" " << ec->source()->point() << + CGAL_NEF_TRACEN(" " << ec->source()->point() << " | " << ec->circle().orthogonal_vector()); if(ml(ec, se1) == -1) se1 = ec; @@ -477,15 +477,15 @@ class sort_sfaces : public SNC_decorator { } CGAL_NEF_TRACEN(" sface 2"); - + SHalfedge_handle se2; SHalfloop_handle sl2; CGAL_forall_sface_cycles_of(fc,sf2) { if(fc.is_shalfedge()) { SHalfedge_handle se(fc); SHalfedge_around_sface_circulator ec(se),ee(se); - CGAL_For_all(ec,ee) { - CGAL_NEF_TRACEN(" " << ec->source()->point() << + CGAL_For_all(ec,ee) { + CGAL_NEF_TRACEN(" " << ec->source()->point() << " | " << ec->circle().orthogonal_vector()); if(ml(ec, se2) == -1) se2 = ec; @@ -496,15 +496,15 @@ class sort_sfaces : public SNC_decorator { else CGAL_assertion(fc.is_svertex()); } - - CGAL_NEF_TRACEN(" sedge cycles existing? " << (se1 != SHalfedge_handle()) + + CGAL_NEF_TRACEN(" sedge cycles existing? " << (se1 != SHalfedge_handle()) << " , " << (se2 != SHalfedge_handle())); if(se1 != SHalfedge_handle() && se2 == SHalfedge_handle()) return true; if(se1 == SHalfedge_handle() && se2 != SHalfedge_handle()) - return false; - + return false; + if(se1 == SHalfedge_handle() && se2 == SHalfedge_handle()) { Vector_3 vec1 = sl1->circle().orthogonal_vector(); Vector_3 vec2 = sl2->circle().orthogonal_vector(); @@ -514,14 +514,14 @@ class sort_sfaces : public SNC_decorator { else if(vec1.y() != vec2.y()) return vec1.y() < vec2.y(); else if(vec1.z() != vec2.z()) - return vec1.z() < vec2.z(); + return vec1.z() < vec2.z(); } - + CGAL_assertion(se1 != SHalfedge_handle() && se2 != SHalfedge_handle()); - CGAL_NEF_TRACEN(" minimal sedge in sface 1:" << se1->source()->point() << + CGAL_NEF_TRACEN(" minimal sedge in sface 1:" << se1->source()->point() << " , " << se1->circle().orthogonal_vector()); - CGAL_NEF_TRACEN(" minimal sedge in sface 2:" << se2->source()->point() << + CGAL_NEF_TRACEN(" minimal sedge in sface 2:" << se2->source()->point() << " , " << se2->circle().orthogonal_vector()); CGAL_NEF_TRACEN("result " << ml(se1,se2)); switch(ml(se1, se2)) { @@ -535,19 +535,19 @@ class sort_sfaces : public SNC_decorator { template class sort_volumes : public SNC_decorator { - + typedef T SNC_structure; typedef CGAL::SNC_decorator Base; typedef typename T::Volume_handle Volume_handle; typedef typename T::SFace_handle SFace_handle; - + public: sort_volumes(T& D) : Base(D) {} - + bool operator() (Volume_handle c1, Volume_handle c2) const { CGAL_NEF_TRACEN("sort volumes"); - SFace_handle sf1 = SFace_handle(c1->shells_begin()); - SFace_handle sf2 = SFace_handle(c2->shells_begin()); + SFace_handle sf1 = SFace_handle(c1->shells_begin()); + SFace_handle sf2 = SFace_handle(c2->shells_begin()); sort_sfaces SORT(*this->sncp()); return SORT(sf1, sf2); @@ -556,7 +556,7 @@ class sort_volumes : public SNC_decorator { template class sort_facet_cycle_entries : public T { - + typedef typename T::SNC_structure SNC_structure; typedef typename T::SM_decorator SM_decorator; typedef typename T::Object_handle Object_handle; @@ -565,21 +565,21 @@ class sort_facet_cycle_entries : public T { typedef typename T::SFace_handle SFace_handle; typedef typename T::Point_3 Point_3; typedef typename T::Vector_3 Vector_3; - + public: sort_facet_cycle_entries(T D) : T(D) {} - + bool operator() (Object_handle o1, Object_handle o2) const { - + SHalfedge_handle se1, se2; SHalfloop_handle sl1, sl2; - + if(!CGAL::assign(se1,o1) && !CGAL::assign(sl1,o1)) CGAL_error_msg("wrong handle"); - + if(!CGAL::assign(se2,o2) && !CGAL::assign(sl2,o2)) - CGAL_error_msg("wrong handle"); - + CGAL_error_msg("wrong handle"); + if(se1 != SHalfedge_handle() && se2 != SHalfedge_handle()) { sort_vertices SORT(*this->sncp()); return SORT(se1->source()->source(), se2->source()->source()); @@ -590,7 +590,7 @@ class sort_facet_cycle_entries : public T { if(se2 != SHalfedge_handle()) return false; - CGAL_assertion(sl1 != SHalfloop_handle() && + CGAL_assertion(sl1 != SHalfloop_handle() && sl2 != SHalfloop_handle()); SM_decorator SD(&*sl1->incident_sface()->center_vertex()); @@ -602,21 +602,21 @@ class sort_facet_cycle_entries : public T { else if(vec1.y() != vec2.y()) return vec1.y() < vec2.y(); else - return vec1.z() < vec2.z(); + return vec1.z() < vec2.z(); } }; template class sort_shell_entries : public T { - + typedef typename T::Object_handle Object_handle; typedef typename T::Shell_entry_iterator Shell_entry_iterator; typedef typename T::SFace_handle SFace_handle; typedef typename T::Point_3 Point_3; - + public: sort_shell_entries(T D) : T(D) {} - + bool operator() (Object_handle o1, Object_handle o2) const { SFace_handle sf1, sf2; CGAL::assign(sf1, o1); @@ -632,7 +632,7 @@ class sort_shell_entries : public T { template struct find_minimal_sface_of_shell : public SNC_decorator { - + typedef T SNC_structure; typedef CGAL::SNC_decorator Base; typedef typename T::Vertex_handle Vertex_handle; @@ -646,11 +646,11 @@ struct find_minimal_sface_of_shell : public SNC_decorator { SFace_visited_hash& Done; SFace_handle sf_min; sort_sfaces SORT; - - find_minimal_sface_of_shell(T& D, SFace_visited_hash& Vi) + + find_minimal_sface_of_shell(T& D, SFace_visited_hash& Vi) : Base(D), Done(Vi), SORT(D) {} - - void visit(SFace_handle h) { + + void visit(SFace_handle h) { Done[h]=true; if(sf_min == SFace_handle()) sf_min = h; @@ -659,7 +659,7 @@ struct find_minimal_sface_of_shell : public SNC_decorator { sf_min = h; } } - + void visit(Vertex_handle ) {} void visit(Halfedge_handle ) {} void visit(Halffacet_handle ) {} @@ -884,32 +884,32 @@ class SNC_io_parser : public SNC_decorator typedef typename SNC_structure::Infi_box Infi_box; typedef typename Infi_box::Standard_kernel Standard_kernel; public: - typedef typename SNC_structure::Vertex_iterator Vertex_iterator; + typedef typename SNC_structure::Vertex_iterator Vertex_iterator; typedef typename SNC_structure::Vertex_handle Vertex_handle; - typedef typename SNC_structure::Halfedge_iterator Halfedge_iterator; + typedef typename SNC_structure::Halfedge_iterator Halfedge_iterator; typedef typename SNC_structure::Halfedge_handle Halfedge_handle; - typedef typename SNC_structure::Halffacet_iterator Halffacet_iterator; + typedef typename SNC_structure::Halffacet_iterator Halffacet_iterator; typedef typename SNC_structure::Halffacet_handle Halffacet_handle; - typedef typename SNC_structure::Volume_iterator Volume_iterator; + typedef typename SNC_structure::Volume_iterator Volume_iterator; typedef typename SNC_structure::Volume_handle Volume_handle; - typedef typename SNC_structure::SVertex_iterator SVertex_iterator; + typedef typename SNC_structure::SVertex_iterator SVertex_iterator; typedef typename SNC_structure::SVertex_handle SVertex_handle; - typedef typename SNC_structure::SHalfedge_iterator SHalfedge_iterator; + typedef typename SNC_structure::SHalfedge_iterator SHalfedge_iterator; typedef typename SNC_structure::SHalfedge_handle SHalfedge_handle; - typedef typename SNC_structure::SFace_iterator SFace_iterator; + typedef typename SNC_structure::SFace_iterator SFace_iterator; typedef typename SNC_structure::SFace_handle SFace_handle; - typedef typename SNC_structure::SHalfloop_iterator SHalfloop_iterator; + typedef typename SNC_structure::SHalfloop_iterator SHalfloop_iterator; typedef typename SNC_structure::SHalfloop_handle SHalfloop_handle; - typedef typename SNC_structure::Object_iterator Object_iterator; + typedef typename SNC_structure::Object_iterator Object_iterator; typedef typename SNC_structure::Object_handle Object_handle; typedef typename SNC_structure::SFace_cycle_iterator SFace_cycle_iterator; typedef typename SNC_structure::Halffacet_cycle_iterator Halffacet_cycle_iterator; typedef typename SNC_structure::Shell_entry_iterator Shell_entry_iterator; - typedef typename SNC_structure::SHalfedge_around_svertex_circulator + typedef typename SNC_structure::SHalfedge_around_svertex_circulator SHalfedge_around_svertex_circulator; - typedef typename SNC_structure::SHalfedge_around_sface_circulator + typedef typename SNC_structure::SHalfedge_around_sface_circulator SHalfedge_around_sface_circulator; - typedef typename SNC_structure::SHalfedge_around_facet_circulator + typedef typename SNC_structure::SHalfedge_around_facet_circulator SHalfedge_around_facet_circulator; typedef typename SNC_structure::Point_3 Point_3; typedef typename SNC_structure::Plane_3 Plane_3; @@ -939,7 +939,7 @@ public: bool sorted; bool addInfiBox; - CGAL::Object_index VI; + CGAL::Object_index VI; CGAL::Object_index EI; CGAL::Object_index FI; CGAL::Object_index CI; @@ -957,7 +957,7 @@ public: std::vector Edge_of; std::vector Halffacet_of; std::vector Volume_of; - std::vector SVertex_of; + std::vector SVertex_of; std::vector SEdge_of; std::vector SLoop_of; std::vector SFace_of; @@ -965,22 +965,22 @@ public: public: SNC_io_parser(std::istream& is, SNC_structure& W); - SNC_io_parser(std::ostream& os, SNC_structure& W, + SNC_io_parser(std::ostream& os, SNC_structure& W, bool sort=false, bool reduce_ = false); std::string index(Vertex_iterator v) const - { return VI(v,verbose); } - std::string index(Halfedge_iterator e) const + { return VI(v,verbose); } + std::string index(Halfedge_iterator e) const { return EI(e,verbose); } - std::string index(Halffacet_iterator f) const + std::string index(Halffacet_iterator f) const { return FI(f,verbose); } - std::string index(Volume_iterator c) const + std::string index(Volume_iterator c) const { return CI(c,verbose); } - std::string index(SHalfedge_iterator e) const + std::string index(SHalfedge_iterator e) const { return SEI(e,verbose); } - std::string index(SHalfloop_iterator l) const + std::string index(SHalfloop_iterator l) const { return SLI(l,verbose); } - std::string index(SFace_iterator f) const + std::string index(SFace_iterator f) const { return SFI(f,verbose); } std::string index(Object_iterator o) const { if( o == 0 ) @@ -1050,44 +1050,44 @@ public: }; template -SNC_io_parser::SNC_io_parser(std::istream& is, SNC_structure& W) : - Base(W), in(is), out(std::cout) { +SNC_io_parser::SNC_io_parser(std::istream& is, SNC_structure& W) : + Base(W), in(is), out(std::cout) { W.clear(); CGAL_assertion(W.is_empty()); - verbose = false; + verbose = false; } template -SNC_io_parser::SNC_io_parser(std::ostream& os, SNC_structure& W, - bool sort, bool reduce_) : +SNC_io_parser::SNC_io_parser(std::ostream& os, SNC_structure& W, + bool sort, bool reduce_) : Base(W), in(std::cin), out(os), FI(W.halffacets_begin(),W.halffacets_end(),'F'), CI(W.volumes_begin(),W.volumes_end(),'C'), SEI(W.shalfedges_begin(),W.shalfedges_end(),'e'), SLI(W.shalfloops_begin(),W.shalfloops_end(),'l'), SFI(W.sfaces_begin(),W.sfaces_end(),'f'), - vn(W.number_of_vertices()), - en(W.number_of_halfedges()), + vn(W.number_of_vertices()), + en(W.number_of_halfedges()), fn(W.number_of_halffacets()), cn(W.number_of_volumes()), sen(W.number_of_shalfedges()), sln(W.number_of_shalfloops()), sfn(W.number_of_sfaces()) -{ - verbose = (out.iword(CGAL::IO::mode) != CGAL::IO::ASCII && - out.iword(CGAL::IO::mode) != CGAL::IO::BINARY); +{ + verbose = (get_mode(out) != CGAL::IO::ASCII && + get_mode(out) != CGAL::IO::BINARY); sorted = sort; reduce = reduce_; reduce = reduce && this->is_extended_kernel() && this->is_bounded(); sorted = sorted || reduce; - Vertex_iterator vi; + Vertex_iterator vi; CGAL_forall_vertices(vi, *this->sncp()) { VL.push_back(vi); if(sorted) { vi->point() = normalized(vi->point()); - if(vi->has_shalfloop() && + if(vi->has_shalfloop() && sort_sloops(*this->sncp())(vi->shalfloop()->twin(), vi->shalfloop())) vi->shalfloop() = vi->shalfloop()->twin(); @@ -1095,7 +1095,7 @@ SNC_io_parser::SNC_io_parser(std::ostream& os, SNC_structure& W, } if(sorted) { VL.sort(sort_vertices(*this->sncp())); - } + } if(reduce) for(int k=0; k<4; k++){ VL.pop_front(); VL.pop_back(); @@ -1104,9 +1104,9 @@ SNC_io_parser::SNC_io_parser(std::ostream& os, SNC_structure& W, typename std::list::iterator vl; for(vl = VL.begin(); vl != VL.end(); vl++) VI[*vl] = i++; - + SM_decorator SD; - Halfedge_iterator ei; + Halfedge_iterator ei; CGAL_forall_halfedges(ei, *this->sncp()) { EL.push_back(ei); if(sorted) { @@ -1133,12 +1133,12 @@ SNC_io_parser::SNC_io_parser(std::ostream& os, SNC_structure& W, for(el = EL.begin(); el != EL.end(); el++) EI[*el] = i++; - Halffacet_iterator fi; + Halffacet_iterator fi; CGAL_forall_halffacets(fi, *this->sncp()){ if(sorted) { sort_sedges sortSE(*this->sncp()); Halffacet_cycle_iterator fc; - for(fc = fi->facet_cycles_begin(); + for(fc = fi->facet_cycles_begin(); fc != fi->facet_cycles_end(); ++fc) { if(fc.is_shalfedge()) { SHalfedge_handle se(fc); @@ -1170,7 +1170,7 @@ SNC_io_parser::SNC_io_parser(std::ostream& os, SNC_structure& W, for(fl = FL.begin(); fl != FL.end(); fl++) FI[*fl] = i++; - SHalfedge_iterator sei; + SHalfedge_iterator sei; CGAL_forall_shalfedges(sei, *this->sncp()) { SEL.push_back(sei); if(sorted) @@ -1186,7 +1186,7 @@ SNC_io_parser::SNC_io_parser(std::ostream& os, SNC_structure& W, for(sel = SEL.begin(); sel != SEL.end(); sel++) SEI[*sel] = i++; - SHalfloop_iterator sli; + SHalfloop_iterator sli; CGAL_forall_shalfloops(sli, *this->sncp()) { SLL.push_back(sli); if(sorted) @@ -1198,7 +1198,7 @@ SNC_io_parser::SNC_io_parser(std::ostream& os, SNC_structure& W, for(sll = SLL.begin(); sll != SLL.end(); sll++) SLI[*sll] = i++; - SFace_iterator sfi; + SFace_iterator sfi; CGAL_forall_sfaces(sfi, *this->sncp()) { if(sorted) { SFace_cycle_iterator fc; @@ -1214,7 +1214,7 @@ SNC_io_parser::SNC_io_parser(std::ostream& os, SNC_structure& W, se->source()->twin()->source()->point())) se = cb; } - else + else if(lexicographically_xyz_smaller(cb->twin()->source()->twin()->source()->point(), se->twin()->source()->twin()->source()->point())) se = cb; @@ -1237,7 +1237,7 @@ SNC_io_parser::SNC_io_parser(std::ostream& os, SNC_structure& W, for(sfl = SFL.begin(); sfl != SFL.end(); sfl++) SFI[*sfl] = i++; - Volume_iterator ci; + Volume_iterator ci; CGAL::Unique_hash_map Done(false); find_minimal_sface_of_shell findMinSF(*this->sncp(),Done); CGAL_forall_volumes(ci, *this->sncp()) { @@ -1249,10 +1249,10 @@ SNC_io_parser::SNC_io_parser(std::ostream& os, SNC_structure& W, *it = make_object(findMinSF.minimal_sface()); } ci->shell_entry_objects().sort(sort_shell_entries((Base)*this)); - } + } CL.push_back(ci); } - + if(sorted) CL.sort(sort_volumes(*this->sncp())); if(reduce) CL.pop_front(); @@ -1273,9 +1273,9 @@ SNC_io_parser::SNC_io_parser(std::ostream& os, SNC_structure& W, template bool SNC_io_parser::check_sep(const char* sep) const { - char c; + char c; do in.get(c); while (isspace(c)); - while (*sep != '\0') { + while (*sep != '\0') { if (*sep != c) { in.putback(c); return false; @@ -1283,7 +1283,7 @@ bool SNC_io_parser::check_sep(const char* sep) const ++sep; in.get(c); } in.putback(c); - return true; + return true; } template @@ -1295,7 +1295,7 @@ bool SNC_io_parser::test_string(std::string s) const { template void SNC_io_parser::print() const -{ +{ out << "Selective Nef Complex" << std::endl; if(this->is_extended_kernel() && (!reduce || !this->is_bounded())) out << "extended" << std::endl; @@ -1309,46 +1309,46 @@ void SNC_io_parser::print() const out << "shalfloops " << SLL.size() << std::endl; out << "sfaces " << SFL.size() << std::endl; - if (verbose) + if (verbose) out << "/* Vertex: index { svs sve ses see sfs sfe sl," << " mark, point } */\n"; typename std::list::const_iterator v; for(v=VL.begin();v!=VL.end();v++) print_vertex(*v); - if (verbose) + if (verbose) out << "/* Edge: index { twin, source, isolated incident_object," << " mark } */\n"; typename std::list::const_iterator e; for(e=EL.begin();e!=EL.end();e++) print_edge(*e); - if (verbose) + if (verbose) out << "/* Facet: index { twin, fclist, ivlist, volume | plane } mark */\n"; typename std::list::const_iterator f; for(f=FL.begin();f!=FL.end();f++) print_facet(*f); - if (verbose) + if (verbose) out << "/* Volume: index { shlist } mark */\n"; typename std::list::const_iterator c; for(c=CL.begin();c!=CL.end();c++) print_volume(*c); - if (verbose) + if (verbose) out << "/* SEdge: index { twin, sprev, snext, source, sface," << " prev, next, facet } */\n"; typename std::list::const_iterator se; for(se=SEL.begin();se!=SEL.end();se++) print_sedge(*se); - if (verbose) + if (verbose) out << "/* SLoop: index { twin, sface, facet } */" << std::endl; typename std::list::const_iterator sl; for(sl=SLL.begin();sl!=SLL.end();sl++) print_sloop(*sl); - if (verbose) + if (verbose) out << "/* SFace: index { fclist, ivlist, sloop, volume } */" << std::endl; typename std::list::const_iterator sf; for(sf=SFL.begin();sf!=SFL.end();sf++) @@ -1359,13 +1359,13 @@ void SNC_io_parser::print() const template void SNC_io_parser::read() -{ - if ( !check_sep("Selective Nef Complex") ) +{ + if ( !check_sep("Selective Nef Complex") ) CGAL_error_msg("SNC_io_parser::read: no SNC header."); std::string kernel_type; in >> kernel_type; CGAL_assertion(kernel_type == "standard" || kernel_type == "extended"); - if ( !(check_sep("vertices") && (in >> vn)) ) + if ( !(check_sep("vertices") && (in >> vn)) ) CGAL_error_msg("SNC_io_parser::read: wrong vertex line."); if ( !(check_sep("halfedges") && (in >> en) && (en%2==0)) ) CGAL_error_msg("SNC_io_parser::read: wrong edge line."); @@ -1407,13 +1407,13 @@ void SNC_io_parser::read_items(int plus01) { if (!read_vertex(*vi)) CGAL_error_msg("SNC_io_parser::read: error in node line"); } - + typename std::vector::iterator ei; for(ei=Edge_of.begin(); ei!=Edge_of.end(); ++ei) { if (!read_edge(*ei)) CGAL_error_msg("SNC_io_parser::read: error in edge line"); } - + typedef typename std::vector::iterator vhf_iterator; vhf_iterator fi; for(fi=Halffacet_of.begin(); fi!=Halffacet_of.end(); ++fi) { @@ -1442,7 +1442,7 @@ void SNC_io_parser::read_items(int plus01) { } SNC_constructor C(*this->sncp()); - C.assign_indices(); + C.assign_indices(); } @@ -1452,17 +1452,17 @@ void SNC_io_parser::print_vertex(Vertex_handle v) const SM_decorator SD(&*v); out << index(v) << " { "; if(sorted) { - - output_sorted_indexes(v->svertices_begin(), + + output_sorted_indexes(v->svertices_begin(), v->svertices_end(), EI); - output_sorted_indexes(v->shalfedges_begin(), + output_sorted_indexes(v->shalfedges_begin(), v->shalfedges_end(), SEI); - output_sorted_indexes(v->sfaces_begin(), + output_sorted_indexes(v->sfaces_begin(), v->sfaces_end(), SFI); out << index(SD.shalfloop()) << " | "; } else { - out + out << index(v->svertices_begin()) << " " << index(v->svertices_last()) << ", " << index(v->shalfedges_begin()) << " " @@ -1473,7 +1473,7 @@ void SNC_io_parser::print_vertex(Vertex_handle v) const } if(reduce) { Geometry_io:: - print_point(out, Infi_box::standard_point(v->point())); + print_point(out, Infi_box::standard_point(v->point())); } else Geometry_io::print_point(out, v->point()); @@ -1492,7 +1492,7 @@ read_vertex(Vertex_handle vh) { in >> index; OK = OK && test_string("{"); vh->sncp() = this->sncp(); - + in >> index; vh->svertices_begin() = (index >= 0 ? Edge_of[index] : this->svertices_end()); in >> index; @@ -1515,12 +1515,12 @@ read_vertex(Vertex_handle vh) { in >> hx >> hy >> hz >> hw; vh->point() = Point_3(hx,hy,hz,hw); #else - vh->point() = + vh->point() = Geometry_io::template read_point(in); #endif OK = OK && test_string("}"); in >> vh->mark(); - + return OK; } @@ -1536,7 +1536,7 @@ void SNC_io_parser::print_edge(Halfedge_handle e) const if(reduce) { Standard_point sp = Infi_box::standard_point(e->point()); Geometry_io:: - print_vector(out, sp-CGAL::ORIGIN); + print_vector(out, sp-CGAL::ORIGIN); } else Geometry_io:: @@ -1557,10 +1557,10 @@ read_edge(Halfedge_handle eh) { bool OK = true; int index; typename K::RT hx,hy,hz,hw; - + in >> index; OK = OK && test_string("{"); - + in >> index; eh->twin() = Edge_of[index]; OK = OK && test_string(","); @@ -1571,7 +1571,7 @@ read_edge(Halfedge_handle eh) { if(index == 0) { in >> index; eh->out_sedge() = SEdge_of[index]; - } else { + } else { in >> index; eh->incident_sface() = SFace_of[index]; } @@ -1580,7 +1580,7 @@ read_edge(Halfedge_handle eh) { in >> hx >> hy >> hz >> hw; eh->point() = Sphere_point(hx,hy,hz); #else - eh->point() = + eh->point() = Geometry_io::template read_point(in); #endif OK = OK && test_string("}"); @@ -1592,9 +1592,9 @@ read_edge(Halfedge_handle eh) { template void SNC_io_parser::print_facet(Halffacet_handle f) const { // syntax: index { twin, fclist, ivlist, volume | plane } mark - out << index(f) << " { "; + out << index(f) << " { "; out << index(f->twin()) << ", "; - Halffacet_cycle_iterator it; + Halffacet_cycle_iterator it; CGAL_forall_facet_cycles_of(it,f) if ( it.is_shalfedge() ) out << index(SHalfedge_handle(it)) << ' '; out << ", "; @@ -1623,11 +1623,11 @@ read_facet(Halffacet_handle fh) { in >> index; OK = OK && test_string("{"); - + in >> index; fh->twin() = Halffacet_of[index]; OK = OK && test_string(","); - + in >> cc; while(isdigit(cc)) { in.putback(cc); @@ -1635,7 +1635,7 @@ read_facet(Halffacet_handle fh) { fh->boundary_entry_objects().push_back(make_object(SEdge_of[index])); in >> cc; } - + in >> cc; while(isdigit(cc)) { in.putback(cc); @@ -1643,7 +1643,7 @@ read_facet(Halffacet_handle fh) { fh->boundary_entry_objects().push_back(make_object(SLoop_of[index])); in >> cc; } - + in >> index; fh->incident_volume() = Volume_of[index+addInfiBox]; OK = OK && test_string("|"); @@ -1651,7 +1651,7 @@ read_facet(Halffacet_handle fh) { in >> a >> b >> c >> d; fh->plane() = Plane_3(a,b,c,d); #else - fh->plane() = + fh->plane() = Geometry_io:: template read_plane(in); #endif @@ -1664,9 +1664,9 @@ read_facet(Halffacet_handle fh) { template void SNC_io_parser::print_volume(Volume_handle c) const { // syntax: index { shlist } mark - out << index(c) << " { "; + out << index(c) << " { "; Shell_entry_iterator it; - CGAL_forall_shells_of(it,c) + CGAL_forall_shells_of(it,c) if(!reduce || Infi_box::is_standard(SFace_handle(it)->center_vertex()->point())) out << index(SFace_handle(it)) << ' '; out << "} " << c->mark() << std::endl; @@ -1679,10 +1679,10 @@ read_volume(Volume_handle ch) { bool OK = true; int index; char cc; - + in >> index; OK = OK && test_string("{"); - + in >> cc; while(isdigit(cc)) { in.putback(cc); @@ -1697,14 +1697,14 @@ read_volume(Volume_handle ch) { template void SNC_io_parser:: -print_sedge(SHalfedge_handle e) const { +print_sedge(SHalfedge_handle e) const { //index { twin, sprev, snext, source, sface, prev, next, facet | circle } mark out << index(e) << " { " - << index(e->twin()) << ", " + << index(e->twin()) << ", " << index(e->sprev()) << ", " << index(e->snext()) << ", " << index(e->source()) << ", " << index(e->incident_sface()) << ", " << index(e->prev()) << ", " << index(e->next()) << ", " - << index(e->facet()) + << index(e->facet()) << " | "; if(reduce) { Geometry_io:: @@ -1716,9 +1716,9 @@ print_sedge(SHalfedge_handle e) const { out << " } " << e->mark(); #ifdef CGAL_NEF_OUTPUT_INDEXES - out << " " << e->get_forward_index() + out << " " << e->get_forward_index() << " " << e->get_backward_index(); -#endif +#endif out << std::endl; } @@ -1730,10 +1730,10 @@ read_sedge(SHalfedge_handle seh) { bool OK = true; int index; typename K::RT a,b,c,d; - + in >> index; OK = OK && test_string("{"); - + in >> index; seh->twin() = SEdge_of[index]; OK = OK && test_string(","); @@ -1762,7 +1762,7 @@ read_sedge(SHalfedge_handle seh) { in >> a >> b >> c >> d; seh->circle() = Sphere_circle(Plane_3(a,b,c,d)); #else - seh->circle() = + seh->circle() = Geometry_io:: template read_plane(in); #endif @@ -1778,8 +1778,8 @@ print_sloop(SHalfloop_handle l) const { // syntax: index { twin, sface, facet | circle } mark out << index(l) << " { " << index(l->twin()) << ", " << index(l->incident_sface()) << ", " - << index(l->facet()) - << " | "; + << index(l->facet()) + << " | "; if(reduce) { Geometry_io:: print_plane(out, Infi_box::standard_plane(l->circle())); @@ -1802,7 +1802,7 @@ read_sloop(SHalfloop_handle slh) { in >> index; OK = OK && test_string("{"); - + in >> index; slh->twin() = SLoop_of[index]; OK = OK && test_string(","); @@ -1811,18 +1811,18 @@ read_sloop(SHalfloop_handle slh) { OK = OK && test_string(","); in >> index; slh->facet() = Halffacet_of[index]; - OK = OK && test_string("|"); + OK = OK && test_string("|"); #ifdef CGAL_NEF_NATURAL_COORDINATE_INPUT in >> a >> b >> c >> d; slh->circle() = Sphere_circle(Plane_3(a,b,c,d)); #else slh->circle() = Geometry_io:: - template read_plane(in); + template read_plane(in); #endif - OK = OK && test_string("}"); + OK = OK && test_string("}"); in >> slh->mark(); - + return OK; } @@ -1831,7 +1831,7 @@ void SNC_io_parser:: print_sface(SFace_handle f) const { // syntax: index { vertex, fclist, ivlist, sloop, volume } SM_decorator D(&*f->center_vertex()); - out << index(f) << " { " << index(f->center_vertex()) << ", "; + out << index(f) << " { " << index(f->center_vertex()) << ", "; SFace_cycle_iterator it; CGAL_forall_sface_cycles_of(it,f) if ( it.is_shalfedge() ) out << index(SHalfedge_handle(it)) << ' '; @@ -1854,11 +1854,11 @@ read_sface(SFace_handle sfh) { in >> index; OK = OK && test_string("{"); - + in >> index; sfh->center_vertex() = Vertex_of[index]; OK = OK && test_string(","); - + in >> cc; while(isdigit(cc)) { in.putback(cc); @@ -1868,7 +1868,7 @@ read_sface(SFace_handle sfh) { SD.link_as_face_cycle(SEdge_of[index],sfh); in >> cc; } - + in >> cc; while(isdigit(cc)) { in.putback(cc); @@ -1886,36 +1886,36 @@ read_sface(SFace_handle sfh) { this->sncp()->store_sm_boundary_item(SLoop_of[index], --(sfh->sface_cycles_end())); in >> cc; } - + in >> index; sfh->volume() = Volume_of[index+addInfiBox]; - OK = OK && test_string("}"); + OK = OK && test_string("}"); in >> sfh->mark(); - + return OK; } template void SNC_io_parser::print_local_graph(Vertex_handle v) const { SM_decorator D(&*v); - out << "Local Graph " + out << "Local Graph " << D.number_of_vertices() << " " << D.number_of_edges() << " " << D.number_of_loops() << " " << D.number_of_faces() << " " << std::endl; - if (verbose) + if (verbose) out << "/* index { twin, source, isolated incident_object, mark } */\n"; SVertex_iterator vit; CGAL_forall_svertices_of(vit,v) print_edge(vit); - if (verbose) + if (verbose) out << "/* index { twin, sprev, snext, source, sface," << " prev, next, facet } */\n"; SHalfedge_iterator eit; CGAL_forall_shalfedges_of(eit,v) print_sedge(eit); - if (verbose) + if (verbose) out << "/* index { twin, sface, facet } */" << std::endl; - if ( D.has_sloop() ) + if ( D.has_sloop() ) { print_sloop(D.loop()); print_sloop(twin(D.loop())); } - if (verbose) + if (verbose) out << "/* index { fclist, ivlist, sloop, volume } */" << std::endl; SFace_iterator fit; CGAL_forall_sfaces_of(fit,v) print_sface(fit); @@ -1945,10 +1945,10 @@ void SNC_io_parser::add_infi_box() { hy = i % 4 > 1 ? -1 : 1; hz = i > 3 ? -1 : 1; vh->point() = Infi_box::create_extended_point(hx, hy, hz); - vh->mark() = 1; + vh->mark() = 1; vh->sncp() = this->sncp(); } - + int seOff[3] = {0, 1, 3}; int twinIdx[24] = { 3, 7,14, 0,10,17, @@ -1958,14 +1958,14 @@ void SNC_io_parser::add_infi_box() { 12,22, 5, 21,13, 8, 18,16,11}; - + for(int i = 0; i < 24; ++i) { Halfedge_handle eh = Edge_of[en+i]; eh->twin() = Edge_of[en+twinIdx[i]]; eh->center_vertex() = Vertex_of[vn+(i/3)]; eh->out_sedge() = SEdge_of[sen+(i/3*6)+seOff[i%3]]; switch(i%3) { - case 0 : + case 0 : hx = i % 6 ? 1 : -1; hy = hz = 0; break; @@ -1981,7 +1981,7 @@ void SNC_io_parser::add_infi_box() { eh->point() = Sphere_point(hx,hy,hz); eh->mark() = 1; } - + int bnd[12] = {19, 18, 43, 42, 35, 34, 47, 46, 39, 38, 45, 44}; for(int i = 0; i < 12; ++i) { @@ -2005,11 +2005,11 @@ void SNC_io_parser::add_infi_box() { fh->plane() = Infi_box::create_extended_plane(hx,hy,hz,hw); fh->mark() = 1; } - + Volume_of[0]->shell_entry_objects().push_back(make_object(SFace_of[sfn])); Volume_of[0]->mark() = 0; Volume_of[1]->shell_entry_objects().push_front(make_object(SFace_of[sfn+1])); - + int sprevOff[6] = {4,3,0,5,2,1}; int snextOff[6] = {2,5,4,1,0,3}; int prevIdx[48] = {7,12,15,26,29,10, @@ -2040,10 +2040,10 @@ void SNC_io_parser::add_infi_box() { -1,-1,1,1,-1,-1, 1,-1,-1,-1,-1,1, -1,1,-1,1,1,1}; - + for(int i = 0; i < 48; ++i) { SHalfedge_handle seh = SEdge_of[sen+i]; - + seh->twin() = SEdge_of[sen+(i/2*2)+((i+1)%2)]; seh->sprev() = SEdge_of[sen+sprevOff[i%6]+(i/6*6)]; seh->snext() = SEdge_of[sen+snextOff[i%6]+(i/6*6)]; @@ -2067,14 +2067,14 @@ void SNC_io_parser::add_infi_box() { seh->circle() = Sphere_circle(Plane_3(RT(hx),RT(hy),RT(hz),RT(0))); seh->mark() = 1; } - + int volIdx[8] = {0,1,1,0,1,0,0,1}; - + for(int i = 0; i < 16; ++i) { SFace_handle sfh = SFace_of[sfn+i]; sfh->center_vertex() = Vertex_of[vn+(i/2)]; sfh->boundary_entry_objects().push_back(make_object(SEdge_of[sen+(i/2*6)+(i%2)])); - this->sncp()->store_sm_boundary_item(SEdge_of[sen+(i/2*6)+(i%2)], + this->sncp()->store_sm_boundary_item(SEdge_of[sen+(i/2*6)+(i%2)], --(sfh->sface_cycles_end())); int cIdx = i%2 ? 1-volIdx[i/2] : volIdx[i/2]; sfh->volume() = Volume_of[cIdx]; diff --git a/Nef_S2/include/CGAL/Nef_S2/SM_io_parser.h b/Nef_S2/include/CGAL/Nef_S2/SM_io_parser.h index a47380fa3e5..059cc498b30 100644 --- a/Nef_S2/include/CGAL/Nef_S2/SM_io_parser.h +++ b/Nef_S2/include/CGAL/Nef_S2/SM_io_parser.h @@ -157,8 +157,8 @@ SM_io_parser(std::ostream& iout, const Base& D) en(this->number_of_shalfedges()), ln(this->number_of_shalfloops()), fn(this->number_of_sfaces()) -{ verbose = (out.iword(CGAL::IO::mode) != CGAL::IO::ASCII && - out.iword(CGAL::IO::mode) != CGAL::IO::BINARY); +{ verbose = (get_mode(out) != CGAL::IO::ASCII && + get_mode(out) != CGAL::IO::BINARY); } diff --git a/Number_types/include/CGAL/test_FPU_rounding_mode_impl.h b/Number_types/include/CGAL/test_FPU_rounding_mode_impl.h index b407e2a91fa..306330bd7dd 100644 --- a/Number_types/include/CGAL/test_FPU_rounding_mode_impl.h +++ b/Number_types/include/CGAL/test_FPU_rounding_mode_impl.h @@ -39,7 +39,6 @@ struct Check_FPU_rounding_mode_is_restored { ~Check_FPU_rounding_mode_is_restored() { - std::cout<<"DELETE ~Check_FPU_rounding_mode_is_restored()"< #endif -#ifdef CGAL_HEADER_ONLY -namespace { -inline bool& get_static_realtimer_m_failed() -{ - static bool m_failed = false; - return m_failed; -} -} // namespace -#else // CGAL_HEADER_ONLY -namespace { -inline bool& get_static_realtimer_m_failed() -{ return Real_timer::m_failed; } -} // namespace -#endif // CGAL_HEADER_ONLY - namespace CGAL { // Member functions for Real_timer diff --git a/Profiling_tools/include/CGAL/Timer.h b/Profiling_tools/include/CGAL/Timer.h index 030ec7a62b7..ae111466c3f 100644 --- a/Profiling_tools/include/CGAL/Timer.h +++ b/Profiling_tools/include/CGAL/Timer.h @@ -48,8 +48,16 @@ private: int interv; bool running; -#ifndef CGAL_HEADER_ONLY +#ifdef CGAL_HEADER_ONLY + static bool& get_static_timer_m_failed() + { + static bool m_failed = false; + return m_failed; + } +#else // CGAL_HEADER_ONLY static bool m_failed; + static bool& get_static_timer_m_failed() + { return CGAL::Timer::m_failed; } #endif // CGAL_HEADER_ONLY double user_process_time() const; // in seconds diff --git a/Profiling_tools/include/CGAL/Timer_impl.h b/Profiling_tools/include/CGAL/Timer_impl.h index e85064416a1..e655a457ffb 100644 --- a/Profiling_tools/include/CGAL/Timer_impl.h +++ b/Profiling_tools/include/CGAL/Timer_impl.h @@ -57,21 +57,6 @@ // For the numerical limits #include -#ifdef CGAL_HEADER_ONLY -namespace { -inline bool& get_static_timer_m_failed() -{ - static bool m_failed = false; - return m_failed; -} -} // namespace -#else // CGAL_HEADER_ONLY -namespace { -inline bool& get_static_timer_m_failed() -{ return Timer::m_failed; } -} // namespace -#endif // CGAL_HEADER_ONLY - namespace CGAL { // Member functions for Timer diff --git a/Random_numbers/include/CGAL/Random.h b/Random_numbers/include/CGAL/Random.h index 22cddd1d164..913a0e688f6 100644 --- a/Random_numbers/include/CGAL/Random.h +++ b/Random_numbers/include/CGAL/Random.h @@ -228,6 +228,17 @@ public: CGAL_EXPORT extern Random default_random; #endif // CGAL_HEADER_ONLY +#ifdef CGAL_HEADER_ONLY +inline Random& get_default_random() +{ + static Random default_random; + return default_random; +} +#else // CGAL_HEADER_ONLY +inline Random& get_default_random() +{ return default_random; } +#endif // CGAL_HEADER_ONLY + } //namespace CGAL #ifdef CGAL_HEADER_ONLY diff --git a/Random_numbers/include/CGAL/Random_impl.h b/Random_numbers/include/CGAL/Random_impl.h index c620df02ab0..16cb9e0cbd3 100644 --- a/Random_numbers/include/CGAL/Random_impl.h +++ b/Random_numbers/include/CGAL/Random_impl.h @@ -33,17 +33,6 @@ namespace CGAL { -#ifdef CGAL_HEADER_ONLY -inline Random& get_default_random() -{ - static Random default_random; - return default_random; -} -#else // CGAL_HEADER_ONLY -inline Random& get_default_random() -{ return Random::default_random; } -#endif // CGAL_HEADER_ONLY - // Class implementation (continued) // ================================ diff --git a/cppfiles.txt b/cppfiles.txt index 35a9358f694..1ca924c42ce 100644 --- a/cppfiles.txt +++ b/cppfiles.txt @@ -1,16 +1,7 @@ -CGAL: - -Clement: - -#include "/home/gdamiand/sources/CGAL/Kinetic_data_structures/src/CGAL/JAMA_numeric_solver.cpp" -#include "/home/gdamiand/sources/CGAL/Kinetic_data_structures/src/CGAL/KDS_Log.cpp" -#include "/home/gdamiand/sources/CGAL/Kinetic_data_structures/src/CGAL/numeric_solvers_support.cpp" -#include "/home/gdamiand/sources/CGAL/Kinetic_data_structures/src/CGAL/Turkowski_numeric_solver.cpp" - -#include "/home/gdamiand/sources/CGAL/Modular_arithmetic/src/CGAL/Residue_type.cpp" - Guillaume +CGAL: + DONE #include "/home/gdamiand/sources/CGAL/STL_Extension/src/CGAL/assertions.cpp" // variables globales DONE #include "/home/gdamiand/sources/CGAL/Stream_support/src/CGAL/io.cpp" // variable statique de classe DONE #include "/home/gdamiand/sources/CGAL/Stream_support/src/CGAL/Color.cpp" // constantes globales @@ -21,6 +12,7 @@ DONE #include "/home/gdamiand/sources/CGAL/Profiling_tools/src/CGAL/Timer.cpp" / DONE #include "/home/gdamiand/sources/CGAL/Profiling_tools/src/CGAL/Real_timer.cpp" // variable statique de classe DONE #include "/home/gdamiand/sources/CGAL/Random_numbers/src/CGAL/Random.cpp" // variable globale; utilisée directement (donc pb pour header only) -> we need to replace the use of CGAL::default_random by CGAL::get_default_random(). DONE #include "/home/gdamiand/sources/CGAL/Modular_arithmetic/src/CGAL/primes.cpp" // constante globale +DONE #include "/home/gdamiand/sources/CGAL/Modular_arithmetic/src/CGAL/Residue_type.cpp" // variables globales (! version multi-thread !) DONE #include "/home/gdamiand/sources/CGAL/Geomview/src/CGAL/Geomview_stream.cpp" DONE #include "/home/gdamiand/sources/CGAL/Intersections_2/src/CGAL/Bbox_2_intersections.cpp" @@ -42,6 +34,15 @@ DONE #include "/home/gdamiand/sources/CGAL/GraphicsView/src/CGAL_Qt4/GraphicsVie DONE #include "/home/gdamiand/sources/CGAL/GraphicsView/src/CGAL_Qt4/DemosMainWindow.cpp" DONE #include "/home/gdamiand/sources/CGAL/GraphicsView/src/CGAL_Qt4/GraphicsViewNavigation.cpp" +Clement: + +CGAL: + +#include "/home/gdamiand/sources/CGAL/Kinetic_data_structures/src/CGAL/JAMA_numeric_solver.cpp" +#include "/home/gdamiand/sources/CGAL/Kinetic_data_structures/src/CGAL/KDS_Log.cpp" +#include "/home/gdamiand/sources/CGAL/Kinetic_data_structures/src/CGAL/numeric_solvers_support.cpp" +#include "/home/gdamiand/sources/CGAL/Kinetic_data_structures/src/CGAL/Turkowski_numeric_solver.cpp" + CGAL_Core: #include "/home/gdamiand/sources/CGAL/CGAL_Core/src/CGAL_Core/CoreIO.cpp" From f7cb6fc7e2265cad33b654a9f5371c254290497d Mon Sep 17 00:00:00 2001 From: Guillaume Damiand Date: Fri, 14 Nov 2014 17:28:42 +0100 Subject: [PATCH 19/30] add a missing impl file --- Modular_arithmetic/include/CGAL/primes_impl.h | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 Modular_arithmetic/include/CGAL/primes_impl.h diff --git a/Modular_arithmetic/include/CGAL/primes_impl.h b/Modular_arithmetic/include/CGAL/primes_impl.h new file mode 100644 index 00000000000..4ad0f262aa7 --- /dev/null +++ b/Modular_arithmetic/include/CGAL/primes_impl.h @@ -0,0 +1,29 @@ +// Copyright (c) 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 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$ +// +// Author(s) : Michael Hemmer + +#include + +namespace CGAL { +namespace internal { + +const int primes [2000] = { + 67111067,67111043,67111027,67111013,67110947,67110943,67110931,67110929,67110889,67110881,67110853,67110851,67110847,67110839,67110829,67110817,67110779,67110739,67110733,67110709,67110677,67110661,67110653,67110647,67110613,67110607,67110601,67110599,67110569,67110559,67110557,67110551,67110541,67110521,67110497,67110493,67110479,67110469,67110467,67110457,67110419,67110391,67110377,67110367,67110353,67110331,67110311,67110301,67110283,67110269,67110259,67110247,67110221,67110209,67110191,67110167,67110161,67110151,67110149,67110139,67110107,67110091,67110083,67110077,67110073,67110023,67110013,67110007,67109969,67109941,67109923,67109773,67109759,67109747,67109737,67109723,67109701,67109687,67109671,67109663,67109633,67109629,67109593,67109573,67109563,67109543,67109519,67109507,67109479,67109443,67109431,67109417,67109407,67109363,67109323,67109321,67109299,67109291,67109281,67109269,67109243,67109233,67109227,67109221,67109209,67109201,67109191,67109177,67109171,67109167,67109131,67109123,67109071,67109051,67109033,67109023,67108981,67108961,67108957,67108933,67108919,67108913,67108879,67108859,67108837,67108819,67108777,67108763,67108757,67108753,67108747,67108739,67108729,67108721,67108709,67108693,67108669,67108667,67108661,67108649,67108633,67108597,67108579,67108529,67108511,67108507,67108493,67108471,67108463,67108453,67108439,67108387,67108373,67108369,67108351,67108331,67108313,67108303,67108289,67108271,67108219,67108207,67108201,67108199,67108187,67108183,67108177,67108127,67108109,67108081,67108049,67108039,67108037,67108033,67108009,67108007,67108003,67107983,67107977,67107967,67107941,67107919,67107913,67107883,67107881,67107871,67107863,67107809,67107797,67107793,67107787,67107773,67107757,67107749,67107739,67107737,67107713,67107707,67107697,67107673,67107643,67107641,67107631,67107617,67107569,67107553,67107541,67107539,67107533,67107527,67107499,67107497,67107473,67107463,67107461,67107457,67107427,67107389,67107349,67107331,67107323,67107319,67107317,67107311,67107301,67107289,67107253,67107241,67107223,67107217,67107203,67107191,67107151,67107149,67107101,67107097,67107071,67107043,67106989,67106987,67106983,67106903,67106833,67106821,67106813,67106797,67106761,67106749,67106737,67106719,67106717,67106693,67106687,67106657,67106591,67106587,67106561,67106539,67106503,67106483,67106477,67106447,67106407,67106399,67106393,67106383,67106357,67106339,67106323,67106311,67106279,67106257,67106243,67106239,67106231,67106213,67106189,67106167,67106159,67106113,67106107,67106099,67106093,67106063,67106059,67106033,67106023,67105991,67105963,67105949,67105943,67105937,67105933,67105903,67105879,67105877,67105873,67105867,67105849,67105837,67105823,67105811,67105781,67105771,67105769,67105763,67105729,67105711,67105699,67105691,67105609,67105567,67105553,67105517,67105501,67105487,67105481,67105471,67105459,67105453,67105439,67105399,67105393,67105373,67105369,67105349,67105319,67105303,67105267,67105249,67105219,67105211,67105201,67105193,67105187,67105141,67105133,67105127,67105091,67105081,67105061,67104997,67104991,67104977,67104949,67104931,67104923,67104913,67104907,67104901,67104893,67104883,67104871,67104859,67104857,67104847,67104841,67104833,67104803,67104769,67104757,67104743,67104707,67104691,67104689,67104679,67104649,67104647,67104617,67104607,67104601,67104589,67104581,67104571,67104563,67104539,67104529,67104517,67104449,67104439,67104437,67104419,67104379,67104361,67104341,67104313,67104293,67104277,67104263,67104251,67104227,67104161,67104139,67104127,67104113,67104073,67104071,67104061,67104053,67104047,67104043,67104031,67104019,67104007,67103983,67103969,67103963,67103909,67103893,67103887,67103867,67103851,67103837,67103821,67103761,67103749,67103737,67103731,67103711,67103689,67103669,67103657,67103653,67103633,67103609,67103587,67103579,67103549,67103513,67103507,67103503,67103483,67103479,67103467,67103431,67103423,67103411,67103389,67103359,67103327,67103321,67103297,67103293,67103273,67103249,67103227,67103219,67103209,67103191,67103173,67103159,67103149,67103147,67103143,67103137,67103107,67103083,67103051,67103039,67103033,67103027,67103021,67103009,67102991,67102969,67102967,67102963,67102949,67102943,67102921,67102913,67102901,67102873,67102843,67102801,67102741,67102733,67102729,67102727,67102703,67102669,67102663,67102657,67102649,67102639,67102627,67102613,67102603,67102561,67102537,67102531,67102499,67102487,67102459,67102457,67102447,67102439,67102397,67102391,67102333,67102331,67102291,67102283,67102249,67102241,67102237,67102223,67102219,67102193,67102181,67102177,67102163,67102159,67102153,67102151,67102099,67102093,67102069,67102067,67102051,67102033,67102031,67102019,67102003,67101997,67101989,67101961,67101919,67101899,67101883,67101877,67101799,67101791,67101779,67101743,67101739,67101691,67101689,67101637,67101631,67101623,67101613,67101607,67101569,67101523,67101509,67101493,67101491,67101479,67101469,67101449,67101443,67101421,67101413,67101361,67101343,67101341,67101323,67101299,67101271,67101263,67101247,67101241,67101191,67101187,67101173,67101169,67101161,67101119,67101109,67101079,67101053,67101043,67100987,67100981,67100977,67100963,67100953,67100947,67100939,67100911,67100909,67100899,67100897,67100861,67100857,67100851,67100849,67100827,67100801,67100791,67100779,67100777,67100773,67100753,67100731,67100713,67100699,67100687,67100681,67100669,67100659,67100653,67100639,67100617,67100599,67100587,67100569,67100531,67100497,67100489,67100459,67100447,67100389,67100357,67100353,67100347,67100329,67100311,67100303,67100281,67100273,67100263,67100261,67100251,67100249,67100239,67100233,67100197,67100179,67100141,67100123,67100101,67100087,67100017,67100009,67099999,67099987,67099957,67099951,67099937,67099931,67099927,67099913,67099889,67099861,67099853,67099831,67099829,67099819,67099801,67099793,67099789,67099783,67099771,67099727,67099699,67099687,67099633,67099589,67099577,67099559,67099547,67099541,67099523,67099517,67099499,67099481,67099457,67099447,67099433,67099399,67099397,67099387,67099369,67099363,67099339,67099321,67099309,67099273,67099271,67099267,67099231,67099223,67099217,67099213,67099199,67099171,67099141,67099133,67099129,67099121,67099111,67099103,67099057,67099037,67099031,67098991,67098971,67098931,67098923,67098917,67098907,67098853,67098851,67098839,67098827,67098821,67098809,67098793,67098769,67098761,67098743,67098739,67098697,67098653,67098637,67098623,67098589,67098529,67098527,67098487,67098463,67098457,67098433,67098419,67098403,67098389,67098377,67098359,67098347,67098341,67098323,67098319,67098313,67098307,67098301,67098299,67098277,67098271,67098259,67098233,67098203,67098197,67098193,67098179,67098151,67098149,67098121,67098091,67098071,67098067,67098049,67098047,67098041,67098029,67098019,67098013,67098007,67098001,67097993,67097977,67097959,67097917,67097903,67097869,67097837,67097819,67097813,67097803,67097749,67097747,67097729,67097707,67097699,67097669,67097659,67097603,67097593,67097579,67097567,67097551,67097543,67097507,67097489,67097447,67097441,67097413,67097383,67097369,67097363,67097339,67097333,67097323,67097321,67097297,67097291,67097281,67097273,67097269,67097267,67097209,67097183,67097179,67097123,67097111,67097087,67097081,67097053,67097047,67096987,67096979,67096973,67096921,67096919,67096907,67096903,67096867,67096837,67096817,67096769,67096751,67096717,67096703,67096697,67096693,67096669,67096663,67096649,67096613,67096607,67096583,67096559,67096553,67096507,67096499,67096487,67096483,67096439,67096423,67096411,67096409,67096387,67096373,67096327,67096319,67096303,67096301,67096291,67096261,67096247,67096243,67096231,67096223,67096177,67096151,67096109,67096103,67096097,67096069,67096067,67096063,67096031,67096021,67096013,67096009,67095989,67095983,67095971,67095929,67095893,67095883,67095869,67095857,67095851,67095799,67095797,67095737,67095733,67095731,67095703,67095701,67095683,67095667,67095659,67095629,67095607,67095559,67095551,67095529,67095521,67095499,67095493,67095487,67095421,67095419,67095407,67095383,67095359,67095349,67095317,67095239,67095227,67095221,67095211,67095199,67095173,67095143,67095139,67095131,67095101,67095079,67095047,67095043,67095037,67095013,67095011,67095001,67094987,67094981,67094969,67094941,67094917,67094899,67094891,67094837,67094831,67094827,67094821,67094809,67094759,67094743,67094723,67094717,67094711,67094707,67094701,67094647,67094639,67094593,67094591,67094581,67094557,67094527,67094513,67094507,67094501,67094497,67094471,67094459,67094437,67094411,67094407,67094389,67094369,67094353,67094351,67094329,67094311,67094309,67094299,67094297,67094281,67094267,67094179,67094177,67094173,67094161,67094143,67094141,67094123,67094119,67094099,67094047,67094039,67094021,67094011,67093993,67093979,67093937,67093933,67093931,67093903,67093861,67093853,67093843,67093841,67093801,67093759,67093757,67093723,67093721,67093699,67093681,67093633,67093627,67093619,67093613,67093603,67093597,67093591,67093547,67093519,67093489,67093471,67093409,67093381,67093349,67093319,67093307,67093303,67093297,67093291,67093267,67093249,67093223,67093183,67093181,67093171,67093163,67093157,67093129,67093121,67093109,67093087,67093079,67093069,67093043,67093031,67093007,67093003,67092997,67092953,67092947,67092911,67092887,67092871,67092869,67092847,67092841,67092821,67092811,67092787,67092757,67092749,67092737,67092721,67092709,67092691,67092673,67092671,67092643,67092637,67092611,67092607,67092589,67092563,67092539,67092521,67092511,67092491,67092461,67092451,67092419,67092407,67092391,67092367,67092331,67092323,67092301,67092271,67092247,67092227,67092203,67092199,67092197,67092143,67092139,67092133,67092119,67092107,67092079,67092071,67092041,67092017,67092001,67091987,67091939,67091933,67091923,67091903,67091873,67091861,67091839,67091833,67091821,67091807,67091803,67091797,67091779,67091771,67091743,67091737,67091729,67091683,67091681,67091677,67091669,67091617,67091611,67091561,67091551,67091543,67091501,67091491,67091477,67091467,67091447,67091443,67091441,67091417,67091407,67091369,67091357,67091351,67091341,67091329,67091317,67091291,67091287,67091251,67091243,67091203,67091159,67091149,67091131,67091113,67091107,67091077,67091041,67091039,67091029,67090999,67090979,67090973,67090939,67090937,67090921,67090871,67090861,67090841,67090783,67090769,67090763,67090759,67090711,67090703,67090693,67090679,67090631,67090627,67090613,67090591,67090589,67090579,67090571,67090567,67090561,67090553,67090549,67090547,67090523,67090519,67090489,67090459,67090451,67090433,67090411,67090403,67090399,67090351,67090343,67090321,67090307,67090271,67090259,67090237,67090229,67090223,67090217,67090207,67090189,67090171,67090151,67090129,67090117,67090099,67090091,67090073,67090061,67090043,67090033,67090031,67090027,67090013,67089989,67089949,67089943,67089907,67089877,67089857,67089839,67089829,67089811,67089809,67089793,67089751,67089739,67089733,67089721,67089707,67089697,67089683,67089619,67089587,67089577,67089541,67089527,67089511,67089479,67089469,67089461,67089377,67089329,67089299,67089287,67089283,67089277,67089271,67089241,67089233,67089223,67089221,67089199,67089097,67089059,67089049,67089047,67089013,67088993,67088969,67088963,67088951,67088939,67088911,67088873,67088849,67088839,67088821,67088797,67088779,67088731,67088719,67088717,67088713,67088711,67088683,67088657,67088653,67088627,67088621,67088603,67088597,67088573,67088561,67088521,67088509,67088501,67088473,67088453,67088429,67088393,67088383,67088381,67088347,67088323,67088311,67088303,67088291,67088279,67088267,67088257,67088249,67088209,67088159,67088149,67088117,67088101,67088093,67088081,67088071,67088059,67088039,67088023,67088011,67087981,67087973,67087961,67087957,67087913,67087901,67087883,67087873,67087871,67087859,67087799,67087781,67087777,67087747,67087723,67087717,67087693,67087681,67087679,67087649,67087637,67087591,67087583,67087571,67087567,67087547,67087529,67087519,67087487,67087483,67087463,67087459,67087451,67087421,67087417,67087381,67087367,67087351,67087277,67087259,67087249,67087243,67087217,67087201,67087187,67087177,67087171,67087127,67087123,67087103,67087087,67087039,67087019,67086983,67086979,67086961,67086949,67086937,67086931,67086917,67086893,67086871,67086869,67086839,67086827,67086823,67086793,67086757,67086727,67086673,67086671,67086667,67086647,67086637,67086629,67086623,67086611,67086589,67086559,67086521,67086457,67086433,67086421,67086391,67086361,67086347,67086337,67086323,67086317,67086311,67086307,67086293,67086281,67086259,67086211,67086191,67086137,67086109,67086083,67086067,67086053,67086049,67086043,67086013,67086007,67086001,67085959,67085939,67085933,67085923,67085911,67085899,67085869,67085867,67085861,67085849,67085839,67085831,67085819,67085813,67085803,67085801,67085783,67085771,67085761,67085741,67085731,67085701,67085677,67085657,67085647,67085639,67085617,67085609,67085569,67085533,67085531,67085527,67085521,67085453,67085443,67085437,67085429,67085401,67085377,67085357,67085353,67085351,67085341,67085303,67085287,67085267,67085261,67085233,67085191,67085189,67085173,67085171,67085159,67085119,67085101,67085099,67085093,67085059,67085047,67085003,67084993,67084981,67084973,67084931,67084891,67084879,67084861,67084817,67084807,67084799,67084793,67084789,67084783,67084781,67084777,67084757,67084753,67084751,67084723,67084709,67084681,67084679,67084657,67084643,67084639,67084637,67084609,67084603,67084553,67084547,67084517,67084513,67084483,67084477,67084471,67084447,67084439,67084427,67084417,67084387,67084349,67084333,67084331,67084313,67084309,67084289,67084267,67084247,67084189,67084187,67084177,67084141,67084139,67084111,67084097,67084081,67084049,67084033,67084013,67084001,67083977,67083959,67083943,67083937,67083901,67083883,67083871,67083859,67083829,67083811,67083803,67083799,67083787,67083781,67083773,67083769,67083761,67083739,67083727,67083707,67083703,67083697,67083689,67083631,67083629,67083619,67083613,67083589,67083539,67083521,67083517,67083481,67083461,67083451,67083437,67083371,67083323,67083239,67083221,67083217,67083209,67083199,67083197,67083193,67083113,67083097,67083067,67083043,67083041,67083017,67082989,67082987,67082963,67082933,67082909,67082891,67082861,67082857,67082843,67082831,67082809,67082801,67082783,67082779,67082753,67082707,67082699,67082689,67082671,67082657,67082599,67082579,67082557,67082551,67082549,67082531,67082503,67082497,67082453,67082417,67082399,67082383,67082363,67082341,67082339,67082321,67082311,67082251,67082231,67082227,67082189,67082159,67082143,67082131,67082129,67082123,67082101,67082083,67082023,67082003,67081957,67081919,67081897,67081871,67081841,67081829,67081811,67081787,67081783,67081771,67081769,67081759,67081741,67081733,67081717,67081709,67081697,67081691,67081687,67081681,67081661,67081633,67081631,67081621,67081603,67081601,67081583,67081579,67081577,67081537,67081529,67081499,67081477,67081459,67081429,67081423,67081393,67081351,67081319,67081309,67081283,67081249,67081243,67081237,67081219,67081213,67081211,67081159,67081139,67081127,67081123,67081103,67081097,67081073,67081057,67081051,67080977,67080971,67080967,67080947,67080917,67080859,67080833,67080823,67080821,67080803,67080781,67080763,67080757,67080751,67080737,67080709,67080701,67080679,67080653,67080647,67080631,67080557,67080553,67080527,67080491,67080479,67080439,67080437,67080413,67080367,67080361,67080353,67080337,67080329,67080323,67080319,67080287,67080281,67080271,67080217,67080191,67080179,67080173,67080157,67080131,67080107,67080073,67080061,67080047,67080037,67080031,67080023,67079993,67079989,67079981,67079963,67079941,67079933,67079917,67079911,67079869,67079863,67079849,67079839,67079801,67079791,67079777,67079767,67079759,67079737,67079711,67079693,67079657,67079647,67079641,67079599,67079591,67079587,67079497,67079491,67079489,67079473,67079461,67079459,67079449,67079437,67079429,67079423,67079393,67079359,67079351,67079347,67079333,67079323,67079317,67079303,67079281,67079267,67079249,67079237,67079219,67079213,67079209,67079203,67079197,67079179,67079153,67079149,67079141,67079123,67079107,67079087,67079083,67079081,67079053,67079041,67079027,67079021,67078981,67078961,67078931,67078919,67078903,67078877,67078871,67078819,67078813,67078807,67078801,67078793,67078789,67078777,67078763,67078703,67078673,67078643,67078577,67078573,67078553,67078519,67078483,67078469,67078463,67078433,67078423,67078391,67078387,67078369,67078367,67078343,67078331,67078309,67078301,67078289,67078283,67078217,67078213,67078199,67078181,67078171,67078169,67078159,67078153,67078147,67078139,67078133,67078127,67078117,67078069,67078061,67078013,67078007,67078001,67077991,67077947,67077931,67077917,67077877,67077859,67077851,67077827,67077811,67077799,67077797,67077793,67077761,67077757,67077737,67077719,67077697,67077643,67077623,67077611,67077607,67077553,67077541,67077539,67077523,67077511,67077503,67077497,67077473,67077469,67077449,67077419,67077403,67077379,67077349,67077341,67077313,67077301,67077299,67077293,67077287,67077259,67077217,67077181,67077173,67077169,67077167,67077161,67077133,67077103,67077079,67077071,67077047,67077007,67077001,67076953,67076929,67076927,67076903,67076899,67076887,67076879,67076869,67076857,67076851,67076843,67076833,67076803,67076773,67076741,67076729,67076693,67076683,67076677,67076663,67076651,67076629,67076627,67076599,67076573,67076549,67076539,67076519,67076497,67076489,67076413,67076411,67076389,67076371,67076357,67076353,67076351,67076341,67076291,67076279,67076263,67076231,67076189,67076147,67076117,67076077,67076071,67076069,67076057,67076039,67076029,67075993,67075991,67075973,67075963,67075949,67075937,67075933,67075913,67075907,67075873,67075867,67075849,67075837,67075823,67075787,67075781,67075769,67075747,67075741,67075699,67075691,67075669,67075663,67075649,67075639,67075633,67075621,67075609,67075607,67075601,67075583,67075577,67075573,67075531 }; + +} // namespace internal +} // namespace CGAL From 6ebeb41dbf4c37e04a14fba03eb43b6733139e4c Mon Sep 17 00:00:00 2001 From: Guillaume Damiand Date: Sat, 15 Nov 2014 16:51:19 +0100 Subject: [PATCH 20/30] Add missing include --- Modular_arithmetic/src/CGAL/Residue_type.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/Modular_arithmetic/src/CGAL/Residue_type.cpp b/Modular_arithmetic/src/CGAL/Residue_type.cpp index e8c18870375..e41a63a907b 100644 --- a/Modular_arithmetic/src/CGAL/Residue_type.cpp +++ b/Modular_arithmetic/src/CGAL/Residue_type.cpp @@ -19,6 +19,7 @@ #ifndef CGAL_HEADER_ONLY +#include #include namespace CGAL{ From 87968c0b6eeb1c03b2235e0853d621a6f91f45c6 Mon Sep 17 00:00:00 2001 From: Guillaume Damiand Date: Sat, 15 Nov 2014 18:23:55 +0100 Subject: [PATCH 21/30] Keep non const version for non header version (TRANSLATION, ROTATION, SCALING, REFLECTION, IDENTITY and primes) --- Kernel_23/include/CGAL/aff_transformation_tags.h | 10 +++++----- .../include/CGAL/aff_transformation_tags_impl.h | 12 ++++++++++++ Modular_arithmetic/include/CGAL/primes.h | 2 +- Modular_arithmetic/include/CGAL/primes_impl.h | 6 +++++- 4 files changed, 23 insertions(+), 7 deletions(-) diff --git a/Kernel_23/include/CGAL/aff_transformation_tags.h b/Kernel_23/include/CGAL/aff_transformation_tags.h index 788269938ec..ea25f0bf3ab 100644 --- a/Kernel_23/include/CGAL/aff_transformation_tags.h +++ b/Kernel_23/include/CGAL/aff_transformation_tags.h @@ -38,11 +38,11 @@ class Identity_transformation {}; #ifndef CGAL_HEADER_ONLY -CGAL_EXPORT extern const Translation TRANSLATION; -CGAL_EXPORT extern const Rotation ROTATION; -CGAL_EXPORT extern const Scaling SCALING; -CGAL_EXPORT extern const Reflection REFLECTION; -CGAL_EXPORT extern const Identity_transformation IDENTITY; +CGAL_EXPORT extern Translation TRANSLATION; +CGAL_EXPORT extern Rotation ROTATION; +CGAL_EXPORT extern Scaling SCALING; +CGAL_EXPORT extern Reflection REFLECTION; +CGAL_EXPORT extern Identity_transformation IDENTITY; #endif diff --git a/Kernel_23/include/CGAL/aff_transformation_tags_impl.h b/Kernel_23/include/CGAL/aff_transformation_tags_impl.h index 4d4fdf2b8a0..5194c5f4645 100644 --- a/Kernel_23/include/CGAL/aff_transformation_tags_impl.h +++ b/Kernel_23/include/CGAL/aff_transformation_tags_impl.h @@ -24,10 +24,22 @@ namespace CGAL { +#ifdef CGAL_HEADER_ONLY + const Translation TRANSLATION; const Rotation ROTATION; const Scaling SCALING; const Reflection REFLECTION; const Identity_transformation IDENTITY; +#else // CGAL_HEADER_ONLY + +Translation TRANSLATION; +Rotation ROTATION; +Scaling SCALING; +Reflection REFLECTION; +Identity_transformation IDENTITY; + +#endif // CGAL_HEADER_ONLY + } //namespace CGAL diff --git a/Modular_arithmetic/include/CGAL/primes.h b/Modular_arithmetic/include/CGAL/primes.h index 3dc47dd8263..b9649b2427f 100644 --- a/Modular_arithmetic/include/CGAL/primes.h +++ b/Modular_arithmetic/include/CGAL/primes.h @@ -28,7 +28,7 @@ namespace CGAL { namespace internal { #ifndef CGAL_HEADER_ONLY -CGAL_EXPORT extern const int primes[2000]; +CGAL_EXPORT extern int primes[2000]; #endif // CGAL_HEADER_ONLY static inline diff --git a/Modular_arithmetic/include/CGAL/primes_impl.h b/Modular_arithmetic/include/CGAL/primes_impl.h index 4ad0f262aa7..5c1821bcb89 100644 --- a/Modular_arithmetic/include/CGAL/primes_impl.h +++ b/Modular_arithmetic/include/CGAL/primes_impl.h @@ -22,7 +22,11 @@ namespace CGAL { namespace internal { -const int primes [2000] = { +#ifdef CGAL_HEADER_ONLY +const +#endif // CGAL_HEADER_ONLY + +int primes [2000] = { 67111067,67111043,67111027,67111013,67110947,67110943,67110931,67110929,67110889,67110881,67110853,67110851,67110847,67110839,67110829,67110817,67110779,67110739,67110733,67110709,67110677,67110661,67110653,67110647,67110613,67110607,67110601,67110599,67110569,67110559,67110557,67110551,67110541,67110521,67110497,67110493,67110479,67110469,67110467,67110457,67110419,67110391,67110377,67110367,67110353,67110331,67110311,67110301,67110283,67110269,67110259,67110247,67110221,67110209,67110191,67110167,67110161,67110151,67110149,67110139,67110107,67110091,67110083,67110077,67110073,67110023,67110013,67110007,67109969,67109941,67109923,67109773,67109759,67109747,67109737,67109723,67109701,67109687,67109671,67109663,67109633,67109629,67109593,67109573,67109563,67109543,67109519,67109507,67109479,67109443,67109431,67109417,67109407,67109363,67109323,67109321,67109299,67109291,67109281,67109269,67109243,67109233,67109227,67109221,67109209,67109201,67109191,67109177,67109171,67109167,67109131,67109123,67109071,67109051,67109033,67109023,67108981,67108961,67108957,67108933,67108919,67108913,67108879,67108859,67108837,67108819,67108777,67108763,67108757,67108753,67108747,67108739,67108729,67108721,67108709,67108693,67108669,67108667,67108661,67108649,67108633,67108597,67108579,67108529,67108511,67108507,67108493,67108471,67108463,67108453,67108439,67108387,67108373,67108369,67108351,67108331,67108313,67108303,67108289,67108271,67108219,67108207,67108201,67108199,67108187,67108183,67108177,67108127,67108109,67108081,67108049,67108039,67108037,67108033,67108009,67108007,67108003,67107983,67107977,67107967,67107941,67107919,67107913,67107883,67107881,67107871,67107863,67107809,67107797,67107793,67107787,67107773,67107757,67107749,67107739,67107737,67107713,67107707,67107697,67107673,67107643,67107641,67107631,67107617,67107569,67107553,67107541,67107539,67107533,67107527,67107499,67107497,67107473,67107463,67107461,67107457,67107427,67107389,67107349,67107331,67107323,67107319,67107317,67107311,67107301,67107289,67107253,67107241,67107223,67107217,67107203,67107191,67107151,67107149,67107101,67107097,67107071,67107043,67106989,67106987,67106983,67106903,67106833,67106821,67106813,67106797,67106761,67106749,67106737,67106719,67106717,67106693,67106687,67106657,67106591,67106587,67106561,67106539,67106503,67106483,67106477,67106447,67106407,67106399,67106393,67106383,67106357,67106339,67106323,67106311,67106279,67106257,67106243,67106239,67106231,67106213,67106189,67106167,67106159,67106113,67106107,67106099,67106093,67106063,67106059,67106033,67106023,67105991,67105963,67105949,67105943,67105937,67105933,67105903,67105879,67105877,67105873,67105867,67105849,67105837,67105823,67105811,67105781,67105771,67105769,67105763,67105729,67105711,67105699,67105691,67105609,67105567,67105553,67105517,67105501,67105487,67105481,67105471,67105459,67105453,67105439,67105399,67105393,67105373,67105369,67105349,67105319,67105303,67105267,67105249,67105219,67105211,67105201,67105193,67105187,67105141,67105133,67105127,67105091,67105081,67105061,67104997,67104991,67104977,67104949,67104931,67104923,67104913,67104907,67104901,67104893,67104883,67104871,67104859,67104857,67104847,67104841,67104833,67104803,67104769,67104757,67104743,67104707,67104691,67104689,67104679,67104649,67104647,67104617,67104607,67104601,67104589,67104581,67104571,67104563,67104539,67104529,67104517,67104449,67104439,67104437,67104419,67104379,67104361,67104341,67104313,67104293,67104277,67104263,67104251,67104227,67104161,67104139,67104127,67104113,67104073,67104071,67104061,67104053,67104047,67104043,67104031,67104019,67104007,67103983,67103969,67103963,67103909,67103893,67103887,67103867,67103851,67103837,67103821,67103761,67103749,67103737,67103731,67103711,67103689,67103669,67103657,67103653,67103633,67103609,67103587,67103579,67103549,67103513,67103507,67103503,67103483,67103479,67103467,67103431,67103423,67103411,67103389,67103359,67103327,67103321,67103297,67103293,67103273,67103249,67103227,67103219,67103209,67103191,67103173,67103159,67103149,67103147,67103143,67103137,67103107,67103083,67103051,67103039,67103033,67103027,67103021,67103009,67102991,67102969,67102967,67102963,67102949,67102943,67102921,67102913,67102901,67102873,67102843,67102801,67102741,67102733,67102729,67102727,67102703,67102669,67102663,67102657,67102649,67102639,67102627,67102613,67102603,67102561,67102537,67102531,67102499,67102487,67102459,67102457,67102447,67102439,67102397,67102391,67102333,67102331,67102291,67102283,67102249,67102241,67102237,67102223,67102219,67102193,67102181,67102177,67102163,67102159,67102153,67102151,67102099,67102093,67102069,67102067,67102051,67102033,67102031,67102019,67102003,67101997,67101989,67101961,67101919,67101899,67101883,67101877,67101799,67101791,67101779,67101743,67101739,67101691,67101689,67101637,67101631,67101623,67101613,67101607,67101569,67101523,67101509,67101493,67101491,67101479,67101469,67101449,67101443,67101421,67101413,67101361,67101343,67101341,67101323,67101299,67101271,67101263,67101247,67101241,67101191,67101187,67101173,67101169,67101161,67101119,67101109,67101079,67101053,67101043,67100987,67100981,67100977,67100963,67100953,67100947,67100939,67100911,67100909,67100899,67100897,67100861,67100857,67100851,67100849,67100827,67100801,67100791,67100779,67100777,67100773,67100753,67100731,67100713,67100699,67100687,67100681,67100669,67100659,67100653,67100639,67100617,67100599,67100587,67100569,67100531,67100497,67100489,67100459,67100447,67100389,67100357,67100353,67100347,67100329,67100311,67100303,67100281,67100273,67100263,67100261,67100251,67100249,67100239,67100233,67100197,67100179,67100141,67100123,67100101,67100087,67100017,67100009,67099999,67099987,67099957,67099951,67099937,67099931,67099927,67099913,67099889,67099861,67099853,67099831,67099829,67099819,67099801,67099793,67099789,67099783,67099771,67099727,67099699,67099687,67099633,67099589,67099577,67099559,67099547,67099541,67099523,67099517,67099499,67099481,67099457,67099447,67099433,67099399,67099397,67099387,67099369,67099363,67099339,67099321,67099309,67099273,67099271,67099267,67099231,67099223,67099217,67099213,67099199,67099171,67099141,67099133,67099129,67099121,67099111,67099103,67099057,67099037,67099031,67098991,67098971,67098931,67098923,67098917,67098907,67098853,67098851,67098839,67098827,67098821,67098809,67098793,67098769,67098761,67098743,67098739,67098697,67098653,67098637,67098623,67098589,67098529,67098527,67098487,67098463,67098457,67098433,67098419,67098403,67098389,67098377,67098359,67098347,67098341,67098323,67098319,67098313,67098307,67098301,67098299,67098277,67098271,67098259,67098233,67098203,67098197,67098193,67098179,67098151,67098149,67098121,67098091,67098071,67098067,67098049,67098047,67098041,67098029,67098019,67098013,67098007,67098001,67097993,67097977,67097959,67097917,67097903,67097869,67097837,67097819,67097813,67097803,67097749,67097747,67097729,67097707,67097699,67097669,67097659,67097603,67097593,67097579,67097567,67097551,67097543,67097507,67097489,67097447,67097441,67097413,67097383,67097369,67097363,67097339,67097333,67097323,67097321,67097297,67097291,67097281,67097273,67097269,67097267,67097209,67097183,67097179,67097123,67097111,67097087,67097081,67097053,67097047,67096987,67096979,67096973,67096921,67096919,67096907,67096903,67096867,67096837,67096817,67096769,67096751,67096717,67096703,67096697,67096693,67096669,67096663,67096649,67096613,67096607,67096583,67096559,67096553,67096507,67096499,67096487,67096483,67096439,67096423,67096411,67096409,67096387,67096373,67096327,67096319,67096303,67096301,67096291,67096261,67096247,67096243,67096231,67096223,67096177,67096151,67096109,67096103,67096097,67096069,67096067,67096063,67096031,67096021,67096013,67096009,67095989,67095983,67095971,67095929,67095893,67095883,67095869,67095857,67095851,67095799,67095797,67095737,67095733,67095731,67095703,67095701,67095683,67095667,67095659,67095629,67095607,67095559,67095551,67095529,67095521,67095499,67095493,67095487,67095421,67095419,67095407,67095383,67095359,67095349,67095317,67095239,67095227,67095221,67095211,67095199,67095173,67095143,67095139,67095131,67095101,67095079,67095047,67095043,67095037,67095013,67095011,67095001,67094987,67094981,67094969,67094941,67094917,67094899,67094891,67094837,67094831,67094827,67094821,67094809,67094759,67094743,67094723,67094717,67094711,67094707,67094701,67094647,67094639,67094593,67094591,67094581,67094557,67094527,67094513,67094507,67094501,67094497,67094471,67094459,67094437,67094411,67094407,67094389,67094369,67094353,67094351,67094329,67094311,67094309,67094299,67094297,67094281,67094267,67094179,67094177,67094173,67094161,67094143,67094141,67094123,67094119,67094099,67094047,67094039,67094021,67094011,67093993,67093979,67093937,67093933,67093931,67093903,67093861,67093853,67093843,67093841,67093801,67093759,67093757,67093723,67093721,67093699,67093681,67093633,67093627,67093619,67093613,67093603,67093597,67093591,67093547,67093519,67093489,67093471,67093409,67093381,67093349,67093319,67093307,67093303,67093297,67093291,67093267,67093249,67093223,67093183,67093181,67093171,67093163,67093157,67093129,67093121,67093109,67093087,67093079,67093069,67093043,67093031,67093007,67093003,67092997,67092953,67092947,67092911,67092887,67092871,67092869,67092847,67092841,67092821,67092811,67092787,67092757,67092749,67092737,67092721,67092709,67092691,67092673,67092671,67092643,67092637,67092611,67092607,67092589,67092563,67092539,67092521,67092511,67092491,67092461,67092451,67092419,67092407,67092391,67092367,67092331,67092323,67092301,67092271,67092247,67092227,67092203,67092199,67092197,67092143,67092139,67092133,67092119,67092107,67092079,67092071,67092041,67092017,67092001,67091987,67091939,67091933,67091923,67091903,67091873,67091861,67091839,67091833,67091821,67091807,67091803,67091797,67091779,67091771,67091743,67091737,67091729,67091683,67091681,67091677,67091669,67091617,67091611,67091561,67091551,67091543,67091501,67091491,67091477,67091467,67091447,67091443,67091441,67091417,67091407,67091369,67091357,67091351,67091341,67091329,67091317,67091291,67091287,67091251,67091243,67091203,67091159,67091149,67091131,67091113,67091107,67091077,67091041,67091039,67091029,67090999,67090979,67090973,67090939,67090937,67090921,67090871,67090861,67090841,67090783,67090769,67090763,67090759,67090711,67090703,67090693,67090679,67090631,67090627,67090613,67090591,67090589,67090579,67090571,67090567,67090561,67090553,67090549,67090547,67090523,67090519,67090489,67090459,67090451,67090433,67090411,67090403,67090399,67090351,67090343,67090321,67090307,67090271,67090259,67090237,67090229,67090223,67090217,67090207,67090189,67090171,67090151,67090129,67090117,67090099,67090091,67090073,67090061,67090043,67090033,67090031,67090027,67090013,67089989,67089949,67089943,67089907,67089877,67089857,67089839,67089829,67089811,67089809,67089793,67089751,67089739,67089733,67089721,67089707,67089697,67089683,67089619,67089587,67089577,67089541,67089527,67089511,67089479,67089469,67089461,67089377,67089329,67089299,67089287,67089283,67089277,67089271,67089241,67089233,67089223,67089221,67089199,67089097,67089059,67089049,67089047,67089013,67088993,67088969,67088963,67088951,67088939,67088911,67088873,67088849,67088839,67088821,67088797,67088779,67088731,67088719,67088717,67088713,67088711,67088683,67088657,67088653,67088627,67088621,67088603,67088597,67088573,67088561,67088521,67088509,67088501,67088473,67088453,67088429,67088393,67088383,67088381,67088347,67088323,67088311,67088303,67088291,67088279,67088267,67088257,67088249,67088209,67088159,67088149,67088117,67088101,67088093,67088081,67088071,67088059,67088039,67088023,67088011,67087981,67087973,67087961,67087957,67087913,67087901,67087883,67087873,67087871,67087859,67087799,67087781,67087777,67087747,67087723,67087717,67087693,67087681,67087679,67087649,67087637,67087591,67087583,67087571,67087567,67087547,67087529,67087519,67087487,67087483,67087463,67087459,67087451,67087421,67087417,67087381,67087367,67087351,67087277,67087259,67087249,67087243,67087217,67087201,67087187,67087177,67087171,67087127,67087123,67087103,67087087,67087039,67087019,67086983,67086979,67086961,67086949,67086937,67086931,67086917,67086893,67086871,67086869,67086839,67086827,67086823,67086793,67086757,67086727,67086673,67086671,67086667,67086647,67086637,67086629,67086623,67086611,67086589,67086559,67086521,67086457,67086433,67086421,67086391,67086361,67086347,67086337,67086323,67086317,67086311,67086307,67086293,67086281,67086259,67086211,67086191,67086137,67086109,67086083,67086067,67086053,67086049,67086043,67086013,67086007,67086001,67085959,67085939,67085933,67085923,67085911,67085899,67085869,67085867,67085861,67085849,67085839,67085831,67085819,67085813,67085803,67085801,67085783,67085771,67085761,67085741,67085731,67085701,67085677,67085657,67085647,67085639,67085617,67085609,67085569,67085533,67085531,67085527,67085521,67085453,67085443,67085437,67085429,67085401,67085377,67085357,67085353,67085351,67085341,67085303,67085287,67085267,67085261,67085233,67085191,67085189,67085173,67085171,67085159,67085119,67085101,67085099,67085093,67085059,67085047,67085003,67084993,67084981,67084973,67084931,67084891,67084879,67084861,67084817,67084807,67084799,67084793,67084789,67084783,67084781,67084777,67084757,67084753,67084751,67084723,67084709,67084681,67084679,67084657,67084643,67084639,67084637,67084609,67084603,67084553,67084547,67084517,67084513,67084483,67084477,67084471,67084447,67084439,67084427,67084417,67084387,67084349,67084333,67084331,67084313,67084309,67084289,67084267,67084247,67084189,67084187,67084177,67084141,67084139,67084111,67084097,67084081,67084049,67084033,67084013,67084001,67083977,67083959,67083943,67083937,67083901,67083883,67083871,67083859,67083829,67083811,67083803,67083799,67083787,67083781,67083773,67083769,67083761,67083739,67083727,67083707,67083703,67083697,67083689,67083631,67083629,67083619,67083613,67083589,67083539,67083521,67083517,67083481,67083461,67083451,67083437,67083371,67083323,67083239,67083221,67083217,67083209,67083199,67083197,67083193,67083113,67083097,67083067,67083043,67083041,67083017,67082989,67082987,67082963,67082933,67082909,67082891,67082861,67082857,67082843,67082831,67082809,67082801,67082783,67082779,67082753,67082707,67082699,67082689,67082671,67082657,67082599,67082579,67082557,67082551,67082549,67082531,67082503,67082497,67082453,67082417,67082399,67082383,67082363,67082341,67082339,67082321,67082311,67082251,67082231,67082227,67082189,67082159,67082143,67082131,67082129,67082123,67082101,67082083,67082023,67082003,67081957,67081919,67081897,67081871,67081841,67081829,67081811,67081787,67081783,67081771,67081769,67081759,67081741,67081733,67081717,67081709,67081697,67081691,67081687,67081681,67081661,67081633,67081631,67081621,67081603,67081601,67081583,67081579,67081577,67081537,67081529,67081499,67081477,67081459,67081429,67081423,67081393,67081351,67081319,67081309,67081283,67081249,67081243,67081237,67081219,67081213,67081211,67081159,67081139,67081127,67081123,67081103,67081097,67081073,67081057,67081051,67080977,67080971,67080967,67080947,67080917,67080859,67080833,67080823,67080821,67080803,67080781,67080763,67080757,67080751,67080737,67080709,67080701,67080679,67080653,67080647,67080631,67080557,67080553,67080527,67080491,67080479,67080439,67080437,67080413,67080367,67080361,67080353,67080337,67080329,67080323,67080319,67080287,67080281,67080271,67080217,67080191,67080179,67080173,67080157,67080131,67080107,67080073,67080061,67080047,67080037,67080031,67080023,67079993,67079989,67079981,67079963,67079941,67079933,67079917,67079911,67079869,67079863,67079849,67079839,67079801,67079791,67079777,67079767,67079759,67079737,67079711,67079693,67079657,67079647,67079641,67079599,67079591,67079587,67079497,67079491,67079489,67079473,67079461,67079459,67079449,67079437,67079429,67079423,67079393,67079359,67079351,67079347,67079333,67079323,67079317,67079303,67079281,67079267,67079249,67079237,67079219,67079213,67079209,67079203,67079197,67079179,67079153,67079149,67079141,67079123,67079107,67079087,67079083,67079081,67079053,67079041,67079027,67079021,67078981,67078961,67078931,67078919,67078903,67078877,67078871,67078819,67078813,67078807,67078801,67078793,67078789,67078777,67078763,67078703,67078673,67078643,67078577,67078573,67078553,67078519,67078483,67078469,67078463,67078433,67078423,67078391,67078387,67078369,67078367,67078343,67078331,67078309,67078301,67078289,67078283,67078217,67078213,67078199,67078181,67078171,67078169,67078159,67078153,67078147,67078139,67078133,67078127,67078117,67078069,67078061,67078013,67078007,67078001,67077991,67077947,67077931,67077917,67077877,67077859,67077851,67077827,67077811,67077799,67077797,67077793,67077761,67077757,67077737,67077719,67077697,67077643,67077623,67077611,67077607,67077553,67077541,67077539,67077523,67077511,67077503,67077497,67077473,67077469,67077449,67077419,67077403,67077379,67077349,67077341,67077313,67077301,67077299,67077293,67077287,67077259,67077217,67077181,67077173,67077169,67077167,67077161,67077133,67077103,67077079,67077071,67077047,67077007,67077001,67076953,67076929,67076927,67076903,67076899,67076887,67076879,67076869,67076857,67076851,67076843,67076833,67076803,67076773,67076741,67076729,67076693,67076683,67076677,67076663,67076651,67076629,67076627,67076599,67076573,67076549,67076539,67076519,67076497,67076489,67076413,67076411,67076389,67076371,67076357,67076353,67076351,67076341,67076291,67076279,67076263,67076231,67076189,67076147,67076117,67076077,67076071,67076069,67076057,67076039,67076029,67075993,67075991,67075973,67075963,67075949,67075937,67075933,67075913,67075907,67075873,67075867,67075849,67075837,67075823,67075787,67075781,67075769,67075747,67075741,67075699,67075691,67075669,67075663,67075649,67075639,67075633,67075621,67075609,67075607,67075601,67075583,67075577,67075573,67075531 }; } // namespace internal From 99cac77c4a8b1986bd8d2b14ad668f4142f4cf88 Mon Sep 17 00:00:00 2001 From: Clement Jamin Date: Tue, 2 Dec 2014 15:40:26 +0100 Subject: [PATCH 22/30] Add a missing #ifdef CGAL_USE_GEOMVIEW to protect the code --- Geomview/include/CGAL/IO/Geomview_stream.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Geomview/include/CGAL/IO/Geomview_stream.h b/Geomview/include/CGAL/IO/Geomview_stream.h index e7d5f8ef80e..6a2c5789265 100644 --- a/Geomview/include/CGAL/IO/Geomview_stream.h +++ b/Geomview/include/CGAL/IO/Geomview_stream.h @@ -25,6 +25,8 @@ #ifndef CGAL_GEOMVIEW_STREAM_H #define CGAL_GEOMVIEW_STREAM_H +#ifdef CGAL_USE_GEOMVIEW + #include #include #include @@ -597,4 +599,6 @@ operator>>(Geomview_stream &gv, Point_3 &point) #include #endif // CGAL_HEADER_ONLY +#endif // CGAL_USE_GEOMVIEW + #endif // CGAL_GEOMVIEW_STREAM_H From e18e59a72a5e097c3c6b23a0ac0efa213a712f66 Mon Sep 17 00:00:00 2001 From: Clement Jamin Date: Tue, 2 Dec 2014 20:41:19 +0100 Subject: [PATCH 23/30] Header-only for package Kinetic_data_structures --- Installation/include/CGAL/export/helpers.h | 39 +- .../CGAL/Kinetic/Active_objects_vector.h | 2 +- .../Handle_degeneracy_function_kernel.h | 4 +- .../include/CGAL/Kinetic/Sort.h | 4 +- .../Kinetic/Two_list_pointer_event_queue.h | 2 +- .../CGAL/Kinetic/internal/debug_counters.h | 54 ++- .../Polynomial/internal/numeric_solvers.h | 11 + .../internal/numeric_solvers_support.h | 5 + .../include/CGAL/Tools/Log.h | 57 ++- .../src/CGAL/JAMA_numeric_solver.cpp | 110 +---- Kinetic_data_structures/src/CGAL/KDS_Log.cpp | 25 +- .../src/CGAL/Turkowski_numeric_solver.cpp | 443 +----------------- .../src/CGAL/numeric_solvers_support.cpp | 248 +--------- .../Delaunay_triangulation_3.cpp | 2 +- .../Kinetic_data_structures/exact_kds.cpp | 2 +- .../include/sort_test.h | 4 +- .../test/Kinetic_data_structures/numbers.cpp | 2 +- .../Kinetic_data_structures/numeric_kds.cpp | 2 +- .../regular_triangulation_3.cpp | 2 +- .../Kinetic_data_structures/simulator.cpp | 2 +- .../test/Kinetic_data_structures/solvers.cpp | 2 +- .../test_KDS_Delaunay_triangulation_2.cpp | 2 +- .../test/Kinetic_data_structures/timings.cpp | 2 +- Profiling_tools/include/CGAL/Timer.h | 5 + Random_numbers/include/CGAL/Random.h | 5 + STL_Extension/include/CGAL/assertions.h | 5 + 26 files changed, 184 insertions(+), 857 deletions(-) diff --git a/Installation/include/CGAL/export/helpers.h b/Installation/include/CGAL/export/helpers.h index 0c6bd9e5a90..9e272492114 100644 --- a/Installation/include/CGAL/export/helpers.h +++ b/Installation/include/CGAL/export/helpers.h @@ -20,20 +20,29 @@ #ifndef CGAL_EXPORT_HELPERS_H #define CGAL_EXPORT_HELPERS_H -#if defined(_WIN32) || defined(__CYGWIN__) -# define CGAL_DLL_IMPORT __declspec(dllimport) -# define CGAL_DLL_EXPORT __declspec(dllexport) -# define CGAL_DLL_LOCAL -#else - #if __GNUC__ >= 4 - #define CGAL_DLL_IMPORT __attribute__ ((visibility ("default"))) - #define CGAL_DLL_EXPORT __attribute__ ((visibility ("default"))) - #define CGAL_DLL_LOCAL __attribute__ ((visibility ("hidden"))) - #else - #define CGAL_DLL_IMPORT - #define CGAL_DLL_EXPORT - #define CGAL_DLL_LOCAL - #endif -#endif +// CJTODO: uncomment this when everything is ready +/*#ifdef CGAL_HEADER_ONLY +# define CGAL_DLL_IMPORT +# define CGAL_DLL_EXPORT +# define CGAL_DLL_LOCA + +#else // !CGAL_HEADER_ONLY*/ +# if defined(_WIN32) || defined(__CYGWIN__) +# define CGAL_DLL_IMPORT __declspec(dllimport) +# define CGAL_DLL_EXPORT __declspec(dllexport) +# define CGAL_DLL_LOCAL +# else + #if __GNUC__ >= 4 + #define CGAL_DLL_IMPORT __attribute__ ((visibility ("default"))) + #define CGAL_DLL_EXPORT __attribute__ ((visibility ("default"))) + #define CGAL_DLL_LOCAL __attribute__ ((visibility ("hidden"))) + #else + #define CGAL_DLL_IMPORT + #define CGAL_DLL_EXPORT + #define CGAL_DLL_LOCAL + #endif +# endif + +//#endif // CGAL_HEADER_ONLY #endif // CGAL_EXPORT_HELPERS_H diff --git a/Kinetic_data_structures/include/CGAL/Kinetic/Active_objects_vector.h b/Kinetic_data_structures/include/CGAL/Kinetic/Active_objects_vector.h index 22de44f98b1..7659c695a95 100644 --- a/Kinetic_data_structures/include/CGAL/Kinetic/Active_objects_vector.h +++ b/Kinetic_data_structures/include/CGAL/Kinetic/Active_objects_vector.h @@ -313,7 +313,7 @@ CGAL_expensive_assertion_code(if ( storage_[i].second == storage_.back().second) iss >> d; if (!iss) { CGAL_ERROR("ERROR reading object from line " << buf); - ++internal::io_errors__; + ++internal::get_static_io_errors(); } else { //CGAL_LOG(Log::LOTS, "Read " << d << std::endl); insert(d); diff --git a/Kinetic_data_structures/include/CGAL/Kinetic/Handle_degeneracy_function_kernel.h b/Kinetic_data_structures/include/CGAL/Kinetic/Handle_degeneracy_function_kernel.h index 3e1dc8da996..a8b91ca941b 100644 --- a/Kinetic_data_structures/include/CGAL/Kinetic/Handle_degeneracy_function_kernel.h +++ b/Kinetic_data_structures/include/CGAL/Kinetic/Handle_degeneracy_function_kernel.h @@ -45,7 +45,7 @@ class HDRS{ CGAL_expensive_precondition(solver_.empty() || solver_.top() >= lb); if (uf.degree() == -1) { CGAL_LOG(Log::SOME, "Zero function found at time " << lb << std::endl); - ++ internal::zero_certificates__; + ++ internal::get_static_zero_certificates(); } #ifndef NDEBUG if (!SLOPPY && k.sign_at_object()(uf, lb) == CGAL::NEGATIVE) { @@ -61,7 +61,7 @@ class HDRS{ CGAL_LOG(Log::LOTS, "Degeneracy at " << solver_.top() << std::endl); CGAL::Sign sn = k.sign_after_object()(uf, lb); if (sn == CGAL::NEGATIVE) { - ++internal::function_degeneracies__; + ++internal::get_static_function_degeneracies(); CGAL_LOG(Log::LOTS, "Extra root at lower bound of " << lb << std::endl); } else { CGAL_LOG(Log::LOTS, "Popping extra root at lower bound of " << lb << std::endl); diff --git a/Kinetic_data_structures/include/CGAL/Kinetic/Sort.h b/Kinetic_data_structures/include/CGAL/Kinetic/Sort.h index d5e0a34ad57..11940198b55 100644 --- a/Kinetic_data_structures/include/CGAL/Kinetic/Sort.h +++ b/Kinetic_data_structures/include/CGAL/Kinetic/Sort.h @@ -277,7 +277,7 @@ public: #endif write(std::cerr); std::cerr << std::endl; - ++internal::audit_failures__; + ++internal::get_static_audit_failures(); if (!wrote_objects_) { wrote_objects_=true; @@ -311,7 +311,7 @@ public: #endif write(std::cerr); std::cerr << std::endl; - ++internal::audit_failures__; + ++internal::get_static_audit_failures(); if (!wrote_objects_) { wrote_objects_=true; diff --git a/Kinetic_data_structures/include/CGAL/Kinetic/Two_list_pointer_event_queue.h b/Kinetic_data_structures/include/CGAL/Kinetic/Two_list_pointer_event_queue.h index 7b49224b297..f3f834d3df8 100644 --- a/Kinetic_data_structures/include/CGAL/Kinetic/Two_list_pointer_event_queue.h +++ b/Kinetic_data_structures/include/CGAL/Kinetic/Two_list_pointer_event_queue.h @@ -717,7 +717,7 @@ protected: #ifndef NDEBUG if (CGAL::compare(tc, tp) == CGAL::SMALLER) { std::cout << "ERROR: Out of order " << tc << std::endl << tp << std::endl << std::endl; - ++internal::audit_failures__; + ++internal::get_static_audit_failures(); } #endif //CGAL_assertion(tc >= tp); diff --git a/Kinetic_data_structures/include/CGAL/Kinetic/internal/debug_counters.h b/Kinetic_data_structures/include/CGAL/Kinetic/internal/debug_counters.h index d03f1e0a9a2..7869e51b567 100644 --- a/Kinetic_data_structures/include/CGAL/Kinetic/internal/debug_counters.h +++ b/Kinetic_data_structures/include/CGAL/Kinetic/internal/debug_counters.h @@ -18,15 +18,67 @@ // // Author(s) : Daniel Russel +#ifndef CGAL_DEBUG_COUNTERS_H_ +#define CGAL_DEBUG_COUNTERS_H_ + #include +#ifdef CGAL_HEADER_ONLY +#undef CGAL_EXPORT // CJTODO: TEMPORARY +#define CGAL_EXPORT +#endif + namespace CGAL { namespace Kinetic { namespace internal { - CGAL_EXPORT extern unsigned int zero_certificates__; + +#ifdef CGAL_HEADER_ONLY + + inline unsigned int& get_static_function_degeneracies() + { + static unsigned int function_degeneracies__ = 0; + return function_degeneracies__; + } + inline unsigned int& get_static_zero_certificates() + { + static unsigned int zero_certificates__ = 0; + return zero_certificates__; + } + inline unsigned int& get_static_io_errors() + { + static unsigned int io_errors__ = 0; + return io_errors__; + } + inline unsigned int& get_static_audit_failures() + { + static unsigned int audit_failures__ = 0; + return audit_failures__; + } + +#else // CGAL_HEADER_ONLY + CGAL_EXPORT extern unsigned int function_degeneracies__; + CGAL_EXPORT extern unsigned int zero_certificates__; CGAL_EXPORT extern unsigned int io_errors__; CGAL_EXPORT extern unsigned int audit_failures__; + inline unsigned int& get_static_function_degeneracies() + { return function_degeneracies__; } + inline unsigned int& get_static_zero_certificates() + { return zero_certificates__; } + inline unsigned int& get_static_io_errors() + { return io_errors__; } + inline unsigned int& get_static_audit_failures() + { return audit_failures__; } + +#endif // CGAL_HEADER_ONLY + + CGAL_EXPORT void write_debug_counters(std::ostream &out); } } } //namespace CGAL::Kinetic + +#ifdef CGAL_HEADER_ONLY +#include +#endif // CGAL_HEADER_ONLY + +#endif // CGAL_DEBUG_COUNTERS_H_ \ No newline at end of file diff --git a/Kinetic_data_structures/include/CGAL/Polynomial/internal/numeric_solvers.h b/Kinetic_data_structures/include/CGAL/Polynomial/internal/numeric_solvers.h index 6c805fd42a5..daa1d4cf330 100644 --- a/Kinetic_data_structures/include/CGAL/Polynomial/internal/numeric_solvers.h +++ b/Kinetic_data_structures/include/CGAL/Polynomial/internal/numeric_solvers.h @@ -23,6 +23,11 @@ #include #include +#ifdef CGAL_HEADER_ONLY +#undef CGAL_EXPORT // CJTODO: TEMPORARY +#define CGAL_EXPORT +#endif + namespace CGAL { namespace POLYNOMIAL { namespace internal { // JAMA @@ -109,4 +114,10 @@ struct Turkowski_cleaned_numeric_solver }; } } } //namespace CGAL::POLYNOMIAL::internal + +#ifdef CGAL_HEADER_ONLY +#include +#include +#endif // CGAL_HEADER_ONLY + #endif diff --git a/Kinetic_data_structures/include/CGAL/Polynomial/internal/numeric_solvers_support.h b/Kinetic_data_structures/include/CGAL/Polynomial/internal/numeric_solvers_support.h index b5e4e03e049..61de4d6da1a 100644 --- a/Kinetic_data_structures/include/CGAL/Polynomial/internal/numeric_solvers_support.h +++ b/Kinetic_data_structures/include/CGAL/Polynomial/internal/numeric_solvers_support.h @@ -57,4 +57,9 @@ void filter_solver_roots(const double *begin, const double *end, std::vector &roots); } } } //namespace CGAL::POLYNOMIAL::internal + +#ifdef CGAL_HEADER_ONLY +#include +#endif // CGAL_HEADER_ONLY + #endif diff --git a/Kinetic_data_structures/include/CGAL/Tools/Log.h b/Kinetic_data_structures/include/CGAL/Tools/Log.h index 60bbb8e8028..c8100c3b62f 100644 --- a/Kinetic_data_structures/include/CGAL/Tools/Log.h +++ b/Kinetic_data_structures/include/CGAL/Tools/Log.h @@ -33,6 +33,11 @@ # pragma warning(disable:4251) #endif +#ifdef CGAL_HEADER_ONLY +#undef CGAL_EXPORT // CJTODO: TEMPORARY +#define CGAL_EXPORT +#endif + namespace CGAL { class Log @@ -59,7 +64,25 @@ private: output_maple_=true; } }; + +#ifdef CGAL_HEADER_ONLY + + inline static State& get_static_state() + { + static State state_; + return state_; + } + +#else // CGAL_HEADER_ONLY + CGAL_EXPORT static State state_; + inline static State& get_static_state() + { + return state_; + } + +#endif // CGAL_HEADER_ONLY + public: // The different types of logs supported /* MAPLE is a log which should be able to be fed directly in to @@ -67,42 +90,42 @@ public: when evaluated. */ - static Level level() {return state_.level_;} - static void set_level(Level l) {state_.level_=l;} + static Level level() {return get_static_state().level_;} + static void set_level(Level l) {get_static_state().level_=l;} static std::ostream &stream(Level l) { if (is_output(l)) { - if (state_.target_== COUT) { + if (get_static_state().target_== COUT) { return std::cout; } else { - return state_.fstream_; + return get_static_state().fstream_; } } else { - return state_.null_; + return get_static_state().null_; } } static bool is_output(Level l) { return l <= level(); } - static Target target() {return state_.target_;} - static CGAL_SET(Target, target, state_.target_=k); - static CGAL_SET(std::string, filename, state_.fstream_.open(k.c_str())); + static Target target() {return get_static_state().target_;} + static CGAL_SET(Target, target, get_static_state().target_=k); + static CGAL_SET(std::string, filename, get_static_state().fstream_.open(k.c_str())); - static bool is_output_maple(){return state_.output_maple_;} + static bool is_output_maple(){return get_static_state().output_maple_;} static void set_output_maple(bool b) { - state_.output_maple_=b; + get_static_state().output_maple_=b; } std::ofstream &maple_stream() { - if (!state_.maple_is_open_) { - state_.maple_is_open_=true; - state_.maple_.open("maple.log"); + if (!get_static_state().maple_is_open_) { + get_static_state().maple_is_open_=true; + get_static_state().maple_.open("maple.log"); } - return state_.maple_; + return get_static_state().maple_; } private: Log() { @@ -163,6 +186,8 @@ struct Set_log_state{ # pragma warning(pop) #endif +#ifdef CGAL_HEADER_ONLY +#include +#endif // CGAL_HEADER_ONLY + #endif - - diff --git a/Kinetic_data_structures/src/CGAL/JAMA_numeric_solver.cpp b/Kinetic_data_structures/src/CGAL/JAMA_numeric_solver.cpp index f602104eb31..a22ab9b0cc5 100644 --- a/Kinetic_data_structures/src/CGAL/JAMA_numeric_solver.cpp +++ b/Kinetic_data_structures/src/CGAL/JAMA_numeric_solver.cpp @@ -18,111 +18,9 @@ // // Author(s) : Daniel Russel -#include +#ifndef CGAL_HEADER_ONLY + #include +#include -#ifdef CGAL_HAVE_TNT -#include -#include -#include -#endif - -#include -#include -#include - -//#include - -namespace CGAL { namespace POLYNOMIAL { namespace internal { -#if CGAL_HAVE_TNT -//static const double max_error_value =0.00005; - -template -static void jama_compute_roots(const NT *begin, const NT *end, NT lb, -NT ub, std::vector &roots) -{ - int degree= end-begin-1; - TNT::Array2D arr(degree, degree, 0.0); - for (int i=0; i< degree; ++i) { - arr[0][i]=-begin[degree-i-1]/begin[degree]; - } - for (int i=0; i+1< degree; ++i) { - arr[i+1][i]=1; - } - - JAMA::Eigenvalue ev(arr); - TNT::Array1D real, imag; - ev.getImagEigenvalues(imag); - ev.getRealEigenvalues(real); - CGAL_Polynomial_assertion(imag.dim1()== real.dim1()); - - /*NT tol; - if (CLEAN) tol=.00005; - else tol=0;*/ - - for (int i=0; i< real.dim1(); ++i) { - if (root_is_good(real[i], imag[i], lb-tol, ub)) { - roots.push_back(real[i]/*polish_root(begin, end, real[i])*/); - } else { - } - } - std::sort(roots.begin(), roots.end(), std::greater()); - if (CLEAN) filter_roots(begin, end, lb, roots); -} - -#endif - - - -void jama_polynomial_compute_roots(const double *begin, const double *end, -double lb, double ub, -std::vector &roots) -{ - std::ptrdiff_t degree= end-begin-1; - switch( degree) { - case -1: - case 0: - break; - case 1: - compute_linear_roots(begin,end, lb, ub, roots); - break; - case 2: - compute_quadratic_roots(begin, end, lb, ub, roots); - break; - default: -#ifdef CGAL_HAVE_TNT - jama_compute_roots(begin, end, lb, ub, roots); -#else - CGAL_error(); -#endif - //jama_compute_roots(begin, end, lb, ub, roots); - } -} - - -void jama_polynomial_compute_cleaned_roots(const double *begin, const double *end, -double lb, double ub, -std::vector &roots) -{ - std::ptrdiff_t degree= end-begin-1; - switch( degree) { - case -1: - case 0: - break; - case 1: - compute_linear_cleaned_roots(begin,end, lb, ub, roots); - break; - case 2: - compute_quadratic_cleaned_roots(begin, end, lb, ub, roots); - break; - default: -#ifdef CGAL_HAVE_TNT - jama_compute_roots(begin, end, lb, ub, roots); -#else - CGAL_error(); -#endif - } -} - - -} } } //namespace CGAL::POLYNOMIAL::internal +#endif \ No newline at end of file diff --git a/Kinetic_data_structures/src/CGAL/KDS_Log.cpp b/Kinetic_data_structures/src/CGAL/KDS_Log.cpp index a2d296c7320..96ebc4338fe 100644 --- a/Kinetic_data_structures/src/CGAL/KDS_Log.cpp +++ b/Kinetic_data_structures/src/CGAL/KDS_Log.cpp @@ -18,30 +18,17 @@ // // Author(s) : Daniel Russel -#include +#ifndef CGAL_HEADER_ONLY -#if defined(BOOST_MSVC) -# pragma warning(disable:4251) -#endif - -#include #include -#include -namespace CGAL { -Log::State Log::state_; -} //namespace CGAL -namespace CGAL { namespace Kinetic { namespace internal { +#include +#include +#include +namespace CGAL { namespace Kinetic { namespace internal { unsigned int function_degeneracies__=0; unsigned int zero_certificates__=0; unsigned int io_errors__=0; unsigned int audit_failures__=0; - - void write_debug_counters(std::ostream &out) { - out << "Degeneracies " << function_degeneracies__ << std::endl; - out << "Zero functions " << zero_certificates__ << std::endl; - if (io_errors__ != 0) out << "I/O errors " << io_errors__ << std::endl; - if (audit_failures__ != 0) out << "Audit failures " << audit_failures__ << std::endl; - } - } } } //namespace CGAL::Kinetic::internal +#endif diff --git a/Kinetic_data_structures/src/CGAL/Turkowski_numeric_solver.cpp b/Kinetic_data_structures/src/CGAL/Turkowski_numeric_solver.cpp index 419aa40bb5e..7c444f6f2ce 100644 --- a/Kinetic_data_structures/src/CGAL/Turkowski_numeric_solver.cpp +++ b/Kinetic_data_structures/src/CGAL/Turkowski_numeric_solver.cpp @@ -18,444 +18,9 @@ // // Author(s) : Daniel Russel -#include +#ifndef CGAL_HEADER_ONLY + #include +#include -/*#ifdef _MSC_VER -#pragma warning(disable:1572) -#endif*/ - - -//#include "numeric_solvers_support.C" - -// Taken from http://www.worldserver.com/turk/opensource/ - -/* Copyright (C) 1978-1999 Ken Turkowski. - * - * All rights reserved. - * - * Warranty Information - * Even though I have reviewed this software, I make no warranty - * or representation, either express or implied, with respect to this - * software, its quality, accuracy, merchantability, or fitness for a - * particular purpose. As a result, this software is provided "as is," - * and you, its user, are assuming the entire risk as to its quality - * and accuracy. - * - * This code may be used and freely distributed as long as it includes - * this copyright notice and the above warranty information. - */ - -#include -#include - -namespace CGAL { namespace POLYNOMIAL { namespace internal { - -# define FLOAT double - -static const unsigned int MAXN= 55; -//# define PARAMFLOAT double_t - -/******************************************************************************* - * FindCubicRoots - * - * Solve: - * coeff[3] * x^3 + coeff[2] * x^2 + coeff[1] * x + coeff[0] = 0 - * - * returns: - * 3 - 3 real roots - * 1 - 1 real root (2 complex conjugate) - *******************************************************************************/ - -static long -FindCubicRoots(const FLOAT coeff[4], FLOAT x[3]) -{ - FLOAT a1 = coeff[2] / coeff[3]; - FLOAT a2 = coeff[1] / coeff[3]; - FLOAT a3 = coeff[0] / coeff[3]; - - double Q = (a1 * a1 - 3 * a2) / 9; - double R = (2 * a1 * a1 * a1 - 9 * a1 * a2 + 27 * a3) / 54; - double Qcubed = Q * Q * Q; - double d = Qcubed - R * R; - - /* Three real roots */ - if (d >= 0) { - double theta = std::acos(R / std::sqrt(Qcubed)); - double sqrtQ = std::sqrt(Q); - x[0] = -2 * sqrtQ * std::cos( theta / 3) - a1 / 3; - x[1] = -2 * sqrtQ * std::cos((theta + 2 * CGAL_PI) / 3) - a1 / 3; - x[2] = -2 * sqrtQ * std::cos((theta + 4 * CGAL_PI) / 3) - a1 / 3; - return (3); - } - - /* One real root */ - else { - double e = std::pow(std::sqrt(-d) + ::CGAL::abs(R), 1. / 3.); - if (R > 0) - e = -e; - x[0] = (e + Q / e) - a1 / 3.; - return (1); - } -} - - -/******************************************************************************* - * FindPolynomialRoots - * - * The Bairstow and Newton correction formulae are used for a simultaneous - * linear and quadratic iterated synthetic division. The coefficients of - * a polynomial of degree n are given as a[i] (i=0,i,..., n) where a[0] is - * the constant term. The coefficients are scaled by dividing them by - * their geometric mean. The Bairstow or Newton iteration method will - * nearly always converge to the number of figures carried, fig, either to - * root values or to their reciprocals. If the simultaneous Newton and - * Bairstow iteration fails to converge on root values or their - * reciprocals in maxiter iterations, the convergence requirement will be - * successively reduced by one decimal figure. This program anticipates - * and protects against loss of significance in the quadratic synthetic - * division. (Refer to "On Programming the Numerical Solution of - * Polynomial Equations," by K. W. Ellenberger, Commun. ACM 3 (Dec. 1960), - * 644-647.) The real and imaginary part of each root is stated as u[i] - * and v[i], respectively, together with the corresponding constant, - * conv[i], used in the convergence test. This program has been used - * successfully for over a year on the Bendix G15-D (Intercard System) and - * has recently been coded for the IBM 709 (Fortran system). - * - * ACM algorithm #30 - Numerical Solution of the Polynomial Equation - * K. W. Ellenberger - * Missle Division, North American Aviation, Downey, California - * Converted to C, modified, optimized, and structured by - * Ken Turkowski - * CADLINC, Inc., Palo Alto, California - *******************************************************************************/ - -static void -FindPolynomialRoots( - const FLOAT *a, /* Coefficients */ - FLOAT *u, /* Real component of each root */ - FLOAT *v, /* Imaginary component of each root */ - FLOAT *conv, /* Convergence constant associated with each root */ - register long n, /* Degree of polynomial (order-1) */ - long maxiter, /* Maximum number of iterations */ - long fig /* The number of decimal figures to be computed */ - ) -{ - int number_of_ITERATE=0; - int number_of_INIT=0; - CGAL_precondition(static_cast(fig) < MAXN); - int i; - register int j; - FLOAT h[MAXN + 3], b[MAXN + 3], c[MAXN + 3], d[MAXN + 3], e[MAXN + 3]; - /* [-2 : n] */ - FLOAT K, ps, qs, pt, qt, s, rev, r= std::numeric_limits::infinity(); - int t; - FLOAT p=std::numeric_limits::infinity(), q=std::numeric_limits::infinity(); - - /* Zero elements with negative indices */ - b[2 + -1] = b[2 + -2] = - c[2 + -1] = c[2 + -2] = - d[2 + -1] = d[2 + -2] = - e[2 + -1] = e[2 + -2] = - h[2 + -1] = h[2 + -2] = 0.0; - - /* Copy polynomial coefficients to working storage */ - for (j = n; j >= 0; j--) - h[2 + j] = *a++; /* Note reversal of coefficients */ - - t = 1; - K = std::pow(10.0, (double)(fig)); /* Relative accuracy */ - - for (; h[2 + n] == 0.0; n--) { /* Look for zero high-order coeff. */ - *u++ = 0.0; - *v++ = 0.0; - *conv++ = K; - } - - INIT: - ++number_of_INIT; - if (number_of_INIT > 1000) { - std::cerr << "Too many INITs" << std::flush; - return; - } - - if (n == 0) - return; - - ps = qs = pt = qt = s = 0.0; - rev = 1.0; - K = std::pow(10.0, (double)(fig)); - - if (n == 1) { - r = -h[2 + 1] / h[2 + 0]; - goto LINEAR; - } - - for (j = n; j >= 0; j--) /* Find geometric mean of coeff's */ - if (h[2 + j] != 0.0) - s += std::log( ::CGAL::abs(h[2 + j])); - s = std::exp(s / (n + 1)); - - for (j = n; j >= 0; j--) /* Normalize coeff's by mean */ - h[2 + j] /= s; - - if ( ::CGAL::abs(h[2 + 1] / h[2 + 0]) < ::CGAL::abs(h[2 + n - 1] / h[2 + n])) { - REVERSE: - t = -t; - for (j = (n - 1) / 2; j >= 0; j--) { - s = h[2 + j]; - h[2 + j] = h[2 + n - j]; - h[2 + n - j] = s; - } - } - if (qs != 0.0) { - p = ps; - q = qs; - } - else { - if (h[2 + n - 2] == 0.0) { - q = 1.0; - p = -2.0; - } - else { - q = h[2 + n] / h[2 + n - 2]; - p = (h[2 + n - 1] - q * h[2 + n - 3]) / h[2 + n - 2]; - } - if (n == 2) - goto QADRTIC; - r = 0.0; - } - ITERATE: - ++number_of_ITERATE; - if (number_of_ITERATE > 1000) { - std::cerr << "Too many ITERATEs" << std::flush; - return; - } - for (i = maxiter; i > 0; i--) { - - for (j = 0; j <= n; j++) { /* BAIRSTOW */ - b[2 + j] = h[2 + j] - p * b[2 + j - 1] - q * b[2 + j - 2]; - c[2 + j] = b[2 + j] - p * c[2 + j - 1] - q * c[2 + j - 2]; - } - if ((h[2 + n - 1] != 0.0) && (b[2 + n - 1] != 0.0)) { - if ( ::CGAL::abs(h[2 + n - 1] / b[2 + n - 1]) >= K) { - b[2 + n] = h[2 + n] - q * b[2 + n - 2]; - } - if (b[2 + n] == 0.0) - goto QADRTIC; - if (K < ::CGAL::abs(h[2 + n] / b[2 + n])) - goto QADRTIC; - } - - for (j = 0; j <= n; j++) { /* NEWTON */ - /* Calculate polynomial at r */ - d[2 + j] = h[2 + j] + r * d[2 + j - 1]; - /* Calculate derivative at r */ - e[2 + j] = d[2 + j] + r * e[2 + j - 1]; - } - if (d[2 + n] == 0.0) - goto LINEAR; - if (K < ::CGAL::abs(h[2 + n] / d[2 + n])) - goto LINEAR; - - c[2 + n - 1] = -p * c[2 + n - 2] - q * c[2 + n - 3]; - s = c[2 + n - 2] * c[2 + n - 2] - c[2 + n - 1] * c[2 + n - 3]; - if (s == 0.0) { - p -= 2.0; - q *= (q + 1.0); - } - else { - p += (b[2 + n - 1] * c[2 + n - 2] - b[2 + n] * c[2 + n - 3]) / s; - q += (-b[2 + n - 1] * c[2 + n - 1] + b[2 + n] * c[2 + n - 2]) / s; - } - if (e[2 + n - 1] == 0.0) - r -= 1.0; /* Minimum step */ - else - r -= d[2 + n] / e[2 + n - 1]; /* Newton's iteration */ - } - ps = pt; - qs = qt; - pt = p; - qt = q; - if (rev < 0.0) - K /= 10.0; - rev = -rev; - goto REVERSE; - - LINEAR: - if (t < 0) - r = 1.0 / r; - n--; - *u++ = r; - *v++ = 0.0; - *conv++ = K; - - for (j = n; j >= 0; j--) { /* Polynomial deflation by lin-nomial */ - if ((d[2 + j] != 0.0) && ( ::CGAL::abs(h[2 + j] / d[2 + j]) < K)) - h[2 + j] = d[2 + j]; - else - h[2 + j] = 0.0; - } - - if (n == 0) - return; - goto ITERATE; - - QADRTIC: - if (t < 0) { - p /= q; - q = 1.0 / q; - } - n -= 2; - - if (0.0 < (q - (p * p / 4.0))) { /* Two complex roots */ - *(u + 1) = *u = -p / 2.0; - u += 2; - s = sqrt(q - (p * p / 4.0)); - *v++ = s; - *v++ = -s; - } /* Two real roots */ - else { - s = std::sqrt(((p * p / 4.0)) - q); - if (p < 0.0) - *u++ = -p / 2.0 + s; - else - *u++ = -p / 2.0 - s; - *u = q / u[-1]; - ++u; // moved from lhs of before - *v++ = 0.0; - *v++ = 0.0; - } - *conv++ = K; - *conv++ = K; - - for (j = n; j >= 0; j--) { /* Polynomial deflation by quadratic */ - if ((b[2 + j] != 0.0) && ( ::CGAL::abs(h[2 + j] / b[2 + j]) < K)) - h[2 + j] = b[2 + j]; - else - h[2 + j] = 0.0; - } - goto INIT; -} - - -#undef MAXN - -template -static void Turkowski_polynomial_compute_roots_t(const double *begin, - const double *end, - double lb, double ub, - std::vector &roots) -{ - std::size_t numc= end-begin; - double rp[MAXN]; - double cp[MAXN]; - double cc[MAXN]; - - /*for (unsigned int i=0; i< numc; ++i){ - rp[i]= std::numeric_limits::infinity(); - }*/ - - for (unsigned int i=0; i< MAXN; ++i){ - cc[i]=std::numeric_limits::infinity(); - rp[i]=std::numeric_limits::infinity(); - cc[i]=std::numeric_limits::infinity(); - } - - FindPolynomialRoots(begin, rp, cp, cc, static_cast(numc)-1, 10*static_cast(numc), 40); - - /*if (CLEAN) { - lb-= .000005; - }*/ - double last= -std::numeric_limits::infinity(); - for (std::size_t i=0; i< numc-1; ++i) { - /* std::cout << "Trying " << rp[i] << "+" << std::setprecision(10) << cp[i] << "i " - << cc[i] << "\n";*/ - if (cc[i] > 10000 && root_is_good(rp[i], cp[i], lb, ub)) { - roots.push_back(rp[i]); - /*std::cout << "Good was " << rp[i] << "+" <()); - - if (CLEAN) filter_solver_roots(begin, end, lb, ub, last, roots); -} - - -void Turkowski_polynomial_compute_roots(const double *begin, const double *end, - double lb, double ub, - std::vector &roots) -{ - - std::ptrdiff_t degree= end-begin-1; - switch( degree) { - case -1: - case 0: - break; - case 1: - compute_linear_roots(begin,end, lb, ub, roots); - break; - case 2: - compute_quadratic_roots(begin, end, lb, ub, roots); - break; - case 3: - { - double rd[3]; - int numr= FindCubicRoots(begin, rd); - for (int i=numr-1; i>=0; --i) { - if (rd[i] >= lb && rd[i] < ub) roots.push_back(rd[i]); - } - std::sort(roots.begin(), roots.end(), std::greater()); - break; - } - default: - Turkowski_polynomial_compute_roots_t(begin, end, lb, ub, roots); - - } - -} - - -void Turkowski_polynomial_compute_cleaned_roots(const double *begin, const double *end, - double lb, double ub, - std::vector &roots) -{ - std::ptrdiff_t degree= end-begin-1; - switch( degree) { - case -1: - case 0: - break; - case 1: - compute_linear_cleaned_roots(begin,end, lb, ub, roots); - break; - case 2: - compute_quadratic_cleaned_roots(begin, end, lb, ub, roots); - break; - case 3: - { - double rd[3]; - int numr= FindCubicRoots(begin, rd); - double last=-std::numeric_limits::infinity(); - for (int i=numr-1; i>=0; --i) { - if (rd[i]< ub && rd[i] >= lb) roots.push_back(rd[i]); - if (rd[i] < lb && rd[i] > last){ - last=rd[i]; - } - } - std::sort(roots.begin(), roots.end(), std::greater()); - filter_solver_roots(begin, end, lb, ub, last, roots); - break; - } - default: - Turkowski_polynomial_compute_roots_t(begin, end, lb, ub, roots); - } -} - - -} } } //namespace CGAL::POLYNOMIAL::internal +#endif \ No newline at end of file diff --git a/Kinetic_data_structures/src/CGAL/numeric_solvers_support.cpp b/Kinetic_data_structures/src/CGAL/numeric_solvers_support.cpp index 1616cb6ee52..5f853cb4eee 100644 --- a/Kinetic_data_structures/src/CGAL/numeric_solvers_support.cpp +++ b/Kinetic_data_structures/src/CGAL/numeric_solvers_support.cpp @@ -19,249 +19,9 @@ // Author(s) : Daniel Russel +#ifndef CGAL_HEADER_ONLY + #include -#include +#include -#include -#include -#include - -/*#ifdef _MSC_VER -#pragma warning(disable:1572) -#endif*/ - -namespace CGAL { namespace POLYNOMIAL { namespace internal { - -static double max_error_value=.00005; - -namespace { -template -inline void compute_quadratic_roots_t(const NT *begin, const NT * /*end*/, NT lb, NT ub, -std::vector &roots) -{ - NT max_error=0; - if (CLEAN) max_error=max_error_value; - CGAL_Polynomial_assertion(begin[2] != 0); - - NT desc= begin[1]*begin[1]-4*begin[0]*begin[2]; - if (desc <= 0) return; - - NT ur= (-begin[1]+sqrt(desc))/(2*begin[2]); - NT lr= (-begin[1]-sqrt(desc))/(2*begin[2]); - if (begin[2]< 0) std::swap(lr, ur); - if (lr > lb-max_error && lr < ub) { - roots.push_back(ur); - if (lr > lb-max_error && lr < ub && (!CLEAN || /*lr > lb+max_error ||*/ begin[2] >0)){ - roots.push_back(lr); - } - } else { - // only upper - if (ur > lb-max_error && ur < ub && (!CLEAN || /*ur > lb+max_error ||*/ begin[2] <0)){ - roots.push_back(ur); - } - - - } - - // drop even roots - /*if (ur >lb-max_error && ur < ub){ - if (!CLEAN || sign(begin[2]) != POSITIVE){ - roots.push_back(ur); - if (lr >lb-max_error && lr < ub){ - roots.push_back(lr); - } - } - } else { - if (lr > lb-max_error && lr &roots) -{ - return compute_quadratic_roots_t(begin, end, lb, ub, roots); -} - - -void compute_quadratic_cleaned_roots(const double *begin, const double *end, -double lb, double ub, std::vector &roots) -{ - return compute_quadratic_roots_t(begin, end, lb, ub, roots); -} - -namespace { -template -inline void compute_linear_roots_t(const NT *begin, const NT *, - NT lb, NT ub, - std::vector &roots) -{ - if (CLEAN && begin[1]>0 ) return; - //NT max_error=0; - //if (CLEAN) max_error=max_error_value; - NT r= -to_double(begin[0]/begin[1]); - if ((CLEAN || r > lb) && r < ub) { - roots.push_back(r); - } -} -} - -void compute_linear_roots(const double *begin, const double *end, -double lb, double ub, std::vector &roots) -{ - return compute_linear_roots_t(begin, end, lb, ub, roots); -} - - -void compute_linear_cleaned_roots(const double *begin, const double *end, - double lb, double ub, std::vector &roots) -{ - return compute_linear_roots_t(begin, end, lb, ub, roots); -} - - -namespace { -template - inline void filter_roots_t(const NT *begin, const NT *end, - NT lb, NT ub, NT last_root, std::vector &roots) -{ -// if we are not close to the current time, then we are fine - if (roots.empty()) return; - //if (roots.back() > lb+ .0005) return; - - //double eps= .0005; - /*double last_root=-std::numeric_limits::infinity(); - - while (roots.back() < lb) { - last_root= roots.back(); - roots.pop_back(); - }*/ - //if (roots.back() > lb+eps) return; - - //typedef CGAL_POLYNOMIAL_NS::Polynomial Fn; - - typedef CGAL_POLYNOMIAL_NS::Interval_polynomial IFn; - typedef CGAL_POLYNOMIAL_NS::internal::Derivative Diff; - typedef typename IFn::NT INT; - - - /*bool popped=false;*/ - // if the last valid root is closer than last, consider it as doubtful instead - if (lb-last_root > roots.back()-lb) { - last_root= roots.back(); - roots.pop_back(); - /*popped=true;*/ - } /*else { - last_root=lb; - }*/ - - INT vi; - if (last_root== -std::numeric_limits::infinity()){ - if ((end-begin)%2==1) { - vi= std::numeric_limits::infinity(); - } else { - vi = -*(end-1); - } - } else { - IFn fi(begin, end); - if (roots.empty()) { - Interval_arithmetic_guard guard; - if (ub== std::numeric_limits::infinity()) { - vi = 10*lb + 1000; - } else { - vi = fi((INT(lb)+INT(ub))/2.0); - } - } else { - Interval_arithmetic_guard guard; - vi = fi((INT(last_root)+INT(roots.back()))/2.0); - } - } - - if (vi.inf() > 0) { - return; - } else if (vi.sup() < 0){ - roots.push_back(last_root); - - /*if (!popped) { - IFn f(begin, end); - std::cout << "Adding last due to sign of " << vi << std::endl; - std::cout << "last " << last_root << " lb " << lb << " poly " << f << std::endl; - }*/ - return; - } - Interval_arithmetic_guard guard; - Diff dx; - IFn f(begin, end); - IFn d= dx(f); - - INT dv= d(roots.back()); - // switch - //while (sign(d(roots.back().representation()))== ZERO) d= dx_(d); - while (dv.inf() <= 0 && dv.sup() >= 0) { - d= dx(d); - dv= d(roots.back()); - } - // switch - //if (sign(d(roots.back().representation()))==POSITIVE){ - if (dv.sup() < 0) { - roots.push_back(last_root); - /*if (!popped) { - IFn f(begin, end); - std::cout << "Adding last due to deriv of " << vi << std::endl; - std::cout << "last " << last_root << " lb " << lb << " poly " << f << std::endl; - }*/ - } -} -} - -void filter_solver_roots(const double *begin, const double *end, - double lb, double ub, double last, - std::vector &roots) -{ - filter_roots_t(begin, end, lb, ub, last, roots); -} - - -/*void polynomial_compute_roots(const double *begin, const double *end, double lb, - double ub, std::vector &roots){ -#ifdef POLYNOMIAL_USE_GSL - gsl_polynomial_compute_roots(begin, end, lb, ub, roots); -#else - jama_polynomial_compute_roots(begin, end, lb, ub, roots); -#endif -} - -void polynomial_compute_cleaned_roots(const double *begin, const double *end, double lb, - double ub, std::vector &roots){ -#ifdef POLYNOMIAL_USE_GSL -gsl_polynomial_compute_cleaned_roots(begin, end, lb, ub, roots); -#else -jama_polynomial_compute_cleaned_roots(begin, end, lb, ub, roots); -#endif -}*/ - -double evaluate_polynomial(const double *b, const double *e, double t) -{ -#ifdef POLYNOMIAL_USE_GSL - return gsl_evaluate_polynomial(b, e, t); -#else - if (b==e) return 0.0; - - const double *rit=e-1; - double result = *rit; - --rit; - for (; rit != b-1; --rit) { - result *= t; - result += (*rit); - } - return result; -#endif -} - - -} } } //namespace CGAL::POLYNOMIAL::internal +#endif \ No newline at end of file diff --git a/Kinetic_data_structures/test/Kinetic_data_structures/Delaunay_triangulation_3.cpp b/Kinetic_data_structures/test/Kinetic_data_structures/Delaunay_triangulation_3.cpp index e4373973c7f..1464fbe1446 100644 --- a/Kinetic_data_structures/test/Kinetic_data_structures/Delaunay_triangulation_3.cpp +++ b/Kinetic_data_structures/test/Kinetic_data_structures/Delaunay_triangulation_3.cpp @@ -111,6 +111,6 @@ int main(int argc, char *argv[]) //std::cout << "Insert " << queue_insertions__ << " and front " << queue_front_insertions__ << std::endl; //std::cout << "Sturm created " << sturm_created__ << " and shrink " << sturm_refined__ << std::endl; - if (CGAL::Kinetic::internal::audit_failures__ != 0 ) return EXIT_FAILURE; + if (CGAL::Kinetic::internal::get_static_audit_failures() != 0 ) return EXIT_FAILURE; else return EXIT_SUCCESS; } diff --git a/Kinetic_data_structures/test/Kinetic_data_structures/exact_kds.cpp b/Kinetic_data_structures/test/Kinetic_data_structures/exact_kds.cpp index 50a99d9cd10..0595ef92dd2 100644 --- a/Kinetic_data_structures/test/Kinetic_data_structures/exact_kds.cpp +++ b/Kinetic_data_structures/test/Kinetic_data_structures/exact_kds.cpp @@ -66,7 +66,7 @@ int main(int argc, char *argv[]) { #endif - if (error || CGAL::Kinetic::internal::audit_failures__ != 0) { + if (error || CGAL::Kinetic::internal::get_static_audit_failures() != 0) { return EXIT_FAILURE; } else { diff --git a/Kinetic_data_structures/test/Kinetic_data_structures/include/sort_test.h b/Kinetic_data_structures/test/Kinetic_data_structures/include/sort_test.h index b373ef99b77..bed6b15515b 100644 --- a/Kinetic_data_structures/test/Kinetic_data_structures/include/sort_test.h +++ b/Kinetic_data_structures/test/Kinetic_data_structures/include/sort_test.h @@ -40,7 +40,7 @@ bool sort_test(Traits &tr, double max_events=std::numeric_limits::infini #ifndef NDEBUG if (tr.simulator_handle()->current_event_number() > max_events){ std::cerr << "ERROR too many events" << std::endl; - ++CGAL::Kinetic::internal::audit_failures__; + ++CGAL::Kinetic::internal::get_static_audit_failures(); std::cerr << *tr.active_points_1_table_handle() << std::endl; } #endif @@ -85,7 +85,7 @@ bool sort_test(Traits &tr, double max_events=std::numeric_limits::infini std::cerr << etag << "Objects " << c->object() << " = " << tr.active_points_1_table_handle()->at(*c).x() << " and " << b->object() << " = " << tr.active_points_1_table_handle()->at(*b).x() << " out of order at end of time " < ("Upper bound"); - if (CGAL::Kinetic::internal::audit_failures__ != 0) return EXIT_FAILURE; + if (CGAL::Kinetic::internal::get_static_audit_failures() != 0) return EXIT_FAILURE; else return EXIT_SUCCESS; //test_sort < CGAL::Kinetic::Exact_simulation_traits_1 > ("Upper bound"); diff --git a/Profiling_tools/include/CGAL/Timer.h b/Profiling_tools/include/CGAL/Timer.h index ae111466c3f..8ded799f2dc 100644 --- a/Profiling_tools/include/CGAL/Timer.h +++ b/Profiling_tools/include/CGAL/Timer.h @@ -28,6 +28,11 @@ #include +#ifdef CGAL_HEADER_ONLY +#undef CGAL_EXPORT // CJTODO: TEMPORARY +#define CGAL_EXPORT +#endif + namespace CGAL { // SECTION: A Timer for User-Process Time diff --git a/Random_numbers/include/CGAL/Random.h b/Random_numbers/include/CGAL/Random.h index 913a0e688f6..5512360c948 100644 --- a/Random_numbers/include/CGAL/Random.h +++ b/Random_numbers/include/CGAL/Random.h @@ -37,6 +37,11 @@ #include +#ifdef CGAL_HEADER_ONLY +#undef CGAL_EXPORT // CJTODO: TEMPORARY +#define CGAL_EXPORT +#endif + namespace CGAL { class Random { diff --git a/STL_Extension/include/CGAL/assertions.h b/STL_Extension/include/CGAL/assertions.h index c9dd318cf71..272b1c516b4 100644 --- a/STL_Extension/include/CGAL/assertions.h +++ b/STL_Extension/include/CGAL/assertions.h @@ -37,6 +37,11 @@ #endif #endif +#ifdef CGAL_HEADER_ONLY +#undef CGAL_EXPORT // CJTODO: TEMPORARY +#define CGAL_EXPORT +#endif + namespace CGAL { // function declarations From 6bf380f8890dfab6d454b400a462c3c26cc0d632 Mon Sep 17 00:00:00 2001 From: Clement Jamin Date: Tue, 2 Dec 2014 20:42:25 +0100 Subject: [PATCH 24/30] Updated cppfiles.txt --- cppfiles.txt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/cppfiles.txt b/cppfiles.txt index 1ca924c42ce..1d1457efd59 100644 --- a/cppfiles.txt +++ b/cppfiles.txt @@ -38,10 +38,10 @@ Clement: CGAL: -#include "/home/gdamiand/sources/CGAL/Kinetic_data_structures/src/CGAL/JAMA_numeric_solver.cpp" -#include "/home/gdamiand/sources/CGAL/Kinetic_data_structures/src/CGAL/KDS_Log.cpp" -#include "/home/gdamiand/sources/CGAL/Kinetic_data_structures/src/CGAL/numeric_solvers_support.cpp" -#include "/home/gdamiand/sources/CGAL/Kinetic_data_structures/src/CGAL/Turkowski_numeric_solver.cpp" +DONE #include "/home/gdamiand/sources/CGAL/Kinetic_data_structures/src/CGAL/JAMA_numeric_solver.cpp" +DONE #include "/home/gdamiand/sources/CGAL/Kinetic_data_structures/src/CGAL/KDS_Log.cpp" +DONE #include "/home/gdamiand/sources/CGAL/Kinetic_data_structures/src/CGAL/numeric_solvers_support.cpp" +DONE #include "/home/gdamiand/sources/CGAL/Kinetic_data_structures/src/CGAL/Turkowski_numeric_solver.cpp" CGAL_Core: From 3915c89c17398aa963e223d96f96468b443309d3 Mon Sep 17 00:00:00 2001 From: Clement Jamin Date: Wed, 3 Dec 2014 11:29:54 +0100 Subject: [PATCH 25/30] Oops, forgot to commit the *_impl.h files --- .../Kinetic/internal/debug_counters_impl.h | 36 ++ .../internal/JAMA_numeric_solvers_impl.h | 135 +++++ .../internal/Turkowski_numeric_solvers_impl.h | 467 ++++++++++++++++++ .../internal/numeric_solvers_impl.h | 138 ++++++ .../internal/numeric_solvers_support_impl.h | 276 +++++++++++ .../include/CGAL/Tools/Log_impl.h | 32 ++ 6 files changed, 1084 insertions(+) create mode 100644 Kinetic_data_structures/include/CGAL/Kinetic/internal/debug_counters_impl.h create mode 100644 Kinetic_data_structures/include/CGAL/Polynomial/internal/JAMA_numeric_solvers_impl.h create mode 100644 Kinetic_data_structures/include/CGAL/Polynomial/internal/Turkowski_numeric_solvers_impl.h create mode 100644 Kinetic_data_structures/include/CGAL/Polynomial/internal/numeric_solvers_impl.h create mode 100644 Kinetic_data_structures/include/CGAL/Polynomial/internal/numeric_solvers_support_impl.h create mode 100644 Kinetic_data_structures/include/CGAL/Tools/Log_impl.h diff --git a/Kinetic_data_structures/include/CGAL/Kinetic/internal/debug_counters_impl.h b/Kinetic_data_structures/include/CGAL/Kinetic/internal/debug_counters_impl.h new file mode 100644 index 00000000000..f939334deed --- /dev/null +++ b/Kinetic_data_structures/include/CGAL/Kinetic/internal/debug_counters_impl.h @@ -0,0 +1,36 @@ +// Copyright (c) 2005 Stanford University (USA). +// 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$ +// +// +// Author(s) : Daniel Russel + +#if defined(BOOST_MSVC) +# pragma warning(disable:4251) +#endif +#include + +namespace CGAL { namespace Kinetic { namespace internal { + + CGAL_INLINE_FUNCTION + void write_debug_counters(std::ostream &out) { + out << "Degeneracies " << get_static_function_degeneracies() << std::endl; + out << "Zero functions " << get_static_zero_certificates() << std::endl; + if (get_static_io_errors() != 0) out << "I/O errors " << get_static_io_errors() << std::endl; + if (get_static_audit_failures() != 0) out << "Audit failures " << get_static_audit_failures() << std::endl; + } + +} } } //namespace CGAL::Kinetic::internal diff --git a/Kinetic_data_structures/include/CGAL/Polynomial/internal/JAMA_numeric_solvers_impl.h b/Kinetic_data_structures/include/CGAL/Polynomial/internal/JAMA_numeric_solvers_impl.h new file mode 100644 index 00000000000..c9153c85667 --- /dev/null +++ b/Kinetic_data_structures/include/CGAL/Polynomial/internal/JAMA_numeric_solvers_impl.h @@ -0,0 +1,135 @@ +// Copyright (c) 2005 Stanford University (USA). +// 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$ +// +// +// Author(s) : Daniel Russel + +#ifdef CGAL_HEADER_ONLY +#define CGAL_INLINE_FUNCTION inline +#else +#define CGAL_INLINE_FUNCTION +#endif + +#include +#include + +#ifdef CGAL_HAVE_TNT +#include +#include +#include +#endif + +#include +#include +#include + +//#include + +namespace CGAL { namespace POLYNOMIAL { namespace internal { +#if CGAL_HAVE_TNT +//static const double max_error_value =0.00005; + +template +static void jama_compute_roots(const NT *begin, const NT *end, NT lb, +NT ub, std::vector &roots) +{ + int degree= end-begin-1; + TNT::Array2D arr(degree, degree, 0.0); + for (int i=0; i< degree; ++i) { + arr[0][i]=-begin[degree-i-1]/begin[degree]; + } + for (int i=0; i+1< degree; ++i) { + arr[i+1][i]=1; + } + + JAMA::Eigenvalue ev(arr); + TNT::Array1D real, imag; + ev.getImagEigenvalues(imag); + ev.getRealEigenvalues(real); + CGAL_Polynomial_assertion(imag.dim1()== real.dim1()); + + /*NT tol; + if (CLEAN) tol=.00005; + else tol=0;*/ + + for (int i=0; i< real.dim1(); ++i) { + if (root_is_good(real[i], imag[i], lb-tol, ub)) { + roots.push_back(real[i]/*polish_root(begin, end, real[i])*/); + } else { + } + } + std::sort(roots.begin(), roots.end(), std::greater()); + if (CLEAN) filter_roots(begin, end, lb, roots); +} + +#endif + + +CGAL_INLINE_FUNCTION +void jama_polynomial_compute_roots(const double *begin, const double *end, +double lb, double ub, +std::vector &roots) +{ + std::ptrdiff_t degree= end-begin-1; + switch( degree) { + case -1: + case 0: + break; + case 1: + compute_linear_roots(begin,end, lb, ub, roots); + break; + case 2: + compute_quadratic_roots(begin, end, lb, ub, roots); + break; + default: +#ifdef CGAL_HAVE_TNT + jama_compute_roots(begin, end, lb, ub, roots); +#else + CGAL_error(); +#endif + //jama_compute_roots(begin, end, lb, ub, roots); + } +} + + +CGAL_INLINE_FUNCTION +void jama_polynomial_compute_cleaned_roots(const double *begin, const double *end, +double lb, double ub, +std::vector &roots) +{ + std::ptrdiff_t degree= end-begin-1; + switch( degree) { + case -1: + case 0: + break; + case 1: + compute_linear_cleaned_roots(begin,end, lb, ub, roots); + break; + case 2: + compute_quadratic_cleaned_roots(begin, end, lb, ub, roots); + break; + default: +#ifdef CGAL_HAVE_TNT + jama_compute_roots(begin, end, lb, ub, roots); +#else + CGAL_error(); +#endif + } +} + + +} } } //namespace CGAL::POLYNOMIAL::internal diff --git a/Kinetic_data_structures/include/CGAL/Polynomial/internal/Turkowski_numeric_solvers_impl.h b/Kinetic_data_structures/include/CGAL/Polynomial/internal/Turkowski_numeric_solvers_impl.h new file mode 100644 index 00000000000..d79a15f981f --- /dev/null +++ b/Kinetic_data_structures/include/CGAL/Polynomial/internal/Turkowski_numeric_solvers_impl.h @@ -0,0 +1,467 @@ +// Copyright (c) 2005 Stanford University (USA). +// 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$ +// +// +// Author(s) : Daniel Russel + +#ifdef CGAL_HEADER_ONLY +#define CGAL_INLINE_FUNCTION inline +#else +#define CGAL_INLINE_FUNCTION +#endif + +#include +#include + +/*#ifdef _MSC_VER +#pragma warning(disable:1572) +#endif*/ + + +//#include "numeric_solvers_support.C" + +// Taken from http://www.worldserver.com/turk/opensource/ + +/* Copyright (C) 1978-1999 Ken Turkowski. + * + * All rights reserved. + * + * Warranty Information + * Even though I have reviewed this software, I make no warranty + * or representation, either express or implied, with respect to this + * software, its quality, accuracy, merchantability, or fitness for a + * particular purpose. As a result, this software is provided "as is," + * and you, its user, are assuming the entire risk as to its quality + * and accuracy. + * + * This code may be used and freely distributed as long as it includes + * this copyright notice and the above warranty information. + */ + +#include +#include + +namespace CGAL { namespace POLYNOMIAL { namespace internal { + +# define FLOAT double + +static const unsigned int MAXN= 55; +//# define PARAMFLOAT double_t + +/******************************************************************************* + * FindCubicRoots + * + * Solve: + * coeff[3] * x^3 + coeff[2] * x^2 + coeff[1] * x + coeff[0] = 0 + * + * returns: + * 3 - 3 real roots + * 1 - 1 real root (2 complex conjugate) + *******************************************************************************/ + +static long +FindCubicRoots(const FLOAT coeff[4], FLOAT x[3]) +{ + FLOAT a1 = coeff[2] / coeff[3]; + FLOAT a2 = coeff[1] / coeff[3]; + FLOAT a3 = coeff[0] / coeff[3]; + + double Q = (a1 * a1 - 3 * a2) / 9; + double R = (2 * a1 * a1 * a1 - 9 * a1 * a2 + 27 * a3) / 54; + double Qcubed = Q * Q * Q; + double d = Qcubed - R * R; + + /* Three real roots */ + if (d >= 0) { + double theta = std::acos(R / std::sqrt(Qcubed)); + double sqrtQ = std::sqrt(Q); + x[0] = -2 * sqrtQ * std::cos( theta / 3) - a1 / 3; + x[1] = -2 * sqrtQ * std::cos((theta + 2 * CGAL_PI) / 3) - a1 / 3; + x[2] = -2 * sqrtQ * std::cos((theta + 4 * CGAL_PI) / 3) - a1 / 3; + return (3); + } + + /* One real root */ + else { + double e = std::pow(std::sqrt(-d) + ::CGAL::abs(R), 1. / 3.); + if (R > 0) + e = -e; + x[0] = (e + Q / e) - a1 / 3.; + return (1); + } +} + + +/******************************************************************************* + * FindPolynomialRoots + * + * The Bairstow and Newton correction formulae are used for a simultaneous + * linear and quadratic iterated synthetic division. The coefficients of + * a polynomial of degree n are given as a[i] (i=0,i,..., n) where a[0] is + * the constant term. The coefficients are scaled by dividing them by + * their geometric mean. The Bairstow or Newton iteration method will + * nearly always converge to the number of figures carried, fig, either to + * root values or to their reciprocals. If the simultaneous Newton and + * Bairstow iteration fails to converge on root values or their + * reciprocals in maxiter iterations, the convergence requirement will be + * successively reduced by one decimal figure. This program anticipates + * and protects against loss of significance in the quadratic synthetic + * division. (Refer to "On Programming the Numerical Solution of + * Polynomial Equations," by K. W. Ellenberger, Commun. ACM 3 (Dec. 1960), + * 644-647.) The real and imaginary part of each root is stated as u[i] + * and v[i], respectively, together with the corresponding constant, + * conv[i], used in the convergence test. This program has been used + * successfully for over a year on the Bendix G15-D (Intercard System) and + * has recently been coded for the IBM 709 (Fortran system). + * + * ACM algorithm #30 - Numerical Solution of the Polynomial Equation + * K. W. Ellenberger + * Missle Division, North American Aviation, Downey, California + * Converted to C, modified, optimized, and structured by + * Ken Turkowski + * CADLINC, Inc., Palo Alto, California + *******************************************************************************/ + +static void +FindPolynomialRoots( + const FLOAT *a, /* Coefficients */ + FLOAT *u, /* Real component of each root */ + FLOAT *v, /* Imaginary component of each root */ + FLOAT *conv, /* Convergence constant associated with each root */ + register long n, /* Degree of polynomial (order-1) */ + long maxiter, /* Maximum number of iterations */ + long fig /* The number of decimal figures to be computed */ + ) +{ + int number_of_ITERATE=0; + int number_of_INIT=0; + CGAL_precondition(static_cast(fig) < MAXN); + int i; + register int j; + FLOAT h[MAXN + 3], b[MAXN + 3], c[MAXN + 3], d[MAXN + 3], e[MAXN + 3]; + /* [-2 : n] */ + FLOAT K, ps, qs, pt, qt, s, rev, r= std::numeric_limits::infinity(); + int t; + FLOAT p=std::numeric_limits::infinity(), q=std::numeric_limits::infinity(); + + /* Zero elements with negative indices */ + b[2 + -1] = b[2 + -2] = + c[2 + -1] = c[2 + -2] = + d[2 + -1] = d[2 + -2] = + e[2 + -1] = e[2 + -2] = + h[2 + -1] = h[2 + -2] = 0.0; + + /* Copy polynomial coefficients to working storage */ + for (j = n; j >= 0; j--) + h[2 + j] = *a++; /* Note reversal of coefficients */ + + t = 1; + K = std::pow(10.0, (double)(fig)); /* Relative accuracy */ + + for (; h[2 + n] == 0.0; n--) { /* Look for zero high-order coeff. */ + *u++ = 0.0; + *v++ = 0.0; + *conv++ = K; + } + + INIT: + ++number_of_INIT; + if (number_of_INIT > 1000) { + std::cerr << "Too many INITs" << std::flush; + return; + } + + if (n == 0) + return; + + ps = qs = pt = qt = s = 0.0; + rev = 1.0; + K = std::pow(10.0, (double)(fig)); + + if (n == 1) { + r = -h[2 + 1] / h[2 + 0]; + goto LINEAR; + } + + for (j = n; j >= 0; j--) /* Find geometric mean of coeff's */ + if (h[2 + j] != 0.0) + s += std::log( ::CGAL::abs(h[2 + j])); + s = std::exp(s / (n + 1)); + + for (j = n; j >= 0; j--) /* Normalize coeff's by mean */ + h[2 + j] /= s; + + if ( ::CGAL::abs(h[2 + 1] / h[2 + 0]) < ::CGAL::abs(h[2 + n - 1] / h[2 + n])) { + REVERSE: + t = -t; + for (j = (n - 1) / 2; j >= 0; j--) { + s = h[2 + j]; + h[2 + j] = h[2 + n - j]; + h[2 + n - j] = s; + } + } + if (qs != 0.0) { + p = ps; + q = qs; + } + else { + if (h[2 + n - 2] == 0.0) { + q = 1.0; + p = -2.0; + } + else { + q = h[2 + n] / h[2 + n - 2]; + p = (h[2 + n - 1] - q * h[2 + n - 3]) / h[2 + n - 2]; + } + if (n == 2) + goto QADRTIC; + r = 0.0; + } + ITERATE: + ++number_of_ITERATE; + if (number_of_ITERATE > 1000) { + std::cerr << "Too many ITERATEs" << std::flush; + return; + } + for (i = maxiter; i > 0; i--) { + + for (j = 0; j <= n; j++) { /* BAIRSTOW */ + b[2 + j] = h[2 + j] - p * b[2 + j - 1] - q * b[2 + j - 2]; + c[2 + j] = b[2 + j] - p * c[2 + j - 1] - q * c[2 + j - 2]; + } + if ((h[2 + n - 1] != 0.0) && (b[2 + n - 1] != 0.0)) { + if ( ::CGAL::abs(h[2 + n - 1] / b[2 + n - 1]) >= K) { + b[2 + n] = h[2 + n] - q * b[2 + n - 2]; + } + if (b[2 + n] == 0.0) + goto QADRTIC; + if (K < ::CGAL::abs(h[2 + n] / b[2 + n])) + goto QADRTIC; + } + + for (j = 0; j <= n; j++) { /* NEWTON */ + /* Calculate polynomial at r */ + d[2 + j] = h[2 + j] + r * d[2 + j - 1]; + /* Calculate derivative at r */ + e[2 + j] = d[2 + j] + r * e[2 + j - 1]; + } + if (d[2 + n] == 0.0) + goto LINEAR; + if (K < ::CGAL::abs(h[2 + n] / d[2 + n])) + goto LINEAR; + + c[2 + n - 1] = -p * c[2 + n - 2] - q * c[2 + n - 3]; + s = c[2 + n - 2] * c[2 + n - 2] - c[2 + n - 1] * c[2 + n - 3]; + if (s == 0.0) { + p -= 2.0; + q *= (q + 1.0); + } + else { + p += (b[2 + n - 1] * c[2 + n - 2] - b[2 + n] * c[2 + n - 3]) / s; + q += (-b[2 + n - 1] * c[2 + n - 1] + b[2 + n] * c[2 + n - 2]) / s; + } + if (e[2 + n - 1] == 0.0) + r -= 1.0; /* Minimum step */ + else + r -= d[2 + n] / e[2 + n - 1]; /* Newton's iteration */ + } + ps = pt; + qs = qt; + pt = p; + qt = q; + if (rev < 0.0) + K /= 10.0; + rev = -rev; + goto REVERSE; + + LINEAR: + if (t < 0) + r = 1.0 / r; + n--; + *u++ = r; + *v++ = 0.0; + *conv++ = K; + + for (j = n; j >= 0; j--) { /* Polynomial deflation by lin-nomial */ + if ((d[2 + j] != 0.0) && ( ::CGAL::abs(h[2 + j] / d[2 + j]) < K)) + h[2 + j] = d[2 + j]; + else + h[2 + j] = 0.0; + } + + if (n == 0) + return; + goto ITERATE; + + QADRTIC: + if (t < 0) { + p /= q; + q = 1.0 / q; + } + n -= 2; + + if (0.0 < (q - (p * p / 4.0))) { /* Two complex roots */ + *(u + 1) = *u = -p / 2.0; + u += 2; + s = sqrt(q - (p * p / 4.0)); + *v++ = s; + *v++ = -s; + } /* Two real roots */ + else { + s = std::sqrt(((p * p / 4.0)) - q); + if (p < 0.0) + *u++ = -p / 2.0 + s; + else + *u++ = -p / 2.0 - s; + *u = q / u[-1]; + ++u; // moved from lhs of before + *v++ = 0.0; + *v++ = 0.0; + } + *conv++ = K; + *conv++ = K; + + for (j = n; j >= 0; j--) { /* Polynomial deflation by quadratic */ + if ((b[2 + j] != 0.0) && ( ::CGAL::abs(h[2 + j] / b[2 + j]) < K)) + h[2 + j] = b[2 + j]; + else + h[2 + j] = 0.0; + } + goto INIT; +} + + +#undef MAXN + +template +static void Turkowski_polynomial_compute_roots_t(const double *begin, + const double *end, + double lb, double ub, + std::vector &roots) +{ + std::size_t numc= end-begin; + double rp[MAXN]; + double cp[MAXN]; + double cc[MAXN]; + + /*for (unsigned int i=0; i< numc; ++i){ + rp[i]= std::numeric_limits::infinity(); + }*/ + + for (unsigned int i=0; i< MAXN; ++i){ + cc[i]=std::numeric_limits::infinity(); + rp[i]=std::numeric_limits::infinity(); + cc[i]=std::numeric_limits::infinity(); + } + + FindPolynomialRoots(begin, rp, cp, cc, static_cast(numc)-1, 10*static_cast(numc), 40); + + /*if (CLEAN) { + lb-= .000005; + }*/ + double last= -std::numeric_limits::infinity(); + for (std::size_t i=0; i< numc-1; ++i) { + /* std::cout << "Trying " << rp[i] << "+" << std::setprecision(10) << cp[i] << "i " + << cc[i] << "\n";*/ + if (cc[i] > 10000 && root_is_good(rp[i], cp[i], lb, ub)) { + roots.push_back(rp[i]); + /*std::cout << "Good was " << rp[i] << "+" <()); + + if (CLEAN) filter_solver_roots(begin, end, lb, ub, last, roots); +} + +CGAL_INLINE_FUNCTION +void Turkowski_polynomial_compute_roots(const double *begin, const double *end, + double lb, double ub, + std::vector &roots) +{ + + std::ptrdiff_t degree= end-begin-1; + switch( degree) { + case -1: + case 0: + break; + case 1: + compute_linear_roots(begin,end, lb, ub, roots); + break; + case 2: + compute_quadratic_roots(begin, end, lb, ub, roots); + break; + case 3: + { + double rd[3]; + int numr= FindCubicRoots(begin, rd); + for (int i=numr-1; i>=0; --i) { + if (rd[i] >= lb && rd[i] < ub) roots.push_back(rd[i]); + } + std::sort(roots.begin(), roots.end(), std::greater()); + break; + } + default: + Turkowski_polynomial_compute_roots_t(begin, end, lb, ub, roots); + + } + +} + +CGAL_INLINE_FUNCTION +void Turkowski_polynomial_compute_cleaned_roots(const double *begin, const double *end, + double lb, double ub, + std::vector &roots) +{ + std::ptrdiff_t degree= end-begin-1; + switch( degree) { + case -1: + case 0: + break; + case 1: + compute_linear_cleaned_roots(begin,end, lb, ub, roots); + break; + case 2: + compute_quadratic_cleaned_roots(begin, end, lb, ub, roots); + break; + case 3: + { + double rd[3]; + int numr= FindCubicRoots(begin, rd); + double last=-std::numeric_limits::infinity(); + for (int i=numr-1; i>=0; --i) { + if (rd[i]< ub && rd[i] >= lb) roots.push_back(rd[i]); + if (rd[i] < lb && rd[i] > last){ + last=rd[i]; + } + } + std::sort(roots.begin(), roots.end(), std::greater()); + filter_solver_roots(begin, end, lb, ub, last, roots); + break; + } + default: + Turkowski_polynomial_compute_roots_t(begin, end, lb, ub, roots); + } +} + + +} } } //namespace CGAL::POLYNOMIAL::internal diff --git a/Kinetic_data_structures/include/CGAL/Polynomial/internal/numeric_solvers_impl.h b/Kinetic_data_structures/include/CGAL/Polynomial/internal/numeric_solvers_impl.h new file mode 100644 index 00000000000..198843140db --- /dev/null +++ b/Kinetic_data_structures/include/CGAL/Polynomial/internal/numeric_solvers_impl.h @@ -0,0 +1,138 @@ +// Copyright (c) 2005 Stanford University (USA). +// 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$ +// +// +// Author(s) : Daniel Russel + +#ifdef CGAL_HEADER_ONLY +#define CGAL_INLINE_FUNCTION inline +#else +#define CGAL_INLINE_FUNCTION +#endif + +#include +#include + +#ifdef CGAL_HAVE_TNT +#include +#include +#include +#endif + +#include +#include +#include + +//#include + +namespace CGAL { namespace POLYNOMIAL { namespace internal { +#if CGAL_HAVE_TNT +//static const double max_error_value =0.00005; + +template +static void jama_compute_roots(const NT *begin, const NT *end, NT lb, +NT ub, std::vector &roots) +{ + int degree= end-begin-1; + TNT::Array2D arr(degree, degree, 0.0); + for (int i=0; i< degree; ++i) { + arr[0][i]=-begin[degree-i-1]/begin[degree]; + } + for (int i=0; i+1< degree; ++i) { + arr[i+1][i]=1; + } + + JAMA::Eigenvalue ev(arr); + TNT::Array1D real, imag; + ev.getImagEigenvalues(imag); + ev.getRealEigenvalues(real); + CGAL_Polynomial_assertion(imag.dim1()== real.dim1()); + + /*NT tol; + if (CLEAN) tol=.00005; + else tol=0;*/ + + for (int i=0; i< real.dim1(); ++i) { + if (root_is_good(real[i], imag[i], lb-tol, ub)) { + roots.push_back(real[i]/*polish_root(begin, end, real[i])*/); + } else { + } + } + std::sort(roots.begin(), roots.end(), std::greater()); + if (CLEAN) filter_roots(begin, end, lb, roots); +} + +#endif + + +CGAL_INLINE_FUNCTION +void jama_polynomial_compute_roots(const double *begin, const double *end, +double lb, double ub, +std::vector &roots) +{ +#ifdef CGAL_HEADER_ONLY + int i = 0; +#endif + std::ptrdiff_t degree= endss-begin-1; + switch( degree) { + case -1: + case 0: + break; + case 1: + compute_linear_roots(begin,end, lb, ub, roots); + break; + case 2: + compute_quadratic_roots(begin, end, lb, ub, roots); + break; + default: +#ifdef CGAL_HAVE_TNT + jama_compute_roots(begin, end, lb, ub, roots); +#else + CGAL_error(); +#endif + //jama_compute_roots(begin, end, lb, ub, roots); + } +} + + +CGAL_INLINE_FUNCTION +void jama_polynomial_compute_cleaned_roots(const double *begin, const double *end, +double lb, double ub, +std::vector &roots) +{ + std::ptrdiff_t degree= end-begin-1; + switch( degree) { + case -1: + case 0: + break; + case 1: + compute_linear_cleaned_roots(begin,end, lb, ub, roots); + break; + case 2: + compute_quadratic_cleaned_roots(begin, end, lb, ub, roots); + break; + default: +#ifdef CGAL_HAVE_TNT + jama_compute_roots(begin, end, lb, ub, roots); +#else + CGAL_error(); +#endif + } +} + + +} } } //namespace CGAL::POLYNOMIAL::internal diff --git a/Kinetic_data_structures/include/CGAL/Polynomial/internal/numeric_solvers_support_impl.h b/Kinetic_data_structures/include/CGAL/Polynomial/internal/numeric_solvers_support_impl.h new file mode 100644 index 00000000000..516bd529e47 --- /dev/null +++ b/Kinetic_data_structures/include/CGAL/Polynomial/internal/numeric_solvers_support_impl.h @@ -0,0 +1,276 @@ +// Copyright (c) 2005 Stanford University (USA). +// 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$ +// +// +// Author(s) : Daniel Russel + + +#ifdef CGAL_HEADER_ONLY +#define CGAL_INLINE_FUNCTION inline +#else +#define CGAL_INLINE_FUNCTION +#endif + +#include +#include + +#include +#include +#include + +/*#ifdef _MSC_VER +#pragma warning(disable:1572) +#endif*/ + +namespace CGAL { namespace POLYNOMIAL { namespace internal { + +static double max_error_value=.00005; + +namespace { +template +inline void compute_quadratic_roots_t(const NT *begin, const NT * /*end*/, NT lb, NT ub, +std::vector &roots) +{ + NT max_error=0; + if (CLEAN) max_error=max_error_value; + CGAL_Polynomial_assertion(begin[2] != 0); + + NT desc= begin[1]*begin[1]-4*begin[0]*begin[2]; + if (desc <= 0) return; + + NT ur= (-begin[1]+sqrt(desc))/(2*begin[2]); + NT lr= (-begin[1]-sqrt(desc))/(2*begin[2]); + if (begin[2]< 0) std::swap(lr, ur); + if (lr > lb-max_error && lr < ub) { + roots.push_back(ur); + if (lr > lb-max_error && lr < ub && (!CLEAN || /*lr > lb+max_error ||*/ begin[2] >0)){ + roots.push_back(lr); + } + } else { + // only upper + if (ur > lb-max_error && ur < ub && (!CLEAN || /*ur > lb+max_error ||*/ begin[2] <0)){ + roots.push_back(ur); + } + + + } + + // drop even roots + /*if (ur >lb-max_error && ur < ub){ + if (!CLEAN || sign(begin[2]) != POSITIVE){ + roots.push_back(ur); + if (lr >lb-max_error && lr < ub){ + roots.push_back(lr); + } + } + } else { + if (lr > lb-max_error && lr &roots) +{ + return compute_quadratic_roots_t(begin, end, lb, ub, roots); +} + +CGAL_INLINE_FUNCTION +void compute_quadratic_cleaned_roots(const double *begin, const double *end, +double lb, double ub, std::vector &roots) +{ + return compute_quadratic_roots_t(begin, end, lb, ub, roots); +} + +namespace { +template +inline void compute_linear_roots_t(const NT *begin, const NT *, + NT lb, NT ub, + std::vector &roots) +{ + if (CLEAN && begin[1]>0 ) return; + //NT max_error=0; + //if (CLEAN) max_error=max_error_value; + NT r= -CGAL::to_double(begin[0]/begin[1]); + if ((CLEAN || r > lb) && r < ub) { + roots.push_back(r); + } +} +} + +CGAL_INLINE_FUNCTION +void compute_linear_roots(const double *begin, const double *end, +double lb, double ub, std::vector &roots) +{ + return compute_linear_roots_t(begin, end, lb, ub, roots); +} + +CGAL_INLINE_FUNCTION +void compute_linear_cleaned_roots(const double *begin, const double *end, + double lb, double ub, std::vector &roots) +{ + return compute_linear_roots_t(begin, end, lb, ub, roots); +} + + +namespace { +template + inline void filter_roots_t(const NT *begin, const NT *end, + NT lb, NT ub, NT last_root, std::vector &roots) +{ +// if we are not close to the current time, then we are fine + if (roots.empty()) return; + //if (roots.back() > lb+ .0005) return; + + //double eps= .0005; + /*double last_root=-std::numeric_limits::infinity(); + + while (roots.back() < lb) { + last_root= roots.back(); + roots.pop_back(); + }*/ + //if (roots.back() > lb+eps) return; + + //typedef CGAL_POLYNOMIAL_NS::Polynomial Fn; + + typedef CGAL_POLYNOMIAL_NS::Interval_polynomial IFn; + typedef CGAL_POLYNOMIAL_NS::internal::Derivative Diff; + typedef typename IFn::NT INT; + + + /*bool popped=false;*/ + // if the last valid root is closer than last, consider it as doubtful instead + if (lb-last_root > roots.back()-lb) { + last_root= roots.back(); + roots.pop_back(); + /*popped=true;*/ + } /*else { + last_root=lb; + }*/ + + INT vi; + if (last_root== -std::numeric_limits::infinity()){ + if ((end-begin)%2==1) { + vi= std::numeric_limits::infinity(); + } else { + vi = -*(end-1); + } + } else { + IFn fi(begin, end); + if (roots.empty()) { + Interval_arithmetic_guard guard; + if (ub== std::numeric_limits::infinity()) { + vi = 10*lb + 1000; + } else { + vi = fi((INT(lb)+INT(ub))/2.0); + } + } else { + Interval_arithmetic_guard guard; + vi = fi((INT(last_root)+INT(roots.back()))/2.0); + } + } + + if (vi.inf() > 0) { + return; + } else if (vi.sup() < 0){ + roots.push_back(last_root); + + /*if (!popped) { + IFn f(begin, end); + std::cout << "Adding last due to sign of " << vi << std::endl; + std::cout << "last " << last_root << " lb " << lb << " poly " << f << std::endl; + }*/ + return; + } + Interval_arithmetic_guard guard; + Diff dx; + IFn f(begin, end); + IFn d= dx(f); + + INT dv= d(roots.back()); + // switch + //while (sign(d(roots.back().representation()))== ZERO) d= dx_(d); + while (dv.inf() <= 0 && dv.sup() >= 0) { + d= dx(d); + dv= d(roots.back()); + } + // switch + //if (sign(d(roots.back().representation()))==POSITIVE){ + if (dv.sup() < 0) { + roots.push_back(last_root); + /*if (!popped) { + IFn f(begin, end); + std::cout << "Adding last due to deriv of " << vi << std::endl; + std::cout << "last " << last_root << " lb " << lb << " poly " << f << std::endl; + }*/ + } +} +} + +CGAL_INLINE_FUNCTION +void filter_solver_roots(const double *begin, const double *end, + double lb, double ub, double last, + std::vector &roots) +{ + filter_roots_t(begin, end, lb, ub, last, roots); +} + + +/*void polynomial_compute_roots(const double *begin, const double *end, double lb, + double ub, std::vector &roots){ +#ifdef POLYNOMIAL_USE_GSL + gsl_polynomial_compute_roots(begin, end, lb, ub, roots); +#else + jama_polynomial_compute_roots(begin, end, lb, ub, roots); +#endif +} + +void polynomial_compute_cleaned_roots(const double *begin, const double *end, double lb, + double ub, std::vector &roots){ +#ifdef POLYNOMIAL_USE_GSL +gsl_polynomial_compute_cleaned_roots(begin, end, lb, ub, roots); +#else +jama_polynomial_compute_cleaned_roots(begin, end, lb, ub, roots); +#endif +}*/ + +CGAL_INLINE_FUNCTION +double evaluate_polynomial(const double *b, const double *e, double t) +{ +#ifdef POLYNOMIAL_USE_GSL + return gsl_evaluate_polynomial(b, e, t); +#else + if (b==e) return 0.0; + + const double *rit=e-1; + double result = *rit; + --rit; + for (; rit != b-1; --rit) { + result *= t; + result += (*rit); + } + return result; +#endif +} + + +} } } //namespace CGAL::POLYNOMIAL::internal diff --git a/Kinetic_data_structures/include/CGAL/Tools/Log_impl.h b/Kinetic_data_structures/include/CGAL/Tools/Log_impl.h new file mode 100644 index 00000000000..566694f1c15 --- /dev/null +++ b/Kinetic_data_structures/include/CGAL/Tools/Log_impl.h @@ -0,0 +1,32 @@ +// Copyright (c) 2005 Stanford University (USA). +// 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$ +// +// +// Author(s) : Daniel Russel + +#ifndef CGAL_HEADER_ONLY + +#if defined(BOOST_MSVC) +# pragma warning(disable:4251) +#endif + +namespace CGAL { + +Log::State Log::state_; +} //namespace CGAL + +#endif // CGAL_HEADER_ONLY From 28cf600b2f3a83b7f00d39f9b0c93fe2099cc061 Mon Sep 17 00:00:00 2001 From: Guillaume Damiand Date: Mon, 15 Dec 2014 21:20:34 +0100 Subject: [PATCH 26/30] Inline only analyze.cpp --- CGAL_ImageIO/src/CGAL_ImageIO/analyze.cpp | 817 +----------------- CGAL_ImageIO/src/CGAL_ImageIO/analyze.h | 3 + CGAL_ImageIO/src/CGAL_ImageIO/analyze_impl.h | 848 +++++++++++++++++++ cppfiles.txt | 3 +- 4 files changed, 856 insertions(+), 815 deletions(-) create mode 100644 CGAL_ImageIO/src/CGAL_ImageIO/analyze_impl.h diff --git a/CGAL_ImageIO/src/CGAL_ImageIO/analyze.cpp b/CGAL_ImageIO/src/CGAL_ImageIO/analyze.cpp index fbc09641344..a40db327bba 100644 --- a/CGAL_ImageIO/src/CGAL_ImageIO/analyze.cpp +++ b/CGAL_ImageIO/src/CGAL_ImageIO/analyze.cpp @@ -19,820 +19,9 @@ // // Author(s) : ASCLEPIOS Project (INRIA Sophia-Antipolis), Laurent Rineau -#include +#ifndef CGAL_HEADER_ONLY #include "analyze.h" +#include "analyze_impl.h" -/* compile time endianness */ -/* replaced by _getEndianness() - see below -#if (defined (_ALPHA_) || defined (_LINUX_)) -#define ARCHITECTURE_ENDIANNESS END_LITTLE -#else -#define ARCHITECTURE_ENDIANNESS END_BIG -#endif -*/ - -/** Magic header for ANALYZE files written in little endian format */ -#define ANALYZE_LE_MAGIC "\000\000\001\134" -/** Magic header for ANALYZE files written in big endian format */ -#define ANALYZE_BE_MAGIC "\134\001\000\000" - -#define DT_NONE 0 -#define DT_UNKNOWN 0 /*Unknown data type*/ -#define DT_BINARY 1 /*Binary (1 bit per voxel)*/ -#define DT_UNSIGNED_CHAR 2 /*Unsigned character (8 bits per voxel)*/ -#define DT_SIGNED_SHORT 4 /*Signed short (16 bits per voxel)*/ -#define DT_SIGNED_INT 8 /*Signed integer (32 bits per voxel)*/ -#define DT_FLOAT 16 /*Floating point (32 bits per voxel)*/ -#define DT_COMPLEX 32 /*Complex (64 bits per voxel; 2 floating point numbers) */ -#define DT_DOUBLE 64 /*Double precision (64 bits per voxel)*/ -#define DT_RGB 128 /* */ -#define DT_ALL 255 /* */ - -struct header_key /* header_key */ - { /* off + size*/ - int sizeof_hdr; /* 0 + 4 */ - char data_type[10]; /* 4 + 10 */ - char db_name[18]; /* 14 + 18 */ - int extents; /* 32 + 4 */ - short int session_error; /* 36 + 2 */ - char regular; /* 38 + 1 */ - char hkey_un0; /* 39 + 1 */ - }; /* total=40 */ - -struct image_dimension /* image_dimension */ - { /* off + size*/ - short int dim[8]; /* 0 + 16 */ - char vox_units[4]; /* 16 + 4 */ - char cal_units[8]; /* 20 + 4 */ - short int unused1; /* 24 + 2 */ - short int datatype; /* 30 + 2 */ - short int bitpix; /* 32 + 2 */ - short int dim_un0; /* 34 + 2 */ - float pixdim[8]; /* 36 + 32 */ - /* - pixdim[] specifies the voxel dimensions: - pixdim[1] - voxel width - pixdim[2] - voxel height - pixdim[3] - interslice distance - ..etc - */ - float vox_offset; /* 68 + 4 */ - float funused1; /* 72 + 4 */ - float funused2; /* 76 + 4 */ - float funused3; /* 80 + 4 */ - float cal_max; /* 84 + 4 */ - float cal_min; /* 88 + 4 */ - int compressed; /* 92 + 4 */ - int verified; /* 96 + 4 */ - int glmax, glmin; /* 100 + 8 */ - }; /* total=108 */ - -struct data_history /* data_history */ - { /* off + size*/ - char descrip[80]; /* 0 + 80 */ - char aux_file[24]; /* 80 + 24 */ - char orient; /* 104 + 1 */ - char originator[10]; /* 105 + 10 */ - char generated[10]; /* 115 + 10 */ - char scannum[10]; /* 125 + 10 */ - char patient_id[10]; /* 135 + 10 */ - char exp_date[10]; /* 145 + 10 */ - char exp_time[10]; /* 155 + 10 */ - char hist_un0[3]; /* 165 + 3 */ - int views; /* 168 + 4 */ - int vols_added; /* 172 + 4 */ - int start_field; /* 176 + 4 */ - int field_skip; /* 180 + 4 */ - int omax,omin; /* 184 + 8 */ - int smax,smin; /* 192 + 8 */ - }; - - -struct dsr /* dsr */ - { /* off + size*/ - struct header_key hk; /* 0 + 40 */ - struct image_dimension dime; /* 40 + 108 */ - struct data_history hist; /* 148 + 200 */ - }; /* total=348 */ - - - - -/*---------------- _swapLong ------------------------------------------------*/ - -static void _swapLong( unsigned char *pntr) -{ - unsigned char b0, b1, b2, b3; - - b0 = *pntr; - b1 = *(pntr+1); - b2 = *(pntr+2); - b3 = *(pntr+3); - - *pntr = b3; - *(pntr+1) = b2; - *(pntr+2) = b1; - *(pntr+3) = b0; -} - -/*---------------- _swapShort -----------------------------------------------*/ - -static void _swapShort( unsigned char *pntr) -{ - unsigned char b0, b1; - - b0 = *pntr; - b1 = *(pntr+1); - - *pntr = b1; - *(pntr+1) = b0; -} - -/*---------------- _swapAnalyzeHdr ------------------------------------------*/ - -static void _swapAnalyzeHdr( struct dsr *pntr) -{ - - _swapLong((unsigned char*) &pntr->hk.sizeof_hdr) ; - _swapLong((unsigned char*) &pntr->hk.extents) ; - _swapShort((unsigned char*) &pntr->hk.session_error) ; - _swapShort((unsigned char*) &pntr->dime.dim[0]) ; - _swapShort((unsigned char*) &pntr->dime.dim[1]) ; - _swapShort((unsigned char*) &pntr->dime.dim[2]) ; - _swapShort((unsigned char*) &pntr->dime.dim[3]) ; - _swapShort((unsigned char*) &pntr->dime.dim[4]) ; - _swapShort((unsigned char*) &pntr->dime.dim[5]) ; - _swapShort((unsigned char*) &pntr->dime.dim[6]) ; - _swapShort((unsigned char*) &pntr->dime.dim[7]) ; - _swapShort((unsigned char*) &pntr->dime.unused1) ; - _swapShort((unsigned char*) &pntr->dime.datatype) ; - _swapShort((unsigned char*) &pntr->dime.bitpix) ; - _swapLong((unsigned char*) &pntr->dime.pixdim[0]) ; - _swapLong((unsigned char*) &pntr->dime.pixdim[1]) ; - _swapLong((unsigned char*) &pntr->dime.pixdim[2]) ; - _swapLong((unsigned char*) &pntr->dime.pixdim[3]) ; - _swapLong((unsigned char*) &pntr->dime.pixdim[4]) ; - _swapLong((unsigned char*) &pntr->dime.pixdim[5]) ; - _swapLong((unsigned char*) &pntr->dime.pixdim[6]) ; - _swapLong((unsigned char*) &pntr->dime.pixdim[7]) ; - _swapLong((unsigned char*) &pntr->dime.vox_offset) ; - _swapLong((unsigned char*) &pntr->dime.funused1) ; - _swapLong((unsigned char*) &pntr->dime.funused2) ; - _swapLong((unsigned char*) &pntr->dime.cal_max) ; - _swapLong((unsigned char*) &pntr->dime.cal_min) ; - _swapLong((unsigned char*) &pntr->dime.compressed) ; - _swapLong((unsigned char*) &pntr->dime.verified) ; - _swapShort((unsigned char*) &pntr->dime.dim_un0) ; - _swapLong((unsigned char*) &pntr->dime.glmax) ; - _swapLong((unsigned char*) &pntr->dime.glmin) ; -} -PTRIMAGE_FORMAT createAnalyzeFormat() { - PTRIMAGE_FORMAT f=(PTRIMAGE_FORMAT) ImageIO_alloc(sizeof(IMAGE_FORMAT)); - - f->testImageFormat=&testAnalyzeHeader; - f->readImageHeader=&readAnalyzeHeader; - f->writeImage=&writeAnalyze; - strcpy(f->fileExtension,".hdr,.hdr.gz,.img,.img.gz"); - strcpy(f->realName,"Analyze"); - return f; -} - -int testAnalyzeHeader(char *magic,const char *) { - /* opened image is an ANALYZE */ - if( !memcmp(magic,ANALYZE_LE_MAGIC,4) || - !memcmp(magic,ANALYZE_BE_MAGIC,4)) - return 0; - else - return -1; -} - -int writeAnalyze( char *name, _image* im) { - char *outputName; - int length, extLength=0, res; - - - length=strlen(name); - outputName= (char *)ImageIO_alloc(length+8); - - if ( strncmp( name+length-4, ".hdr", 4 ) == 0 ) { - extLength = 4; - } - else if ( strncmp( name+length-4, ".img", 4 ) == 0 ) { - extLength = 4; - } - else if ( strncmp( name+length-7, ".img.gz", 7 ) == 0 ) { - extLength = 7; - } - else if ( strncmp( name+length-7, ".hdr.gz", 7 ) == 0 ) { - extLength = 7; - } - - strncpy( outputName, name, length-extLength ); - if ( strncmp( name+length-7, ".hdr.gz", 7 ) == 0 ) - strcpy( outputName+length-extLength, ".hdr.gz" ); - else - strcpy( outputName+length-extLength, ".hdr" ); - - _openWriteImage(im, outputName); - if( !im->fd ) { - fprintf(stderr, "writeAnalyze: error: unable to open file \'%s\'\n", outputName); - if ( outputName != NULL ) ImageIO_free( outputName ); - return ImageIO_OPENING; - } - - res = writeAnalyzeHeader(im); - if ( res < 0 ) { - fprintf(stderr, "writeAnalyze: error: unable to write header of \'%s\'\n", - outputName); - if ( outputName != NULL ) ImageIO_free( outputName ); - ImageIO_close( im ); - im->fd = NULL; - im->openMode = OM_CLOSE; - return( res ); - } - - ImageIO_close(im); - - strncpy( outputName, name, length-extLength ); - if ( strncmp( name+length-3, ".gz", 3 ) == 0 ) { - strcpy( outputName+length-extLength, ".img.gz" ); - } - else { - strcpy( outputName+length-extLength, ".img" ); - } - - _openWriteImage(im, outputName); - - if( !im->fd ) { - fprintf(stderr, "writeAnalyze: error: unable to open file \'%s\'\n", outputName); - if ( outputName != NULL ) ImageIO_free( outputName ); - return ImageIO_OPENING; - } - - res = writeAnalyzeData(im); - if (res < 0) { - fprintf(stderr, "writeAnalyze: error: unable to write data in \'%s\'\n", - outputName ); - ImageIO_close( im ); - im->fd = NULL; - im->openMode = OM_CLOSE; - return( res ); - } - - if ( outputName != NULL ) ImageIO_free( outputName ); - ImageIO_close( im ); - im->fd = NULL; - im->openMode = OM_CLOSE; - - return ( res ); -} - -/* - return: - -1: error - 0: success - */ - -int _readAnalyzeHeader( _image* im, const char* name, - struct dsr *analyzeHeader ) -{ - - unsigned int i ; - /* compile time endianness */ - ENDIANNESS ARCHITECTURE_ENDIANNESS = _getEndianness(); - - if(im->openMode != OM_CLOSE) { - - ImageIO_read( im, analyzeHeader, sizeof(struct dsr) ); - - if( analyzeHeader->hk.sizeof_hdr == sizeof(struct dsr) ) - { - im->endianness = ARCHITECTURE_ENDIANNESS ; - } - else - { - _swapAnalyzeHdr( analyzeHeader ); - if( analyzeHeader->hk.sizeof_hdr != sizeof(struct dsr) ) - { - fprintf (stderr, - "_readAnalyzeHeader: error: unknown magic (%d)...\n", - analyzeHeader->hk.sizeof_hdr ); - return -1; - } - if( ARCHITECTURE_ENDIANNESS == END_LITTLE ) - { - im->endianness = END_BIG; - } - else - { - im->endianness = END_LITTLE; - } - } - - if ( analyzeHeader->dime.dim[0] > 4 ) { - fprintf (stderr, - "_readAnalyzeHeader: error: dimensionality not supported (%d)...\n", - analyzeHeader->dime.dim[0] ); - return -1; - } - - im->xdim = analyzeHeader->dime.dim[1]; - im->ydim = analyzeHeader->dime.dim[2]; - im->zdim = analyzeHeader->dime.dim[3]; - - /* 0 time-points is a convention for one volume only at MNI */ - /* Corrected by X. Pennec following a bug report by Irina Kezele at MNI */ - if( analyzeHeader->dime.dim[4] == 0 ){ - fprintf (stderr, - "_readAnalyzeHeader: warning: time dimension / number if volume (dim[4]) is 0. Assuming this means 1 (otherwise there would be no image...). \n"); - analyzeHeader->dime.dim[4] = 1; - } - - /* Analyze doesn't support vector images. - The forth dimension relates to time. */ - if( analyzeHeader->dime.dim[4] != 1 ) - { - fprintf (stderr, - "_readAnalyzeHeader: error: time dimension not supported (%d)...\n", - analyzeHeader->dime.dim[4] ); - return -1; - } - im->vectMode = VM_SCALAR; - - im->vx = analyzeHeader->dime.pixdim[1]; - im->vy = analyzeHeader->dime.pixdim[2]; - im->vz = analyzeHeader->dime.pixdim[3]; - - if( im->vx == 0.0 ) im->vx = 1.0 ; - if( im->vy == 0.0 ) im->vy = im->vx ; - if( im->vz == 0.0 ) im->vz = im->vy ; - - switch(analyzeHeader->dime.datatype) - { - case DT_BINARY: - case DT_UNSIGNED_CHAR: - case DT_SIGNED_SHORT: - case DT_SIGNED_INT: - case DT_FLOAT: - case DT_COMPLEX: - case DT_DOUBLE: - im->vdim = 1; - break ; - - case DT_RGB: - im->vdim = 3; - break ; - - default: - fprintf (stderr, - "_readAnalyzeHeader: error: data type not supported (%d)...\n", - analyzeHeader->dime.datatype ); - return -1; - } - - switch(analyzeHeader->dime.datatype) - { - case DT_BINARY: - case DT_UNSIGNED_CHAR: - case DT_SIGNED_SHORT: - case DT_SIGNED_INT: - case DT_RGB: - im->wordKind = WK_FIXED; - break ; - - case DT_FLOAT: - case DT_COMPLEX: - case DT_DOUBLE: - im->wordKind = WK_FLOAT; - break ; - - default: - fprintf (stderr, - "_readAnalyzeHeader: error: data type not supported (%d)...\n", - analyzeHeader->dime.datatype ); - return -1; - } - - switch(analyzeHeader->dime.datatype) - { - case DT_BINARY: - case DT_UNSIGNED_CHAR: - case DT_RGB: - im->sign = SGN_UNSIGNED; - break ; - - case DT_SIGNED_SHORT: - case DT_SIGNED_INT: - case DT_FLOAT: - case DT_COMPLEX: - case DT_DOUBLE: - im->sign = SGN_SIGNED; - break ; - - default: - fprintf (stderr, - "_readAnalyzeHeader: error: data type not supported (%d)...\n", - analyzeHeader->dime.datatype ); - return -1; - } - - im->wdim = analyzeHeader->dime.bitpix; - if( analyzeHeader->dime.datatype == DT_RGB ) - { - im->wdim /= 3 ; - } - if(im->wdim != 8 && im->wdim != 16 && im->wdim != 32 && im->wdim != 64) - { - fprintf (stderr, - "_readAnalyzeHeader: error: pixel size not supported (%d)...\n", - analyzeHeader->dime.bitpix ); - return -1; - } - im->wdim >>= 3 ; - - /* There are 17 optional data fields - be careful in the allocation - */ - im->nuser = 1 + 17 ; - im->user = (char **) ImageIO_alloc(im->nuser * sizeof(char *)); - for ( i=0; inuser; i++ ) im->user[i] = NULL; - i = 0 ; - - im->user[i] = (char *) ImageIO_alloc((strlen("Data lost in the Analyze -> ImageIO conversion:") + 1)); - sprintf( im->user[i++], "Data lost in the Analyze -> ImageIO conversion:" ); - - im->user[i] = (char *) ImageIO_alloc((strlen(" descrip: ") + 1 + strlen(analyzeHeader->hist.descrip) )); - sprintf( im->user[i++], " descrip: %s", analyzeHeader->hist.descrip ); - - im->user[i] = (char *) ImageIO_alloc((strlen(" aux_file: ") + 1 + strlen(analyzeHeader->hist.descrip) )); - sprintf( im->user[i++], " aux_file: %s", analyzeHeader->hist.descrip ); - - im->user[i] = (char *) ImageIO_alloc((strlen(" orient: ") + 1+ 2)); - sprintf( im->user[i++], " orient: %d", analyzeHeader->hist.orient ); - - im->user[i] = (char *) ImageIO_alloc((strlen(" originator: ") + 1 + strlen(analyzeHeader->hist.originator) )); - sprintf( im->user[i++], " originator: %s", analyzeHeader->hist.originator ); - - im->user[i] = (char *) ImageIO_alloc((strlen(" generated: ") + 1 + strlen(analyzeHeader->hist.generated) )); - sprintf( im->user[i++], " generated: %s", analyzeHeader->hist.generated ); - - im->user[i] = (char *) ImageIO_alloc((strlen(" scannum: ") + 1 + strlen(analyzeHeader->hist.scannum) )); - sprintf( im->user[i++], " scannum: %s", analyzeHeader->hist.scannum ); - - im->user[i] = (char *) ImageIO_alloc((strlen(" patient_id: ") + 1 + strlen(analyzeHeader->hist.patient_id) )); - sprintf( im->user[i++], " patient_id: %s", analyzeHeader->hist.patient_id ); - - im->user[i] = (char *) ImageIO_alloc((strlen(" exp_date: ") + 1 + strlen(analyzeHeader->hist.exp_date) )); - sprintf( im->user[i++], " exp_date: %s", analyzeHeader->hist.exp_date ); - - im->user[i] = (char *) ImageIO_alloc((strlen(" exp_time: ") + 1 + strlen(analyzeHeader->hist.exp_time) )); - sprintf( im->user[i++], " exp_time: %s", analyzeHeader->hist.exp_time ); - - /* A 32 bit int doesn't print on more than 11 chars */ - im->user[i] = (char *) ImageIO_alloc((strlen(" views: ") + 11 + 1)); - sprintf( im->user[i++], " views: %d", analyzeHeader->hist.views ); - - im->user[i] = (char *) ImageIO_alloc((strlen(" vols_added: ") + 11 + 1)); - sprintf( im->user[i++], " vols_added: %d", analyzeHeader->hist.vols_added ); - - im->user[i] = (char *) ImageIO_alloc((strlen(" start_field: ") + 11 + 1)); - sprintf( im->user[i++], " start_field: %d", analyzeHeader->hist.start_field ); - - im->user[i] = (char *) ImageIO_alloc((strlen(" field_skip: ") + 11 + 1)); - sprintf( im->user[i++], " field_skip: %d", analyzeHeader->hist.field_skip ); - - im->user[i] = (char *) ImageIO_alloc((strlen(" omax: ") + 11 + 1)); - sprintf( im->user[i++], " omax: %d", analyzeHeader->hist.omax ); - - im->user[i] = (char *) ImageIO_alloc((strlen(" omin: ") + 11 + 1)); - sprintf( im->user[i++], " omin: %d", analyzeHeader->hist.omin ); - - im->user[i] = (char *) ImageIO_alloc((strlen(" smax: ") + 11 + 1)); - sprintf( im->user[i++], " smax: %d", analyzeHeader->hist.smax ); - - im->user[i] = (char *) ImageIO_alloc((strlen(" smin: ") + 11 + 1)); - sprintf( im->user[i++], " smin: %d", analyzeHeader->hist.smin ); - - - /* header is read. close header file and open data file. */ - if( name != NULL ) { - - int length = strlen(name) ; - char* data_filename = (char *) ImageIO_alloc(length+4) ; - - if( strcmp( name+length-4, ".hdr" ) ) - { - fprintf (stderr, - "_readAnalyzeHeader: error: file header extension must be .hdr\n"); - ImageIO_free( data_filename ); - return -1; - } - - ImageIO_close(im); - - strcpy(data_filename,name); - strcpy(data_filename+length-3, "img.gz"); - _openReadImage(im,data_filename); - - if(!im->fd) { - - strcpy(data_filename,name); - strcpy(data_filename+length-3, "img"); - _openReadImage(im,data_filename); - if(!im->fd) { - fprintf(stderr, "_readAnalyzeHeader: error: unable to open data file \'%s\'\n", data_filename); - ImageIO_free( data_filename ); - return -1; - - } - } - ImageIO_free( data_filename ); - } - - /* check header validity */ - if(im->xdim > 0 && im->ydim > 0 && im->zdim > 0 && im->vdim > 0 && - im->vx > 0.0 && im->vy > 0.0 && im->vz > 0.0 && - (im->wordKind == WK_FLOAT || (im->wordKind == WK_FIXED && - im->sign != SGN_UNKNOWN)) && - im->endianness != END_UNKNOWN) { - return 0; - } - else return -1; - } - else return -1; -} - - - - - - - -int readAnalyzeHeader( const char* name, _image* im) -{ - struct dsr analyzeHeader ; - return( _readAnalyzeHeader( im, name, &analyzeHeader ) ); -} - - - -int -writeAnalyzeHeader( const _image* im ) -{ - const char *proc = "writeAnalyzeHeader"; - struct dsr hdr; - int i ; - int imin = 0; - int imax = 0; - - memset(&hdr,0, sizeof(struct dsr)); - - for(i=0;i<8;i++) { - hdr.dime.pixdim[i] = 0.0; - } - hdr.dime.vox_offset = 0.0; - hdr.dime.funused1 = 0.0; - hdr.dime.funused2 = 0.0; - hdr.dime.funused3 = 0.0; - hdr.dime.cal_max = 0.0; - hdr.dime.cal_min = 0.0; - - hdr.dime.dim[0] = 4; - hdr.dime.dim[1] = im->xdim; - hdr.dime.dim[2] = im->ydim; - hdr.dime.dim[3] = im->zdim; - hdr.dime.dim[4] = 1 ; - - if ( im->wordKind == WK_FIXED && im->sign == SGN_UNSIGNED ) { - if( im->wdim == 1 ) { - - if ( im->vdim == 1 ) { - hdr.dime.datatype = DT_UNSIGNED_CHAR ; - } - else if ( im->vdim == 3 ) { - hdr.dime.datatype = DT_RGB ; - } - else { - fprintf( stderr, "%s: unsupported image type\n", proc ); - return -1; - } - - { - unsigned char *buf = (unsigned char *)im->data; - int size = im->xdim * im->ydim * im->zdim * im->vdim; - imin = imax = *buf; - for (i=0; i *buf ) imin = *buf; - } - } - - } - else if ( im->wdim == 2 ) { - if ( im->vdim == 1 ) { - unsigned short int *buf = (unsigned short int*)im->data; - int size = im->xdim * im->ydim *im->zdim; - int i; - imin = imax = *buf; - for (i=0; i *buf ) imin = *buf; - } - if ( imax < 32768 ) { - hdr.dime.datatype = DT_SIGNED_SHORT ; - } - else { - fprintf( stderr, "%s: conversion from unsigned short to short impossible, max=%d\n", proc, imax ); - return -1; - } - } - else { - fprintf( stderr, "%s: unsupported image type\n", proc ); - return -1; - } - } - - else { - fprintf( stderr, "%s: unsupported image type\n", proc ); - return -1; - } - - } /* if ( im->wordKind == WK_FIXED && im->sign == SGN_UNSIGNED ) */ - - else if( im->wordKind == WK_FIXED && im->sign == SGN_SIGNED ) { - if ( im->vdim != 1 ) { - fprintf( stderr, "%s: unsupported image type\n", proc ); - return -1; - } - if( im->wdim == 2 ) { - short int *buf = (short int*)im->data; - int size = im->xdim * im->ydim *im->zdim; - int i; - imin = imax = *buf; - for (i=0; i *buf ) imin = *buf; - } - hdr.dime.datatype = DT_SIGNED_SHORT ; - } - else if( im->wdim == 4 ) { - int *buf = (int*)im->data; - int size = im->xdim * im->ydim *im->zdim; - int i; - imin = imax = *buf; - for (i=0; i *buf ) imin = *buf; - } - hdr.dime.datatype = DT_SIGNED_INT ; - } - else { - fprintf( stderr, "%s: unsupported image type\n", proc ); - return -1; - } - } - else if( im->wordKind == WK_FLOAT ) { - if ( im->vdim != 1 ) { - fprintf( stderr, "%s: unsupported image type\n", proc ); - return -1; - } - if( im->wdim == 4 ) { - hdr.dime.datatype = DT_FLOAT ; - } - else if( im->wdim == 8 ) { - hdr.dime.datatype = DT_DOUBLE ; - } - else { - fprintf( stderr, "%s: unsupported image type\n", proc ); - return -1; - } - } - else - { - fprintf( stderr, "%s: unsupported image type\n", proc ); - return -1; - } - - hdr.dime.bitpix = 8*im->wdim*im->vdim ; - - hdr.hk.regular = 'r'; - hdr.hk.sizeof_hdr = sizeof(struct dsr); - - /* this is probably bad and should be changed to the - real values, but I'm too lazy to do it now. AG */ - hdr.dime.glmax = 0 ; /* maximum voxel value */ - hdr.dime.glmin = 0 ; /* minimum voxel value */ - - /* corrected GM - */ - hdr.dime.glmax = imax ; /* maximum voxel value */ - hdr.dime.glmin = imin ; /* minimum voxel value */ - -/* Set the voxel dimension fields: - A value of 0.0 for these fields implies that the value is unknown. - Change these values to what is appropriate for your data - or pass additional command line arguments */ - - hdr.dime.pixdim[1] = (float)im->vx; - hdr.dime.pixdim[2] = (float)im->vy; - hdr.dime.pixdim[3] = (float)im->vz; - -/* Assume zero offset in .img file, byte at which pixel - data starts in the image file */ - - hdr.dime.vox_offset = 0.0; - -/* Planar Orientation; */ -/* Movie flag OFF: 0 = transverse, 1 = coronal, 2 = sagittal - Movie flag ON: 3 = transverse, 4 = coronal, 5 = sagittal */ - - hdr.hist.orient = 0; - -/* up to 3 characters for the voxels units label; i.e. mm., um., cm. */ - - strcpy(hdr.dime.vox_units,"mm."); - -/* up to 7 characters for the calibration units label; i.e. HU */ - - strcpy(hdr.dime.cal_units," "); - -/* Calibration maximum and minimum values; - values of 0.0 for both fields imply that no - calibration max and min values are used */ - - hdr.dime.cal_max = 0.0; - hdr.dime.cal_min = 0.0; - - if(ImageIO_write(im, &hdr, sizeof(struct dsr)) !=sizeof(struct dsr) ) - return -1; - - return 1 ; -} - - - - - -/* Writes the given image body in an already opened file.*/ -int writeAnalyzeData(const _image *im) { - unsigned int lineSize = im->wdim * im->xdim * im->vdim ; - unsigned long size = lineSize * im->ydim * im->zdim; - unsigned int nwrt ; - - if(im->openMode != OM_CLOSE) { - -#ifdef _REVERSE_LINES_IN_ANALYZE_ - char* data = (char *)im->data ; - char* buf = data + size - lineSize ; - - while( buf >= data ) - { - nwrt = ImageIO_write(im, buf, lineSize); - if(nwrt != lineSize) return -1; - buf -= lineSize ; - } -#else - nwrt = ImageIO_write(im, im->data, size); - if(nwrt != size) return -1; -#endif - - return 1 ; - } - else return -1; -} - - -/* Writes the given image body in an already opened file.*/ -int printAnalyzeHeader( const char* name ) -{ - _image *im; - struct dsr analyzeHeader ; - - im = _initImage(); - _openReadImage(im, name); - if(!im->fd) { - fprintf(stderr, "printAnalyzeHeader: error: unable to open file \'%s\'\n", name); - _freeImage(im); - return -1; - } - - if ( _readAnalyzeHeader( im, name, &analyzeHeader ) != 1 ) { - fprintf(stderr, "printAnalyzeHeader: error: unable to read header in file \'%s\'\n", name); - _freeImage(im); - return -1; - } - - - - - - ImageIO_close(im); - im->fd = NULL; - im->openMode = OM_CLOSE; - _freeImage(im); - return( 1 ); - - -} +#endif // CGAL_HEADER_ONLY diff --git a/CGAL_ImageIO/src/CGAL_ImageIO/analyze.h b/CGAL_ImageIO/src/CGAL_ImageIO/analyze.h index c4d88543b3f..a2568bf1df5 100644 --- a/CGAL_ImageIO/src/CGAL_ImageIO/analyze.h +++ b/CGAL_ImageIO/src/CGAL_ImageIO/analyze.h @@ -67,5 +67,8 @@ int writeAnalyzeHeader( const _image* im ) ; */ int writeAnalyzeData( const _image* im ) ; +#ifdef CGAL_HEADER_ONLY +#include "analyse_impl.h" +#endif // CGAL_HEADER_ONLY #endif diff --git a/CGAL_ImageIO/src/CGAL_ImageIO/analyze_impl.h b/CGAL_ImageIO/src/CGAL_ImageIO/analyze_impl.h new file mode 100644 index 00000000000..10d082bbaa2 --- /dev/null +++ b/CGAL_ImageIO/src/CGAL_ImageIO/analyze_impl.h @@ -0,0 +1,848 @@ +// Copyright (c) 2005-2008 ASCLEPIOS Project, INRIA Sophia-Antipolis (France) +// All rights reserved. +// +// This file is part of the ImageIO Library, and as been adapted for +// 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. +// +// These files are 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) : ASCLEPIOS Project (INRIA Sophia-Antipolis), Laurent Rineau + +#ifdef CGAL_HEADER_ONLY +#define CGAL_INLINE_FUNCTION inline +#else +#define CGAL_INLINE_FUNCTION +#endif + +/* compile time endianness */ +/* replaced by _getEndianness() + see below +#if (defined (_ALPHA_) || defined (_LINUX_)) +#define ARCHITECTURE_ENDIANNESS END_LITTLE +#else +#define ARCHITECTURE_ENDIANNESS END_BIG +#endif +*/ + +/** Magic header for ANALYZE files written in little endian format */ +#define ANALYZE_LE_MAGIC "\000\000\001\134" +/** Magic header for ANALYZE files written in big endian format */ +#define ANALYZE_BE_MAGIC "\134\001\000\000" + +#define DT_NONE 0 +#define DT_UNKNOWN 0 /*Unknown data type*/ +#define DT_BINARY 1 /*Binary (1 bit per voxel)*/ +#define DT_UNSIGNED_CHAR 2 /*Unsigned character (8 bits per voxel)*/ +#define DT_SIGNED_SHORT 4 /*Signed short (16 bits per voxel)*/ +#define DT_SIGNED_INT 8 /*Signed integer (32 bits per voxel)*/ +#define DT_FLOAT 16 /*Floating point (32 bits per voxel)*/ +#define DT_COMPLEX 32 /*Complex (64 bits per voxel; 2 floating point numbers) */ +#define DT_DOUBLE 64 /*Double precision (64 bits per voxel)*/ +#define DT_RGB 128 /* */ +#define DT_ALL 255 /* */ + +struct header_key /* header_key */ + { /* off + size*/ + int sizeof_hdr; /* 0 + 4 */ + char data_type[10]; /* 4 + 10 */ + char db_name[18]; /* 14 + 18 */ + int extents; /* 32 + 4 */ + short int session_error; /* 36 + 2 */ + char regular; /* 38 + 1 */ + char hkey_un0; /* 39 + 1 */ + }; /* total=40 */ + +struct image_dimension /* image_dimension */ + { /* off + size*/ + short int dim[8]; /* 0 + 16 */ + char vox_units[4]; /* 16 + 4 */ + char cal_units[8]; /* 20 + 4 */ + short int unused1; /* 24 + 2 */ + short int datatype; /* 30 + 2 */ + short int bitpix; /* 32 + 2 */ + short int dim_un0; /* 34 + 2 */ + float pixdim[8]; /* 36 + 32 */ + /* + pixdim[] specifies the voxel dimensions: + pixdim[1] - voxel width + pixdim[2] - voxel height + pixdim[3] - interslice distance + ..etc + */ + float vox_offset; /* 68 + 4 */ + float funused1; /* 72 + 4 */ + float funused2; /* 76 + 4 */ + float funused3; /* 80 + 4 */ + float cal_max; /* 84 + 4 */ + float cal_min; /* 88 + 4 */ + int compressed; /* 92 + 4 */ + int verified; /* 96 + 4 */ + int glmax, glmin; /* 100 + 8 */ + }; /* total=108 */ + +struct data_history /* data_history */ + { /* off + size*/ + char descrip[80]; /* 0 + 80 */ + char aux_file[24]; /* 80 + 24 */ + char orient; /* 104 + 1 */ + char originator[10]; /* 105 + 10 */ + char generated[10]; /* 115 + 10 */ + char scannum[10]; /* 125 + 10 */ + char patient_id[10]; /* 135 + 10 */ + char exp_date[10]; /* 145 + 10 */ + char exp_time[10]; /* 155 + 10 */ + char hist_un0[3]; /* 165 + 3 */ + int views; /* 168 + 4 */ + int vols_added; /* 172 + 4 */ + int start_field; /* 176 + 4 */ + int field_skip; /* 180 + 4 */ + int omax,omin; /* 184 + 8 */ + int smax,smin; /* 192 + 8 */ + }; + + +struct dsr /* dsr */ + { /* off + size*/ + struct header_key hk; /* 0 + 40 */ + struct image_dimension dime; /* 40 + 108 */ + struct data_history hist; /* 148 + 200 */ + }; /* total=348 */ + + + + +/*---------------- _swapLong ------------------------------------------------*/ +CGAL_INLINE_FUNCTION +static void _swapLong( unsigned char *pntr) +{ + unsigned char b0, b1, b2, b3; + + b0 = *pntr; + b1 = *(pntr+1); + b2 = *(pntr+2); + b3 = *(pntr+3); + + *pntr = b3; + *(pntr+1) = b2; + *(pntr+2) = b1; + *(pntr+3) = b0; +} + +/*---------------- _swapShort -----------------------------------------------*/ +CGAL_INLINE_FUNCTION +static void _swapShort( unsigned char *pntr) +{ + unsigned char b0, b1; + + b0 = *pntr; + b1 = *(pntr+1); + + *pntr = b1; + *(pntr+1) = b0; +} + +/*---------------- _swapAnalyzeHdr ------------------------------------------*/ +CGAL_INLINE_FUNCTION +static void _swapAnalyzeHdr( struct dsr *pntr) +{ + + _swapLong((unsigned char*) &pntr->hk.sizeof_hdr) ; + _swapLong((unsigned char*) &pntr->hk.extents) ; + _swapShort((unsigned char*) &pntr->hk.session_error) ; + _swapShort((unsigned char*) &pntr->dime.dim[0]) ; + _swapShort((unsigned char*) &pntr->dime.dim[1]) ; + _swapShort((unsigned char*) &pntr->dime.dim[2]) ; + _swapShort((unsigned char*) &pntr->dime.dim[3]) ; + _swapShort((unsigned char*) &pntr->dime.dim[4]) ; + _swapShort((unsigned char*) &pntr->dime.dim[5]) ; + _swapShort((unsigned char*) &pntr->dime.dim[6]) ; + _swapShort((unsigned char*) &pntr->dime.dim[7]) ; + _swapShort((unsigned char*) &pntr->dime.unused1) ; + _swapShort((unsigned char*) &pntr->dime.datatype) ; + _swapShort((unsigned char*) &pntr->dime.bitpix) ; + _swapLong((unsigned char*) &pntr->dime.pixdim[0]) ; + _swapLong((unsigned char*) &pntr->dime.pixdim[1]) ; + _swapLong((unsigned char*) &pntr->dime.pixdim[2]) ; + _swapLong((unsigned char*) &pntr->dime.pixdim[3]) ; + _swapLong((unsigned char*) &pntr->dime.pixdim[4]) ; + _swapLong((unsigned char*) &pntr->dime.pixdim[5]) ; + _swapLong((unsigned char*) &pntr->dime.pixdim[6]) ; + _swapLong((unsigned char*) &pntr->dime.pixdim[7]) ; + _swapLong((unsigned char*) &pntr->dime.vox_offset) ; + _swapLong((unsigned char*) &pntr->dime.funused1) ; + _swapLong((unsigned char*) &pntr->dime.funused2) ; + _swapLong((unsigned char*) &pntr->dime.cal_max) ; + _swapLong((unsigned char*) &pntr->dime.cal_min) ; + _swapLong((unsigned char*) &pntr->dime.compressed) ; + _swapLong((unsigned char*) &pntr->dime.verified) ; + _swapShort((unsigned char*) &pntr->dime.dim_un0) ; + _swapLong((unsigned char*) &pntr->dime.glmax) ; + _swapLong((unsigned char*) &pntr->dime.glmin) ; +} + +CGAL_INLINE_FUNCTION +PTRIMAGE_FORMAT createAnalyzeFormat() { + PTRIMAGE_FORMAT f=(PTRIMAGE_FORMAT) ImageIO_alloc(sizeof(IMAGE_FORMAT)); + + f->testImageFormat=&testAnalyzeHeader; + f->readImageHeader=&readAnalyzeHeader; + f->writeImage=&writeAnalyze; + strcpy(f->fileExtension,".hdr,.hdr.gz,.img,.img.gz"); + strcpy(f->realName,"Analyze"); + return f; +} + +CGAL_INLINE_FUNCTION +int testAnalyzeHeader(char *magic,const char *) { + /* opened image is an ANALYZE */ + if( !memcmp(magic,ANALYZE_LE_MAGIC,4) || + !memcmp(magic,ANALYZE_BE_MAGIC,4)) + return 0; + else + return -1; +} + +CGAL_INLINE_FUNCTION +int writeAnalyze( char *name, _image* im) { + char *outputName; + int length, extLength=0, res; + + + length=strlen(name); + outputName= (char *)ImageIO_alloc(length+8); + + if ( strncmp( name+length-4, ".hdr", 4 ) == 0 ) { + extLength = 4; + } + else if ( strncmp( name+length-4, ".img", 4 ) == 0 ) { + extLength = 4; + } + else if ( strncmp( name+length-7, ".img.gz", 7 ) == 0 ) { + extLength = 7; + } + else if ( strncmp( name+length-7, ".hdr.gz", 7 ) == 0 ) { + extLength = 7; + } + + strncpy( outputName, name, length-extLength ); + if ( strncmp( name+length-7, ".hdr.gz", 7 ) == 0 ) + strcpy( outputName+length-extLength, ".hdr.gz" ); + else + strcpy( outputName+length-extLength, ".hdr" ); + + _openWriteImage(im, outputName); + if( !im->fd ) { + fprintf(stderr, "writeAnalyze: error: unable to open file \'%s\'\n", outputName); + if ( outputName != NULL ) ImageIO_free( outputName ); + return ImageIO_OPENING; + } + + res = writeAnalyzeHeader(im); + if ( res < 0 ) { + fprintf(stderr, "writeAnalyze: error: unable to write header of \'%s\'\n", + outputName); + if ( outputName != NULL ) ImageIO_free( outputName ); + ImageIO_close( im ); + im->fd = NULL; + im->openMode = OM_CLOSE; + return( res ); + } + + ImageIO_close(im); + + strncpy( outputName, name, length-extLength ); + if ( strncmp( name+length-3, ".gz", 3 ) == 0 ) { + strcpy( outputName+length-extLength, ".img.gz" ); + } + else { + strcpy( outputName+length-extLength, ".img" ); + } + + _openWriteImage(im, outputName); + + if( !im->fd ) { + fprintf(stderr, "writeAnalyze: error: unable to open file \'%s\'\n", outputName); + if ( outputName != NULL ) ImageIO_free( outputName ); + return ImageIO_OPENING; + } + + res = writeAnalyzeData(im); + if (res < 0) { + fprintf(stderr, "writeAnalyze: error: unable to write data in \'%s\'\n", + outputName ); + ImageIO_close( im ); + im->fd = NULL; + im->openMode = OM_CLOSE; + return( res ); + } + + if ( outputName != NULL ) ImageIO_free( outputName ); + ImageIO_close( im ); + im->fd = NULL; + im->openMode = OM_CLOSE; + + return ( res ); +} + +/* + return: + -1: error + 0: success + */ + +CGAL_INLINE_FUNCTION +int _readAnalyzeHeader( _image* im, const char* name, + struct dsr *analyzeHeader ) +{ + + unsigned int i ; + /* compile time endianness */ + ENDIANNESS ARCHITECTURE_ENDIANNESS = _getEndianness(); + + if(im->openMode != OM_CLOSE) { + + ImageIO_read( im, analyzeHeader, sizeof(struct dsr) ); + + if( analyzeHeader->hk.sizeof_hdr == sizeof(struct dsr) ) + { + im->endianness = ARCHITECTURE_ENDIANNESS ; + } + else + { + _swapAnalyzeHdr( analyzeHeader ); + if( analyzeHeader->hk.sizeof_hdr != sizeof(struct dsr) ) + { + fprintf (stderr, + "_readAnalyzeHeader: error: unknown magic (%d)...\n", + analyzeHeader->hk.sizeof_hdr ); + return -1; + } + if( ARCHITECTURE_ENDIANNESS == END_LITTLE ) + { + im->endianness = END_BIG; + } + else + { + im->endianness = END_LITTLE; + } + } + + if ( analyzeHeader->dime.dim[0] > 4 ) { + fprintf (stderr, + "_readAnalyzeHeader: error: dimensionality not supported (%d)...\n", + analyzeHeader->dime.dim[0] ); + return -1; + } + + im->xdim = analyzeHeader->dime.dim[1]; + im->ydim = analyzeHeader->dime.dim[2]; + im->zdim = analyzeHeader->dime.dim[3]; + + /* 0 time-points is a convention for one volume only at MNI */ + /* Corrected by X. Pennec following a bug report by Irina Kezele at MNI */ + if( analyzeHeader->dime.dim[4] == 0 ){ + fprintf (stderr, + "_readAnalyzeHeader: warning: time dimension / number if volume (dim[4]) is 0. Assuming this means 1 (otherwise there would be no image...). \n"); + analyzeHeader->dime.dim[4] = 1; + } + + /* Analyze doesn't support vector images. + The forth dimension relates to time. */ + if( analyzeHeader->dime.dim[4] != 1 ) + { + fprintf (stderr, + "_readAnalyzeHeader: error: time dimension not supported (%d)...\n", + analyzeHeader->dime.dim[4] ); + return -1; + } + im->vectMode = VM_SCALAR; + + im->vx = analyzeHeader->dime.pixdim[1]; + im->vy = analyzeHeader->dime.pixdim[2]; + im->vz = analyzeHeader->dime.pixdim[3]; + + if( im->vx == 0.0 ) im->vx = 1.0 ; + if( im->vy == 0.0 ) im->vy = im->vx ; + if( im->vz == 0.0 ) im->vz = im->vy ; + + switch(analyzeHeader->dime.datatype) + { + case DT_BINARY: + case DT_UNSIGNED_CHAR: + case DT_SIGNED_SHORT: + case DT_SIGNED_INT: + case DT_FLOAT: + case DT_COMPLEX: + case DT_DOUBLE: + im->vdim = 1; + break ; + + case DT_RGB: + im->vdim = 3; + break ; + + default: + fprintf (stderr, + "_readAnalyzeHeader: error: data type not supported (%d)...\n", + analyzeHeader->dime.datatype ); + return -1; + } + + switch(analyzeHeader->dime.datatype) + { + case DT_BINARY: + case DT_UNSIGNED_CHAR: + case DT_SIGNED_SHORT: + case DT_SIGNED_INT: + case DT_RGB: + im->wordKind = WK_FIXED; + break ; + + case DT_FLOAT: + case DT_COMPLEX: + case DT_DOUBLE: + im->wordKind = WK_FLOAT; + break ; + + default: + fprintf (stderr, + "_readAnalyzeHeader: error: data type not supported (%d)...\n", + analyzeHeader->dime.datatype ); + return -1; + } + + switch(analyzeHeader->dime.datatype) + { + case DT_BINARY: + case DT_UNSIGNED_CHAR: + case DT_RGB: + im->sign = SGN_UNSIGNED; + break ; + + case DT_SIGNED_SHORT: + case DT_SIGNED_INT: + case DT_FLOAT: + case DT_COMPLEX: + case DT_DOUBLE: + im->sign = SGN_SIGNED; + break ; + + default: + fprintf (stderr, + "_readAnalyzeHeader: error: data type not supported (%d)...\n", + analyzeHeader->dime.datatype ); + return -1; + } + + im->wdim = analyzeHeader->dime.bitpix; + if( analyzeHeader->dime.datatype == DT_RGB ) + { + im->wdim /= 3 ; + } + if(im->wdim != 8 && im->wdim != 16 && im->wdim != 32 && im->wdim != 64) + { + fprintf (stderr, + "_readAnalyzeHeader: error: pixel size not supported (%d)...\n", + analyzeHeader->dime.bitpix ); + return -1; + } + im->wdim >>= 3 ; + + /* There are 17 optional data fields + be careful in the allocation + */ + im->nuser = 1 + 17 ; + im->user = (char **) ImageIO_alloc(im->nuser * sizeof(char *)); + for ( i=0; inuser; i++ ) im->user[i] = NULL; + i = 0 ; + + im->user[i] = (char *) ImageIO_alloc((strlen("Data lost in the Analyze -> ImageIO conversion:") + 1)); + sprintf( im->user[i++], "Data lost in the Analyze -> ImageIO conversion:" ); + + im->user[i] = (char *) ImageIO_alloc((strlen(" descrip: ") + 1 + strlen(analyzeHeader->hist.descrip) )); + sprintf( im->user[i++], " descrip: %s", analyzeHeader->hist.descrip ); + + im->user[i] = (char *) ImageIO_alloc((strlen(" aux_file: ") + 1 + strlen(analyzeHeader->hist.descrip) )); + sprintf( im->user[i++], " aux_file: %s", analyzeHeader->hist.descrip ); + + im->user[i] = (char *) ImageIO_alloc((strlen(" orient: ") + 1+ 2)); + sprintf( im->user[i++], " orient: %d", analyzeHeader->hist.orient ); + + im->user[i] = (char *) ImageIO_alloc((strlen(" originator: ") + 1 + strlen(analyzeHeader->hist.originator) )); + sprintf( im->user[i++], " originator: %s", analyzeHeader->hist.originator ); + + im->user[i] = (char *) ImageIO_alloc((strlen(" generated: ") + 1 + strlen(analyzeHeader->hist.generated) )); + sprintf( im->user[i++], " generated: %s", analyzeHeader->hist.generated ); + + im->user[i] = (char *) ImageIO_alloc((strlen(" scannum: ") + 1 + strlen(analyzeHeader->hist.scannum) )); + sprintf( im->user[i++], " scannum: %s", analyzeHeader->hist.scannum ); + + im->user[i] = (char *) ImageIO_alloc((strlen(" patient_id: ") + 1 + strlen(analyzeHeader->hist.patient_id) )); + sprintf( im->user[i++], " patient_id: %s", analyzeHeader->hist.patient_id ); + + im->user[i] = (char *) ImageIO_alloc((strlen(" exp_date: ") + 1 + strlen(analyzeHeader->hist.exp_date) )); + sprintf( im->user[i++], " exp_date: %s", analyzeHeader->hist.exp_date ); + + im->user[i] = (char *) ImageIO_alloc((strlen(" exp_time: ") + 1 + strlen(analyzeHeader->hist.exp_time) )); + sprintf( im->user[i++], " exp_time: %s", analyzeHeader->hist.exp_time ); + + /* A 32 bit int doesn't print on more than 11 chars */ + im->user[i] = (char *) ImageIO_alloc((strlen(" views: ") + 11 + 1)); + sprintf( im->user[i++], " views: %d", analyzeHeader->hist.views ); + + im->user[i] = (char *) ImageIO_alloc((strlen(" vols_added: ") + 11 + 1)); + sprintf( im->user[i++], " vols_added: %d", analyzeHeader->hist.vols_added ); + + im->user[i] = (char *) ImageIO_alloc((strlen(" start_field: ") + 11 + 1)); + sprintf( im->user[i++], " start_field: %d", analyzeHeader->hist.start_field ); + + im->user[i] = (char *) ImageIO_alloc((strlen(" field_skip: ") + 11 + 1)); + sprintf( im->user[i++], " field_skip: %d", analyzeHeader->hist.field_skip ); + + im->user[i] = (char *) ImageIO_alloc((strlen(" omax: ") + 11 + 1)); + sprintf( im->user[i++], " omax: %d", analyzeHeader->hist.omax ); + + im->user[i] = (char *) ImageIO_alloc((strlen(" omin: ") + 11 + 1)); + sprintf( im->user[i++], " omin: %d", analyzeHeader->hist.omin ); + + im->user[i] = (char *) ImageIO_alloc((strlen(" smax: ") + 11 + 1)); + sprintf( im->user[i++], " smax: %d", analyzeHeader->hist.smax ); + + im->user[i] = (char *) ImageIO_alloc((strlen(" smin: ") + 11 + 1)); + sprintf( im->user[i++], " smin: %d", analyzeHeader->hist.smin ); + + + /* header is read. close header file and open data file. */ + if( name != NULL ) { + + int length = strlen(name) ; + char* data_filename = (char *) ImageIO_alloc(length+4) ; + + if( strcmp( name+length-4, ".hdr" ) ) + { + fprintf (stderr, + "_readAnalyzeHeader: error: file header extension must be .hdr\n"); + ImageIO_free( data_filename ); + return -1; + } + + ImageIO_close(im); + + strcpy(data_filename,name); + strcpy(data_filename+length-3, "img.gz"); + _openReadImage(im,data_filename); + + if(!im->fd) { + + strcpy(data_filename,name); + strcpy(data_filename+length-3, "img"); + _openReadImage(im,data_filename); + if(!im->fd) { + fprintf(stderr, "_readAnalyzeHeader: error: unable to open data file \'%s\'\n", data_filename); + ImageIO_free( data_filename ); + return -1; + + } + } + ImageIO_free( data_filename ); + } + + /* check header validity */ + if(im->xdim > 0 && im->ydim > 0 && im->zdim > 0 && im->vdim > 0 && + im->vx > 0.0 && im->vy > 0.0 && im->vz > 0.0 && + (im->wordKind == WK_FLOAT || (im->wordKind == WK_FIXED && + im->sign != SGN_UNKNOWN)) && + im->endianness != END_UNKNOWN) { + return 0; + } + else return -1; + } + else return -1; +} + + + + + + +CGAL_INLINE_FUNCTION +int readAnalyzeHeader( const char* name, _image* im) +{ + struct dsr analyzeHeader ; + return( _readAnalyzeHeader( im, name, &analyzeHeader ) ); +} + + + +CGAL_INLINE_FUNCTION +int +writeAnalyzeHeader( const _image* im ) +{ + const char *proc = "writeAnalyzeHeader"; + struct dsr hdr; + int i ; + int imin = 0; + int imax = 0; + + memset(&hdr,0, sizeof(struct dsr)); + + for(i=0;i<8;i++) { + hdr.dime.pixdim[i] = 0.0; + } + hdr.dime.vox_offset = 0.0; + hdr.dime.funused1 = 0.0; + hdr.dime.funused2 = 0.0; + hdr.dime.funused3 = 0.0; + hdr.dime.cal_max = 0.0; + hdr.dime.cal_min = 0.0; + + hdr.dime.dim[0] = 4; + hdr.dime.dim[1] = im->xdim; + hdr.dime.dim[2] = im->ydim; + hdr.dime.dim[3] = im->zdim; + hdr.dime.dim[4] = 1 ; + + if ( im->wordKind == WK_FIXED && im->sign == SGN_UNSIGNED ) { + if( im->wdim == 1 ) { + + if ( im->vdim == 1 ) { + hdr.dime.datatype = DT_UNSIGNED_CHAR ; + } + else if ( im->vdim == 3 ) { + hdr.dime.datatype = DT_RGB ; + } + else { + fprintf( stderr, "%s: unsupported image type\n", proc ); + return -1; + } + + { + unsigned char *buf = (unsigned char *)im->data; + int size = im->xdim * im->ydim * im->zdim * im->vdim; + imin = imax = *buf; + for (i=0; i *buf ) imin = *buf; + } + } + + } + else if ( im->wdim == 2 ) { + if ( im->vdim == 1 ) { + unsigned short int *buf = (unsigned short int*)im->data; + int size = im->xdim * im->ydim *im->zdim; + int i; + imin = imax = *buf; + for (i=0; i *buf ) imin = *buf; + } + if ( imax < 32768 ) { + hdr.dime.datatype = DT_SIGNED_SHORT ; + } + else { + fprintf( stderr, "%s: conversion from unsigned short to short impossible, max=%d\n", proc, imax ); + return -1; + } + } + else { + fprintf( stderr, "%s: unsupported image type\n", proc ); + return -1; + } + } + + else { + fprintf( stderr, "%s: unsupported image type\n", proc ); + return -1; + } + + } /* if ( im->wordKind == WK_FIXED && im->sign == SGN_UNSIGNED ) */ + + else if( im->wordKind == WK_FIXED && im->sign == SGN_SIGNED ) { + if ( im->vdim != 1 ) { + fprintf( stderr, "%s: unsupported image type\n", proc ); + return -1; + } + if( im->wdim == 2 ) { + short int *buf = (short int*)im->data; + int size = im->xdim * im->ydim *im->zdim; + int i; + imin = imax = *buf; + for (i=0; i *buf ) imin = *buf; + } + hdr.dime.datatype = DT_SIGNED_SHORT ; + } + else if( im->wdim == 4 ) { + int *buf = (int*)im->data; + int size = im->xdim * im->ydim *im->zdim; + int i; + imin = imax = *buf; + for (i=0; i *buf ) imin = *buf; + } + hdr.dime.datatype = DT_SIGNED_INT ; + } + else { + fprintf( stderr, "%s: unsupported image type\n", proc ); + return -1; + } + } + else if( im->wordKind == WK_FLOAT ) { + if ( im->vdim != 1 ) { + fprintf( stderr, "%s: unsupported image type\n", proc ); + return -1; + } + if( im->wdim == 4 ) { + hdr.dime.datatype = DT_FLOAT ; + } + else if( im->wdim == 8 ) { + hdr.dime.datatype = DT_DOUBLE ; + } + else { + fprintf( stderr, "%s: unsupported image type\n", proc ); + return -1; + } + } + else + { + fprintf( stderr, "%s: unsupported image type\n", proc ); + return -1; + } + + hdr.dime.bitpix = 8*im->wdim*im->vdim ; + + hdr.hk.regular = 'r'; + hdr.hk.sizeof_hdr = sizeof(struct dsr); + + /* this is probably bad and should be changed to the + real values, but I'm too lazy to do it now. AG */ + hdr.dime.glmax = 0 ; /* maximum voxel value */ + hdr.dime.glmin = 0 ; /* minimum voxel value */ + + /* corrected GM + */ + hdr.dime.glmax = imax ; /* maximum voxel value */ + hdr.dime.glmin = imin ; /* minimum voxel value */ + +/* Set the voxel dimension fields: + A value of 0.0 for these fields implies that the value is unknown. + Change these values to what is appropriate for your data + or pass additional command line arguments */ + + hdr.dime.pixdim[1] = (float)im->vx; + hdr.dime.pixdim[2] = (float)im->vy; + hdr.dime.pixdim[3] = (float)im->vz; + +/* Assume zero offset in .img file, byte at which pixel + data starts in the image file */ + + hdr.dime.vox_offset = 0.0; + +/* Planar Orientation; */ +/* Movie flag OFF: 0 = transverse, 1 = coronal, 2 = sagittal + Movie flag ON: 3 = transverse, 4 = coronal, 5 = sagittal */ + + hdr.hist.orient = 0; + +/* up to 3 characters for the voxels units label; i.e. mm., um., cm. */ + + strcpy(hdr.dime.vox_units,"mm."); + +/* up to 7 characters for the calibration units label; i.e. HU */ + + strcpy(hdr.dime.cal_units," "); + +/* Calibration maximum and minimum values; + values of 0.0 for both fields imply that no + calibration max and min values are used */ + + hdr.dime.cal_max = 0.0; + hdr.dime.cal_min = 0.0; + + if(ImageIO_write(im, &hdr, sizeof(struct dsr)) !=sizeof(struct dsr) ) + return -1; + + return 1 ; +} + + + + + +/* Writes the given image body in an already opened file.*/ +CGAL_INLINE_FUNCTION +int writeAnalyzeData(const _image *im) { + unsigned int lineSize = im->wdim * im->xdim * im->vdim ; + unsigned long size = lineSize * im->ydim * im->zdim; + unsigned int nwrt ; + + if(im->openMode != OM_CLOSE) { + +#ifdef _REVERSE_LINES_IN_ANALYZE_ + char* data = (char *)im->data ; + char* buf = data + size - lineSize ; + + while( buf >= data ) + { + nwrt = ImageIO_write(im, buf, lineSize); + if(nwrt != lineSize) return -1; + buf -= lineSize ; + } +#else + nwrt = ImageIO_write(im, im->data, size); + if(nwrt != size) return -1; +#endif + + return 1 ; + } + else return -1; +} + + +/* Writes the given image body in an already opened file.*/ +CGAL_INLINE_FUNCTION +int printAnalyzeHeader( const char* name ) +{ + _image *im; + struct dsr analyzeHeader ; + + im = _initImage(); + _openReadImage(im, name); + if(!im->fd) { + fprintf(stderr, "printAnalyzeHeader: error: unable to open file \'%s\'\n", name); + _freeImage(im); + return -1; + } + + if ( _readAnalyzeHeader( im, name, &analyzeHeader ) != 1 ) { + fprintf(stderr, "printAnalyzeHeader: error: unable to read header in file \'%s\'\n", name); + _freeImage(im); + return -1; + } + + + + + + ImageIO_close(im); + im->fd = NULL; + im->openMode = OM_CLOSE; + _freeImage(im); + return( 1 ); + + +} diff --git a/cppfiles.txt b/cppfiles.txt index 1d1457efd59..a007be7f244 100644 --- a/cppfiles.txt +++ b/cppfiles.txt @@ -56,9 +56,10 @@ CGAL_Core: CGAL_ImageIO: +DONE #include "/home/gdamiand/sources/CGAL/CGAL_ImageIO/src/CGAL_ImageIO/analyze.cpp" + #include "/home/gdamiand/sources/CGAL/CGAL_ImageIO/src/CGAL_ImageIO/bmpread.cpp" #include "/home/gdamiand/sources/CGAL/CGAL_ImageIO/src/CGAL_ImageIO/mincio.cpp" -#include "/home/gdamiand/sources/CGAL/CGAL_ImageIO/src/CGAL_ImageIO/analyze.cpp" #include "/home/gdamiand/sources/CGAL/CGAL_ImageIO/src/CGAL_ImageIO/recline.cpp" #include "/home/gdamiand/sources/CGAL/CGAL_ImageIO/src/CGAL_ImageIO/convert.cpp" #include "/home/gdamiand/sources/CGAL/CGAL_ImageIO/src/CGAL_ImageIO/recbuffer.cpp" From 93a007616a0ea689db8cb0153122576821e0a75f Mon Sep 17 00:00:00 2001 From: Clement Jamin Date: Mon, 15 Dec 2014 21:34:29 +0100 Subject: [PATCH 27/30] Header-only CGAL_Core --- CGAL_Core/include/CGAL/CORE/BigFloat.h | 33 +- CGAL_Core/include/CGAL/CORE/BigFloatRep.h | 13 +- CGAL_Core/include/CGAL/CORE/BigFloat_impl.h | 1325 +++++++++++++++++ CGAL_Core/include/CGAL/CORE/BigInt.h | 12 + CGAL_Core/include/CGAL/CORE/CoreAux.h | 12 + CGAL_Core/include/CGAL/CORE/CoreAux_impl.h | 229 +++ CGAL_Core/include/CGAL/CORE/CoreDefs.h | 125 +- CGAL_Core/include/CGAL/CORE/CoreDefs_impl.h | 170 +++ CGAL_Core/include/CGAL/CORE/CoreIO_impl.h | 488 ++++++ CGAL_Core/include/CGAL/CORE/Expr.h | 50 +- CGAL_Core/include/CGAL/CORE/ExprRep.h | 53 +- CGAL_Core/include/CGAL/CORE/Expr_impl.h | 1213 +++++++++++++++ CGAL_Core/include/CGAL/CORE/Filter.h | 9 +- CGAL_Core/include/CGAL/CORE/Gmp.h | 12 + CGAL_Core/include/CGAL/CORE/Gmp_impl.h | 280 ++++ CGAL_Core/include/CGAL/CORE/Real.h | 29 +- CGAL_Core/include/CGAL/CORE/extLong.h | 12 + CGAL_Core/include/CGAL/CORE/poly/Poly.h | 3 +- CGAL_Core/src/CGAL_Core/BigFloat.cpp | 1246 +--------------- CGAL_Core/src/CGAL_Core/CoreAux.cpp | 180 +-- CGAL_Core/src/CGAL_Core/CoreDefs.cpp | 123 +- CGAL_Core/src/CGAL_Core/CoreIO.cpp | 430 +----- CGAL_Core/src/CGAL_Core/Expr.cpp | 1118 +------------- CGAL_Core/src/CGAL_Core/GmpIO.cpp | 254 +--- CGAL_Core/src/CGAL_Core/Real.cpp | 239 +-- CGAL_Core/src/CGAL_Core/extLong.cpp | 154 +- Number_types/include/CGAL/CORE_BigFloat.h | 22 +- .../include/CGAL/CORE_coercion_traits.h | 6 +- .../include/CGAL/Spatial_lock_grid_3.h | 58 - 29 files changed, 4006 insertions(+), 3892 deletions(-) create mode 100644 CGAL_Core/include/CGAL/CORE/BigFloat_impl.h create mode 100644 CGAL_Core/include/CGAL/CORE/CoreAux_impl.h create mode 100644 CGAL_Core/include/CGAL/CORE/CoreDefs_impl.h create mode 100644 CGAL_Core/include/CGAL/CORE/CoreIO_impl.h create mode 100644 CGAL_Core/include/CGAL/CORE/Expr_impl.h create mode 100644 CGAL_Core/include/CGAL/CORE/Gmp_impl.h diff --git a/CGAL_Core/include/CGAL/CORE/BigFloat.h b/CGAL_Core/include/CGAL/CORE/BigFloat.h index 5ed23446997..4ffaabbb0e9 100644 --- a/CGAL_Core/include/CGAL/CORE/BigFloat.h +++ b/CGAL_Core/include/CGAL/CORE/BigFloat.h @@ -37,6 +37,13 @@ #include +#ifdef CGAL_HEADER_ONLY +#undef CGAL_EXPORT // CJTODO: TEMPORARY +#undef CGAL_CORE_EXPORT +#define CGAL_EXPORT +#define CGAL_CORE_EXPORT +#endif + namespace CORE { class Expr; @@ -83,8 +90,8 @@ public: BigFloat(const BigInt& I) : RCBigFloat(new BigFloatRep(I)) {} /// constructor for BigRat - BigFloat(const BigRat& R, const extLong& r = defRelPrec, - const extLong& a = defAbsPrec) + BigFloat(const BigRat& R, const extLong& r = get_static_defRelPrec(), + const extLong& a = get_static_defAbsPrec()) : RCBigFloat(new BigFloatRep()) { rep->approx(R, r, a); } @@ -93,8 +100,8 @@ public: // know about Expr, but BigFloat has a special role in our system! // =============================== /// constructor for Expr - explicit BigFloat(const Expr& E, const extLong& r = defRelPrec, - const extLong& a = defAbsPrec); + explicit BigFloat(const Expr& E, const extLong& r = get_static_defRelPrec(), + const extLong& a = get_static_defAbsPrec()); //Dummy explicit BigFloat(const BigFloat& E, const extLong& , @@ -161,7 +168,7 @@ public: /// operator/= BigFloat& operator/= (const BigFloat& x) { BigFloat z; - z.rep->div(*rep, *x.rep, defBFdivRelPrec); + z.rep->div(*rep, *x.rep, get_static_defBFdivRelPrec()); *this = z; return *this; } @@ -182,11 +189,11 @@ public: /// \name String Conversion Functions //@{ /// set value from const char* (base = 10) - void fromString(const char* s, const extLong& p=defBigFloatInputDigits) { + void fromString(const char* s, const extLong& p=get_static_defBigFloatInputDigits()) { rep->fromString(s, p); } /// convert to std::string (base = 10) - std::string toString(long prec=defBigFloatOutputDigits, bool sci=false) const { + std::string toString(long prec=get_static_defBigFloatOutputDigits(), bool sci=false) const { return rep->toString(prec, sci); } std::string str() const { @@ -435,7 +442,7 @@ inline BigFloat operator* (const BigFloat& x, const BigFloat& y) { /// operator/ inline BigFloat operator/ (const BigFloat& x, const BigFloat& y) { BigFloat z; - z.getRep().div(x.getRep(),y.getRep(),defBFdivRelPrec); + z.getRep().div(x.getRep(),y.getRep(),get_static_defBFdivRelPrec()); return z; } @@ -490,12 +497,12 @@ inline BigFloat power(const BigFloat& x, unsigned long p) { /// The argument x is an initial approximation. BigFloat root(const BigFloat&, unsigned long k, const extLong&, const BigFloat&); inline BigFloat root(const BigFloat& x, unsigned long k) { - return root(x, k, defBFsqrtAbsPrec, x); + return root(x, k, get_static_defBFsqrtAbsPrec(), x); } /// sqrt to defAbsPrec: inline BigFloat sqrt(const BigFloat& x) { - return x.sqrt(defBFsqrtAbsPrec); + return x.sqrt(get_static_defBFsqrtAbsPrec()); } /// convert an BigFloat Interval to a BigFloat with error bits @@ -625,4 +632,10 @@ inline BigRat::BigRat(const BigFloat& f) : RCBigRat(new BigRatRep()){ *this = f.BigRatValue(); } } //namespace CORE + +#ifdef CGAL_HEADER_ONLY +#include +#include +#endif // CGAL_HEADER_ONLY + #endif // _CORE_BIGFLOAT_H_ diff --git a/CGAL_Core/include/CGAL/CORE/BigFloatRep.h b/CGAL_Core/include/CGAL/CORE/BigFloatRep.h index 7cef72c07dc..61b39131269 100644 --- a/CGAL_Core/include/CGAL/CORE/BigFloatRep.h +++ b/CGAL_Core/include/CGAL/CORE/BigFloatRep.h @@ -40,6 +40,13 @@ #include #include +#ifdef CGAL_HEADER_ONLY +#undef CGAL_EXPORT // CJTODO: TEMPORARY +#undef CGAL_CORE_EXPORT +#define CGAL_EXPORT +#define CGAL_CORE_EXPORT +#endif + namespace CORE { // forward reference @@ -144,11 +151,11 @@ private: // conversion // toString() Joaquin Grech 31/5/2003 - std::string toString(long prec=defBigFloatOutputDigits, bool sci=false) const; + std::string toString(long prec=get_static_defBigFloatOutputDigits(), bool sci=false) const; std::string round(std::string inRep, long& L10, unsigned int width) const; - DecimalOutput toDecimal(unsigned int width=defBigFloatOutputDigits, + DecimalOutput toDecimal(unsigned int width=get_static_defBigFloatOutputDigits(), bool Scientific=false) const; - void fromString(const char *p, const extLong & prec = defBigFloatInputDigits); + void fromString(const char *p, const extLong & prec = get_static_defBigFloatInputDigits()); void dump() const; //inline long adjustE(long E, BigInt M, long e) const; diff --git a/CGAL_Core/include/CGAL/CORE/BigFloat_impl.h b/CGAL_Core/include/CGAL/CORE/BigFloat_impl.h new file mode 100644 index 00000000000..d1750ef6d4d --- /dev/null +++ b/CGAL_Core/include/CGAL/CORE/BigFloat_impl.h @@ -0,0 +1,1325 @@ +/**************************************************************************** + * Core Library Version 1.7, August 2004 + * Copyright (c) 1995-2004 Exact Computation Project + * All rights reserved. + * + * This file is part of CORE (http://cs.nyu.edu/exact/core/). + * 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. + * + * + * File: BigFloat.cpp + * Synopsis: + * BigFloat numbers with error bounds + * + * EXACTNESS PROPERTY: + * ================== + * For BigFloats that are exact (i.e., error=0), + * addition/subtraction and multiplication return the + * exact result (i.e., error=0). We also introduce the operation + * div2(), which simply divides a BigFloat by 2, + * but this again preserves exactness. Such exactness + * properties are used in our Newton iteration/Sturm Sequences. + * + * Written by + * Chee Yap + * Chen Li + * Zilin Du + * + * WWW URL: http://cs.nyu.edu/exact/ + * Email: exact@cs.nyu.edu + * + * $URL$ + * $Id$ + ***************************************************************************/ + +#ifdef CGAL_HEADER_ONLY +#define CGAL_INLINE_FUNCTION inline +#else +#define CGAL_INLINE_FUNCTION +#endif + +#include +#include +#include + +namespace CORE { + + +//////////////////////////////////////////////////////////// +// Misc Helper Functions +//////////////////////////////////////////////////////////// + +CGAL_INLINE_FUNCTION +BigInt FiveTo(unsigned long exp) { + if (exp == 0) + return BigInt(1); + else if (exp == 1) + return BigInt(5); + else { + BigInt x = FiveTo(exp / 2); + + x = x * x; + + if (exp & 1) + x *= 5; + + return x; + } +} + +//////////////////////////////////////////////////////////// +// class BigFloat +//////////////////////////////////////////////////////////// + +// STATIC BIGFLOAT CONSTANTS +// ZERO +CGAL_INLINE_FUNCTION +const BigFloat& BigFloat::getZero() { + static BigFloat Zero(0); + return Zero; +} +// ONE +CGAL_INLINE_FUNCTION +const BigFloat& BigFloat::getOne() { + static BigFloat One(1); + return One; +} + +// A special constructor for BigFloat from Expr +// -- this method is somewhat of an anomaly (we normally do not expect +// BigFloats to know about Expr). +CGAL_INLINE_FUNCTION +BigFloat::BigFloat(const Expr& E, const extLong& r, const extLong& a) + : RCBigFloat(new BigFloatRep()) { + *this = E.approx(r, a).BigFloatValue(); // lazy implementaion, any other way? +} + +//////////////////////////////////////////////////////////// +// class BigFloatRep +//////////////////////////////////////////////////////////// + +CGAL_INLINE_FUNCTION +BigFloatRep::BigFloatRep(double d) : m(0), err(0), exp(0) { + if (d != 0.0) { + int isNegative = 0; + + if (d < 0.0) { + isNegative = 1; + d = - d; + } + + int binExp; + double f = frexp(d, &binExp); + + exp = chunkFloor(binExp); + + long s = binExp - bits(exp); + + long stop = 0; + double intPart; + + // convert f into a BigInt + while (f != 0.0 && stop < DBL_MAX_CHUNK) { + f = ldexp(f, (int)CHUNK_BIT); + f = modf(f, &intPart); + m <<= CHUNK_BIT; + m += (long)intPart; + exp--; + stop++; + } +#ifdef CORE_DEBUG + assert (s >= 0); +#endif + + if (s) + m <<= s; + if (isNegative) + negate(m); + } +}//BigFloatRep constructor + +// approximation +CGAL_INLINE_FUNCTION +void BigFloatRep::trunc(const BigInt& I, const extLong& r, const extLong& a) { + if (sign(I)) { + long tr = chunkFloor((- r + bitLength(I)).asLong()); + long ta = chunkFloor(- a.asLong()); + long t; + + if (r.isInfty() || a.isTiny()) + t = ta; + else if (a.isInfty()) + t = tr; + else + t = ta < tr ? tr : ta; + + if (t > 0) { // BigInt remainder; + m = chunkShift(I, - t); + err = 1; + exp = t; + } else { // t <= 0 + m = I; + err = 0; + exp = 0; + } + } else {// I == 0 + m = 0; + err = 0; + exp = 0; + } +} + +CGAL_INLINE_FUNCTION +void BigFloatRep :: truncM(const BigFloatRep& B, const extLong& r, const extLong& a) { + if (sign(B.m)) { + long tr = chunkFloor((- 1 - r + bitLength(B.m)).asLong()); + long ta = chunkFloor(- 1 - a.asLong()) - B.exp; + long t; + + if (r.isInfty() || a.isTiny()) + t = ta; + else if (a.isInfty()) + t = tr; + else + t = ta < tr ? tr : ta; + + if (t >= chunkCeil(clLg(B.err))) { + m = chunkShift(B.m, - t); + err = 2; + exp = B.exp + t; + } else // t < chunkCeil(clLg(B.err)) + core_error(std::string("BigFloat error: truncM called with stricter") + + "precision than current error.", __FILE__, __LINE__, true); + } else {// B.m == 0 + long t = chunkFloor(- a.asLong()) - B.exp; + + if (t >= chunkCeil(clLg(B.err))) { + m = 0; + err = 1; + exp = B.exp + t; + } else // t < chunkCeil(clLg(B.err)) + core_error(std::string("BigFloat error: truncM called with stricter") + + "precision than current error.", __FILE__, __LINE__, true); + } +} + +// This is the main approximation function +// REMARK: would be useful to have a self-modifying version +// of this function (e.g., for Newton). +CGAL_INLINE_FUNCTION +void BigFloatRep::approx(const BigFloatRep& B, + const extLong& r, const extLong& a) { + if (B.err) { + if (1 + clLg(B.err) <= bitLength(B.m)) + truncM(B, r + 1, a); + else // 1 + clLg(B.err) > lg(B.m) + truncM(B, CORE_posInfty, a); + } else {// B.err == 0 + trunc(B.m, r, a - bits(B.exp)); + exp += B.exp; + } + // Call normalization globally -- IP 10/9/98 + normal(); +} + +CGAL_INLINE_FUNCTION +void BigFloatRep::div(const BigInt& N, const BigInt& D, + const extLong& r, const extLong& a) { + if (sign(D)) { + if (sign(N)) { + long tr = chunkFloor((- r + bitLength(N) - bitLength(D) - 1).asLong()); + long ta = chunkFloor(- a.asLong()); + + if (r.isInfty() || a.isTiny()) + exp = ta; + else if (a.isInfty()) + exp = tr; + else + exp = ta < tr ? tr : ta; + + BigInt remainder; + + // divide(chunkShift(N, - exp), D, m, remainder); + div_rem(m, remainder, chunkShift(N, - exp), D); + + if (exp <= 0 && sign(remainder) == 0) + err = 0; + else + err = 1; + } else {// N == 0 + m = 0; + err = 0; + exp = 0; + } + } else // D == 0 + core_error( "BigFloat error: zero divisor.", __FILE__, __LINE__, true); + + // Call normalization globally -- IP 10/9/98 + normal(); +}//div + +// error-normalization +CGAL_INLINE_FUNCTION +void BigFloatRep::normal() { + long le = flrLg(err); + + if (le >= CHUNK_BIT + 2) { // so we do not carry more than 16 = CHUNK_BIT + 2 + // bits of error + long f = chunkFloor(--le); // f is roughly equal to floor(le/CHUNK_BIT) + long bits_f = bits(f); // f chunks will have bits_f many bits +#ifdef CORE_DEBUG + assert (bits_f >= 0); +#endif + + m >>= bits_f; // reduce mantissa by bits_f many bits + err >>= bits_f; // same for err + err += 2; // why 2? + exp += f; + } + if (err == 0) // unlikely, if err += 2 above + eliminateTrailingZeroes(); +} + +// bigNormal(err) +// convert a bigInt error value (=err) into an error that fits into +// a long number. This is done by +// by increasing the exponent, and corresponding decrease +// in the bit lengths of the mantissa and error. +// +CGAL_INLINE_FUNCTION +void BigFloatRep::bigNormal(BigInt& bigErr) { + long le = bitLength(bigErr); + + if (le < CHUNK_BIT + 2) { + err = ulongValue(bigErr); + } else { + long f = chunkFloor(--le); + long bits_f = bits(f); +#ifdef CORE_DEBUG + assert(bits_f >= 0); +#endif + + m >>= bits_f; + bigErr >>= bits_f; + err = ulongValue(bigErr) + 2; // you need to add "2" because "1" comes + // from truncation error in the mantissa, and another + // "1" comes from the truncation error in the bigErr. + // (But there is danger of overflow...) + exp += f; + } + + if (err == 0) + eliminateTrailingZeroes(); +} + +// ARITHMETIC: +// Addition +CGAL_INLINE_FUNCTION +void BigFloatRep::add(const BigFloatRep& x, const BigFloatRep& y) { + long expDiff = x.exp - y.exp; + + if (expDiff > 0) {// x.exp > y.exp + if (!x.err) { + m = chunkShift(x.m, expDiff) + y.m; + err = y.err; + exp = y.exp; + } else {// x.err > 0 + m = x.m + chunkShift(y.m, - expDiff); // negative shift! + err = x.err + 5; // To account for y.err (but why 5?) + exp = x.exp; // + // normal(); + } + } else if (!expDiff) {// x.exp == y.exp + m = x.m + y.m; + err = x.err + y.err; + exp = x.exp; + // normal(); + } else {// x.exp < y.exp + if (!y.err) { + m = x.m + chunkShift(y.m, - expDiff); + err = x.err; + exp = x.exp; + } else {// y.err > 0 + m = chunkShift(x.m, expDiff) + y.m; + err = y.err + 5; + exp = y.exp; + // normal(); + } + } + // Call normalization globally -- IP 10/9/98 + normal(); +} + +// Subtraction +CGAL_INLINE_FUNCTION +void BigFloatRep::sub(const BigFloatRep& x, const BigFloatRep& y) { + long expDiff = x.exp - y.exp; + + if (expDiff > 0) {// x.exp > y.exp + if (!x.err) { + m = chunkShift(x.m, expDiff) - y.m; + err = y.err; + exp = y.exp; + } else {// x.err > 0 + m = x.m - chunkShift(y.m, - expDiff); + err = x.err + 5; + exp = x.exp; + // normal(); + } + } else if (!expDiff) { + m = x.m - y.m; + err = x.err + y.err; + exp = x.exp; + // normal(); + } else { // x.exp < y.exp + if (!y.err) { + m = x.m - chunkShift(y.m, - expDiff); + err = x.err; + exp = x.exp; + } else {// y.err > 0 + m = chunkShift(x.m, expDiff) - y.m; + err = y.err + 5; + exp = y.exp; + // normal(); + } + } + // Call normalization globally -- IP 10/9/98 + normal(); +} + +CGAL_INLINE_FUNCTION +void BigFloatRep::mul(const BigFloatRep& x, const BigFloatRep& y) { + m = x.m * y.m; + exp = x.exp + y.exp; + // compute error (new code, much faster. Zilin Du, Nov 2003) + if (x.err == 0 && y.err == 0) { + err = 0; + eliminateTrailingZeroes(); + } else { + BigInt bigErr(0); + if (y.err != 0) + bigErr += abs(x.m)*y.err; + if (x.err != 0) + bigErr += abs(y.m)*x.err; + if (x.err !=0 && y.err != 0) + bigErr += x.err*y.err; + bigNormal(bigErr); + } +} +// BigFloat div2 will half the value of x, exactly with NO error +// REMARK: should generalize this to dividing by any power of 2 +// We need this in our use of BigFloats to maintain isolation +// intervals (e.g., in Sturm sequences) --Chee/Vikram 4/2003 +// +CGAL_INLINE_FUNCTION +void BigFloatRep :: div2(const BigFloatRep& x) { + if (isEven(x.m)) { + m = (x.m >> 1); + exp = x.exp ; + } else { + m = (x.m << static_cast(CHUNK_BIT-1)); + exp = x.exp -1; + } +} + +// Converts a BigFloat interval into one BigFloat with almost same error bound +// This routine ignores the errors in inputs a and b. +// But you cannot really ignore them since, they are taken into account +// when you compute "r.sub(a,b)"... +CGAL_INLINE_FUNCTION +void BigFloatRep::centerize(const BigFloatRep& a, const BigFloatRep& b) { + if ((a.m == b.m) && (a.err == b.err) && (a.exp == b.exp)) { + m = a.m; + err = a.err; + exp = a.exp; + return; + } + + BigFloatRep r; + r.sub(a, b); + r.div2(r); + + //setup mantissa and exponent, but not error bits + // But this already sets the error bits? Chee + add(a,b); + div2(*this); + // error bits = ceil ( B^{-exp}*|a-b|/2 ) + + // bug fixed: possible overflow on converting + // Zilin & Vikram, 08/24/04 + // err = 1 + longValue(chunkShift(r.m, r.exp - exp)); + BigInt E = chunkShift(r.m, r.exp - exp); + bigNormal(E); +} + +// BigFloat Division, computing x/y: +// Unlike +,-,*, this one takes a relative precision bound R +// Note that R is only used when x and y are error-free! +// (This remark means that we may be less efficient than we could be) +// +// Assert( R>0 && R< CORE_Infty ) +// +CGAL_INLINE_FUNCTION +void BigFloatRep :: div(const BigFloatRep& x, const BigFloatRep& y, + const extLong& R) { + if (!y.isZeroIn()) { // y.m > y.err, so we are not dividing by 0 + if (!x.err && !y.err) { + if (R < 0 || R.isInfty()) //Oct 9, 2002: fixed major bug! [Zilin/Chee] + div(x.m, y.m, get_static_defBFdivRelPrec(), CORE_posInfty); + else + div(x.m, y.m, R, CORE_posInfty); + exp += x.exp - y.exp; // chen: adjust exp. + } else {// x.err > 0 or y.err > 0 + BigInt bigErr, errRemainder; + + if (x.isZeroIn()) { // x.m <= x.err + m = 0; + exp = x.exp - y.exp; + + div_rem(bigErr, errRemainder, abs(x.m) + static_cast(x.err), + abs(y.m) - static_cast(y.err)); + } else { // x.m > x.err + long lx = bitLength(x.m); + long ly = bitLength(y.m); + long r; + + if (!x.err) // x.err == 0 and y.err > 0 + r = ly + 2; + else if(!y.err) // x.err > 0 and y.err == 0 + r = lx + 2; + else // x.err > 0 and y.err > 0 + r = lx < ly ? lx + 2: ly + 2; + + long t = chunkFloor(- r + lx - ly - 1); + BigInt remainder; + + div_rem(m, remainder, chunkShift(x.m, - t), y.m); + exp = t + x.exp - y.exp; + + long delta = ((t > 0) ? 2 : 0); + + // Chen Li: 9/9/99 + // here again, it use ">>" operator with a negative + // right operand. So the result is not well defined. + // Erroneous code: + // divide(abs(remainder) + (static_cast(x.err) >> bits(t)) + // + delta + static_cast(y.err) * abs(m), + // abs(y.m) - static_cast(y.err), + // bigErr, + // errRemainder); + // New code: + BigInt errx_over_Bexp = x.err; + long bits_Bexp = bits(t); + if (bits_Bexp >= 0) { + errx_over_Bexp >>= bits_Bexp; + } else { + errx_over_Bexp <<= (-bits_Bexp); + } + + // divide(abs(remainder) + errx_over_Bexp + // + delta + static_cast(y.err) * abs(m), + // abs(y.m) - static_cast(y.err), + // bigErr, + // errRemainder); + div_rem(bigErr, errRemainder, + abs(remainder) + errx_over_Bexp + delta + static_cast(y.err) * abs(m), + abs(y.m) - static_cast(y.err)); + } + + if (sign(errRemainder)) + ++bigErr; + + bigNormal(bigErr); + } + } else {// y.m <= y.err + core_error("BigFloat error: possible zero divisor.", + __FILE__, __LINE__, true); + } + + // Call normalization globally -- IP 10/9/98 + // normal(); -- Chen: after calling bigNormal, this call is redundant. +}// BigFloatRep::div + +// squareroot for BigInt argument, without initial approximation +// sqrt(x,a) computes sqrt of x to absolute precision a. +// -- this is where Newton is applied +// -- this is called by BigFloatRep::sqrt(BigFloat, extLong) +CGAL_INLINE_FUNCTION +void BigFloatRep::sqrt(const BigInt& x, const extLong& a) { + sqrt(x, a, BigFloat(x, 0, 0)); +} // sqrt(BigInt x, extLong a) , without initial approx + +// sqrt(x,a,A) where +// x = bigInt whose sqrt is to be computed +// a = absolute precision bound +// A = initial approximation in BigFloat +// -- this is where Newton is applied +// -- it is called by BigFloatRep::sqrt(BigFloatRep, extLong, BigFloat) +CGAL_INLINE_FUNCTION +void BigFloatRep::sqrt(const BigInt& x, const extLong& a, const BigFloat& A) { + if (sign(x) == 0) { + m = 0; + err = 0; + exp = 0; + } else if (x == 1) { + m = 1; + err = 0; + exp = 0; + } else {// main case + // here is where we use the initial approximation + m = A.m(); + err = 0; + exp = A.exp(); + + BigFloatRep q, z; + extLong aa; + // need this to make sure that in case the + // initial approximation A is less than sqrt(x) + // then Newton iteration will still proceed at + // least one step. + bool firstTime = true; + for (;;) { + aa = a - bits(exp); + q.div(x, m, CORE_posInfty, aa); + q.err = 0; + q.exp -= exp; + + z.sub(*this, q); // this=current approximation, so z = this - q + /*if (sign(z.m) <= 0 || z.MSB() < - a) // justification: see Koji's + break; // thesis (p. 28) which states + // that we can exit when + // " (*this) <= q + 2**(-a)" + */ + // The preceding code is replaced by what follows: + if (z.MSB() < -a) + break; + if (sign(z.m) <= 0) { + if (firstTime) + firstTime = false; + else + break; + } + + z.add(*this, q); + // Chen Li: a bug fixed here. + // m = z.m >> 1; + // err = 0; + // exp = z.exp; + if ((z.m > 1) && isEven(z.m)) { + m = z.m >> 1; // exact division by 2 + err = 0; + exp = z.exp; + } else { // need to shift left before division by 2 + m = chunkShift(z.m, 1) >> 1; + err = 0; + exp = z.exp - 1; + }//else + }//for + }//else +} // sqrt of BigInt, with initial approx + +// MAIN ENTRY INTO SQRT FUNCTION (BIGFLOAT ARGUMENT, WITHOUT INITIAL APPROX) +CGAL_INLINE_FUNCTION +void BigFloatRep::sqrt(const BigFloatRep& x, const extLong& a) { + sqrt(x, a, BigFloat(x.m, 0, x.exp)); +} //sqrt(BigFloat, extLong a) + +// MAIN ENTRY INTO SQRT FUNCTION (BIGFLOAT ARGUMENT WITH INITIAL APPROXIMATION) +CGAL_INLINE_FUNCTION +void BigFloatRep::sqrt(const BigFloatRep& x, const extLong& a, const BigFloat& A) { + // This computes the sqrt of x to absolute precision a, starting with + // the initial approximation A + if (sign(x.m) >= 0) { // x.m >= 0 + int delta = x.exp & 1; // delta=0 if x.exp is even, otherwise delta=1 + + if (x.isZeroIn()) { // x.m <= x.err + m = 0; + if (!x.err) + err = 0; + else { // x.err > 0 + err = (long)(std::sqrt((double)x.err)); + err++; + err <<= 1; + if (delta) + err <<= HALF_CHUNK_BIT; + } + exp = x.exp >> 1; + normal(); + } else { + long aExp = A.exp() - (x.exp >> 1); + BigFloat AA( chunkShift(A.m(), delta), 0, aExp); + + if (!x.err) { // x.m > x.err = 0 (ERROR FREE CASE) + BigFloatRep z; + extLong ppp; + if (a.isInfty()) //Oct 9, 2002: fixed major bug! [Zilin/Chee] + ppp = get_static_defBFsqrtAbsPrec(); + else + ppp = a + EXTLONG_ONE; + extLong absp = ppp + bits(x.exp >> 1); + + z.sqrt(chunkShift(x.m, delta), absp, AA); // call sqrt(BigInt, a, AA) + + long p = (absp + bits(z.exp)).asLong(); + + // Next, normalize the error: + if (p <= 0) { + m = z.m; + // Chen Li: a bug fixed + // BigInt bigErr = 1 << (-p); + BigInt bigErr(1); + bigErr = bigErr << static_cast(-p); + exp = z.exp + (x.exp >> 1); + bigNormal(bigErr); + } else { // p > 0 + m = chunkShift(z.m, chunkCeil(p)); + long r = CHUNK_BIT - 1 - (p + CHUNK_BIT - 1) % CHUNK_BIT; +#ifdef CORE_DEBUG + assert(r >= 0); +#endif + + err = 1 >> r; + exp = - chunkCeil(ppp.asLong()); + normal(); + } + } else { // x.m > x.err > 0 (mantissa has error) + BigFloatRep z; + extLong absp=-flrLg(x.err)+bitLength(x.m)-(bits(delta) >> 1)+EXTLONG_FOUR; + + z.sqrt(chunkShift(x.m, delta), absp, AA); + + long qqq = - 1 + (bitLength(x.m) >> 1) - delta * HALF_CHUNK_BIT; + long qq = qqq - clLg(x.err); + long q = qq + bits(z.exp); + + if (q <= 0) { + m = z.m; + long qqqq = - qqq - bits(z.exp); + // Chen Li (09/08/99), a bug fixed here: + // BigInt bigErr = x.err << - qqqq; + // when (-qqqq) is negative, the result is not correct. + // how "<<" and ">>" process negative second operand is + // not well defined. Seems it just take it as a unsigned + // integer and extract the last few bits. + // x.err is a long number which easily overflows. + // From page 22 of Koji's paper, I think the exponent is + // wrong here. So I rewrote it as: + BigInt bigErr = x.err; + if (qqqq >= 0) { + bigErr <<= qqqq; + } else { + bigErr >>= (-qqqq); + ++bigErr; // we need to keep its ceiling. + } + + exp = z.exp + (x.exp >> 1); + bigNormal(bigErr); + } else { // q > 0 + m = chunkShift(z.m, chunkCeil(q)); + long r = CHUNK_BIT - 1 - (q + CHUNK_BIT - 1) % CHUNK_BIT; +#ifdef CORE_DEBUG + assert(r >= 0); +#endif + + err = 1 >> r; + exp = (x.exp >> 1) - chunkCeil(qq); + normal(); + } + } // end of case with error in mantissa + }//else + } else + core_error("BigFloat error: squareroot called with negative operand.", + __FILE__, __LINE__, true); +} //sqrt with initial approximation + +// compareMExp(x) +// returns 1 if *this > x +// 0 if *this = x, +// -1 if *this < x, +// +// Main comparison method for BigFloat +// This is called by BigFloat::compare() +// BE CAREFUL: The error bits are ignored! +// Need another version if we want to take care of error bits + +CGAL_INLINE_FUNCTION +int BigFloatRep :: compareMExp(const BigFloatRep& x) const { + int st = sign(m); + int sx = sign(x.m); + + if (st > sx) + return 1; + else if (st == 0 && sx == 0) + return 0; + else if (st < sx) + return - 1; + else { // need to compare m && exp + long expDiff = exp - x.exp; + + if (expDiff > 0) // exp > x.exp + return cmp(chunkShift(m, expDiff), x.m); + else if (!expDiff) + return cmp(m, x.m); + else // exp < x.exp + return cmp(m, chunkShift(x.m, - expDiff)); + } +} + +// 3/6/2000: +// This is a private function used by BigFloatRep::operator<< +// to get the exact value +// of floor(log10(M * 2^ e)) where E is an initial guess. +// We will return the correct E which satisfies +// 10^E <= M * 2^e < 10^{E+1} +// But we convert this into +// mm <= M < 10.mm + +CGAL_INLINE_FUNCTION +long BigFloatRep :: adjustE( long E, BigInt M, long ee) const { + if (M<0) + M=-M; + BigInt mm(1); + if (ee > 0) + M = (M<(ee)); + else + mm = (mm << static_cast(-ee)); + if (E > 0) + mm *= (FiveTo(E)<< static_cast(E)); + else + M *= (FiveTo(-E) << static_cast(-E)); + + if (M < mm) { + do { + E--; + M *= 10; + } while (M < mm); + } else if (M >= 10*mm) { + mm *= 10; + do { + E++; + mm *= 10; + } while (M >= mm); + } + return E; +} + +CGAL_INLINE_FUNCTION +BigFloatRep::DecimalOutput +BigFloatRep::toDecimal(unsigned int width, bool Scientific) const { + BigFloatRep::DecimalOutput decOut; // to be returned + if (err > 0) { + decOut.isExact = false; + } else { // err == 0 + decOut.isExact = true; + } + + if (err > 0 && err >= abs(m)) { + // if err is larger than mantissa, sign and significant values + // can not be determined. + core_error("BigFloat error: Error is too big!", + __FILE__, __LINE__, false); + decOut.rep = "0.0e0"; // error is too big + decOut.isScientific = false; + decOut.noSignificant = 0; + decOut.errorCode = 1; // sign of this number is unknown + return decOut; + } + + decOut.sign = sign(m); + decOut.errorCode = 0; + + BigInt M(m); // temporary mantissa + long lm = bitLength(M); // binary length of mantissa + long e2 = bits(exp); // binary shift length represented by exponent + long le = clLg(err); // binary length of err + if (le == -1) + le = 0; + + long L10 = 0; + if (M != 0) { + L10 = (long)std::floor((lm + e2) / lgTenM); + L10 = adjustE(L10, m, e2); // L10: floor[log10(M 2^(e2))], M != 0 + } else { + L10 = 0; + } + // Convention: in the positional format, when the output is + // the following string of 8 characters: + // (d0, d1, d2, d3, ".", d4, d5, d6, d7) + // then the decimal point is said to be in the 4th position. + // E.g., (d0, ".", d1, d2) has the decimal point in the 1st position. + // The value of L10 says that the decimal point of output should be at + // the (L10 + 1)st position. This is + // true regardingless of whether M = 0 or not. For zero, we output + // {0.0*} so L10=0. In general, the |value| is less than 10 + // if and only if L10 is 0 and the + // decimal point is in the 1st place. Note that L10 is defined even if + // the output is an integer (in which case it does not physically appear + // but conceptually terminates the sequence of digits). + + // First, get the decimal representaion of (m * B^(exp)). + if (e2 < 0) { + M *= FiveTo(-e2); // M = x * 10^(-e2) + } else if (e2 > 0) { + M <<= e2; // M = x * 2^(e2) + } + + std::string decRep = M.get_str(); + // Determine the "significant part" of this string, i.e. the part which + // is guaranteed to be correct in the presence of error, + // except that the last digit which might be subject to +/- 1. + + if (err != 0) { // valid = number of significant digits + unsigned long valid = floorlg10(m) - (long)std::floor(std::log10(float(err))); + if (decRep.length() > valid) { + decRep.erase(valid); + } + } + + // All the digits in decM are correct, except the last one might + // subject to an error +/- 1. + + if ((decRep[0] == '+') || (decRep[0] == '-')) { + decRep.erase(0, 1); + } + + // Second, make choice between positional representation + // and scientific notation. Use scientific notation when: + // 0) if scientific notation flag is on + // 1) err * B^exp >= 1, the error contribute to the integral part. + // 2) (1 + L10) >= width, there is not have enough places to hold the + // positional representation, not including decimal point. + // 3) The distance between the first significant digit and decimal + // point is too large for the width limit. This is equivalent to + // Either ((L10 >= 0 and (L10 + 1) > width)) + // Or ((L10 < 0) and (-L10 + 1) > width). + + if (Scientific || + ((err > 0) && (le + e2) >= 0) || // if err*B^exp >= 1 + ((L10 >= 0) && (L10 + 1 >= (long)width )) || + ((L10 < 0) && (-L10 + 1 > (long)width ))) { + // use scientific notation + decRep = round(decRep, L10, width); + decOut.noSignificant = width; + decRep.insert(1, "."); + if (L10 != 0) { + decRep += 'e'; + if (L10 > 0) { + decRep += '+'; + } else { // L10 < 0 + decRep += '-'; + } + char eBuf[48]; // enought to hold long number L10 + int ne = 0; + if ((ne = sprintf(eBuf, "%ld", labs(L10))) >= 0) { + eBuf[ne] = '\0'; + } else { + //perror("BigFloat.cpp: Problem in outputing the exponent!"); + core_error("BigFloat error: Problem in outputing the exponent", + __FILE__, __LINE__, true); + } + decRep += eBuf; + decOut.isScientific = true; + } + } else { + // use conventional positional notation. + if (L10 >= 0) { // x >= 1 or x == 0 and L10 + 1 <= width + // round when necessary + if (decRep.length() > width ) { + decRep = round(decRep, L10, width ); + if (decRep.length() > width ) { + // overflow happens! use scientific notation + return toDecimal(width, true); + } + } + decOut.noSignificant = decRep.length(); + if (L10 + 1 < (long)width ) { + decRep.insert(L10 + 1, "."); + } else { // L10 + 1 == width + // do nothing + } + } else { // L10 < 0, 0 < x < 1 + // (-L10) leading zeroes, including one to the left of decimal dot + // need to be added in beginning. + decRep = std::string(-L10, '0') + decRep; + // then round when necessary + if (decRep.length() > width ) { + decRep = round(decRep, L10, width ); + // cannot overflow since there are L10 leading zeroes. + } + decOut.noSignificant = decRep.length() - (-L10); + decRep.insert(1, "."); + } + decOut.isScientific = false; + } +#ifdef CORE_DEBUG + assert(decOut.noSignificant >= 0); +#endif + + decOut.rep = decRep; + return decOut; +}//toDecimal + +CGAL_INLINE_FUNCTION +std::string BigFloatRep::round(std::string inRep, long& L10, unsigned int width) const { + // round inRep so that the length would not exceed width. + if (inRep.length() <= width) + return inRep; + + int i = width; // < length + bool carry = false; + + if ((inRep[i] >= '5') && (inRep[i] <= '9')) { + carry = true; + i--; + while ((i >= 0) && carry) { + if (carry) { + inRep[i] ++; + if (inRep[i] > '9') { + inRep[i] = '0'; + carry = true; + } else { + carry = false; + } + } + i-- ; + } + + if ((i < 0) && carry) { // overflow + inRep.insert(inRep.begin(), '1'); + L10 ++; + width ++; + } + } + + return inRep.substr(0, width); +}//round(string,width) + + +// This function fromString(str, prec) is similar to the +// constructor Real(char * str, extLong prec) +// See the file Real.cc for the differences + +CGAL_INLINE_FUNCTION +void BigFloatRep :: fromString(const char *str, const extLong & prec ) { + // NOTE: prec defaults to get_static_defBigFloatInputDigits() (see BigFloat.h) + // check that prec is not INFTY + if (prec.isInfty()) + core_error("BigFloat error: infinite precision not allowed", + __FILE__, __LINE__, true); + + const char *e = strchr(str, 'e'); + int dot = 0; + long e10 = 0; + if (e != NULL) + e10 = atol(e+1); // e10 is decimal precision of the input string + // i.e., input is A/10^{e10}. + else { + e = str + strlen(str); +#ifdef CORE_DEBUG + assert(*e == '\0'); +#endif + + } + + const char *p = str; + if (*p == '-' || *p == '+') + p++; + m = 0; + exp = 0; + + for (; p < e; p++) { + if (*p == '.') { + dot = 1; + continue; + } + m = m * 10 + (*p - '0'); + if (dot) + e10--; + } + + BigInt one = 1; + long t = (e10 < 0) ? -e10 : e10; + BigInt ten = FiveTo(t) * (one << static_cast(t)); + + // HERE IS WHERE WE USE THE SYSTEM CONSTANT + // defBigFloatInputDigits + // Note: this constant is rather similar to defInputDigits which + // is used by Real and Expr for controlling + // input accuracy. The difference is that defInputDigits can + // be CORE_INFTY, but defBigFloatInputDigits must be finite. + + if (e10 < 0) + div(m, ten, CORE_posInfty, 4 * prec); + else + m *= ten; + if (*str == '-') + m = -m; +}//BigFloatRep::fromString + +CGAL_INLINE_FUNCTION +std::istream& BigFloatRep :: operator >>(std::istream& i) { + int size = 20; + char *str = new char[size]; + char *p = str; + char c; + int d = 0, e = 0, s = 0; + // d=1 means dot is found + // e=1 means 'e' or 'E' is found + // int done = 0; + + // Chen Li: fixed a bug, the original statement is + // for (i.get(c); c == ' '; i.get(c)); + // use isspace instead of testing c == ' ', since it must also + // skip tab, catridge/return, etc. + // Change to: + // int status; + do { + c = i.get(); + } while (isspace(c)); /* loop if met end-of-file, or + char read in is white-space. */ + // Chen Li, "if (c == EOF)" is unsafe since c is of char type and + // EOF is of int tyep with a negative value -1 + if (i.eof()) { + i.clear(std::ios::eofbit | std::ios::failbit); + return i; + } + + // the current content in "c" should be the first non-whitespace char + if (c == '-' || c == '+') { + *p++ = c; + i.get(c); + } + + for (; isdigit(c) || (!d && c=='.') || + (!e && ((c=='e') || (c=='E'))) || (!s && (c=='-' || c=='+')); i.get(c)) { + if (!e && (c == '-' || c == '+')) + break; + // Chen Li: put one more rule to prohibite input like + // xxxx.xxxe+xxx.xxx: + if (e && (c == '.')) + break; + if (p - str == size) { + char *t = str; + str = new char[size*2]; + memcpy(str, t, size); + delete [] t; + p = str + size; + size *= 2; + } +#ifdef CORE_DEBUG + assert((p-str) < size); +#endif + + *p++ = c; + if (c == '.') + d = 1; + // Chen Li: fix a bug -- the sign of exponent can not happen before + // the character "e" appears! It must follow the "e' actually. + // if (e || c == '-' || c == '+') s = 1; + if (e) + s = 1; + if ((c == 'e') || (c=='E')) + e = 1; + } + + // chenli: make sure that the p is still in the range + if (p - str >= size) { + int len = p - str; + char *t = str; + str = new char[len + 1]; + memcpy(str, t, len); + delete [] t; + p = str + len; + } + +#ifdef CORE_DEBUG + assert(p - str < size); +#endif + + *p = '\0'; + i.putback(c); + fromString(str); + delete [] str; + return i; +}//operator >> + + +// BigFloatRep::toDouble() +// converts the BigFloat to a machine double +// This is a dangerous function as the method +// is silent when it does not fit into a machine double! +// ToDo: fix this by return a machine NaN, +/- Infinity, +/- 0, +// when appropriate. +// Return NaN when error is larger than mantissa +// Return +/- Infinity if BigFloat is too big +// Return +/- 0 if BigFloat is too small +#ifdef _MSC_VER +#pragma warning(disable: 4723) +#endif +CGAL_INLINE_FUNCTION +double BigFloatRep :: toDouble() const { + if (m == 0) + return (sign(m) * 0.0); + + long e2 = bits(exp); + long le = clLg(err); // if err=0, le will be -1 + if (le == -1) + le = 0; + + BigInt M = m >> static_cast(le);// remove error bits in mantissa + + // Below, we want to return NaN by computing 0.0/0.0. + // To avoid compiler warnings about divide by zero, we do this: + + double foolCompilerZero; + foolCompilerZero = 0.0; + + // COMMENT: we should directly store the + // special IEEE values NaN, +/-Infinity, +/-0 in the code!! + + if (M == 0) + return ( 0.0/foolCompilerZero ) ; // return NaN + + e2 += le; // adjust exponent corresponding to error bits + + int len = bitLength(M) - 53; // this is positive if M is too large + + if (len > 0) { + M >>= len; + e2 += len; + } + + double tt = doubleValue(M); + + int ee = e2 + bitLength(M) - 1; // real exponent. + + if (ee >= 1024) // overflow! + return ( sign(m)/foolCompilerZero ); // return a signed infinity + + if (ee <= -1075) // underflow! + // NOTE: if (-52 < ee <= 0) get denormalized number + return ( sign(m) * 0.0 ); // return signed zero. + + // Execute this loop if e2 < 0; + for (int i = 0; i > e2; i--) + tt /= 2; + + // Execute this loop if e2 > 0; + for (int j = 0; j < e2; j++) + tt *= 2; + + return tt; +}//toDouble +#ifdef _MSC_VER +#pragma warning(default: 4723) +#endif +CGAL_INLINE_FUNCTION +BigInt BigFloatRep::toBigInt() const { + long e2 = bits(exp); + long le = clLg(err); + if (le == -1) + le = 0; +#ifdef CORE_DEBUG + assert (le >= 0); +#endif + + BigInt M = m >> static_cast(le); // discard the contaminated bits. + e2 += le; // adjust the exponent + + if (e2 < 0) + return M >> static_cast(-e2); + else if (e2 > 0) + return M << static_cast(e2); + else + return M; +} + +CGAL_INLINE_FUNCTION +long BigFloatRep :: toLong() const { + // convert a BigFloat to a long integer, rounded toward -\infty. + long e2 = bits(exp); + long le = clLg(err); +#ifdef CORE_DEBUG + assert (le >= 0); +#endif + + BigInt M = m >> static_cast(le); // discard the contaminated bits. + e2 += le; // adjust the exponent + long t; + if (e2 < 0) + t = ulongValue(M >> static_cast(-e2)); + else if (e2 > 0) + t = ulongValue(M << static_cast(e2)); + else + t = ulongValue(M); + // t = M.as_long(); + // Note: as_long() will return LONG_MAX in case of overflow. + + return t; +} + +// pow(r,n) function for BigFloat +// Note: power(r,n) calls pow(r,n) +CGAL_INLINE_FUNCTION +BigFloat pow(const BigFloat& r, unsigned long n) { + if (n == 0) + return BigFloat(1); + else if (n == 1) + return r; + else { + BigFloat x = r; + while ((n % 2) == 0) { // n is even + x *= x; + n >>= 1; + } + BigFloat u = x; + while (true) { + n >>= 1; + if (n == 0) + return u; + x *= x; + if ((n % 2) == 1) // n is odd + u *= x; + } + //return u; // unreachable + } +}//pow + +// experimental +CGAL_INLINE_FUNCTION +BigFloat root(const BigFloat& x, unsigned long k, + const extLong& a, const BigFloat& A) { + if (x.sign() == 0) { + return BigFloat(0); + } else if (x == 1) { + return BigFloat(1); + } else { + BigFloat q, del, zz; + BigFloat z = A; + BigFloat bk = long(k); + for (; ;) { + zz = pow(z, k-1); + q = x.div(zz, a); + q.makeExact(); + del = z - q; + del.makeExact(); + if (del.MSB() < -a) + break; + z = ((bk-1)*z + q).div(bk, a); + // newton's iteration: z_{n+1}=((k-1)z_n+x/z_n^{k-1})/k + z.makeExact(); + } + return z; + } +}//root + +} //namespace CORE diff --git a/CGAL_Core/include/CGAL/CORE/BigInt.h b/CGAL_Core/include/CGAL/CORE/BigInt.h index aa388c2db72..23e89b6aaf1 100644 --- a/CGAL_Core/include/CGAL/CORE/BigInt.h +++ b/CGAL_Core/include/CGAL/CORE/BigInt.h @@ -39,6 +39,13 @@ #include #include +#ifdef CGAL_HEADER_ONLY +#undef CGAL_EXPORT // CJTODO: TEMPORARY +#undef CGAL_CORE_EXPORT +#define CGAL_EXPORT +#define CGAL_CORE_EXPORT +#endif + namespace CORE { @@ -559,4 +566,9 @@ inline BigInt randomize(const BigInt& a) { //@} } //namespace CORE + +#ifdef CGAL_HEADER_ONLY +//#include +#endif // CGAL_HEADER_ONLY + #endif // _CORE_BIGINT_H_ diff --git a/CGAL_Core/include/CGAL/CORE/CoreAux.h b/CGAL_Core/include/CGAL/CORE/CoreAux.h index 82aea0734c5..fcc8cd00799 100644 --- a/CGAL_Core/include/CGAL/CORE/CoreAux.h +++ b/CGAL_Core/include/CGAL/CORE/CoreAux.h @@ -39,6 +39,13 @@ #include #include "CGAL/CORE/Impl.h" +#ifdef CGAL_HEADER_ONLY +#undef CGAL_EXPORT // CJTODO: TEMPORARY +#undef CGAL_CORE_EXPORT +#define CGAL_EXPORT +#define CGAL_CORE_EXPORT +#endif + namespace CORE { #ifndef LONG_BIT // such as in Linux @@ -181,4 +188,9 @@ inline void core_debug(std::string msg){ } //namespace CORE + +#ifdef CGAL_HEADER_ONLY +#include +#endif // CGAL_HEADER_ONLY + #endif // _CORE_COREAUX_H_ diff --git a/CGAL_Core/include/CGAL/CORE/CoreAux_impl.h b/CGAL_Core/include/CGAL/CORE/CoreAux_impl.h new file mode 100644 index 00000000000..98f31a78e43 --- /dev/null +++ b/CGAL_Core/include/CGAL/CORE/CoreAux_impl.h @@ -0,0 +1,229 @@ +/**************************************************************************** + * Core Library Version 1.7, August 2004 + * Copyright (c) 1995-2004 Exact Computation Project + * All rights reserved. + * + * This file is part of CORE (http://cs.nyu.edu/exact/core/). + * 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. + * + * + * File: CoreAux.cpp + * Synopsis: + * Auxiliary routines such as ceiling of log_2, etc. + * they are not specific to any Core classes. + * + * Written by + * Chee Yap + * Chen Li + * Zilin Du + * + * WWW URL: http://cs.nyu.edu/exact/ + * Email: exact@cs.nyu.edu + * + * $URL$ + * $Id$ + ***************************************************************************/ + +#ifdef CGAL_HEADER_ONLY +#define CGAL_INLINE_FUNCTION inline +#else +#define CGAL_INLINE_FUNCTION +#endif + +#include +#include + +namespace CORE { + +//////////////////////////////////////////////////////////// +// More useful functions to implement: +// +// To convert digits into bits: +// given X, compute X * log_2(10) +// To convert bits into digits: +// given X, compute X * log_10(2) +// +//////////////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// flrLg(x) +// returns floor log base 2 of abs(x) +// CONVENTION lg(0) = -1 (Slight improvement, Zilin/Chee 8/5/02) +//////////////////////////////////////////////////////////// +CGAL_INLINE_FUNCTION +int flrLg(long x) { + if (x == LONG_MIN) { + // special treatment as -LONG_MIN would be not representable as "long" + return LONG_BIT - 1; + } else { + // 1 <= |x| <= LONG_MAX + if (x < 0) + x = - x; + + int lg = -1; + while (x > 0) { + lg++; + x >>= 1; + } + return lg; + } +} + +//////////////////////////////////////////////////////////// +// floor log base 2 of unsigned long x +// CONVENTION lg(0) = -1 (Slight improvement, Zilin/Chee 8/5/02) +//////////////////////////////////////////////////////////// +CGAL_INLINE_FUNCTION +int flrLg(unsigned long x) { + int lg = -1; + while (x > 0) { + lg++; + x >>= 1; + } + return lg; +} + +//////////////////////////////////////////////////////////// +// ceiling log base 2 of abs(x) +// CONVENTION lg(0) = -1 (Slight improvement, Zilin/Chee 8/5/02) +//////////////////////////////////////////////////////////// +CGAL_INLINE_FUNCTION +int clLg(long x) { + if (x == LONG_MIN) + return LONG_BIT - 1; + if (x < 0) + x = -x; // use absolute value + if (x > (LONG_MAX >> 1)) // the leading data bit is 1 + return (LONG_BIT - 1); // exclude the sign bit + if (x >= 2) + return flrLg((unsigned long)((x << 1) - 1)); + // SINCE ceilLog_2(x) = floorLog_2(2x-1) for x>=2 + if (x == 1) + return 0; + return -1; // x must be 0 here +} + +//////////////////////////////////////////////////////////// +// ceiling log base 2 of unsigned long x +// CONVENTION lg(0) = -1 +//////////////////////////////////////////////////////////// +CGAL_INLINE_FUNCTION +int clLg(unsigned long x) { + if (x > (ULONG_MAX >> 1)) // the leading bit is 1 + return LONG_BIT; + if (x >= 2) + return flrLg((x << 1) - 1); + // SINCE ceilLog_2(x) = floorLog_2(2x-1) for x>=2. + if (x == 1) + return 0; + return -1; // x must be equal to 0 +} + +/// gcd for machine type long +/** This is needed when we construct Polynomials with int or long coefficients */ +CGAL_INLINE_FUNCTION +long gcd(long m, long n) { + if (m == 0) + return core_abs(n); + if (n == 0) + return core_abs(m); + long p = core_abs(m); + long q = core_abs(n); + if (p0) { + long r = p % q; + p = q; + q = r; + } + return p; +} + +// return a gmp_randstate_t structure +CGAL_INLINE_FUNCTION +gmp_randstate_t* getRandstate() { + static gmp_randstate_t rstate; + static bool initialized = false; + if (!initialized) { + gmp_randinit(rstate, GMP_RAND_ALG_DEFAULT, 32L); + initialized = true; + } + return &rstate; +} + +// char* core_itoa(int n, char* buffer) +// returns a pointer to the null-terminated string in buffer +// NOTES: +// 0. Buffer size should be 17 bytes (resp., 33 bytes, 65 bytes) on 16-bit +// (resp., 32-bit, 64-bit) machines. Formula: 1+sizeof(int)*8 bytes. +// 1. itoa(...) is available on some stdlib.h, but it is +// not defined by ANSI-C and so not all compilers support it. +// 2. Our use of sprintf(...) to do the job is known to +// be inefficient, but this is hardly critical for our usage. +// 3. A more general program should take a 3rd argument (the radix of +// output number). We assume radix 10. +CGAL_INLINE_FUNCTION +char * core_itoa(int n, char* buffer) { + std::sprintf(buffer, "%d", n); + return buffer; +} + +/// implements the "integer mantissa" function +// (See CORE_PATH/progs/ieee/frexp.cpp for details) +CGAL_INLINE_FUNCTION +double IntMantissa(double d) { + int e; + return std::ldexp(std::frexp(d, &e), 53); +} + +/// implements the "integer exponent" function +// (See CORE_PATH/progs/ieee/frexp.cpp for details) +CGAL_INLINE_FUNCTION +int IntExponent(double d) { + int e; + std::frexp(d, &e); + return e-53; +} + +/// CORE_DIAGFILE is file name for core_error(..) output. +const char* CORE_DIAGFILE = "Core_Diagnostics"; // global file name + +/// core_error is the method to write Core Library warning or error messages +/** Both warnings and errors are written to a file called CORE_DIAGFILE. + * But errors are also written on std:cerr (similar to std::perror()). + * */ +// Usage: core_error(message, file_with_error, line_number, err_type) +// where err_type=0 means WARNING, error_type=0 means ERROR +CGAL_INLINE_FUNCTION +void core_error(std::string msg, std::string file, int lineno, bool err) { + std::ofstream outFile(CORE_DIAGFILE, std::ios::app); // open to append + if (!outFile) { + // perror("CORE ERROR: cannot open Core Diagnostics file"); + std::cerr << "CORE ERROR: can't open Core Diagnostics file"< +#ifdef CGAL_HEADER_ONLY +#undef CGAL_EXPORT // CJTODO: TEMPORARY +#undef CGAL_CORE_EXPORT +#define CGAL_EXPORT +#define CGAL_CORE_EXPORT +#endif + +#ifdef CGAL_HEADER_ONLY + + #define CGAL_GLOBAL_STATE_VAR(TYPE, NAME, VALUE) \ + inline TYPE & get_static_##NAME() \ + { \ + static TYPE NAME = VALUE; \ + return NAME; \ + } + +#else // CGAL_HEADER_ONLY + + #define CGAL_GLOBAL_STATE_VAR(TYPE, NAME, VALUE) \ + CGAL_EXPORT extern TYPE NAME; \ + inline TYPE& get_static_##NAME() \ + { \ + return NAME; \ + } + +#endif // CGAL_HEADER_ONLY + namespace CORE { ////////////////////////////////////////////////////////////// @@ -60,34 +87,34 @@ namespace CORE { /** The normal behavior is to abort when an invalid expression * is constructed. This flag can be used to turn off this abort. * In any case, an error message will be printed */ -CGAL_CORE_EXPORT extern bool AbortFlag; +CGAL_GLOBAL_STATE_VAR(bool, AbortFlag, true) /// Invalid Flag -- initiallly value is non-negative /** If the Abort Flag is false, then the Invalid flag will be set to * a negative value whenever an invalid expression is constructed. * It is the user's responsibility to check this flag and to make * it non-negative again. */ -CGAL_CORE_EXPORT extern int InvalidFlag; +CGAL_GLOBAL_STATE_VAR(int, InvalidFlag, 0) /// Escape Precision in bits -CGAL_CORE_EXPORT extern extLong EscapePrec; +CGAL_GLOBAL_STATE_VAR(extLong, EscapePrec, CORE_posInfty) /// current ur when EscapePrec triggered /** this flag becomes negative when default EscapePrec is applied */ -CGAL_CORE_EXPORT extern long EscapePrecFlag; +CGAL_GLOBAL_STATE_VAR(long, EscapePrecFlag, 0) /// Escape Precision Warning Flag /** this flag is true by default, and will cause a warning to be printed when EscapePrec is reached */ -CGAL_CORE_EXPORT extern bool EscapePrecWarning; +CGAL_GLOBAL_STATE_VAR(bool, EscapePrecWarning, true) // These following two values determine the precision of computing // approximations in Expr. /// default Relative Precision in bits -CGAL_CORE_EXPORT extern extLong defRelPrec; +CGAL_GLOBAL_STATE_VAR(extLong, defRelPrec, 60) /// default Absolute Precision in bits -CGAL_CORE_EXPORT extern extLong defAbsPrec; +CGAL_GLOBAL_STATE_VAR(extLong, defAbsPrec, CORE_posInfty) /// default # of decimal digits for conversion from a BF to string. /** This value cannot be CORE_INFTY. @@ -97,42 +124,41 @@ CGAL_CORE_EXPORT extern extLong defAbsPrec; "controls the printout precision of std::cout for BigFloat" Perhaps, we should merge defOutputDigits and defBigFloatOutputDigits? */ -CGAL_CORE_EXPORT extern long defBigFloatOutputDigits; +CGAL_GLOBAL_STATE_VAR(long, defBigFloatOutputDigits, 10) /// default input precision in digits for converting a string to a Real or Expr /** This value can be CORE_INFTY */ -CGAL_CORE_EXPORT extern extLong defInputDigits; +CGAL_GLOBAL_STATE_VAR(extLong, defInputDigits, CORE_posInfty) /// controls the printout precision of std::cout for Real and Expr /** This value cannot be CORE_INFTY See also defBigFloatOutputDigits. (it really should be an int, as in std::cout.setprecision(int)). */ -CGAL_CORE_EXPORT extern long defOutputDigits; +CGAL_GLOBAL_STATE_VAR(long, defOutputDigits, get_static_defBigFloatOutputDigits()) /// default input precision in digits for converting a string to a BigFloat /** This value cannot be CORE_INFTY. */ -CGAL_CORE_EXPORT extern long defBigFloatInputDigits; +CGAL_GLOBAL_STATE_VAR(long, defBigFloatInputDigits, 16) /// default BigFloat Division Relative Precision -CGAL_CORE_EXPORT extern extLong defBFdivRelPrec; - +CGAL_GLOBAL_STATE_VAR(extLong, defBFdivRelPrec, 54) /// default BigFloat Sqrt Absolute Precision -CGAL_CORE_EXPORT extern extLong defBFsqrtAbsPrec; +CGAL_GLOBAL_STATE_VAR(extLong, defBFsqrtAbsPrec, 54) ////////////////////////////////////////////////////////////// // Mode parameters: incremental, progressive, filters ////////////////////////////////////////////////////////////// /// floating point filter flag -CGAL_CORE_EXPORT extern bool fpFilterFlag; +CGAL_GLOBAL_STATE_VAR(bool, fpFilterFlag, true) /// if true, evaluation of expressions would be incremental -CGAL_CORE_EXPORT extern bool incrementalEvalFlag; +CGAL_GLOBAL_STATE_VAR(bool, incrementalEvalFlag, true) /// progressive evaluation flag -CGAL_CORE_EXPORT extern bool progressiveEvalFlag; +CGAL_GLOBAL_STATE_VAR(bool, progressiveEvalFlag, true) /// rational reduction flag -CGAL_CORE_EXPORT extern bool rationalReduceFlag; +CGAL_GLOBAL_STATE_VAR(bool, rationalReduceFlag, false) /// default initial (bit) precision for AddSub Progressive Evaluation -CGAL_CORE_EXPORT extern long defInitialProgressivePrec; +CGAL_GLOBAL_STATE_VAR(long, defInitialProgressivePrec, 64) ////////////////////////////////////////////////////////////// // methods for setting global precision parameters @@ -144,87 +170,87 @@ CGAL_CORE_EXPORT extern long defInitialProgressivePrec; /** It determines the precision to which an Expr evaluates its (exact, implicit) constant value. */ inline void setDefaultPrecision(const extLong &r, const extLong &a) { - defRelPrec = r; - defAbsPrec = a; + get_static_defRelPrec() = r; + get_static_defAbsPrec() = a; } /// set default relative precision inline extLong setDefaultRelPrecision(const extLong &r) { - extLong old = defRelPrec; - defRelPrec = r; + extLong old = get_static_defRelPrec(); + get_static_defRelPrec() = r; return old; } /// set default absolute precision inline extLong setDefaultAbsPrecision(const extLong &a) { - extLong old = defAbsPrec; - defAbsPrec = a; + extLong old = get_static_defAbsPrec(); + get_static_defAbsPrec() = a; return old; } /// set default input digits (for Expr, Real) /** it controls the absolute error */ inline extLong setDefaultInputDigits(const extLong &d) { - extLong old = defInputDigits; - defInputDigits = d; + extLong old = get_static_defInputDigits(); + get_static_defInputDigits() = d; return old; } /// set default output digits (for Expr, Real) -inline long setDefaultOutputDigits(long d = defOutputDigits, +inline long setDefaultOutputDigits(long d = get_static_defOutputDigits(), std::ostream& o = std::cout) { - long old = defOutputDigits; - defOutputDigits = d; + long old = get_static_defOutputDigits(); + get_static_defOutputDigits() = d; o.precision(d); return old; } /// set default input digits for BigFloat inline long setDefaultBFInputDigits(long d) { - long old = defBigFloatInputDigits; - defBigFloatInputDigits = d; + long old = get_static_defBigFloatInputDigits(); + get_static_defBigFloatInputDigits() = d; return old; } /// set default output digits for BigFloat inline long setDefaultBFOutputDigits(long d) { - long old = defBigFloatOutputDigits; - defBigFloatOutputDigits = d; + long old = get_static_defBigFloatOutputDigits(); + get_static_defBigFloatOutputDigits() = d; return old; } /// turn floating-point filter on/off inline bool setFpFilterFlag(bool f) { - bool oldf = fpFilterFlag; - fpFilterFlag = f; + bool oldf = get_static_fpFilterFlag(); + get_static_fpFilterFlag() = f; return oldf; } /// turn incremental evaluation flag on/off inline bool setIncrementalEvalFlag(bool f) { - bool oldf = incrementalEvalFlag; - incrementalEvalFlag = f; + bool oldf = get_static_incrementalEvalFlag(); + get_static_incrementalEvalFlag() = f; return oldf; } /// turn progressive evaluation flag on/off inline bool setProgressiveEvalFlag(bool f) { - bool oldf = progressiveEvalFlag; - progressiveEvalFlag = f; + bool oldf = get_static_progressiveEvalFlag(); + get_static_progressiveEvalFlag() = f; return oldf; } /// set initial bit precision for progressive evaluation: inline long setDefInitialProgressivePrec(long n) { - long oldn = defInitialProgressivePrec; - defInitialProgressivePrec = n; + long oldn = get_static_defInitialProgressivePrec(); + get_static_defInitialProgressivePrec() = n; return oldn; } /// turn rational reduction flag on/off inline bool setRationalReduceFlag(bool f) { - bool oldf = rationalReduceFlag; - rationalReduceFlag = f; + bool oldf = get_static_rationalReduceFlag(); + get_static_rationalReduceFlag() = f; return oldf; } @@ -235,9 +261,9 @@ inline bool setRationalReduceFlag(bool f) { e.g., overriding the default std::cout precision (most systems initializes this value to 6) to our own */ inline void CORE_init(long d) { - defAbsPrec = CORE_posInfty; - defOutputDigits = d; - std::setprecision(defOutputDigits); + get_static_defAbsPrec() = CORE_posInfty; + get_static_defOutputDigits() = d; + std::setprecision(get_static_defOutputDigits()); } /// change to scientific output format @@ -251,4 +277,9 @@ inline void setPositionalFormat(std::ostream& o = std::cout) { } } //namespace CORE + +#ifdef CGAL_HEADER_ONLY +#include +#endif // CGAL_HEADER_ONLY + #endif // _CORE_COREDEFS_H_ diff --git a/CGAL_Core/include/CGAL/CORE/CoreDefs_impl.h b/CGAL_Core/include/CGAL/CORE/CoreDefs_impl.h new file mode 100644 index 00000000000..8fdd7b1e10e --- /dev/null +++ b/CGAL_Core/include/CGAL/CORE/CoreDefs_impl.h @@ -0,0 +1,170 @@ +/**************************************************************************** + * Core Library Version 1.7, August 2004 + * Copyright (c) 1995-2004 Exact Computation Project + * All rights reserved. + * + * This file is part of CORE (http://cs.nyu.edu/exact/core/). + * 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. + * + * + * File: CoreDefs.cpp + * Synopsis: + * Useful parameters for Core Library which users may change + * + * Written by + * Chee Yap + * Chen Li + * Zilin Du + * + * WWW URL: http://cs.nyu.edu/exact/ + * Email: exact@cs.nyu.edu + * + * $URL$ + * $Id$ + ***************************************************************************/ + +#include "CGAL/CORE/CoreDefs.h" + +#ifdef CGAL_HEADER_ONLY +#undef CGAL_EXPORT // CJTODO: TEMPORARY +#undef CGAL_CORE_EXPORT +#define CGAL_EXPORT +#define CGAL_CORE_EXPORT +#endif + +namespace CORE { + +// Default Values + +/* ************************************************************ + * ERROR FLAGS + * ************************************************************ */ + +#ifndef CGAL_HEADER_ONLY + +/** I/O error flag (Default value 0, indicating no error) + * User's responsibility to check and reset value to 0. */ +// This is currently used in geom2d/points2d.cpp for I/O of points + +// Note from 2014: does not seem to be used anywhere, and it is not declared +// in CoreDefs.h so it is not accessible +// Left here for compatibilty when CGAL_HEADER_ONLY is not defined + +int IOErrorFlag = 0; + +/** + * If AbortFlag is true when invalid expression is constructed, system will abort + */ + +bool AbortFlag = true; + +/** + * InvalidFlag is set to negative whenever an invalid expression is constructed. + * The user has the responsibility to reset to non-negative value. + */ + +int InvalidFlag = 0; + +/* ************************************************************ + * PRECISION PARAMETERS + * ************************************************************ */ + +/** + * Default BigFloat Division Relative Precision + * -- this is used by BigFloat division when the arguments are error-free. + */ + +extLong defBFdivRelPrec = 54; + +/** + * Default BigFloat Sqrt Absolute Precision + * -- this is used by BigFloat sqrt when the argument is error-free. + */ + +extLong defBFsqrtAbsPrec = 54; + +/** + * Escape Precision + * -- we will not compare a number to precision higher than this + * -- if this is infinity, there there is no escape precision */ +extLong EscapePrec = CORE_posInfty; + +/** this flag becomes negative if the EscapePrec is used. */ +long EscapePrecFlag = 0; + +/// Escape Precision Warning Flag +/** this flag is true by default, and will cause a warning to be printed + when EscapePrec is reached */ +bool EscapePrecWarning = true; + +/** The Composite Precision [defAbsPrec, defRelPrec] + * determines the precision to which an Expr evaluates its + * (exact, implicit) constant value. */ + +/** absolute precision = 2^31 - 1 */ +extLong defAbsPrec = CORE_posInfty; +/** default relative precision is 60 relative bits. + * Why 60? We would really like this to be 54, so that the default + * conversion duplicates the IEEE double precision. But it turns out + * (see README file under BUGS), we need 59 to ensure this. + * Chee Yap (7/1/01) */ +extLong defRelPrec = 60; + +/** number of BigFloat digits to print out */ +long defBigFloatOutputDigits = 10; + +/** NORMALLY, we like to make this equal to defBigFloatOutputDigits + * 8/3/01, Chee: re-introduced this parameter */ +long defOutputDigits = defBigFloatOutputDigits; + +/** String Input Precision */ + +/** Set this to 16 if you want machine precision. This controls the + * absolute error in string decimal inputs to Real or Expr. + * If defInputDigits is finite, then the absolute error will be + * at most 10^{-defInputDigits}. Otherwise, the input is exactly + * represented by some BigFloat or BigRat value. */ +extLong defInputDigits = CORE_posInfty; + +/** This controls the absolute error in converting from string to BigFloat + * The absolute error will be at most 10^{-defInputDigits} */ +long defBigFloatInputDigits = 16; + +/* ************************************************************ + * EVALUATION FLAGS + * ************************************************************ */ + +/** Floating Point filter + * true = turn on floating point filter */ +bool fpFilterFlag = true; + +/** IncrementaL evaluation flag + * incremental evaluation is requested, This means, we try to use previous + * approximate values to improve an approximation */ +bool incrementalEvalFlag = true; + +/** Progressive evaluation flag + * true = turn on progressive evaluation flag */ +bool progressiveEvalFlag = true; + +/** Initial progressive evaluation precision + * Used by AddSubRep */ +long defInitialProgressivePrec = 64; + +/** RATIONAL REDUCTION FLAG + * true = turn on rational reduction */ +bool rationalReduceFlag = false; + +#endif // CGAL_HEADER_ONLY + +} //namespace CORE + diff --git a/CGAL_Core/include/CGAL/CORE/CoreIO_impl.h b/CGAL_Core/include/CGAL/CORE/CoreIO_impl.h new file mode 100644 index 00000000000..2e3e10bcd8f --- /dev/null +++ b/CGAL_Core/include/CGAL/CORE/CoreIO_impl.h @@ -0,0 +1,488 @@ +/**************************************************************************** + * Core Library Version 1.7, August 2004 + * Copyright (c) 1995-2004 Exact Computation Project + * All rights reserved. + * + * This file is part of CORE (http://cs.nyu.edu/exact/core/). + * 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. + * + * + * File: CoreIO.cpp + * + * Written by + * Zilin Du + * Chee Yap + * + * WWW URL: http://cs.nyu.edu/exact/ + * Email: exact@cs.nyu.edu + * + * $URL$ + * $Id$ + ***************************************************************************/ + +#ifndef _COREIO_IMPL_H_ +#define _COREIO_IMPL_H_ + +#ifdef CGAL_HEADER_ONLY +#define CGAL_INLINE_FUNCTION inline +#else +#define CGAL_INLINE_FUNCTION +#endif + +#ifdef CGAL_HEADER_ONLY +#define CGAL_HEADERONLY_STATIC_FUNCTION static +#else +#define CGAL_HEADERONLY_STATIC_FUNCTION +#endif + +#include +#include +#include + +namespace CORE { + +CGAL_HEADERONLY_STATIC_FUNCTION +void core_io_error_handler(const char *f, const char *m) { + std::cout << "\n error_handler"; + std::cout << "::" << f << "::" << m << "\n"; + std::cout.flush(); + std::abort(); +} + +CGAL_HEADERONLY_STATIC_FUNCTION +void core_io_memory_handler(char *t, const char *f, const char *m) { + if (t == NULL) { + std::cout << "\n memory_handler"; + std::cout << "::" << f << "::" << m; + std::cout << "memory exhausted\n"; + std::cout.flush(); + std::abort(); + } +} + +// s has size old_size and will be resized to new_size. +CGAL_HEADERONLY_STATIC_FUNCTION +void allocate (char * &s, int old_size, int new_size) { + if (old_size > new_size) + old_size = new_size; + + if (s == NULL) + old_size = 0; + + char *t = new char[new_size]; + core_io_memory_handler(t, "CoreIO", "allocate::out of memory error"); + + int i; + for (i = 0; i < old_size; i++) + t[i] = s[i]; + + delete[] s; + s = t; +} + +// appends c to s at position pos. +// sz is the size of s +CGAL_HEADERONLY_STATIC_FUNCTION +void append_char (char * &s, int & sz, int pos, char c) { + if (pos > sz) + core_io_error_handler("CoreIO", "append_char::invalid argument"); + + if (pos == sz) { + allocate(s, sz, 2*sz); + sz *= 2; + } + + s[pos] = c; +} + +// skip blanks, tabs, line breaks and comment lines +CGAL_HEADERONLY_STATIC_FUNCTION +int skip_comment_line (std::istream & in) { + int c; + + do { + c = in.get(); + while ( c == '#' ) { + do { + c = in.get(); + } while ( c != '\n' ); + c = in.get(); + } + } while (c == ' ' || c == '\t' || c == '\n'); + + if (c == EOF) + core_io_error_handler("CoreIO::read_from_file()","unexpected end of file."); + + in.putback(c); + return c; +} + +// skips '\\' followed by '\n' +CGAL_HEADERONLY_STATIC_FUNCTION +int skip_backslash_new_line (std::istream & in) { + int c = in.get(); + + while (c == '\\') { + c = in.get(); + + if (c == '\n') + c = in.get(); + else + core_io_error_handler("CoreIO::operator>>", "\\ must be immediately followed by new line."); + } + + return c; +} + +CGAL_HEADERONLY_STATIC_FUNCTION +void read_string(std::istream& in, char* &buffer, int sz) { + int c, pos=0; + skip_comment_line(in); + + while ( (c = in.get()) != EOF ) { + if ( c == ' ' || c == '\t' || c == '\n' || c == '#') + break; + else + append_char(buffer, sz, pos++, c); + } + append_char(buffer, sz, pos, '\0'); +} + +CGAL_HEADERONLY_STATIC_FUNCTION +void read_base_number(std::istream& in, BigInt& m, long length, long maxBits) { + char *buffer; + int size, offset; + int base; + bool is_negate; + + int c, pos = 0; + skip_comment_line(in); + + // read sign + c = in.get(); + if (c == '-') { + is_negate = true; + c = in.get(); + } else + is_negate = false; + + // read base and compute digits + if (c == '0') { + c = in.get(); + if (c == 'b') { + base = 2; + size = (maxBits == 0 || maxBits > length) ? length : maxBits; + offset = length - size; + } else if (c == 'x') { + base = 16; + size = (maxBits == 0) ? length : (maxBits+3) >> 2; + size = (size > length) ? length : size; + offset = (length - size) << 2; + } else { + base = 8; + size = (maxBits == 0) ? length : (maxBits+2) / 3; + size = (size > length) ? length : size; + offset = (length - size) * 3; + in.putback(c); + } + } else { + base = 10; + size = (maxBits == 0) ? length : (int)std::ceil(maxBits*std::log(2.0)/std::log(10.0)); + size = (size > length) ? length : size; + offset = length - size; + in.putback(c); + } + + buffer = new char[size+2]; + // read digits + for (int i=0; (i 0 && base != 10) { + m <<= offset; + } + + if (is_negate) + negate(m); +} + + +CGAL_HEADERONLY_STATIC_FUNCTION +void write_base_number(std::ostream& out, char* buffer, int length, int base, int charsPerLine) { + // write big number in a format that gmp's mpz_set_str() can + // automatically recognize with argument base = 0. + if (base == 2) + out << "0b"; + else if (base == 16) + out << "0x"; + else if (base == 8) + out << '0'; + + // write big number in charsPerLine. + char* start, *end, c; + for (int i=0; i= length) + out << start; + else { + end = start + charsPerLine; + c = *end; + *end = '\0'; + + out << start << "\\\n"; + *end = c; + } + } +} + +CGAL_INLINE_FUNCTION +void readFromFile(BigInt& z, std::istream& in, long maxLength) { + char *buffer; + long length; + + // check type name whether it is Integer or not. + buffer = new char[8]; + read_string(in, buffer, sizeof(buffer)); + if ( std::strcmp(buffer, "Integer") != 0) + core_io_error_handler("BigInt::read_from_file()","type name expected."); + delete[] buffer; + + // read the bit length field. + buffer = new char[100]; + read_string(in, buffer, sizeof(buffer)); + length = std::atol(buffer); + delete[] buffer; + + // read bigint + read_base_number(in, z, length, maxLength); +} + +CGAL_INLINE_FUNCTION +void writeToFile(const BigInt& z, std::ostream& out, int base, int charsPerLine) { + BigInt c = abs(z); + + // get the absoulte value string + char* buffer = new char[mpz_sizeinbase(c.get_mp(), base) + 2]; + mpz_get_str(buffer, base, c.get_mp()); + int length = std::strlen(buffer); + + // write type name of big number and length + //out << "# This is an experimental big number format.\n"; + out << "Integer " << length << "\n"; + + // if bigint is negative, then write an sign '-'. + if ( sign(z) < 0 ) + out << '-'; + + write_base_number(out, buffer, length, base, charsPerLine); + out << "\n"; + delete[] buffer; +} + +CGAL_INLINE_FUNCTION +void readFromFile(BigFloat& bf, std::istream& in, long maxLength) { + char *buffer; + long length; + long exponent; + BigInt mantissa; + + // check type name whether it is Float + buffer = new char[6]; + read_string(in, buffer, sizeof(buffer)); + if (std::strcmp(buffer, "Float") != 0) + core_io_error_handler("BigFloat::read_from_file()", "type name expected"); + delete[] buffer; + + // read base (default is 16384) + buffer = new char[8]; + read_string(in, buffer, sizeof(buffer)); + if (std::strcmp(buffer, "(16384)") != 0) + core_io_error_handler("BigFloat::read_from_file()", "base expected"); + delete[] buffer; + + // read the bit length field. + buffer = new char[100]; + read_string(in, buffer, sizeof(buffer)); + length = std::atol(buffer); + delete[] buffer; + + // read exponent + buffer = new char[100]; + read_string(in, buffer, sizeof(buffer)); + exponent = std::atol(buffer); + delete[] buffer; + + // read mantissa + read_base_number(in, mantissa, length, maxLength); + + // construct BigFloat + bf = BigFloat(mantissa, 0, exponent); +} + +CGAL_INLINE_FUNCTION +void writeToFile(const BigFloat& bf, std::ostream& out, int base, int charsPerLine) { + BigInt c(CORE::abs(bf.m())); + + // get the absoulte value string + char* buffer = new char[mpz_sizeinbase(c.get_mp(), base) + 2]; + mpz_get_str(buffer, base, c.get_mp()); + int length = std::strlen(buffer); + + + // write type name, base, length + //out << "# This is an experimental Big Float format." << std::endl; + out << "Float (16384) " << length << std::endl; + // write exponent + out << bf.exp() << std::endl; + + // write mantissa + if ( CORE::sign(bf.m()) < 0 ) + out << '-'; + + write_base_number(out, buffer, length, base, charsPerLine); + out << '\n'; + delete[] buffer; +} + +/* Underconstruction ---- +void BigFloat::read_from_file2(std::istream& in, long maxLength) { + long length = 1024; + char *buffer; + + // check type name whether it is Float + buffer = new char[7]; + BigInt::read_string(in, buffer, sizeof(buffer)); + if (strcmp(buffer, "NFloat") != 0) + core_io_error_handler("BigFloat::read_from_file2()", "type name expected"); + delete[] buffer; + + // read base (default is 16) + buffer = new char[5]; + BigInt::read_string(in, buffer, sizeof(buffer)); + if (strcmp(buffer, "(16)") != 0) + core_io_error_handler("BigFloat::read_from_file2()", "base expected"); + delete[] buffer; + + // read length field + buffer = new char[100]; + BigInt::read_string(in, buffer, sizeof(buffer)); + + // get the length field if it is not null. + if (buffer[0] != '\0') { + length = atol(buffer); + if (maxLength > 0 && length >= maxLength) + length = maxLength; + } + delete[] buffer; + + // read exponent + buffer = new char[100]; + BigInt::read_string(in, buffer, sizeof(buffer)); + long exp16 = atol(buffer); + delete[] buffer; + + // read mantissa + buffer = new char[length+2]; + //BigInt::read_base_number(in, buffer, length); + + BigInt m16(buffer); + delete[] buffer; + + // convert to base CHUNK_BIT + exp16 = exp16 - length + 1; + if ( m16.is_negative() ) + exp16 ++; + + long tmp_exp = exp16 * 4; + long q = tmp_exp / CHUNK_BIT; + long r = tmp_exp % CHUNK_BIT; + if ( r < 0 ) { + r += CHUNK_BIT; + q --; + } + + BigInt mantissa = m16 << r; + long exponent = q; + + // construct BigFloat + if (--rep->refCount == 0) + delete rep; + + rep = new BigFloatRep(mantissa, 0, exponent); + rep->refCount++; + +} + +// write normal float +// now it assumed to write in hex base, i.e. B=2^4=16 +// (note: our default base B=2^(CHUNK_BIT)=2^14=16384 +void BigFloat::write_to_file2(std::ostream& out, int base, int charsPerLine) { + // convert to base 16. + long new_base = 4; // 2^4 = 16 + long tmp_exp = (rep->exp) * CHUNK_BIT; + long q = tmp_exp / new_base; + long r = tmp_exp % new_base; + std::cout << "CORE_DEBUG: q=" << q << ", r=" << r << std::endl; + if ( r < 0 ) { + r += new_base; + q--; + } + std::cout << "CORE_DEBUG: q=" << q << ", r=" << r << std::endl; + + BigInt m16 = (rep->m) << r; + + int size = mpz_sizeinbase(m16.I, base) + 2; + std::cout << "size=" << size << std::endl; + char* buffer = new char[size]; + + int length = bigint_to_string(m16, buffer, base); + std::cout << "length=" << length << std::endl; + + long exp16 = q + length - 1; + if ( m16.is_negative() ) + exp16 --; + + // write type name, base, length + out << "# This is an experimental Big Float format." << std::endl; + out << "NFloat (16) " << length << std::endl; + + // write exponent + out << exp16 << std::endl; + + // write mantissa + if ( m16.is_negative() ) { + out << '-'; + buffer ++; + } + + BigInt::write_base_number(out, buffer, length, base, charsPerLine); + out << '\n'; + delete[] buffer; +} +*/ + +} //namespace CORE + +#endif // _COREIO_IMPL_H_ diff --git a/CGAL_Core/include/CGAL/CORE/Expr.h b/CGAL_Core/include/CGAL/CORE/Expr.h index f38795eb720..90f9ca3e784 100644 --- a/CGAL_Core/include/CGAL/CORE/Expr.h +++ b/CGAL_Core/include/CGAL/CORE/Expr.h @@ -36,11 +36,22 @@ * $Id$ ***************************************************************************/ +// We need to include BigFloat.h here because there is a circular dependency +// between Expr and BigFloat. +#include + #ifndef _CORE_EXPR_H_ #define _CORE_EXPR_H_ #include +#ifdef CGAL_HEADER_ONLY +#undef CGAL_EXPORT // CJTODO: TEMPORARY +#undef CGAL_CORE_EXPORT +#define CGAL_EXPORT +#define CGAL_CORE_EXPORT +#endif + namespace CORE { /// \class Expr Expr.h @@ -78,9 +89,9 @@ public: // (i.e., not infinite and not NaN) if (! CGAL_CORE_finite(f)) { std::cerr << " ERROR : constructed an invalid float! " << std::endl; - if (AbortFlag) + if (get_static_AbortFlag()) abort(); - InvalidFlag = -1; + get_static_InvalidFlag() = -1; } rep = new ConstDoubleRep(f); } @@ -89,9 +100,9 @@ public: // (i.e., not infinite and not NaN) if (! CGAL_CORE_finite(d)) { std::cerr << " ERROR : constructed an invalid double! " << std::endl; - if (AbortFlag) + if (get_static_AbortFlag()) abort(); - InvalidFlag = -2; + get_static_InvalidFlag() = -2; } rep = new ConstDoubleRep(d); } @@ -111,11 +122,11 @@ public: * it is generally recommended that the (String) constructor be used in * preference to the (double) constructor. */ - Expr(const char *s, const extLong& p = defInputDigits) + Expr(const char *s, const extLong& p = get_static_defInputDigits()) : RCExpr(new ConstRealRep(Real(s, p))) {} /// constructor for std::string - Expr(const std::string& s, const extLong& p = defInputDigits) + Expr(const std::string& s, const extLong& p = get_static_defInputDigits()) : RCExpr(new ConstRealRep(Real(s, p))) {} /// constructor for Real @@ -179,9 +190,9 @@ public: Expr& operator/=(const Expr& e) { if ((e.rep)->getSign() == 0) { std::cerr << " ERROR : division by zero ! " << std::endl; - if (AbortFlag) + if (get_static_AbortFlag()) abort(); - InvalidFlag = -3; + get_static_InvalidFlag() = -3; } *this = new DivRep(rep, e.rep); return *this; @@ -225,12 +236,12 @@ public: /// \name String Conversion Functions //@{ /// set value from const char* - void fromString(const char* s, const extLong& prec = defInputDigits) { + void fromString(const char* s, const extLong& prec = get_static_defInputDigits()) { *this = Expr(s, prec); } /// convert to std::string /** give decimal string representation */ - std::string toString(long prec=defOutputDigits, bool sci=false) const { + std::string toString(long prec=get_static_defOutputDigits(), bool sci=false) const { return rep->toString(prec, sci); } //@} @@ -282,8 +293,8 @@ public: /** Here is the definition of what this means: If e is the exact value and ee is the approximate value, then |e - ee| <= 2^{-a} or |e - ee| <= 2^{-r} |e|. */ - const Real & approx(const extLong& relPrec = defRelPrec, - const extLong& absPrec = defAbsPrec) const { + const Real & approx(const extLong& relPrec = get_static_defRelPrec(), + const extLong& absPrec = get_static_defAbsPrec()) const { return rep->getAppValue(relPrec, absPrec); } //@} @@ -355,7 +366,7 @@ inline std::ostream& operator<<(std::ostream& o, const Expr& e) { /// I/O Stream operator>> inline std::istream& operator>>(std::istream& i, Expr& e) { Real rVal; - i >> rVal; // precision is = defInputDigits + i >> rVal; // precision is = get_static_defInputDigits() if (i) e = rVal; // only assign when reading is successful. return i; @@ -382,9 +393,9 @@ inline Expr operator*(const Expr& e1, const Expr& e2) { inline Expr operator/(const Expr& e1, const Expr& e2) { if (e2.sign() == 0) { std::cerr << " ERROR : division by zero ! " << std::endl; - if (AbortFlag) + if (get_static_AbortFlag()) abort(); - InvalidFlag = -4; + get_static_InvalidFlag() = -4; } return Expr(new DivRep(e1.Rep(), e2.Rep())); } @@ -485,9 +496,9 @@ inline bool isDivisible(const Expr& e1, const Expr& e2) { inline Expr sqrt(const Expr& e) { if (e.sign() < 0) { std::cerr << " ERROR : sqrt of negative value ! " << std::endl; - if (AbortFlag) + if (get_static_AbortFlag()) abort(); - InvalidFlag = -5; + get_static_InvalidFlag() = -5; } return Expr(new SqrtRep(e.Rep())); } @@ -548,4 +559,9 @@ inline Expr radical(const NT& n, int m) { #include } //namespace CORE + +#ifdef CGAL_HEADER_ONLY +#include +#endif // CGAL_HEADER_ONLY + #endif // _CORE_EXPR_H_ diff --git a/CGAL_Core/include/CGAL/CORE/ExprRep.h b/CGAL_Core/include/CGAL/CORE/ExprRep.h index 19c5bbc84cb..40b228aa1ab 100644 --- a/CGAL_Core/include/CGAL/CORE/ExprRep.h +++ b/CGAL_Core/include/CGAL/CORE/ExprRep.h @@ -43,9 +43,16 @@ #include #include +#ifdef CGAL_HEADER_ONLY +#undef CGAL_EXPORT // CJTODO: TEMPORARY +#undef CGAL_CORE_EXPORT +#define CGAL_EXPORT +#define CGAL_CORE_EXPORT +#endif + namespace CORE { -#ifdef CORE_DEBUG_BOUND +#if defined(CORE_DEBUG_BOUND) && !defined(CGAL_HEADER_ONLY) // These counters are incremented each time each bound is recognized as equal // to the best one in computeBound(). extern unsigned int BFMSS_counter; @@ -189,8 +196,8 @@ public: /// \name Helper Functions //@{ /// Get the approximate value - CGAL_CORE_EXPORT const Real & getAppValue(const extLong& relPrec = defRelPrec, - const extLong& absPrec = defAbsPrec); + CGAL_CORE_EXPORT const Real & getAppValue(const extLong& relPrec = get_static_defRelPrec(), + const extLong& absPrec = get_static_defAbsPrec()); /// Get the sign. int getSign(); int getExactSign(); @@ -389,8 +396,8 @@ public: BigFloat BigFloatValue(); /// represent as a string in decimal value // toString() Joaquin Grech 31/5/2003 - std::string toString(long prec=defOutputDigits, bool sci=false) { - return (getAppValue(defRelPrec, defAbsPrec)).toString(prec,sci); + std::string toString(long prec=get_static_defOutputDigits(), bool sci=false) { + return (getAppValue(get_static_defRelPrec(), get_static_defAbsPrec())).toString(prec,sci); } //@} @@ -677,7 +684,7 @@ protected: tc() = ceilLg(ss.seq[0].getTailCoeff()); // no rational reduction - if (rationalReduceFlag) + if (get_static_rationalReduceFlag()) ratFlag() = -1; flagsComputed() = true; @@ -838,7 +845,12 @@ protected: /// \brief "functor" class used as parameter to AddSubRep<> struct Add { /// name +#ifndef CGAL_HEADER_ONLY CGAL_CORE_EXPORT static const char* name; +#endif + static const char* get_name() { + return "+"; + } /// unary operator template @@ -857,7 +869,12 @@ struct Add { /// \brief "functor" class used as parameter to AddSubRep<> struct Sub { /// name +#ifndef CGAL_HEADER_ONLY CGAL_CORE_EXPORT static const char* name; +#endif + static const char* get_name() { + return "-"; + } /// unary operator template @@ -895,7 +912,7 @@ protected: void computeApproxValue(const extLong&, const extLong&); /// return operator in string const std::string op() const { - return Operator::name; + return Operator::get_name(); } private: static Operator Op; @@ -925,7 +942,7 @@ void AddSubRep::computeExactFlags() { reduceTo(second); sign() = Op(ss); appValue() = Op(appValue()); - if (rationalReduceFlag && ratFlag() > 0) + if (get_static_rationalReduceFlag() && ratFlag() > 0) *(ratValue()) = Op(*(ratValue())); return; } else if (ss == 0) { // second operand is zero @@ -933,7 +950,7 @@ void AddSubRep::computeExactFlags() { return; } // rational node - if (rationalReduceFlag) { + if (get_static_rationalReduceFlag()) { if (first->ratFlag() > 0 && second->ratFlag() > 0) { BigRat val=Op(*(first->ratValue()), *(second->ratValue())); reduceToBigRat(val); @@ -1046,7 +1063,7 @@ void AddSubRep::computeExactFlags() { if (lowBound <= EXTLONG_ZERO) lowBound = EXTLONG_ONE; - if (!progressiveEvalFlag) { + if (!get_static_progressiveEvalFlag()) { // convert the absolute error requirement "lowBound" to // a relative error requirement "ur", s.t. // |x|*2^(-ur) <= 2^(-lowBound). @@ -1085,7 +1102,7 @@ void AddSubRep::computeExactFlags() { // larger than lowBound AND the defaultInitialProgressivePrec, // so that we do at least one iteration of the for-loop. So: // i is the variable for iteration. - extLong i = core_min(defInitialProgressivePrec, lowBound.asLong()); + extLong i = core_min(get_static_defInitialProgressivePrec(), lowBound.asLong()); extLong ua = lowBound.asLong() + EXTLONG_ONE; // NOTE: ua is allowed to be CORE_INFTY @@ -1096,7 +1113,7 @@ void AddSubRep::computeExactFlags() { lMSB() = CORE_negInfty; sign() = 0; - EscapePrecFlag = 0; // reset the Escape Flag + get_static_EscapePrecFlag() = 0; // reset the Escape Flag // Now we try to determine the real lMSB and sign, // in case it is not really zero: @@ -1151,22 +1168,22 @@ void AddSubRep::computeExactFlags() { break; // assert -- this must happen in the loop if nonzero! } //8/9/01, Chee: implement escape precision here: - if (i> EscapePrec) { - EscapePrecFlag = -i.asLong();//negative means EscapePrec is used + if (i> get_static_EscapePrec()) { + get_static_EscapePrecFlag() = -i.asLong();//negative means EscapePrec is used core_error("Escape precision triggered at", __FILE__, __LINE__, false); - if (EscapePrecWarning) + if (get_static_EscapePrecWarning()) std::cout<< "Escape Precision triggered at " - << EscapePrec << " bits" << std::endl; + << get_static_EscapePrec() << " bits" << std::endl; #ifdef CORE_DEBUG - std::cout << "EscapePrecFlags=" << EscapePrecFlag << std::endl; + std::cout << "EscapePrecFlags=" << get_static_EscapePrecFlag() << std::endl; std::cout << "ua =" << ua << ",lowBound=" << lowBound << std::endl; #endif break; }// if }// for (long i=1...) -#ifdef CORE_DEBUG_BOUND +#if defined(CORE_DEBUG_BOUND) && !defined(CGAL_HEADER_ONLY) rootBoundHitCounter++; #endif diff --git a/CGAL_Core/include/CGAL/CORE/Expr_impl.h b/CGAL_Core/include/CGAL/CORE/Expr_impl.h new file mode 100644 index 00000000000..42ef3136c61 --- /dev/null +++ b/CGAL_Core/include/CGAL/CORE/Expr_impl.h @@ -0,0 +1,1213 @@ +/**************************************************************************** + * Core Library Version 1.7, August 2004 + * Copyright (c) 1995-2004 Exact Computation Project + * All rights reserved. + * + * This file is part of CORE (http://cs.nyu.edu/exact/core/). + * 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. + * + * + * File: Expr.cpp + * + * Written by + * Koji Ouchi + * Chee Yap + * Igor Pechtchanski + * Vijay Karamcheti + * Chen Li + * Zilin Du + * Sylvain Pion + * + * WWW URL: http://cs.nyu.edu/exact/ + * Email: exact@cs.nyu.edu + * + * $URL$ + * $Id$ + ***************************************************************************/ + +#ifdef CGAL_HEADER_ONLY +#define CGAL_INLINE_FUNCTION inline +#else +#define CGAL_INLINE_FUNCTION +#endif + +#include +#include + +namespace CORE { + +#if defined(CORE_DEBUG_BOUND) && !defined(CGAL_HEADER_ONLY) +unsigned int BFMSS_counter = 0; +unsigned int BFMSS_only_counter = 0; +unsigned int Measure_counter = 0; +unsigned int Measure_only_counter = 0; +unsigned int Cauchy_counter = 0; +unsigned int Cauchy_only_counter = 0; +unsigned int LiYap_counter = 0; +unsigned int LiYap_only_counter = 0; +unsigned int rootBoundHitCounter = 0; +unsigned int computeBoundCallsCounter = 0; +#endif + +#ifndef CGAL_HEADER_ONLY +const char* Add::name = "+"; +const char* Sub::name = "-"; +#endif + +/******************************************************** + * class Expr + ********************************************************/ +CGAL_INLINE_FUNCTION +const Expr& Expr::getZero() { + static Expr Zero(0); + return Zero; +} +CGAL_INLINE_FUNCTION +const Expr& Expr::getOne() { + static Expr One(1); + return One; +} + +// computes an interval comprising a pair of doubles +// Note: +// +// This function returns are two consecutive representable binary +// IEEE double values whichs contain the real value, but when you print out +// them, you might be confused by the decimal represention due to round. +// +CGAL_INLINE_FUNCTION +void Expr::doubleInterval(double & lb, double & ub) const { + double d = doubleValue(); + if (! CGAL_CORE_finite(d)) { // if overflow, underflow or NaN + lb = ub = d; + return; + } + int sign = ((* this) -Expr(d)).sign(); + // Seems like doubleValue() always give a lower bound, + // so sign = 0 or 1 (never -1). + //std::cout << "Sign = " << sign << std::endl; + if (sign == 0) { + lb = ub = d; + return; + } + int exp; + frexp(d, & exp); // get the exponent of d + exp--; // the exp from frexp satisfies + // 2^{exp-1} <= d < 2^{exp} + // But, we want exp to satisfy + // 2^{exp} <= d < 2^{exp+1} + if (sign > 0) { + lb = d; + ub = d + ldexp(1.0, -52+exp); + return; + } else { + ub = d; + lb = d - ldexp(1.0, -52+exp); + return; + } +} + +// floor(e, sub) returns the floor(e), and puts the +// remainder into sub. +CGAL_INLINE_FUNCTION +BigInt floor(const Expr& e, Expr &sub) { + if (e==0) { + return 0; + } + BigInt f = e.approx(CORE_INFTY, 2).BigIntValue(); + sub = e-f; + // Adjustment + if (sub<0) + ++sub, --f; + if (sub>=1) + --sub, ++f; + assert(sub >=0 && sub<1); // got an assertion error? (Chee 3/24/04) + return f; +} + +// Chenli: implemented algorithm from Goldberg's article. +// 7/01: Thanks to Serge Pashkov for fixing infinite loop when n=0. +CGAL_INLINE_FUNCTION +Expr pow(const Expr& e, unsigned long n) { + if (n == 0) + return Expr(1); + else if (n == 1) + return e; + else { + Expr x = e; + while ((n % 2) == 0) { // n is even + x *= x; + n >>= 1; + } + Expr u = x; + while (true) { + n >>= 1; + if (n == 0) + return u; + x *= x; + if ((n % 2) == 1) // n is odd + u *= x; + } + //return u; // unreachable + } +}//pow + +CGAL_INLINE_FUNCTION +NodeInfo::NodeInfo() : appValue(CORE_REAL_ZERO), appComputed(false), + flagsComputed(false), knownPrecision(CORE_negInfty), +#ifdef CORE_DEBUG + relPrecision(EXTLONG_ZERO), absPrecision(CORE_negInfty), numNodes(0), +#endif + // Most of the following data members don't need to be + // initialized here. + d_e(EXTLONG_ZERO), visited(false), sign(0), + uMSB(CORE_negInfty), lMSB(CORE_negInfty), + // length(0), + measure(EXTLONG_ZERO), high(EXTLONG_ZERO), low(EXTLONG_ONE), + lc(EXTLONG_ZERO), tc(EXTLONG_ZERO), + v2p(EXTLONG_ZERO), v2m(EXTLONG_ZERO), + v5p(EXTLONG_ZERO), v5m(EXTLONG_ZERO), + u25(EXTLONG_ZERO), l25(EXTLONG_ZERO), + ratFlag(0), ratValue(NULL) { } + +/******************************************************** + * class ExprRep + ********************************************************/ +// constructor +CGAL_INLINE_FUNCTION +ExprRep::ExprRep() : refCount(1), nodeInfo(NULL), ffVal(0.0) { } + +// Computes the root bit bound of the expression. +// In effect, computeBound() returns the current value of low. +CGAL_INLINE_FUNCTION +extLong ExprRep::computeBound() { + extLong measureBd = measure(); + // extLong cauchyBd = length(); + extLong ourBd = (d_e() - EXTLONG_ONE) * high() + lc(); + // BFMSS[2,5] bound. + extLong bfmsskBd; + if (v2p().isInfty() || v2m().isInfty()) + bfmsskBd = CORE_INFTY; + else + bfmsskBd = l25() + u25() * (d_e() - EXTLONG_ONE) - v2() - ceilLg5(v5()); + + // since we might compute \infty - \infty for this bound + if (bfmsskBd.isNaN()) + bfmsskBd = CORE_INFTY; + + extLong bd = core_min(measureBd, + // core_min(cauchyBd, + core_min(bfmsskBd, ourBd)); +#ifdef CORE_SHOW_BOUNDS + std::cout << "Bounds (" << measureBd << + "," << bfmsskBd << ", " << ourBd << "), "; + std::cout << "MIN = " << bd << std::endl; + std::cout << "d_e= " << d_e() << std::endl; +#endif + +#if defined(CORE_DEBUG_BOUND) && !defined(CGAL_HEADER_ONLY) + // Some statistics about which one is/are the winner[s]. + computeBoundCallsCounter++; + int number_of_winners = 0; + std::cerr << " New contest " << std::endl; + if (bd == bfmsskBd) { + BFMSS_counter++; + number_of_winners++; + std::cerr << " BFMSS is the winner " << std::endl; + } + if (bd == measureBd) { + Measure_counter++; + number_of_winners++; + std::cerr << " measureBd is the winner " << std::endl; + } + /* if (bd == cauchyBd) { + Cauchy_counter++; + number_of_winners++; + std::cerr << " cauchyBd is the winner " << std::endl; + } + */ + if (bd == ourBd) { + LiYap_counter++; + number_of_winners++; + std::cerr << " ourBd is the winner " << std::endl; + } + + assert(number_of_winners >= 1); + + if (number_of_winners == 1) { + if (bd == bfmsskBd) { + BFMSS_only_counter++; + std::cerr << " BFMSSBd is the only winner " << std::endl; + } else if (bd == measureBd) { + Measure_only_counter++; + std::cerr << " measureBd is the only winner " << std::endl; + } + /* else if (bd == cauchyBd) { + Cauchy_only_counter++; + std::cerr << " cauchyBd is the only winner " << std::endl; + } */ + else if (bd == ourBd) { + LiYap_only_counter++; + std::cerr << " ourBd is the only winner " << std::endl; + } + } +#endif + + return bd; +}//computeBound() + +CGAL_INLINE_FUNCTION +void ExprRep::reduceToBigRat(const BigRat& rat) { + Real value(rat); + + //appValue() = value; + appComputed() = false; // since appValue is not assigned until approx() is called + flagsComputed() = true; + knownPrecision() = CORE_negInfty; + +#ifdef CORE_DEBUG + relPrecision() = EXTLONG_ZERO; + absPrecision() = CORE_negInfty; + //numNodes() = numNodes(); +#endif + + d_e() = EXTLONG_ONE; + //visited() = e->visited(); + sign() = value.sign(); + uMSB() = value.MSB(); + lMSB() = value.MSB(); + // length() = value.length(); // fixed? original = 1 + measure() = value.height(); // measure <= height for rational value + + // BFMSS[2,5] bound. + value.ULV_E(u25(), l25(), v2p(), v2m(), v5p(), v5m()); + + extLong u_e = u25() + v2p(); + extLong l_e = l25() + v2m(); + + u_e = u_e + ceilLg5(v5p()); + l_e = l_e + ceilLg5(v5m()); + + if (l_e == EXTLONG_ZERO) { // no divisions introduced + high() = u_e; + low() = EXTLONG_ONE - u_e; // - (u_e - 1) + } else { + high() = u_e - l_e + EXTLONG_ONE; + low() = 2 - high(); + } + + lc() = l_e; + tc() = u_e; + + if (ratValue() == NULL) + ratValue() = new BigRat(rat); + else + *(ratValue()) = rat; +} + +// This only copies the current information of the argument e to +// *this ExprRep. +CGAL_INLINE_FUNCTION +void ExprRep::reduceTo(const ExprRep *e) { + if (e->appComputed()) { + appValue() = e->appValue(); + appComputed() = true; + flagsComputed() = true; + knownPrecision() = e->knownPrecision(); +#ifdef CORE_DEBUG + relPrecision() = e->relPrecision(); + absPrecision() = e->absPrecision(); + numNodes() = e->numNodes(); +#endif + + } + d_e() = e->d_e(); + //visited() = e->visited(); + sign() = e->sign(); + uMSB() = e->uMSB(); + lMSB() = e->lMSB(); + // length() = e->length(); // fixed? original = 1 + measure() = e->measure(); + + // BFMSS[2,5] bound. + u25() = e->u25(); + l25() = e->l25(); + v2p() = e->v2p(); + v2m() = e->v2m(); + v5p() = e->v5p(); + v5m() = e->v5m(); + + high() = e->high(); + low() = e->low(); // fixed? original = 0 + lc() = e->lc(); + tc() = e->tc(); + + // Chee (Mar 23, 2004), Notes on ratFlag(): + // =============================================================== + // For more information on the use of this flag, see progs/pentagon. + // This is an integer valued member of the NodeInfo class. + // Its value is used to determine whether + // we can ``reduce'' an Expression to a single node containing + // a BigRat value. This reduction is done if the global variable + // get_static_rationalReduceFlag()=true. The default value is false. + // This is the intepretation of ratFlag: + // ratFlag < 0 means irrational + // ratFlag = 0 means not initialized + // ratFlag > 0 means rational + // Currently, ratFlag>0 is an upper bound on the size of the expression, + // since we recursively compute + // ratFlag(v) = ratFlag(v.lchild)+ratFlag(v.rchild) + 1. + // PROPOSAL: if ratFlag() > RAT_REDUCE_THRESHHOLD + // then we automatically do a reduction. We must determine + // an empirical value for RAT_REDUCE_THRESHOLD + + if (get_static_rationalReduceFlag()) { + ratFlag() = e->ratFlag(); + + if (e->ratFlag() > 0 && e->ratValue() != NULL) { + ratFlag() ++; + if (ratValue() == NULL) + ratValue() = new BigRat(*(e->ratValue())); + else + *(ratValue()) = *(e->ratValue()); + } else + ratFlag() = -1; + } +} + +CGAL_INLINE_FUNCTION +void ExprRep::reduceToZero() { + appValue() = CORE_REAL_ZERO; + appComputed() = true; + flagsComputed() = true; + knownPrecision() = CORE_negInfty; +#ifdef CORE_DEBUG + relPrecision() = EXTLONG_ZERO; + absPrecision() = CORE_negInfty; + // numNodes() = 0; +#endif + + d_e() = EXTLONG_ONE; + visited() = false; + sign() = 0; + uMSB() = CORE_negInfty; + lMSB() = CORE_negInfty; + // length() = 0; // fixed? original = 1 + measure() = EXTLONG_ZERO; + + // BFMSS[2,5] bound. + u25() = l25() = v2p() = v2m() = v5p() = v5m() = EXTLONG_ZERO; + + low() = EXTLONG_ONE; // fixed? original = 0 + high() = lc() = tc() = EXTLONG_ZERO; + + if (get_static_rationalReduceFlag()) { + if (ratFlag() > 0) { + ratFlag() ++; + if (ratValue() == NULL) + ratValue() = new BigRat(0); + else + *(ratValue()) = 0; + } else + ratFlag() = 1; + } +} + +//////////////////////////////////////////////////////////// +// Test whether the current approximate value satisfies +// the composite precision requirements [relPrec, absPrec]. +//////////////////////////////////////////////////////////// + +CGAL_INLINE_FUNCTION +bool ExprRep::withinKnownPrecision(const extLong& relPrec, + const extLong& absPrec) { + if (appComputed()) { // an approximate value has been evaluated. + if (appValue().isExact()) { + return true; + } else { // approximation has certain error. + // decide to which position it is required to compute correctly. + extLong required = core_max(-absPrec, appValue().lMSB()-relPrec); + // see whether the existing error is smaller than the requirement. + return (knownPrecision() <= required); + } + } else + return false; +}//withinKnownPrecision(a, r) + +// approximate the expression to certain precisions when +// necessary (either no approximate value available or +// the existing one is not accurate enough). +CGAL_INLINE_FUNCTION +void ExprRep::approx(const extLong& relPrec = get_static_defRelPrec(), + const extLong& absPrec = get_static_defAbsPrec()) { + if (!getSign()) + return; // if it is exactly zero... + + // NOTE: The Filter might give a precise enough approximation already. + if (!getExactSign()) + return; + + if (!appComputed() || (!withinKnownPrecision(relPrec, absPrec))) { + // it's necessary to re-evaluate. + // to avoid huge lMSB which would cause long time and problems. + + // if it is a rational node + if (get_static_rationalReduceFlag() && ratFlag() > 0 && ratValue() != NULL) + appValue() = Real(*(ratValue())).approx(relPrec, absPrec); //< shouldn't + // this case be done by computeApproxValue()? + else + computeApproxValue(relPrec, absPrec); + + // update flags + appComputed() = true; + knownPrecision() = appValue().clLgErr(); +#ifdef CORE_DEBUG + if (relPrecision() < relPrec) + relPrecision() = relPrec; + if (absPrecision() < absPrec) + absPrecision() = absPrec; +#endif + + } +} + +// return an approximate value to certain precision. +CGAL_INLINE_FUNCTION +const Real& ExprRep::getAppValue(const extLong& relPrec, + const extLong& absPrec) { + if (getSign()) { + approx(relPrec, absPrec); + return appValue(); + } else + return CORE_REAL_ZERO; +} + +CGAL_INLINE_FUNCTION +std::ostream& operator<<(std::ostream& o, ExprRep& rep) { + if (rep.getSign()) { + rep.approx(get_static_defRelPrec(), get_static_defAbsPrec()); + o << rep.appValue(); + } else { + o << "0"; + } + return o; +} + +// Chee, Zilin: July 17, 2002 +// Original algorithm is wrongly implemented, and can take time +// exponential in the size of the dag. +// +// METHOD: +// Inductively assume that all "visited" flags are false. +// This calls for a reimplementation of "count()" and "clearFlag()". +// Actually, we did not have to fix the count() function. +// +// (1) First recursively compute d_e for each node +// by calling the count() function. +// Important thing is count() will turn the "visited" flags +// to be true, so that there is no double counting. +// Furthermore, if d_e had already been computed, the +// arithmetic for d_e can be avoided (in this case, +// it is only the setting of "visited" flag that we +// are interested in! +// (2) At the end of count(), we have set all reachable nodes +// to "visited", and their d_e have been computed. +// (3) Now, call clearFlag() to recursively clear all reachable +// nodes. NOTE THAT PREVIOUSLY, clearFlag() was called +// first! This obvious is wrong + +CGAL_INLINE_FUNCTION +extLong ExprRep::degreeBound() { + if (d_e() == EXTLONG_ONE) // no radical nodes below + return EXTLONG_ONE; + count(); + clearFlag(); + return d_e(); +} +// class ConstRealRep +// constructor +CGAL_INLINE_FUNCTION +ConstRealRep::ConstRealRep(const Real & r) : value(r) { + if (!value.isExact()) { + // clone the BigFloat and set its error to zero. + value = value.BigFloatValue().makeExact(); + } + ffVal = filteredFp(value); +} + +// initialize nodeInfo +CGAL_INLINE_FUNCTION +void ConstRep::initNodeInfo() { + nodeInfo = new NodeInfo(); + d_e() = EXTLONG_ONE; +} +CGAL_INLINE_FUNCTION +void UnaryOpRep::initNodeInfo() { + if (child->nodeInfo == NULL) + child->initNodeInfo(); + nodeInfo = new NodeInfo(); +} +CGAL_INLINE_FUNCTION +void BinOpRep::initNodeInfo() { + if (first->nodeInfo == NULL) + first->initNodeInfo(); + if (second->nodeInfo == NULL) + second->initNodeInfo(); + nodeInfo = new NodeInfo(); +} + +#ifdef CORE_DEBUG +CGAL_INLINE_FUNCTION +unsigned long ConstRep::dagSize() { + if (!visited()) { + visited() = true; + numNodes() = 1; + } else + numNodes() = 0; + return numNodes(); +} + +CGAL_INLINE_FUNCTION +unsigned long UnaryOpRep::dagSize() { + if (!visited()) { + visited() = true; + numNodes() = child->dagSize() + 1; + } else + numNodes() = 0; + return numNodes(); +} + +CGAL_INLINE_FUNCTION +unsigned long BinOpRep::dagSize() { + if (!visited()) { + visited() = true; + numNodes() = first->dagSize() + second->dagSize() + 1; + } else + numNodes() = 0; + return numNodes(); +} + +CGAL_INLINE_FUNCTION +void ConstRep::fullClearFlag() { + if (visited()) + visited() = false; +} + +CGAL_INLINE_FUNCTION +void UnaryOpRep::fullClearFlag() { + if (visited()) { + child->fullClearFlag(); + visited() = false; + } +} + +CGAL_INLINE_FUNCTION +void BinOpRep::fullClearFlag() { + if (visited()) { + first->fullClearFlag(); + second->fullClearFlag(); + visited() = false; + } +} +#endif + +// +// clear visited flag +// +/* see Expr.h + void ConstRep::clearFlag() + { visited = false; } +*/ +CGAL_INLINE_FUNCTION +void UnaryOpRep::clearFlag() { + if (d_e() == EXTLONG_ONE) + return; // no radicals below. + if (visited()) { + visited() = false; + child->clearFlag(); + } +} +// class BinOpRep +CGAL_INLINE_FUNCTION +void BinOpRep::clearFlag() { + if (d_e() == EXTLONG_ONE) + return; // rational below + if (visited()) { + visited() = false; + first->clearFlag(); + second->clearFlag(); + } +} + +// +// count # of squareroot +// +CGAL_INLINE_FUNCTION +extLong ConstRep::count() { + if (visited()) + return EXTLONG_ONE; + visited() = true; + return d_e(); +} + +CGAL_INLINE_FUNCTION +extLong NegRep::count() { + if (d_e() == EXTLONG_ONE) + return EXTLONG_ONE; + if (visited()) + return EXTLONG_ONE; + visited() = true; + d_e() = child->count(); + return d_e(); +} + +CGAL_INLINE_FUNCTION +extLong SqrtRep::count() { + if (d_e() == EXTLONG_ONE) + return EXTLONG_ONE; + if (visited()) + return EXTLONG_ONE; + visited() = true; + d_e() = child->count() * EXTLONG_TWO; + return d_e(); +} + +CGAL_INLINE_FUNCTION +extLong BinOpRep::count() { + if (d_e() == EXTLONG_ONE) + return EXTLONG_ONE; + if (visited()) + return EXTLONG_ONE; + visited() = true; + d_e() = first->count() * second->count(); + return d_e(); +} + +// +// compute exact flags functions +// +// exact value + +CGAL_INLINE_FUNCTION +void computeExactFlags_temp(ConstRep* t, const Real &value) { + // Chen Li: the following is incorrect: + // uMSB = lMSB = value.MSB(); + // because the value could be a BigFloat which is an interval. + if (value.isExact()) { + t->uMSB() = t->lMSB() = value.MSB(); + } else { + t->uMSB() = value.uMSB(); + t->lMSB() = value.lMSB(); + core_error("Leaves in DAG is not exact!", __FILE__, __LINE__, true); + } + + t->sign() = value.sign(); + // t->length() = value.length(); + t->measure() = value.height(); // for rationals and integers, + // measure = height. + + // BFMSS[2,5] bound. + value.ULV_E(t->u25(), t->l25(), t->v2p(), t->v2m(), t->v5p(), t->v5m()); + + // The original BFMSS parameters can be set from the BFMSS[2,5] parameters. + // Here we just need them locally. + extLong u_e = t->u25() + t->v2p() + ceilLg5(t->v5p()); + extLong l_e = t->l25() + t->v2m() + ceilLg5(t->v5m()); + +#ifdef ORIGINAL_BFMSS + // To go back to the original BFMSS : + t->u25() = u_e; + t->l25() = l_e; + t->v2p() = t->v2m() = t->v5p() = t->v5m() = EXTLONG_ZERO; +#elif defined BFMSS_2_ONLY + // To go back to BFMSS[2] only : + t->u25() = t->u25() + ceilLg5(t->v5p()); + t->l25() = t->l25() + ceilLg5(t->v5m()); + t->v5p() = t->v5m() = EXTLONG_ZERO; +#endif + + if (l_e == EXTLONG_ZERO) { // no divisions introduced + t->high() = u_e; + t->low() = EXTLONG_ONE - u_e; // - (u_e - 1) + } else { + t->high() = u_e - l_e + EXTLONG_ONE; + t->low() = EXTLONG_TWO - t->high(); + } + + t->lc() = l_e; + t->tc() = u_e; + + // set BigRat value + if (get_static_rationalReduceFlag()) { + t->ratFlag() = 1; + t->ratValue() = new BigRat(value.BigRatValue()); + } + + t->flagsComputed() = true; +} + +CGAL_INLINE_FUNCTION +void ConstDoubleRep::computeExactFlags() {// can be made more efficient + computeExactFlags_temp(this, Real(ffVal.getValue())); +} + +CGAL_INLINE_FUNCTION +void ConstRealRep::computeExactFlags() { + computeExactFlags_temp(this, value); +} + +CGAL_INLINE_FUNCTION +void NegRep::computeExactFlags() { + if (!child->flagsComputed()) + child->computeExactFlags(); + + if (child->sign() == 0) { + reduceToZero(); + return; + } + + if (get_static_rationalReduceFlag()) { + if (child->ratFlag()>0 && child->ratValue() != NULL) { + BigRat val = -(*(child->ratValue())); + reduceToBigRat(val); + ratFlag() = child->ratFlag()+1; + return; + } else + ratFlag() = -1; + } + + sign() = -child->sign(); + uMSB() = child->uMSB(); + lMSB() = child->lMSB(); + + // length() = child->length(); + measure() = child->measure(); + u25() = child->u25(); + l25() = child->l25(); + v2p() = child->v2p(); + v2m() = child->v2m(); + v5p() = child->v5p(); + v5m() = child->v5m(); + high() = child->high(); + low() = child->low(); + lc() = child->lc(); + tc() = child->tc(); + flagsComputed() = true; +}//NegRep::computeExactFlags + +CGAL_INLINE_FUNCTION +void SqrtRep::computeExactFlags() { + if (!child->flagsComputed()) + child->computeExactFlags(); + + if (get_static_rationalReduceFlag()) + ratFlag() = -1; + + sign() = child->sign(); + if (sign() < 0) + core_error("squareroot is called with negative operand.", + __FILE__, __LINE__, true); + + uMSB() = child->uMSB() / EXTLONG_TWO; + lMSB() = child->lMSB() / EXTLONG_TWO; + + // length() = child->length(); + measure() = child->measure(); + + // BFMSS[2,5] bound. + if (child->v2p() + ceilLg5(child->v5p()) + child->u25() >= + child->v2m() + ceilLg5(child->v5m()) + child->l25()) { + extLong vtilda2 = child->v2p() + child->v2m(); + v2p() = vtilda2 / EXTLONG_TWO; + v2m() = child->v2m(); + extLong vmod2; + if (v2p().isInfty()) + vmod2 = CORE_INFTY; + else + vmod2 = vtilda2 - EXTLONG_TWO*v2p(); // == vtilda2 % 2 + extLong vtilda5 = child->v5p() + child->v5m(); + v5p() = vtilda5 / EXTLONG_TWO; + v5m() = child->v5m(); + extLong vmod5; + if (v5p().isInfty()) + vmod5 = CORE_INFTY; + else + vmod5 = vtilda5 - EXTLONG_TWO*v5p(); // == vtilda5 % 2 + u25() = (child->u25() + child->l25() + vmod2 + ceilLg5(vmod5) + EXTLONG_ONE) / EXTLONG_TWO; + l25() = child->l25(); + } else { + extLong vtilda2 = child->v2p() + child->v2m(); + v2p() = child->v2p(); + v2m() = vtilda2 / EXTLONG_TWO; + extLong vmod2; + if (v2m().isInfty()) + vmod2 = CORE_INFTY; + else + vmod2 = vtilda2 - EXTLONG_TWO*v2m(); // == vtilda2 % 2 + extLong vtilda5 = child->v5p() + child->v5m(); + v5p() = child->v5p(); + v5m() = vtilda5 / EXTLONG_TWO; + u25() = child->u25(); + extLong vmod5; + if (v5m().isInfty()) + vmod5 = CORE_INFTY; + else + vmod5 = vtilda5 - EXTLONG_TWO*v5m(); // == vtilda5 % 2 + l25() = (child->u25() + child->l25() + vmod2 + ceilLg5(vmod5) + EXTLONG_ONE) / EXTLONG_TWO; + } + + high() = (child->high() +EXTLONG_ONE)/EXTLONG_TWO; + low() = child->low() / EXTLONG_TWO; + lc() = child->lc(); + tc() = child->tc(); + flagsComputed() = true; +}// SqrtRep::computeExactFlags + +CGAL_INLINE_FUNCTION +void MultRep::computeExactFlags() { + if (!first->flagsComputed()) + first->computeExactFlags(); + if (!second->flagsComputed()) + second->computeExactFlags(); + + if ((!first->sign()) || (!second->sign())) { + // value must be exactly zero. + reduceToZero(); + return; + } + // rational node + if (get_static_rationalReduceFlag()) { + if (first->ratFlag() > 0 && second->ratFlag() > 0) { + BigRat val = (*(first->ratValue()))*(*(second->ratValue())); + reduceToBigRat(val); + ratFlag() = first->ratFlag() + second->ratFlag(); + return; + } else + ratFlag() = -1; + } + + // value is irrational. + uMSB() = first->uMSB() + second->uMSB() + EXTLONG_ONE; + lMSB() = first->lMSB() + second->lMSB(); + sign() = first->sign() * second->sign(); + + extLong df = first->d_e(); + extLong ds = second->d_e(); + // extLong lf = first->length(); + // extLong ls = second->length(); + + // length() = df * ls + ds * lf; + measure() = (first->measure()) * ds+(second->measure()) * df; + + // BFMSS[2,5] bound. + v2p() = first->v2p() + second->v2p(); + v2m() = first->v2m() + second->v2m(); + v5p() = first->v5p() + second->v5p(); + v5m() = first->v5m() + second->v5m(); + u25() = first->u25() + second->u25(); + l25() = first->l25() + second->l25(); + + high() = first->high() + second->high(); + low() = first->low() + second->low(); + + lc() = ds * first->lc() + df * second->lc(); + tc() = core_min(ds * first->tc() + df * second->tc(), measure()); + + flagsComputed() = true; +}// MultRep::computeExactFlags + +CGAL_INLINE_FUNCTION +void DivRep::computeExactFlags() { + if (!first->flagsComputed()) + first->computeExactFlags(); + if (!second->flagsComputed()) + second->computeExactFlags(); + + if (!second->sign()) + core_error("zero divisor.", __FILE__, __LINE__, true); + + if (!first->sign()) {// value must be exactly zero. + reduceToZero(); + return; + } + + // rational node + if (get_static_rationalReduceFlag()) { + if (first->ratFlag() > 0 && second->ratFlag() > 0) { + BigRat val = (*(first->ratValue()))/(*(second->ratValue())); + reduceToBigRat(val); + ratFlag() = first->ratFlag() + second->ratFlag(); + return; + } else + ratFlag() = -1; + } + + // value is irrational. + uMSB() = first->uMSB() - second->lMSB(); + lMSB() = first->lMSB() - second->uMSB() - EXTLONG_ONE; + sign() = first->sign() * second->sign(); + + extLong df = first->d_e(); + extLong ds = second->d_e(); + // extLong lf = first->length(); + // extLong ls = second->length(); + + // length() = df * ls + ds * lf; + measure() = (first->measure())*ds + (second->measure())*df; + + // BFMSS[2,5] bound. + v2p() = first->v2p() + second->v2m(); + v2m() = first->v2m() + second->v2p(); + v5p() = first->v5p() + second->v5m(); + v5m() = first->v5m() + second->v5p(); + u25() = first->u25() + second->l25(); + l25() = first->l25() + second->u25(); + + high() = first->high() + second->low(); + low() = first->low() + second->high(); + + lc() = ds * first->lc() + df * second->tc(); + tc() = core_min(ds * first->tc() + df * second->lc(), measure()); + + flagsComputed() = true; +} + +// +// approximation functions +// +CGAL_INLINE_FUNCTION +void ConstDoubleRep::computeApproxValue(const extLong& /*relPrec*/, + const extLong& /*absPrec*/) +// can ignore precision bounds since ffVal.getValue() returns exact value +{ + appValue() = Real(ffVal.getValue()); +} + +CGAL_INLINE_FUNCTION +void ConstRealRep::computeApproxValue(const extLong& relPrec, + const extLong& absPrec) { + appValue() = value.approx(relPrec, absPrec); +} + +CGAL_INLINE_FUNCTION +void NegRep::computeApproxValue(const extLong& relPrec, + const extLong& absPrec) { + appValue() = -child->getAppValue(relPrec, absPrec); +} + +CGAL_INLINE_FUNCTION +void SqrtRep::computeApproxValue(const extLong& relPrec, + const extLong& absPrec) { + extLong r = relPrec + relPrec + EXTLONG_EIGHT; // chenli: ??? + extLong a = absPrec + absPrec + EXTLONG_EIGHT; + extLong pr = - lMSB() + r; + extLong p = pr < a ? pr : a; + + Real val = child->getAppValue(r, a); + if (get_static_incrementalEvalFlag()) { + if (appValue() == CORE_REAL_ZERO) + appValue() = val; + appValue() = val.sqrt(p, appValue().BigFloatValue()); + } else + appValue() = val.sqrt(p); +} + +CGAL_INLINE_FUNCTION +void MultRep::computeApproxValue(const extLong& relPrec, + const extLong& absPrec) { + if (lMSB() < EXTLONG_BIG && lMSB() > EXTLONG_SMALL) { + extLong r = relPrec + EXTLONG_FOUR; + extLong afr = - first->lMSB() + EXTLONG_ONE; + extLong afa = second->uMSB() + absPrec + EXTLONG_FIVE; + extLong af = afr > afa ? afr : afa; + extLong asr = - second->lMSB() + EXTLONG_ONE; + extLong asa = first->uMSB() + absPrec + EXTLONG_FIVE; + extLong as = asr > asa ? asr : asa; + appValue() = first->getAppValue(r, af)*second->getAppValue(r, as); + } else { + std::cerr << "lMSB = " << lMSB() << std::endl; + core_error("a huge lMSB in MulRep", __FILE__, __LINE__, false); + } +} + +CGAL_INLINE_FUNCTION +void DivRep::computeApproxValue(const extLong& relPrec, + const extLong& absPrec) { + if (lMSB() < EXTLONG_BIG && lMSB() > EXTLONG_SMALL) { + extLong rr = relPrec + EXTLONG_SEVEN; // These rules come from + extLong ra = uMSB() + absPrec + EXTLONG_EIGHT; // Koji's Master Thesis, page 65 + extLong ra2 = core_max(ra, EXTLONG_TWO); + extLong r = core_min(rr, ra2); + extLong af = - first->lMSB() + r; + extLong as = - second->lMSB() + r; + + extLong pr = relPrec + EXTLONG_SIX; + extLong pa = uMSB() + absPrec + EXTLONG_SEVEN; + extLong p = core_min(pr, pa); // Seems to be an error: + // p can be negative here! + // Also, this does not conform to + // Koji's thesis which has a default + // relative precision (p.65). + + appValue() = first->getAppValue(r, af).div(second->getAppValue(r, as), p); + } else { + std::cerr << "lMSB = " << lMSB() << std::endl; + core_error("a huge lMSB in DivRep", __FILE__, __LINE__, false); + } +} + +// +// Debug Help Functions +// +CGAL_INLINE_FUNCTION +void Expr::debug(int mode, int level, int depthLimit) const { + std::cout << "-------- Expr debug() -----------" << std::endl; + std::cout << "rep = " << rep << std::endl; + if (mode == Expr::LIST_MODE) + rep->debugList(level, depthLimit); + else if (mode == Expr::TREE_MODE) + rep->debugTree(level, 0, depthLimit); + else + core_error("unknown debugging mode", __FILE__, __LINE__, false); + std::cout << "---- End Expr debug(): " << std::endl; +} + + +CGAL_INLINE_FUNCTION +const std::string ExprRep::dump(int level) const { + std::ostringstream ost; + if (level == OPERATOR_ONLY) { + ost << op(); + } else if (level == VALUE_ONLY) { + ost << appValue(); + } else if (level == OPERATOR_VALUE) { + ost << op() << "[val: " << appValue() << "]"; + } else if (level == FULL_DUMP) { + ost << op() + << "[val: " << appValue() << "; " + << "kp: " << knownPrecision() << "; " +#ifdef CORE_DEBUG + << "r: " << relPrecision() << "; " + << "a: " << absPrecision() << "; " +#endif + << "lMSB: " << lMSB() << "; " + << "uMSB: " << uMSB() << "; " + << "sign: " << sign() << "; " + // << "length: " << length() << "; " + << "measure: " << measure() << "; " + << "d_e: " << d_e() << "; " + << "u25: " << u25() << "; " + << "l25: " << l25() << "; " + << "v2p: " << v2p() << "; " + << "v2m: " << v2m() << "; " + << "v5p: " << v5p() << "; " + << "v5m: " << v5m() << "; " + << "high: " << high() << "; " + << "low: " << low() << "; " + << "lc: " << lc() << "; " + << "tc: " << tc() + << "]"; + } + return std::string(ost.str()); + // note that str() return an array not properly terminated! +} + + +CGAL_INLINE_FUNCTION +void UnaryOpRep::debugList(int level, int depthLimit) const { + if (depthLimit <= 0) + return; + if (level == Expr::SIMPLE_LEVEL) { + std::cout << "(" << dump(OPERATOR_VALUE); + child->debugList(level, depthLimit - 1); + std::cout << ")"; + } else if (level == Expr::DETAIL_LEVEL) { + std::cout << "(" << dump(FULL_DUMP); + child->debugList(level, depthLimit - 1); + std::cout << ")"; + } +} + +CGAL_INLINE_FUNCTION +void UnaryOpRep::debugTree(int level, int indent, int depthLimit) const { + if (depthLimit <= 0) + return; + for (int i = 0; idebugTree(level, indent + 2, depthLimit - 1); +} + +CGAL_INLINE_FUNCTION +void ConstRep::debugList(int level, int depthLimit) const { + if (depthLimit <= 0) + return; + if (level == Expr::SIMPLE_LEVEL) { + std::cout << "(" << dump(OPERATOR_VALUE) << ")"; + } else if (level == Expr::DETAIL_LEVEL) { + std::cout << "(" << dump(FULL_DUMP) << ")"; + } +} + +CGAL_INLINE_FUNCTION +void ConstRep::debugTree(int level, int indent, int depthLimit) const { + if (depthLimit <= 0) + return; + for (int i=0; idebugList(level, depthLimit - 1); + std::cout << ", "; + second->debugList(level, depthLimit - 1); + std::cout << ")" ; +} + +CGAL_INLINE_FUNCTION +void BinOpRep::debugTree(int level, int indent, int depthLimit) const { + if (depthLimit <= 0) + return; + for (int i=0; idebugTree(level, indent + 2, depthLimit - 1); + second->debugTree(level, indent + 2, depthLimit - 1); +} + +} //namespace CORE diff --git a/CGAL_Core/include/CGAL/CORE/Filter.h b/CGAL_Core/include/CGAL/CORE/Filter.h index 0f1f5901228..42a3af162e0 100644 --- a/CGAL_Core/include/CGAL/CORE/Filter.h +++ b/CGAL_Core/include/CGAL/CORE/Filter.h @@ -42,6 +42,13 @@ #include #include +#ifdef CGAL_HEADER_ONLY +#undef CGAL_EXPORT // CJTODO: TEMPORARY +#undef CGAL_CORE_EXPORT +#define CGAL_EXPORT +#define CGAL_CORE_EXPORT +#endif + #if !defined CGAL_CFG_NO_CPP0X_ISFINITE #define CGAL_CORE_finite(x) std::isfinite(x) #elif defined (_MSC_VER) || defined (__MINGW32__) // add support for MinGW @@ -102,7 +109,7 @@ public: } /// check whether the sign (!) of the filtered value is OK bool isOK() const { - return (fpFilterFlag && // To disable filter + return (get_static_fpFilterFlag() && // To disable filter CGAL_CORE_finite(fpVal) && // Test for infinite and NaNs (core_abs(fpVal) >= maxAbs*ind*CORE_EPS)); } diff --git a/CGAL_Core/include/CGAL/CORE/Gmp.h b/CGAL_Core/include/CGAL/CORE/Gmp.h index 164095fd5d9..4b13adfa029 100644 --- a/CGAL_Core/include/CGAL/CORE/Gmp.h +++ b/CGAL_Core/include/CGAL/CORE/Gmp.h @@ -27,6 +27,13 @@ #include #include +#ifdef CGAL_HEADER_ONLY +#undef CGAL_EXPORT // CJTODO: TEMPORARY +#undef CGAL_CORE_EXPORT +#define CGAL_EXPORT +#define CGAL_CORE_EXPORT +#endif + namespace CORE { CGAL_CORE_EXPORT std::ostream& io_write (std::ostream &, mpz_srcptr); @@ -39,4 +46,9 @@ CGAL_CORE_EXPORT std::istream& io_read (std::istream &, mpq_ptr); //std::istream& operator>> (std::istream &, mpq_ptr); } //namespace CORE + +#ifdef CGAL_HEADER_ONLY +#include +#endif // CGAL_HEADER_ONLY + #endif // _CORE_GMP_H_ diff --git a/CGAL_Core/include/CGAL/CORE/Gmp_impl.h b/CGAL_Core/include/CGAL/CORE/Gmp_impl.h new file mode 100644 index 00000000000..32cec37e7ed --- /dev/null +++ b/CGAL_Core/include/CGAL/CORE/Gmp_impl.h @@ -0,0 +1,280 @@ +/**************************************************************************** + * Core Library Version 1.7, August 2004 + * Copyright (c) 1995-2004 Exact Computation Project + * All rights reserved. + * + * file: GmpIO.cpp + * Adapted from multi-files under /cxx in GMP's source distribution + * + * Zilin Du, 2003 + * + * $URL$ + * $Id$ + ***************************************************************************/ + +/* Auxiliary functions for C++-style input of GMP types. + +Copyright 2001 Free Software Foundation, Inc. + +This file is part of the GNU MP Library. + +The GNU MP Library is free software; 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. + +The GNU MP Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the GNU MP Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#ifdef CGAL_HEADER_ONLY +#define CGAL_INLINE_FUNCTION inline +#else +#define CGAL_INLINE_FUNCTION +#endif + +#include +#include +#include +#include +#include + +using namespace std; + +namespace CORE { + +CGAL_INLINE_FUNCTION +int +__gmp_istream_set_base (istream &i, char &c, bool &zero, bool &showbase) +{ + int base; + + zero = showbase = false; + switch (i.flags() & ios::basefield) + { + case ios::dec: + base = 10; + break; + case ios::hex: + base = 16; + break; + case ios::oct: + base = 8; + break; + default: + showbase = true; // look for initial "0" or "0x" or "0X" + if (c == '0') + { + if (! i.get(c)) + c = 0; // reset or we might loop indefinitely + + if (c == 'x' || c == 'X') + { + base = 16; + i.get(c); + } + else + { + base = 8; + zero = true; // if no other digit is read, the "0" counts + } + } + else + base = 10; + break; + } + + return base; +} + +CGAL_INLINE_FUNCTION +void +__gmp_istream_set_digits (string &s, istream &i, char &c, bool &ok, int base) +{ + switch (base) + { + case 10: + while (isdigit(c)) + { + ok = true; // at least a valid digit was read + s += c; + if (! i.get(c)) + break; + } + break; + case 8: + while (isdigit(c) && c != '8' && c != '9') + { + ok = true; // at least a valid digit was read + s += c; + if (! i.get(c)) + break; + } + break; + case 16: + while (isxdigit(c)) + { + ok = true; // at least a valid digit was read + s += c; + if (! i.get(c)) + break; + } + break; + } +} + +CGAL_INLINE_FUNCTION +istream & +//operator>> (istream &i, mpz_ptr z) +io_read (istream &i, mpz_ptr z) +{ + int base; + char c = 0; + string s; + bool ok = false, zero, showbase; + + i.get(c); // start reading + + if (i.flags() & ios::skipws) // skip initial whitespace + while (isspace(c) && i.get(c)) + ; + + if (c == '-' || c == '+') // sign + { + if (c == '-') // mpz_set_str doesn't accept '+' + s = "-"; + i.get(c); + } + + while (isspace(c) && i.get(c)) // skip whitespace + ; + + base = __gmp_istream_set_base(i, c, zero, showbase); // select the base + __gmp_istream_set_digits(s, i, c, ok, base); // read the number + + if (i.good()) // last character read was non-numeric + i.putback(c); + else if (i.eof() && (ok || zero)) // stopped just before eof + i.clear(); + + if (ok) + mpz_set_str(z, s.c_str(), base); // extract the number + else if (zero) + mpz_set_ui(z, 0); + else + i.setstate(ios::failbit); // read failed + + return i; +} + +CGAL_INLINE_FUNCTION +istream & +//operator>> (istream &i, mpq_ptr q) +io_read (istream &i, mpq_ptr q) +{ + int base; + char c = 0; + string s; + bool ok = false, zero, showbase; + + i.get(c); // start reading + + if (i.flags() & ios::skipws) // skip initial whitespace + while (isspace(c) && i.get(c)) + ; + + if (c == '-' || c == '+') // sign + { + if (c == '-') + s = "-"; + i.get(c); + } + + while (isspace(c) && i.get(c)) // skip whitespace + ; + + base = __gmp_istream_set_base(i, c, zero, showbase); // select the base + __gmp_istream_set_digits(s, i, c, ok, base); // read the numerator + + if (! ok && zero) // the only digit read was "0" + { + base = 10; + s += '0'; + ok = true; + } + + if (i.flags() & ios::skipws) + while (isspace(c) && i.get(c)) // skip whitespace + ; + + if (c == '/') // there's a denominator + { + bool zero2 = false; + int base2 = base; + + s += '/'; + ok = false; // denominator is mandatory + i.get(c); + + while (isspace(c) && i.get(c)) // skip whitespace + ; + + if (showbase) // check base of denominator + base2 = __gmp_istream_set_base(i, c, zero2, showbase); + + if (base2 == base || base2 == 10) // read the denominator + __gmp_istream_set_digits(s, i, c, ok, base); + + if (! ok && zero2) // the only digit read was "0" + { // denominator is 0, but that's your business + s += '0'; + ok = true; + } + } + + if (i.good()) // last character read was non-numeric + i.putback(c); + else if (i.eof() && ok) // stopped just before eof + i.clear(); + + if (ok) + mpq_set_str(q, s.c_str(), base); // extract the number + else + i.setstate(ios::failbit); // read failed + + return i; +} + +CGAL_INLINE_FUNCTION +ostream& +//operator<< (ostream &o, mpz_srcptr z) +io_write (ostream &o, mpz_srcptr z) +{ + char *str = new char [mpz_sizeinbase(z,10) + 2]; + str = mpz_get_str(str, 10, z); + o << str ; + delete[] str; + return o; +} + +CGAL_INLINE_FUNCTION +ostream& +//operator<< (ostream &o, mpq_srcptr q) +io_write (ostream &o, mpq_srcptr q) +{ + // size according to GMP documentation + char *str = new char [mpz_sizeinbase(mpq_numref(q), 10) + + mpz_sizeinbase (mpq_denref(q), 10) + 3]; + str = mpq_get_str(str, 10, q); + o << str ; + delete[] str; + return o; +} + +} //namespace CORE diff --git a/CGAL_Core/include/CGAL/CORE/Real.h b/CGAL_Core/include/CGAL/CORE/Real.h index 52c802fed5b..66cc4718626 100644 --- a/CGAL_Core/include/CGAL/CORE/Real.h +++ b/CGAL_Core/include/CGAL/CORE/Real.h @@ -39,6 +39,13 @@ #define _CORE_REAL_H_ #include "RealRep.h" +#ifdef CGAL_HEADER_ONLY +#undef CGAL_EXPORT // CJTODO: TEMPORARY +#undef CGAL_CORE_EXPORT +#define CGAL_EXPORT +#define CGAL_CORE_EXPORT +#endif + namespace CORE { // class Real typedef RCImpl RCReal; @@ -57,10 +64,10 @@ public: Real(const BigInt& I) : RCReal(new RealBigInt(I)) {} Real(const BigRat& R) : RCReal(new RealBigRat(R)) {} Real(const BigFloat& F) : RCReal(new RealBigFloat(F)) {} - Real(const char* s, const extLong& prec=defInputDigits) : RCReal(NULL) { + Real(const char* s, const extLong& prec=get_static_defInputDigits()) : RCReal(NULL) { constructFromString(s, prec); } - Real(const std::string& s, const extLong& prec=defInputDigits) : RCReal(NULL){ + Real(const std::string& s, const extLong& prec=get_static_defInputDigits()) : RCReal(NULL){ constructFromString(s.c_str(), prec); } @@ -134,12 +141,12 @@ public: /// \name String Conversion Functions //@{ /// set value from const char* - void fromString(const char* s, const extLong& prec = defInputDigits) { + void fromString(const char* s, const extLong& prec = get_static_defInputDigits()) { *this = Real(s, prec); } /// convert to std::string /** give decimal string representation */ - std::string toString(long prec=defOutputDigits, bool sci=false) const { + std::string toString(long prec=get_static_defOutputDigits(), bool sci=false) const { return rep->toString(prec, sci); } //@} @@ -179,7 +186,8 @@ public: /// \name Aprroximation Function //@{ /// approximation - Real approx(const extLong& r=defRelPrec, const extLong& a=defAbsPrec) const { + Real approx(const extLong& r=get_static_defRelPrec(), + const extLong& a=get_static_defAbsPrec()) const { return rep->approx(r, a); } //@} @@ -395,7 +403,7 @@ inline Real& Real::operator*=(const Real& rhs) { return *this; } inline Real& Real::operator/=(const Real& rhs) { - *this = real_div::eval(getRep(), rhs.getRep(), defRelPrec); + *this = real_div::eval(getRep(), rhs.getRep(), get_static_defRelPrec()); return *this; } @@ -413,7 +421,7 @@ inline Real operator*(const Real& x, const Real& y) { } // operator/ inline Real operator/(const Real& x, const Real& y) { - return real_div::eval(x.getRep(), y.getRep(), defRelPrec); + return real_div::eval(x.getRep(), y.getRep(), get_static_defRelPrec()); } // div w/ precision inline Real Real::div(const Real& x, const extLong& r) const { @@ -478,7 +486,7 @@ inline Real power(const Real& r, unsigned long p) { } /// square root inline Real sqrt(const Real& x) { - return x.sqrt(defAbsPrec); + return x.sqrt(get_static_defAbsPrec()); } // class Realbase_for (need defined after Real) @@ -493,4 +501,9 @@ inline Real RealLong::operator-() const { } } //namespace CORE + +#ifdef CGAL_HEADER_ONLY +#include +#endif // CGAL_HEADER_ONLY + #endif // _CORE_REAL_H_ diff --git a/CGAL_Core/include/CGAL/CORE/extLong.h b/CGAL_Core/include/CGAL/CORE/extLong.h index 3091bb740b9..5060cb51d92 100644 --- a/CGAL_Core/include/CGAL/CORE/extLong.h +++ b/CGAL_Core/include/CGAL/CORE/extLong.h @@ -41,6 +41,13 @@ #include #include +#ifdef CGAL_HEADER_ONLY +#undef CGAL_EXPORT // CJTODO: TEMPORARY +#undef CGAL_CORE_EXPORT +#define CGAL_EXPORT +#define CGAL_CORE_EXPORT +#endif + namespace CORE { #ifndef LONG_MAX @@ -294,4 +301,9 @@ inline bool extLong::isNaN() const { } } //namespace CORE + +#ifdef CGAL_HEADER_ONLY +#include +#endif // CGAL_HEADER_ONLY + #endif // _CORE_EXTLONG_H_ diff --git a/CGAL_Core/include/CGAL/CORE/poly/Poly.h b/CGAL_Core/include/CGAL/CORE/poly/Poly.h index 3bb3f5b9065..ff9afa0cf7b 100644 --- a/CGAL_Core/include/CGAL/CORE/poly/Poly.h +++ b/CGAL_Core/include/CGAL/CORE/poly/Poly.h @@ -205,7 +205,8 @@ public: /// Polynomial evaluation where the coefficients are approximated first /// Returns a BigFloat with error that contains the value BigFloat evalApprox(const BigFloat& f, - const extLong& r=defRelPrec, const extLong& a=defAbsPrec) const; + const extLong& r=get_static_defRelPrec(), + const extLong& a=get_static_defAbsPrec()) const; /// Polynomial evaluation at a BigFloat value. /// The returned BigFloat (with error) has the exact sign. /// In particular, if the value is 0, we return 0. diff --git a/CGAL_Core/src/CGAL_Core/BigFloat.cpp b/CGAL_Core/src/CGAL_Core/BigFloat.cpp index 6cd7da52618..301f7b49b13 100644 --- a/CGAL_Core/src/CGAL_Core/BigFloat.cpp +++ b/CGAL_Core/src/CGAL_Core/BigFloat.cpp @@ -41,1247 +41,9 @@ * $Id$ ***************************************************************************/ -#include +#ifndef CGAL_HEADER_ONLY + #include -#include +#include -namespace CORE { - - -//////////////////////////////////////////////////////////// -// Misc Helper Functions -//////////////////////////////////////////////////////////// - -BigInt FiveTo(unsigned long exp) { - if (exp == 0) - return BigInt(1); - else if (exp == 1) - return BigInt(5); - else { - BigInt x = FiveTo(exp / 2); - - x = x * x; - - if (exp & 1) - x *= 5; - - return x; - } -} - -//////////////////////////////////////////////////////////// -// class BigFloat -//////////////////////////////////////////////////////////// - -// STATIC BIGFLOAT CONSTANTS -// ZERO -const BigFloat& BigFloat::getZero() { - static BigFloat Zero(0); - return Zero; -} -// ONE -const BigFloat& BigFloat::getOne() { - static BigFloat One(1); - return One; -} - -// A special constructor for BigFloat from Expr -// -- this method is somewhat of an anomaly (we normally do not expect -// BigFloats to know about Expr). -BigFloat::BigFloat(const Expr& E, const extLong& r, const extLong& a) - : RCBigFloat(new BigFloatRep()) { - *this = E.approx(r, a).BigFloatValue(); // lazy implementaion, any other way? -} - -//////////////////////////////////////////////////////////// -// class BigFloatRep -//////////////////////////////////////////////////////////// - -BigFloatRep::BigFloatRep(double d) : m(0), err(0), exp(0) { - if (d != 0.0) { - int isNegative = 0; - - if (d < 0.0) { - isNegative = 1; - d = - d; - } - - int binExp; - double f = frexp(d, &binExp); - - exp = chunkFloor(binExp); - - long s = binExp - bits(exp); - - long stop = 0; - double intPart; - - // convert f into a BigInt - while (f != 0.0 && stop < DBL_MAX_CHUNK) { - f = ldexp(f, (int)CHUNK_BIT); - f = modf(f, &intPart); - m <<= CHUNK_BIT; - m += (long)intPart; - exp--; - stop++; - } -#ifdef CORE_DEBUG - assert (s >= 0); -#endif - - if (s) - m <<= s; - if (isNegative) - negate(m); - } -}//BigFloatRep constructor - -// approximation -void BigFloatRep::trunc(const BigInt& I, const extLong& r, const extLong& a) { - if (sign(I)) { - long tr = chunkFloor((- r + bitLength(I)).asLong()); - long ta = chunkFloor(- a.asLong()); - long t; - - if (r.isInfty() || a.isTiny()) - t = ta; - else if (a.isInfty()) - t = tr; - else - t = ta < tr ? tr : ta; - - if (t > 0) { // BigInt remainder; - m = chunkShift(I, - t); - err = 1; - exp = t; - } else { // t <= 0 - m = I; - err = 0; - exp = 0; - } - } else {// I == 0 - m = 0; - err = 0; - exp = 0; - } -} - -void BigFloatRep :: truncM(const BigFloatRep& B, const extLong& r, const extLong& a) { - if (sign(B.m)) { - long tr = chunkFloor((- 1 - r + bitLength(B.m)).asLong()); - long ta = chunkFloor(- 1 - a.asLong()) - B.exp; - long t; - - if (r.isInfty() || a.isTiny()) - t = ta; - else if (a.isInfty()) - t = tr; - else - t = ta < tr ? tr : ta; - - if (t >= chunkCeil(clLg(B.err))) { - m = chunkShift(B.m, - t); - err = 2; - exp = B.exp + t; - } else // t < chunkCeil(clLg(B.err)) - core_error(std::string("BigFloat error: truncM called with stricter") - + "precision than current error.", __FILE__, __LINE__, true); - } else {// B.m == 0 - long t = chunkFloor(- a.asLong()) - B.exp; - - if (t >= chunkCeil(clLg(B.err))) { - m = 0; - err = 1; - exp = B.exp + t; - } else // t < chunkCeil(clLg(B.err)) - core_error(std::string("BigFloat error: truncM called with stricter") - + "precision than current error.", __FILE__, __LINE__, true); - } -} - -// This is the main approximation function -// REMARK: would be useful to have a self-modifying version -// of this function (e.g., for Newton). -void BigFloatRep::approx(const BigFloatRep& B, - const extLong& r, const extLong& a) { - if (B.err) { - if (1 + clLg(B.err) <= bitLength(B.m)) - truncM(B, r + 1, a); - else // 1 + clLg(B.err) > lg(B.m) - truncM(B, CORE_posInfty, a); - } else {// B.err == 0 - trunc(B.m, r, a - bits(B.exp)); - exp += B.exp; - } - // Call normalization globally -- IP 10/9/98 - normal(); -} - -void BigFloatRep::div(const BigInt& N, const BigInt& D, - const extLong& r, const extLong& a) { - if (sign(D)) { - if (sign(N)) { - long tr = chunkFloor((- r + bitLength(N) - bitLength(D) - 1).asLong()); - long ta = chunkFloor(- a.asLong()); - - if (r.isInfty() || a.isTiny()) - exp = ta; - else if (a.isInfty()) - exp = tr; - else - exp = ta < tr ? tr : ta; - - BigInt remainder; - - // divide(chunkShift(N, - exp), D, m, remainder); - div_rem(m, remainder, chunkShift(N, - exp), D); - - if (exp <= 0 && sign(remainder) == 0) - err = 0; - else - err = 1; - } else {// N == 0 - m = 0; - err = 0; - exp = 0; - } - } else // D == 0 - core_error( "BigFloat error: zero divisor.", __FILE__, __LINE__, true); - - // Call normalization globally -- IP 10/9/98 - normal(); -}//div - -// error-normalization -void BigFloatRep::normal() { - long le = flrLg(err); - - if (le >= CHUNK_BIT + 2) { // so we do not carry more than 16 = CHUNK_BIT + 2 - // bits of error - long f = chunkFloor(--le); // f is roughly equal to floor(le/CHUNK_BIT) - long bits_f = bits(f); // f chunks will have bits_f many bits -#ifdef CORE_DEBUG - assert (bits_f >= 0); -#endif - - m >>= bits_f; // reduce mantissa by bits_f many bits - err >>= bits_f; // same for err - err += 2; // why 2? - exp += f; - } - if (err == 0) // unlikely, if err += 2 above - eliminateTrailingZeroes(); -} - -// bigNormal(err) -// convert a bigInt error value (=err) into an error that fits into -// a long number. This is done by -// by increasing the exponent, and corresponding decrease -// in the bit lengths of the mantissa and error. -// -void BigFloatRep::bigNormal(BigInt& bigErr) { - long le = bitLength(bigErr); - - if (le < CHUNK_BIT + 2) { - err = ulongValue(bigErr); - } else { - long f = chunkFloor(--le); - long bits_f = bits(f); -#ifdef CORE_DEBUG - assert(bits_f >= 0); -#endif - - m >>= bits_f; - bigErr >>= bits_f; - err = ulongValue(bigErr) + 2; // you need to add "2" because "1" comes - // from truncation error in the mantissa, and another - // "1" comes from the truncation error in the bigErr. - // (But there is danger of overflow...) - exp += f; - } - - if (err == 0) - eliminateTrailingZeroes(); -} - -// ARITHMETIC: -// Addition -void BigFloatRep::add(const BigFloatRep& x, const BigFloatRep& y) { - long expDiff = x.exp - y.exp; - - if (expDiff > 0) {// x.exp > y.exp - if (!x.err) { - m = chunkShift(x.m, expDiff) + y.m; - err = y.err; - exp = y.exp; - } else {// x.err > 0 - m = x.m + chunkShift(y.m, - expDiff); // negative shift! - err = x.err + 5; // To account for y.err (but why 5?) - exp = x.exp; // - // normal(); - } - } else if (!expDiff) {// x.exp == y.exp - m = x.m + y.m; - err = x.err + y.err; - exp = x.exp; - // normal(); - } else {// x.exp < y.exp - if (!y.err) { - m = x.m + chunkShift(y.m, - expDiff); - err = x.err; - exp = x.exp; - } else {// y.err > 0 - m = chunkShift(x.m, expDiff) + y.m; - err = y.err + 5; - exp = y.exp; - // normal(); - } - } - // Call normalization globally -- IP 10/9/98 - normal(); -} - -// Subtraction -void BigFloatRep::sub(const BigFloatRep& x, const BigFloatRep& y) { - long expDiff = x.exp - y.exp; - - if (expDiff > 0) {// x.exp > y.exp - if (!x.err) { - m = chunkShift(x.m, expDiff) - y.m; - err = y.err; - exp = y.exp; - } else {// x.err > 0 - m = x.m - chunkShift(y.m, - expDiff); - err = x.err + 5; - exp = x.exp; - // normal(); - } - } else if (!expDiff) { - m = x.m - y.m; - err = x.err + y.err; - exp = x.exp; - // normal(); - } else { // x.exp < y.exp - if (!y.err) { - m = x.m - chunkShift(y.m, - expDiff); - err = x.err; - exp = x.exp; - } else {// y.err > 0 - m = chunkShift(x.m, expDiff) - y.m; - err = y.err + 5; - exp = y.exp; - // normal(); - } - } - // Call normalization globally -- IP 10/9/98 - normal(); -} - -void BigFloatRep::mul(const BigFloatRep& x, const BigFloatRep& y) { - m = x.m * y.m; - exp = x.exp + y.exp; - // compute error (new code, much faster. Zilin Du, Nov 2003) - if (x.err == 0 && y.err == 0) { - err = 0; - eliminateTrailingZeroes(); - } else { - BigInt bigErr(0); - if (y.err != 0) - bigErr += abs(x.m)*y.err; - if (x.err != 0) - bigErr += abs(y.m)*x.err; - if (x.err !=0 && y.err != 0) - bigErr += x.err*y.err; - bigNormal(bigErr); - } -} -// BigFloat div2 will half the value of x, exactly with NO error -// REMARK: should generalize this to dividing by any power of 2 -// We need this in our use of BigFloats to maintain isolation -// intervals (e.g., in Sturm sequences) --Chee/Vikram 4/2003 -// -void BigFloatRep :: div2(const BigFloatRep& x) { - if (isEven(x.m)) { - m = (x.m >> 1); - exp = x.exp ; - } else { - m = (x.m << static_cast(CHUNK_BIT-1)); - exp = x.exp -1; - } -} - -// Converts a BigFloat interval into one BigFloat with almost same error bound -// This routine ignores the errors in inputs a and b. -// But you cannot really ignore them since, they are taken into account -// when you compute "r.sub(a,b)"... -void BigFloatRep::centerize(const BigFloatRep& a, const BigFloatRep& b) { - if ((a.m == b.m) && (a.err == b.err) && (a.exp == b.exp)) { - m = a.m; - err = a.err; - exp = a.exp; - return; - } - - BigFloatRep r; - r.sub(a, b); - r.div2(r); - - //setup mantissa and exponent, but not error bits - // But this already sets the error bits? Chee - add(a,b); - div2(*this); - // error bits = ceil ( B^{-exp}*|a-b|/2 ) - - // bug fixed: possible overflow on converting - // Zilin & Vikram, 08/24/04 - // err = 1 + longValue(chunkShift(r.m, r.exp - exp)); - BigInt E = chunkShift(r.m, r.exp - exp); - bigNormal(E); -} - -// BigFloat Division, computing x/y: -// Unlike +,-,*, this one takes a relative precision bound R -// Note that R is only used when x and y are error-free! -// (This remark means that we may be less efficient than we could be) -// -// Assert( R>0 && R< CORE_Infty ) -// -void BigFloatRep :: div(const BigFloatRep& x, const BigFloatRep& y, - const extLong& R) { - if (!y.isZeroIn()) { // y.m > y.err, so we are not dividing by 0 - if (!x.err && !y.err) { - if (R < 0 || R.isInfty()) //Oct 9, 2002: fixed major bug! [Zilin/Chee] - div(x.m, y.m, defBFdivRelPrec, CORE_posInfty); - else - div(x.m, y.m, R, CORE_posInfty); - exp += x.exp - y.exp; // chen: adjust exp. - } else {// x.err > 0 or y.err > 0 - BigInt bigErr, errRemainder; - - if (x.isZeroIn()) { // x.m <= x.err - m = 0; - exp = x.exp - y.exp; - - div_rem(bigErr, errRemainder, abs(x.m) + static_cast(x.err), - abs(y.m) - static_cast(y.err)); - } else { // x.m > x.err - long lx = bitLength(x.m); - long ly = bitLength(y.m); - long r; - - if (!x.err) // x.err == 0 and y.err > 0 - r = ly + 2; - else if(!y.err) // x.err > 0 and y.err == 0 - r = lx + 2; - else // x.err > 0 and y.err > 0 - r = lx < ly ? lx + 2: ly + 2; - - long t = chunkFloor(- r + lx - ly - 1); - BigInt remainder; - - div_rem(m, remainder, chunkShift(x.m, - t), y.m); - exp = t + x.exp - y.exp; - - long delta = ((t > 0) ? 2 : 0); - - // Chen Li: 9/9/99 - // here again, it use ">>" operator with a negative - // right operand. So the result is not well defined. - // Erroneous code: - // divide(abs(remainder) + (static_cast(x.err) >> bits(t)) - // + delta + static_cast(y.err) * abs(m), - // abs(y.m) - static_cast(y.err), - // bigErr, - // errRemainder); - // New code: - BigInt errx_over_Bexp = x.err; - long bits_Bexp = bits(t); - if (bits_Bexp >= 0) { - errx_over_Bexp >>= bits_Bexp; - } else { - errx_over_Bexp <<= (-bits_Bexp); - } - - // divide(abs(remainder) + errx_over_Bexp - // + delta + static_cast(y.err) * abs(m), - // abs(y.m) - static_cast(y.err), - // bigErr, - // errRemainder); - div_rem(bigErr, errRemainder, - abs(remainder) + errx_over_Bexp + delta + static_cast(y.err) * abs(m), - abs(y.m) - static_cast(y.err)); - } - - if (sign(errRemainder)) - ++bigErr; - - bigNormal(bigErr); - } - } else {// y.m <= y.err - core_error("BigFloat error: possible zero divisor.", - __FILE__, __LINE__, true); - } - - // Call normalization globally -- IP 10/9/98 - // normal(); -- Chen: after calling bigNormal, this call is redundant. -}// BigFloatRep::div - -// squareroot for BigInt argument, without initial approximation -// sqrt(x,a) computes sqrt of x to absolute precision a. -// -- this is where Newton is applied -// -- this is called by BigFloatRep::sqrt(BigFloat, extLong) -void BigFloatRep::sqrt(const BigInt& x, const extLong& a) { - sqrt(x, a, BigFloat(x, 0, 0)); -} // sqrt(BigInt x, extLong a) , without initial approx - -// sqrt(x,a,A) where -// x = bigInt whose sqrt is to be computed -// a = absolute precision bound -// A = initial approximation in BigFloat -// -- this is where Newton is applied -// -- it is called by BigFloatRep::sqrt(BigFloatRep, extLong, BigFloat) -void BigFloatRep::sqrt(const BigInt& x, const extLong& a, const BigFloat& A) { - if (sign(x) == 0) { - m = 0; - err = 0; - exp = 0; - } else if (x == 1) { - m = 1; - err = 0; - exp = 0; - } else {// main case - // here is where we use the initial approximation - m = A.m(); - err = 0; - exp = A.exp(); - - BigFloatRep q, z; - extLong aa; - // need this to make sure that in case the - // initial approximation A is less than sqrt(x) - // then Newton iteration will still proceed at - // least one step. - bool firstTime = true; - for (;;) { - aa = a - bits(exp); - q.div(x, m, CORE_posInfty, aa); - q.err = 0; - q.exp -= exp; - - z.sub(*this, q); // this=current approximation, so z = this - q - /*if (sign(z.m) <= 0 || z.MSB() < - a) // justification: see Koji's - break; // thesis (p. 28) which states - // that we can exit when - // " (*this) <= q + 2**(-a)" - */ - // The preceding code is replaced by what follows: - if (z.MSB() < -a) - break; - if (sign(z.m) <= 0) { - if (firstTime) - firstTime = false; - else - break; - } - - z.add(*this, q); - // Chen Li: a bug fixed here. - // m = z.m >> 1; - // err = 0; - // exp = z.exp; - if ((z.m > 1) && isEven(z.m)) { - m = z.m >> 1; // exact division by 2 - err = 0; - exp = z.exp; - } else { // need to shift left before division by 2 - m = chunkShift(z.m, 1) >> 1; - err = 0; - exp = z.exp - 1; - }//else - }//for - }//else -} // sqrt of BigInt, with initial approx - -// MAIN ENTRY INTO SQRT FUNCTION (BIGFLOAT ARGUMENT, WITHOUT INITIAL APPROX) -void BigFloatRep::sqrt(const BigFloatRep& x, const extLong& a) { - sqrt(x, a, BigFloat(x.m, 0, x.exp)); -} //sqrt(BigFloat, extLong a) - -// MAIN ENTRY INTO SQRT FUNCTION (BIGFLOAT ARGUMENT WITH INITIAL APPROXIMATION) -void BigFloatRep::sqrt(const BigFloatRep& x, const extLong& a, const BigFloat& A) { - // This computes the sqrt of x to absolute precision a, starting with - // the initial approximation A - if (sign(x.m) >= 0) { // x.m >= 0 - int delta = x.exp & 1; // delta=0 if x.exp is even, otherwise delta=1 - - if (x.isZeroIn()) { // x.m <= x.err - m = 0; - if (!x.err) - err = 0; - else { // x.err > 0 - err = (long)(std::sqrt((double)x.err)); - err++; - err <<= 1; - if (delta) - err <<= HALF_CHUNK_BIT; - } - exp = x.exp >> 1; - normal(); - } else { - long aExp = A.exp() - (x.exp >> 1); - BigFloat AA( chunkShift(A.m(), delta), 0, aExp); - - if (!x.err) { // x.m > x.err = 0 (ERROR FREE CASE) - BigFloatRep z; - extLong ppp; - if (a.isInfty()) //Oct 9, 2002: fixed major bug! [Zilin/Chee] - ppp = defBFsqrtAbsPrec; - else - ppp = a + EXTLONG_ONE; - extLong absp = ppp + bits(x.exp >> 1); - - z.sqrt(chunkShift(x.m, delta), absp, AA); // call sqrt(BigInt, a, AA) - - long p = (absp + bits(z.exp)).asLong(); - - // Next, normalize the error: - if (p <= 0) { - m = z.m; - // Chen Li: a bug fixed - // BigInt bigErr = 1 << (-p); - BigInt bigErr(1); - bigErr = bigErr << static_cast(-p); - exp = z.exp + (x.exp >> 1); - bigNormal(bigErr); - } else { // p > 0 - m = chunkShift(z.m, chunkCeil(p)); - long r = CHUNK_BIT - 1 - (p + CHUNK_BIT - 1) % CHUNK_BIT; -#ifdef CORE_DEBUG - assert(r >= 0); -#endif - - err = 1 >> r; - exp = - chunkCeil(ppp.asLong()); - normal(); - } - } else { // x.m > x.err > 0 (mantissa has error) - BigFloatRep z; - extLong absp=-flrLg(x.err)+bitLength(x.m)-(bits(delta) >> 1)+EXTLONG_FOUR; - - z.sqrt(chunkShift(x.m, delta), absp, AA); - - long qqq = - 1 + (bitLength(x.m) >> 1) - delta * HALF_CHUNK_BIT; - long qq = qqq - clLg(x.err); - long q = qq + bits(z.exp); - - if (q <= 0) { - m = z.m; - long qqqq = - qqq - bits(z.exp); - // Chen Li (09/08/99), a bug fixed here: - // BigInt bigErr = x.err << - qqqq; - // when (-qqqq) is negative, the result is not correct. - // how "<<" and ">>" process negative second operand is - // not well defined. Seems it just take it as a unsigned - // integer and extract the last few bits. - // x.err is a long number which easily overflows. - // From page 22 of Koji's paper, I think the exponent is - // wrong here. So I rewrote it as: - BigInt bigErr = x.err; - if (qqqq >= 0) { - bigErr <<= qqqq; - } else { - bigErr >>= (-qqqq); - ++bigErr; // we need to keep its ceiling. - } - - exp = z.exp + (x.exp >> 1); - bigNormal(bigErr); - } else { // q > 0 - m = chunkShift(z.m, chunkCeil(q)); - long r = CHUNK_BIT - 1 - (q + CHUNK_BIT - 1) % CHUNK_BIT; -#ifdef CORE_DEBUG - assert(r >= 0); -#endif - - err = 1 >> r; - exp = (x.exp >> 1) - chunkCeil(qq); - normal(); - } - } // end of case with error in mantissa - }//else - } else - core_error("BigFloat error: squareroot called with negative operand.", - __FILE__, __LINE__, true); -} //sqrt with initial approximation - -// compareMExp(x) -// returns 1 if *this > x -// 0 if *this = x, -// -1 if *this < x, -// -// Main comparison method for BigFloat -// This is called by BigFloat::compare() -// BE CAREFUL: The error bits are ignored! -// Need another version if we want to take care of error bits - -int BigFloatRep :: compareMExp(const BigFloatRep& x) const { - int st = sign(m); - int sx = sign(x.m); - - if (st > sx) - return 1; - else if (st == 0 && sx == 0) - return 0; - else if (st < sx) - return - 1; - else { // need to compare m && exp - long expDiff = exp - x.exp; - - if (expDiff > 0) // exp > x.exp - return cmp(chunkShift(m, expDiff), x.m); - else if (!expDiff) - return cmp(m, x.m); - else // exp < x.exp - return cmp(m, chunkShift(x.m, - expDiff)); - } -} - -// 3/6/2000: -// This is a private function used by BigFloatRep::operator<< -// to get the exact value -// of floor(log10(M * 2^ e)) where E is an initial guess. -// We will return the correct E which satisfies -// 10^E <= M * 2^e < 10^{E+1} -// But we convert this into -// mm <= M < 10.mm - -long BigFloatRep :: adjustE( long E, BigInt M, long ee) const { - if (M<0) - M=-M; - BigInt mm(1); - if (ee > 0) - M = (M<(ee)); - else - mm = (mm << static_cast(-ee)); - if (E > 0) - mm *= (FiveTo(E)<< static_cast(E)); - else - M *= (FiveTo(-E) << static_cast(-E)); - - if (M < mm) { - do { - E--; - M *= 10; - } while (M < mm); - } else if (M >= 10*mm) { - mm *= 10; - do { - E++; - mm *= 10; - } while (M >= mm); - } - return E; -} - -BigFloatRep::DecimalOutput -BigFloatRep::toDecimal(unsigned int width, bool Scientific) const { - BigFloatRep::DecimalOutput decOut; // to be returned - if (err > 0) { - decOut.isExact = false; - } else { // err == 0 - decOut.isExact = true; - } - - if (err > 0 && err >= abs(m)) { - // if err is larger than mantissa, sign and significant values - // can not be determined. - core_error("BigFloat error: Error is too big!", - __FILE__, __LINE__, false); - decOut.rep = "0.0e0"; // error is too big - decOut.isScientific = false; - decOut.noSignificant = 0; - decOut.errorCode = 1; // sign of this number is unknown - return decOut; - } - - decOut.sign = sign(m); - decOut.errorCode = 0; - - BigInt M(m); // temporary mantissa - long lm = bitLength(M); // binary length of mantissa - long e2 = bits(exp); // binary shift length represented by exponent - long le = clLg(err); // binary length of err - if (le == -1) - le = 0; - - long L10 = 0; - if (M != 0) { - L10 = (long)std::floor((lm + e2) / lgTenM); - L10 = adjustE(L10, m, e2); // L10: floor[log10(M 2^(e2))], M != 0 - } else { - L10 = 0; - } - // Convention: in the positional format, when the output is - // the following string of 8 characters: - // (d0, d1, d2, d3, ".", d4, d5, d6, d7) - // then the decimal point is said to be in the 4th position. - // E.g., (d0, ".", d1, d2) has the decimal point in the 1st position. - // The value of L10 says that the decimal point of output should be at - // the (L10 + 1)st position. This is - // true regardingless of whether M = 0 or not. For zero, we output - // {0.0*} so L10=0. In general, the |value| is less than 10 - // if and only if L10 is 0 and the - // decimal point is in the 1st place. Note that L10 is defined even if - // the output is an integer (in which case it does not physically appear - // but conceptually terminates the sequence of digits). - - // First, get the decimal representaion of (m * B^(exp)). - if (e2 < 0) { - M *= FiveTo(-e2); // M = x * 10^(-e2) - } else if (e2 > 0) { - M <<= e2; // M = x * 2^(e2) - } - - std::string decRep = M.get_str(); - // Determine the "significant part" of this string, i.e. the part which - // is guaranteed to be correct in the presence of error, - // except that the last digit which might be subject to +/- 1. - - if (err != 0) { // valid = number of significant digits - unsigned long valid = floorlg10(m) - (long)std::floor(std::log10(float(err))); - if (decRep.length() > valid) { - decRep.erase(valid); - } - } - - // All the digits in decM are correct, except the last one might - // subject to an error +/- 1. - - if ((decRep[0] == '+') || (decRep[0] == '-')) { - decRep.erase(0, 1); - } - - // Second, make choice between positional representation - // and scientific notation. Use scientific notation when: - // 0) if scientific notation flag is on - // 1) err * B^exp >= 1, the error contribute to the integral part. - // 2) (1 + L10) >= width, there is not have enough places to hold the - // positional representation, not including decimal point. - // 3) The distance between the first significant digit and decimal - // point is too large for the width limit. This is equivalent to - // Either ((L10 >= 0 and (L10 + 1) > width)) - // Or ((L10 < 0) and (-L10 + 1) > width). - - if (Scientific || - ((err > 0) && (le + e2) >= 0) || // if err*B^exp >= 1 - ((L10 >= 0) && (L10 + 1 >= (long)width )) || - ((L10 < 0) && (-L10 + 1 > (long)width ))) { - // use scientific notation - decRep = round(decRep, L10, width); - decOut.noSignificant = width; - decRep.insert(1, "."); - if (L10 != 0) { - decRep += 'e'; - if (L10 > 0) { - decRep += '+'; - } else { // L10 < 0 - decRep += '-'; - } - char eBuf[48]; // enought to hold long number L10 - int ne = 0; - if ((ne = sprintf(eBuf, "%ld", labs(L10))) >= 0) { - eBuf[ne] = '\0'; - } else { - //perror("BigFloat.cpp: Problem in outputing the exponent!"); - core_error("BigFloat error: Problem in outputing the exponent", - __FILE__, __LINE__, true); - } - decRep += eBuf; - decOut.isScientific = true; - } - } else { - // use conventional positional notation. - if (L10 >= 0) { // x >= 1 or x == 0 and L10 + 1 <= width - // round when necessary - if (decRep.length() > width ) { - decRep = round(decRep, L10, width ); - if (decRep.length() > width ) { - // overflow happens! use scientific notation - return toDecimal(width, true); - } - } - decOut.noSignificant = decRep.length(); - if (L10 + 1 < (long)width ) { - decRep.insert(L10 + 1, "."); - } else { // L10 + 1 == width - // do nothing - } - } else { // L10 < 0, 0 < x < 1 - // (-L10) leading zeroes, including one to the left of decimal dot - // need to be added in beginning. - decRep = std::string(-L10, '0') + decRep; - // then round when necessary - if (decRep.length() > width ) { - decRep = round(decRep, L10, width ); - // cannot overflow since there are L10 leading zeroes. - } - decOut.noSignificant = decRep.length() - (-L10); - decRep.insert(1, "."); - } - decOut.isScientific = false; - } -#ifdef CORE_DEBUG - assert(decOut.noSignificant >= 0); -#endif - - decOut.rep = decRep; - return decOut; -}//toDecimal - -std::string BigFloatRep::round(std::string inRep, long& L10, unsigned int width) const { - // round inRep so that the length would not exceed width. - if (inRep.length() <= width) - return inRep; - - int i = width; // < length - bool carry = false; - - if ((inRep[i] >= '5') && (inRep[i] <= '9')) { - carry = true; - i--; - while ((i >= 0) && carry) { - if (carry) { - inRep[i] ++; - if (inRep[i] > '9') { - inRep[i] = '0'; - carry = true; - } else { - carry = false; - } - } - i-- ; - } - - if ((i < 0) && carry) { // overflow - inRep.insert(inRep.begin(), '1'); - L10 ++; - width ++; - } - } - - return inRep.substr(0, width); -}//round(string,width) - - -// This function fromString(str, prec) is similar to the -// constructor Real(char * str, extLong prec) -// See the file Real.cc for the differences - -void BigFloatRep :: fromString(const char *str, const extLong & prec ) { - // NOTE: prec defaults to defBigFloatInputDigits (see BigFloat.h) - // check that prec is not INFTY - if (prec.isInfty()) - core_error("BigFloat error: infinite precision not allowed", - __FILE__, __LINE__, true); - - const char *e = strchr(str, 'e'); - int dot = 0; - long e10 = 0; - if (e != NULL) - e10 = atol(e+1); // e10 is decimal precision of the input string - // i.e., input is A/10^{e10}. - else { - e = str + strlen(str); -#ifdef CORE_DEBUG - assert(*e == '\0'); -#endif - - } - - const char *p = str; - if (*p == '-' || *p == '+') - p++; - m = 0; - exp = 0; - - for (; p < e; p++) { - if (*p == '.') { - dot = 1; - continue; - } - m = m * 10 + (*p - '0'); - if (dot) - e10--; - } - - BigInt one = 1; - long t = (e10 < 0) ? -e10 : e10; - BigInt ten = FiveTo(t) * (one << static_cast(t)); - - // HERE IS WHERE WE USE THE SYSTEM CONSTANT - // defBigFloatInputDigits - // Note: this constant is rather similar to defInputDigits which - // is used by Real and Expr for controlling - // input accuracy. The difference is that defInputDigits can - // be CORE_INFTY, but defBigFloatInputDigits must be finite. - - if (e10 < 0) - div(m, ten, CORE_posInfty, 4 * prec); - else - m *= ten; - if (*str == '-') - m = -m; -}//BigFloatRep::fromString - -std::istream& BigFloatRep :: operator >>(std::istream& i) { - int size = 20; - char *str = new char[size]; - char *p = str; - char c; - int d = 0, e = 0, s = 0; - // d=1 means dot is found - // e=1 means 'e' or 'E' is found - // int done = 0; - - // Chen Li: fixed a bug, the original statement is - // for (i.get(c); c == ' '; i.get(c)); - // use isspace instead of testing c == ' ', since it must also - // skip tab, catridge/return, etc. - // Change to: - // int status; - do { - c = i.get(); - } while (isspace(c)); /* loop if met end-of-file, or - char read in is white-space. */ - // Chen Li, "if (c == EOF)" is unsafe since c is of char type and - // EOF is of int tyep with a negative value -1 - if (i.eof()) { - i.clear(std::ios::eofbit | std::ios::failbit); - return i; - } - - // the current content in "c" should be the first non-whitespace char - if (c == '-' || c == '+') { - *p++ = c; - i.get(c); - } - - for (; isdigit(c) || (!d && c=='.') || - (!e && ((c=='e') || (c=='E'))) || (!s && (c=='-' || c=='+')); i.get(c)) { - if (!e && (c == '-' || c == '+')) - break; - // Chen Li: put one more rule to prohibite input like - // xxxx.xxxe+xxx.xxx: - if (e && (c == '.')) - break; - if (p - str == size) { - char *t = str; - str = new char[size*2]; - memcpy(str, t, size); - delete [] t; - p = str + size; - size *= 2; - } -#ifdef CORE_DEBUG - assert((p-str) < size); -#endif - - *p++ = c; - if (c == '.') - d = 1; - // Chen Li: fix a bug -- the sign of exponent can not happen before - // the character "e" appears! It must follow the "e' actually. - // if (e || c == '-' || c == '+') s = 1; - if (e) - s = 1; - if ((c == 'e') || (c=='E')) - e = 1; - } - - // chenli: make sure that the p is still in the range - if (p - str >= size) { - int len = p - str; - char *t = str; - str = new char[len + 1]; - memcpy(str, t, len); - delete [] t; - p = str + len; - } - -#ifdef CORE_DEBUG - assert(p - str < size); -#endif - - *p = '\0'; - i.putback(c); - fromString(str); - delete [] str; - return i; -}//operator >> - - -// BigFloatRep::toDouble() -// converts the BigFloat to a machine double -// This is a dangerous function as the method -// is silent when it does not fit into a machine double! -// ToDo: fix this by return a machine NaN, +/- Infinity, +/- 0, -// when appropriate. -// Return NaN when error is larger than mantissa -// Return +/- Infinity if BigFloat is too big -// Return +/- 0 if BigFloat is too small -#ifdef _MSC_VER -#pragma warning(disable: 4723) -#endif -double BigFloatRep :: toDouble() const { - if (m == 0) - return (sign(m) * 0.0); - - long e2 = bits(exp); - long le = clLg(err); // if err=0, le will be -1 - if (le == -1) - le = 0; - - BigInt M = m >> static_cast(le);// remove error bits in mantissa - - // Below, we want to return NaN by computing 0.0/0.0. - // To avoid compiler warnings about divide by zero, we do this: - - double foolCompilerZero; - foolCompilerZero = 0.0; - - // COMMENT: we should directly store the - // special IEEE values NaN, +/-Infinity, +/-0 in the code!! - - if (M == 0) - return ( 0.0/foolCompilerZero ) ; // return NaN - - e2 += le; // adjust exponent corresponding to error bits - - int len = bitLength(M) - 53; // this is positive if M is too large - - if (len > 0) { - M >>= len; - e2 += len; - } - - double tt = doubleValue(M); - - int ee = e2 + bitLength(M) - 1; // real exponent. - - if (ee >= 1024) // overflow! - return ( sign(m)/foolCompilerZero ); // return a signed infinity - - if (ee <= -1075) // underflow! - // NOTE: if (-52 < ee <= 0) get denormalized number - return ( sign(m) * 0.0 ); // return signed zero. - - // Execute this loop if e2 < 0; - for (int i = 0; i > e2; i--) - tt /= 2; - - // Execute this loop if e2 > 0; - for (int j = 0; j < e2; j++) - tt *= 2; - - return tt; -}//toDouble -#ifdef _MSC_VER -#pragma warning(default: 4723) -#endif -BigInt BigFloatRep::toBigInt() const { - long e2 = bits(exp); - long le = clLg(err); - if (le == -1) - le = 0; -#ifdef CORE_DEBUG - assert (le >= 0); -#endif - - BigInt M = m >> static_cast(le); // discard the contaminated bits. - e2 += le; // adjust the exponent - - if (e2 < 0) - return M >> static_cast(-e2); - else if (e2 > 0) - return M << static_cast(e2); - else - return M; -} - -long BigFloatRep :: toLong() const { - // convert a BigFloat to a long integer, rounded toward -\infty. - long e2 = bits(exp); - long le = clLg(err); -#ifdef CORE_DEBUG - assert (le >= 0); -#endif - - BigInt M = m >> static_cast(le); // discard the contaminated bits. - e2 += le; // adjust the exponent - long t; - if (e2 < 0) - t = ulongValue(M >> static_cast(-e2)); - else if (e2 > 0) - t = ulongValue(M << static_cast(e2)); - else - t = ulongValue(M); - // t = M.as_long(); - // Note: as_long() will return LONG_MAX in case of overflow. - - return t; -} - -// pow(r,n) function for BigFloat -// Note: power(r,n) calls pow(r,n) -BigFloat pow(const BigFloat& r, unsigned long n) { - if (n == 0) - return BigFloat(1); - else if (n == 1) - return r; - else { - BigFloat x = r; - while ((n % 2) == 0) { // n is even - x *= x; - n >>= 1; - } - BigFloat u = x; - while (true) { - n >>= 1; - if (n == 0) - return u; - x *= x; - if ((n % 2) == 1) // n is odd - u *= x; - } - //return u; // unreachable - } -}//pow - -// experimental -BigFloat root(const BigFloat& x, unsigned long k, - const extLong& a, const BigFloat& A) { - if (x.sign() == 0) { - return BigFloat(0); - } else if (x == 1) { - return BigFloat(1); - } else { - BigFloat q, del, zz; - BigFloat z = A; - BigFloat bk = long(k); - for (; ;) { - zz = pow(z, k-1); - q = x.div(zz, a); - q.makeExact(); - del = z - q; - del.makeExact(); - if (del.MSB() < -a) - break; - z = ((bk-1)*z + q).div(bk, a); - // newton's iteration: z_{n+1}=((k-1)z_n+x/z_n^{k-1})/k - z.makeExact(); - } - return z; - } -}//root - -} //namespace CORE +#endif \ No newline at end of file diff --git a/CGAL_Core/src/CGAL_Core/CoreAux.cpp b/CGAL_Core/src/CGAL_Core/CoreAux.cpp index 8d0c801cb46..adc3998cb57 100644 --- a/CGAL_Core/src/CGAL_Core/CoreAux.cpp +++ b/CGAL_Core/src/CGAL_Core/CoreAux.cpp @@ -33,181 +33,9 @@ * $Id$ ***************************************************************************/ -#include "CGAL/CORE/CoreAux.h" -#include +#ifndef CGAL_HEADER_ONLY -namespace CORE { +#include +#include -//////////////////////////////////////////////////////////// -// More useful functions to implement: -// -// To convert digits into bits: -// given X, compute X * log_2(10) -// To convert bits into digits: -// given X, compute X * log_10(2) -// -//////////////////////////////////////////////////////////// - -//////////////////////////////////////////////////////////// -// flrLg(x) -// returns floor log base 2 of abs(x) -// CONVENTION lg(0) = -1 (Slight improvement, Zilin/Chee 8/5/02) -//////////////////////////////////////////////////////////// -int flrLg(long x) { - if (x == LONG_MIN) { - // special treatment as -LONG_MIN would be not representable as "long" - return LONG_BIT - 1; - } else { - // 1 <= |x| <= LONG_MAX - if (x < 0) - x = - x; - - int lg = -1; - while (x > 0) { - lg++; - x >>= 1; - } - return lg; - } -} - -//////////////////////////////////////////////////////////// -// floor log base 2 of unsigned long x -// CONVENTION lg(0) = -1 (Slight improvement, Zilin/Chee 8/5/02) -//////////////////////////////////////////////////////////// -int flrLg(unsigned long x) { - int lg = -1; - while (x > 0) { - lg++; - x >>= 1; - } - return lg; -} - -//////////////////////////////////////////////////////////// -// ceiling log base 2 of abs(x) -// CONVENTION lg(0) = -1 (Slight improvement, Zilin/Chee 8/5/02) -//////////////////////////////////////////////////////////// -int clLg(long x) { - if (x == LONG_MIN) - return LONG_BIT - 1; - if (x < 0) - x = -x; // use absolute value - if (x > (LONG_MAX >> 1)) // the leading data bit is 1 - return (LONG_BIT - 1); // exclude the sign bit - if (x >= 2) - return flrLg((unsigned long)((x << 1) - 1)); - // SINCE ceilLog_2(x) = floorLog_2(2x-1) for x>=2 - if (x == 1) - return 0; - return -1; // x must be 0 here -} - -//////////////////////////////////////////////////////////// -// ceiling log base 2 of unsigned long x -// CONVENTION lg(0) = -1 -//////////////////////////////////////////////////////////// -int clLg(unsigned long x) { - if (x > (ULONG_MAX >> 1)) // the leading bit is 1 - return LONG_BIT; - if (x >= 2) - return flrLg((x << 1) - 1); - // SINCE ceilLog_2(x) = floorLog_2(2x-1) for x>=2. - if (x == 1) - return 0; - return -1; // x must be equal to 0 -} - -/// gcd for machine type long -/** This is needed when we construct Polynomials with int or long coefficients */ -long gcd(long m, long n) { - if (m == 0) - return core_abs(n); - if (n == 0) - return core_abs(m); - long p = core_abs(m); - long q = core_abs(n); - if (p0) { - long r = p % q; - p = q; - q = r; - } - return p; -} - -// return a gmp_randstate_t structure -gmp_randstate_t* getRandstate() { - static gmp_randstate_t rstate; - static bool initialized = false; - if (!initialized) { - gmp_randinit(rstate, GMP_RAND_ALG_DEFAULT, 32L); - initialized = true; - } - return &rstate; -} - -// char* core_itoa(int n, char* buffer) -// returns a pointer to the null-terminated string in buffer -// NOTES: -// 0. Buffer size should be 17 bytes (resp., 33 bytes, 65 bytes) on 16-bit -// (resp., 32-bit, 64-bit) machines. Formula: 1+sizeof(int)*8 bytes. -// 1. itoa(...) is available on some stdlib.h, but it is -// not defined by ANSI-C and so not all compilers support it. -// 2. Our use of sprintf(...) to do the job is known to -// be inefficient, but this is hardly critical for our usage. -// 3. A more general program should take a 3rd argument (the radix of -// output number). We assume radix 10. -char * core_itoa(int n, char* buffer) { - std::sprintf(buffer, "%d", n); - return buffer; -} - -/// implements the "integer mantissa" function -// (See CORE_PATH/progs/ieee/frexp.cpp for details) -double IntMantissa(double d) { - int e; - return std::ldexp(std::frexp(d, &e), 53); -} - -/// implements the "integer exponent" function -// (See CORE_PATH/progs/ieee/frexp.cpp for details) -int IntExponent(double d) { - int e; - std::frexp(d, &e); - return e-53; -} - -/// CORE_DIAGFILE is file name for core_error(..) output. -const char* CORE_DIAGFILE = "Core_Diagnostics"; // global file name - -/// core_error is the method to write Core Library warning or error messages -/** Both warnings and errors are written to a file called CORE_DIAGFILE. - * But errors are also written on std:cerr (similar to std::perror()). - * */ -// Usage: core_error(message, file_with_error, line_number, err_type) -// where err_type=0 means WARNING, error_type=0 means ERROR -void core_error(std::string msg, std::string file, int lineno, bool err) { - std::ofstream outFile(CORE_DIAGFILE, std::ios::app); // open to append - if (!outFile) { - // perror("CORE ERROR: cannot open Core Diagnostics file"); - std::cerr << "CORE ERROR: can't open Core Diagnostics file"< +#include +#endif diff --git a/CGAL_Core/src/CGAL_Core/CoreIO.cpp b/CGAL_Core/src/CGAL_Core/CoreIO.cpp index a0ae4003802..a03cb47cd03 100644 --- a/CGAL_Core/src/CGAL_Core/CoreIO.cpp +++ b/CGAL_Core/src/CGAL_Core/CoreIO.cpp @@ -29,430 +29,6 @@ * $Id$ ***************************************************************************/ -#include -#include - -namespace CORE { - -void core_io_error_handler(const char *f, const char *m) { - std::cout << "\n error_handler"; - std::cout << "::" << f << "::" << m << "\n"; - std::cout.flush(); - std::abort(); -} - -void core_io_memory_handler(char *t, const char *f, const char *m) { - if (t == NULL) { - std::cout << "\n memory_handler"; - std::cout << "::" << f << "::" << m; - std::cout << "memory exhausted\n"; - std::cout.flush(); - std::abort(); - } -} - -// s has size old_size and will be resized to new_size. -void allocate (char * &s, int old_size, int new_size) { - if (old_size > new_size) - old_size = new_size; - - if (s == NULL) - old_size = 0; - - char *t = new char[new_size]; - core_io_memory_handler(t, "CoreIO", "allocate::out of memory error"); - - int i; - for (i = 0; i < old_size; i++) - t[i] = s[i]; - - delete[] s; - s = t; -} - -// appends c to s at position pos. -// sz is the size of s -void append_char (char * &s, int & sz, int pos, char c) { - if (pos > sz) - core_io_error_handler("CoreIO", "append_char::invalid argument"); - - if (pos == sz) { - allocate(s, sz, 2*sz); - sz *= 2; - } - - s[pos] = c; -} - -// skip blanks, tabs, line breaks and comment lines -int skip_comment_line (std::istream & in) { - int c; - - do { - c = in.get(); - while ( c == '#' ) { - do { - c = in.get(); - } while ( c != '\n' ); - c = in.get(); - } - } while (c == ' ' || c == '\t' || c == '\n'); - - if (c == EOF) - core_io_error_handler("CoreIO::read_from_file()","unexpected end of file."); - - in.putback(c); - return c; -} - -// skips '\\' followed by '\n' -int skip_backslash_new_line (std::istream & in) { - int c = in.get(); - - while (c == '\\') { - c = in.get(); - - if (c == '\n') - c = in.get(); - else - core_io_error_handler("CoreIO::operator>>", "\\ must be immediately followed by new line."); - } - - return c; -} - -void read_string(std::istream& in, char* &buffer, int sz) { - int c, pos=0; - skip_comment_line(in); - - while ( (c = in.get()) != EOF ) { - if ( c == ' ' || c == '\t' || c == '\n' || c == '#') - break; - else - append_char(buffer, sz, pos++, c); - } - append_char(buffer, sz, pos, '\0'); -} - -void read_base_number(std::istream& in, BigInt& m, long length, long maxBits) { - char *buffer; - int size, offset; - int base; - bool is_negate; - - int c, pos = 0; - skip_comment_line(in); - - // read sign - c = in.get(); - if (c == '-') { - is_negate = true; - c = in.get(); - } else - is_negate = false; - - // read base and compute digits - if (c == '0') { - c = in.get(); - if (c == 'b') { - base = 2; - size = (maxBits == 0 || maxBits > length) ? length : maxBits; - offset = length - size; - } else if (c == 'x') { - base = 16; - size = (maxBits == 0) ? length : (maxBits+3) >> 2; - size = (size > length) ? length : size; - offset = (length - size) << 2; - } else { - base = 8; - size = (maxBits == 0) ? length : (maxBits+2) / 3; - size = (size > length) ? length : size; - offset = (length - size) * 3; - in.putback(c); - } - } else { - base = 10; - size = (maxBits == 0) ? length : (int)std::ceil(maxBits*std::log(2.0)/std::log(10.0)); - size = (size > length) ? length : size; - offset = length - size; - in.putback(c); - } - - buffer = new char[size+2]; - // read digits - for (int i=0; (i 0 && base != 10) { - m <<= offset; - } - - if (is_negate) - negate(m); -} - - -void write_base_number(std::ostream& out, char* buffer, int length, int base, int charsPerLine) { - // write big number in a format that gmp's mpz_set_str() can - // automatically recognize with argument base = 0. - if (base == 2) - out << "0b"; - else if (base == 16) - out << "0x"; - else if (base == 8) - out << '0'; - - // write big number in charsPerLine. - char* start, *end, c; - for (int i=0; i= length) - out << start; - else { - end = start + charsPerLine; - c = *end; - *end = '\0'; - - out << start << "\\\n"; - *end = c; - } - } -} - -void readFromFile(BigInt& z, std::istream& in, long maxLength) { - char *buffer; - long length; - - // check type name whether it is Integer or not. - buffer = new char[8]; - read_string(in, buffer, sizeof(buffer)); - if ( std::strcmp(buffer, "Integer") != 0) - core_io_error_handler("BigInt::read_from_file()","type name expected."); - delete[] buffer; - - // read the bit length field. - buffer = new char[100]; - read_string(in, buffer, sizeof(buffer)); - length = std::atol(buffer); - delete[] buffer; - - // read bigint - read_base_number(in, z, length, maxLength); -} - -void writeToFile(const BigInt& z, std::ostream& out, int base, int charsPerLine) { - BigInt c = abs(z); - - // get the absoulte value string - char* buffer = new char[mpz_sizeinbase(c.get_mp(), base) + 2]; - mpz_get_str(buffer, base, c.get_mp()); - int length = std::strlen(buffer); - - // write type name of big number and length - //out << "# This is an experimental big number format.\n"; - out << "Integer " << length << "\n"; - - // if bigint is negative, then write an sign '-'. - if ( sign(z) < 0 ) - out << '-'; - - write_base_number(out, buffer, length, base, charsPerLine); - out << "\n"; - delete[] buffer; -} - -void readFromFile(BigFloat& bf, std::istream& in, long maxLength) { - char *buffer; - long length; - long exponent; - BigInt mantissa; - - // check type name whether it is Float - buffer = new char[6]; - read_string(in, buffer, sizeof(buffer)); - if (std::strcmp(buffer, "Float") != 0) - core_io_error_handler("BigFloat::read_from_file()", "type name expected"); - delete[] buffer; - - // read base (default is 16384) - buffer = new char[8]; - read_string(in, buffer, sizeof(buffer)); - if (std::strcmp(buffer, "(16384)") != 0) - core_io_error_handler("BigFloat::read_from_file()", "base expected"); - delete[] buffer; - - // read the bit length field. - buffer = new char[100]; - read_string(in, buffer, sizeof(buffer)); - length = std::atol(buffer); - delete[] buffer; - - // read exponent - buffer = new char[100]; - read_string(in, buffer, sizeof(buffer)); - exponent = std::atol(buffer); - delete[] buffer; - - // read mantissa - read_base_number(in, mantissa, length, maxLength); - - // construct BigFloat - bf = BigFloat(mantissa, 0, exponent); -} - -void writeToFile(const BigFloat& bf, std::ostream& out, int base, int charsPerLine) { - BigInt c(CORE::abs(bf.m())); - - // get the absoulte value string - char* buffer = new char[mpz_sizeinbase(c.get_mp(), base) + 2]; - mpz_get_str(buffer, base, c.get_mp()); - int length = std::strlen(buffer); - - - // write type name, base, length - //out << "# This is an experimental Big Float format." << std::endl; - out << "Float (16384) " << length << std::endl; - // write exponent - out << bf.exp() << std::endl; - - // write mantissa - if ( CORE::sign(bf.m()) < 0 ) - out << '-'; - - write_base_number(out, buffer, length, base, charsPerLine); - out << '\n'; - delete[] buffer; -} - -/* Underconstruction ---- -void BigFloat::read_from_file2(std::istream& in, long maxLength) { - long length = 1024; - char *buffer; - - // check type name whether it is Float - buffer = new char[7]; - BigInt::read_string(in, buffer, sizeof(buffer)); - if (strcmp(buffer, "NFloat") != 0) - core_io_error_handler("BigFloat::read_from_file2()", "type name expected"); - delete[] buffer; - - // read base (default is 16) - buffer = new char[5]; - BigInt::read_string(in, buffer, sizeof(buffer)); - if (strcmp(buffer, "(16)") != 0) - core_io_error_handler("BigFloat::read_from_file2()", "base expected"); - delete[] buffer; - - // read length field - buffer = new char[100]; - BigInt::read_string(in, buffer, sizeof(buffer)); - - // get the length field if it is not null. - if (buffer[0] != '\0') { - length = atol(buffer); - if (maxLength > 0 && length >= maxLength) - length = maxLength; - } - delete[] buffer; - - // read exponent - buffer = new char[100]; - BigInt::read_string(in, buffer, sizeof(buffer)); - long exp16 = atol(buffer); - delete[] buffer; - - // read mantissa - buffer = new char[length+2]; - //BigInt::read_base_number(in, buffer, length); - - BigInt m16(buffer); - delete[] buffer; - - // convert to base CHUNK_BIT - exp16 = exp16 - length + 1; - if ( m16.is_negative() ) - exp16 ++; - - long tmp_exp = exp16 * 4; - long q = tmp_exp / CHUNK_BIT; - long r = tmp_exp % CHUNK_BIT; - if ( r < 0 ) { - r += CHUNK_BIT; - q --; - } - - BigInt mantissa = m16 << r; - long exponent = q; - - // construct BigFloat - if (--rep->refCount == 0) - delete rep; - - rep = new BigFloatRep(mantissa, 0, exponent); - rep->refCount++; - -} - -// write normal float -// now it assumed to write in hex base, i.e. B=2^4=16 -// (note: our default base B=2^(CHUNK_BIT)=2^14=16384 -void BigFloat::write_to_file2(std::ostream& out, int base, int charsPerLine) { - // convert to base 16. - long new_base = 4; // 2^4 = 16 - long tmp_exp = (rep->exp) * CHUNK_BIT; - long q = tmp_exp / new_base; - long r = tmp_exp % new_base; - std::cout << "CORE_DEBUG: q=" << q << ", r=" << r << std::endl; - if ( r < 0 ) { - r += new_base; - q--; - } - std::cout << "CORE_DEBUG: q=" << q << ", r=" << r << std::endl; - - BigInt m16 = (rep->m) << r; - - int size = mpz_sizeinbase(m16.I, base) + 2; - std::cout << "size=" << size << std::endl; - char* buffer = new char[size]; - - int length = bigint_to_string(m16, buffer, base); - std::cout << "length=" << length << std::endl; - - long exp16 = q + length - 1; - if ( m16.is_negative() ) - exp16 --; - - // write type name, base, length - out << "# This is an experimental Big Float format." << std::endl; - out << "NFloat (16) " << length << std::endl; - - // write exponent - out << exp16 << std::endl; - - // write mantissa - if ( m16.is_negative() ) { - out << '-'; - buffer ++; - } - - BigInt::write_base_number(out, buffer, length, base, charsPerLine); - out << '\n'; - delete[] buffer; -} -*/ - -} //namespace CORE - +#ifndef CGAL_HEADER_ONLY +#include +#endif \ No newline at end of file diff --git a/CGAL_Core/src/CGAL_Core/Expr.cpp b/CGAL_Core/src/CGAL_Core/Expr.cpp index 89751cd62f7..09f0108d0d1 100644 --- a/CGAL_Core/src/CGAL_Core/Expr.cpp +++ b/CGAL_Core/src/CGAL_Core/Expr.cpp @@ -34,1119 +34,9 @@ * $Id$ ***************************************************************************/ +#ifndef CGAL_HEADER_ONLY + #include -#include +#include -namespace CORE { - -#ifdef CORE_DEBUG_BOUND -unsigned int BFMSS_counter = 0; -unsigned int BFMSS_only_counter = 0; -unsigned int Measure_counter = 0; -unsigned int Measure_only_counter = 0; -unsigned int Cauchy_counter = 0; -unsigned int Cauchy_only_counter = 0; -unsigned int LiYap_counter = 0; -unsigned int LiYap_only_counter = 0; -unsigned int rootBoundHitCounter = 0; -unsigned int computeBoundCallsCounter = 0; -#endif - -const char* Add::name = "+"; -const char* Sub::name = "-"; - -/******************************************************** - * class Expr - ********************************************************/ -const Expr& Expr::getZero() { - static Expr Zero(0); - return Zero; -} -const Expr& Expr::getOne() { - static Expr One(1); - return One; -} - -// computes an interval comprising a pair of doubles -// Note: -// -// This function returns are two consecutive representable binary -// IEEE double values whichs contain the real value, but when you print out -// them, you might be confused by the decimal represention due to round. -// -void Expr::doubleInterval(double & lb, double & ub) const { - double d = doubleValue(); - if (! CGAL_CORE_finite(d)) { // if overflow, underflow or NaN - lb = ub = d; - return; - } - int sign = ((* this) -Expr(d)).sign(); - // Seems like doubleValue() always give a lower bound, - // so sign = 0 or 1 (never -1). - //std::cout << "Sign = " << sign << std::endl; - if (sign == 0) { - lb = ub = d; - return; - } - int exp; - frexp(d, & exp); // get the exponent of d - exp--; // the exp from frexp satisfies - // 2^{exp-1} <= d < 2^{exp} - // But, we want exp to satisfy - // 2^{exp} <= d < 2^{exp+1} - if (sign > 0) { - lb = d; - ub = d + ldexp(1.0, -52+exp); - return; - } else { - ub = d; - lb = d - ldexp(1.0, -52+exp); - return; - } -} - -// floor(e, sub) returns the floor(e), and puts the -// remainder into sub. -BigInt floor(const Expr& e, Expr &sub) { - if (e==0) { - return 0; - } - BigInt f = e.approx(CORE_INFTY, 2).BigIntValue(); - sub = e-f; - // Adjustment - if (sub<0) - ++sub, --f; - if (sub>=1) - --sub, ++f; - assert(sub >=0 && sub<1); // got an assertion error? (Chee 3/24/04) - return f; -} - -// Chenli: implemented algorithm from Goldberg's article. -// 7/01: Thanks to Serge Pashkov for fixing infinite loop when n=0. -Expr pow(const Expr& e, unsigned long n) { - if (n == 0) - return Expr(1); - else if (n == 1) - return e; - else { - Expr x = e; - while ((n % 2) == 0) { // n is even - x *= x; - n >>= 1; - } - Expr u = x; - while (true) { - n >>= 1; - if (n == 0) - return u; - x *= x; - if ((n % 2) == 1) // n is odd - u *= x; - } - //return u; // unreachable - } -}//pow - -NodeInfo::NodeInfo() : appValue(CORE_REAL_ZERO), appComputed(false), - flagsComputed(false), knownPrecision(CORE_negInfty), -#ifdef CORE_DEBUG - relPrecision(EXTLONG_ZERO), absPrecision(CORE_negInfty), numNodes(0), -#endif - // Most of the following data members don't need to be - // initialized here. - d_e(EXTLONG_ZERO), visited(false), sign(0), - uMSB(CORE_negInfty), lMSB(CORE_negInfty), - // length(0), - measure(EXTLONG_ZERO), high(EXTLONG_ZERO), low(EXTLONG_ONE), - lc(EXTLONG_ZERO), tc(EXTLONG_ZERO), - v2p(EXTLONG_ZERO), v2m(EXTLONG_ZERO), - v5p(EXTLONG_ZERO), v5m(EXTLONG_ZERO), - u25(EXTLONG_ZERO), l25(EXTLONG_ZERO), - ratFlag(0), ratValue(NULL) { } - -/******************************************************** - * class ExprRep - ********************************************************/ -// constructor -ExprRep::ExprRep() : refCount(1), nodeInfo(NULL), ffVal(0.0) { } - -// Computes the root bit bound of the expression. -// In effect, computeBound() returns the current value of low. -extLong ExprRep::computeBound() { - extLong measureBd = measure(); - // extLong cauchyBd = length(); - extLong ourBd = (d_e() - EXTLONG_ONE) * high() + lc(); - // BFMSS[2,5] bound. - extLong bfmsskBd; - if (v2p().isInfty() || v2m().isInfty()) - bfmsskBd = CORE_INFTY; - else - bfmsskBd = l25() + u25() * (d_e() - EXTLONG_ONE) - v2() - ceilLg5(v5()); - - // since we might compute \infty - \infty for this bound - if (bfmsskBd.isNaN()) - bfmsskBd = CORE_INFTY; - - extLong bd = core_min(measureBd, - // core_min(cauchyBd, - core_min(bfmsskBd, ourBd)); -#ifdef CORE_SHOW_BOUNDS - std::cout << "Bounds (" << measureBd << - "," << bfmsskBd << ", " << ourBd << "), "; - std::cout << "MIN = " << bd << std::endl; - std::cout << "d_e= " << d_e() << std::endl; -#endif - -#ifdef CORE_DEBUG_BOUND - // Some statistics about which one is/are the winner[s]. - computeBoundCallsCounter++; - int number_of_winners = 0; - std::cerr << " New contest " << std::endl; - if (bd == bfmsskBd) { - BFMSS_counter++; - number_of_winners++; - std::cerr << " BFMSS is the winner " << std::endl; - } - if (bd == measureBd) { - Measure_counter++; - number_of_winners++; - std::cerr << " measureBd is the winner " << std::endl; - } - /* if (bd == cauchyBd) { - Cauchy_counter++; - number_of_winners++; - std::cerr << " cauchyBd is the winner " << std::endl; - } - */ - if (bd == ourBd) { - LiYap_counter++; - number_of_winners++; - std::cerr << " ourBd is the winner " << std::endl; - } - - assert(number_of_winners >= 1); - - if (number_of_winners == 1) { - if (bd == bfmsskBd) { - BFMSS_only_counter++; - std::cerr << " BFMSSBd is the only winner " << std::endl; - } else if (bd == measureBd) { - Measure_only_counter++; - std::cerr << " measureBd is the only winner " << std::endl; - } - /* else if (bd == cauchyBd) { - Cauchy_only_counter++; - std::cerr << " cauchyBd is the only winner " << std::endl; - } */ - else if (bd == ourBd) { - LiYap_only_counter++; - std::cerr << " ourBd is the only winner " << std::endl; - } - } -#endif - - return bd; -}//computeBound() - -void ExprRep::reduceToBigRat(const BigRat& rat) { - Real value(rat); - - //appValue() = value; - appComputed() = false; // since appValue is not assigned until approx() is called - flagsComputed() = true; - knownPrecision() = CORE_negInfty; - -#ifdef CORE_DEBUG - relPrecision() = EXTLONG_ZERO; - absPrecision() = CORE_negInfty; - //numNodes() = numNodes(); -#endif - - d_e() = EXTLONG_ONE; - //visited() = e->visited(); - sign() = value.sign(); - uMSB() = value.MSB(); - lMSB() = value.MSB(); - // length() = value.length(); // fixed? original = 1 - measure() = value.height(); // measure <= height for rational value - - // BFMSS[2,5] bound. - value.ULV_E(u25(), l25(), v2p(), v2m(), v5p(), v5m()); - - extLong u_e = u25() + v2p(); - extLong l_e = l25() + v2m(); - - u_e = u_e + ceilLg5(v5p()); - l_e = l_e + ceilLg5(v5m()); - - if (l_e == EXTLONG_ZERO) { // no divisions introduced - high() = u_e; - low() = EXTLONG_ONE - u_e; // - (u_e - 1) - } else { - high() = u_e - l_e + EXTLONG_ONE; - low() = 2 - high(); - } - - lc() = l_e; - tc() = u_e; - - if (ratValue() == NULL) - ratValue() = new BigRat(rat); - else - *(ratValue()) = rat; -} - -// This only copies the current information of the argument e to -// *this ExprRep. -void ExprRep::reduceTo(const ExprRep *e) { - if (e->appComputed()) { - appValue() = e->appValue(); - appComputed() = true; - flagsComputed() = true; - knownPrecision() = e->knownPrecision(); -#ifdef CORE_DEBUG - relPrecision() = e->relPrecision(); - absPrecision() = e->absPrecision(); - numNodes() = e->numNodes(); -#endif - - } - d_e() = e->d_e(); - //visited() = e->visited(); - sign() = e->sign(); - uMSB() = e->uMSB(); - lMSB() = e->lMSB(); - // length() = e->length(); // fixed? original = 1 - measure() = e->measure(); - - // BFMSS[2,5] bound. - u25() = e->u25(); - l25() = e->l25(); - v2p() = e->v2p(); - v2m() = e->v2m(); - v5p() = e->v5p(); - v5m() = e->v5m(); - - high() = e->high(); - low() = e->low(); // fixed? original = 0 - lc() = e->lc(); - tc() = e->tc(); - - // Chee (Mar 23, 2004), Notes on ratFlag(): - // =============================================================== - // For more information on the use of this flag, see progs/pentagon. - // This is an integer valued member of the NodeInfo class. - // Its value is used to determine whether - // we can ``reduce'' an Expression to a single node containing - // a BigRat value. This reduction is done if the global variable - // rationalReduceFlag=true. The default value is false. - // This is the intepretation of ratFlag: - // ratFlag < 0 means irrational - // ratFlag = 0 means not initialized - // ratFlag > 0 means rational - // Currently, ratFlag>0 is an upper bound on the size of the expression, - // since we recursively compute - // ratFlag(v) = ratFlag(v.lchild)+ratFlag(v.rchild) + 1. - // PROPOSAL: if ratFlag() > RAT_REDUCE_THRESHHOLD - // then we automatically do a reduction. We must determine - // an empirical value for RAT_REDUCE_THRESHOLD - - if (rationalReduceFlag) { - ratFlag() = e->ratFlag(); - - if (e->ratFlag() > 0 && e->ratValue() != NULL) { - ratFlag() ++; - if (ratValue() == NULL) - ratValue() = new BigRat(*(e->ratValue())); - else - *(ratValue()) = *(e->ratValue()); - } else - ratFlag() = -1; - } -} - -void ExprRep::reduceToZero() { - appValue() = CORE_REAL_ZERO; - appComputed() = true; - flagsComputed() = true; - knownPrecision() = CORE_negInfty; -#ifdef CORE_DEBUG - relPrecision() = EXTLONG_ZERO; - absPrecision() = CORE_negInfty; - // numNodes() = 0; -#endif - - d_e() = EXTLONG_ONE; - visited() = false; - sign() = 0; - uMSB() = CORE_negInfty; - lMSB() = CORE_negInfty; - // length() = 0; // fixed? original = 1 - measure() = EXTLONG_ZERO; - - // BFMSS[2,5] bound. - u25() = l25() = v2p() = v2m() = v5p() = v5m() = EXTLONG_ZERO; - - low() = EXTLONG_ONE; // fixed? original = 0 - high() = lc() = tc() = EXTLONG_ZERO; - - if (rationalReduceFlag) { - if (ratFlag() > 0) { - ratFlag() ++; - if (ratValue() == NULL) - ratValue() = new BigRat(0); - else - *(ratValue()) = 0; - } else - ratFlag() = 1; - } -} - -//////////////////////////////////////////////////////////// -// Test whether the current approximate value satisfies -// the composite precision requirements [relPrec, absPrec]. -//////////////////////////////////////////////////////////// - -bool ExprRep::withinKnownPrecision(const extLong& relPrec, - const extLong& absPrec) { - if (appComputed()) { // an approximate value has been evaluated. - if (appValue().isExact()) { - return true; - } else { // approximation has certain error. - // decide to which position it is required to compute correctly. - extLong required = core_max(-absPrec, appValue().lMSB()-relPrec); - // see whether the existing error is smaller than the requirement. - return (knownPrecision() <= required); - } - } else - return false; -}//withinKnownPrecision(a, r) - -// approximate the expression to certain precisions when -// necessary (either no approximate value available or -// the existing one is not accurate enough). -void ExprRep::approx(const extLong& relPrec = defRelPrec, - const extLong& absPrec = defAbsPrec) { - if (!getSign()) - return; // if it is exactly zero... - - // NOTE: The Filter might give a precise enough approximation already. - if (!getExactSign()) - return; - - if (!appComputed() || (!withinKnownPrecision(relPrec, absPrec))) { - // it's necessary to re-evaluate. - // to avoid huge lMSB which would cause long time and problems. - - // if it is a rational node - if (rationalReduceFlag && ratFlag() > 0 && ratValue() != NULL) - appValue() = Real(*(ratValue())).approx(relPrec, absPrec); //< shouldn't - // this case be done by computeApproxValue()? - else - computeApproxValue(relPrec, absPrec); - - // update flags - appComputed() = true; - knownPrecision() = appValue().clLgErr(); -#ifdef CORE_DEBUG - if (relPrecision() < relPrec) - relPrecision() = relPrec; - if (absPrecision() < absPrec) - absPrecision() = absPrec; -#endif - - } -} - -// return an approximate value to certain precision. -const Real& ExprRep::getAppValue(const extLong& relPrec, - const extLong& absPrec) { - if (getSign()) { - approx(relPrec, absPrec); - return appValue(); - } else - return CORE_REAL_ZERO; -} - -std::ostream& operator<<(std::ostream& o, ExprRep& rep) { - if (rep.getSign()) { - rep.approx(defRelPrec, defAbsPrec); - o << rep.appValue(); - } else { - o << "0"; - } - return o; -} - -// Chee, Zilin: July 17, 2002 -// Original algorithm is wrongly implemented, and can take time -// exponential in the size of the dag. -// -// METHOD: -// Inductively assume that all "visited" flags are false. -// This calls for a reimplementation of "count()" and "clearFlag()". -// Actually, we did not have to fix the count() function. -// -// (1) First recursively compute d_e for each node -// by calling the count() function. -// Important thing is count() will turn the "visited" flags -// to be true, so that there is no double counting. -// Furthermore, if d_e had already been computed, the -// arithmetic for d_e can be avoided (in this case, -// it is only the setting of "visited" flag that we -// are interested in! -// (2) At the end of count(), we have set all reachable nodes -// to "visited", and their d_e have been computed. -// (3) Now, call clearFlag() to recursively clear all reachable -// nodes. NOTE THAT PREVIOUSLY, clearFlag() was called -// first! This obvious is wrong - -extLong ExprRep::degreeBound() { - if (d_e() == EXTLONG_ONE) // no radical nodes below - return EXTLONG_ONE; - count(); - clearFlag(); - return d_e(); -} -// class ConstRealRep -// constructor -ConstRealRep::ConstRealRep(const Real & r) : value(r) { - if (!value.isExact()) { - // clone the BigFloat and set its error to zero. - value = value.BigFloatValue().makeExact(); - } - ffVal = filteredFp(value); -} - -// initialize nodeInfo -void ConstRep::initNodeInfo() { - nodeInfo = new NodeInfo(); - d_e() = EXTLONG_ONE; -} -void UnaryOpRep::initNodeInfo() { - if (child->nodeInfo == NULL) - child->initNodeInfo(); - nodeInfo = new NodeInfo(); -} -void BinOpRep::initNodeInfo() { - if (first->nodeInfo == NULL) - first->initNodeInfo(); - if (second->nodeInfo == NULL) - second->initNodeInfo(); - nodeInfo = new NodeInfo(); -} - -#ifdef CORE_DEBUG -unsigned long ConstRep::dagSize() { - if (!visited()) { - visited() = true; - numNodes() = 1; - } else - numNodes() = 0; - return numNodes(); -} - -unsigned long UnaryOpRep::dagSize() { - if (!visited()) { - visited() = true; - numNodes() = child->dagSize() + 1; - } else - numNodes() = 0; - return numNodes(); -} - -unsigned long BinOpRep::dagSize() { - if (!visited()) { - visited() = true; - numNodes() = first->dagSize() + second->dagSize() + 1; - } else - numNodes() = 0; - return numNodes(); -} - -void ConstRep::fullClearFlag() { - if (visited()) - visited() = false; -} - -void UnaryOpRep::fullClearFlag() { - if (visited()) { - child->fullClearFlag(); - visited() = false; - } -} - -void BinOpRep::fullClearFlag() { - if (visited()) { - first->fullClearFlag(); - second->fullClearFlag(); - visited() = false; - } -} -#endif - -// -// clear visited flag -// -/* see Expr.h - void ConstRep::clearFlag() - { visited = false; } -*/ -void UnaryOpRep::clearFlag() { - if (d_e() == EXTLONG_ONE) - return; // no radicals below. - if (visited()) { - visited() = false; - child->clearFlag(); - } -} -// class BinOpRep -void BinOpRep::clearFlag() { - if (d_e() == EXTLONG_ONE) - return; // rational below - if (visited()) { - visited() = false; - first->clearFlag(); - second->clearFlag(); - } -} - -// -// count # of squareroot -// -extLong ConstRep::count() { - if (visited()) - return EXTLONG_ONE; - visited() = true; - return d_e(); -} - -extLong NegRep::count() { - if (d_e() == EXTLONG_ONE) - return EXTLONG_ONE; - if (visited()) - return EXTLONG_ONE; - visited() = true; - d_e() = child->count(); - return d_e(); -} - -extLong SqrtRep::count() { - if (d_e() == EXTLONG_ONE) - return EXTLONG_ONE; - if (visited()) - return EXTLONG_ONE; - visited() = true; - d_e() = child->count() * EXTLONG_TWO; - return d_e(); -} - -extLong BinOpRep::count() { - if (d_e() == EXTLONG_ONE) - return EXTLONG_ONE; - if (visited()) - return EXTLONG_ONE; - visited() = true; - d_e() = first->count() * second->count(); - return d_e(); -} - -// -// compute exact flags functions -// -// exact value - -void computeExactFlags_temp(ConstRep* t, const Real &value) { - // Chen Li: the following is incorrect: - // uMSB = lMSB = value.MSB(); - // because the value could be a BigFloat which is an interval. - if (value.isExact()) { - t->uMSB() = t->lMSB() = value.MSB(); - } else { - t->uMSB() = value.uMSB(); - t->lMSB() = value.lMSB(); - core_error("Leaves in DAG is not exact!", __FILE__, __LINE__, true); - } - - t->sign() = value.sign(); - // t->length() = value.length(); - t->measure() = value.height(); // for rationals and integers, - // measure = height. - - // BFMSS[2,5] bound. - value.ULV_E(t->u25(), t->l25(), t->v2p(), t->v2m(), t->v5p(), t->v5m()); - - // The original BFMSS parameters can be set from the BFMSS[2,5] parameters. - // Here we just need them locally. - extLong u_e = t->u25() + t->v2p() + ceilLg5(t->v5p()); - extLong l_e = t->l25() + t->v2m() + ceilLg5(t->v5m()); - -#ifdef ORIGINAL_BFMSS - // To go back to the original BFMSS : - t->u25() = u_e; - t->l25() = l_e; - t->v2p() = t->v2m() = t->v5p() = t->v5m() = EXTLONG_ZERO; -#elif defined BFMSS_2_ONLY - // To go back to BFMSS[2] only : - t->u25() = t->u25() + ceilLg5(t->v5p()); - t->l25() = t->l25() + ceilLg5(t->v5m()); - t->v5p() = t->v5m() = EXTLONG_ZERO; -#endif - - if (l_e == EXTLONG_ZERO) { // no divisions introduced - t->high() = u_e; - t->low() = EXTLONG_ONE - u_e; // - (u_e - 1) - } else { - t->high() = u_e - l_e + EXTLONG_ONE; - t->low() = EXTLONG_TWO - t->high(); - } - - t->lc() = l_e; - t->tc() = u_e; - - // set BigRat value - if (rationalReduceFlag) { - t->ratFlag() = 1; - t->ratValue() = new BigRat(value.BigRatValue()); - } - - t->flagsComputed() = true; -} - -void ConstDoubleRep::computeExactFlags() {// can be made more efficient - computeExactFlags_temp(this, Real(ffVal.getValue())); -} - -void ConstRealRep::computeExactFlags() { - computeExactFlags_temp(this, value); -} - -void NegRep::computeExactFlags() { - if (!child->flagsComputed()) - child->computeExactFlags(); - - if (child->sign() == 0) { - reduceToZero(); - return; - } - - if (rationalReduceFlag) { - if (child->ratFlag()>0 && child->ratValue() != NULL) { - BigRat val = -(*(child->ratValue())); - reduceToBigRat(val); - ratFlag() = child->ratFlag()+1; - return; - } else - ratFlag() = -1; - } - - sign() = -child->sign(); - uMSB() = child->uMSB(); - lMSB() = child->lMSB(); - - // length() = child->length(); - measure() = child->measure(); - u25() = child->u25(); - l25() = child->l25(); - v2p() = child->v2p(); - v2m() = child->v2m(); - v5p() = child->v5p(); - v5m() = child->v5m(); - high() = child->high(); - low() = child->low(); - lc() = child->lc(); - tc() = child->tc(); - flagsComputed() = true; -}//NegRep::computeExactFlags - -void SqrtRep::computeExactFlags() { - if (!child->flagsComputed()) - child->computeExactFlags(); - - if (rationalReduceFlag) - ratFlag() = -1; - - sign() = child->sign(); - if (sign() < 0) - core_error("squareroot is called with negative operand.", - __FILE__, __LINE__, true); - - uMSB() = child->uMSB() / EXTLONG_TWO; - lMSB() = child->lMSB() / EXTLONG_TWO; - - // length() = child->length(); - measure() = child->measure(); - - // BFMSS[2,5] bound. - if (child->v2p() + ceilLg5(child->v5p()) + child->u25() >= - child->v2m() + ceilLg5(child->v5m()) + child->l25()) { - extLong vtilda2 = child->v2p() + child->v2m(); - v2p() = vtilda2 / EXTLONG_TWO; - v2m() = child->v2m(); - extLong vmod2; - if (v2p().isInfty()) - vmod2 = CORE_INFTY; - else - vmod2 = vtilda2 - EXTLONG_TWO*v2p(); // == vtilda2 % 2 - extLong vtilda5 = child->v5p() + child->v5m(); - v5p() = vtilda5 / EXTLONG_TWO; - v5m() = child->v5m(); - extLong vmod5; - if (v5p().isInfty()) - vmod5 = CORE_INFTY; - else - vmod5 = vtilda5 - EXTLONG_TWO*v5p(); // == vtilda5 % 2 - u25() = (child->u25() + child->l25() + vmod2 + ceilLg5(vmod5) + EXTLONG_ONE) / EXTLONG_TWO; - l25() = child->l25(); - } else { - extLong vtilda2 = child->v2p() + child->v2m(); - v2p() = child->v2p(); - v2m() = vtilda2 / EXTLONG_TWO; - extLong vmod2; - if (v2m().isInfty()) - vmod2 = CORE_INFTY; - else - vmod2 = vtilda2 - EXTLONG_TWO*v2m(); // == vtilda2 % 2 - extLong vtilda5 = child->v5p() + child->v5m(); - v5p() = child->v5p(); - v5m() = vtilda5 / EXTLONG_TWO; - u25() = child->u25(); - extLong vmod5; - if (v5m().isInfty()) - vmod5 = CORE_INFTY; - else - vmod5 = vtilda5 - EXTLONG_TWO*v5m(); // == vtilda5 % 2 - l25() = (child->u25() + child->l25() + vmod2 + ceilLg5(vmod5) + EXTLONG_ONE) / EXTLONG_TWO; - } - - high() = (child->high() +EXTLONG_ONE)/EXTLONG_TWO; - low() = child->low() / EXTLONG_TWO; - lc() = child->lc(); - tc() = child->tc(); - flagsComputed() = true; -}// SqrtRep::computeExactFlags - -void MultRep::computeExactFlags() { - if (!first->flagsComputed()) - first->computeExactFlags(); - if (!second->flagsComputed()) - second->computeExactFlags(); - - if ((!first->sign()) || (!second->sign())) { - // value must be exactly zero. - reduceToZero(); - return; - } - // rational node - if (rationalReduceFlag) { - if (first->ratFlag() > 0 && second->ratFlag() > 0) { - BigRat val = (*(first->ratValue()))*(*(second->ratValue())); - reduceToBigRat(val); - ratFlag() = first->ratFlag() + second->ratFlag(); - return; - } else - ratFlag() = -1; - } - - // value is irrational. - uMSB() = first->uMSB() + second->uMSB() + EXTLONG_ONE; - lMSB() = first->lMSB() + second->lMSB(); - sign() = first->sign() * second->sign(); - - extLong df = first->d_e(); - extLong ds = second->d_e(); - // extLong lf = first->length(); - // extLong ls = second->length(); - - // length() = df * ls + ds * lf; - measure() = (first->measure()) * ds+(second->measure()) * df; - - // BFMSS[2,5] bound. - v2p() = first->v2p() + second->v2p(); - v2m() = first->v2m() + second->v2m(); - v5p() = first->v5p() + second->v5p(); - v5m() = first->v5m() + second->v5m(); - u25() = first->u25() + second->u25(); - l25() = first->l25() + second->l25(); - - high() = first->high() + second->high(); - low() = first->low() + second->low(); - - lc() = ds * first->lc() + df * second->lc(); - tc() = core_min(ds * first->tc() + df * second->tc(), measure()); - - flagsComputed() = true; -}// MultRep::computeExactFlags - -void DivRep::computeExactFlags() { - if (!first->flagsComputed()) - first->computeExactFlags(); - if (!second->flagsComputed()) - second->computeExactFlags(); - - if (!second->sign()) - core_error("zero divisor.", __FILE__, __LINE__, true); - - if (!first->sign()) {// value must be exactly zero. - reduceToZero(); - return; - } - - // rational node - if (rationalReduceFlag) { - if (first->ratFlag() > 0 && second->ratFlag() > 0) { - BigRat val = (*(first->ratValue()))/(*(second->ratValue())); - reduceToBigRat(val); - ratFlag() = first->ratFlag() + second->ratFlag(); - return; - } else - ratFlag() = -1; - } - - // value is irrational. - uMSB() = first->uMSB() - second->lMSB(); - lMSB() = first->lMSB() - second->uMSB() - EXTLONG_ONE; - sign() = first->sign() * second->sign(); - - extLong df = first->d_e(); - extLong ds = second->d_e(); - // extLong lf = first->length(); - // extLong ls = second->length(); - - // length() = df * ls + ds * lf; - measure() = (first->measure())*ds + (second->measure())*df; - - // BFMSS[2,5] bound. - v2p() = first->v2p() + second->v2m(); - v2m() = first->v2m() + second->v2p(); - v5p() = first->v5p() + second->v5m(); - v5m() = first->v5m() + second->v5p(); - u25() = first->u25() + second->l25(); - l25() = first->l25() + second->u25(); - - high() = first->high() + second->low(); - low() = first->low() + second->high(); - - lc() = ds * first->lc() + df * second->tc(); - tc() = core_min(ds * first->tc() + df * second->lc(), measure()); - - flagsComputed() = true; -} - -// -// approximation functions -// -void ConstDoubleRep::computeApproxValue(const extLong& /*relPrec*/, - const extLong& /*absPrec*/) -// can ignore precision bounds since ffVal.getValue() returns exact value -{ - appValue() = Real(ffVal.getValue()); -} - -void ConstRealRep::computeApproxValue(const extLong& relPrec, - const extLong& absPrec) { - appValue() = value.approx(relPrec, absPrec); -} - -void NegRep::computeApproxValue(const extLong& relPrec, - const extLong& absPrec) { - appValue() = -child->getAppValue(relPrec, absPrec); -} - -void SqrtRep::computeApproxValue(const extLong& relPrec, - const extLong& absPrec) { - extLong r = relPrec + relPrec + EXTLONG_EIGHT; // chenli: ??? - extLong a = absPrec + absPrec + EXTLONG_EIGHT; - extLong pr = - lMSB() + r; - extLong p = pr < a ? pr : a; - - Real val = child->getAppValue(r, a); - if (incrementalEvalFlag) { - if (appValue() == CORE_REAL_ZERO) - appValue() = val; - appValue() = val.sqrt(p, appValue().BigFloatValue()); - } else - appValue() = val.sqrt(p); -} - -void MultRep::computeApproxValue(const extLong& relPrec, - const extLong& absPrec) { - if (lMSB() < EXTLONG_BIG && lMSB() > EXTLONG_SMALL) { - extLong r = relPrec + EXTLONG_FOUR; - extLong afr = - first->lMSB() + EXTLONG_ONE; - extLong afa = second->uMSB() + absPrec + EXTLONG_FIVE; - extLong af = afr > afa ? afr : afa; - extLong asr = - second->lMSB() + EXTLONG_ONE; - extLong asa = first->uMSB() + absPrec + EXTLONG_FIVE; - extLong as = asr > asa ? asr : asa; - appValue() = first->getAppValue(r, af)*second->getAppValue(r, as); - } else { - std::cerr << "lMSB = " << lMSB() << std::endl; - core_error("a huge lMSB in MulRep", __FILE__, __LINE__, false); - } -} - -void DivRep::computeApproxValue(const extLong& relPrec, - const extLong& absPrec) { - if (lMSB() < EXTLONG_BIG && lMSB() > EXTLONG_SMALL) { - extLong rr = relPrec + EXTLONG_SEVEN; // These rules come from - extLong ra = uMSB() + absPrec + EXTLONG_EIGHT; // Koji's Master Thesis, page 65 - extLong ra2 = core_max(ra, EXTLONG_TWO); - extLong r = core_min(rr, ra2); - extLong af = - first->lMSB() + r; - extLong as = - second->lMSB() + r; - - extLong pr = relPrec + EXTLONG_SIX; - extLong pa = uMSB() + absPrec + EXTLONG_SEVEN; - extLong p = core_min(pr, pa); // Seems to be an error: - // p can be negative here! - // Also, this does not conform to - // Koji's thesis which has a default - // relative precision (p.65). - - appValue() = first->getAppValue(r, af).div(second->getAppValue(r, as), p); - } else { - std::cerr << "lMSB = " << lMSB() << std::endl; - core_error("a huge lMSB in DivRep", __FILE__, __LINE__, false); - } -} - -// -// Debug Help Functions -// -void Expr::debug(int mode, int level, int depthLimit) const { - std::cout << "-------- Expr debug() -----------" << std::endl; - std::cout << "rep = " << rep << std::endl; - if (mode == Expr::LIST_MODE) - rep->debugList(level, depthLimit); - else if (mode == Expr::TREE_MODE) - rep->debugTree(level, 0, depthLimit); - else - core_error("unknown debugging mode", __FILE__, __LINE__, false); - std::cout << "---- End Expr debug(): " << std::endl; -} - - -const std::string ExprRep::dump(int level) const { - std::ostringstream ost; - if (level == OPERATOR_ONLY) { - ost << op(); - } else if (level == VALUE_ONLY) { - ost << appValue(); - } else if (level == OPERATOR_VALUE) { - ost << op() << "[val: " << appValue() << "]"; - } else if (level == FULL_DUMP) { - ost << op() - << "[val: " << appValue() << "; " - << "kp: " << knownPrecision() << "; " -#ifdef CORE_DEBUG - << "r: " << relPrecision() << "; " - << "a: " << absPrecision() << "; " -#endif - << "lMSB: " << lMSB() << "; " - << "uMSB: " << uMSB() << "; " - << "sign: " << sign() << "; " - // << "length: " << length() << "; " - << "measure: " << measure() << "; " - << "d_e: " << d_e() << "; " - << "u25: " << u25() << "; " - << "l25: " << l25() << "; " - << "v2p: " << v2p() << "; " - << "v2m: " << v2m() << "; " - << "v5p: " << v5p() << "; " - << "v5m: " << v5m() << "; " - << "high: " << high() << "; " - << "low: " << low() << "; " - << "lc: " << lc() << "; " - << "tc: " << tc() - << "]"; - } - return std::string(ost.str()); - // note that str() return an array not properly terminated! -} - - -void UnaryOpRep::debugList(int level, int depthLimit) const { - if (depthLimit <= 0) - return; - if (level == Expr::SIMPLE_LEVEL) { - std::cout << "(" << dump(OPERATOR_VALUE); - child->debugList(level, depthLimit - 1); - std::cout << ")"; - } else if (level == Expr::DETAIL_LEVEL) { - std::cout << "(" << dump(FULL_DUMP); - child->debugList(level, depthLimit - 1); - std::cout << ")"; - } -} - -void UnaryOpRep::debugTree(int level, int indent, int depthLimit) const { - if (depthLimit <= 0) - return; - for (int i = 0; idebugTree(level, indent + 2, depthLimit - 1); -} - -void ConstRep::debugList(int level, int depthLimit) const { - if (depthLimit <= 0) - return; - if (level == Expr::SIMPLE_LEVEL) { - std::cout << "(" << dump(OPERATOR_VALUE) << ")"; - } else if (level == Expr::DETAIL_LEVEL) { - std::cout << "(" << dump(FULL_DUMP) << ")"; - } -} - -void ConstRep::debugTree(int level, int indent, int depthLimit) const { - if (depthLimit <= 0) - return; - for (int i=0; idebugList(level, depthLimit - 1); - std::cout << ", "; - second->debugList(level, depthLimit - 1); - std::cout << ")" ; -} - -void BinOpRep::debugTree(int level, int indent, int depthLimit) const { - if (depthLimit <= 0) - return; - for (int i=0; idebugTree(level, indent + 2, depthLimit - 1); - second->debugTree(level, indent + 2, depthLimit - 1); -} - -} //namespace CORE +#endif \ No newline at end of file diff --git a/CGAL_Core/src/CGAL_Core/GmpIO.cpp b/CGAL_Core/src/CGAL_Core/GmpIO.cpp index 3d665366a08..9b74ba289e7 100644 --- a/CGAL_Core/src/CGAL_Core/GmpIO.cpp +++ b/CGAL_Core/src/CGAL_Core/GmpIO.cpp @@ -12,257 +12,9 @@ * $Id$ ***************************************************************************/ -/* Auxiliary functions for C++-style input of GMP types. - -Copyright 2001 Free Software Foundation, Inc. - -This file is part of the GNU MP Library. - -The GNU MP Library is free software; 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. - -The GNU MP Library is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY -or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public -License for more details. - -You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, -MA 02110-1301, USA. */ +#ifndef CGAL_HEADER_ONLY #include -#include -#include -#include -#include +#include -using namespace std; - -namespace CORE { - -int -__gmp_istream_set_base (istream &i, char &c, bool &zero, bool &showbase) -{ - int base; - - zero = showbase = false; - switch (i.flags() & ios::basefield) - { - case ios::dec: - base = 10; - break; - case ios::hex: - base = 16; - break; - case ios::oct: - base = 8; - break; - default: - showbase = true; // look for initial "0" or "0x" or "0X" - if (c == '0') - { - if (! i.get(c)) - c = 0; // reset or we might loop indefinitely - - if (c == 'x' || c == 'X') - { - base = 16; - i.get(c); - } - else - { - base = 8; - zero = true; // if no other digit is read, the "0" counts - } - } - else - base = 10; - break; - } - - return base; -} - -void -__gmp_istream_set_digits (string &s, istream &i, char &c, bool &ok, int base) -{ - switch (base) - { - case 10: - while (isdigit(c)) - { - ok = true; // at least a valid digit was read - s += c; - if (! i.get(c)) - break; - } - break; - case 8: - while (isdigit(c) && c != '8' && c != '9') - { - ok = true; // at least a valid digit was read - s += c; - if (! i.get(c)) - break; - } - break; - case 16: - while (isxdigit(c)) - { - ok = true; // at least a valid digit was read - s += c; - if (! i.get(c)) - break; - } - break; - } -} - -istream & -//operator>> (istream &i, mpz_ptr z) -io_read (istream &i, mpz_ptr z) -{ - int base; - char c = 0; - string s; - bool ok = false, zero, showbase; - - i.get(c); // start reading - - if (i.flags() & ios::skipws) // skip initial whitespace - while (isspace(c) && i.get(c)) - ; - - if (c == '-' || c == '+') // sign - { - if (c == '-') // mpz_set_str doesn't accept '+' - s = "-"; - i.get(c); - } - - while (isspace(c) && i.get(c)) // skip whitespace - ; - - base = __gmp_istream_set_base(i, c, zero, showbase); // select the base - __gmp_istream_set_digits(s, i, c, ok, base); // read the number - - if (i.good()) // last character read was non-numeric - i.putback(c); - else if (i.eof() && (ok || zero)) // stopped just before eof - i.clear(); - - if (ok) - mpz_set_str(z, s.c_str(), base); // extract the number - else if (zero) - mpz_set_ui(z, 0); - else - i.setstate(ios::failbit); // read failed - - return i; -} - -istream & -//operator>> (istream &i, mpq_ptr q) -io_read (istream &i, mpq_ptr q) -{ - int base; - char c = 0; - string s; - bool ok = false, zero, showbase; - - i.get(c); // start reading - - if (i.flags() & ios::skipws) // skip initial whitespace - while (isspace(c) && i.get(c)) - ; - - if (c == '-' || c == '+') // sign - { - if (c == '-') - s = "-"; - i.get(c); - } - - while (isspace(c) && i.get(c)) // skip whitespace - ; - - base = __gmp_istream_set_base(i, c, zero, showbase); // select the base - __gmp_istream_set_digits(s, i, c, ok, base); // read the numerator - - if (! ok && zero) // the only digit read was "0" - { - base = 10; - s += '0'; - ok = true; - } - - if (i.flags() & ios::skipws) - while (isspace(c) && i.get(c)) // skip whitespace - ; - - if (c == '/') // there's a denominator - { - bool zero2 = false; - int base2 = base; - - s += '/'; - ok = false; // denominator is mandatory - i.get(c); - - while (isspace(c) && i.get(c)) // skip whitespace - ; - - if (showbase) // check base of denominator - base2 = __gmp_istream_set_base(i, c, zero2, showbase); - - if (base2 == base || base2 == 10) // read the denominator - __gmp_istream_set_digits(s, i, c, ok, base); - - if (! ok && zero2) // the only digit read was "0" - { // denominator is 0, but that's your business - s += '0'; - ok = true; - } - } - - if (i.good()) // last character read was non-numeric - i.putback(c); - else if (i.eof() && ok) // stopped just before eof - i.clear(); - - if (ok) - mpq_set_str(q, s.c_str(), base); // extract the number - else - i.setstate(ios::failbit); // read failed - - return i; -} - -ostream& -//operator<< (ostream &o, mpz_srcptr z) -io_write (ostream &o, mpz_srcptr z) -{ - char *str = new char [mpz_sizeinbase(z,10) + 2]; - str = mpz_get_str(str, 10, z); - o << str ; - delete[] str; - return o; -} - -ostream& -//operator<< (ostream &o, mpq_srcptr q) -io_write (ostream &o, mpq_srcptr q) -{ - // size according to GMP documentation - char *str = new char [mpz_sizeinbase(mpq_numref(q), 10) + - mpz_sizeinbase (mpq_denref(q), 10) + 3]; - str = mpq_get_str(str, 10, q); - o << str ; - delete[] str; - return o; -} - -} //namespace CORE +#endif diff --git a/CGAL_Core/src/CGAL_Core/Real.cpp b/CGAL_Core/src/CGAL_Core/Real.cpp index 477c02a0cab..cd4604d14c0 100644 --- a/CGAL_Core/src/CGAL_Core/Real.cpp +++ b/CGAL_Core/src/CGAL_Core/Real.cpp @@ -35,242 +35,9 @@ * $Id$ ***************************************************************************/ -#include +#ifndef CGAL_HEADER_ONLY + #include +#include -namespace CORE { - -const Real& Real::getZero() { - static Real Zero(0); - return Zero; -} - -BigInt floor(const Real& r, Real &sub) { - BigInt f = r.approx(CORE_INFTY, 2).BigIntValue(); - sub = r-f; - // Adjustment - if (sub<0) - ++sub, --f; - if (sub>=1) - --sub, ++f; - assert(sub >=0 && sub<1); - return f; -} - -// pow(r,n) and power(r, n) are the same function -// -Real pow(const Real& r, unsigned long n) { - if (n == 0) - return Real(1); - else if (n == 1) - return r; - else { - Real x = r; - while ((n % 2) == 0) { // n is even - x *= x; - n >>= 1; - } - Real u = x; - while (true) { - n >>= 1; - if (n == 0) - return u; - x *= x; - if ((n % 2) == 1) // n is odd - u *= x; - } - //return u; // unreachable - } -}//pow - -extern BigInt FiveTo(unsigned long exp); - -// Construct Real from String -// Note: -// -- Zilin Du: 06/03/2003 -// -- Original it is the code for Real's constructor for "const char*". -// I change it to a function so that two constrcutors can share the code. -// now it is private and no default value. -// -// --Default value of the argument "prec" is defInputDigits -// --If prec is CORE_posInfty, then the input is -// read in exactly. Otherwise, we convert to a RealBigFloat -// with absolute error at most 10^{-prec} - -// Constructor Real( char *str, extLong& prec) -// is very similar to -// BigFloatRep::fromString( char *str, extLong& prec); -// Differences: -// In BigFloat(str, prec), the value of prec cannot be infinity, and -// it defaults to defBigFloatInputDigits; -// In Real(str, prec), the value of prec is allowed to be infinity, and -// it defaults to defInputDigits. -// -// Why do we have the two versions? It allows us to use the BigFloat class -// directly, without relying on Real class. - -void Real::constructFromString(const char *str, const extLong& prec ) -// NOTE: prec defaults to defInputDigits (see Real.h) -{ - // 8/8/01, Chee and Zilin: add a new rational string format: - // this format is indicated by the presence of a slash "/" - // Moreover, the value of prec is ignored (basically - // assumed to be infinity). - - if (std::strchr(str, '/') != NULL) { // this is a rational number - rep = new RealBigRat(BigRat(str)); - return; - } - - const char *e = std::strchr(str, 'e'); - int dot = 0; - long e10 = 0; - if (e != NULL) - e10 = std::atol(e+1); // e10 is decimal precision of the input string - // i.e., input is A/10^{e10}. - else { - e = str + std::strlen(str); -#ifdef CORE_DEBUG - assert(*e == '\0'); #endif - } - - const char *p = str; - if (*p == '-' || *p == '+') - p++; - BigInt m(0); - - for (; p < e; p++) { - if (*p == '.') { - dot = 1; - continue; - } - m = m * 10 + (*p - '0'); - if (dot) - e10--; - } - - long t = (e10 < 0) ? -e10 : e10; - BigInt one(1); - BigInt ten = FiveTo(t) * (one << static_cast(t)); - if (*str == '-') - m = -m; - if (e10 >= 0) { - // convert exactly from integer numbers - m *= ten; - rep = new RealBigInt(m); - } else { // e10 < 0, fractional numbers - // HERE IS WHERE WE USE THE SYSTEM CONSTANT - // defInputDigits - // Note: defInputDigits should be at least log_2(10). - // We default defInputDigits to 4. - //std::cout << "(m,ten)=" << m << "," << ten << std::endl; - BigRat r(m, ten); - if (prec.isInfty()) { // convert exactly! to a big rational - rep = new RealBigRat(r); - } else { - // convert approximately, to a BigFloat within the - // specified precision: - // BigFloat bf(r, CORE_posInfty, prec * lgTenM) ; - BigFloat bf(r, CORE_posInfty, prec * 4) ; - rep = new RealBigFloat(bf); - } - } -}// Real(str, prec) - -// The operator >>(i,x) calls the constructor Real(char*) -std::istream& operator >>(std::istream& i, Real& x) { - int size = 20; - char *str = new char[size]; - char *p = str; - char c; - int d = 0, e = 0, s = 0; - // int done = 0; - - // Chen Li: fixed a bug, the original statement is - // for (i.get(c); c == ' '; i.get(c)); - // use isspace instead of testing c == ' ', since it must also - // skip tab, catridge/return, etc. - // Change to: - // int status; - do { - i.get(c); - } while (!i.eof() && isspace(c)); /* loop if met end-of-file, or - char read in is white-space. */ - // Chen Li, - // original "if (c == EOF) ..." is unsafe since c is of char type and - // EOF is of int tyep with a negative value -1 - - if (i.eof()) { - i.clear(std::ios::eofbit | std::ios::failbit); - delete [] str; - return i; - } - - // the current content in "c" should be the first non-whitespace char - if (c == '-' || c == '+') { - *p++ = c; - i.get(c); - } - - for (; isdigit(c) || (!d && c=='.') || - (!e && c=='e') || (!s && (c=='-' || c=='+')); i.get(c)) { - if (!i) break; - if (!e && (c == '-' || c == '+')) - break; - // Chen Li: put one more rule to prohibite input like - // xxxx.xxxe+xxx.xxx: - if (e && (c == '.')) - break; - if (p - str == size) { - char *t = str; - str = new char[size*2]; - std::memcpy(str, t, size); - delete [] t; - p = str + size; - size *= 2; - } -#ifdef CORE_DEBUG - assert((p-str) < size); -#endif - - *p++ = c; - if (c == '.') - d = 1; - // Chen Li: fix a bug -- the sign of exponent can not happen before - // the character "e" appears! It must follow the "e' actually. - // if (e || c == '-' || c == '+') s = 1; - if (e) - s = 1; - if (c == 'e') - e = 1; - } - - if (!i && !i.eof()) { - delete [] str; - return i; - } - // chenli: make sure that the p is still in the range - if (p - str >= size) { - int len = p - str; - char *t = str; - str = new char[len + 1]; - std::memcpy(str, t, len); - delete [] t; - p = str + len; - } - -#ifdef CORE_DEBUG - assert(p - str < size); -#endif - - *p = '\0'; - i.putback(c); - i.clear(); - // old: x = Real(str, i.precision()); // use precision of input stream. - x = Real(str); // default precision = defInputDigits - delete [] str; - return i; -}//operator >> (std::istream&, Real&) - -} //namespace CORE diff --git a/CGAL_Core/src/CGAL_Core/extLong.cpp b/CGAL_Core/src/CGAL_Core/extLong.cpp index a4fdccbfca5..901b758de58 100644 --- a/CGAL_Core/src/CGAL_Core/extLong.cpp +++ b/CGAL_Core/src/CGAL_Core/extLong.cpp @@ -39,157 +39,9 @@ * $Id$ ***************************************************************************/ +#ifndef CGAL_HEADER_ONLY + #include +#include -namespace CORE { - -const extLong& extLong::getNaNLong() { - static extLong NaNLong(true); - return NaNLong; -} - -const extLong& extLong::getPosInfty() { - static extLong posInfty(EXTLONG_MAX); - return posInfty; -} - -const extLong& extLong::getNegInfty() { - static extLong negInfty(EXTLONG_MIN); - return negInfty; -} - -void extLong::add(extLong& z, long x, long y) { - if (x > 0 && y > 0 && x >= EXTLONG_MAX - y) { - z.val = EXTLONG_MAX; - z.flag = 1; - } else if (x < 0 && y < 0 && x <= EXTLONG_MIN - y) { - z.val = EXTLONG_MIN; - z.flag = -1; - } else { - z.val = x + y; - z.flag = 0; - } -} - -// arithmetic and assignment operators -extLong& extLong::operator+= (const extLong& y) { - if (flag == 2 || y.flag == 2 || (flag * y.flag < 0)) { -#ifdef CORE_DEBUG - if (flag * y.flag < 0) //want a message at the first creation of NaN - core_error("extLong NaN Error in addition.", __FILE__, __LINE__, false); #endif - - *this = CORE_NaNLong; - } else if (flag == 1 || y.flag == 1) { // one of them is +Inf - *this = CORE_posInfty; - } else if (flag == -1 || y.flag == -1) { // one of them is -Inf - *this = CORE_negInfty; - } else { // x and y are normal now - add(*this, val, y.val); - } - return *this; -} - -extLong& extLong::operator-= (const extLong& y) { - if (flag == 2 || y.flag == 2 || (flag * y.flag > 0)) { -#ifdef CORE_DEBUG - if (flag * y.flag > 0) //want a message at the first creation of NaN - core_error("extLong NaN Error in subtraction.", __FILE__, __LINE__, false); -#endif - - *this = CORE_NaNLong; - } else if (flag == 1 || y.flag == -1) { - *this = CORE_posInfty; - } else if (flag == -1 || y.flag == 1) { - *this = CORE_negInfty; - } else { - add(*this, val, -y.val); - } - return *this; -} - -extLong& extLong::operator*= (const extLong& y) { - if (flag == 2 || y.flag == 2) { - *this = CORE_NaNLong; - } else if ((flag != 0) || (y.flag != 0)) { - if (sign() * y.sign() > 0) - *this = CORE_posInfty; - else - *this = CORE_negInfty; - } else { // flag == 0 and y.flag == 0 - double d = double(val) * double(y.val); - long p = val * y.val; - if (std::fabs(d - p) <= std::fabs(d) * relEps) { - val = p; - flag = 0; - } else if (d > EXTLONG_MAX) { - *this = CORE_posInfty; - } else if (d < EXTLONG_MIN) { - *this = CORE_negInfty; - } else { -#ifdef CORE_DEBUG - core_error("extLong NaN Error in multiplication.",__FILE__,__LINE__,false); -#endif - *this = CORE_NaNLong; - } - } - return *this; -} - -extLong& extLong::operator/= (const extLong& y) { - if (flag==2 || y.flag==2 || ((flag != 0) && (y.flag != 0)) || (y.val == 0)) { -#ifdef CORE_DEBUG - if (y.val == 0) - core_error("extLong NaN Error, Divide by Zero.", __FILE__, __LINE__, false); - else if ((flag !=0) && (y.flag !=0)) - core_error("extLong NaN Error, +/-Inf/Inf.", __FILE__, __LINE__, false); -#endif - - *this = CORE_NaNLong; - } else if ((flag != 0) || (y.flag != 0)) { // y.flag == 0 now and y != 0 - if (sign() * y.sign() > 0) - *this = CORE_posInfty; - else - *this = CORE_negInfty; - } else { // flag == 0 and y.flag == 0 - val /= y.val; // no overflow in divisions - flag = 0; - } - return *this; -} - -// unary minus -extLong extLong::operator- () const { - if (flag == 0) - return extLong(-val); - else if (flag == 1) - return CORE_negInfty; - else if (flag == -1) - return CORE_posInfty; - else // NaN - return CORE_NaNLong; -} - -// sign -// You should check "flag" before calling this, otherwise -// you cannot interprete the returned value! -int extLong::sign() const { - if (flag == 2) - core_error("NaN Sign can not be determined!", __FILE__, __LINE__, false); - return ((val == 0) ? 0 : ((val > 0) ? 1 : -1)); -} - -// stream operators -std::ostream& operator<< (std::ostream& o, const extLong& x) { - if (x.flag == 1) - o << " infty "; - else if (x.flag == - 1) - o << " tiny "; - else if (x.flag == 2) - o << " NaN "; - else - o << x.val; - return o; -} - -} //namespace CORE diff --git a/Number_types/include/CGAL/CORE_BigFloat.h b/Number_types/include/CGAL/CORE_BigFloat.h index 48e2dffabd7..2488af7d00d 100644 --- a/Number_types/include/CGAL/CORE_BigFloat.h +++ b/Number_types/include/CGAL/CORE_BigFloat.h @@ -251,7 +251,7 @@ namespace internal{ CORE::BigFloat inline -round(const CORE::BigFloat& x, long rel_prec = CORE::defRelPrec.toLong() ){ +round(const CORE::BigFloat& x, long rel_prec = CORE::get_static_defRelPrec().toLong() ){ CGAL_postcondition(rel_prec >= 0); // since there is not rel prec defined if Zero_in(x) @@ -344,9 +344,9 @@ public: typedef long result_type; long operator() ( long prec ) const { - long result = ::CORE::defRelPrec.toLong(); - ::CORE::defRelPrec = prec; - ::CORE::defBFdivRelPrec = prec; + long result = ::CORE::get_static_defRelPrec().toLong(); + ::CORE::get_static_defRelPrec() = prec; + ::CORE::get_static_defBFdivRelPrec() = prec; return result; } }; @@ -356,7 +356,7 @@ public: typedef long result_type; long operator() () const { - return ::CORE::defRelPrec.toLong(); + return ::CORE::get_static_defRelPrec().toLong(); } }; }; @@ -378,17 +378,19 @@ template <> class Algebraic_structure_traits< CORE::BigFloat > : public std::unary_function< Type, Type > { public: Type operator()( const Type& x ) const { - // What I want is a sqrt computed with ::CORE::defRelPrec bits. + // What I want is a sqrt computed with + // ::CORE::get_static_defRelPrec() bits. // And not ::CORE::defBFsqrtAbsPrec as CORE does. - CGAL_precondition(::CORE::defRelPrec.toLong() > 0); + CGAL_precondition(::CORE::get_static_defRelPrec().toLong() > 0); CGAL_precondition(x > 0); - Type a = CGAL::internal::round(x, ::CORE::defRelPrec.toLong()*2); + Type a = CGAL::internal::round( + x, ::CORE::get_static_defRelPrec().toLong()*2); CGAL_postcondition(a > 0); - Type tmp1 = - CORE::BigFloat(a.m(),0,0).sqrt(::CORE::defRelPrec.toLong()); + Type tmp1 = CORE::BigFloat( + a.m(),0,0).sqrt(::CORE::get_static_defRelPrec().toLong()); Type err = Type(0,long(std::sqrt(double(a.err()))),0) * CORE::BigFloat::exp2(a.exp()*7); diff --git a/Number_types/include/CGAL/CORE_coercion_traits.h b/Number_types/include/CGAL/CORE_coercion_traits.h index d097ffcc6f1..d1ebbc69b72 100644 --- a/Number_types/include/CGAL/CORE_coercion_traits.h +++ b/Number_types/include/CGAL/CORE_coercion_traits.h @@ -84,7 +84,7 @@ struct Coercion_traits{ Type operator()(const CORE::BigFloat& x) const { return x;} Type operator()(const ::CORE::BigInt x) const { CORE::BigFloat result; - result.approx(x,CORE::defRelPrec.toLong(),LONG_MAX); + result.approx(x,CORE::get_static_defRelPrec().toLong(),LONG_MAX); // Do not use MakeFloorExact as it changes the Bigfloat CGAL_postcondition( ::CORE::BigRat(::CORE::BigFloat(result.m()-result.err(),0,result.exp())) <= x ); CGAL_postcondition( ::CORE::BigRat(::CORE::BigFloat(result.m()+result.err(),0,result.exp())) >= x ); @@ -104,7 +104,7 @@ struct Coercion_traits{ Type operator()(const CORE::BigFloat& x) const { return x;} Type operator()(const ::CORE::BigRat x) const { - CORE::BigFloat result(x,CORE::defRelPrec.toLong(),LONG_MAX); + CORE::BigFloat result(x,CORE::get_static_defRelPrec().toLong(),LONG_MAX); // Do not use MakeFloorExact as it changes the Bigfloat CGAL_postcondition( ::CORE::BigRat(::CORE::BigFloat(result.m()-result.err(),0,result.exp())) <= x ); CGAL_postcondition( ::CORE::BigRat(::CORE::BigFloat(result.m()+result.err(),0,result.exp())) >= x ); @@ -123,7 +123,7 @@ struct Coercion_traits{ typedef Type result_type; Type operator()(const CORE::BigFloat& x) const { return x;} Type operator()(const ::CORE::Expr x) const { - CORE::BigFloat result(x, CORE::defRelPrec.toLong(),LONG_MAX); + CORE::BigFloat result(x, CORE::get_static_defRelPrec().toLong(),LONG_MAX); // Do not use MakeFloorExact as it changes the Bigfloat CGAL_postcondition( ::CORE::BigRat(::CORE::BigFloat(result.m()-result.err(),0,result.exp())) <= x ); CGAL_postcondition( ::CORE::BigRat(::CORE::BigFloat(result.m()+result.err(),0,result.exp())) >= x ); diff --git a/STL_Extension/include/CGAL/Spatial_lock_grid_3.h b/STL_Extension/include/CGAL/Spatial_lock_grid_3.h index c2a389361b0..14a5e869790 100644 --- a/STL_Extension/include/CGAL/Spatial_lock_grid_3.h +++ b/STL_Extension/include/CGAL/Spatial_lock_grid_3.h @@ -606,64 +606,6 @@ protected: TLS_thread_uint_ids m_tls_thread_ids; }; -//***************************************************************************** -// class Spatial_lock_grid_3 -// Note: undocumented, for testing only... -//***************************************************************************** - -template <> -class Spatial_lock_grid_3 - : public Spatial_lock_grid_base_3< - Spatial_lock_grid_3 > -{ - typedef Spatial_lock_grid_base_3< - Spatial_lock_grid_3 > Base; - -public: - // Constructors - Spatial_lock_grid_3(const Bbox_3 &bbox, int num_grid_cells_per_axis) - : Base(bbox, num_grid_cells_per_axis) - { - int num_cells = - num_grid_cells_per_axis*num_grid_cells_per_axis*num_grid_cells_per_axis; - m_grid.resize(num_cells); - } - - /// Destructor - ~Spatial_lock_grid_3() - { - } - - bool is_cell_locked_impl(int cell_index) - { - bool locked = m_grid[cell_index].try_lock(); - if (locked) - m_grid[cell_index].unlock(); - return !locked; - } - - template - bool try_lock_cell_impl(int cell_index) - { - bool success = m_grid[cell_index].try_lock(); - if (success) - { - get_thread_local_grid()[cell_index] = true; - m_tls_locked_cells.local().push_back(cell_index); - } - return success; - } - - void unlock_cell_impl(int cell_index) - { - m_grid[cell_index].unlock(); - } - -protected: - - std::vector m_grid; -}; - } //namespace CGAL #else // !CGAL_LINKED_WITH_TBB From f532cbc0133c384a36ac3a5c0d9c833bf37c1b8c Mon Sep 17 00:00:00 2001 From: Clement Jamin Date: Mon, 15 Dec 2014 21:57:51 +0100 Subject: [PATCH 28/30] Forgot 2 *_impl.h files --- CGAL_Core/include/CGAL/CORE/Real_impl.h | 291 +++++++++++++++++++++ CGAL_Core/include/CGAL/CORE/extLong_impl.h | 212 +++++++++++++++ 2 files changed, 503 insertions(+) create mode 100644 CGAL_Core/include/CGAL/CORE/Real_impl.h create mode 100644 CGAL_Core/include/CGAL/CORE/extLong_impl.h diff --git a/CGAL_Core/include/CGAL/CORE/Real_impl.h b/CGAL_Core/include/CGAL/CORE/Real_impl.h new file mode 100644 index 00000000000..4916e8057e6 --- /dev/null +++ b/CGAL_Core/include/CGAL/CORE/Real_impl.h @@ -0,0 +1,291 @@ +/**************************************************************************** + * Core Library Version 1.7, August 2004 + * Copyright (c) 1995-2004 Exact Computation Project + * All rights reserved. + * + * This file is part of CORE (http://cs.nyu.edu/exact/core/). + * 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. + * + * + * File: Real.cpp + * Synopsis: The Real class is a superclass for all the number + * systems in the Core Library (int, long, float, double, + * BigInt, BigRat, BigFloat, etc) + * + * Written by + * Koji Ouchi + * Chee Yap + * Chen Li + * Zilin Du + * Sylvain Pion + * + * WWW URL: http://cs.nyu.edu/exact/ + * Email: exact@cs.nyu.edu + * + * $URL$ + * $Id$ + ***************************************************************************/ + +#ifdef CGAL_HEADER_ONLY +#define CGAL_INLINE_FUNCTION inline +#else +#define CGAL_INLINE_FUNCTION +#endif + +#include +#include + +#ifdef CGAL_HEADER_ONLY +#include // for FiveTo +#endif + +namespace CORE { + +CGAL_INLINE_FUNCTION +const Real& Real::getZero() { + static Real Zero(0); + return Zero; +} + +CGAL_INLINE_FUNCTION +BigInt floor(const Real& r, Real &sub) { + BigInt f = r.approx(CORE_INFTY, 2).BigIntValue(); + sub = r-f; + // Adjustment + if (sub<0) + ++sub, --f; + if (sub>=1) + --sub, ++f; + assert(sub >=0 && sub<1); + return f; +} + +// pow(r,n) and power(r, n) are the same function +// +CGAL_INLINE_FUNCTION +Real pow(const Real& r, unsigned long n) { + if (n == 0) + return Real(1); + else if (n == 1) + return r; + else { + Real x = r; + while ((n % 2) == 0) { // n is even + x *= x; + n >>= 1; + } + Real u = x; + while (true) { + n >>= 1; + if (n == 0) + return u; + x *= x; + if ((n % 2) == 1) // n is odd + u *= x; + } + //return u; // unreachable + } +}//pow + +extern BigInt FiveTo(unsigned long exp); + +// Construct Real from String +// Note: +// -- Zilin Du: 06/03/2003 +// -- Original it is the code for Real's constructor for "const char*". +// I change it to a function so that two constrcutors can share the code. +// now it is private and no default value. +// +// --Default value of the argument "prec" is get_static_defInputDigits() +// --If prec is CORE_posInfty, then the input is +// read in exactly. Otherwise, we convert to a RealBigFloat +// with absolute error at most 10^{-prec} + +// Constructor Real( char *str, extLong& prec) +// is very similar to +// BigFloatRep::fromString( char *str, extLong& prec); +// Differences: +// In BigFloat(str, prec), the value of prec cannot be infinity, and +// it defaults to defBigFloatInputDigits; +// In Real(str, prec), the value of prec is allowed to be infinity, and +// it defaults to defInputDigits. +// +// Why do we have the two versions? It allows us to use the BigFloat class +// directly, without relying on Real class. + +CGAL_INLINE_FUNCTION +void Real::constructFromString(const char *str, const extLong& prec ) +// NOTE: prec defaults to get_static_defInputDigits() (see Real.h) +{ + // 8/8/01, Chee and Zilin: add a new rational string format: + // this format is indicated by the presence of a slash "/" + // Moreover, the value of prec is ignored (basically + // assumed to be infinity). + + if (std::strchr(str, '/') != NULL) { // this is a rational number + rep = new RealBigRat(BigRat(str)); + return; + } + + const char *e = std::strchr(str, 'e'); + int dot = 0; + long e10 = 0; + if (e != NULL) + e10 = std::atol(e+1); // e10 is decimal precision of the input string + // i.e., input is A/10^{e10}. + else { + e = str + std::strlen(str); +#ifdef CORE_DEBUG + assert(*e == '\0'); +#endif + } + + const char *p = str; + if (*p == '-' || *p == '+') + p++; + BigInt m(0); + + for (; p < e; p++) { + if (*p == '.') { + dot = 1; + continue; + } + m = m * 10 + (*p - '0'); + if (dot) + e10--; + } + + long t = (e10 < 0) ? -e10 : e10; + BigInt one(1); + BigInt ten = FiveTo(t) * (one << static_cast(t)); + if (*str == '-') + m = -m; + if (e10 >= 0) { + // convert exactly from integer numbers + m *= ten; + rep = new RealBigInt(m); + } else { // e10 < 0, fractional numbers + // HERE IS WHERE WE USE THE SYSTEM CONSTANT + // get_static_defInputDigits() + // Note: get_static_defInputDigits() should be at least log_2(10). + // We default get_static_defInputDigits() to 4. + //std::cout << "(m,ten)=" << m << "," << ten << std::endl; + BigRat r(m, ten); + if (prec.isInfty()) { // convert exactly! to a big rational + rep = new RealBigRat(r); + } else { + // convert approximately, to a BigFloat within the + // specified precision: + // BigFloat bf(r, CORE_posInfty, prec * lgTenM) ; + BigFloat bf(r, CORE_posInfty, prec * 4) ; + rep = new RealBigFloat(bf); + } + } +}// Real(str, prec) + +// The operator >>(i,x) calls the constructor Real(char*) +CGAL_INLINE_FUNCTION +std::istream& operator >>(std::istream& i, Real& x) { + int size = 20; + char *str = new char[size]; + char *p = str; + char c; + int d = 0, e = 0, s = 0; + // int done = 0; + + // Chen Li: fixed a bug, the original statement is + // for (i.get(c); c == ' '; i.get(c)); + // use isspace instead of testing c == ' ', since it must also + // skip tab, catridge/return, etc. + // Change to: + // int status; + do { + i.get(c); + } while (!i.eof() && isspace(c)); /* loop if met end-of-file, or + char read in is white-space. */ + // Chen Li, + // original "if (c == EOF) ..." is unsafe since c is of char type and + // EOF is of int tyep with a negative value -1 + + if (i.eof()) { + i.clear(std::ios::eofbit | std::ios::failbit); + delete [] str; + return i; + } + + // the current content in "c" should be the first non-whitespace char + if (c == '-' || c == '+') { + *p++ = c; + i.get(c); + } + + for (; isdigit(c) || (!d && c=='.') || + (!e && c=='e') || (!s && (c=='-' || c=='+')); i.get(c)) { + if (!i) break; + if (!e && (c == '-' || c == '+')) + break; + // Chen Li: put one more rule to prohibite input like + // xxxx.xxxe+xxx.xxx: + if (e && (c == '.')) + break; + if (p - str == size) { + char *t = str; + str = new char[size*2]; + std::memcpy(str, t, size); + delete [] t; + p = str + size; + size *= 2; + } +#ifdef CORE_DEBUG + assert((p-str) < size); +#endif + + *p++ = c; + if (c == '.') + d = 1; + // Chen Li: fix a bug -- the sign of exponent can not happen before + // the character "e" appears! It must follow the "e' actually. + // if (e || c == '-' || c == '+') s = 1; + if (e) + s = 1; + if (c == 'e') + e = 1; + } + + if (!i && !i.eof()) { + delete [] str; + return i; + } + // chenli: make sure that the p is still in the range + if (p - str >= size) { + int len = p - str; + char *t = str; + str = new char[len + 1]; + std::memcpy(str, t, len); + delete [] t; + p = str + len; + } + +#ifdef CORE_DEBUG + assert(p - str < size); +#endif + + *p = '\0'; + i.putback(c); + i.clear(); + // old: x = Real(str, i.precision()); // use precision of input stream. + x = Real(str); // default precision = get_static_defInputDigits() + delete [] str; + return i; +}//operator >> (std::istream&, Real&) + +} //namespace CORE diff --git a/CGAL_Core/include/CGAL/CORE/extLong_impl.h b/CGAL_Core/include/CGAL/CORE/extLong_impl.h new file mode 100644 index 00000000000..238e2164ec0 --- /dev/null +++ b/CGAL_Core/include/CGAL/CORE/extLong_impl.h @@ -0,0 +1,212 @@ +/**************************************************************************** + * Core Library Version 1.7, August 2004 + * Copyright (c) 1995-2004 Exact Computation Project + * All rights reserved. + * + * This file is part of CORE (http://cs.nyu.edu/exact/core/). + * 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. + * + * + * File: extLong.cpp + * Synopsis: + * The class extLong is basically a wrapper around the machine + * type long. It is an important class to provide several + * additional facilities to detect overflows and undefined values. + * Future development includes extensions to level arithmetic + * (i.e., if a number overflows level i, we will go to level i+1). + * Level i representation of a number n is just i iterations + * of log_2 applied to n. + * + * Written by + * Chee Yap + * Chen Li + * Zilin Du + * Sylvain Pion + * + * WWW URL: http://cs.nyu.edu/exact/ + * Email: exact@cs.nyu.edu + * + * $URL$ + * $Id$ + ***************************************************************************/ + +#ifdef CGAL_HEADER_ONLY +#define CGAL_INLINE_FUNCTION inline +#else +#define CGAL_INLINE_FUNCTION +#endif + +#include + +namespace CORE { + +CGAL_INLINE_FUNCTION +const extLong& extLong::getNaNLong() { + static extLong NaNLong(true); + return NaNLong; +} + +CGAL_INLINE_FUNCTION +const extLong& extLong::getPosInfty() { + static extLong posInfty(EXTLONG_MAX); + return posInfty; +} + +CGAL_INLINE_FUNCTION +const extLong& extLong::getNegInfty() { + static extLong negInfty(EXTLONG_MIN); + return negInfty; +} + +CGAL_INLINE_FUNCTION +void extLong::add(extLong& z, long x, long y) { + if (x > 0 && y > 0 && x >= EXTLONG_MAX - y) { + z.val = EXTLONG_MAX; + z.flag = 1; + } else if (x < 0 && y < 0 && x <= EXTLONG_MIN - y) { + z.val = EXTLONG_MIN; + z.flag = -1; + } else { + z.val = x + y; + z.flag = 0; + } +} + +// arithmetic and assignment operators +CGAL_INLINE_FUNCTION +extLong& extLong::operator+= (const extLong& y) { + if (flag == 2 || y.flag == 2 || (flag * y.flag < 0)) { +#ifdef CORE_DEBUG + if (flag * y.flag < 0) //want a message at the first creation of NaN + core_error("extLong NaN Error in addition.", __FILE__, __LINE__, false); +#endif + + *this = CORE_NaNLong; + } else if (flag == 1 || y.flag == 1) { // one of them is +Inf + *this = CORE_posInfty; + } else if (flag == -1 || y.flag == -1) { // one of them is -Inf + *this = CORE_negInfty; + } else { // x and y are normal now + add(*this, val, y.val); + } + return *this; +} + +CGAL_INLINE_FUNCTION +extLong& extLong::operator-= (const extLong& y) { + if (flag == 2 || y.flag == 2 || (flag * y.flag > 0)) { +#ifdef CORE_DEBUG + if (flag * y.flag > 0) //want a message at the first creation of NaN + core_error("extLong NaN Error in subtraction.", __FILE__, __LINE__, false); +#endif + + *this = CORE_NaNLong; + } else if (flag == 1 || y.flag == -1) { + *this = CORE_posInfty; + } else if (flag == -1 || y.flag == 1) { + *this = CORE_negInfty; + } else { + add(*this, val, -y.val); + } + return *this; +} + +CGAL_INLINE_FUNCTION +extLong& extLong::operator*= (const extLong& y) { + if (flag == 2 || y.flag == 2) { + *this = CORE_NaNLong; + } else if ((flag != 0) || (y.flag != 0)) { + if (sign() * y.sign() > 0) + *this = CORE_posInfty; + else + *this = CORE_negInfty; + } else { // flag == 0 and y.flag == 0 + double d = double(val) * double(y.val); + long p = val * y.val; + if (std::fabs(d - p) <= std::fabs(d) * relEps) { + val = p; + flag = 0; + } else if (d > EXTLONG_MAX) { + *this = CORE_posInfty; + } else if (d < EXTLONG_MIN) { + *this = CORE_negInfty; + } else { +#ifdef CORE_DEBUG + core_error("extLong NaN Error in multiplication.",__FILE__,__LINE__,false); +#endif + *this = CORE_NaNLong; + } + } + return *this; +} + +CGAL_INLINE_FUNCTION +extLong& extLong::operator/= (const extLong& y) { + if (flag==2 || y.flag==2 || ((flag != 0) && (y.flag != 0)) || (y.val == 0)) { +#ifdef CORE_DEBUG + if (y.val == 0) + core_error("extLong NaN Error, Divide by Zero.", __FILE__, __LINE__, false); + else if ((flag !=0) && (y.flag !=0)) + core_error("extLong NaN Error, +/-Inf/Inf.", __FILE__, __LINE__, false); +#endif + + *this = CORE_NaNLong; + } else if ((flag != 0) || (y.flag != 0)) { // y.flag == 0 now and y != 0 + if (sign() * y.sign() > 0) + *this = CORE_posInfty; + else + *this = CORE_negInfty; + } else { // flag == 0 and y.flag == 0 + val /= y.val; // no overflow in divisions + flag = 0; + } + return *this; +} + +// unary minus +CGAL_INLINE_FUNCTION +extLong extLong::operator- () const { + if (flag == 0) + return extLong(-val); + else if (flag == 1) + return CORE_negInfty; + else if (flag == -1) + return CORE_posInfty; + else // NaN + return CORE_NaNLong; +} + +// sign +// You should check "flag" before calling this, otherwise +// you cannot interprete the returned value! +CGAL_INLINE_FUNCTION +int extLong::sign() const { + if (flag == 2) + core_error("NaN Sign can not be determined!", __FILE__, __LINE__, false); + return ((val == 0) ? 0 : ((val > 0) ? 1 : -1)); +} + +// stream operators +CGAL_INLINE_FUNCTION +std::ostream& operator<< (std::ostream& o, const extLong& x) { + if (x.flag == 1) + o << " infty "; + else if (x.flag == - 1) + o << " tiny "; + else if (x.flag == 2) + o << " NaN "; + else + o << x.val; + return o; +} + +} //namespace CORE From ff79502a72d287546e0e4d4e79d0e0b7a269ff38 Mon Sep 17 00:00:00 2001 From: Clement Jamin Date: Tue, 16 Dec 2014 11:28:16 +0100 Subject: [PATCH 29/30] In a class, we should using "static" functions --- Kinetic_data_structures/include/CGAL/Tools/Log.h | 4 ++-- Profiling_tools/include/CGAL/Real_timer.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Kinetic_data_structures/include/CGAL/Tools/Log.h b/Kinetic_data_structures/include/CGAL/Tools/Log.h index c8100c3b62f..8d2a155da6b 100644 --- a/Kinetic_data_structures/include/CGAL/Tools/Log.h +++ b/Kinetic_data_structures/include/CGAL/Tools/Log.h @@ -67,7 +67,7 @@ private: #ifdef CGAL_HEADER_ONLY - inline static State& get_static_state() + static State& get_static_state() { static State state_; return state_; @@ -76,7 +76,7 @@ private: #else // CGAL_HEADER_ONLY CGAL_EXPORT static State state_; - inline static State& get_static_state() + static State& get_static_state() { return state_; } diff --git a/Profiling_tools/include/CGAL/Real_timer.h b/Profiling_tools/include/CGAL/Real_timer.h index 06f96b6ac02..4c621cd9114 100644 --- a/Profiling_tools/include/CGAL/Real_timer.h +++ b/Profiling_tools/include/CGAL/Real_timer.h @@ -51,7 +51,7 @@ private: bool running; #ifdef CGAL_HEADER_ONLY - inline bool& get_static_realtimer_m_failed() + static bool& get_static_realtimer_m_failed() { static bool m_failed = false; return m_failed; From d96bdd9d4bab3d0d8a14d7d9cf6fb69a00a1bf42 Mon Sep 17 00:00:00 2001 From: Guillaume Damiand Date: Wed, 17 Dec 2014 14:59:19 +0100 Subject: [PATCH 30/30] According the modifs in master, variables TRANSLATION ROTATION SCALING REFLECTION IDENTITY are always const. --- .../include/CGAL/aff_transformation_tags.h | 10 ++++----- .../CGAL/aff_transformation_tags_impl.h | 22 +++++-------------- 2 files changed, 10 insertions(+), 22 deletions(-) diff --git a/Kernel_23/include/CGAL/aff_transformation_tags.h b/Kernel_23/include/CGAL/aff_transformation_tags.h index ea25f0bf3ab..bfb773acb0d 100644 --- a/Kernel_23/include/CGAL/aff_transformation_tags.h +++ b/Kernel_23/include/CGAL/aff_transformation_tags.h @@ -38,11 +38,11 @@ class Identity_transformation {}; #ifndef CGAL_HEADER_ONLY -CGAL_EXPORT extern Translation TRANSLATION; -CGAL_EXPORT extern Rotation ROTATION; -CGAL_EXPORT extern Scaling SCALING; -CGAL_EXPORT extern Reflection REFLECTION; -CGAL_EXPORT extern Identity_transformation IDENTITY; +CGAL_EXPORT extern const Translation TRANSLATION; +CGAL_EXPORT extern const Rotation ROTATION; +CGAL_EXPORT extern const Scaling SCALING; +CGAL_EXPORT extern const Reflection REFLECTION; +CGAL_EXPORT extern const Identity_transformation IDENTITY; #endif diff --git a/Kernel_23/include/CGAL/aff_transformation_tags_impl.h b/Kernel_23/include/CGAL/aff_transformation_tags_impl.h index 5194c5f4645..d454b445653 100644 --- a/Kernel_23/include/CGAL/aff_transformation_tags_impl.h +++ b/Kernel_23/include/CGAL/aff_transformation_tags_impl.h @@ -24,22 +24,10 @@ namespace CGAL { -#ifdef CGAL_HEADER_ONLY - -const Translation TRANSLATION; -const Rotation ROTATION; -const Scaling SCALING; -const Reflection REFLECTION; -const Identity_transformation IDENTITY; - -#else // CGAL_HEADER_ONLY - -Translation TRANSLATION; -Rotation ROTATION; -Scaling SCALING; -Reflection REFLECTION; -Identity_transformation IDENTITY; - -#endif // CGAL_HEADER_ONLY +const Translation TRANSLATION = Translation(); +const Rotation ROTATION = Rotation(); +const Scaling SCALING = Scaling(); +const Reflection REFLECTION = Reflection(); +const Identity_transformation IDENTITY = Identity_transformation(); } //namespace CGAL