Skip to Content.
Sympa Menu

cgal-discuss - Re: [cgal-discuss] Re: Help: how to load 3D tet mesh from file into c3t3 (sorry if noob)

Subject: CGAL users discussion list

List archive

Re: [cgal-discuss] Re: Help: how to load 3D tet mesh from file into c3t3 (sorry if noob)


Chronological Thread 
  • From: "Laurent Rineau (GeometryFactory)" <>
  • To:
  • Subject: Re: [cgal-discuss] Re: Help: how to load 3D tet mesh from file into c3t3 (sorry if noob)
  • Date: Fri, 2 Apr 2010 17:40:30 +0200
  • Organization: GeometryFactory

Le Vendredi 02 Avril 2010 17:17:24, Ramin H a écrit :
> template < class GT, class Tds >
> std::istream &
> operator>> (std::istream& is, Triangulation_3<GT, Tds> &tr)
>
> in Triangulation_3.h is missing the code that should read those indexes.
>
> but operator<< is writing "the non combinatorial information on the cells".
>
> Is there a patch that I can apply and resolve this issue?

Yes. Sorry I was too busy to handle that today.

Here is a patch from my own copy of Mesh_3, to be applied in the CGAL
installation with the following command line:
patch -p0 < Mesh_3.patch

The patch is made against the (internal) development version CGAL-3.7-I, but
you can probably apply it against CGAL-3.6 as well. If you are not used to
"patch", I can send the patched files instead.

I have tested that patch will binary I/O.

--
Laurent Rineau, PhD
Release Manager of the CGAL Project http://www.cgal.org/
R&D Engineer at GeometryFactory http://www.geometryfactory.com/
Index: include/CGAL/Mesh_cell_base_3.h
===================================================================
--- include/CGAL/Mesh_cell_base_3.h	(revision 55047)
+++ include/CGAL/Mesh_cell_base_3.h	(revision 55048)
@@ -39,11 +39,11 @@
 class Mesh_cell_base_3
 : public Mesh_3::Mesh_surface_cell_base_3<GT, MD, Cb>
 {
-  // Base
-  typedef Mesh_3::Mesh_surface_cell_base_3<GT, MD, Cb> Base;
   typedef typename GT::FT FT;
   
 public:
+  // Base
+  typedef Mesh_3::Mesh_surface_cell_base_3<GT, MD, Cb> Base;
   // Index Type
   typedef typename MD::Subdomain_index Subdomain_index;
   typedef typename MD::Surface_index Surface_index;
@@ -127,7 +127,15 @@
 operator>>(std::istream &is,
            Mesh_cell_base_3<GT, MT, Cb> &c)
 {
-  return is >> static_cast<Cb&>(c);
+  typename Mesh_cell_base_3<GT, MT, Cb>::Subdomain_index index;
+  if(is_ascii(is))
+    is >> index;
+  else
+    read(is, index);
+  typedef typename Mesh_cell_base_3<GT, MT, Cb>::Base Cell_base;
+  is >> static_cast<Cell_base&>(c);
+  if(is) c.set_subdomain_index(index);
+  return is;
 }
 
 template < class GT, class MT, class Cb >
@@ -135,7 +143,12 @@
 operator<<(std::ostream &os,
            const Mesh_cell_base_3<GT, MT, Cb> &c)
 {
-  return os << c.subdomain_index() << static_cast<const Cb&>(c);
+  if(is_ascii(os))
+     os << c.subdomain_index();
+  else
+    write(os, c.subdomain_index());
+  typedef typename Mesh_cell_base_3<GT, MT, Cb>::Base Cell_base;
+  return os << static_cast<const Cell_base&>(c);
 }
 
 }  // end namespace CGAL
Index: include/CGAL/Mesh_complex_3_in_triangulation_3.h
===================================================================
--- include/CGAL/Mesh_complex_3_in_triangulation_3.h	(revision 55047)
+++ include/CGAL/Mesh_complex_3_in_triangulation_3.h	(revision 55048)
@@ -83,6 +83,12 @@
 
   /// Destructor
   ~Mesh_complex_3_in_triangulation_3() { };
