MorphoGraphX  2.0-1-227
SystemProcessSave.hpp
Go to the documentation of this file.
1 //
2 // This file is part of MorphoGraphX - http://www.MorphoGraphX.org
3 // Copyright (C) 2012-2016 Richard S. Smith and collaborators.
4 //
5 // If you use MorphoGraphX in your work, please cite:
6 // http://dx.doi.org/10.7554/eLife.05864
7 //
8 // MorphoGraphX is free software, and is licensed under under the terms of the
9 // GNU General (GPL) Public License version 2.0, http://www.gnu.org/licenses.
10 //
11 #ifndef SYSTEMPROCESSSAVE_HPP
12 #define SYSTEMPROCESSSAVE_HPP
13 
14 #include <Process.hpp>
15 
16 #include <QFileDialog>
17 #include <QRegExp>
18 #include <GraphUtils.hpp>
19 #include <QTreeWidget>
20 
26 class QDialog;
27 class Ui_SaveMeshDialog;
28 class Ui_ExportMeshDialog;
29 class Ui_ExportStackDialog;
30 class Ui_PlyCellGraphDlg;
31 
32 namespace mgx
33 {
34 
89  class mgx_EXPORT StackSave : public Process {
90  public:
91  StackSave(const Process& proc) : Process(proc)
92  {
93  setName("Stack/System/Save");
94  setDesc("Save a stack into a known 3D image format");
95 
96  addParm("Filename","Filename",""); // 0
97  addParm("Store","Store","Main", storeChoice()); // 1
98  addParm("Stack Number","Stack number","0"); // 2
99  addParm("Compression Level","Compression level, from 0 to 9","5"); // 3
100  addParm("HDF5 DataSetName","HDF5 DataSetName","/label"); // 4
101  }
102 
103  bool initialize(QWidget* parent);
104 
105  bool run();
113  bool run(Stack* stack, Store* store, const QString& filename, int compressionLevel = 0);
114  QIcon icon() const { return QIcon(":/images/save.png"); }
115  };
116 
124  class mgx_EXPORT StackExport : public Process {
125  Q_OBJECT
126  public:
127  StackExport(const Process& proc) : Process(proc)
128  {
129  setName("Stack/System/Export");
130  setDesc("Export a stack into an image sequence.");
131 
132  addParm("Filename","Filename",""); // 0
133  addParm("Store","Store","Main", storeChoice()); // 1
134  addParm("Format","Format","CImg Auto"); // 2
135  addParm("Generate Voxel Spacing","Generate Voxel Spacing","No", booleanChoice()); // 3
136  addParm("Stack Number","Stack number","0"); // 4
137  addParm("Num Digits","Number of digits for file numbering","0"); // 5
138  }
139 
140  bool initialize(QWidget* parent);
141 
142  bool run();
156  bool run(Stack* stack, Store* store, const QString& filename, const QString& type,
157  unsigned int nb_digit, bool generate_voxel_spacing);
158  QIcon icon() const { return QIcon(":/images/save.png"); }
159 
160  protected slots:
161  void selectImageFile();
162  void setImageType(const QString& type);
163 
164  protected:
165  Ui_ExportStackDialog* ui;
166  QDialog* dlg;
167  };
168 
238  class mgx_EXPORT MeshSave : public Process {
239  Q_OBJECT
240  public:
241  MeshSave(const Process& proc) : Process(proc)
242  {
243  setName("Mesh/System/Save");
244  setDesc("Save a mesh into a known mesh format");
245 
246  addParm("Filename","Filename",""); // 0
247  addParm("Transform","Transform","No", booleanChoice()); // 1
248  addParm("Mesh Number","Mesh number","0", QStringList() << "0" << "1"); // 2
249  }
250 
251  bool run();
258  bool run(Mesh* mesh, const QString& filename, bool transform);
259  QIcon icon() const { return QIcon(":/images/save.png"); }
260  bool initialize(QWidget* parent);
261 
262  protected slots:
263  void selectMeshFile();
264 
265  protected:
266  QString properFile(QString filename) const;
267  void setMeshFile(const QString& filename);
268  Point3d savedPos(Point3d pos, bool transform, const Stack* stack);
269 
270  bool saveMesh(Mesh* mesh, const QString& filename, bool transform);
271 
272  QDialog* dlg;
273  Ui_SaveMeshDialog* ui;
274  };
275 
276 
431  bool savePLYCellGraph(Mesh* mesh, const QString& filename, bool binary);
432 
433  class mgx_EXPORT MeshExport : public Process {
434  Q_OBJECT
435  public:
436  MeshExport(const Process& proc) : Process(proc)
437  {
438  setName("Mesh/System/Export");
439  setDesc("Export a mesh into a known mesh format");
440 
441  addParm("Filename","Filename",""); // 0
442  addParm("Kind","Kind","Text", QStringList() << "PLY Binary" << "PLY Ascii" << "VTK Mesh Binary"
443  << "VTK Mesh Ascii" << "Text" << "Cells" << "MeshEdit" << "STL" << "OBJ"); // 1
444  addParm("Transform","Transform","no", booleanChoice()); // 2
445  addParm("Mesh Number","Mesh number","0", booleanChoice()); // 3
446  addParm("Extended PLY","If the PLY format is chosen, save a mesh file with extended information","No", booleanChoice()); // 2
447  }
448 
449  bool run();
457  bool run(Mesh* mesh, const QString& filename, const QString& type, bool transform);
458  QIcon icon() const { return QIcon(":/images/save.png"); }
459  bool initialize(QWidget* parent);
460 
461  bool savePLY(Mesh* mesh, const QString& filename, bool transform, bool binary = false); // Soeren: made public to be accessible by new 2-file Ply process in HeatMap
462 
463  protected slots:
464  void selectMeshFile();
465  void selectMeshType(const QString& type);
466 
467  protected:
468  QString properFile(QString filename, const QString& type) const;
469  void setMeshFile(const QString& filename);
470  Point3d savedPos(Point3d pos, bool transform, const Stack* stack);
471 
472  bool saveText(Mesh* mesh, const QString& filename, bool transform);
473  bool saveCells(Mesh* mesh, const QString& filename, bool transform);
474  bool saveMeshEdit(Mesh* mesh, const QString& filename, bool transform);
475  bool saveMeshSTL(Mesh* mesh, const QString& filename, bool transform);
476  bool saveVTU(Mesh* mesh, const QString& filename, bool transform, bool binary = false);
477  bool saveOBJ(Mesh* mesh, const QString& filename, bool transform);
478 
479  QDialog* dlg;
480  Ui_ExportMeshDialog* ui;
481 
482  bool extendedPLY = false;
483  };
484 
492  class mgx_EXPORT SaveViewFile : public Process {
493  public:
494  SaveViewFile(const Process& proc) : Process(proc)
495  {
496  setName("Misc/System/Save View");
497  setDesc("Save the view file for the current configuration.");
498 
499  addParm("Filename","Filename",""); // 0
500  }
501 
502  bool run();
507  bool run(const QString& filename);
508 
509  bool initialize(QWidget* parent);
510 
511  QIcon icon() const { return QIcon(":/images/save.png"); }
512  };
513 
521  class mgx_EXPORT QuickSaveFile : public Process {
522  public:
523  QuickSaveFile(const Process& proc) : Process(proc)
524  {
525  setName("Misc/System/Quick Save");
526  setDesc("Save all active mesh, stack and view files.");
527 
528  addParm("Save with File Extensions","Save with File Extensions","No", booleanChoice()); // 0
529  addParm("Extension Counter","Extension Counter","1"); // 1
530  }
531 
532  void saveStore(int stackNr, Store* store, int compressionLevel);
533  void saveMesh(int meshNr);
534 
535  QString addIncSuffix(QString filename, QString fileExtension);
536 
539 
540  bool initialize(QWidget* parent);
541 
546  bool run();
547 
548  QIcon icon() const { return QIcon(":/images/save.png"); }
549  };
550 
573  class mgx_EXPORT TakeSnapshot : public Process {
574  public:
575  TakeSnapshot(const Process& proc) : Process(proc)
576  {
577  setName("Misc/System/Snapshot");
578  setDesc("Take a snapshot of the current view");
579 
580  addParm("Filename","Filename",""); // 0
581  addParm("Expand Frustum","Expand Frustum","false"); // 1
582  addParm("Width","Width","0"); // 2
583  addParm("Height","Height","0"); // 3
584  addParm("Oversampling","Oversampling","1.0"); // 4
585  addParm("Quality","Quality","95"); // 5
586  }
587 
588  bool run()
589  {
590  QString filename = parm("Filename");
591  if(filename.isEmpty())
592  return setErrorMessage("Error, no file name specified.");
593  int width = parm("Width").toInt();
594  int height = parm("Height").toInt();
595  float overSampling = parm("Oversampling").toFloat();
596  int quality = parm("Quality").toInt();
597  bool expand_frustum = stringToBool(parm("Expand Frustum"));
598  return run(filename, overSampling, width, height, quality, expand_frustum);
599  }
600 
601  bool run(QString filename, float overSampling, int width, int height, int quality, bool expand_frustum);
602 
603  QIcon icon() const { return QIcon(":/images/SaveScreenshot.png"); }
604  };
605 
606 
612  class mgx_EXPORT StackOpenSaveFolder : public Process {
613  public:
614  StackOpenSaveFolder(const Process& proc) : Process(proc)
615  {
616  setName("Stack/System/Batch Open and Save");
617  setDesc("Opens and saves a compressed TIFF for all tif stacks of a folder");
618 
619  addParm("Folder","Folder",""); // 0
620  addParm("File Prefix","File Prefix for new files","MGX_"); // 1
621  addParm("Compression Level","Compression Level (-1 to 9)","9"); // 2
622  }
623 
624  bool run();
625 
626  QStringList images;
627 
628  bool initialize(QWidget* parent);
629  QIcon icon() const { return QIcon(":/images/open.png"); }
630  };
631 
632  class CellGraph3D : public Process
633  {
634  public:
635  CellGraph3D(const Process& process) : Process(process)
636  {
637  setName("Mesh/Export/Cell Graph 3D");
638  setDesc("Export the 3D cell graph");
639  setIcon(QIcon(":/images/CellGraph3D.png"));
640 
641  addParm("File Name", "File name to save cell graph","CellGraph3D.csv");
642  addParm("Min Area", "Minimum area of cell-cell interfaces to include in CSV file, 0 for all", "0.0");
643  addParm("Tolerance", "Tolerance for collapsing shared vertices", "0.0001");
644  }
645 
646  bool run()
647  {
649  return false;
650 
651  Mesh *m = currentMesh();
652  bool res = run(m, parm("File Name"), parm("Min Area").toDouble(), parm("Tolerance").toDouble());
653  if(res)
654  m->showHeat();
655  return res;
656  }
657 
658  bool run(Mesh* mesh, const QString &fileName, double minArea, double tolerance);
659  };
660 }
661 
662 #endif
mgx::QuickSaveFile::icon
QIcon icon() const
Definition: SystemProcessSave.hpp:548
mgx::savePLYCellGraph
bool savePLYCellGraph(Mesh *mesh, const QString &filename, bool binary)
mgx::MeshSave::dlg
QDialog * dlg
Definition: SystemProcessSave.hpp:272
mgx::StackOpenSaveFolder
Definition: SystemProcessSave.hpp:612
mgx::ProcessParms::addParm
bool addParm(const QString &parmName, const QString &desc, const QString &def, const QStringList &choices=QStringList())
Add a parameter to the list.
mgx::StackExport::StackExport
StackExport(const Process &proc)
Definition: SystemProcessSave.hpp:127
Process.hpp
mgx::QuickSaveFile::saveWithExt
bool saveWithExt
Definition: SystemProcessSave.hpp:537
mgx::StackExport::icon
QIcon icon() const
Definition: SystemProcessSave.hpp:158
mgx::TakeSnapshot::icon
QIcon icon() const
Definition: SystemProcessSave.hpp:603
mgx::TakeSnapshot::TakeSnapshot
TakeSnapshot(const Process &proc)
Definition: SystemProcessSave.hpp:575
mgx::CellGraph3D
Definition: SystemProcessSave.hpp:632
mgx::StackSave
Definition: SystemProcessSave.hpp:89
GraphUtils.hpp
mgx::StackExport
Definition: SystemProcessSave.hpp:124
mgx::QuickSaveFile::extCounter
int extCounter
Definition: SystemProcessSave.hpp:538
mgx::TakeSnapshot
Definition: SystemProcessSave.hpp:573
mgx::TakeSnapshot::run
bool run()
Runs the process.
Definition: SystemProcessSave.hpp:588
mgx::MeshSave::ui
Ui_SaveMeshDialog * ui
Definition: SystemProcessSave.hpp:273
mgx::QuickSaveFile
Definition: SystemProcessSave.hpp:521
mgx::SaveViewFile::SaveViewFile
SaveViewFile(const Process &proc)
Definition: SystemProcessSave.hpp:494
mgx::Stack
Definition: Stack.hpp:33
mgx
Distributed matrix library.
Definition: Assert.hpp:26
mgx::Process::MESH_NON_EMPTY
@ MESH_NON_EMPTY
Non-empty mesh.
Definition: Process.hpp:638
mgx::Process::checkState
CheckState checkState()
Call this function and convert the result to a boolean.
mgx::StackExport::ui
Ui_ExportStackDialog * ui
Definition: SystemProcessSave.hpp:165
mgx::MeshExport
Definition: SystemProcessSave.hpp:433
mgx::ProcessParms::setIcon
bool setIcon(const QIcon &icon)
Set the icon.
mgx::Process
Definition: Process.hpp:219
mgx::MeshExport::dlg
QDialog * dlg
Definition: SystemProcessSave.hpp:479
mgx::stringToBool
mgx_EXPORT bool stringToBool(const QString &string)
Helper function converting a string into a boolean.
mgx::StackOpenSaveFolder::StackOpenSaveFolder
StackOpenSaveFolder(const Process &proc)
Definition: SystemProcessSave.hpp:614
mgx::MeshExport::MeshExport
MeshExport(const Process &proc)
Definition: SystemProcessSave.hpp:436
mgx::MeshExport::icon
QIcon icon() const
Definition: SystemProcessSave.hpp:458
mgx::ProcessParms::setDesc
bool setDesc(const QString &description)
Set the description.
mgx::StackOpenSaveFolder::icon
QIcon icon() const
Definition: SystemProcessSave.hpp:629
mgx::Mesh
Definition: Mesh.hpp:54
mgx::MeshExport::ui
Ui_ExportMeshDialog * ui
Definition: SystemProcessSave.hpp:480
mgx::SaveViewFile::icon
QIcon icon() const
Definition: SystemProcessSave.hpp:511
mgx::Vector< 3, double >
mgx::StackSave::icon
QIcon icon() const
Definition: SystemProcessSave.hpp:114
mgx::CellGraph3D::run
bool run()
Runs the process.
Definition: SystemProcessSave.hpp:646
mgx::CellGraph3D::CellGraph3D
CellGraph3D(const Process &process)
Definition: SystemProcessSave.hpp:635
mgx::MeshSave
Definition: SystemProcessSave.hpp:238
mgx::StackExport::dlg
QDialog * dlg
Definition: SystemProcessSave.hpp:166
mgx::MeshSave::MeshSave
MeshSave(const Process &proc)
Definition: SystemProcessSave.hpp:241
mgx::MeshSave::icon
QIcon icon() const
Definition: SystemProcessSave.hpp:259
mgx::Process::mesh
Mesh * mesh(int i)
Returns the ith mesh.
mgx::ProcessParms::setName
bool setName(const QString &name)
Set the name.
mgx::Mesh::showHeat
bool showHeat() const
Definition: Mesh.hpp:679
mgx::StackOpenSaveFolder::images
QStringList images
Definition: SystemProcessSave.hpp:626
mgx::ProcessParms::parm
QString parm(const QString &name) const
Get a single parameter value by name.
mgx::SaveViewFile
Definition: SystemProcessSave.hpp:492
mgx::Process::currentMesh
Mesh * currentMesh()
Returns the current mesh (i.e.
mgx::QuickSaveFile::QuickSaveFile
QuickSaveFile(const Process &proc)
Definition: SystemProcessSave.hpp:523
mgx::StackSave::StackSave
StackSave(const Process &proc)
Definition: SystemProcessSave.hpp:91
mgx::Store
Definition: Store.hpp:33