1
// Copyright (c) 2006-2013 INRIA Nancy-Grand Est (France). All rights reserved.
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.
8
// See the file LICENSE.LGPL distributed with CGAL.
10
// Licensees holding a valid commercial license may use this file in
11
// accordance with the commercial license agreement provided with the software.
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.
19
// Author: Luis Peñaranda <luis.penaranda@gmx.com>
21
#ifndef CGAL_RS_RS2_CALLS_H
22
#define CGAL_RS_RS2_CALLS_H
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>
30
#ifdef CGAL_RS_OLD_INCLUDES
31
#define CGALRS_PTR(a) long int a
33
#define CGALRS_PTR(a) void *a
41
static void init_solver(){
42
static bool first=true;
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,
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);
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
81
CGAL_assertion_msg(rs_export_dim_vect_ibfr
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);
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
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);
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
113
CGAL_assertion_msg(rs_export_dim_vect_ibfr
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
131
}; // struct RS2_calls
136
#endif // CGAL_RS_RS2_CALLS_H