+
+  void clear() {
+    number_of_cells_ = 0;
+    number_of_facets_ = 0;
+    tr_.clear();
+  }
   
   /// Assignment operator
   Self& operator=(Self rhs)
@@ -155,10 +161,6 @@
   /// Returns the number of surface facets of the mesh
   size_type number_of_facets() const { return number_of_facets_; }
 
-private:
-  /// The number of surface facets
-  size_type number_of_facets_;
-
   //-------------------------------------------------------
   // MeshComplex_3InTriangulation3 interface
   //-------------------------------------------------------
@@ -399,9 +401,15 @@
                                  Cell_not_in_complex(*this));
   }
 
-
+public:
+  template <typename Tr2>
+  friend
+  std::istream & 
+  operator>> (std::istream& is, 
+              Mesh_complex_3_in_triangulation_3<Tr2> &c3t3);
 private:
   // Private date members
+  size_type number_of_facets_;
   Triangulation tr_;
   size_type number_of_cells_;
 
@@ -440,6 +448,51 @@
   }
 }
 
+template < class Tr>
+std::ostream & 
+operator<< (std::ostream& os, 
+            const Mesh_complex_3_in_triangulation_3<Tr> &c3t3)
+{
+  return os << c3t3.triangulation();
+}
+
+
+template < class Tr>
+std::istream & 
+operator>> (std::istream& is, 
+            Mesh_complex_3_in_triangulation_3<Tr> &c3t3)
+{
+  c3t3.clear();
+  is >> c3t3.triangulation();
+
+  if(!is) {
+    c3t3.clear();
+    return is;
+  }
+
+  for(typename Tr::Finite_facets_iterator 
+        fit = c3t3.triangulation().finite_facets_begin(),
+        end = c3t3.triangulation().finite_facets_end();
+      fit != end; ++fit) 
+  {
+    if ( c3t3.is_in_complex(*fit) ) {
+      ++c3t3.number_of_facets_;
+    }
+  }
+
+  for(typename Tr::Finite_cells_iterator 
+        cit = c3t3.triangulation().finite_cells_begin(),
+        end = c3t3.triangulation().finite_cells_end();
+      cit != end; ++cit) 
+  {
+    if ( c3t3.is_in_complex(cit) ) {
+      ++c3t3.number_of_cells_;
+    }
+  }
+
+  return is;
+}
+
 }  // end namespace CGAL
 
 #endif // CGAL_MESH_COMPLEX_3_IN_TRIANGULATION_3_H
Index: include/CGAL/Mesh_3/Mesh_surface_cell_base_3.h
===================================================================
--- include/CGAL/Mesh_3/Mesh_surface_cell_base_3.h	(revision 55047)
+++ include/CGAL/Mesh_3/Mesh_surface_cell_base_3.h	(revision 55048)
@@ -173,7 +173,42 @@
 
 };  // end class Mesh_surface_cell_base_3
 
+template < class GT, class MT, class Cb >
+inline
+std::istream&
+operator>>(std::istream &is, Mesh_surface_cell_base_3<GT, MT, Cb> &c)
+{
+  typename Mesh_surface_cell_base_3<GT, MT, Cb>::Surface_index index;
+  is >> static_cast<Cb&>(c);
+  for(int i = 0; i < 4; ++i)
+  {
+    if(is_ascii(is))
+      is >> index;
+    else
+    {
+      read(is, index);
+    }
+    c.set_surface_index(i, index);
+  }
+  return is;
+}
 
+template < class GT, class MT, class Cb >
+inline
+std::ostream&
+operator<<(std::ostream &os,
+           const Mesh_surface_cell_base_3<GT, MT, Cb> &c)
+{
+  os << static_cast<const Cb&>(c);
+  for(int i = 0; i < 4; ++i)
+  {
+    if(is_ascii(os))
+      os << ' ' << c.surface_index(i);
+    else
+      write(os, static_cast<int>(c.surface_index(i)));
+  }
+  return os;
+}
 
 
 }  // end namespace Mesh_3



Archive powered by MHonArc 2.6.16.

Top of Page