File: Handle_degeneracy_function_kernel.h

package info (click to toggle)
cgal 4.0-5
  • links: PTS
  • area: main
  • in suites: wheezy
  • size: 65,068 kB
  • sloc: cpp: 500,870; ansic: 102,544; sh: 321; python: 92; makefile: 75; xml: 2
file content (121 lines) | stat: -rw-r--r-- 3,737 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
// 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: svn+ssh://scm.gforge.inria.fr/svn/cgal/branches/next/Kinetic_data_structures/include/CGAL/Kinetic/Handle_degeneracy_function_kernel.h $
// $Id: Handle_degeneracy_function_kernel.h 67093 2012-01-13 11:22:39Z lrineau $
// 
//
// Author(s)     : Daniel Russel <drussel@alumni.princeton.edu>

#ifndef CGAL_KINETIC_ROOT_DEGEN_FK_H
#define CGAL_KINETIC_ROOT_DEGEN_FK_H
#include <CGAL/Kinetic/basic.h>
#include <CGAL/Kinetic/internal/debug_counters.h>

namespace CGAL { namespace Kinetic {


template <class Traits_t, bool SLOPPY>
class HDRS{
  private:
    typedef typename Traits_t::Root_stack Wrapped_solver;
    typedef typename Traits_t::Function Function;

  public:
    typedef typename Wrapped_solver::Root Root;
    typedef Traits_t Traits;
    //! Construct and check preconditions
    /*!

    */
    HDRS(const Function &uf, const Root& lb,
	 const Root& ub, const Traits_t& k): solver_(k.root_stack_object(uf, lb, ub)) {
      CGAL_LOG(Log::LOTS, "Function= " << uf << std::endl);
      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__;
      }
#ifndef NDEBUG
      if (!SLOPPY && k.sign_at_object()(uf, lb) == CGAL::NEGATIVE) {
	CGAL_ERROR( "Invalid certificate constructed for function " << uf << " between " << lb 
			    << " and " << ub << " will fail immediately." << std::endl);
	CGAL_exactness_precondition(k.sign_at_object()(uf, lb) != CGAL::NEGATIVE);
      }
#endif
      if (solver_.empty()) {
	CGAL_LOG(Log::LOTS, "No failure" << std::endl);
	 //sn = k.sign_between_roots_object()(uf, lb, ub);
      } else if (solver_.top() == lb) {
	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__;
	  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);
	  solver_.pop();
	}
      } 
    }

    HDRS(){}

    //! Drop even roots
    const Root& top() const
    {
      return solver_.top();
    }

    void pop() {
      solver_.pop();
    }

    bool empty() const
    {
      return solver_.empty();
    }
  /*double estimate() const {
      return solver_.estimate();
      }*/

    std::ostream &write(std::ostream& out) const {
      out << solver_;
      return out;
    }

  protected:
    Wrapped_solver solver_;
  };

template <class Traits_t, bool SLOPPY>
struct Handle_degeneracy_function_kernel: public Traits_t
{

  typedef HDRS<Traits_t, SLOPPY> Root_stack;

  Root_stack root_stack_object(const typename Traits_t::Function &f,
			       const typename Traits_t::Root &lb,
			       const typename Traits_t::Root &ub) const {
    return Root_stack(f, lb, ub, *this);
  }
};

template <class T, bool SLOPPY>
std::ostream &operator<<(std::ostream &out, const HDRS<T, SLOPPY> &k) {
  return k.write(out);
}

} } //namespace CGAL::Kinetic
#endif