diff --git a/Polyhedron/demo/Polyhedron/Plugins/IO/CMakeLists.txt b/Polyhedron/demo/Polyhedron/Plugins/IO/CMakeLists.txt index 90545c377eb..05e47f73bb4 100644 --- a/Polyhedron/demo/Polyhedron/Plugins/IO/CMakeLists.txt +++ b/Polyhedron/demo/Polyhedron/Plugins/IO/CMakeLists.txt @@ -33,10 +33,7 @@ polyhedron_demo_plugin(surface_mesh_io_plugin Surface_mesh_io_plugin) target_link_libraries(surface_mesh_io_plugin scene_surface_mesh_item scene_polygon_soup_item) polyhedron_demo_plugin(surf_io_plugin Surf_io_plugin) -target_link_libraries(surf_io_plugin scene_polyhedron_item) - -polyhedron_demo_plugin(surf_to_sm_io_plugin Surf_to_sm_io_plugin) -target_link_libraries(surf_to_sm_io_plugin scene_surface_mesh_item) +target_link_libraries(surf_io_plugin scene_polyhedron_item scene_surface_mesh_item) diff --git a/Polyhedron/demo/Polyhedron/Plugins/IO/Surf_io_plugin.cpp b/Polyhedron/demo/Polyhedron/Plugins/IO/Surf_io_plugin.cpp index 0f274e8f610..43f44a90613 100644 --- a/Polyhedron/demo/Polyhedron/Plugins/IO/Surf_io_plugin.cpp +++ b/Polyhedron/demo/Polyhedron/Plugins/IO/Surf_io_plugin.cpp @@ -1,5 +1,6 @@ #include "Scene_polyhedron_item.h" #include "Polyhedron_type.h" +#include "Scene_surface_mesh_item.h" #include #include @@ -43,6 +44,8 @@ public: QString name() const { return "surf_io_plugin"; } QString nameFilters() const { return "Amira files (*.surf)"; } bool canLoad() const{ return true; } + template + CGAL::Three::Scene_item* actual_load(QFileInfo fileinfo); CGAL::Three::Scene_item* load(QFileInfo fileinfo); bool canSave(const CGAL::Three::Scene_item*) { return false; } @@ -52,6 +55,18 @@ public: CGAL::Three::Scene_item* Surf_io_plugin::load(QFileInfo fileinfo) { + if(mw->property("is_polyhedron_mode").toBool()) + return actual_load(fileinfo); + else + return actual_load(fileinfo); +} +template< class FaceGraphItem> +CGAL::Three::Scene_item* Surf_io_plugin::actual_load(QFileInfo fileinfo) +{ + typedef typename FaceGraphItem::Face_graph FaceGraph; + typedef typename boost::property_traits< + typename boost::property_map::type + >::value_type Point_3; // Open file std::ifstream in(fileinfo.filePath().toUtf8()); if(!in) { @@ -59,11 +74,11 @@ CGAL::Three::Scene_item* Surf_io_plugin::load(QFileInfo fileinfo) return NULL; } - std::vector patches; + std::vector patches; std::vector material_data; CGAL::Bbox_3 grid_box; CGAL::cpp11::array grid_size = {{1, 1, 1}}; - boost::container::flat_set duplicated_points; + boost::container::flat_set duplicated_points; read_surf(in, patches, material_data, grid_box, grid_size , std::inserter(duplicated_points, duplicated_points.end())); @@ -82,7 +97,7 @@ CGAL::Three::Scene_item* Surf_io_plugin::load(QFileInfo fileinfo) Scene_group_item* group = new Scene_group_item(fileinfo.completeBaseName()); for(std::size_t i=0; isetName(QString("Patch #%1").arg(i)); patch->setColor(colors_[i]); scene->addItem(patch); diff --git a/Polyhedron/demo/Polyhedron/Plugins/IO/Surf_to_sm_io_plugin.cpp b/Polyhedron/demo/Polyhedron/Plugins/IO/Surf_to_sm_io_plugin.cpp deleted file mode 100644 index 0ad0f37c63d..00000000000 --- a/Polyhedron/demo/Polyhedron/Plugins/IO/Surf_to_sm_io_plugin.cpp +++ /dev/null @@ -1,93 +0,0 @@ -#include "Scene_surface_mesh_item.h" - -#include -#include -#include -#include -#include -#include - -#include - -#include -#include - -#include "Color_map.h" -#include -#include - -using namespace CGAL::Three; -class Surf_io_plugin: - public QObject, - public Polyhedron_demo_io_plugin_interface, - public Polyhedron_demo_plugin_helper -{ - Q_OBJECT - Q_INTERFACES(CGAL::Three::Polyhedron_demo_plugin_interface CGAL::Three::Polyhedron_demo_io_plugin_interface) - Q_PLUGIN_METADATA(IID "com.geometryfactory.PolyhedronDemo.PluginInterface/1.0") - Q_PLUGIN_METADATA(IID "com.geometryfactory.PolyhedronDemo.IOPluginInterface/1.0") - -public: - void init(QMainWindow* mainWindow, - CGAL::Three::Scene_interface* scene_interface, - Messages_interface*) { - //get the references - this->scene = scene_interface; - this->mw = mainWindow; - } - QList actions() const { - return QList(); - } - bool applicable(QAction*) const { return false;} - QString name() const { return "surf_to_sm_io_plugin"; } - QString nameFilters() const { return "Amira files (*.surf)"; } - bool canLoad() const{ return true; } - CGAL::Three::Scene_item* load(QFileInfo fileinfo); - - bool canSave(const CGAL::Three::Scene_item*) { return false; } - bool save(const CGAL::Three::Scene_item*, QFileInfo) { return false; } -}; - - -CGAL::Three::Scene_item* Surf_io_plugin::load(QFileInfo fileinfo) -{ - // Open file - std::ifstream in(fileinfo.filePath().toUtf8()); - if(!in) { - std::cerr << "Error! Cannot open file " << (const char*)fileinfo.filePath().toUtf8() << std::endl; - return NULL; - } - - std::vector patches; - std::vector material_data; - CGAL::Bbox_3 grid_box; - CGAL::cpp11::array grid_size = {{1, 1, 1}}; - boost::container::flat_set duplicated_points; - read_surf(in, patches, material_data, grid_box, grid_size - , std::inserter(duplicated_points, duplicated_points.end())); - - for (std::size_t i = 0; i colors_; - compute_color_map(QColor(100, 100, 255), static_cast(patches.size()), - std::back_inserter(colors_)); - Scene_group_item* group = new Scene_group_item(fileinfo.completeBaseName()); - for(std::size_t i=0; isetName(QString("Patch #%1").arg(i)); - patch->setColor(colors_[i]); - scene->addItem(patch); - scene->changeGroup(patch, group); - } - return group; -} - -#include "Surf_to_sm_io_plugin.moc" diff --git a/Polyhedron/demo/Polyhedron/include/CGAL/IO/read_surf_trianglemesh.h b/Polyhedron/demo/Polyhedron/include/CGAL/IO/read_surf_trianglemesh.h index e0e3b906b11..d8790391422 100644 --- a/Polyhedron/demo/Polyhedron/include/CGAL/IO/read_surf_trianglemesh.h +++ b/Polyhedron/demo/Polyhedron/include/CGAL/IO/read_surf_trianglemesh.h @@ -29,14 +29,15 @@ std::string to_lower_case(const std::string& str) bool get_material_metadata(std::istream& input, std::string& line, - material& _material) + material& _material, + int material_id) { std::istringstream iss; iss.str(line); iss >> _material.second;//name - static int material_id = 0; + //static int material_id = 0; while (std::getline(input, line)) { std::string prop; //property @@ -94,6 +95,7 @@ bool read_surf(std::istream& input, std::vector& output, std::size_t nb_vertices(0); std::vector materials; //ignore header + int material_id = 0; while(std::getline(input, line)) { if (line_starts_with(line, "Materials")) @@ -105,7 +107,7 @@ bool read_surf(std::istream& input, std::vector& output, else { material _material; - if (!get_material_metadata(input, line, _material)) + if (!get_material_metadata(input, line, _material, material_id++)) return false; materials.push_back(_material); }