Skip to Content.
Sympa Menu

cgal-discuss - Re: [cgal-discuss] Arrangement_2 IO problem

Subject: CGAL users discussion list

List archive

Re: [cgal-discuss] Arrangement_2 IO problem


Chronological Thread 
  • From: David Keller <>
  • To:
  • Subject: Re: [cgal-discuss] Arrangement_2 IO problem
  • Date: Sat, 28 Jun 2008 19:20:57 +0200

Hi,
This seems to be the same bug I posted on 3/28/2008 on this list. Later on, I proposed a solution in the form of a patch which I attach to this message again. Hope it helps, please let me know.

By the way, @Efi Fogel: On 4/17/2008 I pointed out another issue in overlaying arrangements with partially equal curves. Did you in the meanwhile find the time to have a closer look at it? I'm still lost there. Thanks for your help.

Kind regards
David Keller

Paul Neugebauer wrote:
Yes, I think you are right. It is a writing or reading problem. As you can see this is from examples/Arrangement_2/io.cpp but modified. I have marked the little modification. I just try to write the arr2 to a file again. I always get a Segmentation fault (core dumped).

//! \file examples/Arrangement_2/io.cpp
// Using the arrangement I/O operators.

#include "arr_rational_nt.h"
#include <CGAL/Cartesian.h>
#include <CGAL/Arr_segment_traits_2.h>
#include <CGAL/Arrangement_2.h>
#include <CGAL/IO/Arr_iostream.h>
#include <fstream>

#include "point_location_utils.h"

typedef CGAL::Cartesian<Number_type> Kernel;
typedef CGAL::Arr_segment_traits_2<Kernel> Traits_2;
typedef CGAL::Arrangement_2<Traits_2> Arrangement_2;

int main ()
{
// Construct the arrangement.
Arrangement_2 arr;

construct_segments_arr (arr);

std::cout << "Writing an arrangement of size:" << std::endl
<< " V = " << arr.number_of_vertices()
<< ", E = " << arr.number_of_edges()
<< ", F = " << arr.number_of_faces() << std::endl;

// Write the arrangement to a file.
std::ofstream out_file ("arr_ex_io.dat");

out_file << arr;
out_file.close();

// Read the arrangement from the file.
Arrangement_2 arr2;
std::ifstream in_file ("arr_ex_io.dat");

in_file >> arr2;
in_file.close();

std::cout << "Read an arrangement of size:" << std::endl
<< " V = " << arr2.number_of_vertices()
<< ", E = " << arr2.number_of_edges()
<< ", F = " << arr2.number_of_faces() << std::endl;

//+++++++++++++++++++modified +++++++++++++++++++++++++
// Write the arrangement to a file2.
std::ofstream out_file2 ("arr_ex_io2.dat");

std::cout << "still ok" << std::endl;
out_file2 << arr2;
std::cout << "not ok" << std::endl;

out_file2.close();
//+++++++++++++++++++modified +++++++++++++++++++++++++

return (0);
}

I hope this helps!

I use CGAL 3.3-2 from the ubuntu packages.

paul


Efi Fogel schrieb:
It's seems like a bug. Probably in the writing to or reading from a file. Can you confirm?

Paul Neugebauer wrote:
Hi list,

I have got a strange problem with the Arrangement_2 IO. Here is a part of my program:

...
Naive_pl naive_pl(arr);

point_location_query(naive_pl, source);

// Write the arrangement to a file
std::ofstream out_file("output/arr_io.dat");
Formatter formatter;

write(arr, out_file, formatter);
out_file.close();

// Read the arrangement from a file
std::ifstream in_file2("output/arr_io.dat");
Arrangement_2 arr2;

read(arr2, in_file2, formatter);
in_file2.close();
assert(arr2.is_valid());

Naive_pl naive_pl2(arr2);

point_location_query(naive_pl2, source);
...

The ouput is: The point is located inside the UNBOUNDED face
The point is located inside the BOUNDED face

But it is the same point: source
If I use naive_pl for the second point_location_query again, like this:

point_location_query(naive_pl, source);

everything is ok.

Any idea anybody ?

Thanks,
paul





diff -Naur CGAL-3.3.1.orig/include/CGAL/Arr_accessor.h CGAL-3.3.1/include/CGAL/Arr_accessor.h
--- CGAL-3.3.1.orig/include/CGAL/Arr_accessor.h	2007-08-25 21:01:33.000000000 +0200
+++ CGAL-3.3.1/include/CGAL/Arr_accessor.h	2008-04-06 17:34:08.000000000 +0200
@@ -1119,6 +1119,46 @@
   {
     return (p_arr->dcel.new_isolated_vertex());
   }
