diff --git a/Surface_reconstruction_points_3/demo/Surface_reconstruction_points_3/Point_set_demo/CMakeLists.txt b/Surface_reconstruction_points_3/demo/Surface_reconstruction_points_3/Point_set_demo/CMakeLists.txt index df43594a2d1..109d253c72e 100644 --- a/Surface_reconstruction_points_3/demo/Surface_reconstruction_points_3/Point_set_demo/CMakeLists.txt +++ b/Surface_reconstruction_points_3/demo/Surface_reconstruction_points_3/Point_set_demo/CMakeLists.txt @@ -175,6 +175,9 @@ if(CGAL_Qt4_FOUND AND QT4_FOUND AND OPENGL_FOUND AND QGLVIEWER_FOUND) polyhedron_demo_plugin(off_plugin Point_set_demo_off_plugin) target_link_libraries(off_plugin scene_polyhedron_item point_set) + polyhedron_demo_plugin(xyz_plugin Point_set_demo_xyz_plugin) + target_link_libraries(xyz_plugin scene_polyhedron_item point_set) + polyhedron_demo_plugin(convex_hull_plugin Point_set_demo_convex_hull_plugin) target_link_libraries(convex_hull_plugin scene_polyhedron_item) diff --git a/Surface_reconstruction_points_3/demo/Surface_reconstruction_points_3/Point_set_demo/Point_set_demo_off_plugin.cpp b/Surface_reconstruction_points_3/demo/Surface_reconstruction_points_3/Point_set_demo/Point_set_demo_off_plugin.cpp index ec069b248ce..5ac482f1ef1 100644 --- a/Surface_reconstruction_points_3/demo/Surface_reconstruction_points_3/Point_set_demo/Point_set_demo_off_plugin.cpp +++ b/Surface_reconstruction_points_3/demo/Surface_reconstruction_points_3/Point_set_demo/Point_set_demo_off_plugin.cpp @@ -35,8 +35,10 @@ Point_set_demo_off_plugin::load(QFileInfo fileinfo) { // Open file std::ifstream in(fileinfo.filePath().toUtf8()); - if(!in) - std::cerr << "Error!\n"; + if(!in) { + std::cerr << "Error! Cannot open file " << (const char*)fileinfo.filePath().toUtf8() << std::endl; + return NULL; + } // Try to read .off in a polyhedron Scene_polyhedron_item* item = new Scene_polyhedron_item(); diff --git a/Surface_reconstruction_points_3/demo/Surface_reconstruction_points_3/Point_set_demo/Point_set_demo_xyz_plugin.cpp b/Surface_reconstruction_points_3/demo/Surface_reconstruction_points_3/Point_set_demo/Point_set_demo_xyz_plugin.cpp new file mode 100644 index 00000000000..5dbe42cea35 --- /dev/null +++ b/Surface_reconstruction_points_3/demo/Surface_reconstruction_points_3/Point_set_demo/Point_set_demo_xyz_plugin.cpp @@ -0,0 +1,74 @@ +#include "Point_set_scene_item.h" +#include "Point_set_demo_types.h" + +#include "Polyhedron_demo_io_plugin_interface.h" +#include + +class Point_set_demo_xyz_plugin : + public QObject, + public Polyhedron_demo_io_plugin_interface +{ + Q_OBJECT + Q_INTERFACES(Polyhedron_demo_io_plugin_interface); + +public: + QStringList nameFilters() const; + bool canLoad() const; + Scene_item* load(QFileInfo fileinfo); + + bool canSave(const Scene_item*); + bool save(const Scene_item*, QFileInfo fileinfo); +}; + +QStringList Point_set_demo_xyz_plugin::nameFilters() const { + return QStringList() << "XYZ files (*.xyz)" + << "Point Sets with Normal (*.pwn)"; +}; + +bool Point_set_demo_xyz_plugin::canLoad() const { + return true; +} + + +Scene_item* +Point_set_demo_xyz_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; + } + + // Try to read .xyz in a point set + Point_set_scene_item* point_set_item = new Point_set_scene_item; + point_set_item->setName(fileinfo.baseName()); + if(!point_set_item->read_xyz_point_set(in)) { + delete point_set_item; + return NULL; + } + return point_set_item; +} + +bool Point_set_demo_xyz_plugin::canSave(const Scene_item* item) +{ + // This plugin supports point sets + return qobject_cast(item); +} + +bool Point_set_demo_xyz_plugin::save(const Scene_item* item, QFileInfo fileinfo) +{ + // This plugin supports point sets + const Point_set_scene_item* point_set_item = + qobject_cast(item); + if(!point_set_item) + return false; + + std::ofstream out(fileinfo.filePath().toUtf8()); + + return point_set_item->write_xyz_point_set(out); +} + +#include +Q_EXPORT_PLUGIN2(Point_set_demo_xyz_plugin, Point_set_demo_xyz_plugin); +#include "Point_set_demo_xyz_plugin.moc" diff --git a/Surface_reconstruction_points_3/demo/Surface_reconstruction_points_3/Point_set_demo/Point_set_scene_item.cpp b/Surface_reconstruction_points_3/demo/Surface_reconstruction_points_3/Point_set_demo/Point_set_scene_item.cpp index eab364216ff..e6c7559357f 100644 --- a/Surface_reconstruction_points_3/demo/Surface_reconstruction_points_3/Point_set_demo/Point_set_scene_item.cpp +++ b/Surface_reconstruction_points_3/demo/Surface_reconstruction_points_3/Point_set_demo/Point_set_scene_item.cpp @@ -38,31 +38,39 @@ Point_set_scene_item::clone() const } // Load point set from .OFF file -bool Point_set_scene_item::read_off_point_set(std::istream& stream) +bool +Point_set_scene_item::read_off_point_set(std::istream& in) { m_points.clear(); - return CGAL::read_off_point_set(stream, std::back_inserter(m_points)); + return in && + CGAL::read_off_point_set(in, std::back_inserter(m_points)) && + !isEmpty(); } // Write point set to .OFF file -bool Point_set_scene_item::write_off_point_set(std::ostream& stream) const +bool +Point_set_scene_item::write_off_point_set(std::ostream& out) const { - return stream && - CGAL::write_off_point_set(stream, m_points.begin(), m_points.end()); + return out && !isEmpty() && + CGAL::write_off_point_set(out, m_points.begin(), m_points.end()); } // Load point set from .XYZ file -bool Point_set_scene_item::read_xyz_point_set(std::istream& stream) +bool +Point_set_scene_item::read_xyz_point_set(std::istream& in) { m_points.clear(); - return CGAL::read_xyz_point_set(stream, std::back_inserter(m_points)); + return in && + CGAL::read_xyz_point_set(in, std::back_inserter(m_points)) && + !isEmpty(); } // Write point set to .XYZ file -bool Point_set_scene_item::write_xyz_point_set(std::ostream& stream) const +bool +Point_set_scene_item::write_xyz_point_set(std::ostream& out) const { - return stream && - CGAL::write_xyz_point_set(stream, m_points.begin(), m_points.end()); + return out && !isEmpty() && + CGAL::write_xyz_point_set(out, m_points.begin(), m_points.end()); } QString diff --git a/Surface_reconstruction_points_3/demo/Surface_reconstruction_points_3/Point_set_demo/Scene_polyhedron_item.cpp b/Surface_reconstruction_points_3/demo/Surface_reconstruction_points_3/Point_set_demo/Scene_polyhedron_item.cpp index 8d24f8f0237..fa45fc49fc0 100644 --- a/Surface_reconstruction_points_3/demo/Surface_reconstruction_points_3/Point_set_demo/Scene_polyhedron_item.cpp +++ b/Surface_reconstruction_points_3/demo/Surface_reconstruction_points_3/Point_set_demo/Scene_polyhedron_item.cpp @@ -39,6 +39,7 @@ Scene_polyhedron_item::clone() const { return new Scene_polyhedron_item(*poly); } +// Load polyhedron from .OFF file bool Scene_polyhedron_item::load(std::istream& in) { @@ -46,9 +47,12 @@ Scene_polyhedron_item::load(std::istream& in) return in && !isEmpty(); } +// Write polyhedron to .OFF file bool Scene_polyhedron_item::save(std::ostream& out) const { + if (isEmpty()) + return false; out << *poly; return out; } diff --git a/Surface_reconstruction_points_3/demo/Surface_reconstruction_points_3/Point_set_demo/include/UI_point_3.h b/Surface_reconstruction_points_3/demo/Surface_reconstruction_points_3/Point_set_demo/include/UI_point_3.h index 11bfabe4376..c621afc4a3f 100644 --- a/Surface_reconstruction_points_3/demo/Surface_reconstruction_points_3/Point_set_demo/include/UI_point_3.h +++ b/Surface_reconstruction_points_3/demo/Surface_reconstruction_points_3/Point_set_demo/include/UI_point_3.h @@ -15,7 +15,6 @@ /// It contains: /// - a position, /// - a normal (oriented or not), -/// - an original normal (optional, always oriented), /// - a selection flag. /// /// @heading Is Model for the Concepts: @@ -89,21 +88,18 @@ public: : Base(upt) { m_is_selected = upt.m_is_selected; - m_original_normal = upt.m_original_normal; } template UI_point_3(const UI_point_3& upt) : Base(upt) { m_is_selected = upt.is_selected(); - m_original_normal = upt.m_original_normal; } /// Operator =() UI_point_3& operator=(const UI_point_3& upt) { Base::operator=(upt); m_is_selected = upt.m_is_selected; - m_original_normal = upt.m_original_normal; return *this; } @@ -113,18 +109,11 @@ public: bool is_selected() const { return m_is_selected; } void select(bool is_selected=true) { m_is_selected = is_selected; } - /// Get/set *original* normal. - const Vector_3& original_normal() const { return m_original_normal; } - Vector_3& original_normal() { return m_original_normal; } - // Data private: // Selection flag. bool m_is_selected; - - /// *Original* normal. - Vector_3 m_original_normal; }; diff --git a/Surface_reconstruction_points_3/demo/Surface_reconstruction_points_3/poisson/include/Point_set_3.h b/Surface_reconstruction_points_3/demo/Surface_reconstruction_points_3/poisson/include/Point_set_3.h index 07ec4655092..06d71f05136 100644 --- a/Surface_reconstruction_points_3/demo/Surface_reconstruction_points_3/poisson/include/Point_set_3.h +++ b/Surface_reconstruction_points_3/demo/Surface_reconstruction_points_3/poisson/include/Point_set_3.h @@ -55,8 +55,8 @@ public: // Repeat base class' types /// @cond SKIP_IN_MANUAL - using Base::iterator; - using Base::const_iterator; + typedef typename Base::iterator iterator; + typedef typename Base::const_iterator const_iterator; /// @endcond // Classic CGAL geometric types @@ -77,8 +77,8 @@ public: typedef typename UI_point::Normal Normal; ///< Model of OrientableNormal_3 concept. // Iterator over Point_3 points - typedef std::deque::iterator Point_iterator; - typedef std::deque::const_iterator Point_const_iterator; + typedef typename std::deque::iterator Point_iterator; + typedef typename std::deque::const_iterator Point_const_iterator; // Iterator over normals typedef CGAL::Iterator_project - UI_point_3(const Point_with_normal_3& pwn) + UI_point_3(const CGAL::Point_with_normal_3& pwn) : Base(pwn) { m_is_selected = false; @@ -110,32 +110,32 @@ public: } /// Copy constructor - UI_point_3(const UI_point_3& gpt) - : Base(gpt) + UI_point_3(const UI_point_3& upt) + : Base(upt) { - m_is_selected = gpt.m_is_selected; - m_original_normal = gpt.m_original_normal; + m_is_selected = upt.m_is_selected; + m_original_normal = upt.m_original_normal; } template - UI_point_3(const UI_point_3& gpt) - : Base(gpt) + UI_point_3(const UI_point_3& upt) + : Base(upt) { - m_is_selected = gpt.is_selected(); - m_original_normal = gpt.m_original_normal; + m_is_selected = upt.is_selected(); + m_original_normal = upt.m_original_normal; } /// Operator =() - UI_point_3& operator=(const UI_point_3& gpt) + UI_point_3& operator=(const UI_point_3& upt) { - Base::operator=(gpt); - m_is_selected = gpt.m_is_selected; - m_original_normal = gpt.m_original_normal; + Base::operator=(upt); + m_is_selected = upt.m_is_selected; + m_original_normal = upt.m_original_normal; return *this; } /// Merge points, including lists of camera/2D point pairs. - void merge(const UI_point_3& gpt) + void merge(const UI_point_3& upt) { - Base::merge(gpt); + Base::merge(upt); } // Inherited operators ==() and !=() are fine.