From 94a09dc4c11e8bf45b9675d098a724a6edc1236c Mon Sep 17 00:00:00 2001 From: Andreas Fabri Date: Mon, 2 May 2016 16:48:56 +0200 Subject: [PATCH] At least allow to write polyhedral surfaces into .obj files --- .../demo/Polyhedron/Plugins/IO/OFF_io_plugin.cpp | 13 ++++++++++--- .../demo/Polyhedron/Scene_polyhedron_item.cpp | 11 +++++++++++ Polyhedron/demo/Polyhedron/Scene_polyhedron_item.h | 1 + 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/Polyhedron/demo/Polyhedron/Plugins/IO/OFF_io_plugin.cpp b/Polyhedron/demo/Polyhedron/Plugins/IO/OFF_io_plugin.cpp index d2aa7b6a28c..259a3dbf415 100644 --- a/Polyhedron/demo/Polyhedron/Plugins/IO/OFF_io_plugin.cpp +++ b/Polyhedron/demo/Polyhedron/Plugins/IO/OFF_io_plugin.cpp @@ -155,9 +155,16 @@ bool Polyhedron_demo_off_plugin::save(const CGAL::Three::Scene_item* item, QFile std::ofstream out(fileinfo.filePath().toUtf8()); out.precision (std::numeric_limits::digits10 + 2); - return (poly_item && poly_item->save(out)) || - (soup_item && soup_item->save(out)) || - (points_item && points_item->write_off_point_set(out)); + + if(fileinfo.suffix().toLower() == "off"){ + return (poly_item && poly_item->save(out)) || + (soup_item && soup_item->save(out)) || + (points_item && points_item->write_off_point_set(out)); + } + if(fileinfo.suffix().toLower() == "obj"){ + return (poly_item && poly_item->save_obj(out)); + } + return false; } #include "OFF_io_plugin.moc" diff --git a/Polyhedron/demo/Polyhedron/Scene_polyhedron_item.cpp b/Polyhedron/demo/Polyhedron/Scene_polyhedron_item.cpp index f715f405970..7a2d38eae55 100644 --- a/Polyhedron/demo/Polyhedron/Scene_polyhedron_item.cpp +++ b/Polyhedron/demo/Polyhedron/Scene_polyhedron_item.cpp @@ -3,6 +3,8 @@ #include #include "Kernel_type.h" #include +#include +#include #include #include @@ -730,6 +732,15 @@ Scene_polyhedron_item::save(std::ostream& out) const return (bool) out; } +bool +Scene_polyhedron_item::save_obj(std::ostream& out) const +{ + CGAL::File_writer_wavefront writer; + CGAL::generic_print_polyhedron(out, *poly, writer); + return out.good(); +} + + QString Scene_polyhedron_item::toolTip() const { diff --git a/Polyhedron/demo/Polyhedron/Scene_polyhedron_item.h b/Polyhedron/demo/Polyhedron/Scene_polyhedron_item.h index 4763502584e..aa16ea0ed20 100644 --- a/Polyhedron/demo/Polyhedron/Scene_polyhedron_item.h +++ b/Polyhedron/demo/Polyhedron/Scene_polyhedron_item.h @@ -58,6 +58,7 @@ public: bool load(std::istream& in); bool load_obj(std::istream& in); bool save(std::ostream& out) const; + bool save_obj(std::ostream& out) const; // Function for displaying meta-data of the item virtual QString toolTip() const;