mirror of https://github.com/CGAL/cgal
Create Qt Point Set demo from Qt Polyhedron demo and Poisson MFC demo.
Step 4: - added xyz_plugin to load/save .xyz/.pwn point set files
This commit is contained in:
parent
0760ac6624
commit
206c29a68a
|
|
@ -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)
|
||||
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
|
|
|||
|
|
@ -0,0 +1,74 @@
|
|||
#include "Point_set_scene_item.h"
|
||||
#include "Point_set_demo_types.h"
|
||||
|
||||
#include "Polyhedron_demo_io_plugin_interface.h"
|
||||
#include <fstream>
|
||||
|
||||
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<const Point_set_scene_item*>(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<const Point_set_scene_item*>(item);
|
||||
if(!point_set_item)
|
||||
return false;
|
||||
|
||||
std::ofstream out(fileinfo.filePath().toUtf8());
|
||||
|
||||
return point_set_item->write_xyz_point_set(out);
|
||||
}
|
||||
|
||||
#include <QtPlugin>
|
||||
Q_EXPORT_PLUGIN2(Point_set_demo_xyz_plugin, Point_set_demo_xyz_plugin);
|
||||
#include "Point_set_demo_xyz_plugin.moc"
|
||||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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<class K>
|
||||
UI_point_3(const UI_point_3<K>& 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;
|
||||
};
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -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<UI_point>::iterator Point_iterator;
|
||||
typedef std::deque<UI_point>::const_iterator Point_const_iterator;
|
||||
typedef typename std::deque<UI_point>::iterator Point_iterator;
|
||||
typedef typename std::deque<UI_point>::const_iterator Point_const_iterator;
|
||||
|
||||
// Iterator over normals
|
||||
typedef CGAL::Iterator_project<iterator,
|
||||
|
|
|
|||
|
|
@ -80,7 +80,7 @@ public:
|
|||
m_is_selected = false;
|
||||
}
|
||||
template <class K, class N>
|
||||
UI_point_3(const Point_with_normal_3<K,N>& pwn)
|
||||
UI_point_3(const CGAL::Point_with_normal_3<K,N>& 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<class K>
|
||||
UI_point_3(const UI_point_3<K>& gpt)
|
||||
: Base(gpt)
|
||||
UI_point_3(const UI_point_3<K>& 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.
|
||||
|
|
|
|||
Loading…
Reference in New Issue