~ubuntu-branches/debian/stretch/cgal/stretch

« back to all changes in this revision

Viewing changes to include/CGAL/RS/isole_1.h

  • Committer: Package Import Robot
  • Author(s): Joachim Reichel
  • Date: 2014-04-05 10:56:43 UTC
  • mfrom: (1.2.4)
  • Revision ID: package-import@ubuntu.com-20140405105643-jgnrpu2thtx23zfs
Tags: 4.4-1
* New upstream release.
* Remove patches do-not-link-example-with-qt4-support-library.patch and
  fix_jet_fitting_3.patch (applied upstream).

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
// Copyright (c) 2011 National and Kapodistrian University of Athens (Greece).
2
 
// All rights reserved.
3
 
//
4
 
// This file is part of CGAL (www.cgal.org); you can redistribute it and/or
5
 
// modify it under the terms of the GNU Lesser General Public License as
6
 
// published by the Free Software Foundation; either version 3 of the License,
7
 
// or (at your option) any later version.
8
 
//
9
 
// Licensees holding a valid commercial license may use this file in
10
 
// accordance with the commercial license agreement provided with the software.
11
 
//
12
 
// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
13
 
// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
14
 
//
15
 
// $URL$
16
 
// $Id$
17
 
//
18
 
// Author: Luis Peñaranda <luis.penaranda@gmx.com>
19
 
 
20
 
#ifndef CGAL_RS_ISOLE_1_H
21
 
#define CGAL_RS_ISOLE_1_H
22
 
 
23
 
#include <CGAL/RS/basic.h>
24
 
#include <CGAL/RS/rs_calls_1.h>
25
 
#include <CGAL/Gmpfi.h>
26
 
#include <vector>
27
 
 
28
 
namespace CGAL{
29
 
 
30
 
namespace RS{
31
 
 
32
 
// CGAL::RS::isolator<P> solves a polynomial of type P and returns a vector
33
 
// of Gmpfi's containing the solutions. Currently, the only implemented
34
 
// isolator solves polynomials of type CGAL::Polynomial<CGAL::Gmpz>.
35
 
 
36
 
template <class PolynomialType>
37
 
struct isolator{
38
 
        typedef PolynomialType          PolynomialT;
39
 
        inline std::vector<Gmpfi>
40
 
        operator()(const PolynomialT&,unsigned int prec=CGAL_RS_DEF_PREC);
41
 
};
42
 
 
43
 
template <class PolynomialType>
44
 
inline std::vector<Gmpfi>
45
 
isolator<PolynomialType>::operator()(const PolynomialType &p,unsigned int prec){
46
 
        CGAL_error_msg(
47
 
                "isolator not implemented for this type of polynomials");
48
 
        return std::vector<Gmpfi>();
49
 
}
50
 
 
51
 
template <>
52
 
inline std::vector<Gmpfi>
53
 
isolator<Polynomial<Gmpz> >::operator()(const Polynomial<Gmpz> &p,
54
 
                                        unsigned int prec){
55
 
        int numsols;
56
 
        unsigned int degree=p.degree();
57
 
        mpz_t *coeffs=(mpz_t*)malloc((degree+1)*sizeof(mpz_t));
58
 
        mpfi_ptr *intervals_mpfi=(mpfi_ptr*)malloc(degree*sizeof(mpfi_ptr));
59
 
        std::vector<Gmpfi> intervals;
60
 
        for(unsigned int i=0;i<=degree;++i)
61
 
                coeffs[i][0]=*(p[i].mpz());
62
 
        init_solver();
63
 
        create_rs_upoly(coeffs,degree,rs_get_default_up());
64
 
        free(coeffs);
65
 
        set_rs_precisol(prec);
66
 
        set_rs_verbose(CGAL_RS_VERB);
67
 
        rs_run_algo(CGALRS_CSTR("UISOLE"));
68
 
        numsols=affiche_sols_eqs(intervals_mpfi);
69
 
        for(int j=0;j<numsols;++j)
70
 
                intervals.push_back(Gmpfi(intervals_mpfi[j]));
71
 
        free(intervals_mpfi);
72
 
        return intervals;
73
 
}
74
 
 
75
 
} // namespace RS
76
 
 
77
 
} // namespace CGAL
78
 
 
79
 
#endif  // CGAL_RS_ISOLE_1_H