mirror of https://github.com/CGAL/cgal
Replace IO API to be able to load/save several items at a time
This commit is contained in:
parent
04c5313a1c
commit
56c99d8a23
|
|
@ -41,7 +41,7 @@
|
|||
#include <QTime>
|
||||
#include <QWidgetAction>
|
||||
#include <QJsonArray>
|
||||
|
||||
#include <QSequentialIterable>
|
||||
#ifdef QT_SCRIPT_LIB
|
||||
# include <QScriptValue>
|
||||
# ifdef QT_SCRIPTTOOLS_LIB
|
||||
|
|
@ -998,20 +998,33 @@ void MainWindow::reloadItem() {
|
|||
|
||||
CGAL::Three::Polyhedron_demo_io_plugin_interface* fileloader = findLoader(loader_name);
|
||||
QFileInfo fileinfo(filename);
|
||||
|
||||
CGAL::Three::Scene_item* new_item = loadItem(fileinfo, fileloader);
|
||||
if(!new_item)
|
||||
bool ok;
|
||||
QList<Scene_item*> new_items = loadItem(fileinfo, fileloader, ok, false);
|
||||
if(!ok)
|
||||
return;
|
||||
new_item->setName(item->name());
|
||||
new_item->setColor(item->color());
|
||||
new_item->setRenderingMode(item->renderingMode());
|
||||
new_item->setVisible(item->visible());
|
||||
Scene_item_with_properties *property_item = dynamic_cast<Scene_item_with_properties*>(new_item);
|
||||
scene->replaceItem(scene->item_id(item), new_item, true);
|
||||
if(property_item)
|
||||
property_item->copyProperties(item);
|
||||
new_item->invalidateOpenGLBuffers();
|
||||
item->deleteLater();
|
||||
QVariant varian = item->property("load_mates");
|
||||
if (!varian.canConvert<QVariantList>())
|
||||
qDebug()<<"Well, that's gonna be a problem !";
|
||||
QSequentialIterable iterable = varian.value<QSequentialIterable>();
|
||||
// Can use foreach:
|
||||
int mate_id = 0;
|
||||
Q_FOREACH(const QVariant &v, iterable)
|
||||
{
|
||||
Scene_item* mate = v.value<Scene_item*>();
|
||||
Scene_item* new_item = new_items[mate_id];
|
||||
if(!new_item)
|
||||
qDebug()<<"That too, is gonna be a problem...";
|
||||
new_item->setName(mate->name());
|
||||
new_item->setColor(mate->color());
|
||||
new_item->setRenderingMode(mate->renderingMode());
|
||||
new_item->setVisible(mate->visible());
|
||||
Scene_item_with_properties *property_item = dynamic_cast<Scene_item_with_properties*>(new_item);
|
||||
scene->replaceItem(scene->item_id(mate), new_item, true);
|
||||
if(property_item)
|
||||
property_item->copyProperties(mate);
|
||||
new_item->invalidateOpenGLBuffers();
|
||||
mate->deleteLater();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1105,7 +1118,7 @@ void MainWindow::open(QString filename)
|
|||
// collect all io_plugins and offer them to load if the file extension match one name filter
|
||||
// also collect all available plugin in case of a no extension match
|
||||
Q_FOREACH(CGAL::Three::Polyhedron_demo_io_plugin_interface* io_plugin, io_plugins) {
|
||||
if ( !io_plugin->canLoad() ) continue;
|
||||
if ( !io_plugin->canLoad(fileinfo) ) continue;
|
||||
all_items << io_plugin->name();
|
||||
if ( file_matches_filter(io_plugin->loadNameFilters(), filename.toLower()) )
|
||||
{
|
||||
|
|
@ -1148,71 +1161,70 @@ void MainWindow::open(QString filename)
|
|||
|
||||
settings.setValue("OFF open directory",
|
||||
fileinfo.absoluteDir().absolutePath());
|
||||
CGAL::Three::Scene_item* scene_item = loadItem(fileinfo, findLoader(load_pair.first));
|
||||
loadItem(fileinfo, findLoader(load_pair.first), ok);
|
||||
|
||||
if(!scene_item)
|
||||
if(!ok)
|
||||
return;
|
||||
this->addToRecentFiles(fileinfo.absoluteFilePath());
|
||||
selectSceneItem(scene->addItem(scene_item));
|
||||
|
||||
CGAL::Three::Scene_group_item* group =
|
||||
qobject_cast<CGAL::Three::Scene_group_item*>(scene_item);
|
||||
if(group)
|
||||
scene->redraw_model();
|
||||
updateViewersBboxes(true);
|
||||
}
|
||||
|
||||
bool MainWindow::open(QString filename, QString loader_name) {
|
||||
QFileInfo fileinfo(filename);
|
||||
boost::optional<CGAL::Three::Scene_item*> item_opt;
|
||||
boost::optional<bool> item_opt;
|
||||
CGAL::Three::Scene_item* item = 0;
|
||||
try {
|
||||
item_opt = wrap_a_call_to_cpp
|
||||
([this, fileinfo, loader_name]()
|
||||
{
|
||||
return loadItem(fileinfo, findLoader(loader_name));
|
||||
bool ok;
|
||||
loadItem(fileinfo, findLoader(loader_name), ok);
|
||||
return ok;
|
||||
},
|
||||
this, __FILE__, __LINE__
|
||||
);
|
||||
if(!item_opt) return false;
|
||||
else item = *item_opt;
|
||||
//else item = *item_opt;
|
||||
}
|
||||
catch(std::logic_error& e) {
|
||||
std::cerr << e.what() << std::endl;
|
||||
return false;
|
||||
}
|
||||
selectSceneItem(scene->addItem(item));
|
||||
|
||||
CGAL::Three::Scene_group_item* group =
|
||||
qobject_cast<CGAL::Three::Scene_group_item*>(item);
|
||||
if(group)
|
||||
scene->redraw_model();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
CGAL::Three::Scene_item* MainWindow::loadItem(QFileInfo fileinfo, CGAL::Three::Polyhedron_demo_io_plugin_interface* loader) {
|
||||
CGAL::Three::Scene_item* item = NULL;
|
||||
QList<Scene_item*> MainWindow::loadItem(QFileInfo fileinfo,
|
||||
CGAL::Three::Polyhedron_demo_io_plugin_interface* loader,
|
||||
bool &ok,
|
||||
bool add_to_scene) {
|
||||
if(!fileinfo.isFile() || !fileinfo.isReadable()) {
|
||||
QMessageBox::warning(this, tr("Error"),
|
||||
QString("File %1 is not a readable file.")
|
||||
.arg(fileinfo.absoluteFilePath()));
|
||||
}
|
||||
QApplication::setOverrideCursor(Qt::WaitCursor);
|
||||
|
||||
item = loader->load(fileinfo);
|
||||
QApplication::restoreOverrideCursor();
|
||||
if(!item) {
|
||||
CGAL::Three::Three::CursorScopeGuard guard(QCursor(Qt::WaitCursor));
|
||||
QList<Scene_item*> result = loader->load(fileinfo, ok, add_to_scene);
|
||||
selectSceneItem(scene->item_id(result.back()));
|
||||
if(!ok)
|
||||
{
|
||||
QApplication::restoreOverrideCursor();
|
||||
QMessageBox::warning(this, tr("Error"),
|
||||
QString("Could not load item from file %1 using plugin %2")
|
||||
.arg(fileinfo.absoluteFilePath()).arg(loader->name()));
|
||||
return 0;
|
||||
return QList<Scene_item*>();
|
||||
}
|
||||
|
||||
item->setProperty("source filename", fileinfo.absoluteFilePath());
|
||||
item->setProperty("loader_name", loader->name());
|
||||
return item;
|
||||
for(Scene_item* item : result)
|
||||
{
|
||||
CGAL::Three::Scene_group_item* group =
|
||||
qobject_cast<CGAL::Three::Scene_group_item*>(item);
|
||||
if(group)
|
||||
scene->redraw_model();
|
||||
item->setProperty("source filename", fileinfo.absoluteFilePath());
|
||||
item->setProperty("loader_name", loader->name());
|
||||
item->setProperty("load_mates",QVariant::fromValue(result));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -1831,7 +1843,7 @@ void MainWindow::on_actionLoad_triggered()
|
|||
typedef QMap<QString, CGAL::Three::Polyhedron_demo_io_plugin_interface*> FilterPluginMap;
|
||||
FilterPluginMap filterPluginMap;
|
||||
|
||||
Q_FOREACH(CGAL::Three::Polyhedron_demo_io_plugin_interface* plugin, io_plugins) {
|
||||
for(CGAL::Three::Polyhedron_demo_io_plugin_interface* plugin : io_plugins) {
|
||||
QStringList split_filters = plugin->loadNameFilters().split(";;");
|
||||
Q_FOREACH(const QString& filter, split_filters) {
|
||||
FilterPluginMap::iterator it = filterPluginMap.find(filter);
|
||||
|
|
@ -1877,18 +1889,25 @@ void MainWindow::on_actionLoad_triggered()
|
|||
std::size_t nb_item = -1;
|
||||
|
||||
Q_FOREACH(const QString& filename, dialog.selectedFiles()) {
|
||||
|
||||
|
||||
CGAL::Three::Scene_item* item = NULL;
|
||||
if(selectedPlugin) {
|
||||
QFileInfo info(filename);
|
||||
item = loadItem(info, selectedPlugin);
|
||||
item->setColor(colors_[++nb_item]);
|
||||
Scene::Item_id index = scene->addItem(item);
|
||||
selectSceneItem(index);
|
||||
CGAL::Three::Scene_group_item* group =
|
||||
qobject_cast<CGAL::Three::Scene_group_item*>(item);
|
||||
if(group)
|
||||
scene->redraw_model();
|
||||
bool ok;
|
||||
QList<Scene_item*> result = loadItem(info, selectedPlugin, ok);
|
||||
if(!ok)
|
||||
continue;
|
||||
for(Scene_item* item : result)
|
||||
{
|
||||
++nb_item;
|
||||
item->setColor(colors_[nb_item]);
|
||||
Scene::Item_id index = scene->addItem(item);
|
||||
selectSceneItem(index);
|
||||
CGAL::Three::Scene_group_item* group =
|
||||
qobject_cast<CGAL::Three::Scene_group_item*>(item);
|
||||
if(group)
|
||||
scene->redraw_model();
|
||||
}
|
||||
this->addToRecentFiles(filename);
|
||||
} else {
|
||||
int scene_size = scene->numberOfEntries();
|
||||
|
|
@ -1901,15 +1920,19 @@ void MainWindow::on_actionLoad_triggered()
|
|||
|
||||
void MainWindow::on_actionSaveAs_triggered()
|
||||
{
|
||||
Scene_item* item = NULL;
|
||||
|
||||
Q_FOREACH(Scene::Item_id id, scene->selectionIndices())
|
||||
QList<Scene_item*> to_save;
|
||||
for(Scene::Item_id id : scene->selectionIndices())
|
||||
{
|
||||
item = scene->item(id);
|
||||
Scene_item* item = scene->item(id);
|
||||
to_save.append(item);
|
||||
}
|
||||
while(!to_save.empty())
|
||||
{
|
||||
Scene_item* item = to_save.front();
|
||||
QVector<CGAL::Three::Polyhedron_demo_io_plugin_interface*> canSavePlugins;
|
||||
QStringList filters;
|
||||
QString sf;
|
||||
Q_FOREACH(CGAL::Three::Polyhedron_demo_io_plugin_interface* plugin, io_plugins) {
|
||||
for(CGAL::Three::Polyhedron_demo_io_plugin_interface* plugin : io_plugins) {
|
||||
if(plugin->canSave(item)) {
|
||||
canSavePlugins << plugin;
|
||||
filters += plugin->saveNameFilters();
|
||||
|
|
@ -1925,7 +1948,7 @@ void MainWindow::on_actionSaveAs_triggered()
|
|||
tr("Cannot save"),
|
||||
tr("The selected object %1 cannot be saved.")
|
||||
.arg(item->name()));
|
||||
return;
|
||||
return;
|
||||
}
|
||||
Q_FOREACH(QString string, filters)
|
||||
{
|
||||
|
|
@ -1961,14 +1984,14 @@ void MainWindow::on_actionSaveAs_triggered()
|
|||
dir,
|
||||
filters.join(";;"),
|
||||
&sf);
|
||||
|
||||
|
||||
if(filename.isEmpty())
|
||||
return;
|
||||
last_saved_dir = QFileInfo(filename).absoluteDir().path();
|
||||
extensions.indexIn(sf.split(";;").first());
|
||||
QString filter_ext, filename_ext;
|
||||
filter_ext = extensions.cap().split(" ").first();// in case of syntax like (*.a *.b)
|
||||
|
||||
|
||||
filter_ext.remove(")");
|
||||
filter_ext.remove("(");
|
||||
//remove *
|
||||
|
|
@ -2016,18 +2039,18 @@ void MainWindow::on_actionSaveAs_triggered()
|
|||
}
|
||||
for(auto v : CGAL::QGLViewer::QGLViewerPool())
|
||||
v->update();
|
||||
save(filename, item);
|
||||
save(filename, to_save);
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::save(QString filename, CGAL::Three::Scene_item* item) {
|
||||
void MainWindow::save(QString filename, QList<CGAL::Three::Scene_item*>& to_save) {
|
||||
QFileInfo fileinfo(filename);
|
||||
bool saved = false;
|
||||
Q_FOREACH(CGAL::Three::Polyhedron_demo_io_plugin_interface* plugin, io_plugins) {
|
||||
if( plugin->canSave(item) &&
|
||||
for(CGAL::Three::Polyhedron_demo_io_plugin_interface* plugin : io_plugins) {
|
||||
if( plugin->canSave(to_save.front()) &&
|
||||
file_matches_filter(plugin->saveNameFilters(),filename.toLower()) )
|
||||
{
|
||||
if(plugin->save(item, fileinfo))
|
||||
if(plugin->save(fileinfo, to_save))
|
||||
{
|
||||
saved = true;
|
||||
break;
|
||||
|
|
@ -2038,7 +2061,7 @@ void MainWindow::save(QString filename, CGAL::Three::Scene_item* item) {
|
|||
QMessageBox::warning(this,
|
||||
tr("Cannot save"),
|
||||
tr("The selected object %1 was not saved. (Maybe a wrong extension ?)")
|
||||
.arg(item->name()));
|
||||
.arg(to_save.front()->name()));
|
||||
}
|
||||
|
||||
void MainWindow::on_actionSaveSnapshot_triggered()
|
||||
|
|
@ -2470,7 +2493,7 @@ QString MainWindow::get_item_stats()
|
|||
for(int i=0; i<items.size(); i++)
|
||||
{
|
||||
Scene_item* item = scene->item(id);
|
||||
QString classname = item->property("classname").toString();
|
||||
QString classname = item->property("classname").toString();
|
||||
if(classname.isEmpty())
|
||||
classname = item->metaObject()->className();
|
||||
if(classnames.at(i).contains(classname))
|
||||
|
|
@ -3131,14 +3154,16 @@ void MainWindow::on_action_Save_triggered()
|
|||
if(QMessageBox::question(this, "Save", "Are you sure you want to override these files ?")
|
||||
== QMessageBox::No)
|
||||
return;
|
||||
Scene_item* item = nullptr;
|
||||
Q_FOREACH(Scene::Item_id id, scene->selectionIndices())
|
||||
QList<Scene_item*> to_save;
|
||||
|
||||
for(Scene::Item_id id : scene->selectionIndices())
|
||||
{
|
||||
item = scene->item(id);
|
||||
Scene_item* item = scene->item(id);
|
||||
if(!item->property("source filename").toString().isEmpty())
|
||||
{
|
||||
QString filename = item->property("source filename").toString();
|
||||
save(filename, item);
|
||||
to_save.append(item);
|
||||
save(filename, to_save);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -87,11 +87,14 @@ public:
|
|||
@returns the IO plugin associated with `loader_name`*/
|
||||
CGAL::Three::Polyhedron_demo_io_plugin_interface* findLoader(const QString& loader_name) const;
|
||||
|
||||
/*! \brief Loads an item with a given loader.
|
||||
/*! \brief Loads on or more item with a given loader.
|
||||
*
|
||||
* throws `std::logic_error` if loading does not succeed or
|
||||
* `std::invalid_argument` if `fileinfo` specifies an invalid file*/
|
||||
CGAL::Three::Scene_item* loadItem(QFileInfo fileinfo, CGAL::Three::Polyhedron_demo_io_plugin_interface*);
|
||||
QList<CGAL::Three::Scene_item *> loadItem(QFileInfo fileinfo,
|
||||
CGAL::Three::Polyhedron_demo_io_plugin_interface*,
|
||||
bool& ok,
|
||||
bool add_to_scene=true);
|
||||
void computeViewerBBox(CGAL::qglviewer::Vec &min, CGAL::qglviewer::Vec &max);
|
||||
void updateViewerBbox(Viewer* vi, bool recenter, CGAL::qglviewer::Vec min,
|
||||
CGAL::qglviewer::Vec max);
|
||||
|
|
@ -346,7 +349,7 @@ protected Q_SLOTS:
|
|||
//!Opens a dialog to save selected item if able.
|
||||
void on_actionSaveAs_triggered();
|
||||
//!Calls the function save of the current plugin if able.
|
||||
void save(QString filename, CGAL::Three::Scene_item* item);
|
||||
void save(QString filename, QList<CGAL::Three::Scene_item*>& to_save);
|
||||
//!Calls the function saveSnapShot of the viewer.
|
||||
void on_actionSaveSnapshot_triggered();
|
||||
//!Opens a Dialog to choose a color and make it the background color.
|
||||
|
|
|
|||
|
|
@ -40,30 +40,31 @@ public:
|
|||
bool applicable(QAction*) const { return false;}
|
||||
QString nameFilters() const;
|
||||
QString name() const { return "gocad_plugin"; }
|
||||
bool canLoad() const;
|
||||
CGAL::Three::Scene_item* load(QFileInfo fileinfo);
|
||||
bool canLoad(QFileInfo) const;
|
||||
QList<Scene_item*> load(QFileInfo fileinfo, bool& ok, bool add_to_scene=true);
|
||||
|
||||
bool canSave(const CGAL::Three::Scene_item*);
|
||||
bool save(const CGAL::Three::Scene_item*, QFileInfo fileinfo);
|
||||
bool save(QFileInfo fileinfo, QList<CGAL::Three::Scene_item*>& );
|
||||
};
|
||||
|
||||
QString Polyhedron_demo_gocad_plugin::nameFilters() const {
|
||||
return "GOCAD files (*.ts)";
|
||||
}
|
||||
|
||||
bool Polyhedron_demo_gocad_plugin::canLoad() const {
|
||||
bool Polyhedron_demo_gocad_plugin::canLoad(QFileInfo) const {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
CGAL::Three::Scene_item*
|
||||
Polyhedron_demo_gocad_plugin::load(QFileInfo fileinfo) {
|
||||
QList<Scene_item*>
|
||||
Polyhedron_demo_gocad_plugin::load(QFileInfo fileinfo, bool& ok, bool add_to_scene) {
|
||||
|
||||
// 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;
|
||||
ok = false;
|
||||
return QList<Scene_item*>();
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -74,7 +75,10 @@ Polyhedron_demo_gocad_plugin::load(QFileInfo fileinfo) {
|
|||
if(fileinfo.size() == 0)
|
||||
{
|
||||
CGAL::Three::Three::warning( tr("The file you are trying to load is empty."));
|
||||
return item;
|
||||
ok = true;
|
||||
if(add_to_scene)
|
||||
CGAL::Three::Three::scene()->addItem(item);
|
||||
return QList<Scene_item*>()<<item;
|
||||
}
|
||||
SMesh& P = * const_cast<SMesh*>(item->polyhedron());
|
||||
|
||||
|
|
@ -82,7 +86,8 @@ Polyhedron_demo_gocad_plugin::load(QFileInfo fileinfo) {
|
|||
if(! read_gocad(P, in, name, color)){
|
||||
std::cerr << "Error: Invalid polyhedron" << std::endl;
|
||||
delete item;
|
||||
return 0;
|
||||
ok = false;
|
||||
return QList<Scene_item*>();
|
||||
}
|
||||
|
||||
t.stop();
|
||||
|
|
@ -98,7 +103,10 @@ Polyhedron_demo_gocad_plugin::load(QFileInfo fileinfo) {
|
|||
item->setColor(qcolor);
|
||||
}
|
||||
item->invalidateOpenGLBuffers();
|
||||
return item;
|
||||
ok = true;
|
||||
if(add_to_scene)
|
||||
CGAL::Three::Three::scene()->addItem(item);
|
||||
return QList<Scene_item*>()<<item;
|
||||
}
|
||||
|
||||
bool Polyhedron_demo_gocad_plugin::canSave(const CGAL::Three::Scene_item* item)
|
||||
|
|
@ -107,8 +115,10 @@ bool Polyhedron_demo_gocad_plugin::canSave(const CGAL::Three::Scene_item* item)
|
|||
return qobject_cast<const Scene_surface_mesh_item*>(item);
|
||||
}
|
||||
|
||||
bool Polyhedron_demo_gocad_plugin::save(const CGAL::Three::Scene_item* item, QFileInfo fileinfo)
|
||||
bool Polyhedron_demo_gocad_plugin::
|
||||
save(QFileInfo fileinfo,QList<CGAL::Three::Scene_item*>& items)
|
||||
{
|
||||
Scene_item* item = items.front();
|
||||
// This plugin supports polyhedrons
|
||||
const Scene_surface_mesh_item* sm_item =
|
||||
qobject_cast<const Scene_surface_mesh_item*>(item);
|
||||
|
|
@ -120,6 +130,7 @@ bool Polyhedron_demo_gocad_plugin::save(const CGAL::Three::Scene_item* item, QFi
|
|||
out.precision (std::numeric_limits<double>::digits10 + 2);
|
||||
SMesh* poly = const_cast<SMesh*>(sm_item->polyhedron());
|
||||
write_gocad(*poly, out, qPrintable(fileinfo.baseName()));
|
||||
items.pop_front();
|
||||
return true;
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,8 +1,9 @@
|
|||
#include "Scene_points_with_normal_item.h"
|
||||
#include <CGAL/Three/Polyhedron_demo_io_plugin_interface.h>
|
||||
|
||||
#include <CGAL/Three/Three.h>
|
||||
#include <CGAL/Three/Scene_item.h>
|
||||
#include <fstream>
|
||||
|
||||
using namespace CGAL::Three;
|
||||
class Polyhedron_demo_las_plugin :
|
||||
public QObject,
|
||||
public CGAL::Three::Polyhedron_demo_io_plugin_interface
|
||||
|
|
@ -14,19 +15,19 @@ class Polyhedron_demo_las_plugin :
|
|||
public:
|
||||
QString name() const { return "las_plugin"; }
|
||||
QString nameFilters() const { return "LAS files (*.las);;Compressed LAS files (*.laz)"; }
|
||||
bool canLoad() const;
|
||||
CGAL::Three::Scene_item* load(QFileInfo fileinfo);
|
||||
bool canLoad(QFileInfo fileinfo) const;
|
||||
QList<Scene_item*> load(QFileInfo fileinfo, bool& ok, bool add_to_scene=true);
|
||||
|
||||
bool canSave(const CGAL::Three::Scene_item*);
|
||||
bool save(const CGAL::Three::Scene_item*, QFileInfo fileinfo);
|
||||
bool save(QFileInfo fileinfo,QList<CGAL::Three::Scene_item*>& );
|
||||
};
|
||||
|
||||
bool Polyhedron_demo_las_plugin::canLoad() const {
|
||||
bool Polyhedron_demo_las_plugin::canLoad(QFileInfo fileinfo) const {
|
||||
return true;
|
||||
}
|
||||
|
||||
CGAL::Three::Scene_item*
|
||||
Polyhedron_demo_las_plugin::load(QFileInfo fileinfo) {
|
||||
QList<Scene_item*> Polyhedron_demo_las_plugin::
|
||||
load(QFileInfo fileinfo, bool& ok, bool add_to_scene) {
|
||||
std::ifstream in(fileinfo.filePath().toUtf8(), std::ios_base::binary);
|
||||
|
||||
if(!in)
|
||||
|
|
@ -37,11 +38,15 @@ Polyhedron_demo_las_plugin::load(QFileInfo fileinfo) {
|
|||
if(!item->read_las_point_set(in))
|
||||
{
|
||||
delete item;
|
||||
return 0;
|
||||
ok = false;
|
||||
return QList<Scene_item*>();
|
||||
}
|
||||
|
||||
item->setName(fileinfo.completeBaseName());
|
||||
return item;
|
||||
ok = true;
|
||||
if(add_to_scene)
|
||||
CGAL::Three::Three::scene()->addItem(item);
|
||||
return QList<Scene_item*>()<<item;
|
||||
}
|
||||
|
||||
bool Polyhedron_demo_las_plugin::canSave(const CGAL::Three::Scene_item* item)
|
||||
|
|
@ -49,8 +54,9 @@ bool Polyhedron_demo_las_plugin::canSave(const CGAL::Three::Scene_item* item)
|
|||
return qobject_cast<const Scene_points_with_normal_item*>(item);
|
||||
}
|
||||
|
||||
bool Polyhedron_demo_las_plugin::save(const CGAL::Three::Scene_item* item, QFileInfo fileinfo)
|
||||
bool Polyhedron_demo_las_plugin::save(QFileInfo fileinfo,QList<CGAL::Three::Scene_item*>& items)
|
||||
{
|
||||
Scene_item* item = items.front();
|
||||
// Check extension (quietly)
|
||||
std::string extension = fileinfo.suffix().toUtf8().data();
|
||||
if (extension != "las" && extension != "LAS")
|
||||
|
|
@ -63,6 +69,7 @@ bool Polyhedron_demo_las_plugin::save(const CGAL::Three::Scene_item* item, QFile
|
|||
return false;
|
||||
|
||||
std::ofstream out(fileinfo.filePath().toUtf8().data());
|
||||
items.pop_front();
|
||||
return point_set_item->write_las_point_set(out);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -17,32 +17,37 @@ class Polyhedron_demo_io_nef_plugin :
|
|||
public:
|
||||
QString nameFilters() const;
|
||||
QString name() const { return "io_nef_plugin"; }
|
||||
bool canLoad() const;
|
||||
CGAL::Three::Scene_item* load(QFileInfo fileinfo);
|
||||
bool canLoad(QFileInfo) const;
|
||||
QList<Scene_item*> load(QFileInfo fileinfo, bool& ok, bool add_to_scene=true);
|
||||
|
||||
bool canSave(const CGAL::Three::Scene_item*);
|
||||
bool save(const CGAL::Three::Scene_item*, QFileInfo fileinfo);
|
||||
bool save(QFileInfo fileinfo,QList<CGAL::Three::Scene_item*>& items);
|
||||
};
|
||||
|
||||
QString Polyhedron_demo_io_nef_plugin::nameFilters() const {
|
||||
return "nef files (*.nef3)";
|
||||
}
|
||||
|
||||
bool Polyhedron_demo_io_nef_plugin::canLoad() const {
|
||||
bool Polyhedron_demo_io_nef_plugin::canLoad(QFileInfo) const {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
CGAL::Three::Scene_item*
|
||||
Polyhedron_demo_io_nef_plugin::load(QFileInfo fileinfo) {
|
||||
QList<Scene_item*> Polyhedron_demo_io_nef_plugin::
|
||||
load(QFileInfo fileinfo, bool& ok, bool add_to_scene) {
|
||||
//do not try file with extension different from nef3
|
||||
if (fileinfo.suffix() != "nef3") return 0;
|
||||
if (fileinfo.suffix() != "nef3")
|
||||
{
|
||||
ok = false;
|
||||
return QList<Scene_item*>();
|
||||
}
|
||||
|
||||
// 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;
|
||||
ok = false;
|
||||
return QList<Scene_item*>();
|
||||
}
|
||||
|
||||
// Try to read .nef3 in a polyhedron
|
||||
|
|
@ -51,15 +56,22 @@ Polyhedron_demo_io_nef_plugin::load(QFileInfo fileinfo) {
|
|||
if(fileinfo.size() == 0)
|
||||
{
|
||||
CGAL::Three::Three::warning( tr("The file you are trying to load is empty."));
|
||||
return item;
|
||||
ok = true;
|
||||
if(add_to_scene)
|
||||
CGAL::Three::Three::scene()->addItem(item);
|
||||
return QList<Scene_item*>()<<item;
|
||||
}
|
||||
if(!item->load(in))
|
||||
{
|
||||
delete item;
|
||||
return 0;
|
||||
ok = false;
|
||||
return QList<Scene_item*>();
|
||||
}
|
||||
|
||||
return item;
|
||||
ok = true;
|
||||
if(add_to_scene)
|
||||
CGAL::Three::Three::scene()->addItem(item);
|
||||
return QList<Scene_item*>()<<item;
|
||||
}
|
||||
|
||||
bool Polyhedron_demo_io_nef_plugin::canSave(const CGAL::Three::Scene_item* item)
|
||||
|
|
@ -68,8 +80,9 @@ bool Polyhedron_demo_io_nef_plugin::canSave(const CGAL::Three::Scene_item* item)
|
|||
return qobject_cast<const Scene_nef_polyhedron_item*>(item);
|
||||
}
|
||||
|
||||
bool Polyhedron_demo_io_nef_plugin::save(const CGAL::Three::Scene_item* item, QFileInfo fileinfo)
|
||||
bool Polyhedron_demo_io_nef_plugin::save(QFileInfo fileinfo,QList<CGAL::Three::Scene_item*>& items)
|
||||
{
|
||||
Scene_item* item = items.front();
|
||||
// This plugin supports polyhedrons and polygon soups
|
||||
const Scene_nef_polyhedron_item* nef_item =
|
||||
qobject_cast<const Scene_nef_polyhedron_item*>(item);
|
||||
|
|
@ -79,6 +92,7 @@ bool Polyhedron_demo_io_nef_plugin::save(const CGAL::Three::Scene_item* item, QF
|
|||
|
||||
std::ofstream out(fileinfo.filePath().toUtf8());
|
||||
out.precision (std::numeric_limits<double>::digits10 + 2);
|
||||
items.pop_front();
|
||||
return (nef_item && nef_item->save(out));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -40,22 +40,21 @@ public:
|
|||
}
|
||||
QString name() const { return "off_plugin"; }
|
||||
QString nameFilters() const { return "OFF files (*.off);;Wavefront OBJ (*.obj)"; }
|
||||
bool canLoad() const;
|
||||
CGAL::Three::Scene_item* load(QFileInfo fileinfo);
|
||||
CGAL::Three::Scene_item* load_off(QFileInfo fileinfo);
|
||||
CGAL::Three::Scene_item* load_obj(QFileInfo fileinfo);
|
||||
bool canLoad(QFileInfo fileinfo) const;
|
||||
QList<Scene_item*> load(QFileInfo fileinfo, bool& ok, bool add_to_scene=true);
|
||||
CGAL::Three::Scene_item* load_off(QFileInfo fileinfo);
|
||||
CGAL::Three::Scene_item* load_obj(QFileInfo fileinfo);
|
||||
|
||||
bool canSave(const CGAL::Three::Scene_item*);
|
||||
bool save(const CGAL::Three::Scene_item*, QFileInfo fileinfo);
|
||||
bool save(QFileInfo fileinfo,QList<CGAL::Three::Scene_item*>& );
|
||||
};
|
||||
|
||||
bool Polyhedron_demo_off_plugin::canLoad() const {
|
||||
bool Polyhedron_demo_off_plugin::canLoad(QFileInfo) const {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
CGAL::Three::Scene_item*
|
||||
Polyhedron_demo_off_plugin::load(QFileInfo fileinfo) {
|
||||
QList<Scene_item*> Polyhedron_demo_off_plugin::
|
||||
load(QFileInfo fileinfo, bool& ok, bool add_to_scene) {
|
||||
|
||||
if(fileinfo.size() == 0)
|
||||
{
|
||||
|
|
@ -63,14 +62,41 @@ Polyhedron_demo_off_plugin::load(QFileInfo fileinfo) {
|
|||
Scene_surface_mesh_item* item =
|
||||
new Scene_surface_mesh_item(SMesh());
|
||||
item->setName(fileinfo.completeBaseName());
|
||||
return item;
|
||||
ok = true;
|
||||
if(add_to_scene)
|
||||
CGAL::Three::Three::scene()->addItem(item);
|
||||
return QList<Scene_item*>()<<item;
|
||||
}
|
||||
if(fileinfo.suffix().toLower() == "off"){
|
||||
return load_off(fileinfo);
|
||||
Scene_item* item = load_off(fileinfo);
|
||||
if(item){
|
||||
ok = true;
|
||||
if(add_to_scene)
|
||||
CGAL::Three::Three::scene()->addItem(item);
|
||||
return QList<Scene_item*>()<<item;
|
||||
}
|
||||
else
|
||||
{
|
||||
ok = false;
|
||||
return QList<Scene_item*>();
|
||||
}
|
||||
} else if(fileinfo.suffix().toLower() == "obj"){
|
||||
return load_obj(fileinfo);
|
||||
|
||||
Scene_item* item = load_obj(fileinfo);
|
||||
if(item)
|
||||
{
|
||||
ok = true;
|
||||
if(add_to_scene)
|
||||
CGAL::Three::Three::scene()->addItem(item);
|
||||
return QList<Scene_item*>()<<item;
|
||||
}
|
||||
else
|
||||
{
|
||||
ok = true;
|
||||
return QList<Scene_item*>();
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
return QList<Scene_item*>();
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -183,8 +209,12 @@ bool Polyhedron_demo_off_plugin::canSave(const CGAL::Three::Scene_item* item)
|
|||
qobject_cast<const Scene_points_with_normal_item*>(item);
|
||||
}
|
||||
|
||||
bool Polyhedron_demo_off_plugin::save(const CGAL::Three::Scene_item* item, QFileInfo fileinfo)
|
||||
|
||||
bool
|
||||
Polyhedron_demo_off_plugin::
|
||||
save(QFileInfo fileinfo,QList<CGAL::Three::Scene_item*>& items)
|
||||
{
|
||||
Scene_item* item = items.front();
|
||||
// This plugin supports point sets, surface_meshes and polygon soups
|
||||
const Scene_points_with_normal_item* points_item =
|
||||
qobject_cast<const Scene_points_with_normal_item*>(item);
|
||||
|
|
@ -200,12 +230,26 @@ bool Polyhedron_demo_off_plugin::save(const CGAL::Three::Scene_item* item, QFile
|
|||
out.precision (std::numeric_limits<double>::digits10 + 2);
|
||||
|
||||
if(fileinfo.suffix().toLower() == "off"){
|
||||
return (sm_item && sm_item->save(out)) ||
|
||||
bool res = (sm_item && sm_item->save(out)) ||
|
||||
(soup_item && soup_item->save(out)) ||
|
||||
(points_item && points_item->write_off_point_set(out));
|
||||
if(res){
|
||||
items.pop_front();
|
||||
return true;
|
||||
}
|
||||
else{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if(fileinfo.suffix().toLower() == "obj"){
|
||||
return (sm_item && sm_item->save_obj(out));
|
||||
bool res = (sm_item && sm_item->save_obj(out));
|
||||
if(res)
|
||||
{
|
||||
items.pop_front();
|
||||
return true;
|
||||
}
|
||||
else
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,19 +16,19 @@ class Polyhedron_demo_off_to_nef_plugin :
|
|||
public:
|
||||
QString name() const { return "off_to_nef_plugin"; }
|
||||
QString nameFilters() const { return "OFF files, into nef (*.off)"; }
|
||||
bool canLoad() const;
|
||||
CGAL::Three::Scene_item* load(QFileInfo fileinfo);
|
||||
bool canLoad(QFileInfo) const;
|
||||
QList<Scene_item*> load(QFileInfo fileinfo, bool& ok, bool add_to_scene=true);
|
||||
|
||||
bool canSave(const CGAL::Three::Scene_item*);
|
||||
bool save(const CGAL::Three::Scene_item*, QFileInfo fileinfo);
|
||||
bool save(QFileInfo fileinfo,QList<CGAL::Three::Scene_item*>& );
|
||||
};
|
||||
|
||||
bool Polyhedron_demo_off_to_nef_plugin::canLoad() const {
|
||||
bool Polyhedron_demo_off_to_nef_plugin::canLoad(QFileInfo) const {
|
||||
return true;
|
||||
}
|
||||
|
||||
CGAL::Three::Scene_item*
|
||||
Polyhedron_demo_off_to_nef_plugin::load(QFileInfo fileinfo) {
|
||||
QList<Scene_item*> Polyhedron_demo_off_to_nef_plugin::
|
||||
load(QFileInfo fileinfo, bool& ok, bool add_to_scene){
|
||||
std::ifstream in(fileinfo.filePath().toUtf8());
|
||||
|
||||
if(!in)
|
||||
|
|
@ -38,16 +38,23 @@ Polyhedron_demo_off_to_nef_plugin::load(QFileInfo fileinfo) {
|
|||
{
|
||||
CGAL::Three::Three::warning( tr("The file you are trying to load is empty."));
|
||||
item->setName(fileinfo.completeBaseName());
|
||||
return item;
|
||||
ok = true;
|
||||
if(add_to_scene)
|
||||
CGAL::Three::Three::scene()->addItem(item);
|
||||
return QList<Scene_item*>()<<item;
|
||||
}
|
||||
if(!item->load_from_off(in))
|
||||
{
|
||||
delete item;
|
||||
return 0;
|
||||
ok = false;
|
||||
return QList<Scene_item*>()<<item;
|
||||
}
|
||||
|
||||
item->setName(fileinfo.baseName());
|
||||
return item;
|
||||
ok = true;
|
||||
if(add_to_scene)
|
||||
CGAL::Three::Three::scene()->addItem(item);
|
||||
return QList<Scene_item*>()<<item;
|
||||
}
|
||||
|
||||
bool Polyhedron_demo_off_to_nef_plugin::canSave(const CGAL::Three::Scene_item*)
|
||||
|
|
@ -55,7 +62,8 @@ bool Polyhedron_demo_off_to_nef_plugin::canSave(const CGAL::Three::Scene_item*)
|
|||
return false;
|
||||
}
|
||||
|
||||
bool Polyhedron_demo_off_to_nef_plugin::save(const CGAL::Three::Scene_item*, QFileInfo)
|
||||
bool Polyhedron_demo_off_to_nef_plugin::
|
||||
save(QFileInfo fileinfo,QList<CGAL::Three::Scene_item*>& items)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@
|
|||
#include <CGAL/IO/PLY_writer.h>
|
||||
#include <CGAL/Polygon_mesh_processing/polygon_soup_to_polygon_mesh.h>
|
||||
#include <QMessageBox>
|
||||
|
||||
using namespace CGAL::Three;
|
||||
class Polyhedron_demo_ply_plugin :
|
||||
public QObject,
|
||||
public CGAL::Three::Polyhedron_demo_io_plugin_interface
|
||||
|
|
@ -31,20 +31,22 @@ public:
|
|||
}
|
||||
QString name() const { return "ply_plugin"; }
|
||||
QString nameFilters() const { return "PLY files (*.ply)"; }
|
||||
bool canLoad() const;
|
||||
CGAL::Three::Scene_item* load(QFileInfo fileinfo);
|
||||
bool canLoad(QFileInfo fileinfo) const;
|
||||
QList<Scene_item*> load(QFileInfo fileinfo, bool& ok, bool add_to_scene=true);
|
||||
|
||||
bool canSave(const CGAL::Three::Scene_item*);
|
||||
bool save(const CGAL::Three::Scene_item*, QFileInfo fileinfo);
|
||||
bool save(QFileInfo fileinfo,QList<CGAL::Three::Scene_item*>&);
|
||||
|
||||
};
|
||||
|
||||
bool Polyhedron_demo_ply_plugin::canLoad() const {
|
||||
bool Polyhedron_demo_ply_plugin::
|
||||
canLoad(QFileInfo) const {
|
||||
return true;
|
||||
}
|
||||
|
||||
CGAL::Three::Scene_item*
|
||||
Polyhedron_demo_ply_plugin::load(QFileInfo fileinfo) {
|
||||
QList<Scene_item*>
|
||||
Polyhedron_demo_ply_plugin::
|
||||
load(QFileInfo fileinfo, bool& ok, bool add_to_scene) {
|
||||
std::ifstream in(fileinfo.filePath().toUtf8(), std::ios_base::binary);
|
||||
|
||||
if(!in)
|
||||
|
|
@ -55,7 +57,8 @@ Polyhedron_demo_ply_plugin::load(QFileInfo fileinfo) {
|
|||
if(fileinfo.size() == 0)
|
||||
{
|
||||
CGAL::Three::Three::warning( tr("The file you are trying to load is empty."));
|
||||
return 0;
|
||||
ok = false;
|
||||
return QList<Scene_item*>();
|
||||
}
|
||||
|
||||
// Test if input is mesh or point set
|
||||
|
|
@ -99,7 +102,10 @@ Polyhedron_demo_ply_plugin::load(QFileInfo fileinfo) {
|
|||
sm_item->setName(fileinfo.completeBaseName());
|
||||
sm_item->comments() = comments;
|
||||
QApplication::restoreOverrideCursor();
|
||||
return sm_item;
|
||||
ok = true;
|
||||
if(add_to_scene)
|
||||
CGAL::Three::Three::scene()->addItem(sm_item);
|
||||
return QList<Scene_item*>()<<sm_item;
|
||||
}
|
||||
|
||||
in.clear();
|
||||
|
|
@ -114,14 +120,18 @@ Polyhedron_demo_ply_plugin::load(QFileInfo fileinfo) {
|
|||
if (!(CGAL::read_PLY (in, points, polygons, fcolors, vcolors)))
|
||||
{
|
||||
QApplication::restoreOverrideCursor();
|
||||
return NULL;
|
||||
ok = false;
|
||||
return QList<Scene_item*>();
|
||||
}
|
||||
|
||||
Scene_polygon_soup_item* soup_item = new Scene_polygon_soup_item;
|
||||
soup_item->setName(fileinfo.completeBaseName());
|
||||
soup_item->load (points, polygons, fcolors, vcolors);
|
||||
QApplication::restoreOverrideCursor();
|
||||
return soup_item;
|
||||
ok = true;
|
||||
if(add_to_scene)
|
||||
CGAL::Three::Three::scene()->addItem(soup_item);
|
||||
return QList<Scene_item*>()<<soup_item;
|
||||
}
|
||||
else // Open point set
|
||||
{
|
||||
|
|
@ -131,16 +141,21 @@ Polyhedron_demo_ply_plugin::load(QFileInfo fileinfo) {
|
|||
{
|
||||
delete item;
|
||||
QApplication::restoreOverrideCursor();
|
||||
return NULL;
|
||||
ok = false;
|
||||
return QList<Scene_item*>();
|
||||
}
|
||||
if(item->has_normals())
|
||||
item->setRenderingMode(CGAL::Three::Three::defaultPointSetRenderingMode());
|
||||
item->setName(fileinfo.completeBaseName());
|
||||
QApplication::restoreOverrideCursor();
|
||||
return item;
|
||||
ok = true;
|
||||
if(add_to_scene)
|
||||
CGAL::Three::Three::scene()->addItem(item);
|
||||
return QList<Scene_item*>()<<item;
|
||||
}
|
||||
QApplication::restoreOverrideCursor();
|
||||
return NULL;
|
||||
ok = true;
|
||||
return QList<Scene_item*>();
|
||||
}
|
||||
|
||||
bool Polyhedron_demo_ply_plugin::canSave(const CGAL::Three::Scene_item* item)
|
||||
|
|
@ -152,8 +167,10 @@ bool Polyhedron_demo_ply_plugin::canSave(const CGAL::Three::Scene_item* item)
|
|||
|| qobject_cast<const Scene_textured_surface_mesh_item*>(item));
|
||||
}
|
||||
|
||||
bool Polyhedron_demo_ply_plugin::save(const CGAL::Three::Scene_item* item, QFileInfo fileinfo)
|
||||
bool Polyhedron_demo_ply_plugin::
|
||||
save(QFileInfo fileinfo,QList<CGAL::Three::Scene_item*>& items)
|
||||
{
|
||||
Scene_item* item = items.front();
|
||||
// Check extension (quietly)
|
||||
std::string extension = fileinfo.suffix().toUtf8().data();
|
||||
if (extension != "ply" && extension != "PLY")
|
||||
|
|
@ -179,25 +196,49 @@ bool Polyhedron_demo_ply_plugin::save(const CGAL::Three::Scene_item* item, QFile
|
|||
const Scene_points_with_normal_item* point_set_item =
|
||||
qobject_cast<const Scene_points_with_normal_item*>(item);
|
||||
if (point_set_item)
|
||||
return point_set_item->write_ply_point_set(out, (choice == tr("Binary")));
|
||||
{
|
||||
bool res =
|
||||
point_set_item->write_ply_point_set(out, (choice == tr("Binary")));
|
||||
if(res)
|
||||
items.pop_front();
|
||||
return res;
|
||||
}
|
||||
|
||||
// This plugin supports polygon soups
|
||||
const Scene_polygon_soup_item* soup_item =
|
||||
qobject_cast<const Scene_polygon_soup_item*>(item);
|
||||
if (soup_item)
|
||||
return CGAL::write_PLY (out, soup_item->points(), soup_item->polygons());
|
||||
{
|
||||
bool res =
|
||||
CGAL::write_PLY (out, soup_item->points(), soup_item->polygons());
|
||||
if(res)
|
||||
items.pop_front();
|
||||
return res;
|
||||
}
|
||||
|
||||
// This plugin supports surface meshes
|
||||
const Scene_surface_mesh_item* sm_item =
|
||||
qobject_cast<const Scene_surface_mesh_item*>(item);
|
||||
if (sm_item)
|
||||
return CGAL::write_ply (out, *(sm_item->polyhedron()), sm_item->comments());
|
||||
{
|
||||
bool res =
|
||||
CGAL::write_ply (out, *(sm_item->polyhedron()), sm_item->comments());
|
||||
if(res)
|
||||
items.pop_front();
|
||||
return res;
|
||||
}
|
||||
|
||||
// This plugin supports textured surface meshes
|
||||
const Scene_textured_surface_mesh_item* stm_item =
|
||||
qobject_cast<const Scene_textured_surface_mesh_item*>(item);
|
||||
if (stm_item)
|
||||
return CGAL::write_ply (out, *(stm_item->textured_face_graph()));
|
||||
{
|
||||
bool res =
|
||||
CGAL::write_ply (out, *(stm_item->textured_face_graph()));
|
||||
if(res)
|
||||
items.pop_front();
|
||||
return res;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -45,11 +45,11 @@ public:
|
|||
}
|
||||
QString name() const { return "polylines_io_plugin"; }
|
||||
QString nameFilters() const { return "Polylines files (*.polylines.txt *.cgal)"; }
|
||||
bool canLoad() const;
|
||||
CGAL::Three::Scene_item* load(QFileInfo fileinfo);
|
||||
bool canLoad(QFileInfo fileinfo) const;
|
||||
QList<Scene_item*> load(QFileInfo fileinfo, bool& ok, bool add_to_scene=true);
|
||||
|
||||
bool canSave(const CGAL::Three::Scene_item*);
|
||||
bool save(const CGAL::Three::Scene_item*, QFileInfo fileinfo);
|
||||
bool save(QFileInfo fileinfo,QList<CGAL::Three::Scene_item*>&);
|
||||
bool applicable(QAction* a) const {
|
||||
bool all_polylines_selected = true;
|
||||
Q_FOREACH(int index, scene->selectionIndices())
|
||||
|
|
@ -85,19 +85,21 @@ private:
|
|||
QAction* actionJoin_polylines;
|
||||
};
|
||||
|
||||
bool Polyhedron_demo_polylines_io_plugin::canLoad() const {
|
||||
bool Polyhedron_demo_polylines_io_plugin::canLoad(QFileInfo fileinfo) const{
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
CGAL::Three::Scene_item*
|
||||
Polyhedron_demo_polylines_io_plugin::load(QFileInfo fileinfo) {
|
||||
QList<Scene_item*>
|
||||
Polyhedron_demo_polylines_io_plugin::
|
||||
load(QFileInfo fileinfo, bool& ok, bool add_to_scene){
|
||||
|
||||
// Open file
|
||||
std::ifstream ifs(fileinfo.filePath().toUtf8());
|
||||
if(!ifs) {
|
||||
std::cerr << "Error! Cannot open file " << (const char*)fileinfo.filePath().toUtf8() << std::endl;
|
||||
return NULL;
|
||||
ok = false;
|
||||
return QList<Scene_item*>();
|
||||
}
|
||||
|
||||
if(fileinfo.size() == 0)
|
||||
|
|
@ -105,7 +107,10 @@ Polyhedron_demo_polylines_io_plugin::load(QFileInfo fileinfo) {
|
|||
CGAL::Three::Three::warning( tr("The file you are trying to load is empty."));
|
||||
Scene_polylines_item* item = new Scene_polylines_item;
|
||||
item->setName(fileinfo.completeBaseName());
|
||||
return item;
|
||||
ok = true;
|
||||
if(add_to_scene)
|
||||
CGAL::Three::Three::scene()->addItem(item);
|
||||
return QList<Scene_item*>()<<item;
|
||||
}
|
||||
|
||||
std::list<std::vector<Scene_polylines_item::Point_3> > polylines;
|
||||
|
|
@ -123,7 +128,11 @@ Polyhedron_demo_polylines_io_plugin::load(QFileInfo fileinfo) {
|
|||
Scene_polylines_item::Point_3 p;
|
||||
ifs >> p;
|
||||
polyline.push_back(p);
|
||||
if(!ifs.good()) return 0;
|
||||
if(!ifs.good())
|
||||
{
|
||||
ok = false;
|
||||
return QList<Scene_item*>();
|
||||
}
|
||||
}
|
||||
std::string line_remainder;
|
||||
std::getline(ifs, line_remainder);
|
||||
|
|
@ -136,9 +145,17 @@ Polyhedron_demo_polylines_io_plugin::load(QFileInfo fileinfo) {
|
|||
std::cerr << " (metadata: \"" << qPrintable(metadata) << "\")\n";
|
||||
} else {
|
||||
}
|
||||
if(ifs.bad() || ifs.fail()) return 0;
|
||||
if(ifs.bad() || ifs.fail())
|
||||
{
|
||||
ok = false;
|
||||
return QList<Scene_item*>();
|
||||
}
|
||||
}
|
||||
if(counter == 0)
|
||||
{
|
||||
ok = false;
|
||||
return QList<Scene_item*>();
|
||||
}
|
||||
if(counter == 0) return 0;
|
||||
Scene_polylines_item* item = new Scene_polylines_item;
|
||||
item->polylines = polylines;
|
||||
item->setName(fileinfo.baseName());
|
||||
|
|
@ -146,7 +163,10 @@ Polyhedron_demo_polylines_io_plugin::load(QFileInfo fileinfo) {
|
|||
item->setProperty("polylines metadata", polylines_metadata);
|
||||
std::cerr << "Number of polylines in item: " << item->polylines.size() << std::endl;
|
||||
item->invalidateOpenGLBuffers();
|
||||
return item;
|
||||
ok = true;
|
||||
if(add_to_scene)
|
||||
CGAL::Three::Three::scene()->addItem(item);
|
||||
return QList<Scene_item*>()<<item;
|
||||
}
|
||||
|
||||
bool Polyhedron_demo_polylines_io_plugin::canSave(const CGAL::Three::Scene_item* item)
|
||||
|
|
@ -154,8 +174,10 @@ bool Polyhedron_demo_polylines_io_plugin::canSave(const CGAL::Three::Scene_item*
|
|||
return qobject_cast<const Scene_polylines_item*>(item) != 0;
|
||||
}
|
||||
|
||||
bool Polyhedron_demo_polylines_io_plugin::save(const CGAL::Three::Scene_item* item, QFileInfo fileinfo)
|
||||
bool Polyhedron_demo_polylines_io_plugin::
|
||||
save(QFileInfo fileinfo,QList<CGAL::Three::Scene_item*>& items)
|
||||
{
|
||||
Scene_item* item = items.front();
|
||||
const Scene_polylines_item* poly_item =
|
||||
qobject_cast<const Scene_polylines_item*>(item);
|
||||
|
||||
|
|
@ -188,7 +210,10 @@ bool Polyhedron_demo_polylines_io_plugin::save(const CGAL::Three::Scene_item* it
|
|||
}
|
||||
out << std::endl;
|
||||
}
|
||||
return (bool) out;
|
||||
bool res = (bool) out;
|
||||
if(res)
|
||||
items.pop_front();
|
||||
return res;
|
||||
}
|
||||
|
||||
void Polyhedron_demo_polylines_io_plugin::split()
|
||||
|
|
|
|||
|
|
@ -47,44 +47,51 @@ public:
|
|||
bool applicable(QAction*) const { return false;}
|
||||
QString nameFilters() const;
|
||||
QString name() const { return "stl_plugin"; }
|
||||
bool canLoad() const;
|
||||
CGAL::Three::Scene_item* load(QFileInfo fileinfo);
|
||||
bool canLoad(QFileInfo fileinfo) const;
|
||||
QList<Scene_item*> load(QFileInfo fileinfo, bool& ok, bool add_to_scene=true);
|
||||
|
||||
bool canSave(const CGAL::Three::Scene_item*);
|
||||
bool save(const CGAL::Three::Scene_item*, QFileInfo fileinfo);
|
||||
bool save(QFileInfo fileinfo,QList<CGAL::Three::Scene_item*>&);
|
||||
};
|
||||
|
||||
QString Polyhedron_demo_stl_plugin::nameFilters() const {
|
||||
return "STL files (*.stl)";
|
||||
}
|
||||
|
||||
bool Polyhedron_demo_stl_plugin::canLoad() const {
|
||||
bool Polyhedron_demo_stl_plugin::canLoad(QFileInfo) const {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
CGAL::Three::Scene_item*
|
||||
Polyhedron_demo_stl_plugin::load(QFileInfo fileinfo) {
|
||||
|
||||
QList<Scene_item*>
|
||||
Polyhedron_demo_stl_plugin::
|
||||
load(QFileInfo fileinfo, bool& ok, bool add_to_scene){
|
||||
|
||||
// Open file
|
||||
std::ifstream in(fileinfo.filePath().toUtf8(), std::ios::in | std::ios::binary);
|
||||
if(!in) {
|
||||
std::cerr << "Error! Cannot open file " << (const char*)fileinfo.filePath().toUtf8() << std::endl;
|
||||
return NULL;
|
||||
ok = false;
|
||||
return QList<Scene_item*>();
|
||||
}
|
||||
if(fileinfo.size() == 0)
|
||||
{
|
||||
CGAL::Three::Three::warning( tr("The file you are trying to load is empty."));
|
||||
Scene_surface_mesh_item* item = new Scene_surface_mesh_item();
|
||||
item->setName(fileinfo.completeBaseName());
|
||||
return item;
|
||||
ok = true;
|
||||
if(add_to_scene)
|
||||
CGAL::Three::Three::scene()->addItem(item);
|
||||
return QList<Scene_item*>()<<item;
|
||||
}
|
||||
std::vector<std::array<double, 3> > points;
|
||||
std::vector<std::array<int, 3> > triangles;
|
||||
if (!CGAL::read_STL(in, points, triangles))
|
||||
{
|
||||
std::cerr << "Error: invalid STL file" << std::endl;
|
||||
return NULL;
|
||||
ok = false;
|
||||
return QList<Scene_item*>();
|
||||
}
|
||||
|
||||
try{
|
||||
|
|
@ -98,7 +105,10 @@ Polyhedron_demo_stl_plugin::load(QFileInfo fileinfo) {
|
|||
else{
|
||||
Scene_surface_mesh_item* item = new Scene_surface_mesh_item(SM);
|
||||
item->setName(fileinfo.completeBaseName());
|
||||
return item;
|
||||
ok = true;
|
||||
if(add_to_scene)
|
||||
CGAL::Three::Three::scene()->addItem(item);
|
||||
return QList<Scene_item*>()<<item;
|
||||
}
|
||||
}
|
||||
catch(...){}
|
||||
|
|
@ -106,7 +116,10 @@ Polyhedron_demo_stl_plugin::load(QFileInfo fileinfo) {
|
|||
Scene_polygon_soup_item* item = new Scene_polygon_soup_item();
|
||||
item->setName(fileinfo.completeBaseName());
|
||||
item->load(points, triangles);
|
||||
return item;
|
||||
ok = true;
|
||||
if(add_to_scene)
|
||||
CGAL::Three::Three::scene()->addItem(item);
|
||||
return QList<Scene_item*>()<<item;
|
||||
}
|
||||
|
||||
bool Polyhedron_demo_stl_plugin::canSave(const CGAL::Three::Scene_item* item)
|
||||
|
|
@ -114,8 +127,10 @@ bool Polyhedron_demo_stl_plugin::canSave(const CGAL::Three::Scene_item* item)
|
|||
return qobject_cast<const Scene_surface_mesh_item*>(item);
|
||||
}
|
||||
|
||||
bool Polyhedron_demo_stl_plugin::save(const CGAL::Three::Scene_item* item, QFileInfo fileinfo)
|
||||
bool Polyhedron_demo_stl_plugin::
|
||||
save(QFileInfo fileinfo,QList<CGAL::Three::Scene_item*>& items)
|
||||
{
|
||||
Scene_item* item = items.front();
|
||||
const Scene_surface_mesh_item* sm_item =
|
||||
qobject_cast<const Scene_surface_mesh_item*>(item);
|
||||
|
||||
|
|
@ -144,6 +159,7 @@ bool Polyhedron_demo_stl_plugin::save(const CGAL::Three::Scene_item* item, QFile
|
|||
if (sm_item)
|
||||
{
|
||||
CGAL::write_STL(*sm_item->face_graph(), out);
|
||||
items.pop_front();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
|
|
|||
|
|
@ -42,19 +42,34 @@ public:
|
|||
bool applicable(QAction*) const { return false;}
|
||||
QString name() const { return "surf_io_plugin"; }
|
||||
QString nameFilters() const { return "Amira files (*.surf)"; }
|
||||
bool canLoad() const{ return true; }
|
||||
bool canLoad(QFileInfo) const{ return true; }
|
||||
template<class FaceGraphItem>
|
||||
CGAL::Three::Scene_item* actual_load(QFileInfo fileinfo);
|
||||
CGAL::Three::Scene_item* load(QFileInfo fileinfo);
|
||||
QList<Scene_item*> load(QFileInfo fileinfo, bool& ok, bool add_to_scene=true);
|
||||
|
||||
bool canSave(const CGAL::Three::Scene_item*) { return false; }
|
||||
bool save(const CGAL::Three::Scene_item*, QFileInfo) { return false; }
|
||||
bool save(QFileInfo fileinfo,QList<CGAL::Three::Scene_item*>& ) { return false; }
|
||||
};
|
||||
|
||||
|
||||
CGAL::Three::Scene_item* Surf_io_plugin::load(QFileInfo fileinfo)
|
||||
QList<Scene_item*>
|
||||
Surf_io_plugin::
|
||||
load(QFileInfo fileinfo, bool& ok, bool add_to_scene)
|
||||
{
|
||||
return actual_load<Scene_surface_mesh_item>(fileinfo);
|
||||
Scene_item* item =
|
||||
actual_load<Scene_surface_mesh_item>(fileinfo);
|
||||
if(item)
|
||||
{
|
||||
ok = true;
|
||||
if(add_to_scene)
|
||||
CGAL::Three::Three::scene()->addItem(item);
|
||||
return QList<Scene_item*>()<<item;
|
||||
}
|
||||
else
|
||||
{
|
||||
ok = false;
|
||||
return QList<Scene_item*>();
|
||||
}
|
||||
}
|
||||
template< class FaceGraphItem>
|
||||
CGAL::Three::Scene_item* Surf_io_plugin::actual_load(QFileInfo fileinfo)
|
||||
|
|
|
|||
|
|
@ -21,26 +21,28 @@ public:
|
|||
|
||||
QString name() const { return "xyz_plugin"; }
|
||||
QString nameFilters() const { return "XYZ as Point Set (*.xyz);;Point Set with Normal (*.pwn)"; }
|
||||
bool canLoad() const;
|
||||
CGAL::Three::Scene_item* load(QFileInfo fileinfo);
|
||||
bool canLoad(QFileInfo) const;
|
||||
QList<Scene_item*> load(QFileInfo fileinfo, bool& ok, bool add_to_scene=true);
|
||||
|
||||
bool canSave(const CGAL::Three::Scene_item*);
|
||||
bool save(const CGAL::Three::Scene_item*, QFileInfo fileinfo);
|
||||
bool save(QFileInfo fileinfo,QList<CGAL::Three::Scene_item*>&);
|
||||
};
|
||||
|
||||
bool Polyhedron_demo_xyz_plugin::canLoad() const {
|
||||
bool Polyhedron_demo_xyz_plugin::canLoad(QFileInfo) const {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
CGAL::Three::Scene_item*
|
||||
Polyhedron_demo_xyz_plugin::load(QFileInfo fileinfo)
|
||||
QList<Scene_item*>
|
||||
Polyhedron_demo_xyz_plugin::
|
||||
load(QFileInfo fileinfo, bool& ok, bool add_to_scene)
|
||||
{
|
||||
// Open file
|
||||
std::ifstream in(fileinfo.filePath().toUtf8().data());
|
||||
if(!in) {
|
||||
std::cerr << "Error! Cannot open file " << fileinfo.filePath().toStdString() << std::endl;
|
||||
return NULL;
|
||||
ok = false;
|
||||
return QList<Scene_item*>();
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -50,19 +52,26 @@ Polyhedron_demo_xyz_plugin::load(QFileInfo fileinfo)
|
|||
Scene_points_with_normal_item* item =
|
||||
new Scene_points_with_normal_item();
|
||||
item->setName(fileinfo.completeBaseName());
|
||||
return item;
|
||||
ok = true;
|
||||
if(add_to_scene)
|
||||
CGAL::Three::Three::scene()->addItem(item);
|
||||
return QList<Scene_item*>()<<item;
|
||||
}
|
||||
// Read .xyz in a point set
|
||||
Scene_points_with_normal_item* point_set_item = new Scene_points_with_normal_item;
|
||||
point_set_item->setName(fileinfo.completeBaseName());
|
||||
if(!point_set_item->read_xyz_point_set(in)) {
|
||||
delete point_set_item;
|
||||
return NULL;
|
||||
ok = false;
|
||||
return QList<Scene_item*>();
|
||||
}
|
||||
if(point_set_item->has_normals())
|
||||
point_set_item->setRenderingMode(CGAL::Three::Three::defaultPointSetRenderingMode());
|
||||
|
||||
return point_set_item;
|
||||
ok = true;
|
||||
if(add_to_scene)
|
||||
CGAL::Three::Three::scene()->addItem(point_set_item);
|
||||
return QList<Scene_item*>()<<point_set_item;
|
||||
}
|
||||
|
||||
bool Polyhedron_demo_xyz_plugin::canSave(const CGAL::Three::Scene_item* item)
|
||||
|
|
@ -71,8 +80,10 @@ bool Polyhedron_demo_xyz_plugin::canSave(const CGAL::Three::Scene_item* item)
|
|||
return qobject_cast<const Scene_points_with_normal_item*>(item);
|
||||
}
|
||||
|
||||
bool Polyhedron_demo_xyz_plugin::save(const CGAL::Three::Scene_item* item, QFileInfo fileinfo)
|
||||
bool Polyhedron_demo_xyz_plugin::
|
||||
save(QFileInfo fileinfo,QList<CGAL::Three::Scene_item*>& items)
|
||||
{
|
||||
Scene_item* item = items.front();
|
||||
// Check extension (quietly)
|
||||
std::string extension = fileinfo.suffix().toUtf8().data();
|
||||
if (extension != "xyz" && extension != "XYZ" &&
|
||||
|
|
@ -88,7 +99,10 @@ bool Polyhedron_demo_xyz_plugin::save(const CGAL::Three::Scene_item* item, QFile
|
|||
// Save point set as .xyz
|
||||
std::ofstream out(fileinfo.filePath().toUtf8().data());
|
||||
out.precision (std::numeric_limits<double>::digits10 + 2);
|
||||
return point_set_item->write_xyz_point_set(out);
|
||||
bool res = point_set_item->write_xyz_point_set(out);
|
||||
if(res)
|
||||
items.pop_front();
|
||||
return res;
|
||||
}
|
||||
|
||||
#include "XYZ_io_plugin.moc"
|
||||
|
|
|
|||
|
|
@ -33,13 +33,14 @@ public:
|
|||
"3-map files (*.3map)";
|
||||
}
|
||||
|
||||
bool canLoad() const { return true; }
|
||||
CGAL::Three::Scene_item* load(QFileInfo fileinfo){
|
||||
bool canLoad(QFileInfo) const { return true; }
|
||||
QList<CGAL::Three::Scene_item*> load(QFileInfo fileinfo, bool& ok, bool add_to_scene=true){
|
||||
// Open file
|
||||
std::ifstream ifs(fileinfo.filePath().toUtf8());
|
||||
if(!ifs) {
|
||||
std::cerr << "Error! Cannot open file " << (const char*)fileinfo.filePath().toUtf8() << std::endl;
|
||||
return nullptr;
|
||||
ok = false;
|
||||
return QList<CGAL::Three::Scene_item*>();
|
||||
}
|
||||
|
||||
Scene_lcc_item::LCC lcc;
|
||||
|
|
@ -53,17 +54,21 @@ public:
|
|||
}
|
||||
if(!res)
|
||||
{
|
||||
return nullptr;
|
||||
ok = false;
|
||||
return QList<CGAL::Three::Scene_item*>();
|
||||
}
|
||||
Scene_lcc_item* new_item = new Scene_lcc_item(lcc);
|
||||
new_item->setName(fileinfo.fileName());
|
||||
new_item->invalidateOpenGLBuffers();
|
||||
return new_item;
|
||||
if(add_to_scene)
|
||||
CGAL::Three::Three::scene()->addItem(new_item);
|
||||
ok = true;
|
||||
return QList<CGAL::Three::Scene_item*>()<<new_item;
|
||||
}
|
||||
|
||||
|
||||
bool canSave(const CGAL::Three::Scene_item*){return false;}
|
||||
bool save(const CGAL::Three::Scene_item*, QFileInfo){
|
||||
bool save(QFileInfo, QList<CGAL::Three::Scene_item*>& ){
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -37,11 +37,11 @@ public:
|
|||
{
|
||||
return false;
|
||||
}
|
||||
bool canLoad() const;
|
||||
CGAL::Three::Scene_item* load(QFileInfo fileinfo);
|
||||
bool canLoad(QFileInfo) const;
|
||||
QList<Scene_item*> load(QFileInfo fileinfo, bool& ok, bool add_to_scene=true);
|
||||
|
||||
bool canSave(const CGAL::Three::Scene_item*);
|
||||
bool save(const CGAL::Three::Scene_item*, QFileInfo fileinfo);
|
||||
bool save(QFileInfo fileinfo,QList<CGAL::Three::Scene_item*>& );
|
||||
|
||||
private:
|
||||
bool try_load_other_binary_format(std::istream& in, C3t3& c3t3);
|
||||
|
|
@ -50,21 +50,23 @@ private:
|
|||
};
|
||||
|
||||
|
||||
bool Polyhedron_demo_c3t3_binary_io_plugin::canLoad() const {
|
||||
bool Polyhedron_demo_c3t3_binary_io_plugin::canLoad(QFileInfo) const {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
CGAL::Three::Scene_item*
|
||||
Polyhedron_demo_c3t3_binary_io_plugin::load(QFileInfo fileinfo) {
|
||||
QList<Scene_item*>
|
||||
Polyhedron_demo_c3t3_binary_io_plugin::load(
|
||||
QFileInfo fileinfo, bool& ok, bool add_to_scene) {
|
||||
|
||||
// Open file
|
||||
ok = true;
|
||||
std::ifstream in(fileinfo.filePath().toUtf8(),
|
||||
std::ios_base::in|std::ios_base::binary);
|
||||
if(!in) {
|
||||
std::cerr << "Error! Cannot open file "
|
||||
<< (const char*)fileinfo.filePath().toUtf8() << std::endl;
|
||||
return NULL;
|
||||
ok = false;
|
||||
return QList<Scene_item*>();
|
||||
}
|
||||
Scene_c3t3_item* item = new Scene_c3t3_item();
|
||||
|
||||
|
|
@ -72,7 +74,9 @@ Polyhedron_demo_c3t3_binary_io_plugin::load(QFileInfo fileinfo) {
|
|||
{
|
||||
CGAL::Three::Three::warning( tr("The file you are trying to load is empty."));
|
||||
item->setName(fileinfo.completeBaseName());
|
||||
return item;
|
||||
if(add_to_scene)
|
||||
CGAL::Three::Three::scene()->addItem(item);
|
||||
return QList<Scene_item*>()<< item;
|
||||
}
|
||||
if(fileinfo.suffix().toLower() == "cgal")
|
||||
{
|
||||
|
|
@ -80,7 +84,9 @@ Polyhedron_demo_c3t3_binary_io_plugin::load(QFileInfo fileinfo) {
|
|||
|
||||
|
||||
if(item->load_binary(in)) {
|
||||
return item;
|
||||
if(add_to_scene)
|
||||
CGAL::Three::Three::scene()->addItem(item);
|
||||
return QList<Scene_item*>() << item;
|
||||
}
|
||||
|
||||
item->c3t3().clear();
|
||||
|
|
@ -89,7 +95,9 @@ Polyhedron_demo_c3t3_binary_io_plugin::load(QFileInfo fileinfo) {
|
|||
item->c3t3_changed();
|
||||
item->changed();
|
||||
item->resetCutPlane();
|
||||
return item;
|
||||
if(add_to_scene)
|
||||
CGAL::Three::Three::scene()->addItem(item);
|
||||
return QList<Scene_item*>()<< item;
|
||||
}
|
||||
|
||||
item->c3t3().clear();
|
||||
|
|
@ -98,7 +106,9 @@ Polyhedron_demo_c3t3_binary_io_plugin::load(QFileInfo fileinfo) {
|
|||
item->c3t3_changed();
|
||||
item->changed();
|
||||
item->resetCutPlane();
|
||||
return item;
|
||||
if(add_to_scene)
|
||||
CGAL::Three::Three::scene()->addItem(item);
|
||||
return QList<Scene_item*>()<<item;
|
||||
}
|
||||
}
|
||||
else if (fileinfo.suffix().toLower() == "mesh")
|
||||
|
|
@ -154,7 +164,9 @@ Polyhedron_demo_c3t3_binary_io_plugin::load(QFileInfo fileinfo) {
|
|||
|
||||
item->c3t3_changed();
|
||||
item->resetCutPlane();
|
||||
return item;
|
||||
if(add_to_scene)
|
||||
CGAL::Three::Three::scene()->addItem(item);
|
||||
return QList<Scene_item*>()<<item;
|
||||
}
|
||||
else if(item->c3t3().triangulation().number_of_finite_cells() == 0)
|
||||
{
|
||||
|
|
@ -168,7 +180,8 @@ Polyhedron_demo_c3t3_binary_io_plugin::load(QFileInfo fileinfo) {
|
|||
|
||||
// if all loading failed...
|
||||
delete item;
|
||||
return NULL;
|
||||
ok = false;
|
||||
return QList<Scene_item*>();
|
||||
}
|
||||
|
||||
bool Polyhedron_demo_c3t3_binary_io_plugin::canSave(const CGAL::Three::Scene_item* item)
|
||||
|
|
@ -179,51 +192,63 @@ bool Polyhedron_demo_c3t3_binary_io_plugin::canSave(const CGAL::Three::Scene_ite
|
|||
|
||||
bool
|
||||
Polyhedron_demo_c3t3_binary_io_plugin::
|
||||
save(const CGAL::Three::Scene_item* item, QFileInfo fileinfo)
|
||||
save(QFileInfo fileinfo, QList<Scene_item *> &items)
|
||||
{
|
||||
const Scene_c3t3_item* c3t3_item = qobject_cast<const Scene_c3t3_item*>(item);
|
||||
if ( NULL == c3t3_item )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
Scene_item* item = items.front();
|
||||
const Scene_c3t3_item* c3t3_item = qobject_cast<const Scene_c3t3_item*>(item);
|
||||
if ( NULL == c3t3_item )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
QString path = fileinfo.absoluteFilePath();
|
||||
QString path = fileinfo.absoluteFilePath();
|
||||
|
||||
if(path.endsWith(".cgal"))
|
||||
{
|
||||
if(path.endsWith(".cgal"))
|
||||
{
|
||||
std::ofstream out(fileinfo.filePath().toUtf8(),
|
||||
std::ios_base::out|std::ios_base::binary);
|
||||
std::ios_base::out|std::ios_base::binary);
|
||||
|
||||
return out && c3t3_item->save_binary(out);
|
||||
}
|
||||
|
||||
else if (fileinfo.suffix() == "mesh")
|
||||
{
|
||||
std::ofstream medit_file (qPrintable(path));
|
||||
c3t3_item->c3t3().output_to_medit(medit_file,true,true);
|
||||
return true;
|
||||
}
|
||||
else if (fileinfo.suffix() == "ma")
|
||||
{
|
||||
std::ofstream maya_file (qPrintable(path));
|
||||
c3t3_item->c3t3().output_to_maya(
|
||||
maya_file,true);
|
||||
return true;
|
||||
}
|
||||
else if (fileinfo.suffix() == "am")
|
||||
{
|
||||
std::ofstream avizo_file (qPrintable(path));
|
||||
CGAL::output_to_avizo(avizo_file, c3t3_item->c3t3());
|
||||
return true;
|
||||
}
|
||||
else if (fileinfo.suffix() == "off")
|
||||
{
|
||||
std::ofstream off_file(qPrintable(path));
|
||||
c3t3_item->c3t3().output_facets_in_complex_to_off(off_file);
|
||||
return true;
|
||||
}
|
||||
bool ok = out && c3t3_item->save_binary(out);
|
||||
if(!ok)
|
||||
return false;
|
||||
else
|
||||
return false;
|
||||
{
|
||||
items.pop_front();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
else if (fileinfo.suffix() == "mesh")
|
||||
{
|
||||
std::ofstream medit_file (qPrintable(path));
|
||||
c3t3_item->c3t3().output_to_medit(medit_file,true,true);
|
||||
items.pop_front();
|
||||
return true;
|
||||
}
|
||||
else if (fileinfo.suffix() == "ma")
|
||||
{
|
||||
std::ofstream maya_file (qPrintable(path));
|
||||
c3t3_item->c3t3().output_to_maya(
|
||||
maya_file,true);
|
||||
items.pop_front();
|
||||
return true;
|
||||
}
|
||||
else if (fileinfo.suffix() == "am")
|
||||
{
|
||||
std::ofstream avizo_file (qPrintable(path));
|
||||
CGAL::output_to_avizo(avizo_file, c3t3_item->c3t3());
|
||||
items.pop_front();
|
||||
return true;
|
||||
}
|
||||
else if (fileinfo.suffix() == "off")
|
||||
{
|
||||
std::ofstream off_file(qPrintable(path));
|
||||
c3t3_item->c3t3().output_facets_in_complex_to_off(off_file);
|
||||
items.pop_front();
|
||||
return true;
|
||||
}
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
struct Fake_mesh_domain {
|
||||
|
|
|
|||
|
|
@ -282,15 +282,18 @@ public:
|
|||
Io_image_plugin() : planeSwitch(NULL) {}
|
||||
|
||||
QString nameFilters() const;
|
||||
bool canLoad() const;
|
||||
CGAL::Three::Scene_item* load(QFileInfo fileinfo);
|
||||
bool canLoad(QFileInfo) const;
|
||||
QList<Scene_item*> load(QFileInfo fileinfo, bool& ok, bool add_to_scene=true);
|
||||
|
||||
bool canSave(const CGAL::Three::Scene_item*);
|
||||
bool save(const CGAL::Three::Scene_item* item, QFileInfo fi) {
|
||||
bool save(QFileInfo fileinfo, QList<CGAL::Three::Scene_item*>& items ) {
|
||||
Scene_item* item = items.front();
|
||||
const Scene_image_item* im_item = qobject_cast<const Scene_image_item*>(item);
|
||||
|
||||
point_image p_im = *im_item->image()->image();
|
||||
return _writeImage(&p_im, fi.filePath().toUtf8()) == 0;
|
||||
bool ok = _writeImage(&p_im, fileinfo.filePath().toUtf8()) == 0;
|
||||
items.pop_front();
|
||||
return ok;
|
||||
}
|
||||
QString name() const { return "segmented images"; }
|
||||
|
||||
|
|
@ -965,7 +968,7 @@ QString Io_image_plugin::nameFilters() const {
|
|||
}
|
||||
|
||||
|
||||
bool Io_image_plugin::canLoad() const {
|
||||
bool Io_image_plugin::canLoad(QFileInfo) const {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
@ -987,8 +990,11 @@ void convert(Image* image)
|
|||
image->image()->wdim = 4;
|
||||
image->image()->wordKind = WK_FLOAT;
|
||||
}
|
||||
CGAL::Three::Scene_item*
|
||||
Io_image_plugin::load(QFileInfo fileinfo) {
|
||||
|
||||
QList<Scene_item*>
|
||||
Io_image_plugin::load(QFileInfo fileinfo, bool& ok, bool add_to_scene)
|
||||
{
|
||||
ok = true;
|
||||
QApplication::restoreOverrideCursor();
|
||||
Image* image = new Image;
|
||||
if(fileinfo.suffix() != "H" && fileinfo.suffix() != "HH" &&
|
||||
|
|
@ -1075,8 +1081,9 @@ Io_image_plugin::load(QFileInfo fileinfo) {
|
|||
success = false;
|
||||
}
|
||||
if(!success){
|
||||
ok = false;
|
||||
delete image;
|
||||
return NULL;
|
||||
return QList<Scene_item*>();
|
||||
}
|
||||
}
|
||||
//read a sep file
|
||||
|
|
@ -1117,7 +1124,8 @@ Io_image_plugin::load(QFileInfo fileinfo) {
|
|||
if(return_code != QDialog::Accepted)
|
||||
{
|
||||
delete image;
|
||||
return NULL;
|
||||
ok = false;
|
||||
return QList<Scene_item*>();
|
||||
}
|
||||
|
||||
// Get selected precision
|
||||
|
|
@ -1145,7 +1153,9 @@ Io_image_plugin::load(QFileInfo fileinfo) {
|
|||
else
|
||||
image_item = new Scene_image_item(image,voxel_scale, false);
|
||||
image_item->setName(fileinfo.baseName());
|
||||
return image_item;
|
||||
if(add_to_scene)
|
||||
CGAL::Three::Three::scene()->addItem(image_item);
|
||||
return QList<Scene_item*>() << image_item;
|
||||
}
|
||||
|
||||
bool Io_image_plugin::canSave(const CGAL::Three::Scene_item* item)
|
||||
|
|
|
|||
|
|
@ -78,7 +78,7 @@ public:
|
|||
QString nameFilters() const { return "Selection files(*.selection.txt)"; }
|
||||
QString name() const { return "selection_sm_plugin"; }
|
||||
|
||||
bool canLoad() const {
|
||||
bool canLoad(QFileInfo) const {
|
||||
Scene_item * item = CGAL::Three::Three::scene()->item(
|
||||
CGAL::Three::Three::scene()->mainSelectionIndex());
|
||||
Scene_facegraph_item* fg_item = qobject_cast<Scene_facegraph_item*>(item);
|
||||
|
|
@ -91,26 +91,38 @@ public:
|
|||
return false;
|
||||
}
|
||||
|
||||
CGAL::Three::Scene_item* load(QFileInfo fileinfo) {
|
||||
if(fileinfo.suffix().toLower() != "txt") return 0;
|
||||
QList<Scene_item*> load(QFileInfo fileinfo, bool& ok, bool add_to_scene=true) {
|
||||
if(fileinfo.suffix().toLower() != "txt")
|
||||
{
|
||||
ok = false;
|
||||
return QList<Scene_item*>();
|
||||
}
|
||||
// There will be no actual loading at this step.
|
||||
Scene_polyhedron_selection_item* item = new Scene_polyhedron_selection_item();
|
||||
if(!item->load(fileinfo.filePath().toStdString())) {
|
||||
delete item;
|
||||
return NULL;
|
||||
ok = false;
|
||||
return QList<Scene_item*>();
|
||||
}
|
||||
item->setName(fileinfo.baseName());
|
||||
return item;
|
||||
ok = true;
|
||||
if(add_to_scene)
|
||||
CGAL::Three::Three::scene()->addItem(item);
|
||||
return QList<Scene_item*>()<<item;
|
||||
}
|
||||
|
||||
bool canSave(const CGAL::Three::Scene_item* scene_item) {
|
||||
return qobject_cast<const Scene_polyhedron_selection_item*>(scene_item);
|
||||
}
|
||||
bool save(const CGAL::Three::Scene_item* scene_item, QFileInfo fileinfo) {
|
||||
bool save(QFileInfo fileinfo,QList<CGAL::Three::Scene_item*>& items) {
|
||||
Scene_item* scene_item = items.front();
|
||||
const Scene_polyhedron_selection_item* item = qobject_cast<const Scene_polyhedron_selection_item*>(scene_item);
|
||||
if(item == NULL) { return false; }
|
||||
|
||||
return item->save(fileinfo.filePath().toStdString());
|
||||
bool res = item->save(fileinfo.filePath().toStdString());
|
||||
if(res)
|
||||
items.pop_front();
|
||||
return res;
|
||||
}
|
||||
|
||||
bool applicable(QAction*) const {
|
||||
|
|
|
|||
|
|
@ -58,17 +58,23 @@ public:
|
|||
|
||||
//! Specifies if the io_plugin is able to load an item or not.
|
||||
//! This must be overriden.
|
||||
virtual bool canLoad() const = 0;
|
||||
//! Loads an item from a file.
|
||||
virtual bool canLoad(QFileInfo fileinfo) const = 0;
|
||||
//! Loads one or more item(s) from a file. `ok` is `true` if the loading
|
||||
//! was successful, `false` otherwise.
|
||||
//! New items will be added to the scene if `add_to_scene` is `true`.
|
||||
//! You don't want that when you reload an item, for example,
|
||||
//! as it will be added at some other point of the process.
|
||||
//! This must be overriden.
|
||||
virtual Scene_item* load(QFileInfo fileinfo) = 0;
|
||||
virtual QList<Scene_item*> load(QFileInfo fileinfo, bool& ok, bool add_to_scene=true) = 0;
|
||||
//!Specifies if the io_plugin can save the item or not.
|
||||
//!This must be overriden.
|
||||
virtual bool canSave(const Scene_item*) = 0;
|
||||
//!Saves the item in the file corresponding to the path
|
||||
//!Saves one or more items in the file corresponding to the path
|
||||
//!contained in fileinfo. Returns false if error.
|
||||
//! This must be overriden.
|
||||
virtual bool save(const Scene_item*, QFileInfo fileinfo) = 0;
|
||||
//! @attention When a file is successfully saved, it must be removed from the
|
||||
//! list.
|
||||
virtual bool save(QFileInfo fileinfo,QList<CGAL::Three::Scene_item*>& ) = 0;
|
||||
|
||||
//! If this returns `true`, then the loader will be chosen as default in the
|
||||
//! list of available loaders when saving a file, which means it will be the
|
||||
|
|
|
|||
|
|
@ -0,0 +1,4 @@
|
|||
#ifndef SCENE_3MF_ITEM_INTERFACE_H
|
||||
#define SCENE_3MF_ITEM_INTERFACE_H
|
||||
|
||||
#endif // SCENE_3MF_ITEM_INTERFACE_H
|
||||
Loading…
Reference in New Issue