From f68eee378c7b8bf5d881c8e20292ea0fd024cb04 Mon Sep 17 00:00:00 2001 From: Maxime Gimeno Date: Tue, 17 Nov 2015 09:47:14 +0100 Subject: [PATCH 1/9] Fix for #46 - Addition of an IO plugin for the c3t3 meshes. The function try_load_other_binary_format() has been commented because it generates a compilation error that I couldn't fix. --- Polyhedron/demo/Polyhedron/C3t3_io_plugin.cpp | 415 ++++++++++++++++++ Polyhedron/demo/Polyhedron/C3t3_type.h | 2 + Polyhedron/demo/Polyhedron/CMakeLists.txt | 4 +- .../demo/Polyhedron/Scene_c3t3_item.cpp | 26 +- Polyhedron/demo/Polyhedron/Scene_c3t3_item.h | 9 + Polyhedron/demo/Polyhedron/c3t3_io_plugin.cpp | 1 + 6 files changed, 455 insertions(+), 2 deletions(-) create mode 100644 Polyhedron/demo/Polyhedron/C3t3_io_plugin.cpp create mode 100644 Polyhedron/demo/Polyhedron/c3t3_io_plugin.cpp diff --git a/Polyhedron/demo/Polyhedron/C3t3_io_plugin.cpp b/Polyhedron/demo/Polyhedron/C3t3_io_plugin.cpp new file mode 100644 index 00000000000..98a563c42cf --- /dev/null +++ b/Polyhedron/demo/Polyhedron/C3t3_io_plugin.cpp @@ -0,0 +1,415 @@ +#include +#include "Scene_c3t3_item.h" + +#include +#include +#include + +class Polyhedron_demo_c3t3_binary_io_plugin : + public QObject, + public CGAL::Three::Polyhedron_demo_io_plugin_interface +{ + Q_OBJECT + Q_INTERFACES(CGAL::Three::Polyhedron_demo_io_plugin_interface) + Q_PLUGIN_METADATA(IID "com.geometryfactory.PolyhedronDemo.PluginInterface/1.0") + +public: + QString name() const { return "C3t3_io_plugin"; } + QString nameFilters() const { return "binary files (*.cgal)"; } + + bool canLoad() const; + Scene_item* load(QFileInfo fileinfo); + + bool canSave(const Scene_item*); + bool save(const Scene_item*, QFileInfo fileinfo); + +private: + bool try_load_other_binary_format(std::istream& in, C3t3& c3t3); + bool try_load_a_cdt_3(std::istream& in, C3t3& c3t3); +}; + + +bool Polyhedron_demo_c3t3_binary_io_plugin::canLoad() const { + return true; +} + + +Scene_item* +Polyhedron_demo_c3t3_binary_io_plugin::load(QFileInfo fileinfo) { + + // Open file + std::ifstream in(fileinfo.filePath().toUtf8(), + std::ios_base::in|std::ios_base::binary); + if(!in) { + std::cerr << "Error! Cannot open file " + << (const char*)fileinfo.filePath().toUtf8() << std::endl; + return NULL; + } + + Scene_c3t3_item* item = new Scene_c3t3_item(); + item->setName(fileinfo.baseName()); + + + if(item->load_binary(in)) { + item->changed(); + return item; + } + + item->c3t3().clear(); + in.seekg(0); + if(try_load_other_binary_format(in, item->c3t3())) { + item->changed(); + return item; + } + + item->c3t3().clear(); + in.seekg(0); + if(try_load_a_cdt_3(in, item->c3t3())) { + item->changed(); + return item; + } + + // if all loading failed... + delete item; + return NULL; +} + +bool Polyhedron_demo_c3t3_binary_io_plugin::canSave(const Scene_item* item) +{ + // This plugin supports c3t3 items. + return qobject_cast(item); +} + +bool +Polyhedron_demo_c3t3_binary_io_plugin:: +save(const Scene_item* item, QFileInfo fileinfo) +{ + if(!fileinfo.filePath().endsWith(".cgal")) + return false; + // This plugin supports polyhedrons and polygon soups + const Scene_c3t3_item* c3t3_item = + qobject_cast(item); + + if(!c3t3_item) + return false; + std::ofstream out(fileinfo.filePath().toUtf8(), + std::ios_base::out|std::ios_base::binary); + + return out && c3t3_item->save_binary(out); +} + +struct Fake_mesh_domain { + typedef CGAL::Tag_true Has_features; + typedef int Subdomain_index; + typedef std::pair Surface_patch_index; + typedef int Curve_segment_index; + typedef int Corner_index; + typedef boost::variant Index; +}; + +typedef Geom_traits Fake_gt; +typedef CGAL::Mesh_vertex_base_3 Fake_vertex_base; +typedef CGAL::Compact_mesh_cell_base_3 Fake_cell_base; +typedef CGAL::Triangulation_data_structure_3 Fake_tds; +typedef CGAL::Regular_triangulation_3 Fake_tr; +typedef CGAL::Mesh_complex_3_in_triangulation_3< + Fake_tr, + Fake_mesh_domain::Corner_index, + Fake_mesh_domain::Curve_segment_index> Fake_c3t3; + +template > +struct Fake_CDT_3_vertex_base : public Vb +{ + typedef Vb Base; + bool steiner; + std::size_t ref_1, ref_2; + + template < typename TDS2 > + struct Rebind_TDS { + typedef typename Base::template Rebind_TDS::Other Vb2; + typedef Fake_CDT_3_vertex_base Other; + }; +}; + +template +std::istream& +operator>>( std::istream& is, Fake_CDT_3_vertex_base& v) +{ + is >> static_cast::Base&>(v); + char s; + if( CGAL::is_ascii(is) ) { + is >> s; + if( s == 'S' ) { + v.steiner = true; + is >> v.ref_1 >> v.ref_2; + } + else { + CGAL_assertion(s == '.' or s == 'F'); + v.steiner = false; + } + } else { + CGAL::read( is, s ); + if(is.bad()) return is; + if( s == 'S' ) { + v.steiner = true; + CGAL::read( is, v.ref_1 ); + CGAL::read( is, v.ref_2 ); + } + else { + // if(s != '.') { + // std::cerr << "v.point()=" << v.point() << std::endl; + // std::cerr << "s=" << s << " (" << (int)s + // << "), just before position " + // << is.tellg() << " !\n"; + // } + CGAL_assertion(s == '.' || s== 'F'); + v.steiner = false; + } + } + return is; +} + +template > +struct Fake_CDT_3_cell_base : public Cb +{ + typedef Cb Base; + int constrained_facet[4]; + bool _restoring[6]; + int to_edge_index( int li, int lj ) const { + CGAL_triangulation_precondition( li >= 0 && li < 4 ); + CGAL_triangulation_precondition( lj >= 0 && lj < 4 ); + CGAL_triangulation_precondition( li != lj ); + return ( li==0 || lj==0 ) ? li+lj-1 : li+lj; + } + + template < typename TDS2 > + struct Rebind_TDS { + typedef typename Base::template Rebind_TDS::Other Cb2; + typedef Fake_CDT_3_cell_base Other; + }; +}; + +template +std::istream& +operator>>( std::istream& is, Fake_CDT_3_cell_base& c) { + char s; + for( int li = 0; li < 4; ++li ) { + if( CGAL::is_ascii(is) ) + is >> c.constrained_facet[li]; + else + CGAL::read( is, c.constrained_facet[li] ); + } + + if( CGAL::is_ascii(is) ) { + is >> s; + CGAL_assertion(s == '-'); + } + is >> static_cast::Base&>(c); + for( int li = 0; li < 3; ++li ) { + for( int lj = li+1; lj < 4; ++lj ) { + char s; + is >> s; + if(s == 'C') { + c._restoring[c.to_edge_index(li, lj)] = true; + } else { + if(s != '.') { + std::cerr << "cDT cell:"; + for( int li = 0; li < 4; ++li ) { + std::cerr << " " << c.constrained_facet[li]; + } + std::cerr << "\n"; + std::cerr << "s=" << s << " (" << (int)s + << "), just before position " + << is.tellg() << " !\n"; } + CGAL_assertion(s == '.'); + c._restoring[c.to_edge_index(li, lj)] = false; + } + } + } + return is; +} + +typedef CGAL::Triangulation_data_structure_3, Fake_CDT_3_cell_base<> > Fake_CDT_3_TDS; +typedef CGAL::Triangulation_3 Fake_CDT_3; + +#ifdef CGAL_MESH_3_IO_SIGNATURE_H +namespace CGAL { +template <> +struct Get_io_signature { + std::string operator()() const + { + return std::string("std::pair"); + } +}; // end Get_io_signature +} // end namespace CGAL +#endif + +/*namespace std { + std::ostream& operator<<(std::ostream& out, const Patch_id& id) { + return out << id; + } + std::istream& operator>>(std::istream& in, Patch_id& id) { + return in >> id; + } +} // end namespace std*/ + +namespace CGAL { +template <> +class Output_rep { + typedef Patch_id T; + const T& t; +public: + //! initialize with a const reference to \a t. + Output_rep( const T& tt) : t(tt) {} + //! perform the output, calls \c operator\<\< by default. + std::ostream& operator()( std::ostream& out) const { + if(is_ascii(out)) { + out << t; + } else { + CGAL::write(out, t); + } + return out; + } +}; + +template <> +class Input_rep { + typedef Patch_id T; + T& t; +public: + //! initialize with a const reference to \a t. + Input_rep( T& tt) : t(tt) {} + //! perform the output, calls \c operator\<\< by default. + std::istream& operator()( std::istream& in) const { + if(is_ascii(in)) { + in >> t; + } else { + CGAL::read(in, t); + } + return in; + } +}; +} // end namespace CGAL + +struct Update_vertex { + typedef Fake_mesh_domain::Surface_patch_index Sp_index; + template + bool operator()(const V1& v1, V2& v2) { + v2.set_point(v1.point()); + v2.set_dimension(v1.in_dimension()); + v2.set_special(v1.is_special()); + switch(v1.in_dimension()) { + case 0: + case 1: + case 3: + v2.set_index(boost::get(v1.index())); + break; + default: // case 2 + const typename V1::Index& index = v1.index(); + const Sp_index sp_index = + boost::get(index); + const int i = (static_cast(sp_index.first) + << (std::numeric_limits::digits >> 1)) + + sp_index.second; + v2.set_index(i); + } + return true; + } +}; // end struct Update_vertex + +struct Update_cell { + typedef Fake_mesh_domain::Surface_patch_index Sp_index; + template + bool operator()(const C1& c1, C2& c2) { + c2.set_subdomain_index(c1.subdomain_index()); + for(int i = 0; i < 4; ++i) { + const Sp_index sp_index = c1.surface_patch_index(i); + const int new_index = (static_cast(sp_index.first) + << (std::numeric_limits::digits >> 1)) + + sp_index.second; + c2.set_surface_patch_index(i, new_index); + } + return true; + } +}; // end struct Update_cell + +#include + +struct Update_vertex_from_CDT_3 { + template + bool operator()(const V1& v1, V2& v2) { + v2.set_point(v1.point()); + v2.set_dimension(2); + v2.set_special(false); + return true; + } +}; // end struct Update_vertex + +struct Update_cell_from_CDT_3 { + typedef Fake_mesh_domain::Surface_patch_index Sp_index; + template + bool operator()(const C1& c1, C2& c2) { + c2.set_subdomain_index(1); + for(int i = 0; i < 4; ++i) { + c2.set_surface_patch_index(i, c1.constrained_facet[i]); + } + return true; + } +}; // end struct Update_cell + +bool +Polyhedron_demo_c3t3_binary_io_plugin:: +try_load_a_cdt_3(std::istream& is, C3t3& c3t3) +{ + std::cerr << "Try load a CDT_3..."; + CGAL::set_binary_mode(is); + if(CGAL::file_input< + Fake_CDT_3, + C3t3::Triangulation, + Update_vertex_from_CDT_3, + Update_cell_from_CDT_3>(is, c3t3.triangulation())) + { + std::cerr << "Try load a CDT_3... DONE"; + return true; + } + else { + return false; + } +} +//Generates a compilation error. +bool +Polyhedron_demo_c3t3_binary_io_plugin:: +try_load_other_binary_format(std::istream& /*is*/, C3t3& /*c3t3*/) +{/* + CGAL::set_ascii_mode(is); + std::string s; + is >> s; + if (s != "binary" || + !(is >> s) || + s != "CGAL" || + !(is >> s) || + s != "c3t3") + { + return false; + } + std::getline(is, s); + if(s != "") { + if(s != std::string(" ") + CGAL::Get_io_signature()()) { + std::cerr << "Polyhedron_demo_c3t3_binary_io_plugin::try_load_other_binary_format:" + << "\n expected format: " << CGAL::Get_io_signature()() + << "\n got format:" << s << std::endl; + return false; + } + } + CGAL::set_binary_mode(is); + std::istream& f_is = CGAL::file_input< + Fake_c3t3::Triangulation, + C3t3::Triangulation, + Update_vertex, + Update_cell>(is, c3t3.triangulation()); + return f_is.good();*/ + return false; +} + +#include +#include "C3t3_io_plugin.moc" diff --git a/Polyhedron/demo/Polyhedron/C3t3_type.h b/Polyhedron/demo/Polyhedron/C3t3_type.h index 38ab09be9e4..68546a03ca6 100644 --- a/Polyhedron/demo/Polyhedron/C3t3_type.h +++ b/Polyhedron/demo/Polyhedron/C3t3_type.h @@ -65,6 +65,8 @@ typedef CGAL::Polyhedron_demo_labeled_mesh_domain_3 Function_me #endif typedef CGAL::Mesh_complex_3_in_triangulation_3 C3t3; +typedef CGAL::Robust_weighted_circumcenter_filtered_traits_3 Geom_traits; + // 3D complex #endif // CGAL_DEMO_MESH_3_C3T3_TYPE_H diff --git a/Polyhedron/demo/Polyhedron/CMakeLists.txt b/Polyhedron/demo/Polyhedron/CMakeLists.txt index 673a1568795..b901bb64cb2 100644 --- a/Polyhedron/demo/Polyhedron/CMakeLists.txt +++ b/Polyhedron/demo/Polyhedron/CMakeLists.txt @@ -126,7 +126,6 @@ if(CGAL_Qt5_FOUND AND Qt5_FOUND AND OPENGL_FOUND AND QGLVIEWER_FOUND) NO_DEFAULT_PATH DOC "Path to CGAL/Three/Viewer_interface.h") hide_variable(CGAL_THREE_VIEWER_INTERFACE_H_PATH) - if(CGAL_THREE_VIEWER_INTERFACE_H_PATH) qt5_generate_moc( "${CGAL_THREE_VIEWER_INTERFACE_H_PATH}/CGAL/Three/Viewer_interface.h" "${CMAKE_CURRENT_BINARY_DIR}/Viewer_interface_moc.cpp" ) @@ -319,6 +318,9 @@ if(CGAL_Qt5_FOUND AND Qt5_FOUND AND OPENGL_FOUND AND QGLVIEWER_FOUND) polyhedron_demo_plugin(nef_io_plugin Polyhedron_demo_io_nef_plugin) target_link_libraries(nef_io_plugin scene_nef_polyhedron_item) + polyhedron_demo_plugin(c3t3_io_plugin C3t3_io_plugin) + target_link_libraries(c3t3_io_plugin scene_c3t3_item) + qt5_wrap_ui( polylines_ioUI_FILES Add_polylines_dialog.ui ) polyhedron_demo_plugin(polylines_io_plugin Polyhedron_demo_polylines_io_plugin ${polylines_ioUI_FILES}) target_link_libraries(polylines_io_plugin scene_polylines_item) diff --git a/Polyhedron/demo/Polyhedron/Scene_c3t3_item.cpp b/Polyhedron/demo/Polyhedron/Scene_c3t3_item.cpp index 080348e65f8..63284d7611e 100644 --- a/Polyhedron/demo/Polyhedron/Scene_c3t3_item.cpp +++ b/Polyhedron/demo/Polyhedron/Scene_c3t3_item.cpp @@ -12,7 +12,6 @@ #include #include #include - #include #include @@ -1060,3 +1059,28 @@ void Scene_c3t3_item::compute_elements() const } +bool Scene_c3t3_item::load_binary(std::istream& is) +{ + if(!CGAL::Mesh_3::load_binary_file(is, c3t3())) return false; + // if(!c3t3().triangulation().is_valid()) std::cerr << "INVALID\n"; + if(is && frame == 0) { + frame = new qglviewer::ManipulatedFrame(); + } + reset_cut_plane(); + if(is.good()) { + changed(); + return true; + } + else + return false; +} + +void +Scene_c3t3_item::reset_cut_plane() { + const Bbox& bbox = this->bbox(); + const float xcenter = static_cast((bbox.xmax+bbox.xmin)/2.); + const float ycenter = static_cast((bbox.ymax+bbox.ymin)/2.); + const float zcenter = static_cast((bbox.zmax+bbox.zmin)/2.); + + frame->setPosition(qglviewer::Vec(xcenter, ycenter, zcenter)); +} diff --git a/Polyhedron/demo/Polyhedron/Scene_c3t3_item.h b/Polyhedron/demo/Polyhedron/Scene_c3t3_item.h index 1087c2710e7..01ef86887b2 100644 --- a/Polyhedron/demo/Polyhedron/Scene_c3t3_item.h +++ b/Polyhedron/demo/Polyhedron/Scene_c3t3_item.h @@ -23,6 +23,7 @@ #include #include #include +#include struct Scene_c3t3_item_priv; @@ -38,6 +39,11 @@ public: Scene_c3t3_item(const C3t3& c3t3); ~Scene_c3t3_item(); + bool save_binary(std::ostream& os) const + { + return CGAL::Mesh_3::save_binary_file(os, c3t3()); + } + void invalidate_buffers() { are_buffers_filled = false; @@ -81,6 +87,8 @@ public: return 0; } + bool load_binary(std::istream& is); + // data item const Scene_item* data_item() const; void set_data_item(const Scene_item* data_item); @@ -96,6 +104,7 @@ public: void draw_edges(CGAL::Three::Viewer_interface* viewer) const; void draw_points(CGAL::Three::Viewer_interface * viewer) const; private: + void reset_cut_plane(); void draw_triangle(const Kernel::Point_3& pa, const Kernel::Point_3& pb, const Kernel::Point_3& pc, bool /* is_cut */) const; diff --git a/Polyhedron/demo/Polyhedron/c3t3_io_plugin.cpp b/Polyhedron/demo/Polyhedron/c3t3_io_plugin.cpp new file mode 100644 index 00000000000..8b137891791 --- /dev/null +++ b/Polyhedron/demo/Polyhedron/c3t3_io_plugin.cpp @@ -0,0 +1 @@ + From 0fd89241967f3149d1ed5f27f02910610a7ec3ef Mon Sep 17 00:00:00 2001 From: Jane Tournois Date: Tue, 17 Nov 2015 14:36:19 +0100 Subject: [PATCH 2/9] avoid duplicating typedef --- Polyhedron/demo/Polyhedron/C3t3_type.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Polyhedron/demo/Polyhedron/C3t3_type.h b/Polyhedron/demo/Polyhedron/C3t3_type.h index 68546a03ca6..e8be6c02511 100644 --- a/Polyhedron/demo/Polyhedron/C3t3_type.h +++ b/Polyhedron/demo/Polyhedron/C3t3_type.h @@ -65,7 +65,7 @@ typedef CGAL::Polyhedron_demo_labeled_mesh_domain_3 Function_me #endif typedef CGAL::Mesh_complex_3_in_triangulation_3 C3t3; -typedef CGAL::Robust_weighted_circumcenter_filtered_traits_3 Geom_traits; +typedef Tr::Geom_traits Geom_traits; // 3D complex From 5f284c032e21d471e917749263638d5695d4dfa7 Mon Sep 17 00:00:00 2001 From: Jane Tournois Date: Tue, 17 Nov 2015 14:42:00 +0100 Subject: [PATCH 3/9] add missing file --- .../include/CGAL/Triangulation_file_input.h | 103 ++++++++++++++++++ 1 file changed, 103 insertions(+) create mode 100644 Polyhedron/demo/Polyhedron/include/CGAL/Triangulation_file_input.h diff --git a/Polyhedron/demo/Polyhedron/include/CGAL/Triangulation_file_input.h b/Polyhedron/demo/Polyhedron/include/CGAL/Triangulation_file_input.h new file mode 100644 index 00000000000..af08e43db88 --- /dev/null +++ b/Polyhedron/demo/Polyhedron/include/CGAL/Triangulation_file_input.h @@ -0,0 +1,103 @@ +// Copyright (c) 1997-2010 INRIA Sophia-Antipolis (France). +// Copyright (c) 2011 GeometryFactory Sarl (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) : Laurent Rineau +// + +// Adapted from operator>>(std::istream&, Triangulation_3&) from +// + +#ifndef CGAL_TRIANGULATION_FILE_INPUT_3_H +#define CGAL_TRIANGULATION_FILE_INPUT_3_H + +#include + +namespace CGAL { + +template +std::istream& file_input(std::istream& is, Tr2 &tr, + Update_vertex update_vertex = Update_vertex(), + Update_cell update_cell = Update_cell()) + // reads + // the dimension + // the number of finite vertices + // the non combinatorial information on vertices (point, etc) + // the number of cells + // the cells by the indices of their vertices in the preceding list + // of vertices, plus the non combinatorial information on each cell + // the neighbors of each cell by their index in the preceding list of cells + // when dimension < 3 : the same with faces of maximal dimension +{ + typedef Tr2 Triangulation; + typedef typename Triangulation::Vertex_handle Vertex_handle; + typedef typename Triangulation::Cell_handle Cell_handle; + + typedef typename Tr1::Vertex Vertex1; + typedef typename Tr1::Cell Cell1; + + tr.clear(); + tr.tds().cells().clear(); + + std::size_t n; + int d; + if(is_ascii(is)) + is >> d >> n; + else { + read(is, d); + read(is, n); + } + if(!is) return is; + tr.tds().set_dimension(d); + + std::map< std::size_t, Vertex_handle > V; + V[0] = tr.infinite_vertex(); + // the infinite vertex is numbered 0 + + for (std::size_t i=1; i <= n; i++) { + V[i] = tr.tds().create_vertex(); + Vertex1 v; + if(!(is >> v)) return is; + if(!update_vertex(v, *V[i])) { + is.setstate(std::ios_base::failbit); + return is; + } + } + + std::map< std::size_t, Cell_handle > C; + + std::size_t m; + tr.tds().read_cells(is, V, m, C); + + for (std::size_t j=0 ; j < m; j++) { + Cell1 c; + if(!(is >> c)) return is; + if(!update_cell(c, *(C[j]))) { + is.setstate(std::ios_base::failbit); + return is; + } + } + + CGAL_triangulation_assertion( tr.is_valid(false) ); + return is; +} + +} // end namespace CGAL + +#endif // CGAL_TRIANGULATION_FILE_INPUT_3_H From c86e52b37accc342ebb176a9238c9d6cdd8e2755 Mon Sep 17 00:00:00 2001 From: Jane Tournois Date: Tue, 17 Nov 2015 15:21:34 +0100 Subject: [PATCH 4/9] Surface_patch_index is an integer for all mesh domains in the Polyhedron demo --- Polyhedron/demo/Polyhedron/C3t3_io_plugin.cpp | 43 ++++++++----------- 1 file changed, 18 insertions(+), 25 deletions(-) diff --git a/Polyhedron/demo/Polyhedron/C3t3_io_plugin.cpp b/Polyhedron/demo/Polyhedron/C3t3_io_plugin.cpp index 98a563c42cf..da7275efabb 100644 --- a/Polyhedron/demo/Polyhedron/C3t3_io_plugin.cpp +++ b/Polyhedron/demo/Polyhedron/C3t3_io_plugin.cpp @@ -101,7 +101,7 @@ save(const Scene_item* item, QFileInfo fileinfo) struct Fake_mesh_domain { typedef CGAL::Tag_true Has_features; typedef int Subdomain_index; - typedef std::pair Surface_patch_index; + typedef int Surface_patch_index; typedef int Curve_segment_index; typedef int Corner_index; typedef boost::variant Index; @@ -232,17 +232,17 @@ operator>>( std::istream& is, Fake_CDT_3_cell_base& c) { typedef CGAL::Triangulation_data_structure_3, Fake_CDT_3_cell_base<> > Fake_CDT_3_TDS; typedef CGAL::Triangulation_3 Fake_CDT_3; -#ifdef CGAL_MESH_3_IO_SIGNATURE_H -namespace CGAL { -template <> -struct Get_io_signature { - std::string operator()() const - { - return std::string("std::pair"); - } -}; // end Get_io_signature -} // end namespace CGAL -#endif +//#ifdef CGAL_MESH_3_IO_SIGNATURE_H +//namespace CGAL { +//template <> +//struct Get_io_signature { +// std::string operator()() const +// { +// return std::string("std::pair"); +// } +//}; // end Get_io_signature +//} // end namespace CGAL +//#endif /*namespace std { std::ostream& operator<<(std::ostream& out, const Patch_id& id) { @@ -306,12 +306,8 @@ struct Update_vertex { break; default: // case 2 const typename V1::Index& index = v1.index(); - const Sp_index sp_index = - boost::get(index); - const int i = (static_cast(sp_index.first) - << (std::numeric_limits::digits >> 1)) - + sp_index.second; - v2.set_index(i); + const Sp_index sp_index = boost::get(index); + v2.set_index(sp_index); } return true; } @@ -324,10 +320,7 @@ struct Update_cell { c2.set_subdomain_index(c1.subdomain_index()); for(int i = 0; i < 4; ++i) { const Sp_index sp_index = c1.surface_patch_index(i); - const int new_index = (static_cast(sp_index.first) - << (std::numeric_limits::digits >> 1)) - + sp_index.second; - c2.set_surface_patch_index(i, new_index); + c2.set_surface_patch_index(i, sp_index); } return true; } @@ -379,8 +372,8 @@ try_load_a_cdt_3(std::istream& is, C3t3& c3t3) //Generates a compilation error. bool Polyhedron_demo_c3t3_binary_io_plugin:: -try_load_other_binary_format(std::istream& /*is*/, C3t3& /*c3t3*/) -{/* +try_load_other_binary_format(std::istream& is, C3t3& c3t3) +{ CGAL::set_ascii_mode(is); std::string s; is >> s; @@ -407,7 +400,7 @@ try_load_other_binary_format(std::istream& /*is*/, C3t3& /*c3t3*/) C3t3::Triangulation, Update_vertex, Update_cell>(is, c3t3.triangulation()); - return f_is.good();*/ + return f_is.good(); return false; } From 625bc56c8afb5fb007a4266377fee07fc0f09af8 Mon Sep 17 00:00:00 2001 From: Jane Tournois Date: Tue, 17 Nov 2015 15:30:18 +0100 Subject: [PATCH 5/9] remove useless comments --- Polyhedron/demo/Polyhedron/C3t3_io_plugin.cpp | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/Polyhedron/demo/Polyhedron/C3t3_io_plugin.cpp b/Polyhedron/demo/Polyhedron/C3t3_io_plugin.cpp index da7275efabb..a88843b6a34 100644 --- a/Polyhedron/demo/Polyhedron/C3t3_io_plugin.cpp +++ b/Polyhedron/demo/Polyhedron/C3t3_io_plugin.cpp @@ -232,18 +232,6 @@ operator>>( std::istream& is, Fake_CDT_3_cell_base& c) { typedef CGAL::Triangulation_data_structure_3, Fake_CDT_3_cell_base<> > Fake_CDT_3_TDS; typedef CGAL::Triangulation_3 Fake_CDT_3; -//#ifdef CGAL_MESH_3_IO_SIGNATURE_H -//namespace CGAL { -//template <> -//struct Get_io_signature { -// std::string operator()() const -// { -// return std::string("std::pair"); -// } -//}; // end Get_io_signature -//} // end namespace CGAL -//#endif - /*namespace std { std::ostream& operator<<(std::ostream& out, const Patch_id& id) { return out << id; From f80603cc9a78ea6bf0a598439317bd99e709306b Mon Sep 17 00:00:00 2001 From: Jane Tournois Date: Tue, 17 Nov 2015 15:30:46 +0100 Subject: [PATCH 6/9] remove extra return statement --- Polyhedron/demo/Polyhedron/C3t3_io_plugin.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Polyhedron/demo/Polyhedron/C3t3_io_plugin.cpp b/Polyhedron/demo/Polyhedron/C3t3_io_plugin.cpp index a88843b6a34..f52273a2646 100644 --- a/Polyhedron/demo/Polyhedron/C3t3_io_plugin.cpp +++ b/Polyhedron/demo/Polyhedron/C3t3_io_plugin.cpp @@ -388,8 +388,8 @@ try_load_other_binary_format(std::istream& is, C3t3& c3t3) C3t3::Triangulation, Update_vertex, Update_cell>(is, c3t3.triangulation()); + return f_is.good(); - return false; } #include From 8df2be4c634a2204557e578c63b8f554c12f4c3e Mon Sep 17 00:00:00 2001 From: Maxime Gimeno Date: Wed, 18 Nov 2015 16:01:54 +0100 Subject: [PATCH 7/9] Addition of the I/O management of the ascii ".mesh" format. - This has been done partially in the scene_c3t3_item. The next step is to move this code in the plugin. --- Polyhedron/demo/Polyhedron/C3t3_io_plugin.cpp | 113 ++++++++++++------ .../demo/Polyhedron/Scene_c3t3_item.cpp | 50 +++++++- Polyhedron/demo/Polyhedron/Scene_c3t3_item.h | 8 ++ 3 files changed, 128 insertions(+), 43 deletions(-) diff --git a/Polyhedron/demo/Polyhedron/C3t3_io_plugin.cpp b/Polyhedron/demo/Polyhedron/C3t3_io_plugin.cpp index f52273a2646..0733d8c205c 100644 --- a/Polyhedron/demo/Polyhedron/C3t3_io_plugin.cpp +++ b/Polyhedron/demo/Polyhedron/C3t3_io_plugin.cpp @@ -15,7 +15,7 @@ class Polyhedron_demo_c3t3_binary_io_plugin : public: QString name() const { return "C3t3_io_plugin"; } - QString nameFilters() const { return "binary files (*.cgal)"; } + QString nameFilters() const { return "binary files (*.cgal);;ascii (*.mesh)"; } bool canLoad() const; Scene_item* load(QFileInfo fileinfo); @@ -37,40 +37,75 @@ bool Polyhedron_demo_c3t3_binary_io_plugin::canLoad() const { Scene_item* Polyhedron_demo_c3t3_binary_io_plugin::load(QFileInfo fileinfo) { - // Open file - std::ifstream in(fileinfo.filePath().toUtf8(), - std::ios_base::in|std::ios_base::binary); - if(!in) { - std::cerr << "Error! Cannot open file " - << (const char*)fileinfo.filePath().toUtf8() << std::endl; - return NULL; - } + if(fileinfo.suffix().toLower() == "mesh") + { + // Open file + std::ifstream in(fileinfo.filePath().toUtf8(), + std::ios_base::in); + if(!in) { + std::cerr << "Error! Cannot open file " + << (const char*)fileinfo.filePath().toUtf8() << std::endl; + return NULL; + } - Scene_c3t3_item* item = new Scene_c3t3_item(); - item->setName(fileinfo.baseName()); + Scene_c3t3_item* item = new Scene_c3t3_item(); + item->setName(fileinfo.baseName()); - if(item->load_binary(in)) { - item->changed(); - return item; - } + if(item->load_ascii(in)) { + item->changed(); + return item; + } + + item->c3t3().clear(); + in.seekg(0); + + item->c3t3().clear(); + in.seekg(0); + if(try_load_a_cdt_3(in, item->c3t3())) { + item->changed(); + return item; + } + } + + else if(fileinfo.suffix().toLower() == "cgal") + { + // Open file + std::ifstream in(fileinfo.filePath().toUtf8(), + std::ios_base::in|std::ios_base::binary); + if(!in) { + std::cerr << "Error! Cannot open file " + << (const char*)fileinfo.filePath().toUtf8() << std::endl; + return NULL; + } + + Scene_c3t3_item* item = new Scene_c3t3_item(); + item->setName(fileinfo.baseName()); + + + if(item->load_binary(in)) { + item->changed(); + return item; + } + + item->c3t3().clear(); + in.seekg(0); + if(try_load_other_binary_format(in, item->c3t3())) { + item->changed(); + return item; + } + + item->c3t3().clear(); + in.seekg(0); + if(try_load_a_cdt_3(in, item->c3t3())) { + item->changed(); + return item; + } + } - item->c3t3().clear(); - in.seekg(0); - if(try_load_other_binary_format(in, item->c3t3())) { - item->changed(); - return item; - } - item->c3t3().clear(); - in.seekg(0); - if(try_load_a_cdt_3(in, item->c3t3())) { - item->changed(); - return item; - } // if all loading failed... - delete item; return NULL; } @@ -84,18 +119,27 @@ bool Polyhedron_demo_c3t3_binary_io_plugin:: save(const Scene_item* item, QFileInfo fileinfo) { - if(!fileinfo.filePath().endsWith(".cgal")) - return false; // This plugin supports polyhedrons and polygon soups const Scene_c3t3_item* c3t3_item = qobject_cast(item); if(!c3t3_item) return false; + if(fileinfo.filePath().endsWith(".cgal")) + { std::ofstream out(fileinfo.filePath().toUtf8(), std::ios_base::out|std::ios_base::binary); return out && c3t3_item->save_binary(out); + } + else if(fileinfo.filePath().endsWith(".mesh")) + { + std::ofstream out(fileinfo.filePath().toUtf8(), + std::ios_base::out); + return out && c3t3_item->save_ascii(out); + } + else + return false; } struct Fake_mesh_domain { @@ -232,15 +276,6 @@ operator>>( std::istream& is, Fake_CDT_3_cell_base& c) { typedef CGAL::Triangulation_data_structure_3, Fake_CDT_3_cell_base<> > Fake_CDT_3_TDS; typedef CGAL::Triangulation_3 Fake_CDT_3; -/*namespace std { - std::ostream& operator<<(std::ostream& out, const Patch_id& id) { - return out << id; - } - std::istream& operator>>(std::istream& in, Patch_id& id) { - return in >> id; - } -} // end namespace std*/ - namespace CGAL { template <> class Output_rep { diff --git a/Polyhedron/demo/Polyhedron/Scene_c3t3_item.cpp b/Polyhedron/demo/Polyhedron/Scene_c3t3_item.cpp index 63284d7611e..2dd0de06f84 100644 --- a/Polyhedron/demo/Polyhedron/Scene_c3t3_item.cpp +++ b/Polyhedron/demo/Polyhedron/Scene_c3t3_item.cpp @@ -47,11 +47,11 @@ void Scene_c3t3_item::compile_shaders() " \n" "void main(void) \n" "{ \n" - " color = vec4(colors,1.0); \n" - " fP = mv_matrix * vertex; \n" - " fN = mat3(mv_matrix)* normals; \n" + " color = vec4(colors,1.0); \n" + " fP = mv_matrix * vertex; \n" + " fN = mat3(mv_matrix)* normals; \n" " gl_Position = mvp_matrix * \n" - " vec4(radius*vertex.x + center.x, radius* vertex.y + center.y, radius*vertex.z + center.z, 1.0) ; \n" + " vec4(radius*vertex.x + center.x, radius* vertex.y + center.y, radius*vertex.z + center.z, 1.0) ; \n" "} \n" }; QOpenGLShader *vertex_shader = new QOpenGLShader(QOpenGLShader::Vertex); @@ -1075,6 +1075,48 @@ bool Scene_c3t3_item::load_binary(std::istream& is) return false; } +bool Scene_c3t3_item::load_ascii(std::istream& is) +{ + + std::string s; + is >> s; + if (s != "ascii" || + !(is >> s) || + s != "CGAL" || + !(is >> s) || + s != "c3t3") + { + return false; + } + std::getline(is, s); + if(s != "") { + if(s != std::string(" ") + CGAL::Get_io_signature()()) { + std::cerr << "load_ascii_file:" + << "\n expected format: " << CGAL::Get_io_signature()() + << "\n got format:" << s << std::endl; + return false; + } + } + CGAL::set_ascii_mode(is); + is >> c3t3(); + // return !!is; + // call operator!() twice, because operator bool() is C++11 + + + if(!(!!is)) return false; + // if(!c3t3().triangulation().is_valid()) std::cerr << "INVALID\n"; + if(is && frame == 0) { + frame = new qglviewer::ManipulatedFrame(); + } + reset_cut_plane(); + if(is.good()) { + changed(); + return true; + } + else + return false; +} + void Scene_c3t3_item::reset_cut_plane() { const Bbox& bbox = this->bbox(); diff --git a/Polyhedron/demo/Polyhedron/Scene_c3t3_item.h b/Polyhedron/demo/Polyhedron/Scene_c3t3_item.h index 01ef86887b2..73f2fd05771 100644 --- a/Polyhedron/demo/Polyhedron/Scene_c3t3_item.h +++ b/Polyhedron/demo/Polyhedron/Scene_c3t3_item.h @@ -43,6 +43,12 @@ public: { return CGAL::Mesh_3::save_binary_file(os, c3t3()); } + bool save_ascii(std::ostream& os) const + { + os << "ascii CGAL c3t3 " << CGAL::Get_io_signature()() << "\n"; + CGAL::set_ascii_mode(os); + return !!(os << c3t3()); + } void invalidate_buffers() { @@ -89,6 +95,8 @@ public: bool load_binary(std::istream& is); + bool load_ascii(std::istream& is); + // data item const Scene_item* data_item() const; void set_data_item(const Scene_item* data_item); From 9fd0dc69d41940a0be05264200c65c36e69ade72 Mon Sep 17 00:00:00 2001 From: Maxime Gimeno Date: Thu, 19 Nov 2015 15:22:53 +0100 Subject: [PATCH 8/9] Implementation - Addition of .mesh and .ma as save format. - The Polyhedron_demo_io_plugin_interface now has a saveNameFilters and a loadNameFilters that both return nameFilters() by default, in case an IO_plugin have diffrent input and output formats. --- Polyhedron/demo/Polyhedron/MainWindow.cpp | 8 +- .../Plugins/Mesh_3_plugin/C3t3_io_plugin.cpp | 413 ++++++++++++++++++ .../demo/Polyhedron/Scene_c3t3_item.cpp | 42 -- Polyhedron/demo/Polyhedron/Scene_c3t3_item.h | 2 - .../Polyhedron_demo_io_plugin_interface.h | 3 + 5 files changed, 420 insertions(+), 48 deletions(-) create mode 100644 Polyhedron/demo/Polyhedron/Plugins/Mesh_3_plugin/C3t3_io_plugin.cpp diff --git a/Polyhedron/demo/Polyhedron/MainWindow.cpp b/Polyhedron/demo/Polyhedron/MainWindow.cpp index b5339c95172..f89275246f2 100644 --- a/Polyhedron/demo/Polyhedron/MainWindow.cpp +++ b/Polyhedron/demo/Polyhedron/MainWindow.cpp @@ -892,7 +892,7 @@ void MainWindow::open(QString filename) Q_FOREACH(CGAL::Three::Polyhedron_demo_io_plugin_interface* io_plugin, io_plugins) { if ( !io_plugin->canLoad() ) continue; all_items << io_plugin->name(); - if ( file_matches_filter(io_plugin->nameFilters(), filename) ) + if ( file_matches_filter(io_plugin->loadNameFilters(), filename) ) selected_items << io_plugin->name(); } } @@ -1275,7 +1275,7 @@ void MainWindow::on_actionLoad_triggered() FilterPluginMap filterPluginMap; Q_FOREACH(CGAL::Three::Polyhedron_demo_io_plugin_interface* plugin, io_plugins) { - QStringList split_filters = plugin->nameFilters().split(";;"); + QStringList split_filters = plugin->loadNameFilters().split(";;"); Q_FOREACH(const QString& filter, split_filters) { FilterPluginMap::iterator it = filterPluginMap.find(filter); if(it != filterPluginMap.end()) { @@ -1346,7 +1346,7 @@ void MainWindow::on_actionSaveAs_triggered() Q_FOREACH(CGAL::Three::Polyhedron_demo_io_plugin_interface* plugin, io_plugins) { if(plugin->canSave(item)) { canSavePlugins << plugin; - filters += plugin->nameFilters(); + filters += plugin->saveNameFilters(); } } filters << tr("All files (*)"); @@ -1373,7 +1373,7 @@ void MainWindow::save(QString filename, CGAL::Three::Scene_item* item) { Q_FOREACH(CGAL::Three::Polyhedron_demo_io_plugin_interface* plugin, io_plugins) { if( plugin->canSave(item) && - file_matches_filter(plugin->nameFilters(),filename) ) + file_matches_filter(plugin->saveNameFilters(),filename) ) { if(plugin->save(item, fileinfo)) break; diff --git a/Polyhedron/demo/Polyhedron/Plugins/Mesh_3_plugin/C3t3_io_plugin.cpp b/Polyhedron/demo/Polyhedron/Plugins/Mesh_3_plugin/C3t3_io_plugin.cpp new file mode 100644 index 00000000000..e1e9a3ba4a7 --- /dev/null +++ b/Polyhedron/demo/Polyhedron/Plugins/Mesh_3_plugin/C3t3_io_plugin.cpp @@ -0,0 +1,413 @@ +#include +#include "Scene_c3t3_item.h" + +#include +#include +#include + +class Polyhedron_demo_c3t3_binary_io_plugin : + public QObject, + public CGAL::Three::Polyhedron_demo_io_plugin_interface +{ + Q_OBJECT + Q_INTERFACES(CGAL::Three::Polyhedron_demo_io_plugin_interface) + Q_PLUGIN_METADATA(IID "com.geometryfactory.PolyhedronDemo.PluginInterface/1.0") + +public: + QString name() const { return "C3t3_io_plugin"; } + QString nameFilters() const { return "binary files (*.cgal);;ascii (*.mesh);;maya (*.ma)"; } + QString saveNameFilters() const { return "binary files (*.cgal);;ascii (*.mesh);;maya (*.ma)"; } + QString loadNameFilters() const { return "binary files (*.cgal)" ; } + + bool canLoad() const; + CGAL::Three::Scene_item* load(QFileInfo fileinfo); + + bool canSave(const CGAL::Three::Scene_item*); + bool save(const CGAL::Three::Scene_item*, QFileInfo fileinfo); + +private: + bool try_load_other_binary_format(std::istream& in, C3t3& c3t3); + bool try_load_a_cdt_3(std::istream& in, C3t3& c3t3); +}; + + +bool Polyhedron_demo_c3t3_binary_io_plugin::canLoad() const { + return true; +} + + +CGAL::Three::Scene_item* +Polyhedron_demo_c3t3_binary_io_plugin::load(QFileInfo fileinfo) { + + + if(fileinfo.suffix().toLower() == "cgal") + { + // Open file + std::ifstream in(fileinfo.filePath().toUtf8(), + std::ios_base::in|std::ios_base::binary); + if(!in) { + std::cerr << "Error! Cannot open file " + << (const char*)fileinfo.filePath().toUtf8() << std::endl; + return NULL; + } + + Scene_c3t3_item* item = new Scene_c3t3_item(); + item->setName(fileinfo.baseName()); + + + if(item->load_binary(in)) { + item->changed(); + return item; + } + + item->c3t3().clear(); + in.seekg(0); + if(try_load_other_binary_format(in, item->c3t3())) { + item->changed(); + return item; + } + + item->c3t3().clear(); + in.seekg(0); + if(try_load_a_cdt_3(in, item->c3t3())) { + item->changed(); + return item; + } + } + + + + // if all loading failed... + return NULL; +} + +bool Polyhedron_demo_c3t3_binary_io_plugin::canSave(const CGAL::Three::Scene_item* item) +{ + // This plugin supports c3t3 items. + return qobject_cast(item); +} + +bool +Polyhedron_demo_c3t3_binary_io_plugin:: +save(const CGAL::Three::Scene_item* item, QFileInfo fileinfo) +{ + const Scene_c3t3_item* c3t3_item = qobject_cast(item); + if ( NULL == c3t3_item ) + { + return false; + } + + QString path = fileinfo.absoluteFilePath(); + + if(path.endsWith(".cgal")) + { + std::ofstream out(fileinfo.filePath().toUtf8(), + std::ios_base::out|std::ios_base::binary); + + return out && c3t3_item->save_binary(out); + } + + else if (fileinfo.suffix() == "mesh") + { + std::ofstream medit_file (qPrintable(path)); + c3t3_item->c3t3().output_to_medit(medit_file,true,true); + return true; + } + else if (fileinfo.suffix() == "ma") + { + std::ofstream maya_file (qPrintable(path)); + c3t3_item->c3t3().output_to_maya( + maya_file,true); + return true; + } + else + return false; +} + +struct Fake_mesh_domain { + typedef CGAL::Tag_true Has_features; + typedef int Subdomain_index; + typedef int Surface_patch_index; + typedef int Curve_segment_index; + typedef int Corner_index; + typedef boost::variant Index; +}; + +typedef Geom_traits Fake_gt; +typedef CGAL::Mesh_vertex_base_3 Fake_vertex_base; +typedef CGAL::Compact_mesh_cell_base_3 Fake_cell_base; +typedef CGAL::Triangulation_data_structure_3 Fake_tds; +typedef CGAL::Regular_triangulation_3 Fake_tr; +typedef CGAL::Mesh_complex_3_in_triangulation_3< + Fake_tr, + Fake_mesh_domain::Corner_index, + Fake_mesh_domain::Curve_segment_index> Fake_c3t3; + +template > +struct Fake_CDT_3_vertex_base : public Vb +{ + typedef Vb Base; + bool steiner; + std::size_t ref_1, ref_2; + + template < typename TDS2 > + struct Rebind_TDS { + typedef typename Base::template Rebind_TDS::Other Vb2; + typedef Fake_CDT_3_vertex_base Other; + }; +}; + +template +std::istream& +operator>>( std::istream& is, Fake_CDT_3_vertex_base& v) +{ + is >> static_cast::Base&>(v); + char s; + if( CGAL::is_ascii(is) ) { + is >> s; + if( s == 'S' ) { + v.steiner = true; + is >> v.ref_1 >> v.ref_2; + } + else { + CGAL_assertion(s == '.' or s == 'F'); + v.steiner = false; + } + } else { + CGAL::read( is, s ); + if(is.bad()) return is; + if( s == 'S' ) { + v.steiner = true; + CGAL::read( is, v.ref_1 ); + CGAL::read( is, v.ref_2 ); + } + else { + // if(s != '.') { + // std::cerr << "v.point()=" << v.point() << std::endl; + // std::cerr << "s=" << s << " (" << (int)s + // << "), just before position " + // << is.tellg() << " !\n"; + // } + CGAL_assertion(s == '.' || s== 'F'); + v.steiner = false; + } + } + return is; +} + +template > +struct Fake_CDT_3_cell_base : public Cb +{ + typedef Cb Base; + int constrained_facet[4]; + bool _restoring[6]; + int to_edge_index( int li, int lj ) const { + CGAL_triangulation_precondition( li >= 0 && li < 4 ); + CGAL_triangulation_precondition( lj >= 0 && lj < 4 ); + CGAL_triangulation_precondition( li != lj ); + return ( li==0 || lj==0 ) ? li+lj-1 : li+lj; + } + + template < typename TDS2 > + struct Rebind_TDS { + typedef typename Base::template Rebind_TDS::Other Cb2; + typedef Fake_CDT_3_cell_base Other; + }; +}; + +template +std::istream& +operator>>( std::istream& is, Fake_CDT_3_cell_base& c) { + char s; + for( int li = 0; li < 4; ++li ) { + if( CGAL::is_ascii(is) ) + is >> c.constrained_facet[li]; + else + CGAL::read( is, c.constrained_facet[li] ); + } + + if( CGAL::is_ascii(is) ) { + is >> s; + CGAL_assertion(s == '-'); + } + is >> static_cast::Base&>(c); + for( int li = 0; li < 3; ++li ) { + for( int lj = li+1; lj < 4; ++lj ) { + char s; + is >> s; + if(s == 'C') { + c._restoring[c.to_edge_index(li, lj)] = true; + } else { + if(s != '.') { + std::cerr << "cDT cell:"; + for( int li = 0; li < 4; ++li ) { + std::cerr << " " << c.constrained_facet[li]; + } + std::cerr << "\n"; + std::cerr << "s=" << s << " (" << (int)s + << "), just before position " + << is.tellg() << " !\n"; } + CGAL_assertion(s == '.'); + c._restoring[c.to_edge_index(li, lj)] = false; + } + } + } + return is; +} + +typedef CGAL::Triangulation_data_structure_3, Fake_CDT_3_cell_base<> > Fake_CDT_3_TDS; +typedef CGAL::Triangulation_3 Fake_CDT_3; + +namespace CGAL { +template <> +class Output_rep { + typedef Patch_id T; + const T& t; +public: + //! initialize with a const reference to \a t. + Output_rep( const T& tt) : t(tt) {} + //! perform the output, calls \c operator\<\< by default. + std::ostream& operator()( std::ostream& out) const { + if(is_ascii(out)) { + out << t; + } else { + CGAL::write(out, t); + } + return out; + } +}; + +template <> +class Input_rep { + typedef Patch_id T; + T& t; +public: + //! initialize with a const reference to \a t. + Input_rep( T& tt) : t(tt) {} + //! perform the output, calls \c operator\<\< by default. + std::istream& operator()( std::istream& in) const { + if(is_ascii(in)) { + in >> t; + } else { + CGAL::read(in, t); + } + return in; + } +}; +} // end namespace CGAL + +struct Update_vertex { + typedef Fake_mesh_domain::Surface_patch_index Sp_index; + template + bool operator()(const V1& v1, V2& v2) { + v2.set_point(v1.point()); + v2.set_dimension(v1.in_dimension()); + v2.set_special(v1.is_special()); + switch(v1.in_dimension()) { + case 0: + case 1: + case 3: + v2.set_index(boost::get(v1.index())); + break; + default: // case 2 + const typename V1::Index& index = v1.index(); + const Sp_index sp_index = boost::get(index); + v2.set_index(sp_index); + } + return true; + } +}; // end struct Update_vertex + +struct Update_cell { + typedef Fake_mesh_domain::Surface_patch_index Sp_index; + template + bool operator()(const C1& c1, C2& c2) { + c2.set_subdomain_index(c1.subdomain_index()); + for(int i = 0; i < 4; ++i) { + const Sp_index sp_index = c1.surface_patch_index(i); + c2.set_surface_patch_index(i, sp_index); + } + return true; + } +}; // end struct Update_cell + +#include + +struct Update_vertex_from_CDT_3 { + template + bool operator()(const V1& v1, V2& v2) { + v2.set_point(v1.point()); + v2.set_dimension(2); + v2.set_special(false); + return true; + } +}; // end struct Update_vertex + +struct Update_cell_from_CDT_3 { + typedef Fake_mesh_domain::Surface_patch_index Sp_index; + template + bool operator()(const C1& c1, C2& c2) { + c2.set_subdomain_index(1); + for(int i = 0; i < 4; ++i) { + c2.set_surface_patch_index(i, c1.constrained_facet[i]); + } + return true; + } +}; // end struct Update_cell + +bool +Polyhedron_demo_c3t3_binary_io_plugin:: +try_load_a_cdt_3(std::istream& is, C3t3& c3t3) +{ + std::cerr << "Try load a CDT_3..."; + CGAL::set_binary_mode(is); + if(CGAL::file_input< + Fake_CDT_3, + C3t3::Triangulation, + Update_vertex_from_CDT_3, + Update_cell_from_CDT_3>(is, c3t3.triangulation())) + { + std::cerr << "Try load a CDT_3... DONE"; + return true; + } + else { + return false; + } +} +//Generates a compilation error. +bool +Polyhedron_demo_c3t3_binary_io_plugin:: +try_load_other_binary_format(std::istream& is, C3t3& c3t3) +{ + CGAL::set_ascii_mode(is); + std::string s; + is >> s; + if (s != "binary" || + !(is >> s) || + s != "CGAL" || + !(is >> s) || + s != "c3t3") + { + return false; + } + std::getline(is, s); + if(s != "") { + if(s != std::string(" ") + CGAL::Get_io_signature()()) { + std::cerr << "Polyhedron_demo_c3t3_binary_io_plugin::try_load_other_binary_format:" + << "\n expected format: " << CGAL::Get_io_signature()() + << "\n got format:" << s << std::endl; + return false; + } + } + CGAL::set_binary_mode(is); + std::istream& f_is = CGAL::file_input< + Fake_c3t3::Triangulation, + C3t3::Triangulation, + Update_vertex, + Update_cell>(is, c3t3.triangulation()); + + return f_is.good(); +} + +#include +#include "C3t3_io_plugin.moc" diff --git a/Polyhedron/demo/Polyhedron/Scene_c3t3_item.cpp b/Polyhedron/demo/Polyhedron/Scene_c3t3_item.cpp index 32c686bf365..5e789dee136 100644 --- a/Polyhedron/demo/Polyhedron/Scene_c3t3_item.cpp +++ b/Polyhedron/demo/Polyhedron/Scene_c3t3_item.cpp @@ -1076,48 +1076,6 @@ bool Scene_c3t3_item::load_binary(std::istream& is) return false; } -bool Scene_c3t3_item::load_ascii(std::istream& is) -{ - - std::string s; - is >> s; - if (s != "ascii" || - !(is >> s) || - s != "CGAL" || - !(is >> s) || - s != "c3t3") - { - return false; - } - std::getline(is, s); - if(s != "") { - if(s != std::string(" ") + CGAL::Get_io_signature()()) { - std::cerr << "load_ascii_file:" - << "\n expected format: " << CGAL::Get_io_signature()() - << "\n got format:" << s << std::endl; - return false; - } - } - CGAL::set_ascii_mode(is); - is >> c3t3(); - // return !!is; - // call operator!() twice, because operator bool() is C++11 - - - if(!(!!is)) return false; - // if(!c3t3().triangulation().is_valid()) std::cerr << "INVALID\n"; - if(is && frame == 0) { - frame = new qglviewer::ManipulatedFrame(); - } - reset_cut_plane(); - if(is.good()) { - changed(); - return true; - } - else - return false; -} - void Scene_c3t3_item::reset_cut_plane() { const Bbox& bbox = this->bbox(); diff --git a/Polyhedron/demo/Polyhedron/Scene_c3t3_item.h b/Polyhedron/demo/Polyhedron/Scene_c3t3_item.h index e0876908aad..3e50295caf5 100644 --- a/Polyhedron/demo/Polyhedron/Scene_c3t3_item.h +++ b/Polyhedron/demo/Polyhedron/Scene_c3t3_item.h @@ -95,8 +95,6 @@ public: bool load_binary(std::istream& is); - bool load_ascii(std::istream& is); - // data item const Scene_item* data_item() const; void set_data_item(const Scene_item* data_item); diff --git a/Three/include/CGAL/Three/Polyhedron_demo_io_plugin_interface.h b/Three/include/CGAL/Three/Polyhedron_demo_io_plugin_interface.h index 0727b21b3b5..dae02d2278c 100644 --- a/Three/include/CGAL/Three/Polyhedron_demo_io_plugin_interface.h +++ b/Three/include/CGAL/Three/Polyhedron_demo_io_plugin_interface.h @@ -42,6 +42,9 @@ public: * Example : to filter OFF files : return "OFF files (*.off)" */ virtual QString nameFilters() const = 0; + virtual QString saveNameFilters() const {return nameFilters();} + virtual QString loadNameFilters() const {return nameFilters();} + //! Specifies if the io_plugin is able to load an item or not. virtual bool canLoad() const = 0; //! Loads an item from a file. From 4878859db1d04053d25eae698f7f7a1a81ab628a Mon Sep 17 00:00:00 2001 From: Maxime Gimeno Date: Mon, 23 Nov 2015 10:14:48 +0100 Subject: [PATCH 9/9] Error fix - replaced 'or' by '||' --- .../demo/Polyhedron/Plugins/Mesh_3_plugin/C3t3_io_plugin.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Polyhedron/demo/Polyhedron/Plugins/Mesh_3_plugin/C3t3_io_plugin.cpp b/Polyhedron/demo/Polyhedron/Plugins/Mesh_3_plugin/C3t3_io_plugin.cpp index e1e9a3ba4a7..f3372eb0a3b 100644 --- a/Polyhedron/demo/Polyhedron/Plugins/Mesh_3_plugin/C3t3_io_plugin.cpp +++ b/Polyhedron/demo/Polyhedron/Plugins/Mesh_3_plugin/C3t3_io_plugin.cpp @@ -170,7 +170,7 @@ operator>>( std::istream& is, Fake_CDT_3_vertex_base& v) is >> v.ref_1 >> v.ref_2; } else { - CGAL_assertion(s == '.' or s == 'F'); + CGAL_assertion(s == '.' || s == 'F'); v.steiner = false; } } else {