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)
|
polyhedron_demo_plugin(off_plugin Point_set_demo_off_plugin)
|
||||||
target_link_libraries(off_plugin scene_polyhedron_item point_set)
|
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)
|
polyhedron_demo_plugin(convex_hull_plugin Point_set_demo_convex_hull_plugin)
|
||||||
target_link_libraries(convex_hull_plugin scene_polyhedron_item)
|
target_link_libraries(convex_hull_plugin scene_polyhedron_item)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -35,8 +35,10 @@ Point_set_demo_off_plugin::load(QFileInfo fileinfo) {
|
||||||
|
|
||||||
// Open file
|
// Open file
|
||||||
std::ifstream in(fileinfo.filePath().toUtf8());
|
std::ifstream in(fileinfo.filePath().toUtf8());
|
||||||
if(!in)
|
if(!in) {
|
||||||
std::cerr << "Error!\n";
|
std::cerr << "Error! Cannot open file " << (const char*)fileinfo.filePath().toUtf8() << std::endl;
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
// Try to read .off in a polyhedron
|
// Try to read .off in a polyhedron
|
||||||
Scene_polyhedron_item* item = new Scene_polyhedron_item();
|
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
|
// 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();
|
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
|
// 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 &&
|
return out && !isEmpty() &&
|
||||||
CGAL::write_off_point_set(stream, m_points.begin(), m_points.end());
|
CGAL::write_off_point_set(out, m_points.begin(), m_points.end());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load point set from .XYZ file
|
// 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();
|
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
|
// 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 &&
|
return out && !isEmpty() &&
|
||||||
CGAL::write_xyz_point_set(stream, m_points.begin(), m_points.end());
|
CGAL::write_xyz_point_set(out, m_points.begin(), m_points.end());
|
||||||
}
|
}
|
||||||
|
|
||||||
QString
|
QString
|
||||||
|
|
|
||||||
|
|
@ -39,6 +39,7 @@ Scene_polyhedron_item::clone() const {
|
||||||
return new Scene_polyhedron_item(*poly);
|
return new Scene_polyhedron_item(*poly);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Load polyhedron from .OFF file
|
||||||
bool
|
bool
|
||||||
Scene_polyhedron_item::load(std::istream& in)
|
Scene_polyhedron_item::load(std::istream& in)
|
||||||
{
|
{
|
||||||
|
|
@ -46,9 +47,12 @@ Scene_polyhedron_item::load(std::istream& in)
|
||||||
return in && !isEmpty();
|
return in && !isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Write polyhedron to .OFF file
|
||||||
bool
|
bool
|
||||||
Scene_polyhedron_item::save(std::ostream& out) const
|
Scene_polyhedron_item::save(std::ostream& out) const
|
||||||
{
|
{
|
||||||
|
if (isEmpty())
|
||||||
|
return false;
|
||||||
out << *poly;
|
out << *poly;
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,6 @@
|
||||||
/// It contains:
|
/// It contains:
|
||||||
/// - a position,
|
/// - a position,
|
||||||
/// - a normal (oriented or not),
|
/// - a normal (oriented or not),
|
||||||
/// - an original normal (optional, always oriented),
|
|
||||||
/// - a selection flag.
|
/// - a selection flag.
|
||||||
///
|
///
|
||||||
/// @heading Is Model for the Concepts:
|
/// @heading Is Model for the Concepts:
|
||||||
|
|
@ -89,21 +88,18 @@ public:
|
||||||
: Base(upt)
|
: Base(upt)
|
||||||
{
|
{
|
||||||
m_is_selected = upt.m_is_selected;
|
m_is_selected = upt.m_is_selected;
|
||||||
m_original_normal = upt.m_original_normal;
|
|
||||||
}
|
}
|
||||||
template<class K>
|
template<class K>
|
||||||
UI_point_3(const UI_point_3<K>& upt)
|
UI_point_3(const UI_point_3<K>& upt)
|
||||||
: Base(upt)
|
: Base(upt)
|
||||||
{
|
{
|
||||||
m_is_selected = upt.is_selected();
|
m_is_selected = upt.is_selected();
|
||||||
m_original_normal = upt.m_original_normal;
|
|
||||||
}
|
}
|
||||||
/// Operator =()
|
/// Operator =()
|
||||||
UI_point_3& operator=(const UI_point_3& upt)
|
UI_point_3& operator=(const UI_point_3& upt)
|
||||||
{
|
{
|
||||||
Base::operator=(upt);
|
Base::operator=(upt);
|
||||||
m_is_selected = upt.m_is_selected;
|
m_is_selected = upt.m_is_selected;
|
||||||
m_original_normal = upt.m_original_normal;
|
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -113,18 +109,11 @@ public:
|
||||||
bool is_selected() const { return m_is_selected; }
|
bool is_selected() const { return m_is_selected; }
|
||||||
void select(bool is_selected=true) { m_is_selected = 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
|
// Data
|
||||||
private:
|
private:
|
||||||
|
|
||||||
// Selection flag.
|
// Selection flag.
|
||||||
bool m_is_selected;
|
bool m_is_selected;
|
||||||
|
|
||||||
/// *Original* normal.
|
|
||||||
Vector_3 m_original_normal;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -55,8 +55,8 @@ public:
|
||||||
|
|
||||||
// Repeat base class' types
|
// Repeat base class' types
|
||||||
/// @cond SKIP_IN_MANUAL
|
/// @cond SKIP_IN_MANUAL
|
||||||
using Base::iterator;
|
typedef typename Base::iterator iterator;
|
||||||
using Base::const_iterator;
|
typedef typename Base::const_iterator const_iterator;
|
||||||
/// @endcond
|
/// @endcond
|
||||||
|
|
||||||
// Classic CGAL geometric types
|
// Classic CGAL geometric types
|
||||||
|
|
@ -77,8 +77,8 @@ public:
|
||||||
typedef typename UI_point::Normal Normal; ///< Model of OrientableNormal_3 concept.
|
typedef typename UI_point::Normal Normal; ///< Model of OrientableNormal_3 concept.
|
||||||
|
|
||||||
// Iterator over Point_3 points
|
// Iterator over Point_3 points
|
||||||
typedef std::deque<UI_point>::iterator Point_iterator;
|
typedef typename std::deque<UI_point>::iterator Point_iterator;
|
||||||
typedef std::deque<UI_point>::const_iterator Point_const_iterator;
|
typedef typename std::deque<UI_point>::const_iterator Point_const_iterator;
|
||||||
|
|
||||||
// Iterator over normals
|
// Iterator over normals
|
||||||
typedef CGAL::Iterator_project<iterator,
|
typedef CGAL::Iterator_project<iterator,
|
||||||
|
|
|
||||||
|
|
@ -80,7 +80,7 @@ public:
|
||||||
m_is_selected = false;
|
m_is_selected = false;
|
||||||
}
|
}
|
||||||
template <class K, class N>
|
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)
|
: Base(pwn)
|
||||||
{
|
{
|
||||||
m_is_selected = false;
|
m_is_selected = false;
|
||||||
|
|
@ -110,32 +110,32 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Copy constructor
|
/// Copy constructor
|
||||||
UI_point_3(const UI_point_3& gpt)
|
UI_point_3(const UI_point_3& upt)
|
||||||
: Base(gpt)
|
: Base(upt)
|
||||||
{
|
{
|
||||||
m_is_selected = gpt.m_is_selected;
|
m_is_selected = upt.m_is_selected;
|
||||||
m_original_normal = gpt.m_original_normal;
|
m_original_normal = upt.m_original_normal;
|
||||||
}
|
}
|
||||||
template<class K>
|
template<class K>
|
||||||
UI_point_3(const UI_point_3<K>& gpt)
|
UI_point_3(const UI_point_3<K>& upt)
|
||||||
: Base(gpt)
|
: Base(upt)
|
||||||
{
|
{
|
||||||
m_is_selected = gpt.is_selected();
|
m_is_selected = upt.is_selected();
|
||||||
m_original_normal = gpt.m_original_normal;
|
m_original_normal = upt.m_original_normal;
|
||||||
}
|
}
|
||||||
/// Operator =()
|
/// Operator =()
|
||||||
UI_point_3& operator=(const UI_point_3& gpt)
|
UI_point_3& operator=(const UI_point_3& upt)
|
||||||
{
|
{
|
||||||
Base::operator=(gpt);
|
Base::operator=(upt);
|
||||||
m_is_selected = gpt.m_is_selected;
|
m_is_selected = upt.m_is_selected;
|
||||||
m_original_normal = gpt.m_original_normal;
|
m_original_normal = upt.m_original_normal;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Merge points, including lists of camera/2D point pairs.
|
/// 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.
|
// Inherited operators ==() and !=() are fine.
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue