Subject: CGAL users discussion list
List archive
- From: Benjamin Kehlet <>
- To: cgal-discuss <>
- Subject: [cgal-discuss] 2D Snap rounding
- Date: Fri, 27 Jun 2014 01:58:08 +0200
Hello!
I am attempting to use the 2D snap rounding package to safely get from
exact numbers to float in our mesh generation tool in FEniCS. However,
I get some (to me) unexpected results. Here is a simple example:
When running this simple modification of
examples/Snap_rounding_2/snap_rounding.cpp:
---
#include <CGAL/Cartesian.h>
#include <CGAL/Quotient.h>
#include <CGAL/MP_Float.h>
#include <CGAL/Snap_rounding_traits_2.h>
#include <CGAL/Snap_rounding_2.h>
typedef CGAL::Quotient<CGAL::MP_Float> Number_type;
typedef CGAL::Cartesian<Number_type> Kernel;
typedef CGAL::Snap_rounding_traits_2<Kernel> Traits;
typedef Kernel::Segment_2 Segment_2;
typedef Kernel::Point_2 Point_2;
typedef std::list<Segment_2> Segment_list_2;
typedef std::list<Point_2> Polyline_2;
typedef std::list<Polyline_2> Polyline_list_2;
int main()
{
Segment_list_2 seg_list;
Polyline_list_2 output_list;
seg_list.push_back(Segment_2(Point_2(1, 0), Point_2(0, 0)));
// Generate an iterated snap-rounding representation, where the centers of
// the hot pixels bear their original coordinates, using 5 kd trees:
CGAL::snap_rounding_2<Traits,Segment_list_2::const_iterator,Polyline_list_2>
(seg_list.begin(), seg_list.end(), output_list, .1, true, false, 5);
int counter = 0;
Polyline_list_2::const_iterator iter1;
for (iter1 = output_list.begin(); iter1 != output_list.end(); ++iter1) {
std::cout << "Polyline number " << ++counter << ":\n";
Polyline_2::const_iterator iter2;
for (iter2 = iter1->begin(); iter2 != iter1->end(); ++iter2)
std::cout << " (" << iter2->x() << ":" << iter2->y() << ")\n";
}
return(0);
}
---
I get this result:
benjamik@benjamik-ThinkPad-X300:~/software/CGAL-4.4/examples/Snap_rounding_2/build$
./snap_rounding
Polyline number 1:
(0.1/2:0.1/2)
benjamik@benjamik-ThinkPad-X300:~/software/CGAL-4.4/examples/Snap_rounding_2/build$
So the one segment in the input seems to be "reduced" to a single
point. Is this expected? If the pixel size argument in the call to
CGAL::snap_rounding_2() is changed to "Number_type(1, 10)", then I get
the output that I would expect:
benjamik@benjamik-ThinkPad-X300:~/software/CGAL-4.4/examples/Snap_rounding_2/build$
./snap_rounding
Polyline number 1:
(210/200:10/200)
(10/200:10/200)
benjamik@benjamik-ThinkPad-X300:~/software/CGAL-4.4/examples/Snap_rounding_2/build$
This may be due to my limited knowledge of the
Quotient<CGAL::MP_float> number type, but from the reference manual it
seems that it should be constructable from a double.
This occurs with a debug build of CGAL 4.4. I get the equal results on
a 32-bit Ubuntu 13.10 box with gcc 4.8.1 and with a 64-bit debian
Jessie box with gcc 4.9.0.
Best regards
Benjamin Kehlet
- [cgal-discuss] 2D Snap rounding, Benjamin Kehlet, 06/27/2014
- Re: [cgal-discuss] 2D Snap rounding, Benjamin Kehlet, 06/27/2014
- Re: [cgal-discuss] 2D Snap rounding, Benjamin Kehlet, 06/28/2014
- Re: [cgal-discuss] 2D Snap rounding, Benjamin Kehlet, 06/27/2014
Archive powered by MHonArc 2.6.18.