Subject: CGAL users discussion list
List archive
- From: Andreas Fabri <>
- To:
- Subject: Re: [cgal-discuss] alpha_shape_2 rounding issue
- Date: Tue, 11 Mar 2008 10:56:30 +0100
Hi Murray,
In fact this is not a CGAL issue but a C++ issue. Take the following
program
#include <iostream>
int main()
{
double d= 463540.18;
std::cout << d << std::endl;
std::cout.precision(20);
std::cout << d << std::endl;
return 0;
}
On my machine the output is
463540
463540.17999999999
With the precision method of the stream you can influence how many
digits are displayed.
Another insight might be that 463540.18 is not representable
with double. Welcome in the world of machine precision.
best regards,
andreas
Murray Richardson wrote:
Hi,
I guess that would help! Here are the typdefs I used, from the alpha_shapes2 example and modified a bit to use a triangulation hierarchy. There is probably extra unnecessary code in there but it's fairly foreign to me. The other pertinent code follows that. Again from the CGAL examples, but modified to write output segments to file. Thanks in advance for any advice.
typedef double coord_type;
typedef CGAL::Simple_cartesian<coord_type> SC;
typedef CGAL::Filtered_kernel<SC> K;
typedef K::Point_2 Point;
typedef K::Segment_2 Segment;
typedef CGAL::Alpha_shape_vertex_base_2<K> Avb;
typedef CGAL::Triangulation_hierarchy_vertex_base_2<Avb> Av;
typedef CGAL::Triangulation_face_base_2<K> Tf;
typedef CGAL::Alpha_shape_face_base_2<K,Tf> Af;
typedef CGAL::Triangulation_default_data_structure_2<K,Av,Af> Tds;
typedef CGAL::Delaunay_triangulation_2<K,Tds> Dt;
typedef CGAL::Triangulation_hierarchy_2<Dt> Ht;
typedef CGAL::Alpha_shape_2<Ht> Alpha_shape_2;
typedef Alpha_shape_2::Face Face;
typedef Alpha_shape_2::Vertex Vertex;
typedef Alpha_shape_2::Edge Edge;
typedef Alpha_shape_2::Face_handle Face_handle;
typedef Alpha_shape_2::Vertex_handle Vertex_handle;
typedef Alpha_shape_2::Face_circulator Face_circulator;
typedef Alpha_shape_2::Vertex_circulator Vertex_circulator;
typedef Alpha_shape_2::Locate_type Locate_type;
typedef Alpha_shape_2::Face_iterator Face_iterator;
typedef Alpha_shape_2::Edge_iterator Edge_iterator;
typedef Alpha_shape_2::Edge_circulator Edge_circulator;
typedef Alpha_shape_2::Alpha_iterator Alpha_iterator;
typedef Alpha_shape_2::Alpha_shape_edges_iterator Alpha_shape_edges_iterator;
template <class OutputIterator>
void
alpha_edges( const Alpha_shape_2& A,
OutputIterator out)
{
for(Alpha_shape_edges_iterator it = A.alpha_shape_edges_begin();
it != A.alpha_shape_edges_end();
++it){
*out++ = A.segment(*it);
}
}
template <class OutputIterator>
bool
file_input(OutputIterator out)
{
std::ifstream is("xyz.txt", std::ios::in);
if(is.fail()){
std::cerr << "unable to open file for input" << std::endl;
return false;
}
int n;
is >> n;
std::cout << "Reading " << n << " points from file" << std::endl;
CGAL::copy_n(std::istream_iterator<Point>(is), n, out);
return true;
}
//------------------ main -------------------------------------------
int main()
{
std::list<Point> points;
if(! file_input(std::back_inserter(points))){
return -1;
}
Alpha_shape_2 A(points.begin(), points.end(),
coord_type(10),
Alpha_shape_2::GENERAL);
std::vector<Segment> segments;
alpha_edges( A, std::back_inserter(segments));
std::cout << "Alpha Shape computed" << std::endl;
std::cout << segments.size() << " alpha shape edges" << std::endl;
std::cout << "Optimal alpha: " << *A.find_optimal_alpha(1)<<std::endl;
std::ofstream os("L:\\Rproj\\alphabogs\\xyzsegs.txt");
unsigned int i;
for (i=0; i < segments.size(); i++) {
if (os.is_open()){ os << segments[i] << "\n"; }
else std::cout<<"Unable to open file";
}
os.close();
return 0;
}
Andreas Fabri wrote:
Murray Richardson wrote:
Hello again,
This is probably a very simple question but I am new to CGAL and C++. When I create alpha shapes (Alpha_shape_2) on a set of points in real world UTM coordinates (e.g. sample: 463540.18 5263448.13) the output segments are rounded to the nearest metre (e.g. 463540) and 10 metres (5263450). Is there a simple way to stop this?
Thanks
Murray
Hi Murray,
It might help if you tell us what kernel you use and how your code for IO
looks like.
andreas
- alpha_shape_2 rounding issue, Murray Richardson, 03/10/2008
- Re: [cgal-discuss] alpha_shape_2 rounding issue, Andreas Fabri, 03/10/2008
- Re: [cgal-discuss] alpha_shape_2 rounding issue, Murray Richardson, 03/11/2008
- Re: [cgal-discuss] alpha_shape_2 rounding issue, Andreas Fabri, 03/11/2008
- Re: [cgal-discuss] alpha_shape_2 rounding issue, Murray Richardson, 03/11/2008
- Re: [cgal-discuss] alpha_shape_2 rounding issue, Andreas Fabri, 03/11/2008
- Re: [cgal-discuss] alpha_shape_2 rounding issue, Murray Richardson, 03/11/2008
- Re: [cgal-discuss] alpha_shape_2 rounding issue, Andreas Fabri, 03/10/2008
Archive powered by MHonArc 2.6.16.