From ba53fc3365de319a273b45e63b5d6e1693835692 Mon Sep 17 00:00:00 2001 From: Laurent Rineau Date: Wed, 5 Apr 2006 08:57:15 +0000 Subject: [PATCH] - demo now output an off file, probably non oriented. - Mesh_3/application/off_to_medit.C helps to convert it to a medit file. --- Mesh_3/applications/off_to_medit.C | 4 +- Surface_mesher/changes.txt | 4 + .../Surface_mesher/implicit_surface_mesher.C | 13 +- .../CGAL/Complex_2_in_triangulation_3.h | 18 +- ...n_triangulation_surface_mesh_cell_base_3.h | 168 ------------------ ...Complex_2_in_triangulation_3_file_writer.h | 45 +++-- .../CGAL/Surface_mesher/Surface_mesher.h | 2 +- 7 files changed, 57 insertions(+), 197 deletions(-) delete mode 100644 Surface_mesher/include/CGAL/Complex_2_in_triangulation_surface_mesh_cell_base_3.h diff --git a/Mesh_3/applications/off_to_medit.C b/Mesh_3/applications/off_to_medit.C index d70468c3cf4..66c8d430d64 100644 --- a/Mesh_3/applications/off_to_medit.C +++ b/Mesh_3/applications/off_to_medit.C @@ -62,8 +62,8 @@ int main(int argc, char** argv) if(off) { mesh << (i1 + 1) << " " - << (i2 + 1) << " " - << (i3 + 1) << " 0\n"; + << (i2 + 1) << " " + << (i3 + 1) << " 0\n"; --number_of_faces; } } diff --git a/Surface_mesher/changes.txt b/Surface_mesher/changes.txt index 9d581354a75..62d118a8a8e 100644 --- a/Surface_mesher/changes.txt +++ b/Surface_mesher/changes.txt @@ -1,3 +1,7 @@ +5 April 2006 Laurent Rineau +- demo now output an off file, probably non oriented. +- Mesh_3/application/off_to_medit.C helps to convert it to a medit file. + 29 March 2006 Laurent Rineau - New "#ifdef CGAL_USE_CORE/#endif" around the use of CORE, in test/Surface_mesher/implicit_surface_mesher_test.C diff --git a/Surface_mesher/demo/Surface_mesher/implicit_surface_mesher.C b/Surface_mesher/demo/Surface_mesher/implicit_surface_mesher.C index 442848cece7..8f1df135d0e 100644 --- a/Surface_mesher/demo/Surface_mesher/implicit_surface_mesher.C +++ b/Surface_mesher/demo/Surface_mesher/implicit_surface_mesher.C @@ -3,6 +3,8 @@ #include #include +#include + #include "implicit_functions.h" #include "parameters.h" @@ -199,5 +201,14 @@ int main(int argc, char **argv) { std::cerr << "\nNumber of points after refine_surface(): " << tr.number_of_vertices() << std::endl; - + + std::cerr << "\nWriting " << filename.c_str() << "...\n"; + std::ofstream out(filename.c_str()); + if( !out ) + std::cerr << "Cannot open " << filename.c_str() << "!\n"; + else + { + CGAL::output_surface_facets_to_off(out, c2t3); + std::cerr << "done.\n"; + } } diff --git a/Surface_mesher/include/CGAL/Complex_2_in_triangulation_3.h b/Surface_mesher/include/CGAL/Complex_2_in_triangulation_3.h index 664b5d7904e..584ebbb4d2e 100644 --- a/Surface_mesher/include/CGAL/Complex_2_in_triangulation_3.h +++ b/Surface_mesher/include/CGAL/Complex_2_in_triangulation_3.h @@ -394,7 +394,6 @@ protected: } void set_in_complex (const Cell_handle c, const int i) { - ++m_number_of_facets; Cell_handle c2 = c->neighbor(i); int i2 = c2->index(c); Facet f = canonical_facet(c, i); @@ -403,7 +402,9 @@ protected: // unifying cases dim == 2 ou 3 if (tr.dimension() == 3) { // if not already in the complex - if ( face_status (c, i) == NOT_IN_COMPLEX ) { + if ( face_status (c, i) == NOT_IN_COMPLEX ) + { + ++m_number_of_facets; c->set_facet_on_surface(i,true); c2->set_facet_on_surface(i2,true); @@ -434,7 +435,9 @@ protected: } else if (tr.dimension() == 2) { // if not already in the complex - if ( face_status (c, i) == NOT_IN_COMPLEX ) { + if ( face_status (c, i) == NOT_IN_COMPLEX ) + { + ++m_number_of_facets; c->set_facet_on_surface(i,true); @@ -466,7 +469,6 @@ protected: } void remove_from_complex (const Cell_handle c, const int i) { - --m_number_of_facets; Cell_handle c2 = c->neighbor(i); int i2 = c2->index(c); Facet f = canonical_facet(c, i); @@ -475,7 +477,9 @@ protected: // unifying cases dim == 2 ou 3 if (tr.dimension() == 3) { // if in the complex - if ( face_status (c, i) != NOT_IN_COMPLEX ) { + if ( face_status (c, i) != NOT_IN_COMPLEX ) + { + --m_number_of_facets; c->set_facet_on_surface(i,false); c2->set_facet_on_surface(i2,false); @@ -512,7 +516,9 @@ protected: else if (tr.dimension() == 2){ // if in the complex - if ( face_status (c, i) != NOT_IN_COMPLEX ) { + if ( face_status (c, i) != NOT_IN_COMPLEX ) + { + --m_number_of_facets; c->set_facet_on_surface(i,false); diff --git a/Surface_mesher/include/CGAL/Complex_2_in_triangulation_surface_mesh_cell_base_3.h b/Surface_mesher/include/CGAL/Complex_2_in_triangulation_surface_mesh_cell_base_3.h deleted file mode 100644 index 026009bbc14..00000000000 --- a/Surface_mesher/include/CGAL/Complex_2_in_triangulation_surface_mesh_cell_base_3.h +++ /dev/null @@ -1,168 +0,0 @@ -// Copyright (c) 2003-2005 INRIA Sophia-Antipolis (France). -// All rights reserved. -// -// This file is part of CGAL (www.cgal.org); you may redistribute it under -// the terms of the Q Public License version 1.0. -// See the file LICENSE.QPL distributed with CGAL. -// -// Licensees holding a valid commercial license may use this file in -// accordance with the commercial license agreement provided with the software. -// -// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE -// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. -// -// $URL$ -// $Id$ -// -// -// Author(s) : Steve Oudot, David Rey, Mariette Yvinec, Laurent Rineau, Andreas Fabri - - - - - -#ifndef CGAL_COMPLEX_2_IN_TRIANGULATION_SURFACE_MESH_CELL_BASE_3_H -#define CGAL_COMPLEX_2_IN_TRIANGULATION_SURFACE_MESH_CELL_BASE_3_H - -#include - -namespace CGAL { - - template < class GT, class Cb=Complex_2_in_triangulation_cell_base_3 > - class Complex_2_in_triangulation_surface_mesh_cell_base_3 : - public Cb { - - public: - typedef Complex_2_in_triangulation_surface_mesh_cell_base_3 Self; - - template < class TDS3 > - struct Rebind_TDS { - typedef typename Cb::template Rebind_TDS::Other Cb3; - typedef Complex_2_in_triangulation_surface_mesh_cell_base_3 Other; - }; - - - typedef typename GT::Point_3 Point; - - typedef typename Cb::Triangulation_data_structure Tds; - typedef typename Tds::Vertex_handle Vertex_handle; - typedef typename Tds::Cell_handle Cell_handle; - - - private: - - // Champs ajoutes a la classe - - // Facets - Point tab_surface_center_facets [4]; - bool facet_visited [4]; - bool visits [4]; - - - public: - - // Constructors - - Complex_2_in_triangulation_surface_mesh_cell_base_3() : Cb() { - - facet_visited[0] = facet_visited[1] = facet_visited[2] = - facet_visited[3] = false; - visits[0] = visits[1] = visits[2] = visits[3] = false; - } - - Complex_2_in_triangulation_surface_mesh_cell_base_3 (Vertex_handle v0, - Vertex_handle v1, - Vertex_handle v2, - Vertex_handle v3) : - Cb (v0, v1, v2, v3) { - - facet_visited[0] = facet_visited[1] = facet_visited[2] = - facet_visited[3] = false; - visits[0] = visits[1] = visits[2] = visits[3] = false; - } - - Complex_2_in_triangulation_surface_mesh_cell_base_3 (Vertex_handle v0, - Vertex_handle v1, - Vertex_handle v2, - Vertex_handle v3, - Cell_handle n0, - Cell_handle n1, - Cell_handle n2, - Cell_handle n3) : - Cb (v0, v1, v2, v3, n0, n1, n2, n3) { - - facet_visited[0] = facet_visited[1] = facet_visited[2] = - facet_visited[3] = false; - visits[0] = visits[1] = visits[2] = visits[3] = false; - } - - - - // Access functions - - // Facets - - bool is_facet_visited (const int facet) const { - CGAL_assertion (facet>=0 && facet <4); - return facet_visited[facet]; - } - - bool visited (const int facet) const { - CGAL_assertion (facet>=0 && facet <4); - return visits[facet]; - } - - const Point& get_facet_surface_center(const int facet) const { - CGAL_assertion (facet>=0 && facet <4); - return(tab_surface_center_facets[facet]); - } - - // Setting functions - - // Facets - - void set_facet_visited (const int facet) { - CGAL_assertion (facet>=0 && facet <4); - facet_visited[facet] = true; - } - - void set_visited (const int facet) { - CGAL_assertion (facet>=0 && facet <4); - visits[facet] = true; - } - - void reset_visited (const int facet) { - CGAL_assertion (facet>=0 && facet <4); - visits[facet] = false; - facet_visited [facet] = false; - } - - void set_facet_surface_center(const int facet, - const Point& p) { - CGAL_assertion (facet>=0 && facet <4); - tab_surface_center_facets[facet]=p; - } - - }; // end Complex_2_in_triangulation_surface_mesh_cell_base_3 - -template < class GT, class Cb > -std::istream& -operator>>(std::istream &is, - Complex_2_in_triangulation_surface_mesh_cell_base_3 &v) -{ - return is >> static_cast(v); -} - -template < class GT, class Cb > -std::ostream& -operator<<(std::ostream &os, - const Complex_2_in_triangulation_surface_mesh_cell_base_3 &v) -{ - return os << static_cast(v); -} - -} // namespace CGAL - - -#endif // CGAL_COMPLEX_2_IN_TRIANGULATION_SURFACE_MESH_CELL_BASE_3_H - diff --git a/Surface_mesher/include/CGAL/IO/Complex_2_in_triangulation_3_file_writer.h b/Surface_mesher/include/CGAL/IO/Complex_2_in_triangulation_3_file_writer.h index ecf6ddd6fbe..75ed6f23639 100644 --- a/Surface_mesher/include/CGAL/IO/Complex_2_in_triangulation_3_file_writer.h +++ b/Surface_mesher/include/CGAL/IO/Complex_2_in_triangulation_3_file_writer.h @@ -1,4 +1,4 @@ -// Copyright (c) 2003-2005 INRIA Sophia-Antipolis (France). +// Copyright (c) 2003-2006 INRIA Sophia-Antipolis (France). // All rights reserved. // // This file is part of CGAL (www.cgal.org); you may redistribute it under @@ -15,7 +15,7 @@ // $Id$ // // -// Author(s) : Steve OUDOT +// Author(s) : Steve Oudot, Laurent Rineau #ifndef CGAL_IO_COMPLEX_2_IN_TRIANGULATION_3_FILE_WRITER_H @@ -37,9 +37,11 @@ int number_of_facets_on_surface(const Tr& T) { } -template < class Tr> +template void -output_surface_facets_to_off (std::ostream& os, const Tr & T) { +output_surface_facets_to_off (std::ostream& os, const C2t3& c2t3) +{ + typedef typename C2t3::Triangulation Tr; typedef typename Tr::Finite_facets_iterator Finite_facets_iterator; typedef typename Tr::Finite_vertices_iterator Finite_vertices_iterator; typedef typename Tr::Vertex_handle Vertex_handle; @@ -47,36 +49,41 @@ output_surface_facets_to_off (std::ostream& os, const Tr & T) { // Header. + const Tr& tr = c2t3.triangulation(); os << "OFF \n" - << T.number_of_vertices() << " " << - number_of_facets_on_surface (T) << - " " << 0 << "\n"; + << tr.number_of_vertices() << " " + << c2t3.number_of_facets() + << " " << 0 << "\n"; + + CGAL_assertion(c2t3.number_of_facets() == number_of_facets_on_surface(tr)); os << std::setprecision(20); // Finite vertices coordinates. std::map V; int inum = 0; - for( Finite_vertices_iterator - vit = T.finite_vertices_begin(); vit != T.finite_vertices_end(); ++vit) { + for(Finite_vertices_iterator vit = tr.finite_vertices_begin(); + vit != tr.finite_vertices_end(); + ++vit) + { V[vit] = inum++; Point p = static_cast(vit->point()); os << p.x() << " " << p.y() << " " << p.z() << "\n"; } // Finite facets indices. - for( Finite_facets_iterator fit = T.finite_facets_begin(); - fit != T.finite_facets_end(); ++fit) + for( Finite_facets_iterator fit = tr.finite_facets_begin(); + fit != tr.finite_facets_end(); ++fit) if ((*fit).first->is_facet_on_surface((*fit).second)==true) - { - os << "3 "; - for (int i=0; i<4; i++) - if (i != (*fit).second) - os << V[(*fit).first->vertex(i)] << " "; - - os << "\n"; // without color. - } + { + os << "3 "; + for (int i=0; i<4; i++) + if (i != (*fit).second) + os << V[(*fit).first->vertex(i)] << " "; + + os << "\n"; // without color. + } } // only if cells have is_in_domain() method. diff --git a/Surface_mesher/include/CGAL/Surface_mesher/Surface_mesher.h b/Surface_mesher/include/CGAL/Surface_mesher/Surface_mesher.h index d57e9935cba..0e9290044de 100644 --- a/Surface_mesher/include/CGAL/Surface_mesher/Surface_mesher.h +++ b/Surface_mesher/include/CGAL/Surface_mesher/Surface_mesher.h @@ -520,7 +520,7 @@ namespace CGAL { // Tests whether a given facet is restricted or not bool is_facet_on_surface(const Facet& f, Point& center, - const bool check_visits = false) { + const bool check_visits = true) { typedef typename Surface_mesh_traits::Intersect_3 Intersect_3; Intersect_3 intersect = meshtraits.intersect_3_object();