+
+  /*!
+   * Set the bottom right vertex
+   */
+  void set_bottom_right_fictitious_vertex( Dcel_vertex* vertex )
+  {
+    p_arr->v_br = vertex;
+  }
+
+  /*!
+   * Set the top right vertex
+   */
+  void set_top_right_fictitious_vertex( Dcel_vertex* vertex )
+  {
+    p_arr->v_tr = vertex;
+  }
+
+  /*!
+   * Set the bottom left vertex
+   */
+  void set_bottom_left_fictitious_vertex( Dcel_vertex* vertex )
+  {
+    p_arr->v_bl = vertex;
+  }
+
+  /*!
+   * Set the top left vertex
+   */
+  void set_top_left_fictitious_vertex( Dcel_vertex* vertex )
+  {
+    p_arr->v_tl = vertex;
+  }
+
+  /*! Set the fictitious face of the arrangement. */
+  void set_fictitious_face( Dcel_face* face )
+  {
+    p_arr->un_face = face;
+  }
+
+
   //@}
 };
 
diff -Naur CGAL-3.3.1.orig/include/CGAL/IO/Arrangement_2_reader.h CGAL-3.3.1/include/CGAL/IO/Arrangement_2_reader.h
--- CGAL-3.3.1.orig/include/CGAL/IO/Arrangement_2_reader.h	2007-08-25 21:01:33.000000000 +0200
+++ CGAL-3.3.1/include/CGAL/IO/Arrangement_2_reader.h	2008-04-06 21:05:15.000000000 +0200
@@ -123,6 +123,10 @@
                                                  MINUS_INFINITY);
     v_tr =  m_arr_access.new_vertex_at_infinity (PLUS_INFINITY,
                                                  PLUS_INFINITY);
+    m_arr_access.set_bottom_left_fictitious_vertex( v_bl );
+    m_arr_access.set_top_left_fictitious_vertex( v_tl );
+    m_arr_access.set_bottom_right_fictitious_vertex( v_br );
+    m_arr_access.set_top_right_fictitious_vertex( v_tr );
 
     // Read the DCEL vertices and store them in the vertices vector.
     formatter.read_vertices_begin();
@@ -276,6 +280,10 @@
   void _read_face(Formatter& formatter)
   {
     formatter.read_face_begin();
+  
+    // Read unbounded
+    bool ubd = formatter.read_size ("unbounded" );
+
 
     // Try reading the outer CCB of the face.
     formatter.read_outer_ccb_begin();
@@ -288,6 +296,7 @@
       // Allocate the fictitious DCEL face.
       new_f = m_arr_access.new_face();
       new_f->set_halfedge (NULL);
+      m_arr_access.set_fictitious_face( new_f );
     }
     else
     {
@@ -296,6 +305,7 @@
       he = _read_ccb (formatter, new_f, outer_size, NULL);
       new_f->set_halfedge (he);
     }
+    new_f->set_unbounded( ubd );
     formatter.read_outer_ccb_end();
 
     // Read the holes inside the face.
diff -Naur CGAL-3.3.1.orig/include/CGAL/IO/Arrangement_2_writer.h CGAL-3.3.1/include/CGAL/IO/Arrangement_2_writer.h
--- CGAL-3.3.1.orig/include/CGAL/IO/Arrangement_2_writer.h	2007-08-25 21:01:33.000000000 +0200
+++ CGAL-3.3.1/include/CGAL/IO/Arrangement_2_writer.h	2008-04-06 21:02:45.000000000 +0200
@@ -219,6 +219,9 @@
 
     formatter.write_face_begin();
 
+    // Write unbounded
+    formatter.write_size ("unbounded", static_cast<int>( f->is_unbounded() ) );
+
     // Write the outer CCB.
     formatter.write_outer_ccb_begin();
     if (f->is_fictitious())
diff -Naur CGAL-3.3.1.orig/include/CGAL/IO/Arr_text_formatter.h CGAL-3.3.1/include/CGAL/IO/Arr_text_formatter.h
--- CGAL-3.3.1.orig/include/CGAL/IO/Arr_text_formatter.h	2007-08-25 21:01:33.000000000 +0200
+++ CGAL-3.3.1/include/CGAL/IO/Arr_text_formatter.h	2008-04-06 20:59:36.000000000 +0200
@@ -27,6 +27,7 @@
 
 #include <CGAL/basic.h>
 #include <iostream>
+#include <string>
 
 CGAL_BEGIN_NAMESPACE
 
@@ -391,6 +392,10 @@
     int  val;
 
     in() >> val;
+
+    // ignore blank after value
+    m_in->ignore();
+
     return (val);
   }
 
@@ -479,8 +484,9 @@
   {
     CGAL_assertion (m_in != NULL);
 
-    int     c;
-    while ((c = m_in->get()) != EOF && c != '\n');
+    std::string line;
+    std::getline( *m_in, line );
+
     return;
   }
   
@@ -488,12 +494,15 @@
   void _skip_comments () 
   {
     CGAL_assertion (m_in != NULL);
-
-    int     c;
-    while ((c = m_in->get()) != EOF && c == '#')
-      _skip_until_EOL();
-    m_in->putback (c);
-
+    
+    std::string comment;
+    std::getline( *m_in, comment );
+    if ( comment.empty() )
+      return _skip_comments();
+    int s = comment[0];
+    if ( s == '\n' )
+      return _skip_comments();
+    CGAL_assertion ( s == '#' );
     return;
   }
 



Archive powered by MHonArc 2.6.16.

Top of Page