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

« back to all changes in this revision

Viewing changes to include/CGAL/RS/rs2_calls.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) 2006-2013 INRIA Nancy-Grand Est (France). All rights reserved.
 
2
//
 
3
// This file is part of CGAL (www.cgal.org); you can redistribute it and/or
 
4
// modify it under the terms of the GNU Lesser General Public License as
 
5
// published by the Free Software Foundation; either version 3 of the License,
 
6
// or (at your option) any later version.
 
7
 
 
8
// See the file LICENSE.LGPL distributed with CGAL.
 
9
//
 
10
// Licensees holding a valid commercial license may use this file in
 
11
// accordance with the commercial license agreement provided with the software.
 
12
//
 
13
// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
 
14
// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
 
15
//
 
16
// $URL$
 
17
// $Id$
 
18
//
 
19
// Author: Luis Peñaranda <luis.penaranda@gmx.com>
 
20
 
 
21
#ifndef CGAL_RS_RS2_CALLS_H
 
22
#define CGAL_RS_RS2_CALLS_H
 
23
 
 
24
#include <CGAL/Gmpz.h>
 
25
#include <CGAL/Gmpfr.h>
 
26
#include <CGAL/Gmpfi.h>
 
27
#include <CGAL/Polynomial.h>
 
28
#include <rs_exports.h>
 
29
 
 
30
#ifdef CGAL_RS_OLD_INCLUDES
 
31
#define CGALRS_PTR(a)   long int a
 
32
#else
 
33
#define CGALRS_PTR(a)   void *a
 
34
#endif
 
35
 
 
36
namespace CGAL{
 
37
namespace RS2{
 
38
 
 
39
struct RS2_calls{
 
40
 
 
41
        static void init_solver(){
 
42
                static bool first=true;
 
43
                if(first){
 
44
                        first=false;
 
45
                        rs_init_rs();
 
46
                        rs_reset_all();
 
47
                }else
 
48
                        rs_reset_all();
 
49
        }
 
50
 
 
51
        static void create_rs_upoly(CGAL::Polynomial<CGAL::Gmpz> poly,
 
52
                                    CGALRS_PTR(ident_pol)){
 
53
                CGALRS_PTR(ident_mon);
 
54
                CGALRS_PTR(ident_coeff);
 
55
                rs_import_uppring((char*)"T");
 
56
                for(int i=0;i<=poly.degree();++i)
 
57
                        if(mpz_sgn(poly[i].mpz())){   // don't add if == 0
 
58
                                ident_mon=rs_export_new_mon_upp_bz();
 
59
                                ident_coeff=rs_export_new_gmp();
 
60
                                rs_import_bz_gmp(ident_coeff,
 
61
                                                 TO_RSPTR_IN(&(poly[i].mpz())));
 
62
                                rs_dset_mon_upp_bz(ident_mon,ident_coeff,i);
 
63
                                rs_dappend_list_mon_upp_bz(ident_pol,
 
64
                                                           ident_mon);
 
65
                        }
 
66
        }
 
67
 
 
68
        static int affiche_sols_eqs(mpfi_ptr *x){
 
69
                CGALRS_PTR(ident_sols_eqs);
 
70
                CGALRS_PTR(ident_node);
 
71
                CGALRS_PTR(ident_vect);
 
72
                CGALRS_PTR(ident_elt);
 
73
                int nb_elts;
 
74
                ident_sols_eqs=rs_get_default_sols_eqs();
 
75
                nb_elts=rs_export_list_vect_ibfr_nb(ident_sols_eqs);
 
76
                ident_node=rs_export_list_vect_ibfr_firstnode(ident_sols_eqs);
 
77
                mpfi_t *roots=(mpfi_t*)malloc(nb_elts*sizeof(mpfi_t));
 
78
                for(int i=0;i<nb_elts;++i){
 
79
                        ident_vect=rs_export_list_vect_ibfr_monnode
 
80
                                (ident_node);
 
81
                        CGAL_assertion_msg(rs_export_dim_vect_ibfr
 
82
                                                (ident_vect)==1,
 
83
                                           "vector dimension must be 1");
 
84
                        ident_elt=rs_export_elt_vect_ibfr(ident_vect,0);
 
85
                        mpfi_ptr root_pointer=
 
86
                                (mpfi_ptr)rs_export_ibfr_mpfi(ident_elt);
 
87
                        mpfi_init2(roots[i],mpfi_get_prec(root_pointer));
 
88
                        mpfi_set(roots[i],root_pointer);
 
89
                        x[i]=roots[i];
 
90
                        // This doesn't work because RS relocates the
 
91
                        // mpfrs that form the mpfi. Nevertheless, the
 
92
                        // mpfi address is not changed.
 
93
                        //x[i]=(mpfi_ptr)rs_export_ibfr_mpfi(ident_elt);
 
94
                        ident_node=rs_export_list_vect_ibfr_nextnode
 
95
                                (ident_node);
 
96
                }
 
97
                return nb_elts;
 
98
        }
 
99
 
 
100
        template<class OutputIterator>
 
101
        static OutputIterator insert_roots(OutputIterator x){
 
102
                CGALRS_PTR(ident_sols_eqs);
 
103
                CGALRS_PTR(ident_node);
 
104
                CGALRS_PTR(ident_vect);
 
105
                CGALRS_PTR(ident_elt);
 
106
                int nb_elts;
 
107
                ident_sols_eqs=rs_get_default_sols_eqs();
 
108
                nb_elts=rs_export_list_vect_ibfr_nb(ident_sols_eqs);
 
109
                ident_node=rs_export_list_vect_ibfr_firstnode(ident_sols_eqs);
 
110
                for(int i=0;i<nb_elts;++i){
 
111
                        ident_vect=rs_export_list_vect_ibfr_monnode
 
112
                                (ident_node);
 
113
                        CGAL_assertion_msg(rs_export_dim_vect_ibfr
 
114
                                                (ident_vect)==1,
 
115
                                           "vector dimension must be 1");
 
116
                        ident_elt=rs_export_elt_vect_ibfr(ident_vect,0);
 
117
                        mpfi_ptr root_pointer=
 
118
                                (mpfi_ptr)rs_export_ibfr_mpfi(ident_elt);
 
119
                        mp_prec_t root_prec=mpfi_get_prec(root_pointer);
 
120
                        // Construct Gmpfr's with pointers to endpoints.
 
121
                        Gmpfr left(&(root_pointer->left),root_prec);
 
122
                        Gmpfr right(&(root_pointer->right),root_prec);
 
123
                        // Copy them, to have the data out of RS memory.
 
124
                        *x++=Gmpfi(left,right,root_prec+1);
 
125
                        ident_node=rs_export_list_vect_ibfr_nextnode
 
126
                                (ident_node);
 
127
                }
 
128
                return x;
 
129
        }
 
130
 
 
131
}; // struct RS2_calls
 
132
 
 
133
} // namespace RS2
 
134
} // namespace CGAL
 
135
 
 
136
#endif // CGAL_RS_RS2_CALLS_H