Skip to Content.
Sympa Menu

cgal-discuss - Problem with binary io of Polygon_2

Subject: CGAL users discussion list

List archive

Problem with binary io of Polygon_2


Chronological Thread 
  • From:
  • To:
  • Subject: Problem with binary io of Polygon_2
  • Date: Thu, 06 Mar 2008 19:11:06 +0100

I have a problem at reading a Polygon_2 from a binary file.

First I write a polygon to a binary file and then I read a copy of the
polygon from this file and compare them.
Depending on the values of the vertices of the polygon, sometime the
copy is equal and sometimes it's not equal to the original polygon.

When they are not equal, the vertices of the copy are all the same
after a certain index.
I inspected the binary file in a hex-editor and I came to the conclusion
that writing to the binary file will work, but reading fail.

Please, look at my attachments and tell me if this is a bug, or if I
made a mistake.

best Regards

Richard Maierhofer
TU Graz

Attachments:
io_polygon_2_test.cpp: source code of my test program
output.txt: console output of my test program
test.dat: binary file containing the polygon

PS: I use CGAL 3.3.1, with Visual C++ 2005


Attachment: test.dat
Description: Binary data

#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/Polygon_2.h>

struct K : CGAL::Exact_predicates_inexact_constructions_kernel {};

typedef K::Point_2 Point;
typedef CGAL::Polygon_2<K> Polygon;

#include <iostream>
#include <fstream>

using std::endl;
using std::cout;

using std::ofstream;
using std::ifstream;

int _tmain(int argc, _TCHAR* argv[])
{

Polygon p_original;

ofstream out("test.dat");
CGAL::set_binary_mode(out);

for (int i=1; i<51; ++i)
p_original.push_back(Point(1.1,1.0/i));

out << p_original;
out.close();

ifstream in(outfilename.c_str());
CGAL::set_binary_mode(in);

Polygon p_copy;
in >> p_copy;
in.close();

size_t c1 = p_original.size();
size_t c2 = p_copy.size();

bool same_size = (c1==c2);
cout << "same size: " << same_size << endl;

if (same_size)
{
for (int i=0; i<c1; ++i)
{
if (p_original[i] != p_copy[i]) cout << i << ": " <<
p_original[i] << " != " << p_copy[i] << endl;
}
}
return 0;
}same size: 1
28: 1.1 0.0344828 != 1.1 0.0357143
29: 1.1 0.0333333 != 1.1 0.0357143
30: 1.1 0.0322581 != 1.1 0.0357143
31: 1.1 0.03125 != 1.1 0.0357143
32: 1.1 0.030303 != 1.1 0.0357143
33: 1.1 0.0294118 != 1.1 0.0357143
34: 1.1 0.0285714 != 1.1 0.0357143
35: 1.1 0.0277778 != 1.1 0.0357143
36: 1.1 0.027027 != 1.1 0.0357143
37: 1.1 0.0263158 != 1.1 0.0357143
38: 1.1 0.025641 != 1.1 0.0357143
39: 1.1 0.025 != 1.1 0.0357143
40: 1.1 0.0243902 != 1.1 0.0357143
41: 1.1 0.0238095 != 1.1 0.0357143
42: 1.1 0.0232558 != 1.1 0.0357143
43: 1.1 0.0227273 != 1.1 0.0357143
44: 1.1 0.0222222 != 1.1 0.0357143
45: 1.1 0.0217391 != 1.1 0.0357143
46: 1.1 0.0212766 != 1.1 0.0357143
47: 1.1 0.0208333 != 1.1 0.0357143
48: 1.1 0.0204082 != 1.1 0.0357143
49: 1.1 0.02 != 1.1 0.0357143

  • Problem with binary io of Polygon_2, ma . ric, 03/06/2008

Archive powered by MHonArc 2.6.16.

Top of Page